@biconomy/abstractjs
Version:
SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.
158 lines • 6.53 kB
TypeScript
import { type Account, type Address, type Chain, type ClientConfig, type Hex, type LocalAccount, type OneOf, type Prettify, type PublicClient, type RpcSchema, type Transport, type WalletClient } from "viem";
import { type SmartAccount, type SmartAccountImplementation, type UserOperation } from "viem/account-abstraction";
import type { SignAuthorizationReturnType } from "viem/accounts";
import type { MeeAuthorization } from "../clients/decorators/mee/getQuote";
import { EntrypointAbi } from "../constants/abi";
import type { ComposableCall } from "../modules/utils/composabilityCalls";
import type { Validator } from "../modules/validators/toValidator";
import type { Call } from "./utils/Types";
import { type EthersWallet } from "./utils/Utils";
import { type AddressConfigsAdditions, type NexusVersion } from "./utils/getVersion";
import { type EthereumProvider, type Signer } from "./utils/toSigner";
/**
* Base module configuration type
*/
export type MinimalModuleConfig = {
module: Address;
data: Hex;
};
/**
* Generic module configuration type that can be extended with additional properties
*/
export type GenericModuleConfig<T extends MinimalModuleConfig = MinimalModuleConfig> = T;
export type PrevalidationHookModuleConfig = GenericModuleConfig & {
hookType: bigint;
};
/**
* Parameters for creating a Nexus Smart Account
*/
export type ToNexusSmartAccountParameters = {
/** The blockchain network */
chain: Chain;
/** The transport configuration */
transport: ClientConfig["transport"];
/** The signer account or address */
signer: OneOf<EthereumProvider | WalletClient<Transport, Chain | undefined, Account> | LocalAccount | EthersWallet>;
/** Optional index for the account */
index?: bigint | undefined;
/** Optional account address override */
accountAddress?: Address;
/** Optional validator modules configuration */
validators?: Array<Validator>;
/** Optional executor modules configuration */
executors?: Array<GenericModuleConfig>;
/** Optional prevalidation hook modules configuration */
prevalidationHooks?: Array<PrevalidationHookModuleConfig>;
/** Optional hook module configuration */
hook?: GenericModuleConfig;
/** Optional fallback modules configuration */
fallbacks?: Array<GenericModuleConfig>;
/** Optional bootstrap address */
bootStrapAddress?: Address;
/** Optional implementation address */
implementationAddress?: Address;
/** Optional version of the Nexus Smart Account. If undefined, the latest version will be used. */
nexusVersion?: NexusVersion;
/** Optional factory address */
factoryAddress?: Address;
/** Optional init data */
initData?: Hex;
} & AddressConfigsAdditions[keyof AddressConfigsAdditions] & Prettify<Pick<ClientConfig<Transport, Chain, Account, RpcSchema>, "account" | "cacheTime" | "chain" | "key" | "name" | "pollingInterval" | "rpcSchema">>;
/**
* Nexus Smart Account type
*/
export type NexusAccount = Prettify<SmartAccount<NexusSmartAccountImplementation>>;
/**
* NonceInfo type
*/
export type NonceInfo = {
nonceKey: bigint;
nonce: bigint;
};
/**
* Delegation type
* @param authorization - Custom authorization to use. Optional
* @param delegatedContract - The contract address to delegate the authorization to. Defaults to the implementation address.
* @param multiChain - Whether to use the multi-chain authorization. Defaults to false.
*/
export type DelegationParams = {
authorization?: SignAuthorizationReturnType;
multiChain?: boolean;
delegatedContract?: Address;
};
/**
* UnDelegation type
* @param authorization - Custom authorization to use. Optional
*/
export type UnDelegationParams = {
authorization?: SignAuthorizationReturnType;
};
/**
* Nexus Smart Account Implementation
*/
export type NexusSmartAccountImplementation = SmartAccountImplementation<typeof EntrypointAbi, "0.7", {
/** Gets the counterfactual address of the account */
getAddress: () => Promise<Address>;
/** Gets the init code for the account */
getInitCode: () => Hex;
/** Gets the nonce with key for the account */
getNonceWithKey: (accountAddress: Address, parameters?: {
key?: bigint;
validationMode?: "0x00" | "0x01" | "0x02";
moduleAddress?: Address;
}) => Promise<NonceInfo>;
/** Encodes a single call for execution */
encodeExecute: (call: Call) => Promise<Hex>;
/** Encodes a batch of calls for execution */
encodeExecuteBatch: (calls: readonly Call[]) => Promise<Hex>;
/** Encodes a composable call for execution */
encodeExecuteComposable: (calls: ComposableCall[]) => Promise<Hex>;
/** Calculates the hash of a user operation */
getUserOpHash: (userOp: UserOperation) => Hex;
/** Factory data used for account creation */
factoryData: Hex;
/** Factory address used for account creation */
factoryAddress: Address;
/** The signer instance */
signer: Signer;
/** The public client instance */
publicClient: PublicClient;
/** The wallet client instance */
walletClient: WalletClient<Transport, Chain | undefined, Account, RpcSchema>;
/** The blockchain network */
chain: Chain;
/** Get the active module */
getModule: () => Validator;
/** Set the active module */
setModule: (validationModule: Validator) => void;
/** Get authorization data for the EOA to Nexus Account
* @param params - {@link DelegationParams}
* @returns MeeAuthorization
*/
toDelegation: (params?: DelegationParams) => Promise<MeeAuthorization>;
/** Execute the transaction to unauthorize the account
* @param params - {@link UnDelegationParams}
*/
unDelegate: (params?: UnDelegationParams) => Promise<Hex>;
/** Check if the account is delegated to the implementation address */
isDelegated: () => Promise<boolean>;
}>;
/**
* @description Create a Nexus Smart Account.
*
* @param parameters - {@link ToNexusSmartAccountParameters}
* @returns Nexus Smart Account. {@link NexusAccount}
*
* @example
* import { toNexusAccount } from '@biconomy/abstractjs'
* import { createWalletClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
*
* const account = await toNexusAccount({
* chain: mainnet,
* transport: http(),
* signer: '0x...',
* })
*/
export declare const toNexusAccount: (parameters: ToNexusSmartAccountParameters) => Promise<NexusAccount>;
//# sourceMappingURL=toNexusAccount.d.ts.map