You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.9 KiB
53 lines
1.9 KiB
import { writeContract, } from '../../actions/wallet/writeContract.js';
|
|
import { portal2Abi } from '../abis.js';
|
|
/**
|
|
* Proves a withdrawal that occurred on an L2. Used in the Withdrawal flow.
|
|
*
|
|
* - Docs: https://viem.sh/op-stack/actions/proveWithdrawal
|
|
*
|
|
* @param client - Client to use
|
|
* @param parameters - {@link ProveWithdrawalParameters}
|
|
* @returns The prove transaction hash. {@link ProveWithdrawalReturnType}
|
|
*
|
|
* @example
|
|
* import { createWalletClient, http } from 'viem'
|
|
* import { mainnet, optimism } from 'viem/chains'
|
|
* import { proveWithdrawal } from 'viem/op-stack'
|
|
*
|
|
* const walletClientL1 = createWalletClient({
|
|
* chain: mainnet,
|
|
* transport: http(),
|
|
* })
|
|
*
|
|
* const request = await proveWithdrawal(walletClientL1, {
|
|
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
|
* l2OutputIndex: 4529n,
|
|
* outputRootProof: { ... },
|
|
* targetChain: optimism,
|
|
* withdrawalProof: [ ... ],
|
|
* withdrawal: { ... },
|
|
* })
|
|
*/
|
|
export async function proveWithdrawal(client, parameters) {
|
|
const { account, chain = client.chain, gas, l2OutputIndex, maxFeePerGas, maxPriorityFeePerGas, nonce, outputRootProof, targetChain, withdrawalProof, withdrawal, } = parameters;
|
|
const portalAddress = (() => {
|
|
if (parameters.portalAddress)
|
|
return parameters.portalAddress;
|
|
if (chain)
|
|
return targetChain.contracts.portal[chain.id].address;
|
|
return Object.values(targetChain.contracts.portal)[0].address;
|
|
})();
|
|
return writeContract(client, {
|
|
account: account,
|
|
abi: portal2Abi,
|
|
address: portalAddress,
|
|
chain,
|
|
functionName: 'proveWithdrawalTransaction',
|
|
args: [withdrawal, l2OutputIndex, outputRootProof, withdrawalProof],
|
|
gas: gas ?? undefined,
|
|
maxFeePerGas,
|
|
maxPriorityFeePerGas,
|
|
nonce,
|
|
});
|
|
}
|
|
//# sourceMappingURL=proveWithdrawal.js.map
|