diff --git a/src/actions/index.ts b/src/actions/index.ts index 3b10c12e..35f87b3e 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -26,7 +26,7 @@ export { type SimulateDepositERC20ReturnType, } from './public/L1/simulateDepositERC20.js' export { - type simulateDepositETH, + simulateDepositETH, type SimulateDepositETHParameters, type SimulateDepositETHReturnType, } from './public/L1/simulateDepositETH.js' diff --git a/src/actions/wallet/L1/writeDepositETH.ts b/src/actions/wallet/L1/writeDepositETH.ts index 7742c3a6..a8a82659 100644 --- a/src/actions/wallet/L1/writeDepositETH.ts +++ b/src/actions/wallet/L1/writeDepositETH.ts @@ -1,4 +1,5 @@ import type { Account, Chain, Transport, WalletClient, WriteContractReturnType } from 'viem' +import { estimateContractGas } from 'viem/actions' import { ABI, CONTRACT, type DepositETHParameters, FUNCTION } from '../../../types/depositETH.js' import type { L1WriteActionBaseType } from '../../../types/l1Actions.js' import { writeOpStackL1, type WriteOpStackL1Parameters } from './writeOpStackL1.js' @@ -33,24 +34,22 @@ export async function writeDepositETH< args: { to, minGasLimit, extraData = '0x' }, l1StandardBridgeAddress, ...rest - }: WriteDepositETHParameters< - TChain, - TAccount, - TChainOverride - >, + }: WriteDepositETHParameters, ): Promise { + const gas = await estimateContractGas(client, { + account: client.account, + args: [to, minGasLimit, extraData], + abi: ABI, + functionName: FUNCTION, + address: l1StandardBridgeAddress, + } as any) return writeOpStackL1(client, { address: l1StandardBridgeAddress, abi: ABI, contract: CONTRACT, functionName: FUNCTION, + gas: gas + (gas / BigInt(2)), args: [to, minGasLimit, extraData], ...rest, - } as unknown as WriteOpStackL1Parameters< - TChain, - TAccount, - TChainOverride, - typeof ABI, - typeof FUNCTION - >) + } as unknown as WriteOpStackL1Parameters) }