|
| 1 | +# Routing Mechanics |
| 2 | + |
| 3 | +[ITS Hub](/dev/amplifier/its-hub/introduction/) modifies the existing token transfer mechanism by introducing a centralized routing point. Instead of ITS Edge Contracts communicating directly, all ITS calls are routed through the ITS Hub. This approach allows for enhanced security measures, balance tracking, and prepares the system for future features. |
| 4 | + |
| 5 | +## How Routing Works |
| 6 | + |
| 7 | +ITS Hub routing works in the following way: |
| 8 | + |
| 9 | +- [Dual GMP calls](#dual-gmp-calls) |
| 10 | +- [Payload wrapping](#payload-wrapping) |
| 11 | + |
| 12 | +### Dual GMP Calls |
| 13 | + |
| 14 | +Each token transfer or deployment involves two General Message Passing (GMP) calls: |
| 15 | + |
| 16 | +1. **From Source Chain to ITS Hub**: The ITS Edge Contract on the source chain sends a GMP call to the ITS Hub, wrapping the original payload. |
| 17 | +2. **From ITS Hub to Destination Chain**: The ITS Hub processes the payload, applies security measures, and forwards it to the ITS Edge Contract on the destination chain. |
| 18 | + |
| 19 | +### Payload Wrapping |
| 20 | + |
| 21 | +To facilitate routing through the ITS Hub, new message types are introduced: |
| 22 | + |
| 23 | +```solidity |
| 24 | +uint256 private constant MESSAGE_TYPE_SEND_TO_HUB = 3; |
| 25 | +uint256 private constant MESSAGE_TYPE_RECEIVE_FROM_HUB = 4; |
| 26 | +``` |
| 27 | + |
| 28 | +- **MESSAGE_TYPE_SEND_TO_HUB (3)**: Indicates the message is intended for the ITS Hub. |
| 29 | +- **MESSAGE_TYPE_RECEIVE_FROM_HUB (4)**: Indicates the message is coming from the ITS Hub. |
| 30 | + |
| 31 | +**Example Payload Wrapping:** |
| 32 | + |
| 33 | +On the source chain: |
| 34 | + |
| 35 | +```solidity |
| 36 | +string destinationAddress = trustedAddresses[destinationChain]; |
| 37 | +
|
| 38 | +if (destinationAddress == itsHubAddress) { |
| 39 | + payload = abi.encode( |
| 40 | + MESSAGE_TYPE_SEND_TO_HUB, |
| 41 | + destinationChain, // True destination chain |
| 42 | + originalPayload // Original ITS payload |
| 43 | + ); |
| 44 | + destinationChain = axelarChainName; // Route to ITS Hub |
| 45 | +} |
| 46 | +
|
| 47 | +gateway.callContract(destinationChain, destinationAddress, payload); |
| 48 | +``` |
| 49 | + |
| 50 | +On the ITS Hub: |
| 51 | + |
| 52 | +```solidity |
| 53 | +// Unwrap the payload |
| 54 | +(destinationChain, originalPayload) = abi.decode(payload, (string, bytes)); |
| 55 | +
|
| 56 | +// Process the payload (apply security checks, balance tracking, etc.) |
| 57 | +
|
| 58 | +// Wrap the payload to send to the destination chain |
| 59 | +payload = abi.encode( |
| 60 | + MESSAGE_TYPE_RECEIVE_FROM_HUB, |
| 61 | + sourceChain, // True source chain |
| 62 | + originalPayload // Original ITS payload |
| 63 | +); |
| 64 | +
|
| 65 | +gateway.callContract(destinationChain, destinationAddress, payload); |
| 66 | +``` |
| 67 | + |
| 68 | +## Visualizing the Routing Process |
| 69 | + |
| 70 | +### ITS Chain A to ITS Chain B via ITS Hub |
| 71 | + |
| 72 | +<object |
| 73 | + type="image/svg+xml" |
| 74 | + data="/images/its-hub/its-hub-routing-dark.svg" |
| 75 | + class="hidden dark:block w-full max-w-[60rem] mx-auto py-6" |
| 76 | +></object> |
| 77 | +<object |
| 78 | + type="image/svg+xml" |
| 79 | + data="/images/its-hub/its-hub-routing-light.svg" |
| 80 | + class=" dark:hidden w-full max-w-[60rem] mx-auto py-6" |
| 81 | +></object> |
| 82 | + |
| 83 | +## Interacting with Different Chain Types |
| 84 | + |
| 85 | +### Amplifier Chains |
| 86 | + |
| 87 | +- **Smart Contract Chains**: Have [ITS Edge Contracts](https://github.com/axelarnetwork/axelar-cgp-sui/tree/main/move/example/sources/its) similar to EVM chains. The routing mechanics are consistent with the dual GMP call approach. |
| 88 | +- **Non-Smart Contract Chains**: The Axelar Gateway on these chains acts as an ITS Edge Contract, translating ITS commands into custom token transfer or deployment transactions. |
| 89 | + |
| 90 | +**Amplifier Chain to ITS Hub** |
| 91 | + |
| 92 | +<object |
| 93 | + type="image/svg+xml" |
| 94 | + data="/images/its-hub/amplifier-to-its-dark.svg" |
| 95 | + class="hidden dark:block w-full max-w-[60rem] mx-auto py-6" |
| 96 | +></object> |
| 97 | +<object |
| 98 | + type="image/svg+xml" |
| 99 | + data="/images/its-hub/amplifier-to-its-light.svg" |
| 100 | + class=" dark:hidden w-full max-w-[60rem] mx-auto py-6" |
| 101 | +></object> |
| 102 | + |
| 103 | +**ITS Hub to Amplifier Chain** |
| 104 | + |
| 105 | +<object |
| 106 | + type="image/svg+xml" |
| 107 | + data="/images/its-hub/its-to-amplifier-dark.svg" |
| 108 | + class="hidden dark:block w-full max-w-[60rem] mx-auto py-6" |
| 109 | +></object> |
| 110 | +<object |
| 111 | + type="image/svg+xml" |
| 112 | + data="/images/its-hub/its-to-amplifier-light.svg" |
| 113 | + class=" dark:hidden w-full max-w-[60rem] mx-auto py-6" |
| 114 | +></object> |
| 115 | + |
| 116 | +### Consensus Chains |
| 117 | + |
| 118 | +- Use the existing Axelar protocol for GMP calls. |
| 119 | +- The ITS Hub interacts with consensus modules to handle GMP calls with tokens (Gateway tokens). |
| 120 | + |
| 121 | +**Consensus Chain to ITS Hub with Gateway Token** |
| 122 | + |
| 123 | +<object |
| 124 | + type="image/svg+xml" |
| 125 | + data="/images/its-hub/consensus-to-its-dark.svg" |
| 126 | + class="hidden dark:block w-full max-w-[60rem] mx-auto py-6" |
| 127 | +></object> |
| 128 | +<object |
| 129 | + type="image/svg+xml" |
| 130 | + data="/images/its-hub/consensus-to-its-light.svg" |
| 131 | + class=" dark:hidden w-full max-w-[60rem] mx-auto py-6" |
| 132 | +></object> |
| 133 | + |
| 134 | +## Security Measures |
| 135 | + |
| 136 | +The ITS Hub enhances security through: |
| 137 | + |
| 138 | +- **Balance Tracking**: Keeps track of the total bridged balance per token per chain to prevent over-escrow or unauthorized minting. |
| 139 | +- **Rate Limits**: Applies per-token rate limits to mitigate risks from compromised chains or contracts. |
| 140 | +- **Centralized Control**: Allows pausing or disconnecting specific chain connections in case of security threats. |
| 141 | + |
| 142 | +## Future Compatibility |
| 143 | + |
| 144 | +The ITS Hub is designed to accommodate future features: |
| 145 | + |
| 146 | +- **GMP Express**: Support for faster message passing without compromising security. |
| 147 | +- **Integration with Axelar and Cosmos Chains**: Enabling ITS functionalities on these chains through the ITS Hub. |
| 148 | +- **Migration Support**: Existing P2P ITS connections can be migrated to route through the ITS Hub. |
0 commit comments