Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ahramy committed Nov 7, 2024
1 parent 8731388 commit c90f14f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
43 changes: 23 additions & 20 deletions contracts/InterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,23 +155,21 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
/**
* @notice Deploys a remote interchain token on a specified destination chain.
* @param salt The unique salt for deploying the token.
* @param localMinter TBD
* @param remoteMinter TBD
* @param remoteMinter The calldata representing the minter's address on the remote chain. Must be empty if no minter is specified.
* Reverts if the msg.sender does not have mint permission for the token.
* @param destinationChain The name of the destination chain.
* @param gasValue The amount of gas to send for the deployment.
* @return tokenId The tokenId corresponding to the deployed InterchainToken.
*/
function deployRemoteInterchainToken(
bytes32 salt,
address localMinter,
address remoteMinter,
bytes memory remoteMinter,
string memory destinationChain,
uint256 gasValue
) public payable returns (bytes32 tokenId) {
string memory tokenName;
string memory tokenSymbol;
uint8 tokenDecimals;
bytes memory remoteMinterBytes = new bytes(0);

salt = interchainTokenSalt(chainNameHash, msg.sender, salt);
tokenId = interchainTokenService.interchainTokenId(TOKEN_FACTORY_DEPLOYER, salt);
Expand All @@ -182,19 +180,12 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
tokenSymbol = token.symbol();
tokenDecimals = token.decimals();

if (localMinter != address(0)) {
if (!token.isMinter(localMinter)) revert NotMinter(localMinter);
if (localMinter == address(interchainTokenService)) revert InvalidMinter(localMinter);
if (remoteMinter.length != 0) {
if (!token.isMinter(msg.sender)) revert NotMinter(msg.sender);
if (msg.sender == address(interchainTokenService)) revert InvalidMinter(msg.sender);
}

// Prepare remote minter for deployment on the destination chain
if (remoteMinter != address(0)) {
if (!token.isMinter(remoteMinter)) revert NotMinter(remoteMinter);
if (remoteMinter == address(interchainTokenService)) revert InvalidMinter(remoteMinter);
remoteMinterBytes = remoteMinter.toBytes();
}

tokenId = _deployInterchainToken(salt, destinationChain, tokenName, tokenSymbol, tokenDecimals, remoteMinterBytes, gasValue);
tokenId = _deployInterchainToken(salt, destinationChain, tokenName, tokenSymbol, tokenDecimals, remoteMinter, gasValue);
}

/**
Expand All @@ -204,23 +195,22 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
* Other source chains are not supported anymore to simplify ITS token deployment behaviour.
* @param originalChainName The name of the chain where the token originally exists.
* @param salt The unique salt for deploying the token.
* @param minter The address to receive the minter and operator role of the token, in addition to ITS. If the address is `address(0)`,
* @dev minter The address to receive the minter and operator role of the token, in addition to ITS. If the address is `address(0)`,
* no additional minter is set on the token. Reverts if the minter does not have mint permission for the token.
* @param destinationChain The name of the destination chain.
* @param gasValue The amount of gas to send for the deployment.
* @return tokenId The tokenId corresponding to the deployed InterchainToken.
*/
// This method is deprecated, should I remove it with the minter change or we want to keep it?
function deployRemoteInterchainToken(
string calldata originalChainName,
bytes32 salt,
address minter,
address /*minter*/,
string memory destinationChain,
uint256 gasValue
) external payable returns (bytes32 tokenId) {
if (bytes(originalChainName).length != 0) revert NotSupported();

tokenId = deployRemoteInterchainToken(salt, minter, address(0), destinationChain, gasValue);
tokenId = deployRemoteInterchainToken(salt, abi.encodePacked(address(0)), destinationChain, gasValue);
}

/**
Expand Down Expand Up @@ -317,4 +307,17 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M

tokenId = deployRemoteCanonicalInterchainToken(originalTokenAddress, destinationChain, gasValue);
}

function addressToBytes(address _address) public pure returns (bytes memory) {
return abi.encodePacked(_address);
}

function bytesToAddress(bytes memory data) public pure returns (address) {
require(data.length == 20, 'Invalid bytes length for address');

Check warning on line 316 in contracts/InterchainTokenFactory.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements
address addr;
assembly {
addr := mload(add(data, 20))
}
return addr;
}
}
11 changes: 6 additions & 5 deletions contracts/interfaces/IInterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,28 @@ interface IInterchainTokenFactory is IUpgradable, IMulticall {
/**
* @notice Deploys a remote interchain token on a specified destination chain.
* @param salt The unique salt for deploying the token.
* @param localMinter TBD
* @param remoteMinter TBD
* @param remoteMinter The calldata representing the minter's address on the remote chain. Must be empty if no minter is specified.
* Reverts if the msg.sender does not have mint permission for the token.
* @param destinationChain The name of the destination chain.
* @param gasValue The amount of gas to send for the deployment.
* @return tokenId The tokenId corresponding to the deployed InterchainToken.
*/
function deployRemoteInterchainToken(
bytes32 salt,
address localMinter,
address remoteMinter,
bytes calldata remoteMinter,
string memory destinationChain,
uint256 gasValue
) external payable returns (bytes32 tokenId);

/**
* @notice Deploys a remote interchain token on a specified destination chain.
* This method is deprecated and will be removed in the future. Please use the above method instead.
* @dev originalChainName is only allowed to be '', i.e the current chain.
* Other source chains are not supported anymore to simplify ITS token deployment behaviour.
* @param originalChainName The name of the chain where the token originally exists.
* @param salt The unique salt for deploying the token.
* @param minter The address to distribute the token on the destination chain.
* @dev minter The address to receive the minter and operator role of the token, in addition to ITS. If the address is `address(0)`,
* no additional minter is set on the token. Reverts if the minter does not have mint permission for the token.
* @param destinationChain The name of the destination chain.
* @param gasValue The amount of gas to send for the deployment.
* @return tokenId The tokenId corresponding to the deployed InterchainToken.
Expand Down

0 comments on commit c90f14f

Please sign in to comment.