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

feat(its-factory): allow minter to be arbitrary bytes for remote token deployment #297

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions contracts/InterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +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 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 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 minter,
bytes memory remoteMinter,
string memory destinationChain,
uint256 gasValue
) public payable returns (bytes32 tokenId) {
string memory tokenName;
string memory tokenSymbol;
uint8 tokenDecimals;
bytes memory minter_ = new bytes(0);

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

if (minter != address(0)) {
if (!token.isMinter(minter)) revert NotMinter(minter);
if (minter == address(interchainTokenService)) revert InvalidMinter(minter);

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

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

/**
Expand All @@ -198,7 +195,7 @@ 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.
Expand All @@ -207,13 +204,14 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
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();
bytes memory minter_ = new bytes(0);

tokenId = deployRemoteInterchainToken(salt, minter, destinationChain, gasValue);
tokenId = deployRemoteInterchainToken(salt, minter_, destinationChain, gasValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is incosistent with the other function. I think we should not have the same function name twice in the same contract anyway, and this function does nothing for now, since the additional parameter has to be empty. If you wanna add the parameter now and support it later then maybe remove the other function completely. If you need both you should have an internal function that executes the logic and have both external functions call it to avoid the extra external call, which I think is what happens here (test this i might be wrong).

}

/**
Expand Down
9 changes: 6 additions & 3 deletions contracts/interfaces/IInterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +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 minter The address to distribute the token on the destination chain.
* @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 minter,
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
Loading