import { optimismPortalABI } from '../../../constants/abi.js' import type { Account, Chain, ContractFunctionArgs, Transport, WalletClient, WriteContractParameters, WriteContractReturnType, } from 'viem' import { writeContract } from 'viem/actions' import { type RawOrContractAddress, resolveAddress } from '../../../types/addresses.js' import type { L1WriteActionBaseType } from '../../../types/l1Actions.js' import type { GetProveWithdrawalTransactionArgsReturnType } from '../../index.js' export const ABI = optimismPortalABI export const FUNCTION = 'proveWithdrawalTransaction' export type ProveWithdrawalTransactionParameters = GetProveWithdrawalTransactionArgsReturnType export type WriteProveWithdrawalTransactionParameters< TChain extends Chain | undefined = Chain, TAccount extends Account | undefined = Account | undefined, TChainOverride extends Chain | undefined = Chain | undefined, _chainId = TChain extends Chain ? TChain['id'] : number, > = & { args: ProveWithdrawalTransactionParameters; portal: RawOrContractAddress<_chainId> } & L1WriteActionBaseType< typeof ABI, typeof FUNCTION, ContractFunctionArgs, TChain, TAccount, TChainOverride > /** * Calls proveWithdrawalTransaction on the OptimismPortal contract. * Is the first L1 step of a withdrawal. * * @param parameters - {@link WriteProveWithdrawalTransactionParameters} * @returns A [Transaction Hash](https://viem.sh/docs/glossary/terms.html#hash). {@link WriteContractReturnType} */ export async function writeProveWithdrawalTransaction< TChain extends Chain | undefined, TAccount extends Account | undefined, TChainOverride extends Chain | undefined = undefined, >( client: WalletClient, { args: { withdrawalTransaction, L2OutputIndex, outputRootProof, withdrawalProof}, portal, ...rest }: WriteProveWithdrawalTransactionParameters< TChain, TAccount, TChainOverride >, ): Promise { return writeContract(client, { address: resolveAddress(portal), abi: ABI, functionName: FUNCTION, args: [withdrawalTransaction, L2OutputIndex, outputRootProof, withdrawalProof], ...rest, } as unknown as WriteContractParameters< typeof ABI, typeof FUNCTION, ContractFunctionArgs< typeof ABI, 'nonpayable', typeof FUNCTION >, TChain, TAccount, TChainOverride >) }