|
1 | 1 | import type { Account, Chain, Transport, WalletClient, WriteContractReturnType } from 'viem' |
| 2 | +import { estimateContractGas } from 'viem/actions' |
2 | 3 | import { ABI, CONTRACT, type DepositETHParameters, FUNCTION } from '../../../types/depositETH.js' |
3 | 4 | import type { L1WriteActionBaseType } from '../../../types/l1Actions.js' |
4 | 5 | import { writeOpStackL1, type WriteOpStackL1Parameters } from './writeOpStackL1.js' |
@@ -33,24 +34,22 @@ export async function writeDepositETH< |
33 | 34 | args: { to, minGasLimit, extraData = '0x' }, |
34 | 35 | l1StandardBridgeAddress, |
35 | 36 | ...rest |
36 | | - }: WriteDepositETHParameters< |
37 | | - TChain, |
38 | | - TAccount, |
39 | | - TChainOverride |
40 | | - >, |
| 37 | + }: WriteDepositETHParameters<TChain, TAccount, TChainOverride>, |
41 | 38 | ): Promise<WriteContractReturnType> { |
| 39 | + const gas = await estimateContractGas(client, { |
| 40 | + args: { to, minGasLimit, extraData }, |
| 41 | + l1StandardBridgeAddress, |
| 42 | + abi: ABI, |
| 43 | + functionName: FUNCTION, |
| 44 | + ...rest, |
| 45 | + } as any) |
42 | 46 | return writeOpStackL1(client, { |
43 | 47 | address: l1StandardBridgeAddress, |
44 | 48 | abi: ABI, |
45 | 49 | contract: CONTRACT, |
46 | 50 | functionName: FUNCTION, |
| 51 | + gas: gas + (gas / BigInt(2)), |
47 | 52 | args: [to, minGasLimit, extraData], |
48 | 53 | ...rest, |
49 | | - } as unknown as WriteOpStackL1Parameters< |
50 | | - TChain, |
51 | | - TAccount, |
52 | | - TChainOverride, |
53 | | - typeof ABI, |
54 | | - typeof FUNCTION |
55 | | - >) |
| 54 | + } as unknown as WriteOpStackL1Parameters<TChain, TAccount, TChainOverride, typeof ABI, typeof FUNCTION>) |
56 | 55 | } |
0 commit comments