import type { Account, Address, Chain, ContractFunctionArgs, PublicClient, SimulateContractParameters, SimulateContractReturnType, Transport, } from 'viem' import { simulateContract } from 'viem/actions' import { type RawOrContractAddress, resolveAddress } from '../../../types/addresses.js' import { ABI, type DepositERC20Parameters, FUNCTION } from '../../../types/depositERC20.js' import type { L1SimulateActionBaseType } from '../../../types/l1Actions.js' export type SimulateDepositERC20Parameters< TChain extends Chain | undefined = Chain, TChainOverride extends Chain | undefined = Chain | undefined, TAccountOverride extends Account | Address | undefined = undefined, _chainId = TChain extends Chain ? TChain['id'] : number, > = & { args: DepositERC20Parameters; l1StandardBridge: RawOrContractAddress<_chainId> } & L1SimulateActionBaseType< typeof ABI, typeof FUNCTION, ContractFunctionArgs, TChain, TChainOverride, TAccountOverride > export type SimulateDepositERC20ReturnType< TChain extends Chain | undefined = Chain | undefined, TAccount extends Account | undefined = Account | undefined, TChainOverride extends Chain | undefined = Chain | undefined, TAccountOverride extends Account | Address | undefined = | Account | Address | undefined, > = SimulateContractReturnType< typeof ABI, typeof FUNCTION, ContractFunctionArgs, TChain, TAccount, TChainOverride, TAccountOverride > /** * Simulates a deposit of ERC20 tokens to L2 * @param parameters - {@link SimulateDepositERC20Parameters} * @returns A [Transaction Hash](https://viem.sh/docs/glossary/terms.html#hash). {@link WriteContractReturnType} */ export async function simulateDepositERC20< TChain extends Chain | undefined, TAccount extends Account | undefined, TChainOverride extends Chain | undefined, TAccountOverride extends Account | Address | undefined = undefined, >( client: PublicClient, { args: { l1Token, l2Token, to, amount, minGasLimit, extraData = '0x' }, l1StandardBridge, ...rest }: SimulateDepositERC20Parameters, ): Promise< SimulateContractReturnType< typeof ABI, typeof FUNCTION, ContractFunctionArgs, TChain, TAccount, TChainOverride, TAccountOverride > > { return simulateContract(client, { address: resolveAddress(l1StandardBridge), abi: ABI, functionName: FUNCTION, args: [l1Token, l2Token, to, amount, minGasLimit, extraData], ...rest, } as unknown as SimulateContractParameters< typeof ABI, typeof FUNCTION, ContractFunctionArgs, TChain, TChainOverride, TAccountOverride >) as unknown as SimulateContractReturnType< typeof ABI, typeof FUNCTION, ContractFunctionArgs, TChain, TAccount, TChainOverride, TAccountOverride > }