import { type Address, type Chain, type Client, type Hex, type SendTransactionParameters, type Transport, type TypedData, } from "viem"; import type { GetAccountParameter, GetEntryPointFromAccount, SmartContractAccount, } from "../../account/smartContractAccount"; import { buildUserOperation } from "../../actions/smartAccount/buildUserOperation.js"; import { buildUserOperationFromTx } from "../../actions/smartAccount/buildUserOperationFromTx.js"; import { buildUserOperationFromTxs } from "../../actions/smartAccount/buildUserOperationFromTxs.js"; import { checkGasSponsorshipEligibility, type CheckGasSponsorshipEligibilityResult, } from "../../actions/smartAccount/checkGasSponsorshipEligibility.js"; import { dropAndReplaceUserOperation } from "../../actions/smartAccount/dropAndReplaceUserOperation.js"; import { getAddress } from "../../actions/smartAccount/getAddress.js"; import { sendTransaction } from "../../actions/smartAccount/sendTransaction.js"; import { sendTransactions } from "../../actions/smartAccount/sendTransactions.js"; import { sendUserOperation } from "../../actions/smartAccount/sendUserOperation.js"; import { signMessage, type SignMessageParameters, } from "../../actions/smartAccount/signMessage.js"; import { signTypedData, type SignTypedDataParameters, } from "../../actions/smartAccount/signTypedData.js"; import { signUserOperation } from "../../actions/smartAccount/signUserOperation.js"; import type { BuildTransactionParameters, BuildUserOperationFromTransactionsResult, BuildUserOperationParameters, DropAndReplaceUserOperationParameters, SendTransactionsParameters, SendUserOperationParameters, SignUserOperationParameters, UpgradeAccountParams, UserOperationContext, WaitForUserOperationTxParameters, } from "../../actions/smartAccount/types"; import { upgradeAccount } from "../../actions/smartAccount/upgradeAccount.js"; import { waitForUserOperationTransaction } from "../../actions/smartAccount/waitForUserOperationTransacation.js"; import type { UserOperationOverrides, UserOperationRequest, UserOperationStruct, } from "../../types"; import type { IsUndefined } from "../../utils"; import type { SendUserOperationResult } from "../types"; //#region SmartAccountClientActions export type BaseSmartAccountClientActions< TChain extends Chain | undefined = Chain | undefined, TAccount extends SmartContractAccount | undefined = | SmartContractAccount | undefined, TContext extends UserOperationContext | undefined = | UserOperationContext | undefined, TEntryPointVersion extends GetEntryPointFromAccount = GetEntryPointFromAccount, > = { buildUserOperation: ( args: BuildUserOperationParameters, ) => Promise>; buildUserOperationFromTx: ( args: SendTransactionParameters, overrides?: UserOperationOverrides, context?: TContext, ) => Promise>; buildUserOperationFromTxs: ( args: BuildTransactionParameters, ) => Promise>; checkGasSponsorshipEligibility: < TContext extends UserOperationContext | undefined = | UserOperationContext | undefined, TEntryPointVersion extends GetEntryPointFromAccount = GetEntryPointFromAccount, >( args: SendUserOperationParameters, ) => Promise< CheckGasSponsorshipEligibilityResult >; signUserOperation: ( args: SignUserOperationParameters, ) => Promise>; dropAndReplaceUserOperation: ( args: DropAndReplaceUserOperationParameters, ) => Promise>; // TODO: for v4 we should combine override and context into an `opts` parameter // which wraps both of these properties so we can use GetContextParameter sendTransaction: ( args: SendTransactionParameters, overrides?: UserOperationOverrides, context?: TContext, ) => Promise; sendTransactions: ( args: SendTransactionsParameters, ) => Promise; sendUserOperation: ( args: SendUserOperationParameters< TAccount, TContext, GetEntryPointFromAccount >, ) => Promise>; waitForUserOperationTransaction: ( args: WaitForUserOperationTxParameters, ) => Promise; upgradeAccount: ( args: UpgradeAccountParams, ) => Promise; signMessage: (args: SignMessageParameters) => Promise; signTypedData: < const TTypedData extends TypedData | { [key: string]: unknown }, TPrimaryType extends string = string, >( args: SignTypedDataParameters, ) => Promise; } & (IsUndefined extends false ? { getAddress: () => Address } : { getAddress: (args: GetAccountParameter) => Address; }); // #endregion SmartAccountClientActions /** * Provides a set of smart account client actions to decorate the provided client. These actions include building and signing user operations, sending transactions, and more. * * NOTE: this is already added to clients returned from `createSmartAccountClient` * * @param {Client} client The client to bind the smart account actions to * @returns {BaseSmartAccountClientActions} An object containing various smart account client actions */ export const smartAccountClientActions: < TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends SmartContractAccount | undefined = | SmartContractAccount | undefined, TContext extends UserOperationContext | undefined = | UserOperationContext | undefined, >( client: Client, ) => BaseSmartAccountClientActions = (client) => ({ buildUserOperation: (args) => buildUserOperation(client, args), buildUserOperationFromTx: (args, overrides, context) => buildUserOperationFromTx(client, args, overrides, context), buildUserOperationFromTxs: (args) => buildUserOperationFromTxs(client, args), checkGasSponsorshipEligibility: (args) => checkGasSponsorshipEligibility(client, args), signUserOperation: (args) => signUserOperation(client, args), dropAndReplaceUserOperation: (args) => dropAndReplaceUserOperation(client, args), sendTransaction: (args, overrides, context) => sendTransaction(client, args, overrides, context), sendTransactions: (args) => sendTransactions(client, args), sendUserOperation: (args) => sendUserOperation(client, args), waitForUserOperationTransaction: (args) => waitForUserOperationTransaction.bind(client)(client, args), upgradeAccount: (args) => upgradeAccount(client, args), getAddress: (args) => getAddress(client, args), signMessage: (args) => signMessage(client, args), signTypedData: (args) => signTypedData(client, args), }); export const smartAccountClientMethodKeys = Object.keys( // @ts-expect-error we just want to get the keys smartAccountClientActions(undefined), ).reduce((accum, curr) => { accum.add(curr); return accum; }, new Set());