Skip to content

Commit

Permalink
fix: add gas limit buffer for deposits (#1339)
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc authored Dec 7, 2023
1 parent fcb728a commit 69c6302
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/arb-token-bridge-ui/src/hooks/useArbTokenBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ class TokenDisabledError extends Error {
}
}

// https://github.com/OffchainLabs/arbitrum-sdk/blob/main/src/lib/message/L1ToL2MessageGasEstimator.ts#L76
function percentIncrease(num: BigNumber, increase: BigNumber): BigNumber {
return num.add(num.mul(increase).div(100))
}

export interface TokenBridgeParams {
l1: { provider: JsonRpcProvider; network: Chain }
l2: { provider: JsonRpcProvider; network: Chain }
Expand Down Expand Up @@ -190,12 +195,20 @@ export const useArbTokenBridge = (

const ethBridger = await EthBridger.fromProvider(l2.provider)

const depositRequest = await ethBridger.getDepositRequest({
amount,
from: walletAddress
})

let tx: L1EthDepositTransaction

try {
const gasLimit = await l1.provider.estimateGas(depositRequest.txRequest)

tx = await ethBridger.deposit({
amount,
l1Signer
l1Signer,
overrides: { gasLimit: percentIncrease(gasLimit, BigNumber.from(5)) }
})

if (txLifecycle?.onTxSubmit) {
Expand Down Expand Up @@ -453,9 +466,12 @@ export const useArbTokenBridge = (
amount
})

const gasLimit = await l1.provider.estimateGas(depositRequest.txRequest)

const tx = await erc20Bridger.deposit({
...depositRequest,
l1Signer
l1Signer,
overrides: { gasLimit: percentIncrease(gasLimit, BigNumber.from(5)) }
})

if (txLifecycle?.onTxSubmit) {
Expand Down

1 comment on commit 69c6302

@vercel
Copy link

@vercel vercel bot commented on 69c6302 Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.