Skip to content

Commit

Permalink
Mention native gas tokens for Orbit chains
Browse files Browse the repository at this point in the history
  • Loading branch information
TucksonDev committed Nov 6, 2024
1 parent a0028fe commit 250f5fc
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 43 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ yarn install

#### :white_check_mark: Moving stuff around

- ⤴️ 🔹 [Deposit Ether](./packages/eth-deposit/)
- ⤴️ 🔹 [Deposit Ether to a different address](./packages/eth-deposit-to-different-address/)
- ⤵️ 🔹 [Withdraw Ether](./packages/eth-withdraw/)
- ⤴️ 🔹 [Deposit Ether or native token](./packages/eth-deposit/)
- ⤴️ 🔹 [Deposit Ether or native token to a different address](./packages/eth-deposit-to-different-address/)
- ⤵️ 🔹 [Withdraw Ether or native token](./packages/eth-withdraw/)
- ⤴️ 💸 [Deposit Token](./packages/token-deposit/)
- ⤵️ 💸 [Withdraw token](./packages/token-withdraw/)
- ⤴️ 🔹 [Contract alias control in the child chain, and fund-transfer guide](./packages/contract-deposit/)
Expand Down
10 changes: 5 additions & 5 deletions packages/eth-deposit-to-different-address/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# eth-deposit-to-different-address tutorial
# Tutorial: deposit Ether or native token to a different address

`eth-deposit-to-different-address` shows how to move Ether from the parent chain into an Arbitrum or Orbit chain, to an address different than the depositor.
`eth-deposit-to-different-address` shows how to move Ether (or your chain's native token if you're using a custom gas token) from the parent chain into an Arbitrum or Orbit chain, to an address different than the depositor.

## How it works (under the hood)

For the common case of depositing ETH to the same account on the child chain, use the tutorial [eth-deposit](../eth-deposit/README.md).
For the common case of depositing Ether (or your chain's native token) to the same account on the child chain, use the tutorial [eth-deposit](../eth-deposit/README.md).

In this specific case, we will use a retryable ticket (Arbitrum's canonical method for creating cross-chain messages) to deposit ETH into a different address. We will use the parameter `l2CallValue` of the retryable ticket to specify the amount of ETH to deposit, and `callValueRefundAddress` to specify the destination address. For more info on retryable tickets, see [this page of the Arbitrum documentation](https://docs.arbitrum.io/how-arbitrum-works/arbos/l1-l2-messaging#eth-deposits).
In this specific case, we will use a retryable ticket (Arbitrum's canonical method for creating cross-chain messages) to deposit the chain's native token (e.g. Ether) into a different address. We will use the parameter `l2CallValue` of the retryable ticket to specify the amount of assets to deposit, and `callValueRefundAddress` to specify the destination address. For more info on retryable tickets, see [this page of the Arbitrum documentation](https://docs.arbitrum.io/how-arbitrum-works/arbos/l1-l2-messaging#eth-deposits).

## Using the Arbitrum SDK

Our [Arbitrum SDK](https://github.com/OffchainLabs/arbitrum-sdk) provides a simply convenience method for depositing Ether, abstracting away the need for the client to connect to any contracts manually.
Our [Arbitrum SDK](https://github.com/OffchainLabs/arbitrum-sdk) provides a simply convenience method for depositing Ether (or your chain's native token), abstracting away the need for the client to connect to any contracts manually.

See [./exec.js](./scripts/exec.js) for inline explanation.

Expand Down
19 changes: 10 additions & 9 deletions packages/eth-deposit-to-different-address/scripts/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const parentChainProvider = new providers.JsonRpcProvider(
const childChainProvider = new providers.JsonRpcProvider(process.env.CHAIN_RPC)

const parentChainWallet = new Wallet(walletPrivateKey, parentChainProvider)
const childChainWallet = new Wallet(walletPrivateKey, childChainProvider)

/**
* Set the destination address and amount to be deposited in the child chain (in wei)
Expand All @@ -32,7 +31,9 @@ const destAddress = '0x2D98cBc6f944c4bD36EdfE9f98cd7CB57faEC8d6'
const depositAmount = utils.parseEther('0.0001')

const main = async () => {
await arbLog('Deposit Eth via Arbitrum SDK on a different address')
await arbLog(
'Deposit native token (e.g. Ether) via Arbitrum SDK to a different address'
)

/**
* Add the custom network configuration to the SDK if present
Expand All @@ -41,24 +42,24 @@ const main = async () => {

/**
* Use childChainNetwork to create an Arbitrum SDK EthBridger instance
* We'll use EthBridger for its convenience methods around transferring ETH to the child chain
* We'll use EthBridger for its convenience methods around transferring the native asset to the child chain
*/
const childChainNetwork = await getArbitrumNetwork(childChainProvider)
const ethBridger = new EthBridger(childChainNetwork)

/**
* First, let's check the ETH balance of the destination address
* First, let's check the balance of the destination address
*/
const destinationAddressInitialEthBalance =
await childChainProvider.getBalance(destAddress)

/**
* Transfer ether from parent chain to a different address on child chain
* Transfer ether (or native token) from parent chain to a different address on child chain
* This convenience method automatically queries for the retryable's max submission cost and forwards the appropriate amount to the specified address on the child chain
* by using a retryable ticket instead of a regular deposit.
* Arguments required are:
* (1) amount: The amount of ETH to be transferred
* (2) parentSigner: The address on the parent chain of the account transferring ETH to the child chain
* (1) amount: The amount of ETH (or native token) to be transferred
* (2) parentSigner: The address on the parent chain of the account transferring ETH (or native token) to the child chain
* (3) childProvider: A provider of the child chain
* (4) destinationAddress: The address where the ETH will be sent to
*/
Expand Down Expand Up @@ -102,12 +103,12 @@ const main = async () => {
)

/**
* Our destination address ETH balance should be updated now
* Our destination address balance should be updated now
*/
const destinationAddressUpdatedEthBalance =
await childChainProvider.getBalance(destAddress)
console.log(
`ETH balance of the destination address has been updated from ${destinationAddressInitialEthBalance.toString()} to ${destinationAddressUpdatedEthBalance.toString()}`
`Balance of the destination address has been updated from ${destinationAddressInitialEthBalance.toString()} to ${destinationAddressUpdatedEthBalance.toString()}`
)
}
main()
Expand Down
8 changes: 4 additions & 4 deletions packages/eth-deposit/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# eth-deposit Tutorial
# Tutorial: deposit Ether or native token

`eth-deposit` shows how to move Ether from the parent chain into an Arbitrum or Orbit chain.
`eth-deposit` shows how to move Ether (or your chain's native token if you're using a custom gas token) from the parent chain into an Arbitrum or Orbit chain.

## How it works (under the hood)

A user deposits Ether onto an Arbitrum chain using Arbitrum's general Parent-to-child message passing system, and simply passing the desired Ether as callvalue and no additional data. For more info, see [this page of the Arbitrum documentation](https://docs.arbitrum.io/how-arbitrum-works/arbos/l1-l2-messaging#eth-deposits).
A user deposits the chain's native token (e.g. Ether) onto an Arbitrum chain using Arbitrum's general Parent-to-child message passing system, and simply passing the desired Ether as callvalue and no additional data. For more info, see [this page of the Arbitrum documentation](https://docs.arbitrum.io/how-arbitrum-works/arbos/l1-l2-messaging#eth-deposits).

## Using the Arbitrum SDK

Our [Arbitrum SDK](https://github.com/OffchainLabs/arbitrum-sdk) provides a simply convenience method for depositing Ether, abstracting away the need for the client to connect to any contracts manually.
Our [Arbitrum SDK](https://github.com/OffchainLabs/arbitrum-sdk) provides a simply convenience method for depositing Ether (or your chain's native token), abstracting away the need for the client to connect to any contracts manually.

See [./exec.js](./scripts/exec.js) for inline explanation.

Expand Down
16 changes: 8 additions & 8 deletions packages/eth-deposit/scripts/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const childChainWallet = new Wallet(walletPrivateKey, childChainProvider)
const depositAmount = utils.parseEther('0.0001')

const main = async () => {
await arbLog('Deposit Eth via Arbitrum SDK')
await arbLog('Deposit native token (e.g. Ether) via Arbitrum SDK')

/**
* Add the custom network configuration to the SDK if present
Expand All @@ -40,22 +40,22 @@ const main = async () => {

/**
* Use childChainNetwork to create an Arbitrum SDK EthBridger instance
* We'll use EthBridger for its convenience methods around transferring ETH to the child chain
* We'll use EthBridger for its convenience methods around transferring the native asset to the child chain
*/
const childChainNetwork = await getArbitrumNetwork(childChainProvider)
const ethBridger = new EthBridger(childChainNetwork)

/**
* First, let's check the wallet's initial ETH balance in the child chain
* First, let's check the wallet's initial balance in the child chain
*/
const initialEthBalance = await childChainWallet.getBalance()

/**
* Transfer ether from parent to child chain
* Transfer ether (or native token) from parent to child chain
* This convenience method automatically queries for the retryable's max submission cost and forwards the appropriate amount to the child chain
* Arguments required are:
* (1) amount: The amount of ETH to be transferred
* (2) parentSigner: The address on the parent chain of the account transferring ETH to the child chain
* (1) amount: The amount of ETH (or native token) to be transferred
* (2) parentSigner: The address on the parent chain of the account transferring ETH (or native token) to the child chain
* (3) childProvider: A provider of the child chain
*/
const depositTransaction = await ethBridger.deposit({
Expand Down Expand Up @@ -98,11 +98,11 @@ const main = async () => {
)

/**
* Our wallet's ETH balance on the child chain should be updated now
* Our wallet's balance on the child chain should be updated now
*/
const updatedEthBalance = await childChainWallet.getBalance()
console.log(
`Your ETH balance in the child chain is updated from ${initialEthBalance.toString()} to ${updatedEthBalance.toString()}`
`Your balance in the child chain is updated from ${initialEthBalance.toString()} to ${updatedEthBalance.toString()}`
)
}
main()
Expand Down
10 changes: 5 additions & 5 deletions packages/eth-withdraw/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# eth-withdraw tutorial
# Tutorial: withdraw Ether or native token

`eth-withdraw` shows how to move Ether from an Arbitrum or Orbit chain into its parent chain.
`eth-withdraw` shows how to move Ether (or your chain's native token if you're using a custom gas token) from an Arbitrum or Orbit chain into its parent chain.

Note that this repo covers initiating an Ether withdrawal. For a demo on releasing the funds from the Outbox, see [outbox-execute](../outbox-execute/README.md)
Note that this repo covers initiating a withdrawal. For a demo on releasing the funds from the Outbox, see [outbox-execute](../outbox-execute/README.md)

## How it works (under the hood)

To withdraw Ether from an Arbitrum chain, a client creates an outgoing / child to parent message using the `ArbSys` precompile that later lets them release Ether from its escrow in the parent chain's Bridge contract. For more info, see [this page of the Arbitrum documentation](https://docs.arbitrum.io/how-arbitrum-works/arbos/l2-l1-messaging).
To withdraw Ether (or your chain's native token) from an Arbitrum chain, a client creates an outgoing / child to parent message using the `ArbSys` precompile that later lets them release the asset from its escrow in the parent chain's Bridge contract. For more info, see [this page of the Arbitrum documentation](https://docs.arbitrum.io/how-arbitrum-works/arbos/l2-l1-messaging).

## Using the Arbitrum SDK

Our [Arbitrum SDK](https://github.com/OffchainLabs/arbitrum-sdk) provides a simply convenience method for withdrawing Ether, abstracting away the need for the client to connect to any contracts manually.
Our [Arbitrum SDK](https://github.com/OffchainLabs/arbitrum-sdk) provides a simply convenience method for withdrawing Ether (or your chain's native token), abstracting away the need for the client to connect to any contracts manually.

See [./exec.js](./scripts/exec.js) for inline explanation.

Expand Down
14 changes: 5 additions & 9 deletions packages/eth-withdraw/scripts/exec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const { utils, providers, Wallet } = require('ethers')
const {
getArbitrumNetwork,
EthBridger,
EthDepositMessageStatus,
} = require('@arbitrum/sdk')
const { getArbitrumNetwork, EthBridger } = require('@arbitrum/sdk')
const {
arbLog,
requireEnvVariables,
Expand Down Expand Up @@ -34,26 +30,26 @@ const main = async () => {

/**
* Use childChainNetwork to create an Arbitrum SDK EthBridger instance
* We'll use EthBridger for its convenience methods around transferring ETH to the parent chain
* We'll use EthBridger for its convenience methods around transferring the native asset to the parent chain
*/
const childChainNetwork = await getArbitrumNetwork(childChainProvider)
const ethBridger = new EthBridger(childChainNetwork)

/**
* First, let's check our wallet's initial ETH balance in the child chain and ensure there's some ETH to withdraw
* First, let's check our wallet's initial balance in the child chain and ensure there's some native asset to withdraw
*/
const initialEthBalance = await childChainWallet.getBalance()

if (initialEthBalance.lt(withdrawAmount)) {
console.log(
`Oops - not enough ether; fund your wallet on the child chain ${childChainWallet.address} with at least 0.000001 ether`
`Oops - not enough balance; fund your wallet on the child chain ${childChainWallet.address} with at least 0.000001 ether (or your chain's gas token)`
)
process.exit(1)
}
console.log('Wallet properly funded: initiating withdrawal now')

/**
* We're ready to withdraw ETH using the ethBridger instance from Arbitrum SDK
* We're ready to withdraw the native asset using the ethBridger instance from Arbitrum SDK
* It will use our current wallet's address as the default destination
*/
const withdrawTransaction = await ethBridger.withdraw({
Expand Down

0 comments on commit 250f5fc

Please sign in to comment.