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: rename deployTokenManager to linkToken and change the message type for deploying remote token managers #318

Merged
merged 15 commits into from
Jan 13, 2025
12 changes: 10 additions & 2 deletions contracts/InterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,24 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
* @return tokenId The tokenId corresponding to the registered canonical token.
*/
function registerCanonicalInterchainToken(address tokenAddress) external payable returns (bytes32 tokenId) {
bytes memory params = abi.encode('', tokenAddress);
bytes32 deploySalt = canonicalInterchainTokenDeploySalt(tokenAddress);
string memory currentChain = '';
// No custom operator is set for canonical token registration
bytes memory linkParams = '';
uint256 gasValue = 0;

// Ensure that the ERC20 token has metadata before registering it
// slither-disable-next-line unused-return
_getTokenMetadata(tokenAddress);

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

/**
Expand Down
165 changes: 107 additions & 58 deletions contracts/InterchainTokenService.sol

Large diffs are not rendered by default.

35 changes: 26 additions & 9 deletions contracts/interfaces/IInterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ interface IInterchainTokenService is
error EmptyTokenSymbol();
error EmptyParams();
error EmptyDestinationAddress();
error EmptyTokenAddress();
error NotSupported();

event InterchainTransfer(
Expand All @@ -72,9 +73,12 @@ interface IInterchainTokenService is
uint256 amount,
bytes32 dataHash
);
event TokenManagerDeploymentStarted(
event TokenMetadataRegistered(address indexed tokenAddress, uint8 decimals);
event LinkTokenStarted(
bytes32 indexed tokenId,
string destinationChain,
bytes sourceTokenAddress,
bytes destinationTokenAddress,
TokenManagerType indexed tokenManagerType,
bytes params
);
Expand Down Expand Up @@ -170,19 +174,32 @@ interface IInterchainTokenService is
function interchainTokenId(address operator_, bytes32 salt) external view returns (bytes32 tokenId);

/**
* @notice Deploys a custom token manager contract on a remote chain.
* @param salt The salt used for token manager deployment.
* @param destinationChain The name of the destination chain.
* @param tokenManagerType The type of token manager. Cannot be NATIVE_INTERCHAIN_TOKEN.
* @param params The deployment parameters.
* @param gasValue The gas value for deployment.
* @notice Registers metadata for a token on the ITS Hub. This metadata is used for scaling linked tokens.
* The token metadata must be registered before linkToken can be called for the corresponding token.
* @param tokenAddress The address of the token.
* @param gasValue The cross-chain gas value for sending the registration message to ITS Hub.
*/
function registerTokenMetadata(address tokenAddress, uint256 gasValue) external payable;

/**
* @notice If `destinationChain` is an empty string, this function will register the token address on the current chain.
* Otherwise, it will link the token address on the destination chain with the token corresponding to the tokenId on the current chain.
* A token manager is deployed on EVM chains that's responsible for managing the linked token.
* @dev This function replaces the prior `deployTokenManager` function.
* @param salt A unique identifier to allow for multiple tokens registered per deployer.
* @param destinationChain The chain to link the token to. Pass an empty string for this chain.
* @param destinationTokenAddress The token address to link, as bytes.
* @param tokenManagerType The type of the token manager to use to send and receive tokens.
* @param linkParams Additional parameteres to use to link the token. Fow not it is just the address of the operator.
* @param gasValue Pass a non-zero value only for remote linking, which should be the gas to use to pay for the contract call.
* @return tokenId The tokenId associated with the token manager.
*/
function deployTokenManager(
function linkToken(
bytes32 salt,
string calldata destinationChain,
bytes memory destinationTokenAddress,
TokenManagerType tokenManagerType,
bytes calldata params,
bytes memory linkParams,
uint256 gasValue
) external payable returns (bytes32 tokenId);

Expand Down
13 changes: 12 additions & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ const compilerSettings = {
optimizer: optimizerSettings,
},
};
const itsCompilerSettings = {
version: '0.8.27',
settings: {
evmVersion: process.env.EVM_VERSION || 'london',
optimizer: {
...optimizerSettings,
runs: 100,
},
},
};

/**
* @type import('hardhat/config').HardhatUserConfig
Expand All @@ -59,7 +69,8 @@ module.exports = {
'contracts/proxies/InterchainProxy.sol': fixedContractCompilerSettings,
'contracts/proxies/TokenManagerProxy.sol': fixedContractCompilerSettings,
'contracts/interchain-token/InterchainToken.sol': fixedContractCompilerSettings,
'contracts/test/TestInterchainTokenService.sol': fixedContractCompilerSettings,
'contracts/test/TestInterchainTokenService.sol': itsCompilerSettings,
'contracts/InterchainTokenService.sol': itsCompilerSettings,
},
},
defaultNetwork: 'hardhat',
Expand Down
1 change: 0 additions & 1 deletion scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ async function deployInterchainTokenService(
operatorAddress = wallet.address,
) {
const interchainTokenServiceAddress = await getCreate3Address(create3DeployerAddress, wallet, deploymentKey);

const implementation = await deployContract(wallet, 'InterchainTokenService', [
tokenManagerDeployerAddress,
interchainTokenDeployerAddress,
Expand Down
Loading