UNPKG

@biconomy/abstractjs

Version:

SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.

258 lines 11.8 kB
import type { Hex } from "viem"; import type { Instruction, MeeAuthorization } from "../clients/decorators/mee/getQuote"; import type { ComposabilityVersion, MEEVersion, PolicyData } from "../constants"; import type { ModularSmartAccount } from "../modules/utils/Types"; import { type BuildComposableInstructionTypes, type BuildInstructionTypes } from "./decorators/build"; import { type BuildActionPolicyParamTypes } from "./decorators/buildActionPolicy"; import { type BridgingInstructions, type MultichainBridgingParams } from "./decorators/buildBridgeInstructions"; import { type BuildSessionActionTypes, type SessionAction } from "./decorators/buildSessionAction"; import { type UnifiedERC20Balance } from "./decorators/getUnifiedERC20Balance"; import { type IsDelegatedParameters, type IsDelegatedPayload } from "./decorators/isDelegated"; import { type MultichainReadParameters, type MultiChainReadPayload } from "./decorators/multichainRead"; import { type OwnershipParams, type OwnershipParamsWithData, type OwnershipResult } from "./decorators/ownership"; import { type BridgeQueryResult, type QueryBridgeParams } from "./decorators/queryBridge"; import { type UnDelegateParameters, type UnDelegatePayload } from "./decorators/unDelegate"; import { type WaitForTransactionReceiptParameters, type WaitForTransactionReceiptPayload } from "./decorators/waitForTransactionReceipts"; import { type ChainConfiguration, type DelegationParams, type ToNexusSmartAccountParameters } from "./toNexusAccount"; import type { MultichainToken } from "./utils/Types"; import type { Signer } from "./utils/toSigner"; /** * Parameters required to create a multichain Nexus account */ export type MultichainNexusParams = Partial<Omit<ToNexusSmartAccountParameters, "signer" | "nexusContracts">> & { /** The signer instance used for account creation */ signer: ToNexusSmartAccountParameters["signer"]; /** Array of chain configuration */ chainConfigurations: ChainConfiguration[]; }; /** * Represents a smart account deployed across multiple chains */ export type BaseMultichainSmartAccount = { /** Array of minimal MEE smart account instances across different chains */ deployments: ModularSmartAccount[]; /** The signer associated with this multichain account */ signer: Signer; /** * Function to retrieve deployment information for a specific chain * @param chainId - The ID of the chain to query * @param strictMode - Whether to throw an error if no deployment exists for the specified chain * @returns The smart account deployment for the specified chain * @throws Error if no deployment exists for the specified chain and strictMode is true */ deploymentOn: { (chainId: number, strictMode: true): ModularSmartAccount; (chainId: number, strictMode?: false): ModularSmartAccount | undefined; }; /** * Function to retrieve the address of the account on a specific chain * @param chainId - The ID of the chain to query * @param strictMode - Whether to throw an error if no deployment exists for the specified chain * @returns The address of the account on the specified chain * @throws Error if no deployment exists for the specified chain and strictMode is true */ addressOn: { (chainId: number, strictMode: true): Hex; (chainId: number, strictMode?: false): Hex | undefined; }; }; export type MultichainSmartAccount = BaseMultichainSmartAccount & { /** * Function to retrieve the unified ERC20 balance across all deployments * @param mcToken - The multichain token to query * @returns The unified ERC20 balance across all deployments * @example * const balance = await mcAccount.getUnifiedERC20Balance(mcUSDC) */ getUnifiedERC20Balance: (mcToken: MultichainToken) => Promise<UnifiedERC20Balance>; /** * Function to build instructions for bridging a token across all deployments * @param params - The parameters for the balance requirement * @returns Instructions for any required bridging operations * @example * const instructions = await mcAccount.build({ * amount: BigInt(1000), * mcToken: mcUSDC, * toChain: base * }) */ build: (params: BuildInstructionTypes, currentInstructions?: Instruction[]) => Promise<Instruction[]>; /** * Function to build composable instructions * @param params - The parameters for the composable instruction * @returns Returns composable instructions * @example * const instructions = await mcAccount.build({ * amount: BigInt(1000), * mcToken: mcUSDC, * toChain: base * }) */ buildComposable: (params: BuildComposableInstructionTypes, currentInstructions?: Instruction[]) => Promise<Instruction[]>; /** * Function to build action policy for smart sessions * @param params - The parameters for the smart session action policies * @returns Action policy * @example * const actionPolicy = await mcAccount.buildActionPolicy({ * type: "sudo" * }) */ buildActionPolicy: (params: BuildActionPolicyParamTypes) => PolicyData; /** * Function to build actions for smart sessions * @param params - The parameters for the smart session actions * @returns Action * @example * const action = await mcAccount.buildSessionAction({ * type: "transfer", * data: { chainIds: [1, 10], contractAddress: "0x...", policies: [{ type: "sudo" }] } * }) */ buildSessionAction: (params: BuildSessionActionTypes) => SessionAction[]; /** * Function to build instructions for bridging a token across all deployments * @param params - The parameters for the balance requirement * @returns Instructions for any required bridging operations * @example * const instructions = await mcAccount.buildBridgeInstructions({ * amount: BigInt(1000), * mcToken: mcUSDC, * toChain: base * }) */ buildBridgeInstructions: (params: Omit<MultichainBridgingParams, "account">) => Promise<BridgingInstructions>; /** * Function to query the bridge * @param params - The parameters for the bridge query * @returns The bridge query result * @example * const result = await mcAccount.queryBridge({ * amount: BigInt(1000), * mcToken: mcUSDC, * toChain: base * }) */ queryBridge: (params: QueryBridgeParams) => Promise<BridgeQueryResult | null>; /** * Function to check if the account is delegated * @returns True if the account is delegated, false otherwise * @example * const isDelegated = await mcAccount.isDelegated() */ isDelegated: (parameter?: IsDelegatedParameters) => Promise<IsDelegatedPayload>; /** * Function to get the composability version for a specific chain * @param chainId - The ID of the chain to query * @returns The composability version of a given multichain account on the specified chain * @example * const composabilityVersion = await mcAccount.getComposabilityVersion(1) */ getComposabilityVersion: (chainId: number) => ComposabilityVersion; /** * Function to get the MEE version for a specific chain * @param chainId - The ID of the chain to query * @returns The MEE version of a given multichain account on the specified chain * @example * const meeVersion = await mcAccount.getMeeVersion(1) */ getMeeVersion: (chainId: number) => MEEVersion; /** * Function to undelegate the account * @returns The transaction hashes of the undelegate transactions * @example * const receipts = await mcAccount.unDelegate() */ unDelegate: (parameters?: UnDelegateParameters) => Promise<UnDelegatePayload>; /** * Function to wait for transaction receipts * @param hashes - The transaction hashes to wait for * @returns The transaction receipts * @example * const receipts = await mcAccount.waitForTransactionReceipts([hash1, hash2]) */ waitForTransactionReceipts: (parameters: WaitForTransactionReceiptParameters) => Promise<WaitForTransactionReceiptPayload>; /** * Function to read data across all deployments * @param params - The parameters for the read * @returns The read data */ read: <T>(params: MultichainReadParameters) => Promise<MultiChainReadPayload<T>[]>; /** * Function to get the delegation data for the account. * The chainId will be 0 for multi-chain authorization. * @returns The delegation data. * @example * const delegation = await mcAccount.toDelegation() */ toDelegation: (params?: DelegationParams) => Promise<MeeAuthorization>; /** * Creates instructions to set ownership data on the StxValidator across all chains. * Use this when no ownership data exists yet for the given ownership type. * @param params - Ownership type and optional ownership data override * @returns Instructions calling setOwnershipData on every configured chain */ addOwnership: (params: OwnershipParamsWithData) => Instruction[]; /** * Creates instructions to change existing ownership data on the StxValidator across all chains. * Reads current ownership data first and throws if none exists (use addOwnership instead). * @param params - Ownership type and optional ownership data override * @returns Instructions calling setOwnershipData on every configured chain */ changeOwnership: (params: OwnershipParamsWithData) => Promise<Instruction[]>; /** * Creates instructions to remove ownership data from the StxValidator across all chains. * @param params - Ownership type to clean, with optional chainIds filter * @returns Instructions calling cleanOwnershipData on every configured chain */ cleanOwnership: (params: OwnershipParams) => Instruction[]; /** * Reads ownership data from the StxValidator across all chains. * @param params - Ownership type to query, with optional chainIds filter * @returns Ownership data per chain */ getOwnership: (params: OwnershipParams) => Promise<OwnershipResult[]>; }; /** * Creates a multichain Nexus account across specified chains * * @param parameters - {@link MultichainNexusParams} Configuration for multichain account creation * @param parameters.signer - The signer instance used for account creation * @param parameters.chainConfigurations - Array of chain configuration objects where the account will be deployed * * @returns Promise resolving to {@link MultichainSmartAccount} instance * * @throws Error if account creation fails on any chain * * @example * const account = await toMultichainNexusAccount({ * signer: mySigner, * chainConfigurations: [ * { * chain: optimism, * transport: http(), * version: getMEEVersion(MEEversion.V2_1_0) * }, * { * chain: base, * transport: http(), * version: getMEEVersion(MEEversion.V2_1_0) * } * ] * }); * * // Get deployment on specific chain * const optimismDeployment = account.deploymentOn(10); * * // Check token balance across chains * const balance = await account.getUnifiedERC20Balance(mcUSDC); * * // Build bridge transaction * const bridgeInstructions = await account.buildBridgeInstructions({ * amount: BigInt("1000000"), // 1 USDC * mcToken: mcUSDC, * toChain: base * }); */ export declare function toMultichainNexusAccount(multiChainNexusParams: MultichainNexusParams): Promise<MultichainSmartAccount>; //# sourceMappingURL=toMultiChainNexusAccount.d.ts.map