From 6b38250be08054d7c556b0d7f91f55936bdbcb1b Mon Sep 17 00:00:00 2001 From: Lion <54601286+0xstt@users.noreply.github.com> Date: Fri, 6 Sep 2024 22:30:57 +0300 Subject: [PATCH 1/2] Fix document content tracker (#114) --- components/tracker.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/tracker.tsx b/components/tracker.tsx index d5d82da9..2f4816cf 100644 --- a/components/tracker.tsx +++ b/components/tracker.tsx @@ -51,7 +51,7 @@ const IndexedDBComponent: React.FC = () => { getAllRequest.onsuccess = function (event: any) { const paths = event.target.result as { path: string }[]; paths.forEach(item => { - const sidebarItem = document.querySelector(`a[href="${item.path}"]`); + const sidebarItem = document.querySelector(`aside a[href="${item.path}"]`); if (sidebarItem) { // Check if a checkmark already exists From 170071762735fbf1ad46fc6735a3f3d3946e809a Mon Sep 17 00:00:00 2001 From: Owen Date: Sat, 7 Sep 2024 00:41:42 +0400 Subject: [PATCH 2/2] fix: erc20 to erc20 ictt bridge chapter (#111) --- .../common/avalanche-ictt/erc20erc20cli.mdx | 215 ----------------- .../common/avalanche-ictt/setup-manual.mdx | 108 --------- .../01-erc-20-to-erc-20-bridge.mdx | 80 +++++-- .../02-deploy-erc-20-token.mdx | 4 +- .../03-deploy-home.mdx | 4 +- .../04-deploy-remote.mdx | 56 +++-- .../05-test-transfer.mdx | 4 +- .../06-deploy-with-avalanche-cli.mdx | 170 +++++++++++++ .../07-avacloud-and-core-bridge.mdx | 38 +++ .../X-deploy-with-avalanche-cli.mdx | 223 ------------------ .../01-native-to-erc-20-bridge.mdx | 2 +- public/course-images/ictt/core-bridge.png | Bin 0 -> 124724 bytes 12 files changed, 308 insertions(+), 596 deletions(-) delete mode 100644 content/common/avalanche-ictt/erc20erc20cli.mdx delete mode 100644 content/common/avalanche-ictt/setup-manual.mdx create mode 100644 content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/06-deploy-with-avalanche-cli.mdx create mode 100644 content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/07-avacloud-and-core-bridge.mdx delete mode 100644 content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/X-deploy-with-avalanche-cli.mdx create mode 100644 public/course-images/ictt/core-bridge.png diff --git a/content/common/avalanche-ictt/erc20erc20cli.mdx b/content/common/avalanche-ictt/erc20erc20cli.mdx deleted file mode 100644 index 016b6ca0..00000000 --- a/content/common/avalanche-ictt/erc20erc20cli.mdx +++ /dev/null @@ -1,215 +0,0 @@ -## Transfer an ERC20 Token to an Avalanche L1 as an ERC20 Token - -The following example will show you how to send an ERC20 Token on C-chain to an Avalanche L1 as an ERC20 token using Interchain Messaging and Foundry. This demo is conducted on a local network run by the CLI, but can be applied to Fuji Testnet and Avalanche Mainnet directly. - -**All Avalanche Interchain Token Transfer contracts and interfaces implemented in this example implementation are maintained in the [avalanche-interchain-token-transfer](https://github.com/ava-labs/avalanche-interchain-token-transfer/tree/main/contracts/src) repository.** - -If you prefer full end-to-end testing written in Golang for bridging ERC20s, native tokens, or any combination of the two, you can view the test workflows directly in the [avalanche-interchain-token-transfer](https://github.com/ava-labs/avalanche-interchain-token-transfer/tree/main/tests/flows) repository. - -Deep dives on each template interface can be found [here](https://github.com/ava-labs/avalanche-interchain-token-transfer/blob/main/contracts/README.md). - -_Disclaimer: The avalanche-interchain-token-transfer contracts used in this tutorial are under active development and are not yet intended for production deployments. Use at your own risk._ - -## What we have to do - -1. Codespace Environment Setup -2. Create a blockchain and deploy on it on local network -3. Deploy an ERC20 Contract on C-chain -4. Deploy the Avalanche Interchain Token Transfer Contracts on C-chain and your blockchain -5. Start Sending Tokens - -## Environment Setup - -### Run on Github Codespace - -You can run them directly on Github by clicking **Code**, switching to the **Codespaces** tab and clicking **Create codespace on main**. A new window will open that loads the codespace. Afterwards you will see a browser version of VS code with all the dependencies installed. Codespace time out after some time of inactivity, but can be restarted. - -## Local Network Environment - -For convenience the private key `56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027` of the default airdrop address is stored in the environment variable `$PK` in `.devcontainer/devcontainer.json`. Furthermore, the RPC url for the C-Chain `local-c` and Avalanche L1 created with the name `myblockchain` on the local network is set in the `foundry.toml` file. - -### Avalanche L1 Configuration and Deployment - -To get started, create an Avalanche L1 configuration named "myblockchain": - -```bash -avalanche blockchain create myblockchain -``` - -Your Avalanche L1 should have the following things: - -- Interchain Messaging enabled -- CLI should run an AWM Relayer -- Upon Avalanche L1 deployment, 100 tokens should be airdropped to the default ewoq address (0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC) - -```bash -✔ Avalanche L1-EVM -✔ Use latest release version -✔ Yes -✔ Yes -Installing subnet-evm-v0.6.6... -subnet-evm-v0.6.6 installation successful -creating genesis for subnet myblockchain -Enter your subnet's ChainId. It can be any positive integer. -ChainId: 123 -Select a symbol for your subnet's native token -Token symbol: NAT -✔ Low disk use / Low Throughput 1.5 mil gas/s (C-Chain's setting) -✔ Airdrop 1 million tokens to the default ewoq address (do not use in production) -prefunding address 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC with balance 1000000000000000000000000 -✔ No -✓ Successfully created subnet configuration -``` - -Finally, deploy your Avalanche L1: - -```bash -avalanche blockchain deploy myblockchain -``` - -```bash -? Choose a network for the operation: -✔ Local Network -Deploying [myblockchain] to Local Network -``` - -The CLI will output addresses and information that will be important for the rest of the tutorial: - -```bash -Deploying Blockchain. Wait until network acknowledges... - -Teleporter Messenger successfully deployed to c-chain (0x253b2784c75e510dD0fF1da844684a1aC0aa5fcf) -Interchain Messaging Registry successfully deployed to c-chain (0x17aB05351fC94a1a67Bf3f56DdbB941aE6c63E25) - -Teleporter Messenger successfully deployed to myblockchain (0x253b2784c75e510dD0fF1da844684a1aC0aa5fcf) -Interchain Messaging Registry successfully deployed to myblockchain (0x73b1dB7E9923c9d8fd643ff381e74dd9618EA1a5) - -using awm-relayer version (v1.3.3) -Installing AWM-Relayer v1.3.3 -Executing AWM-Relayer... - - - -Browser Extension connection details (any node URL from above works): -RPC URL: http://127.0.0.1:9650/ext/bc/2u9Hu7Noja3Z1kbZyrztTMZcDeqb6acwyPyqP4BbVDjoT8ZaYc/rpc -Codespace RPC URL: https://organic-palm-tree-ppr5xxg7xvv2974r-9650.app.github.dev/ext/bc/2u9Hu7Noja3Z1kbZyrztTMZcDeqb6acwyPyqP4BbVDjoT8ZaYc/rpc -Funded address: 0x69AD03393144008463beD1DcB3FD33eb9A7081ba with 600 (10^18) -Funded address: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC with 1000000 (10^18) - private key: 56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027 -Network name: myblockchain -Chain ID: 123 -Currency Symbol: NAT -``` - -From this output, take note of the Funded Address (with 100 tokens) and set the parameter as environment variable so that we can manage them easily and also use them in the commands later. - -```bash -export FUNDED_ADDRESS= -``` - -## Deploy ERC20 Contract on C-chain - -First step is to deploy the ERC20 contract. We are using OZs example contract here and the contract is renamed to `ERC20.sol` for convenience. You can use any other pre deployed ERC20 contract or change the names according to your Avalanche L1 native token as well. - -```bash -forge create --rpc-url local-c --private-key $PK src/8-erc20-to-erc20-interchain-token-transfer/ERC20.sol:TOK -``` - -Now, make sure to add the contract address in the environment variables. - -```bash -export ERC20_HOME_C_CHAIN=<"Deployed to" address> -``` - -If you deployed the above example contract, you should see a balance of 100,000 tokens when you run the below command: - -```bash -cast call --rpc-url local-c --private-key $PK $ERC20_HOME_C_CHAIN "balanceOf(address)(uint)" $FUNDED_ADDRESS -``` - -## Deploy Avalanche Interchain Token Transfer Contracts - -We will deploy two Interchain Token Transfer contracts. One of the source chain (which is C-chain in our case) and another on the destination chain (myblockchain in our case). This will be done by a single command with the Avalanche CLI - -```bash -avalanche interchain tokenTransferrer deploy -``` -Go - -```bash -✔ Local Network -✔ C-Chain -✔ Deploy a new Home for the token -✔ An ERC-20 token -Enter the address of the ERC-20 Token: 0x5DB9A7629912EBF95876228C24A848de0bfB43A9 -✔ Avalanche L1 myblockchain -Downloading Avalanche InterChain Token Transfer Contracts -Compiling Avalanche InterChain Token Transfer - -Home Deployed to http://127.0.0.1:9650/ext/bc/C/rpc -Home Address: 0x4Ac1d98D9cEF99EC6546dEd4Bd550b0b287aaD6D - -Remote Deployed to http://127.0.0.1:9650/ext/bc/2u9Hu7Noja3Z1kbZyrztTMZcDeqb6acwyPyqP4BbVDjoT8ZaYc/rpc -Remote Address: 0x0D189a705c1FFe77F1bF3ee834931b6b9B356c05 -``` - -Save the Remote contract address in the environment variables. - -```bash -export ERC20_REMOTE_SUBNET=<"Remote address"> -``` - -## Get Balances - -Before transfering some funds Cross-Chain, check the current balances of both the ERC20 Home token and the Remote one. - -```bash -avalanche key list --local --keys ewoq --blockchains c,myblockchain --tokens $ERC20_HOME_C_CHAIN,$ERC20_REMOTE_SUBNET -``` - -```bash -+--------+------+---------+--------------------------------------------+---------------+------------------+---------------+ -| KIND | NAME | SUBNET | ADDRESS | TOKEN | BALANCE | NETWORK | -+--------+------+---------+--------------------------------------------+---------------+------------------+---------------+ -| stored | ewoq | myblockchain | 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC | TOK (0x0D18.)| 0 | Local Network | -+ + +----------+--------------------------------------------+---------------+-----------------+---------------+ -| | | C-Chain | 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC | TOK (0x5DB9.)| 100000.000000000 | Local Network | -+--------+------+----------+--------------------------------------------+---------------+-----------------+---------------+ -``` - -## Transfer the Token Cross-chain - -Now that the Avalanche Interchain Token Transfer contracts have been deployed, transfer some ERC20 tokens TOK from C-Chain to _myblockchain_ with the following command - -```bash -avalanche key transfer -``` - -``` -✔ Local Network -✔ C-Chain -✔ Avalanche L1 myblockchain -Enter the address of the Token Transferrer on c-chain: 0x4Ac1d98D9cEF99EC6546dEd4Bd550b0b287aaD6D -Enter the address of the Token Transferrer on myblockchain: 0x0D189a705c1FFe77F1bF3ee834931b6b9B356c05 -✔ ewoq -✔ Key -✔ ewoq -Amount to send (TOKEN units): 100 -``` - -## Get New Balances - -Before transfering some funds Cross-Chain, check the current balances of both the ERC20 Home token and the Remote one. - -```bash -avalanche key list --local --keys ewoq --subnets c,myblockchain --tokens $ERC20_HOME_C_CHAIN,$ERC20_REMOTE_SUBNET -``` - -```bash -+--------+------+----------+--------------------------------------------+---------------+-----------------+---------------+ -| KIND | NAME | SUBNET | ADDRESS | TOKEN | BALANCE | NETWORK | -+--------+------+----------+--------------------------------------------+---------------+-----------------+---------------+ -| stored | ewoq | myblockchain | 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC | TOK (0x0D18.) | 100.000000000 | Local Network | -+ + +----------+--------------------------------------------+---------------+-----------------+---------------+ -| | | C-Chain | 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC | TOK (0x5DB9.) | 99900.000000000 | Local Network | -+--------+------+----------+--------------------------------------------+---------------+-----------------+---------------+ -``` diff --git a/content/common/avalanche-ictt/setup-manual.mdx b/content/common/avalanche-ictt/setup-manual.mdx deleted file mode 100644 index 537d2421..00000000 --- a/content/common/avalanche-ictt/setup-manual.mdx +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: ERC-20 to ERC-20 Bridge -description: TBD -updated: 2024-05-31 -authors: [ashucoder9] -icon: Book ---- - - -## Local Network Environment - -For convenience the private key `56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027` of the default airdrop address is stored in the environment variable `$PK` in `.devcontainer/devcontainer.json` of the Starter-kit. Furthermore, the RPC url for the C-Chain `local-c` and the Avalanche L1 with the name `myblockchain` on the local network is set in the `foundry.toml` file. - -### Avalanche L1 Configuration and Deployment - -To get started, create an Avalanche L1 configuration named "myblockchain": - -```bash -avalanche blockchain create myblockchain -``` - -Your Avalanche L1 should have the following things: - -- Interchain Messaging enabled -- CLI should run an AWM Relayer -- Upon Avalanche L1 deployment, 100 tokens should be airdropped to the default ewoq address (0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC) -- Native Minter Precompile enabled with either your admin address or the pre-computed Remote token address - -_Note: If you have created your Avalanche L1 using AvaCloud, you can add Remote Token address [using the dashboard](https://support.avacloud.io/avacloud-how-do-i-use-the-native-token-minter)._ - -```bash -✔ Avalanche L1-EVM -✔ Use latest release version -✔ Yes -✔ Yes -creating genesis for subnet myblockchain -Enter your subnet's ChainId. It can be any positive integer. -ChainId: 123 -Select a symbol for your subnet's native token -Token symbol: NAT -✔ Low disk use / Low Throughput 1.5 mil gas/s (C-Chain's setting) -✔ Customize your airdrop -Address to airdrop to: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC -Amount to airdrop (in NAT units): 100 -✔ No -✔ Yes -✔ Native Minting -✔ Add -Enter Address : 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC -✔ Done -✔ Done -✔ Done -✔ No -✓ Successfully created subnet configuration -``` - -Finally, deploy your Avalanche L1: - -```bash -avalanche blockchain deploy myblockchain -``` - -```bash -? Choose a network for the operation: -✔ Local Network -Deploying [myblockchain] to Local Network -``` - -The CLI will output addresses and information that will be important for the rest of the tutorial: - -```bash -Deploying Blockchain. Wait until network acknowledges... - -Teleporter Messenger successfully deployed to c-chain (0x253b2784c75e510dD0fF1da844684a1aC0aa5fcf) -Interchain Messaging Registry successfully deployed to c-chain (0x17aB05351fC94a1a67Bf3f56DdbB941aE6c63E25) - -Teleporter Messenger successfully deployed to myblockchain (0x253b2784c75e510dD0fF1da844684a1aC0aa5fcf) -Interchain Messaging Registry successfully deployed to myblockchain (0x73b1dB7E9923c9d8fd643ff381e74dd9618EA1a5) - -using awm-relayer version (v1.3.0) -Executing AWM-Relayer... - - - -Browser Extension connection details (any node URL from above works): -RPC URL: http://127.0.0.1:9650/ext/bc/bFjwbbhaSCotYtdZTPDrQwZn8uVqRoL7YbZxCxXY94k7Qhf3E/rpc -Codespace RPC URL: https://humble-cod-j4prxq655qpcpw96-9650.app.github.dev/ext/bc/bFjwbbhaSCotYtdZTPDrQwZn8uVqRoL7YbZxCxXY94k7Qhf3E/rpc -Funded address: 0x834E891749c29d1417f4501B72945B72224d10dB with 600 (10^18) -Funded address: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC with 100 (10^18) - private key: 56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027 -Network name: myblockchain -Chain ID: 123 -Currency Symbol: NAT -``` - -From this output, take note of the following parameters - -- Funded Address (with 100 tokens), -- Interchain Messaging Registry on C-chain, and -- Interchain Messaging Registry on Avalanche L1 - -Set these parameters as environment variables so that we can manage them easily and also use them in the commands later. - -```bash -export FUNDED_ADDRESS= -export TELEPORTER_REGISTRY_C_CHAIN= -export TELEPORTER_REGISTRY_SUBNET= -``` - diff --git a/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/01-erc-20-to-erc-20-bridge.mdx b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/01-erc-20-to-erc-20-bridge.mdx index 613d9beb..32d64a9b 100644 --- a/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/01-erc-20-to-erc-20-bridge.mdx +++ b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/01-erc-20-to-erc-20-bridge.mdx @@ -5,27 +5,79 @@ updated: 2024-05-31 authors: [ashucoder9] icon: Book --- +import { Step, Steps } from 'fumadocs-ui/components/steps'; +import Link from 'next/link'; +import { cn } from '@/utils/cn'; +import { buttonVariants } from '@/components/ui/button.tsx' -import ICTTsetup from "@/content/common/avalanche-ictt/setup-manual.mdx"; +## Transfer an ERC-20 Token → Avalanche L1 as an ERC-20 Token -## Transfer an ERC20 Token → Avalanche L1 as an ERC-20 Token +This chapter will show you how to send an ERC-20 Token on C-Chain to an Avalanche L1 using Interchain Messaging and Foundry. This demo is conducted on a local network, but can be applied to Fuji Testnet and Avalanche Mainnet directly. -The following example will show you how to send an ERC20 Token on C-chain to an Avalanche L1 using Interchain Messaging and Foundry. This demo is conducted on a local network, but can be applied to Fuji Testnet and Avalanche Mainnet directly. - -**All Avalanche Interchain Token Transfer contracts and interfaces implemented in this example implementation are maintained in the [avalanche-interchain-token-transfer](https://github.com/ava-labs/avalanche-interchain-token-transfer/tree/main/contracts/src) repository.** - -If you prefer full end-to-end testing written in Golang for bridging ERC20s, native tokens, or any combination of the two, you can view the test workflows directly in the [avalanche-interchain-token-transfer](https://github.com/ava-labs/avalanche-interchain-token-transfer/tree/main/tests/flows) repository. +**All Avalanche Interchain Token Transfer contracts and interfaces implemented in this chapter implementation are maintained in the [`avalanche-interchain-token-transfer`](https://github.com/ava-labs/avalanche-interchain-token-transfer/tree/main/contracts/src) repository.** Deep dives on each template interface can be found [here](https://github.com/ava-labs/avalanche-interchain-token-transfer/blob/main/contracts/README.md). _Disclaimer: The avalanche-interchain-token-transfer contracts used in this tutorial are under active development and are not yet intended for production deployments. Use at your own risk._ -## What we have to do +## What we will do + +1. Deploy an ERC-20 Contract on C-Chain +2. Deploy the Interchain Token Transferer Contracts on C-Chain and Avalanche L1 +3. Register Remote Token contract with the Home Transferer contract +4. Add Collateral and Start Sending Tokens + +## Setup + + +## Configuration and Deployment +### Run on Github Codespace + +The best way to follow along is using Github Codespaces. Click on the button below to open the repository in a Codespace. + +Open Avalanche Starter Kit + +### Create a Codespace +- Click the green **Code** button +- Switch to the **Codespaces** tab +- Click **Create Codespace on main** or if you already have a Codespace click the plus (**+**) button + +The Codespace will open in a new tab. Wait a few minutes until it's fully built. + +This ensures that all the dependencies are pre-installed and the environment is ready to use. +Ensure your blockchain is spun up and running. If not, [follow the create blockchain documentation.](/course/interchain-token-transfer/02-avalanche-starter-kit/03-create-blockchain) + + +### Fetch the `Teleporter Registry` address from the Avalanche L1 and set it as an environment variable. + +```bash +avalanche blockchain describe myblockchain +``` + +```bash ++-------------------------------------------------------------------------------------------+ +| TELEPORTER | ++---------------+------------------------------+--------------------------------------------+ +| Local Network | Teleporter Messenger Address | 0x253b2784c75e510dD0fF1da844684a1aC0aa5fcf | +| +------------------------------+--------------------------------------------+ +| | Teleporter Registry Address | 0x82EeEf8e31D4Bf95916219D7949D66c468Ac0681 | ++---------------+------------------------------+--------------------------------------------+ +``` + + +### Export `Teleporter Registry Address` as environment variable. + +Most other environment variables we will need are already set in the devcontainer. +```bash +export TELEPORTER_REGISTRY_L1=0x82EeEf8e31D4Bf95916219D7949D66c468Ac0681 +``` + + -1. Create an Avalanche L1 and Deploy on Local Network -2. Deploy an ERC20 Contract on C-chain -3. Deploy the Interchain Token Transferer Contracts on C-chain and Avalanche L1 -4. Register Remote Token with Home Transferer -5. Add Collateral and Start Sending Tokens - diff --git a/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/02-deploy-erc-20-token.mdx b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/02-deploy-erc-20-token.mdx index 05215080..12c0a384 100644 --- a/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/02-deploy-erc-20-token.mdx +++ b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/02-deploy-erc-20-token.mdx @@ -25,7 +25,7 @@ forge create --rpc-url local-c --private-key $PK src/8-erc20-to-erc20-interchain ### Save the ERC-20 Address ```bash -export ERC20_HOME_C_CHAIN=<"Deployed to" address> +export ERC20_C_CHAIN=<"Deployed to" address> ``` @@ -36,7 +36,7 @@ export ERC20_HOME_C_CHAIN=<"Deployed to" address> If you deployed the above example contract, you should see a balance of 100,000 tokens when you run the below command: ```bash -cast call --rpc-url local-c --private-key $PK $ERC20_HOME_C_CHAIN "balanceOf(address)(uint)" $FUNDED_ADDRESS +cast call --rpc-url local-c --private-key $PK $ERC20_C_CHAIN "balanceOf(address)(uint)" $FUNDED_ADDRESS ``` diff --git a/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/03-deploy-home.mdx b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/03-deploy-home.mdx index 0fafee27..9478aed9 100644 --- a/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/03-deploy-home.mdx +++ b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/03-deploy-home.mdx @@ -16,7 +16,7 @@ We will deploy two Avalanche Interchain Token Transfer contracts. One of the sou ### Deploy ERC20Home Contract ```bash -forge create --rpc-url local-c --private-key $PK lib/avalanche-interchain-token-transfer/contracts/src/TokenHome/ERC20TokenHome.sol:ERC20TokenHome --constructor-args $TELEPORTER_REGISTRY_C_CHAIN $FUNDED_ADDRESS $ERC20_HOME_C_CHAIN 18 +forge create --rpc-url local-c --private-key $PK lib/avalanche-interchain-token-transfer/contracts/src/TokenHome/ERC20TokenHome.sol:ERC20TokenHome --constructor-args $TELEPORTER_REGISTRY_C_CHAIN $FUNDED_ADDRESS $ERC20_C_CHAIN 18 ``` @@ -25,7 +25,7 @@ forge create --rpc-url local-c --private-key $PK lib/avalanche-interchain-token- ### Save the ERC-20 Home Address ```bash -export ERC20_HOME_TRANSFERER_C_CHAIN=<"Deployed to" address> +export ERC20_HOME_C_CHAIN=<"Deployed to" address> ``` diff --git a/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/04-deploy-remote.mdx b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/04-deploy-remote.mdx index 2d24ba3d..4e5fadaa 100644 --- a/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/04-deploy-remote.mdx +++ b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/04-deploy-remote.mdx @@ -20,37 +20,35 @@ First, get the `Source Blockchain ID` in hexidecimal format, which in this examp ```bash avalanche blockchain describe myblockchain ``` - -`Source Blockchain ID` is in the field: `Local Network BlockchainID (HEX)`. - - - - -### Save the Source Blockchain ID - ```bash -export SOURCE_BLOCKCHAIN_ID_HEX=0x4d569bf60a38e3ab3e92afd016fe37f7060d7d63c44e3378f42775bf82a7642d -``` ++---------------------------------------------------------------------------------------------------------------+ +| MYBLOCKCHAIN | ++---------------+-----------------------------------------------------------------------------------------------+ +| Name | myblockchain | ++---------------+-----------------------------------------------------------------------------------------------+ +| VM ID | qDNV9vtxZYYNqm7TN1mYBuaaknLdefDbFK8bFmMLTJQJKaWjV | ++---------------+-----------------------------------------------------------------------------------------------+ +| VM Version | v0.6.9 | ++---------------+--------------------------+--------------------------------------------------------------------+ +| Local Network | ChainID | 1 | +| +--------------------------+--------------------------------------------------------------------+ +| | SubnetID | 2AKbBT8jFUfUsUJ2hhRiDUnAAajJdNhTKeNgEe3q77spMj1N8F | +| +--------------------------+--------------------------------------------------------------------+ +| | Owners (Threhold=1) | P-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p | +| +--------------------------+--------------------------------------------------------------------+ +| | BlockchainID (CB58) | 2EzvQgth5D5aZ81gmF13TsA61c2zduHWqszYPVvzzvRWZXcQgA | +| +--------------------------+--------------------------------------------------------------------+ +| | BlockchainID (HEX) | 0xa37b5143f12ecf020ec893e4a8f48159e470b47fd9ff293ab0a808be47a4f67c | ++---------------+--------------------------+--------------------------------------------------------------------+ - - - -### Get the Destination Blockchain ID - -```bash -avalanche primary describe ``` - -`Destination Blockchain ID` is in the field: `BlockchainID (HEX)`. - - -### Save the Destination Blockchain ID +### Save the Source Blockchain ID ```bash -export C_CHAIN_BLOCKCHAIN_ID_HEX=0x55e1fcfdde01f9f6d4c16fa2ed89ce65a8669120a86f321eef121891cab61241 +export SOURCE_BLOCKCHAIN_ID_HEX= ``` @@ -58,19 +56,19 @@ export C_CHAIN_BLOCKCHAIN_ID_HEX=0x55e1fcfdde01f9f6d4c16fa2ed89ce65a8669120a86f3 ### Deploy the Remote Contract -Using the [`forge create`](https://book.getfoundry.sh/reference/forge/forge-create) command, we will deploy the [ERC20Remote.sol](./NativeTokenHome.sol] contract, passing in the following constructor arguments: +Using the [`forge create`](https://book.getfoundry.sh/reference/forge/forge-create) command, we will deploy the `ERC20Remote.sol` contract, passing in the following constructor arguments: - Interchain Messaging Registry Address **(for C-Chain)** - Interchain Messaging Manager (our funded address) - Source Blockchain ID (hexidecimal representation of our Avalanche L1's Blockchain ID) -- Token Home Address (address of NativeTokenHome.sol deployed on Avalanche L1 in the last step) +- Token Home Address (address of `ERC20TokenHome.sol` deployed on Avalanche L1 in the last step) - Token Name (input in the constructor of the [wrapped token contract](./ExampleWNATV.sol)) - Token Symbol (input in the constructor of the [wrapped token contract](./ExampleWNATV.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 myblockchain --private-key $PK lib/teleporter-token-bridge/contracts/src/TokenRemote/ERC20TokenRemote.sol:ERC20TokenRemote \ ---constructor-args "(${TELEPORTER_REGISTRY_SUBNET}, ${FUNDED_ADDRESS}, ${C_CHAIN_BLOCKCHAIN_ID_HEX}, ${ERC20_HOME_BRIDGE_C_CHAIN})" "TOK" "TOK" 18 +forge create --rpc-url myblockchain --private-key $PK lib/avalanche-interchain-token-transfer/contracts/src/TokenRemote/ERC20TokenRemote.sol:ERC20TokenRemote \ +--constructor-args "(${TELEPORTER_REGISTRY_L1}, ${FUNDED_ADDRESS}, ${C_CHAIN_BLOCKCHAIN_ID_HEX}, ${ERC20_HOME_C_CHAIN}, 18)" "TOK" "TOK" 18 ``` @@ -92,7 +90,7 @@ export ERC20_TOKEN_REMOTE_L1=<"Deployed to" address> 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 myblockchain --private-key $PK $ERC20_TOKEN_REMOTE_SUBNET "registerWithHome((address, uint256))" "(0x0000000000000000000000000000000000000000, 0)" +cast send --rpc-url myblockchain --private-key $PK $ERC20_TOKEN_REMOTE_L1 "registerWithHome((address, uint256))" "(0x0000000000000000000000000000000000000000, 0)" ``` @@ -103,7 +101,7 @@ cast send --rpc-url myblockchain --private-key $PK $ERC20_TOKEN_REMOTE_SUBNET "r You can increase/decrease the numbers here as per your requirements. (All values are mentioned in wei) ```bash -cast send --rpc-url local-c --private-key $PK $ERC20_HOME_C_CHAIN "approve(address, uint256)" $ERC20_HOME_BRIDGE_C_CHAIN 2000000000000000000000 +cast send --rpc-url local-c --private-key $PK $ERC20_C_CHAIN "approve(address, uint256)" $ERC20_HOME_C_CHAIN 2000000000000000000000 ``` diff --git a/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/05-test-transfer.mdx b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/05-test-transfer.mdx index 0d9f36c2..d077de04 100644 --- a/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/05-test-transfer.mdx +++ b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/05-test-transfer.mdx @@ -15,7 +15,7 @@ import { Step, Steps } from 'fumadocs-ui/components/steps'; Now that all the bridge contracts have been deployed, send a native token from your Avalanche L1 to C-Chain with the [`cast send`](https://book.getfoundry.sh/reference/cast/cast-send) foundry command. ```bash -cast send --rpc-url local-c --private-key $PK $ERC20_HOME_BRIDGE_C_CHAIN "send((bytes32, address, address, address, uint256, uint256, uint256, address), uint256)" "(${SUBNET_BLOCKCHAIN_ID_HEX}, ${ERC20_TOKEN_REMOTE_SUBNET}, ${FUNDED_ADDRESS}, ${ERC20_HOME_C_CHAIN}, 0, 0, 250000, 0x0000000000000000000000000000000000000000)" 1000000000000000000000 +cast send --rpc-url local-c --private-key $PK $ERC20_HOME_C_CHAIN "send((bytes32, address, address, address, uint256, uint256, uint256, address), uint256)" "(${SOURCE_BLOCKCHAIN_ID_HEX}, ${ERC20_TOKEN_REMOTE_L1}, ${FUNDED_ADDRESS}, ${ERC20_C_CHAIN}, 0, 0, 250000, 0x0000000000000000000000000000000000000000)" 1000000000000000000000 ``` @@ -26,7 +26,7 @@ cast send --rpc-url local-c --private-key $PK $ERC20_HOME_BRIDGE_C_CHAIN "send(( To confirm the token was bridged from C-Chain to a Avalanche L1, we will check the recipient's balance of wrapped tokens on the Avalanche L1 with the [`cast call`](https://book.getfoundry.sh/reference/cast/cast-call?highlight=cast%20call#cast-call) foundry command: ```bash -cast call --rpc-url myblockchain $ERC20_TOKEN_REMOTE_SUBNET "balanceOf(address)(uint)" $FUNDED_ADDRESS +cast call --rpc-url myblockchain $ERC20_TOKEN_REMOTE_L1 "balanceOf(address)(uint)" $FUNDED_ADDRESS ``` diff --git a/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/06-deploy-with-avalanche-cli.mdx b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/06-deploy-with-avalanche-cli.mdx new file mode 100644 index 00000000..bed8e187 --- /dev/null +++ b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/06-deploy-with-avalanche-cli.mdx @@ -0,0 +1,170 @@ +--- +title: Deploy and Use ICTT with Avalanche CLI +description: Alternative and simplified way to deploy ICTT to transfer ERC-20 to ERC-20 assets +updated: 2024-05-31 +authors: [ashucoder9] +icon: Terminal +--- +import { Step, Steps } from 'fumadocs-ui/components/steps'; +import Link from 'next/link'; +import { cn } from '@/utils/cn'; +import { buttonVariants } from '@/components/ui/button.tsx' + + + +## Transfer an ERC-20 Token to an Avalanche L1 as an ERC-20 Token + +In the previous sections of this chapter we manually deployed and interacted with the Interchain Token Transfer contracts. In this section we will use the Avalanche CLI to deploy the contracts and transfer the tokens. + +## What we will do + +2. Create an Avalanche L1 and Deploy on Local Network +3. Deploy an ERC-20 Contract on C-chain +4. Deploy the Avalanche Interchain Token Transfer Contracts on C-chain and Avalanche L1 +5. Start Sending Tokens + + + + +## Configuration and Deployment +### Run on Github Codespace + +The best way to follow along is using Github Codespaces. Click on the button below to open the repository in a Codespace. + +Open Avalanche Starter Kit + +### Create a Codespace +- Click the green **Code** button +- Switch to the **Codespaces** tab +- Click **Create Codespace on main** or if you already have a Codespace click the plus (**+**) button + +The Codespace will open in a new tab. Wait a few minutes until it's fully built. + +This ensures that all the dependencies are pre-installed and the environment is ready to use. + +Ensure your blockchain is spun up and running. If not, [follow the create blockchain documentation.](/course/interchain-token-transfer/02-avalanche-starter-kit/03-create-blockchain) + + + + + + +## Deploy ERC-20 Contract on C-chain + +Now we will deploy an ERC-20 contract. We are using OpenZeppelin's example contract which has been renamed to `ERC20.sol` for convenience. + +```bash +forge create --rpc-url local-c --private-key $PK src/8-erc20-to-erc20-interchain-token-transfer/ERC20.sol:TOK +``` + +Add the contract address in the environment variables. + +```bash +export ERC20_C_CHAIN=<"Deployed to" address> +``` + +Check your balance using the command below: +```bash +cast call --rpc-url local-c --private-key $PK $ERC20_C_CHAIN "balanceOf(address)(uint)" $FUNDED_ADDRESS +``` +100,000 tokens should be returned. + + + +## Deploy Avalanche Interchain Token Transfer Contracts + +Next we will deploy two Interchain Token Transfer contracts. One for the source chain (C-Chain) and another on the destination chain (myblockchain). + +```bash +avalanche interchain tokenTransferrer deploy +``` + +```bash +✔ Local Network +✔ C-Chain +✔ Deploy a new Home for the token +✔ An ERC-20 token +Enter the address of the ERC-20 Token: 0x5DB9A7629912EBF95876228C24A848de0bfB43A9 +... +Home Deployed to http://127.0.0.1:9650/ext/bc/C/rpc +Home Address: 0x4Ac1d98D9cEF99EC6546dEd4Bd550b0b287aaD6D + +Remote Deployed to http://127.0.0.1:9650/ext/bc/2u9Hu7Noja3Z1kbZyrztTMZcDeqb6acwyPyqP4BbVDjoT8ZaYc/rpc +Remote Address: 0x0D189a705c1FFe77F1bF3ee834931b6b9B356c05 +``` + +Save the Remote contract address in the environment variables. + +```bash +export ERC20_REMOTE_L1=<"Remote address"> +``` + + +## Get Balances + +Before transfering some funds Cross-Chain, check the current balances of both the ERC20 Home token and the Remote one. + +```bash +avalanche key list --local --keys ewoq --blockchains c,myblockchain --tokens $ERC20_C_CHAIN,$ERC20_REMOTE_L1 +``` + +```bash ++--------+------+---------+--------------------------------------------+---------------+------------------+---------------+ +| KIND | NAME | SUBNET | ADDRESS | TOKEN | BALANCE | NETWORK | ++--------+------+---------+--------------------------------------------+---------------+------------------+---------------+ +| stored | ewoq | myblockchain | | TOK (0x0D18.)| 0 | Local Network | ++ + +----------+--------------------------------------------+---------------+-----------------+---------------+ +| | | C-Chain | 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC | TOK (0x5DB9.)| 100000.000000000 | Local Network | ++--------+------+----------+--------------------------------------------+---------------+-----------------+---------------+ +``` + + +## Transfer the Token Cross-chain + +Now that the Avalanche Interchain Token Transfer contracts have been deployed, transfer some ERC20 tokens `TOK` from C-Chain to _myblockchain_ + +```bash +avalanche key transfer +``` + +``` +✔ Local Network +✔ C-Chain +✔ Blockchain myblockchain +Enter the address of the Token Transferrer on c-chain: 0x4Ac1d98D9cEF99EC6546dEd4Bd550b0b287aaD6D +Enter the address of the Token Transferrer on myblockchain: 0x0D189a705c1FFe77F1bF3ee834931b6b9B356c05 +✔ ewoq +✔ Key +✔ ewoq +Amount to send (TOKEN units): 100 +``` + + +## Check Balances + +Now we can check the balances of both the ERC-20 Home token and the Remote one. + +```bash +avalanche key list --local --keys ewoq --blockchains c,myblockchain --tokens $ERC20_C_CHAIN,$ERC20_REMOTE_L1 +``` + +```bash ++--------+------+----------+--------------------------------------------+---------------+-----------------+---------------+ +| KIND | NAME | SUBNET | ADDRESS | TOKEN | BALANCE | NETWORK | ++--------+------+----------+--------------------------------------------+---------------+-----------------+---------------+ +| stored | ewoq | myblockchain | 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC | TOK (0x0D18.) | 100.000000000 | Local Network | ++ + +----------+--------------------------------------------+---------------+-----------------+---------------+ +| | | C-Chain | 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC | TOK (0x5DB9.) | 99900.000000000 | Local Network | ++--------+------+----------+--------------------------------------------+---------------+-----------------+---------------+ +``` + + + + +**Success!** We have transferred 100 tokens from C-Chain to myblockchain using the Avalanche CLI. diff --git a/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/07-avacloud-and-core-bridge.mdx b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/07-avacloud-and-core-bridge.mdx new file mode 100644 index 00000000..594ebc33 --- /dev/null +++ b/content/course/interchain-token-transfer/06-erc-20-to-erc-20-bridge/07-avacloud-and-core-bridge.mdx @@ -0,0 +1,38 @@ +--- +title: AvaCloud, Core and ICTT +description: Learn how to integrate ICTT bridges into the Core Bridge through AvaCloud. +updated: 2024-05-31 +icon: Book +authors: [owenwahlgren] +--- + +## ICTT Bridge Inclusion in Core + +ICTT bridges deployed through [**AvaCloud**](https://avacloud.io/) will automatically integrate into the [**Core Bridge**](https://core.app/en/bridge). This ensures that any bridges created through AvaCloud are available immediately and do not need extra review. + +{/* ![](/course-images/ictt/core-bridge.png) */} + +However, **ICTT bridges** deployed outside of AvaCloud (by third-party developers or other methods) will need to be submitted for manual review. Developers will need to provide: + +1. **Token Bridge Contract Address(es)**: The bridge contract(s) on the L1. +2. **Layer 1 Information**: Name and other key details of the associated L1 blockchain. + +The Core team will review this info to ensure the bridge meets security and compliance standards. This guarantees network reliability while allowing more flexibility. + +### [Community Submission Form](https://forms.gle/jdcKcYWu26CsY6jRA) + +