From 7fcd9a1f141aa4536ea5df046603b69081da50a4 Mon Sep 17 00:00:00 2001 From: owenwahlgren Date: Mon, 9 Sep 2024 16:52:33 -0400 Subject: [PATCH 1/3] native to erc20 bridge chapter rough draft --- .../01-native-to-erc-20-bridge.mdx | 56 ++------ .../02-deploy-wrapped-native.mdx | 120 +++--------------- .../03-bridge-tokens.mdx | 101 --------------- .../03-deploy-native-token-home.mdx | 103 +++++++++++++++ .../04-deploy-erc20-token-remote.mdx | 57 +++++++++ .../05-bridge-tokens.mdx | 36 ++++++ .../x-deploy-with-avalanchecli.mdx | 7 - .../interchain-token-transfer/meta.json | 2 + 8 files changed, 229 insertions(+), 253 deletions(-) delete mode 100644 content/course/interchain-token-transfer/08-native-to-erc-20-bridge/03-bridge-tokens.mdx create mode 100644 content/course/interchain-token-transfer/08-native-to-erc-20-bridge/03-deploy-native-token-home.mdx create mode 100644 content/course/interchain-token-transfer/08-native-to-erc-20-bridge/04-deploy-erc20-token-remote.mdx create mode 100644 content/course/interchain-token-transfer/08-native-to-erc-20-bridge/05-bridge-tokens.mdx delete mode 100644 content/course/interchain-token-transfer/08-native-to-erc-20-bridge/x-deploy-with-avalanchecli.mdx diff --git a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/01-native-to-erc-20-bridge.mdx b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/01-native-to-erc-20-bridge.mdx index 98b02a1d..7fafe4f0 100644 --- a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/01-native-to-erc-20-bridge.mdx +++ b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/01-native-to-erc-20-bridge.mdx @@ -1,49 +1,17 @@ --- -title: Native to ERC-20 Token Bridge -description: TBD -updated: 2024-05-31 -authors: [ashucoder9] +title: Native to ERC-20 Token Bridge Overview +description: Learn how to transfer native Avalanche L1 tokens to the C-Chain as ERC-20 tokens. +updated: 2024-09-09 +authors: [owenwahlgren] icon: Book --- -import ICTTsetup from "@/content/common/avalanche-starter-kit/create-default-blockchain.mdx"; - - -## Bridge a Avalanche L1's Native Token to the C-Chain - -The following code example will show you how to send a Avalanche L1's native token to the C-Chain 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 token bridge contracts and interfaces implemented in this example implementation are maintained in the [teleporter-token-bridge](https://github.com/ava-labs/teleporter-token-bridge/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 [teleporter-token-bridge](https://github.com/ava-labs/teleporter-token-bridge/tree/main/tests/flows) repository. - -Deep dives on each template interface can be found [here](https://github.com/ava-labs/teleporter-token-bridge/blob/main/contracts/README.md). - -_Disclaimer: The teleporter-token-bridge 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. Create an Avalanche L1 and Deploy on Local Network -2. Deploy Wrapped Native Token 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 - - - -## Parameter Management - -As you deploy the teleporter contracts, keeping track of their addresses will make testing and troubleshooting much easier. The parameters you should keep track of include: - -| Parameter | Network | Description | -| :---------------------------- | :------ | :-------------------------------------------------------------------------------------------------------------------------------------------------- | -| Funded Address (with 1000000) | Both | The public address you use to deploy contracts, and send tokens through the bridge. Used as the `teleporterManager` constructor parameter in this example. | -| Interchain Messaging Registry | C-Chain | Address of the TeleporterRegistry contract on C-Chain deployed by the CLI | -| Interchain Messaging Registry | Avalanche L1 | Address of the TeleporterRegistry contract on Avalanche L1 deployed by the CLI | -| Wrapped Native Token | Avalanche L1 | Address of the wrapped token contract for your Avalanche L1's native token to be deployed on the Avalanche L1 | -| Native Token Home | Avalanche L1 | Address of the bridge's Home contract to be deployed on the Avalanche L1 | -| ERC20 Remote | C-Chain | Address of the bridge's remote contract to be deployed on the C-Chain | -| Avalanche L1 Blockchain ID | Avalanche L1 | Hexadecimal representation of the Avalanche L1's Blockchain ID. Returned by `avalanche subnet describe `. | -| C-Chain Blockchain ID | C-Chain | Hexadecimal representation of the C-Chain's Blockchain ID on the selected network. Returned by `avalanche primary describe`. | - +ICTT is also capable of bridging native tokens from Avalanche L1s to the C-Chain as ERC-20 tokens. This process involves deploying a `NativeTokenHome` contract on the Avalanche L1, and a `ERC20TokenRemote` contract on the C-Chain. The `NativeTokenHome` contract will be used to bridge the native token to the C-Chain as an ERC-20 token. +This example will cover native to ERC-20 token bridging between `myblockchain` and the C-Chain, but the process can be adapted to bridge the C-Chain's native asset, `AVAX`, to any L1 as an ERC-20 token. +### What we will do +1. Deploy a Wrapped Native Token to `myblockchain` +2. Deploy the `NativeTokenHome` contract on `myblockchain` +3. Deploy the `ERC20TokenRemote` contract on the C-Chain +4. Register `ERC20TokenRemote` on C-Chain with `NativeTokenHome` on `myblockchain` +4. Perform a transfer of the native token on `myblockchain` to the C-Chain as an ERC-20 token diff --git a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/02-deploy-wrapped-native.mdx b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/02-deploy-wrapped-native.mdx index ccea4782..4343e1e6 100644 --- a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/02-deploy-wrapped-native.mdx +++ b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/02-deploy-wrapped-native.mdx @@ -1,116 +1,34 @@ --- -title: Deploy a ICTT contracts -description: deploy remote, home and wrapped native tokens +title: Deploy Wrapped Native Token Contracts +description: Deploy the wrapped native token contract to the Avalanche L1 blockchain. updated: 2024-05-31 -authors: [ashucoder9] +authors: [ashucoder9, owenwahlgren] icon: Book --- +import { Step, Steps } from 'fumadocs-ui/components/steps'; - -## Wrapped Native Token - -On your Avalanche L1, deploy a wrapped token contract for your native token. When we configured the Avalanche L1 earlier, we named the token `NATV`. This is reflected in line 19 of our [example wrapped token contract](https://github.com/ava-labs/avalanche-interchain-token-transfer/blob/main/contracts/src/WrappedNativeToken.sol). - -``` -forge create --rpc-url myblockchain --private-key $PK src/5-native-to-erc20-token-bridge/ExampleWNATV.sol:WNATV -``` - -Export the "Deployed to" address as an environment variables. + + +### Deploy Wrapped Native Token `ExampleWNATV` ```bash -export WRAPPED_ERC20_HOME_SUBNET=<"Deployed to" address> +forge create --rpc-url myblockchain --private-key $PK src/5-native-to-erc20-interchain-token-transfer/ExampleWNATV.sol:WNATV +``` ``` - -```bash [⠊] Compiling... -[⠃] Compiling 7 files with Solc 0.8.18 -[⠊] Solc 0.8.18 finished in 778.12ms +[⠰] Compiling 7 files with Solc 0.8.18 +[⠔] Solc 0.8.18 finished in 371.02ms Compiler run successful! Deployer: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC -Deployed to: 0x52C84043CD9c865236f11d9Fc9F56aa003c1f922 -Transaction hash: 0x054e7b46b221c30f400b81df0fa2601668ae832054cf8e8b873f4ba615fa4115 -``` - -## Native Token Home - -To bridge the token out of your Avalanche L1, you'll need to first deploy a _home_ contract on your Avalanche L1 that implements the `INativeTokenBridge` interface, and inherits the properties of the `TeleporterTokenHome` contract standard. - -Using the [`forge create`](https://book.getfoundry.sh/reference/forge/forge-create) command, we will deploy the [NativeTokenHome.sol](https://github.com/ava-labs/avalanche-interchain-token-transfer/blob/main/contracts/src/TokenHome/NativeTokenHome.sol) contract, passing in the following constructor arguments: - -```bash -forge create --rpc-url myblockchain --private-key $PK lib/teleporter-token-bridge/contracts/src/TokenHome/NativeTokenHome.sol:NativeTokenHome --constructor-args $TELEPORTER_REGISTRY_SUBNET $FUNDED_ADDRESS $WRAPPED_ERC20_HOME_SUBNET -``` - -- Interchain Messaging Registry (for our Avalanche L1) -- Interchain Messaging Manager (our funded address) -- Wrapped Token Address (deployed in the last step) - -For example, this foundry command could be entered into your terminal as: - -```bash -forge create --rpc-url myblockchain --private-key $PK src/5-native-token-bridge/NativeTokenHome.sol:NativeTokenHome --constructor-args 0xAd00Ce990172Cfed987B0cECd3eF58221471a0a3 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC 0x52C84043CD9c865236f11d9Fc9F56aa003c1f922 -``` - -Note the address the home contract was "Deployed to". - -```bash -export ERC20_HOME_BRIDGE_SUBNET=<"Deployed to" address> -``` - -### ERC20 Remote - -To ensure the wrapped token is bridged into the destination chain (in this case, C-Chain) you'll need to deploy a _remote_ contract that implements the `IERC20Bridge` interface, as well as inheriting the properties of `TeleporterTokenRemote`. In order for the bridged tokens to have all the normal functionality of a locally deployed ERC20 token, this remote contract must also inherit the properties of a standard `ERC20` contract. - -First, get the `Source Blockchain ID` in hexidecimal format, which in this example is the BlockchainID of your Avalanche L1, run: - -```bash -avalanche subnet describe myblockchain -``` - -```bash -export SUBNET_BLOCKCHAIN_ID_HEX=0x4d569bf60a38e3ab3e92afd016fe37f7060d7d63c44e3378f42775bf82a7642d -``` - -`Source Blockchain ID` is in the field: `Local Network BlockchainID (HEX)`. - -Using the [`forge create`](https://book.getfoundry.sh/reference/forge/forge-create) command, we will deploy the [ERC20RTokenRemote.sol](https://github.com/ava-labs/avalanche-interchain-token-transfer/blob/main/contracts/src/TokenRemote/ERC20TokenRemote.sol) contract, passing in the following constructor arguments: - -```bash -forge create --rpc-url local-c --private-key $PK lib/teleporter-token-bridge/contracts/src/TokenRemote/ERC20TokenRemote.sol:ERC20TokenRemote --constructor-args "(${TELEPORTER_REGISTRY_C_CHAIN}, ${FUNDED_ADDRESS}, ${SUBNET_BLOCKCHAIN_ID_HEX}, ${ERC20_HOME_BRIDGE_SUBNET})" "Wrapped NATV" "WNATV" 18 -``` - -- 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 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.) - -For example, this contract deployment could be entered into your terminal as: - -```bash -forge create --rpc-url local-c --private-key $PK \ -lib/teleporter-token-bridge/contracts/src/TokenRemote/ERC20TokenRemote.sol:ERC20TokenRemote \ ---constructor-args 0xAd00Ce990172Cfed987B0cECd3eF58221471a0a3 \ -0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC \ -0xbcb8143686b1f0c765a1404bb94ad13134cafa5cf56f181a3a990ba21b1151b9 \ -0x17aB05351fC94a1a67Bf3f56DdbB941aE6c63E25 \ -"Wrapped NATV" \ -"WNATV" \ -18 +Deployed to: 0x52C84043CD9c865236f11d9Fc9F56aa003c1f922 // [!code highlight] +Transaction hash: 0x481398f0648cd2298a6e14fcbc474f71feaff9c85eb367100b31bb7a2213232b ``` - -Note the address the remote contract was "Deployed to". - -```bash -export ERC20_TOKEN_REMOTE_C_CHAIN=<"Deployed to" address> -``` - -## Register Remote Bridge with Home Bridge - -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`. + + +### Save the Wrapped Native Token Address ```bash -cast send --rpc-url local-c --private-key $PK $ERC20_TOKEN_REMOTE_C_CHAIN "registerWithHome((address, uint256))" "(0x0000000000000000000000000000000000000000, 0)" +export WRAPPED_ERC20_L1=0x52C84043CD9c865236f11d9Fc9F56aa003c1f922 ``` + + \ No newline at end of file diff --git a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/03-bridge-tokens.mdx b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/03-bridge-tokens.mdx deleted file mode 100644 index 82020b11..00000000 --- a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/03-bridge-tokens.mdx +++ /dev/null @@ -1,101 +0,0 @@ ---- -title: Deploy a ICTT contracts -description: deploy remote home and wrapped native tokens -updated: 2024-05-31 -authors: [ashucoder9] -icon: Book ---- - - -## Bridge the Token Cross-chain - -First, get the `Destination Blockchain ID` in hexidecimal format, which in this example is the BlockchainID of your local C-Chain, run: - -```zsh -avalanche primary describe -``` - -`Destination Blockchain ID` is in the field: `BlockchainID (HEX)`. - -```bash -export C_CHAIN_BLOCKCHAIN_ID_HEX=0x55e1fcfdde01f9f6d4c16fa2ed89ce65a8669120a86f321eef121891cab61241 -``` - -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. - -```zsh -cast send --rpc-url myblockchain --private-key $PK \ -"" \ -"(,,...)" \ ---value -``` - -In [`NativeTokenHome`](https://github.com/ava-labs/avalanche-interchain-token-transfer/blob/main/contracts/src/TokenHome/NativeTokenHome.sol) is the send function we will call to send the tokens: - -```solidity -function send(SendTokensInput calldata input) external payable { - _send(input, msg.value, false); - } -``` - -The function parameters are defined by the `SendTokensInput` struct defined in [`ITokenTransferrer.sol`](https://github.com/ava-labs/avalanche-interchain-token-transfer/blob/main/contracts/src/interfaces/ITokenTransferrer.sol). - -```solidity -struct SendTokensInput { - bytes32 destinationBlockchainID; - address destinationBridgeAddress; - address recipient; - address feeTokenAddress; - uint256 primaryFee; - uint256 secondaryFee; - uint256 requiredGasLimit; -} -``` - -- destinationBlockchainID: C-Chain Blockchain ID -- destinationBridgeAddress: ERC20 Remote address -- recipient: any Ethereum Address you want to send funds to -- feeTokenAddress: Wrapped Native Token address -- primaryFee: amount of tokens to pay for Interchain Messaging fee on the source chain, can be 0 for this example -- secondaryFee: amount of tokens to pay for Interchain Messaging fee if a multi-hop is needed, can be 0 for this example -- requiredGasLimit: gas limit requirement for sending to a token bridge, can be 1000000 for this example - -For example, this token transfer could be entered into your terminal as: - -```solidity - function sendAndCall(SendAndCallInput calldata input) external payable { - _sendAndCall({ - sourceBlockchainID: blockchainID, - originBridgeAddress: address(this), - originSenderAddress:_msgSender(), - input: input, - amount: msg.value, - isMultiHop: false - }); - } - -struct SendTokensInput { - bytes32 destinationBlockchainID; - address destinationBridgeAddress; - address recipient; - address primaryFeeTokenAddress; - uint256 primaryFee; - uint256 secondaryFee; - uint256 requiredGasLimit; - address multiHopFallback; -} -``` - -```bash -cast send --rpc-url myblockchain --private-key $PK $ERC20_HOME_BRIDGE_SUBNET "send((bytes32, address, address, address, uint256, uint256, uint256, address))" "(${C_CHAIN_BLOCKCHAIN_ID_HEX}, ${ERC20_TOKEN_REMOTE_C_CHAIN}, ${FUNDED_ADDRESS}, 0x0000000000000000000000000000000000000000, 0, 0, 250000, 0x0000000000000000000000000000000000000000)" --value 1 -``` - -If your parameters were entered correctly, this command will sign and publish a transaction, resulting in a large JSON response of transaction information in the terminal. - -To confirm the token was bridged from Avalanche L1 to C-Chain, we will check the recipient's balance of wrapped tokens on the C-Chain with the [`cast call`](https://book.getfoundry.sh/reference/cast/cast-call?highlight=cast%20call#cast-call) foundry command: - -```zsh -cast call --rpc-url local-c $ERC20_TOKEN_REMOTE_C_CHAIN "balanceOf(address)(uint)" $FUNDED_ADDRESS -``` - -If the command returns a balance greater than 0, congratulations, you've now successfully deployed a Teleporter-enabled bridge and successfully sent tokens cross-chain! \ No newline at end of file diff --git a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/03-deploy-native-token-home.mdx b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/03-deploy-native-token-home.mdx new file mode 100644 index 00000000..6edaee1f --- /dev/null +++ b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/03-deploy-native-token-home.mdx @@ -0,0 +1,103 @@ +--- +title: Deploy Native Token Home +description: Deploy the NativeTokenHome contract on the Avalanche L1 blockchain. +updated: 2024-05-31 +authors: [owenwahlgren] +icon: Book +--- +import { Step, Steps } from 'fumadocs-ui/components/steps'; + +You may already have `TELEPORTER_REGISTRY_L1` and `SOURCE_BLOCKCHAIN_ID_HEX` set from previous sections. If you do, you can skip to step 5. + + +### Get the `Teleporter Registry Address` of `myblockchain` + +```bash +avalanche blockchain describe myblockchain +``` + +``` ++-------------------------------------------------------------------------------------------+ +| TELEPORTER | ++---------------+------------------------------+--------------------------------------------+ +| Local Network | Teleporter Messenger Address | 0x253b2784c75e510dD0fF1da844684a1aC0aa5fcf | +| +------------------------------+--------------------------------------------+ +| | Teleporter Registry Address | 0xB4DC3d786D658d118631F5C6B75CB5935be8407C | // [!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_L1=0xa3493940a13b426BD2f7dA6E55A39c060C0e6020 +``` + + + +### Get the `Blockchain ID (hex)` of `myblockchain` + + +``` ++---------------------------------------------------------------------------------------------------------------+ +| MYBLOCKCHAIN | ++---------------+-----------------------------------------------------------------------------------------------+ +| Name | myblockchain | ++---------------+-----------------------------------------------------------------------------------------------+ +| VM ID | qDNV9vtxZYYNqm7TSa9KnDTRabGxtBLv6vd888791J9a89kTF | ++---------------+-----------------------------------------------------------------------------------------------+ +| VM Version | v0.6.9 | ++---------------+--------------------------+--------------------------------------------------------------------+ +| Local Network | ChainID | 1 | +| +--------------------------+--------------------------------------------------------------------+ +| | SubnetID | 2KhsQJhH3VqS7WWMreodAAHpGfGCUNuGQDSaP2vUT29p1HELBV | +| +--------------------------+--------------------------------------------------------------------+ +| | Owners (Threhold=1) | P-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p | +| +--------------------------+--------------------------------------------------------------------+ +| | BlockchainID (CB58) | 2ZempAyezixFRdJhJribDdj2wiK6YFF63CkXKaimfPb3hWeWVH | +| +--------------------------+--------------------------------------------------------------------+ +| | BlockchainID (HEX) | 0xcdd5b2b99ae462c32a8e4ea47e94f2c7804519353558fd4127cf7ae11d8a6e52 | // [!code highlight] ++---------------+--------------------------+--------------------------------------------------------------------+ + +``` + + + +### Save the `Blockchain ID (hex)` + +```bash +export SOURCE_BLOCKCHAIN_ID_HEX=0xcdd5b2b99ae462c32a8e4ea47e94f2c7804519353558fd4127cf7ae11d8a6e52 +``` + + + +### Deploy `NativeTokenHome` on `myblockchain` + +Using the [`forge create`](https://book.getfoundry.sh/reference/forge/forge-create) command, we will deploy the [NativeTokenHome.sol](https://github.com/ava-labs/avalanche-interchain-token-transfer/blob/main/contracts/src/TokenHome/NativeTokenHome.sol) contract, passing in the following constructor arguments: + +- Interchain Messaging Registry (for our Avalanche L1) +- Interchain Messaging Manager (our funded address) +- Wrapped Token Address (deployed in the last step) + +```bash +forge create --rpc-url myblockchain --private-key $PK lib/avalanche-interchain-token-transfer/contracts/src/TokenHome/NativeTokenHome.sol:NativeTokenHome --constructor-args $TELEPORTER_REGISTRY_L1 $FUNDED_ADDRESS $WRAPPED_ERC20_L1 +``` +``` +[⠊] Compiling... +[⠊] Compiling 22 files with Solc 0.8.18 +[⠒] Solc 0.8.18 finished in 1.95s +Compiler run successful! +Deployer: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC +Deployed to: 0x17aB05351fC94a1a67Bf3f56DdbB941aE6c63E25 // [!code highlight] +Transaction hash: 0x91c60be19a69aadb1415112dd42302764b30bc48f09957c3a191021d70ccc9d4 +``` + + +### Save the Native Token Home Address + +```bash +export ERC20_HOME_BRIDGE_L1=0x17aB05351fC94a1a67Bf3f56DdbB941aE6c63E25 +``` + + \ No newline at end of file diff --git a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/04-deploy-erc20-token-remote.mdx b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/04-deploy-erc20-token-remote.mdx new file mode 100644 index 00000000..68993ca1 --- /dev/null +++ b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/04-deploy-erc20-token-remote.mdx @@ -0,0 +1,57 @@ +--- +title: Deploy ERC20 Token Remote +description: Deploy and register the ERC20TokenRemote contract to the Avalanche C-Chain. +updated: 2024-05-31 +authors: [owenwahlgren] +icon: Book +--- +import { Step, Steps } from 'fumadocs-ui/components/steps'; + + + +### Deploy `ERC20TokenRemote` on C-Chain + +Using the [`forge create`](https://book.getfoundry.sh/reference/forge/forge-create) command, we will deploy the [ERC20TokenRemote.sol](https://github.com/ava-labs/avalanche-interchain-token-transfer/blob/main/contracts/src/TokenRemote/ERC20TokenRemote.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 `myblockchain`) +- Token Home Address (address of NativeTokenHome.sol deployed on our Avalanche L1 `myblockchain` in the last step) +- 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; typically 18 decimals) + + +```bash +forge create --rpc-url local-c --private-key $PK lib/avalanche-interchain-token-transfer/contracts/src/TokenRemote/ERC20TokenRemote.sol:ERC20TokenRemote \ +--constructor-args "(${TELEPORTER_REGISTRY_C_CHAIN}, ${FUNDED_ADDRESS}, ${SOURCE_BLOCKCHAIN_ID_HEX}, ${ERC20_HOME_BRIDGE_L1}, 18)" "Wrapped NATV" "WNATV" 18 +``` +``` +[⠊] Compiling... +[⠆] Compiling 5 files with Solc 0.8.18 +[⠰] Solc 0.8.18 finished in 1.23s +Compiler run successful! +Deployer: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC +Deployed to: 0x5DB9A7629912EBF95876228C24A848de0bfB43A9 // [!code highlight] +Transaction hash: 0x3d437a3421f7b2b1bf0276e9a80f57815291e62313584ff48afb69fb206b5daf +``` + + +### Save the ERC20 Token Remote Address + +```bash +export ERC20_TOKEN_REMOTE_C_CHAIN=0x5DB9A7629912EBF95876228C24A848de0bfB43A9 +``` + + + +### Register `ERC20TokenRemote` on C-Chain with `NativeTokenHome` on `myblockchain` + +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 local-c --private-key $PK $ERC20_TOKEN_REMOTE_C_CHAIN "registerWithHome((address, uint256))" "(0x0000000000000000000000000000000000000000, 0)" +``` + + + \ No newline at end of file diff --git a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/05-bridge-tokens.mdx b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/05-bridge-tokens.mdx new file mode 100644 index 00000000..90241611 --- /dev/null +++ b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/05-bridge-tokens.mdx @@ -0,0 +1,36 @@ +--- +title: Native Token Bridge Transfer +description: Perform a transfer of a native Avalanche L1 token to the C-Chain as an ERC-20 token. +updated: 2024-05-31 +authors: [ashucoder9, owenwahlgren] +icon: Book +--- +import { Step, Steps } from 'fumadocs-ui/components/steps'; + + + +### Transfer the L1's Native Token to the C-Chain + +Now that all the bridge contracts have been deployed and configured, 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 myblockchain --private-key $PK $ERC20_HOME_BRIDGE_L1 \ +"send((bytes32, address, address, address, uint256, uint256, uint256, address))" \ +"(${C_CHAIN_BLOCKCHAIN_ID_HEX}, ${ERC20_TOKEN_REMOTE_C_CHAIN}, ${FUNDED_ADDRESS}, 0x0000000000000000000000000000000000000000, 0, 0, 250000, 0x0000000000000000000000000000000000000000)" --value 1ether +``` + + + +### Check Balance +To confirm the token was bridged from Avalanche L1 to C-Chain, we will check the recipient's balance of wrapped tokens on the C-Chain with the [`cast call`](https://book.getfoundry.sh/reference/cast/cast-call?highlight=cast%20call#cast-call) foundry command: + +```bash +cast call --rpc-url local-c $ERC20_TOKEN_REMOTE_C_CHAIN "balanceOf(address)(uint)" $FUNDED_ADDRESS +``` + +```bash +1000000000000000000 +``` +**Success!** Our balance of native wrapped tokens on the C-Chain is 1 token! + + diff --git a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/x-deploy-with-avalanchecli.mdx b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/x-deploy-with-avalanchecli.mdx deleted file mode 100644 index 10700d22..00000000 --- a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/x-deploy-with-avalanchecli.mdx +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: Deploy with CLI -description: TBD -updated: 2024-05-31 -authors: [ashucoder9] -icon: BookOpen ---- \ No newline at end of file diff --git a/content/course/interchain-token-transfer/meta.json b/content/course/interchain-token-transfer/meta.json index 60746786..b7e57384 100644 --- a/content/course/interchain-token-transfer/meta.json +++ b/content/course/interchain-token-transfer/meta.json @@ -17,6 +17,8 @@ "...06-erc-20-to-erc-20-bridge", "---ERC-20 Multi-Hop Transfer---", "...07-tokens-on-multiple-chains", + "---Native to ERC-20 Token Bridge---", + "...08-native-to-erc-20-bridge", "---Send and Call---", "...12-send-and-call", "---Cross-Chain Token Swaps---", From 9c2a4bd717c92ac8239835718d6b3d3871343104 Mon Sep 17 00:00:00 2001 From: owenwahlgren Date: Mon, 9 Sep 2024 17:05:00 -0400 Subject: [PATCH 2/3] nit --- .../08-native-to-erc-20-bridge/05-bridge-tokens.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/05-bridge-tokens.mdx b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/05-bridge-tokens.mdx index 90241611..13e30a1d 100644 --- a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/05-bridge-tokens.mdx +++ b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/05-bridge-tokens.mdx @@ -11,7 +11,7 @@ import { Step, Steps } from 'fumadocs-ui/components/steps'; ### Transfer the L1's Native Token to the C-Chain -Now that all the bridge contracts have been deployed and configured, 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. +Now that all the bridge contracts have been deployed and configured, send a some native tokens 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 myblockchain --private-key $PK $ERC20_HOME_BRIDGE_L1 \ @@ -31,6 +31,6 @@ cast call --rpc-url local-c $ERC20_TOKEN_REMOTE_C_CHAIN "balanceOf(address)(uint ```bash 1000000000000000000 ``` -**Success!** Our balance of native wrapped tokens on the C-Chain is 1 token! +**Success!** We have bridged 1 native token from our Avalanche L1 to the C-Chain as an ERC-20 token. From a1dcae05cf85ea513beb7897360eece526329a74 Mon Sep 17 00:00:00 2001 From: owenwahlgren Date: Mon, 9 Sep 2024 17:07:24 -0400 Subject: [PATCH 3/3] nit --- .../08-native-to-erc-20-bridge/01-native-to-erc-20-bridge.mdx | 1 + .../08-native-to-erc-20-bridge/05-bridge-tokens.mdx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/01-native-to-erc-20-bridge.mdx b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/01-native-to-erc-20-bridge.mdx index 7fafe4f0..e6ca628b 100644 --- a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/01-native-to-erc-20-bridge.mdx +++ b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/01-native-to-erc-20-bridge.mdx @@ -9,6 +9,7 @@ icon: Book ICTT is also capable of bridging native tokens from Avalanche L1s to the C-Chain as ERC-20 tokens. This process involves deploying a `NativeTokenHome` contract on the Avalanche L1, and a `ERC20TokenRemote` contract on the C-Chain. The `NativeTokenHome` contract will be used to bridge the native token to the C-Chain as an ERC-20 token. This example will cover native to ERC-20 token bridging between `myblockchain` and the C-Chain, but the process can be adapted to bridge the C-Chain's native asset, `AVAX`, to any L1 as an ERC-20 token. + ### What we will do 1. Deploy a Wrapped Native Token to `myblockchain` 2. Deploy the `NativeTokenHome` contract on `myblockchain` diff --git a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/05-bridge-tokens.mdx b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/05-bridge-tokens.mdx index 13e30a1d..b59d5626 100644 --- a/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/05-bridge-tokens.mdx +++ b/content/course/interchain-token-transfer/08-native-to-erc-20-bridge/05-bridge-tokens.mdx @@ -11,7 +11,7 @@ import { Step, Steps } from 'fumadocs-ui/components/steps'; ### Transfer the L1's Native Token to the C-Chain -Now that all the bridge contracts have been deployed and configured, send a some native tokens from your Avalanche L1 to C-Chain with the [`cast send`](https://book.getfoundry.sh/reference/cast/cast-send) foundry command. +Now that all the bridge contracts have been deployed and configured, send some native tokens 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 myblockchain --private-key $PK $ERC20_HOME_BRIDGE_L1 \