OffchainLabs / arbitrum-sdk

https://arbitrum-sdk.vercel.app
Apache License 2.0
233 stars 177 forks source link

eth carried with the deposit erc20 token #465

Open liaoyinglong opened 6 months ago

liaoyinglong commented 6 months ago

First of all, this is an awesome library!

I have a question about when I call Erc20Bridger.deposit I can control the amount of ETH to send? if not, how can I know I will send the ETH amount in L1 and will receive the ETH amount in L2 before do deposit action?

the code like:

const bridger = new Erc20Bridger(l2Network)
// I want to know how much is  will send ETH amount in L1 and will receive the ETH amount in L2

const ethDepositTxResponse = await bridger.deposit({
  amount: utils.parseEther('10'),
  l1Signer: l1Signer /** <-- connected ethers-js Wallet */,
  l2Provider: l2Provider /** <--- ethers-js Provider */,
})

Thank of all!

spsjvc commented 6 months ago

For depositing ETH, you should use EthBridger. Erc20Bridger is used for depositing ERC-20 tokens.

liaoyinglong commented 6 months ago

yes, I mean when I deposit ERC20 token that will send some ETH to bridge in this line https://github.com/OffchainLabs/arbitrum-sdk/blob/01af6ef017e164bb7cb7febf7026ce60af76a112/src/lib/assetBridger/erc20Bridger.ts#L696

and can I know how much eth amount will be sent to my L2 address ?

spsjvc commented 6 months ago

The ETH sent is there to cover for the retryable execution fees and it's necessary for your ERC-20 deposit to succeed.

You can calculate this amount upfront by using the L1ToL2MessageGasEstimator. You can see here how the Erc20Bridger uses it: https://github.com/OffchainLabs/arbitrum-sdk/blob/main/src/lib/assetBridger/erc20Bridger.ts#L686

liaoyinglong commented 6 months ago

thank you! The amount is send to bridge's ETH amount, can i get the amount of will received in L2 address?

example:

I'd like to know if it's possible to calculate this value 0.0000395035 Ether before making a deposit.

SCR-20240426-orqc SCR-20240426-osym