diff --git a/content/course/interchain-token-transfer/07-tokens-on-multiple-chains/01-tokens-on-multiple-chain.mdx b/content/course/interchain-token-transfer/07-tokens-on-multiple-chains/01-tokens-on-multiple-chain.mdx index 583df606..c0a6b5c2 100644 --- a/content/course/interchain-token-transfer/07-tokens-on-multiple-chains/01-tokens-on-multiple-chain.mdx +++ b/content/course/interchain-token-transfer/07-tokens-on-multiple-chains/01-tokens-on-multiple-chain.mdx @@ -1,10 +1,20 @@ --- -title: Tokens on Multiple Chains -description: TBD +title: Overview of Multi-hop Transfers +description: Learn about how ICTT supports multi-hop transfers between spoke chains. updated: 2024-05-31 -authors: [ashucoder9] +authors: [owenwahlgren] icon: Book --- -The token bridge also supports "multi-hop" transfers, where tokens can be transferred between spoke chains. To illustrate, consider two spokes _Sa_ and _Sb_ that are both connected to the same remote _H_. A multi-hop transfer from _Sa_ to _Sb_ first gets routed from _Sa_ to _H_, where spoke balances are updated, and then _H_ automatically routes the transfer on to _Sb_. +The token bridge also supports "multi-hop" transfers, where tokens can be transferred between remote chains via the home chain. To illustrate, consider two remotes _Ra_ and _Rb_ that are both connected to the same home _H_. A multi-hop transfer from _Ra_ to _Rb_ first gets routed from _Ra_ to _H_, where the remote balances are updated, and then _H_ automatically routes the transfer on to _Rb_. + +In this example, our _Ra_ chain is `myblockchain`, our _Rb_ chain is `myblockchain2`, and _H_ chain is the Avalanche C-Chain. + +### What we will do + +1. Deploy a new local blockchain `myblockchain2` +2. Deploy a new `ERC20TokenRemote` contract to `myblockchain2` +3. Register the new `ERC20TokenRemote` contract with the `TokenHome` contract on the Avalanche C-Chain +3. Perform a multi-hop transfer of `TOK` from `myblockchain` to `myblockchain2`, with a 'hop' through the Avalanche C-Chain + diff --git a/content/course/interchain-token-transfer/07-tokens-on-multiple-chains/02-deploy-additional-blockchain.mdx b/content/course/interchain-token-transfer/07-tokens-on-multiple-chains/02-deploy-additional-blockchain.mdx new file mode 100644 index 00000000..75556d00 --- /dev/null +++ b/content/course/interchain-token-transfer/07-tokens-on-multiple-chains/02-deploy-additional-blockchain.mdx @@ -0,0 +1,107 @@ +--- +title: Deploy Additional Blockchain for Multi-hop +description: Set up a new blockchain to test ICTT multi-hop transfers. +updated: 2024-05-31 +authors: [owenwahlgren] +icon: Book +--- +import { Step, Steps } from 'fumadocs-ui/components/steps'; + + + +### Create a new blockchain `myblockchain2` for multi-hop transfer + +```bash +avalanche blockchain create myblockchain2 +``` +```bash +✔ Subnet-EVM +✔ I want to use defaults for a test environment +✔ Chain ID: 2 +✔ Token Symbol: chain2 +prefunding address 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC with balance 1000000000000000000000000 +✓ Successfully created blockchain configuration +``` + + +### Deploy the new blockchain `myblockchain2` +```bash +avalanche blockchain deploy myblockchain2 +``` +```bash +✔ Local Network +``` + + +### Get the `Teleporter Registry Address` of `myblockchain2` + +```bash +avalanche blockchain describe myblockchain2 +``` + +``` ++-------------------------------------------------------------------------------------------+ +| TELEPORTER | ++---------------+------------------------------+--------------------------------------------+ +| Local Network | Teleporter Messenger Address | 0x253b2784c75e510dD0fF1da844684a1aC0aa5fcf | +| +------------------------------+--------------------------------------------+ +| | Teleporter Registry Address | 0xa3493940a13b426BD2f7dA6E55A39c060C0e6020 | // [!code highlight] ++---------------+------------------------------+--------------------------------------------+ +``` + + +### Save the `Teleporter Registry Address` + +Most other environment variables we will need are already set in the devcontainer or from the [previous section](/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/01-erc-20-to-erc-20-bridge). +```bash +export TELEPORTER_REGISTRY_CHAIN2=0xa3493940a13b426BD2f7dA6E55A39c060C0e6020 +``` + + + +### Get the `Blockchain ID (hex)` of `myblockchain2` + + +``` ++---------------------------------------------------------------------------------------------------------------+ +| MYBLOCKCHAIN2 | ++---------------+-----------------------------------------------------------------------------------------------+ +| Name | myblockchain2 | ++---------------+-----------------------------------------------------------------------------------------------+ +| VM ID | qDNV9vtxZYYNqm7TSa9KnDTRabGxtBLv6vd888791J9a89kTF | ++---------------+-----------------------------------------------------------------------------------------------+ +| VM Version | v0.6.9 | ++---------------+--------------------------+--------------------------------------------------------------------+ +| Local Network | ChainID | 2 | +| +--------------------------+--------------------------------------------------------------------+ +| | SubnetID | 2KhsQJhH3VqS7WWMreodAAHpGfGCUNuGQDSaP2vUT29p1HELBV | +| +--------------------------+--------------------------------------------------------------------+ +| | Owners (Threhold=1) | P-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p | +| +--------------------------+--------------------------------------------------------------------+ +| | BlockchainID (CB58) | 2ZempAyezixFRdJhJribDdj2wiK6YFF63CkXKaimfPb3hWeWVH | +| +--------------------------+--------------------------------------------------------------------+ +| | BlockchainID (HEX) | 0xcdd5b2b99ae462c32a8e4ea47e94f2c7804519353558fd4127cf7ae11d8a6e52 | // [!code highlight] ++---------------+--------------------------+--------------------------------------------------------------------+ + +``` + + + +### Save the Source Blockchain ID + +```bash +export SOURCE_BLOCKCHAIN2_ID_HEX=0xcdd5b2b99ae462c32a8e4ea47e94f2c7804519353558fd4127cf7ae11d8a6e52 +``` + + + + +### Add `myblockchain2` RPC to `foundry.toml` config +```toml +[rpc_endpoints] +local-c = "http://localhost:9650/ext/bc/C/rpc" +myblockchain = "http://localhost:9650/ext/bc/myblockchain/rpc" +myblockchain2 = "http://localhost:9650/ext/bc/myblockchain2/rpc" // [!code highlight] +``` + + \ No newline at end of file diff --git a/content/course/interchain-token-transfer/07-tokens-on-multiple-chains/03-deploy-token-remote.mdx b/content/course/interchain-token-transfer/07-tokens-on-multiple-chains/03-deploy-token-remote.mdx new file mode 100644 index 00000000..951d63fd --- /dev/null +++ b/content/course/interchain-token-transfer/07-tokens-on-multiple-chains/03-deploy-token-remote.mdx @@ -0,0 +1,69 @@ +--- +title: Deploy Token Remote for Multi-hop +description: Deploy and configure the ERC20TokenRemote contract on the second blockchain. +updated: 2024-05-31 +authors: [owenwahlgren] +icon: Book +--- +import { Step, Steps } from 'fumadocs-ui/components/steps'; + + + + +### Deploy the Remote Contract + +Using the [`forge create`](https://book.getfoundry.sh/reference/forge/forge-create) command, we will deploy the `ERC20TokenRemote.sol` contract, passing in the following constructor arguments: + +- Interchain Messaging Registry Address **(for `myblockchain2`)** +- Interchain Messaging Manager (our funded address) +- Source Blockchain ID (hexidecimal representation of Avalanche C-Chain) +- Token Home Address (address of `NativeTokenHome.sol` deployed on Avalanche C-Chain in the [Deploy a Home Contract](/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/03-deploy-home) section) +- Token Name (input in the constructor of the [wrapped token contract](https://github.com/ava-labs/avalanche-interchain-token-transfer/blob/main/contracts/src/WrappedNativeToken.sol)) +- Token Symbol (input in the constructor of the [wrapped token contract](https://github.com/ava-labs/avalanche-interchain-token-transfer/blob/main/contracts/src/WrappedNativeToken.sol)) +- Token Decimals (uint8 integer representing number of decimal places for the ERC20 token being created. Most ERC20 tokens follow the Ethereum standard, which defines 18 decimal places.) + +```bash +forge create --rpc-url myblockchain2 --private-key $PK \ +lib/avalanche-interchain-token-transfer/contracts/src/TokenRemote/ERC20TokenRemote.sol:ERC20TokenRemote \ +--constructor-args "(${TELEPORTER_REGISTRY_CHAIN2}, ${FUNDED_ADDRESS}, ${C_CHAIN_BLOCKCHAIN_ID_HEX}, ${ERC20_HOME_C_CHAIN}, 18)" "TOK" "TOK" 18 +``` + + + + +### Save the Remote Contract Address + +Note the address the remote contract was "Deployed to". + +```bash +export ERC20_TOKEN_REMOTE_CHAIN2=<"Deployed to" address> +``` + + + + +### Register Remote Contract with Home Contract + +After deploying the bridge contracts, you'll need to register the remote bridge by sending a dummy message using the `registerWithHome` method. This message includes details which inform the Home Bridge about your destination blockchain and bridge settings, eg. `initialReserveImbalance`. + +```bash +cast send --rpc-url myblockchain2 --private-key $PK $ERC20_TOKEN_REMOTE_CHAIN2 \ +"registerWithHome((address, uint256))" "(0x0000000000000000000000000000000000000000, 0)" +``` + + + + +### Approve tokens for the Token Remote contract on `myblockchain` +Now that our `ERC20TokenRemote` contract is deployed and configured on `myblockchain2`, we need to prepare `myblockchain` for the token transfer. +We will approve the `ERC20TokenRemote` contract to spend a certain amount of tokens on behalf of the sender. + +You can increase/decrease the numbers here as per your requirements. (All values are mentioned in wei) + +```bash +cast send --rpc-url myblockchain --private-key $PK $ERC20_TOKEN_REMOTE_L1 \ +"approve(address, uint256)" $ERC20_TOKEN_REMOTE_L1 2000000000000000000000 +``` + + + diff --git a/content/course/interchain-token-transfer/07-tokens-on-multiple-chains/04-multihop.mdx b/content/course/interchain-token-transfer/07-tokens-on-multiple-chains/04-multihop.mdx new file mode 100644 index 00000000..a9becd69 --- /dev/null +++ b/content/course/interchain-token-transfer/07-tokens-on-multiple-chains/04-multihop.mdx @@ -0,0 +1,41 @@ +--- +title: Multi-hop Transfer +description: Perform the multi-hop transfer of `TOK` from `myblockchain` to `myblockchain2`, with a 'hop' through the Avalanche C-Chain. +updated: 2024-05-31 +authors: [owenwahlgren] +icon: Book +--- + +import { Step, Steps } from 'fumadocs-ui/components/steps'; + + + + +### Transfer the Token Cross-chain with a Multi-hop Transfer + +Now that all the bridge contracts have been deployed and configured, send the ERC-20 token from `myblockchain` to `myblockchain2` with the [`cast send`](https://book.getfoundry.sh/reference/cast/cast-send) foundry command. + +The token will be routed through the Avalanche C-Chain and then to `myblockchain2`. + +```bash +cast send --rpc-url myblockchain --private-key $PK $ERC20_TOKEN_REMOTE_L1 \ +"send((bytes32, address, address, address, uint256, uint256, uint256, address), uint256)" \ +"(${SOURCE_BLOCKCHAIN2_ID_HEX}, ${ERC20_TOKEN_REMOTE_CHAIN2}, ${FUNDED_ADDRESS}, ${ERC20_C_CHAIN}, 0, 0, 250000, ${FUNDED_ADDRESS})" 500000000000000 +``` + + + + +### Check Balance + +To confirm the token was bridged from `myblockchain1` to `myblockchain2` via the C-Chain, we will check the recipient's balance on `myblockchain2` with the [`cast call`](https://book.getfoundry.sh/reference/cast/cast-call?highlight=cast%20call#cast-call) foundry command: + +```bash +cast call --rpc-url myblockchain2 $ERC20_TOKEN_REMOTE_CHAIN2 "balanceOf(address)(uint)" $FUNDED_ADDRESS +``` + +```bash +500000000000000 [5e14] +``` + + diff --git a/content/course/interchain-token-transfer/meta.json b/content/course/interchain-token-transfer/meta.json index 7de0102c..60746786 100644 --- a/content/course/interchain-token-transfer/meta.json +++ b/content/course/interchain-token-transfer/meta.json @@ -15,6 +15,8 @@ "...05-avalanche-interchain-token-transfer", "---ERC-20 to ERC-20 Token Bridge---", "...06-erc-20-to-erc-20-bridge", + "---ERC-20 Multi-Hop Transfer---", + "...07-tokens-on-multiple-chains", "---Send and Call---", "...12-send-and-call", "---Cross-Chain Token Swaps---",