Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ITS): token type LOCK_UNLOCK_FEE express amount #193

Merged
merged 8 commits into from
Dec 1, 2023
15 changes: 13 additions & 2 deletions contracts/InterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,20 @@ contract InterchainTokenService is
{
ITokenManager tokenManager = ITokenManager(validTokenManagerAddress(tokenId));
token = IERC20(tokenManager.tokenAddress());
}

token.safeTransferFrom(msg.sender, destinationAddress, amount);
if (tokenManager.implementationType() == uint256(TokenManagerType.LOCK_UNLOCK_FEE)) {
uint256 balanceAmount = token.balanceOf(destinationAddress);

token.safeTransferFrom(msg.sender, destinationAddress, amount);
balanceAmount = token.balanceOf(destinationAddress) - balanceAmount;

if (balanceAmount < amount) {
deanamiel marked this conversation as resolved.
Show resolved Hide resolved
amount = balanceAmount;
}
} else {
token.safeTransferFrom(msg.sender, destinationAddress, amount);
}
}

// slither-disable-next-line reentrancy-events
emit InterchainTransferReceived(
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { networks, etherscan } = importNetworks(chains, keys);

const optimizerSettings = {
enabled: true,
runs: 10000,
runs: 1000,
details: {
peephole: process.env.COVERAGE === undefined,
inliner: process.env.COVERAGE === undefined,
Expand Down
6 changes: 3 additions & 3 deletions test/TokenManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ describe('Token Manager', () => {
const proxyBytecodeHash = keccak256(proxyBytecode);

const expected = {
istanbul: '0x6b736a5ec65994238466070da91520144aaa3b41ecdcda7cfa4e7b6cd2296347',
berlin: '0xcbd407743ce6492f90dc2542f2ad71ca6c99d21fd29cc9a8fdf6ff54bb28131f',
london: '0x028f986ea9320071af6747d2dad9e0870c28e8bd19542168f5e4855566e38376',
istanbul: '0xce3ee5c04c84351d193a6e5dc52e34702039a6083437b077367bac26da57103c',
berlin: '0xea7ab1f8727ce63dd60f1b7c6770723259b7ac2ce69a74046509e2a65cd4b899',
london: '0x97da1989bb59bf727d23961f163900ce0dcab3dafa2b3fa0aec39f09c5bd233e',
}[getEVMVersion()];

expect(proxyBytecodeHash).to.be.equal(expected);
Expand Down
34 changes: 31 additions & 3 deletions test/TokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,34 @@ describe('Interchain Token Service', () => {
.and.to.emit(service, 'ExpressExecutionFulfilled')
.withArgs(commandId, sourceChain, sourceAddress, keccak256(payload), wallet.address);
});

it('Should be able to receive lock/unlock with fee on transfer token with normal ERC20 token', async () => {
const [token, tokenManager, tokenId] = await deployFunctions.lockUnlockFee(
`Test Token Lock Unlock`,
'TT',
12,
2 * amount,
false,
'free',
);
await (await token.transfer(tokenManager.address, amount)).wait();
await (await token.approve(service.address, amount)).wait();

const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'bytes', 'bytes', 'uint256', 'bytes'],
[MESSAGE_TYPE_INTERCHAIN_TRANSFER, tokenId, hexlify(wallet.address), destAddress, amount, '0x'],
);

const commandId = getRandomBytes32();
await (await service.expressExecute(commandId, sourceChain, sourceAddress, payload)).wait();
await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload, getRandomBytes32(), 0, commandId);

await expect(service.execute(commandId, sourceChain, sourceAddress, payload))
.to.emit(token, 'Transfer')
.withArgs(tokenManager.address, wallet.address, amount)
.and.to.emit(service, 'ExpressExecutionFulfilled')
.withArgs(commandId, sourceChain, sourceAddress, keccak256(payload), wallet.address);
});
});

describe('Express Receive Remote Token with Data', () => {
Expand Down Expand Up @@ -2542,9 +2570,9 @@ describe('Interchain Token Service', () => {
const proxyBytecodeHash = keccak256(proxyBytecode);

const expected = {
istanbul: '0xc3db348537acecfe55d79dfcac2afdbe7fb4e3a3911dcfe96665bbb6e364c19e',
berlin: '0x2d8417cd1af08f7eb531649d52505299ce4db63fb0a2a30ee16397435ab8b7d3',
london: '0x6e2908fca7d4bf622350ebb2d3f536d34b55a7588ac26a056cf4c11f71694826',
istanbul: '0x4e164bfb56555d2b7bfec101a5bae5aa87fcfbcdd2c895a5c3cccbd68047ed27',
berlin: '0x5b973f3ea8aada2c5a451b77fbed9d668ef176c3ef0d0e4be24fda1347a2df68',
london: '0x5ab26238fc73053542097bf88cf7661d41b25c17d3f08f1c1fb9872d4476ce9d',
}[getEVMVersion()];

expect(proxyBytecodeHash).to.be.equal(expected);
Expand Down
Loading