diff --git a/DESIGN.md b/DESIGN.md index a9187a40..0704f2ba 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -43,7 +43,7 @@ We designed an [interface](./contracts/interfaces/IInterchainTokenStandard.sol) ## Interchain Communication Spec -The messages going through the Axelar Network between `InterchainTokenServices` need to have a consistent format to be understood properly. We chose to use `abi` encoding because it is easy to use in EVM chains, which are at the front and center of programmable blockchains, and because it is easy to implement in other ecosystems which tend to be more gas efficient. There are currently three supported message types: `INTERCHAIN_TRANSFER`, `DEPLOY_INTERCHAIN_TOKEN`, `DEPLOY_TOKEN_MANAGER`. +The messages going through the Axelar Network between `InterchainTokenServices` need to have a consistent format to be understood properly. We chose to use `abi` encoding because it is easy to use in EVM chains, which are at the front and center of programmable blockchains, and because it is easy to implement in other ecosystems which tend to be more gas efficient. There are currently three supported message types: `INTERCHAIN_TRANSFER`, `DEPLOY_INTERCHAIN_TOKEN`, `REGISTER_TOKEN`. ### `INTERCHAIN_TRANSFER` @@ -62,16 +62,16 @@ This message is used to transfer tokens between chains. The tokens are handled a This message is used to deploy an `InterchainToken` on a remote chain, that corresponds to the `tokenId` of a local ERC-20 token registered in ITS. This allows a user to deploy tokens to remote chains from a single source chain, instead of having to make a tx on each chain. It also allows the implementation on each chain to be flexible (e.g. `tokenId` derivation can be different on remote chains). -| Name | Type | Description | -| -------- | --------- | ----------------------------------------------------------------------------------------------------------------------- | +| Name | Type | Description | +| ----------- | --------- | ----------------------------------------------------------------------------------------------------------------------- | | messageType | `uint256` | Will always have a value of `1` | -| tokenId | `bytes32` | The `interchainTokenId` of the token being deployed | -| name | `string` | The name for the token | -| symbol | `string` | The symbol for the token | -| decimals | `uint8` | The decimals for the token | -| minter | `bytes` | An address on the destination chain that can mint/burn the deployed token on the destination chain, empty for no minter | +| tokenId | `bytes32` | The `interchainTokenId` of the token being deployed | +| name | `string` | The name for the token | +| symbol | `string` | The symbol for the token | +| decimals | `uint8` | The decimals for the token | +| minter | `bytes` | An address on the destination chain that can mint/burn the deployed token on the destination chain, empty for no minter | -### `DEPLOY_TOKEN_MANAGER` +### `REGISTER_TOKEN` This message is used to deploy a token manager on a remote chain, that corresponds to a local token manager. This is useful to link custom tokens via ITS with the same tokenId. @@ -86,18 +86,18 @@ This message is used to deploy a token manager on a remote chain, that correspon This message is used to route an ITS message via the ITS Hub. The ITS Hub applies certain security checks, and then routes it to the true destination chain. This mode is enabled if the trusted address corresponding to the destination chain is set to the ITS Hub identifier. -| Name | Type | Description | -| ------------------ | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| messageType | `uint256` | Will always have a value of `3` | -| destinationChain | `string` | The true destination chain for the ITS call | -| payload | `bytes` | The actual ITS message that's being routed through ITS Hub +| Name | Type | Description | +| ---------------- | --------- | ---------------------------------------------------------- | +| messageType | `uint256` | Will always have a value of `3` | +| destinationChain | `string` | The true destination chain for the ITS call | +| payload | `bytes` | The actual ITS message that's being routed through ITS Hub | ### `RECEIVE_FROM_HUB` This message is used to receive an ITS message from the ITS Hub. The ITS Hub applies certain security checks, and then routes it to the ITS contract. The message is accepted if the trusted address corresponding to the original source chain is set to the ITS Hub identifier. -| Name | Type | Description | -| ------------------ | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| messageType | `uint256` | Will always have a value of `4` | -| sourceChain | `string` | The original source chain for the ITS call | -| payload | `bytes` | The actual ITS message that's being routed through ITS Hub +| Name | Type | Description | +| ----------- | --------- | ---------------------------------------------------------- | +| messageType | `uint256` | Will always have a value of `4` | +| sourceChain | `string` | The original source chain for the ITS call | +| payload | `bytes` | The actual ITS message that's being routed through ITS Hub | diff --git a/contracts/InterchainTokenService.sol b/contracts/InterchainTokenService.sol index 5b2afc14..595080ca 100644 --- a/contracts/InterchainTokenService.sol +++ b/contracts/InterchainTokenService.sol @@ -79,7 +79,7 @@ contract InterchainTokenService is uint256 private constant MESSAGE_TYPE_INTERCHAIN_TRANSFER = 0; uint256 private constant MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN = 1; - uint256 private constant MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER = 2; + uint256 private constant MESSAGE_TYPE_REGISTER_TOKEN = 2; uint256 private constant MESSAGE_TYPE_SEND_TO_HUB = 3; uint256 private constant MESSAGE_TYPE_RECEIVE_FROM_HUB = 4; @@ -814,7 +814,7 @@ contract InterchainTokenService is if (messageType == MESSAGE_TYPE_INTERCHAIN_TRANSFER) { address expressExecutor = _getExpressExecutorAndEmitEvent(commandId, sourceChain, sourceAddress, payloadHash); _processInterchainTransferPayload(commandId, expressExecutor, originalSourceChain, payload); - } else if (messageType == MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER) { + } else if (messageType == MESSAGE_TYPE_REGISTER_TOKEN) { _processDeployTokenManagerPayload(payload); } else if (messageType == MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN) { _processDeployInterchainTokenPayload(payload); @@ -884,7 +884,7 @@ contract InterchainTokenService is emit TokenManagerDeploymentStarted(tokenId, destinationChain, tokenManagerType, params); - bytes memory payload = abi.encode(MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, tokenId, tokenManagerType, params); + bytes memory payload = abi.encode(MESSAGE_TYPE_REGISTER_TOKEN, tokenId, tokenManagerType, params); _callContract(destinationChain, payload, IGatewayCaller.MetadataVersion.CONTRACT_CALL, gasValue); } diff --git a/contracts/types/InterchainTokenServiceTypes.sol b/contracts/types/InterchainTokenServiceTypes.sol index 9e293028..2ac5453e 100644 --- a/contracts/types/InterchainTokenServiceTypes.sol +++ b/contracts/types/InterchainTokenServiceTypes.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.0; enum MessageType { INTERCHAIN_TRANSFER, DEPLOY_INTERCHAIN_TOKEN, - DEPLOY_TOKEN_MANAGER + REGISTER_TOKEN } struct InterchainTransfer { diff --git a/test/InterchainTokenService.js b/test/InterchainTokenService.js index f12ecc7e..ffddae8b 100644 --- a/test/InterchainTokenService.js +++ b/test/InterchainTokenService.js @@ -17,7 +17,7 @@ const { deployAll, deployContract, deployInterchainTokenService } = require('../ const { MESSAGE_TYPE_INTERCHAIN_TRANSFER, MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, - MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, + MESSAGE_TYPE_REGISTER_TOKEN, MESSAGE_TYPE_RECEIVE_FROM_HUB, INVALID_MESSAGE_TYPE, NATIVE_INTERCHAIN_TOKEN, @@ -1046,7 +1046,7 @@ describe('Interchain Token Service', () => { const type = LOCK_UNLOCK; const payload = defaultAbiCoder.encode( ['uint256', 'bytes32', 'uint256', 'bytes'], - [MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, tokenId, type, params], + [MESSAGE_TYPE_REGISTER_TOKEN, tokenId, type, params], ); const tokenManager = await getContractAt('TokenManager', await service.validTokenManagerAddress(tokenId), wallet); @@ -1127,12 +1127,12 @@ describe('Interchain Token Service', () => { const params = defaultAbiCoder.encode(['bytes', 'address'], [wallet.address, token.address]); const payload = defaultAbiCoder.encode( ['uint256', 'bytes32', 'uint256', 'bytes'], - [MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, tokenId, LOCK_UNLOCK, params], + [MESSAGE_TYPE_REGISTER_TOKEN, tokenId, LOCK_UNLOCK, params], ); const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload); const expectedTokenManagerAddress = await service.tokenManagerAddress(tokenId); - await expect(reportGas(service.execute(commandId, sourceChain, sourceAddress, payload), 'Receive GMP DEPLOY_TOKEN_MANAGER')) + await expect(reportGas(service.execute(commandId, sourceChain, sourceAddress, payload), 'Receive GMP REGISTER_TOKEN')) .to.emit(service, 'TokenManagerDeployed') .withArgs(tokenId, expectedTokenManagerAddress, LOCK_UNLOCK, params); @@ -1155,7 +1155,7 @@ describe('Interchain Token Service', () => { const params = defaultAbiCoder.encode(['bytes', 'address'], [wallet.address, token.address]); const payload = defaultAbiCoder.encode( ['uint256', 'bytes32', 'uint256', 'bytes'], - [MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, tokenId, MINT_BURN, params], + [MESSAGE_TYPE_REGISTER_TOKEN, tokenId, MINT_BURN, params], ); const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload); @@ -1181,7 +1181,7 @@ describe('Interchain Token Service', () => { const params = defaultAbiCoder.encode(['bytes', 'address'], [wallet.address, token.address]); const payload = defaultAbiCoder.encode( ['uint256', 'bytes32', 'uint256', 'bytes'], - [MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, tokenId, NATIVE_INTERCHAIN_TOKEN, params], + [MESSAGE_TYPE_REGISTER_TOKEN, tokenId, NATIVE_INTERCHAIN_TOKEN, params], ); const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload); @@ -2422,7 +2422,7 @@ describe('Interchain Token Service', () => { const payload = defaultAbiCoder.encode( ['uint256', 'bytes32', 'bytes', 'uint256'], - [MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, tokenId, destAddress, amount], + [MESSAGE_TYPE_REGISTER_TOKEN, tokenId, destAddress, amount], ); const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload); @@ -2430,7 +2430,7 @@ describe('Interchain Token Service', () => { (gasOptions) => service.expressExecute(commandId, sourceChain, sourceAddress, payload, gasOptions), service, 'InvalidExpressMessageType', - [MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER], + [MESSAGE_TYPE_REGISTER_TOKEN], ); }); diff --git a/test/InterchainTokenServiceFullFlow.js b/test/InterchainTokenServiceFullFlow.js index 085faaa1..03ec9477 100644 --- a/test/InterchainTokenServiceFullFlow.js +++ b/test/InterchainTokenServiceFullFlow.js @@ -18,7 +18,7 @@ const { approveContractCall } = require('../scripts/utils'); const { MESSAGE_TYPE_INTERCHAIN_TRANSFER, MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, - MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, + MESSAGE_TYPE_REGISTER_TOKEN, MESSAGE_TYPE_SEND_TO_HUB, MESSAGE_TYPE_RECEIVE_FROM_HUB, NATIVE_INTERCHAIN_TOKEN, @@ -372,7 +372,7 @@ describe('Interchain Token Service Full Flow', () => { const payload = defaultAbiCoder.encode( ['uint256', 'bytes32', 'uint256', 'bytes'], - [MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, tokenId, MINT_BURN, params], + [MESSAGE_TYPE_REGISTER_TOKEN, tokenId, MINT_BURN, params], ); const expectedTokenManagerAddress = await service.tokenManagerAddress(tokenId); await expect(service.multicall(calls, { value })) diff --git a/test/constants.js b/test/constants.js index a4fef332..58ca939d 100644 --- a/test/constants.js +++ b/test/constants.js @@ -2,7 +2,7 @@ const MESSAGE_TYPE_INTERCHAIN_TRANSFER = 0; const MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN = 1; -const MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER = 2; +const MESSAGE_TYPE_REGISTER_TOKEN = 2; const MESSAGE_TYPE_SEND_TO_HUB = 3; const MESSAGE_TYPE_RECEIVE_FROM_HUB = 4; const INVALID_MESSAGE_TYPE = 5; @@ -25,7 +25,7 @@ const ITS_HUB_ADDRESS = 'axelar1xyz'; module.exports = { MESSAGE_TYPE_INTERCHAIN_TRANSFER, MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, - MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER, + MESSAGE_TYPE_REGISTER_TOKEN, MESSAGE_TYPE_SEND_TO_HUB, MESSAGE_TYPE_RECEIVE_FROM_HUB, INVALID_MESSAGE_TYPE,