UNPKG

1inch-agent-kit

Version:

AI Agent Kit for 1inch - Connect any LLM to 1inch DeFi protocols

183 lines 4.57 kB
/** * Wallet connection utility for 1inch Agent Kit * Handles both local JSON wallet (for scripts) and frontend wallet connections */ /** * Wallet interface for both local and frontend wallets */ export interface Wallet { address: string; chainId: number; privateKey?: string; isTestWallet?: boolean; name?: string; balance?: string; ensName?: string | null; walletType?: string; } /** * Wallet context for function calls */ export interface WalletContext { wallet: Wallet | null; isConnected: boolean; source: 'local' | 'frontend' | 'none'; } /** * Transaction parameters for signing and sending */ export interface TransactionParams { to: string; data: string; value: string | bigint; gasPrice?: string | bigint; gas?: string | bigint; nonce?: number; chainId?: number; } /** * Transaction result */ export interface TransactionResult { hash: string; from: string; to: string; data: string; value: string; gasPrice: string; gas: string; nonce: number; chainId: number; } /** * Wallet manager class */ export declare class WalletManager { private currentWallet; private walletSource; private localWalletPath; private ethersWallet; private provider; constructor(); /** * Initialize wallet - automatically detects if running in script mode or frontend mode */ initialize(frontendWallet?: Wallet): Promise<WalletContext>; /** * Load local wallet from JSON file */ private loadLocalWallet; /** * Initialize ethers wallet for transaction signing */ private initializeEthersWallet; /** * Get RPC URL for a given chain ID */ private getRpcUrl; /** * Set frontend wallet */ setFrontendWallet(wallet: Wallet): WalletContext; /** * Get current wallet context */ getWalletContext(): WalletContext; /** * Get wallet for specific chain (with validation) */ getWalletForChain(chainId: number): Wallet | null; /** * Check if wallet is connected */ isConnected(): boolean; /** * Get wallet address */ getAddress(): string | null; /** * Get wallet chain ID */ getChainId(): number | null; /** * Disconnect wallet */ disconnect(): void; /** * Create wallet parameters for function calls */ createWalletParams(overrides?: Partial<Wallet>): Wallet | null; /** * Sign and send a transaction * For local wallets: uses ethers.js to sign and send * For frontend wallets: returns transaction data for external signing */ signAndSendTransaction(params: TransactionParams): Promise<TransactionResult>; /** * Sign and send transaction using local ethers wallet */ private signAndSendLocalTransaction; /** * Prepare transaction data for frontend wallet signing */ private prepareTransactionForFrontend; /** * Sign a message */ signMessage(message: string): Promise<string>; /** * Sign EIP-712 typed data (for Fusion+ orders) */ signTypedData(typedData: any): Promise<string>; /** * Get wallet balance */ getBalance(): Promise<string>; /** * Get transaction count (nonce) */ getTransactionCount(): Promise<number>; } /** * Global wallet manager instance */ export declare const walletManager: WalletManager; /** * Utility functions for wallet operations */ export declare class WalletUtils { /** * Validate Ethereum address */ static isValidAddress(address: string): boolean; /** * Format address for display */ static formatAddress(address: string, startChars?: number, endChars?: number): string; /** * Get chain name from chain ID */ static getChainName(chainId: number): string; /** * Convert Wei to Ether */ static weiToEther(wei: string): string; /** * Convert Ether to Wei */ static etherToWei(ether: string): string; /** * Create a new wallet with private key */ static createWallet(privateKey: string, chainId?: number): Wallet; /** * Generate a new random wallet */ static generateWallet(chainId?: number): Wallet; } /** * Decorator function to inject wallet into function parameters */ export declare function withWallet<T extends (...args: any[]) => any>(fn: T, requireWallet?: boolean): T; export default walletManager; //# sourceMappingURL=wallet.d.ts.map