UNPKG

@coinbase/agentkit

Version:

Coinbase AgentKit core primitives

149 lines (148 loc) 5.18 kB
import { CdpClient, EvmSmartAccount, EvmServerAccount } from "@coinbase/cdp-sdk"; import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, PublicClient, ReadContractParameters, ReadContractReturnType, TransactionRequest, LocalAccount } from "viem"; import { Network } from "../network"; import { EvmWalletProvider } from "./evmWalletProvider"; import { WalletProviderWithClient, CdpSmartWalletProviderConfig } from "./cdpShared"; /** * Supported network types for CDP SDK smart wallet operations */ type CdpSmartWalletNetwork = "base" | "base-sepolia" | "ethereum" | "ethereum-sepolia" | "polygon" | "arbitrum" | "optimism"; /** * A wallet provider that uses the Coinbase CDP SDK smart wallets. */ export declare class CdpSmartWalletProvider extends EvmWalletProvider implements WalletProviderWithClient { #private; smartAccount: EvmSmartAccount; ownerAccount: LocalAccount | EvmServerAccount; /** * Constructs a new CdpSmartWalletProvider. * * @param config - The configuration options for the CdpSmartWalletProvider. */ private constructor(); /** * Configures a new CdpSmartWalletProvider with a smart wallet. * * @param config - Optional configuration parameters * @returns A Promise that resolves to a new CdpSmartWalletProvider instance * @throws Error if required environment variables are missing or wallet initialization fails */ static configureWithWallet(config?: CdpSmartWalletProviderConfig): Promise<CdpSmartWalletProvider>; /** * Exports the wallet. * * @returns The wallet's data. */ exportWallet(): Promise<{ name: string | undefined; address: Address; ownerAddress: Address; }>; /** * Signs a raw hash using the owner account. * * @param _hash - The hash to sign. * @returns The signed hash. */ sign(_hash: Hex): Promise<Hex>; /** * Signs a message using the owner account. * * @param _message - The message to sign. * @returns The signed message. */ signMessage(_message: string): Promise<Hex>; /** * Signs a typed data object using the owner account. * * @param typedData - The typed data object to sign. * @returns The signed typed data object. */ signTypedData(typedData: any): Promise<Hex>; /** * Signs a transaction using the owner account. * * @param _ - The transaction to sign. * @returns The signed transaction. */ signTransaction(_: TransactionRequest): Promise<Hex>; /** * Sends a user operation through the smart wallet. * * @param transaction - The transaction to send. * @returns The user operation hash. */ sendTransaction(transaction: TransactionRequest): Promise<Hex>; /** * Gets the address of the smart wallet. * * @returns The address of the smart wallet. */ getAddress(): string; /** * Gets the network of the wallet. * * @returns The network of the wallet. */ getNetwork(): Network; /** * Gets the name of the wallet provider. * * @returns The name of the wallet provider. */ getName(): string; /** * Gets the CDP client. * * @returns The CDP client. */ getClient(): CdpClient; /** * Gets the paymaster URL for gasless transactions. * * @returns The paymaster URL if configured, undefined otherwise. */ getPaymasterUrl(): string | undefined; /** * Gets the Viem PublicClient used for read-only operations. * * @returns The Viem PublicClient instance used for read-only operations. */ getPublicClient(): PublicClient; /** * Gets the balance of the smart wallet. * * @returns The balance of the wallet in wei */ getBalance(): Promise<bigint>; /** * Waits for a user operation receipt. * * @param userOpHash - The user operation hash to wait for. * @returns The user operation receipt. */ waitForTransactionReceipt(userOpHash: Hex): Promise<any>; /** * Reads a contract. * * @param params - The parameters to read the contract. * @returns The response from the contract. */ readContract<const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName<abi, "pure" | "view">, const args extends ContractFunctionArgs<abi, "pure" | "view", functionName>>(params: ReadContractParameters<abi, functionName, args>): Promise<ReadContractReturnType<abi, functionName, args>>; /** * Transfer the native asset of the network using smart wallet. * * @param to - The destination address. * @param value - The amount to transfer in atomic units (Wei). * @returns The user operation hash. */ nativeTransfer(to: Address, value: string): Promise<Hex>; /** * Converts the internal network ID to the format expected by the CDP SDK. * * @returns The network ID in CDP SDK format * @throws Error if the network is not supported */ getCdpSdkNetwork(): CdpSmartWalletNetwork; } export {};