import "@ethersproject/shims"; import { BigNumber, BigNumberish } from 'ethers'; import { Provider } from '@ethersproject/providers'; import { UserOperationStruct } from '@account-abstraction/contracts'; import { TransactionDetailsForUserOp } from './TransactionDetailsForUserOp'; import { PaymasterAPI } from './PaymasterAPI'; import { NotPromise } from '@account-abstraction/utils'; import { GasOverheads } from './calcPreVerificationGas'; export interface BaseApiParams { provider: Provider; entryPointAddress: string; walletAddress?: string; overheads?: Partial; paymasterAPI?: PaymasterAPI; } export interface UserOpResult { transactionHash: string; success: boolean; } /** * Base class for all Smart Wallet ERC-4337 Clients to implement. * Subclass should inherit 5 methods to support a specific wallet contract: * * - getWalletInitCode - return the value to put into the "initCode" field, if the wallet is not yet deployed. should create the wallet instance using a factory contract. * - getNonce - return current wallet's nonce value * - encodeExecute - encode the call from entryPoint through our wallet to the target contract. * - signRequestId - sign the requestId of a UserOp. * * The user can use the following APIs: * - createUnsignedUserOp - given "target" and "calldata", fill userOp to perform that operation from the wallet. * - createSignedUserOp - helper to call the above createUnsignedUserOp, and then extract the requestId and sign it */ export declare abstract class BaseWalletAPI { private senderAddress; private isPhantom; private readonly entryPointView; provider: Provider; overheads?: Partial; entryPointAddress: string; walletAddress?: string; paymasterAPI?: PaymasterAPI; /** * base constructor. * subclass SHOULD add parameters that define the owner (signer) of this wallet */ protected constructor(params: BaseApiParams); init(): Promise; /** * return the value to put into the "initCode" field, if the wallet is not yet deployed. * this value holds the "factory" address, followed by this wallet's information */ abstract getWalletInitCode(): Promise; /** * return current wallet's nonce. */ abstract getNonce(): Promise; /** * encode the call from entryPoint through our wallet to the target contract. * @param target * @param value * @param data */ abstract encodeExecute(target: string, value: BigNumberish, data: string): Promise; /** * sign a userOp's hash (requestId). * @param requestId */ abstract signRequestId(requestId: string): Promise; /** * check if the wallet is already deployed. */ checkWalletPhantom(): Promise; /** * calculate the wallet address even before it is deployed */ getCounterFactualAddress(): Promise; /** * return initCode value to into the UserOp. * (either deployment code, or empty hex if contract already deployed) */ getInitCode(): Promise; /** * return maximum gas used for verification. * NOTE: createUnsignedUserOp will add to this value the cost of creation, if the wallet is not yet created. */ getVerificationGasLimit(): Promise; /** * should cover cost of putting calldata on-chain, and some overhead. * actual overhead depends on the expected bundle size */ getPreVerificationGas(userOp: Partial): Promise; /** * ABI-encode a user operation. used for calldata cost estimation */ packUserOp(userOp: NotPromise): string; encodeUserOpCallDataAndGasLimit(detailsForUserOp: TransactionDetailsForUserOp): Promise<{ callData: string; callGasLimit: BigNumber; }>; /** * return requestId for signing. * This value matches entryPoint.getRequestId (calculated off-chain, to avoid a view call) * @param userOp userOperation, (signature field ignored) */ getRequestId(userOp: UserOperationStruct): Promise; /** * return the wallet's address. * this value is valid even before deploying the wallet. */ getWalletAddress(): Promise; /** * create a UserOperation, filling all details (except signature) * - if wallet is not yet created, add initCode to deploy it. * - if gas or nonce are missing, read them from the chain (note that we can't fill gaslimit before the wallet is created) * @param info */ createUnsignedUserOp(info: TransactionDetailsForUserOp): Promise; /** * Sign the filled userOp. * @param userOp the UserOperation to sign (with signature field ignored) */ signUserOp(userOp: UserOperationStruct): Promise; /** * helper method: create and sign a user operation. * @param info transaction details for the userOp */ createSignedUserOp(info: TransactionDetailsForUserOp): Promise; /** * get the transaction that has this requestId mined, or null if not found * @param requestId returned by sendUserOpToBundler (or by getRequestId..) * @param timeout stop waiting after this timeout * @param interval time to wait between polls. * @return the transactionHash this userOp was mined, or null if not found. */ getUserOpReceipt(requestId: string, timeout?: number, interval?: number): Promise; }