Skip to content

Commit

Permalink
feat(its): rename deploy token manager message to register token message
Browse files Browse the repository at this point in the history
  • Loading branch information
ahramy committed Nov 4, 2024
1 parent 588f79c commit 85901a0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
38 changes: 19 additions & 19 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -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.

Expand All @@ -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 |
6 changes: 3 additions & 3 deletions contracts/InterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/types/InterchainTokenServiceTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
enum MessageType {
INTERCHAIN_TRANSFER,
DEPLOY_INTERCHAIN_TOKEN,
DEPLOY_TOKEN_MANAGER
REGISTER_TOKEN
}

struct InterchainTransfer {
Expand Down
16 changes: 8 additions & 8 deletions test/InterchainTokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -2422,15 +2422,15 @@ 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);

await expectRevert(
(gasOptions) => service.expressExecute(commandId, sourceChain, sourceAddress, payload, gasOptions),
service,
'InvalidExpressMessageType',
[MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER],
[MESSAGE_TYPE_REGISTER_TOKEN],
);
});

Expand Down
4 changes: 2 additions & 2 deletions test/InterchainTokenServiceFullFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 }))
Expand Down
4 changes: 2 additions & 2 deletions test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 85901a0

Please sign in to comment.