Skip to content

Commit

Permalink
Added a check for the token to exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Dec 23, 2024
1 parent 862eeb4 commit 5bfbc66
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions contracts/InterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,24 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
bytes32 deploySalt = canonicalInterchainTokenDeploySalt(tokenAddress);
string memory currentChain = '';
uint256 gasValue = 0;
_checkToken(tokenAddress);

tokenId = interchainTokenService.deployTokenManager(deploySalt, currentChain, TokenManagerType.LOCK_UNLOCK, params, gasValue);
}

function _checkToken(address tokenAddress) internal view {
IERC20Named token = IERC20Named(tokenAddress);
try token.name() {} catch {
revert NotToken(tokenAddress);
}
try token.symbol() {} catch {
revert NotToken(tokenAddress);
}
try token.decimals() {} catch {
revert NotToken(tokenAddress);
}
}

/**
* @notice Deploys a canonical interchain token on a remote chain.
* @param originalTokenAddress The address of the original token on the original chain.
Expand Down
1 change: 1 addition & 0 deletions contracts/interfaces/IInterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface IInterchainTokenFactory is IUpgradable, IMulticall {
error RemoteDeploymentNotApproved();
error InvalidTokenId(bytes32 tokenId, bytes32 expectedTokenId);
error ZeroSupplyToken();
error NotToken(address tokenAddress);

/// @notice Emitted when a minter approves a deployer for a remote interchain token deployment that uses a custom destinationMinter address.
event DeployRemoteInterchainTokenApproval(
Expand Down
4 changes: 4 additions & 0 deletions test/InterchainTokenFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ describe('InterchainTokenFactory', () => {
.withArgs(tokenId, tokenManagerAddress, LOCK_UNLOCK, params);
});

it('Should not register a non-existing token', async () => {
await expectRevert((gasOptions) => tokenFactory.registerCanonicalInterchainToken(tokenFactory.address, { gasOptions }), tokenFactory, "NotToken", [tokenFactory.address])
});

it('Should initiate a remote interchain token deployment with no original chain name provided', async () => {
const gasValue = 1234;
const payload = defaultAbiCoder.encode(
Expand Down

0 comments on commit 5bfbc66

Please sign in to comment.