|
| 1 | +import { ICacheManager, IAgentRuntime, Provider, Memory, State, Action, Plugin } from '@elizaos/core'; |
| 2 | +import { Hash, Address, Chain, PublicClient, HttpTransport, Account, WalletClient, PrivateKeyAccount } from 'viem'; |
| 3 | +import { Token } from '@lifi/types'; |
| 4 | +import * as viemChains from 'viem/chains'; |
| 5 | + |
| 6 | +declare const _SupportedChainList: Array<keyof typeof viemChains>; |
| 7 | +type SupportedChain = (typeof _SupportedChainList)[number]; |
| 8 | +interface Transaction { |
| 9 | + hash: Hash; |
| 10 | + from: Address; |
| 11 | + to: Address; |
| 12 | + value: bigint; |
| 13 | + data?: `0x${string}`; |
| 14 | + chainId?: number; |
| 15 | +} |
| 16 | +interface TokenWithBalance { |
| 17 | + token: Token; |
| 18 | + balance: bigint; |
| 19 | + formattedBalance: string; |
| 20 | + priceUSD: string; |
| 21 | + valueUSD: string; |
| 22 | +} |
| 23 | +interface WalletBalance { |
| 24 | + chain: SupportedChain; |
| 25 | + address: Address; |
| 26 | + totalValueUSD: string; |
| 27 | + tokens: TokenWithBalance[]; |
| 28 | +} |
| 29 | +interface ChainMetadata { |
| 30 | + chainId: number; |
| 31 | + name: string; |
| 32 | + chain: Chain; |
| 33 | + rpcUrl: string; |
| 34 | + nativeCurrency: { |
| 35 | + name: string; |
| 36 | + symbol: string; |
| 37 | + decimals: number; |
| 38 | + }; |
| 39 | + blockExplorerUrl: string; |
| 40 | +} |
| 41 | +interface ChainConfig { |
| 42 | + chain: Chain; |
| 43 | + publicClient: PublicClient<HttpTransport, Chain, Account | undefined>; |
| 44 | + walletClient?: WalletClient; |
| 45 | +} |
| 46 | +interface TransferParams { |
| 47 | + fromChain: SupportedChain; |
| 48 | + toAddress: Address; |
| 49 | + amount: string; |
| 50 | + data?: `0x${string}`; |
| 51 | +} |
| 52 | +interface SwapParams { |
| 53 | + chain: SupportedChain; |
| 54 | + fromToken: Address; |
| 55 | + toToken: Address; |
| 56 | + amount: string; |
| 57 | + slippage?: number; |
| 58 | +} |
| 59 | +interface BridgeParams { |
| 60 | + fromChain: SupportedChain; |
| 61 | + toChain: SupportedChain; |
| 62 | + fromToken: Address; |
| 63 | + toToken: Address; |
| 64 | + amount: string; |
| 65 | + toAddress?: Address; |
| 66 | +} |
| 67 | +interface EvmPluginConfig { |
| 68 | + rpcUrl?: { |
| 69 | + ethereum?: string; |
| 70 | + abstract?: string; |
| 71 | + base?: string; |
| 72 | + sepolia?: string; |
| 73 | + bsc?: string; |
| 74 | + arbitrum?: string; |
| 75 | + avalanche?: string; |
| 76 | + polygon?: string; |
| 77 | + optimism?: string; |
| 78 | + cronos?: string; |
| 79 | + gnosis?: string; |
| 80 | + fantom?: string; |
| 81 | + fraxtal?: string; |
| 82 | + klaytn?: string; |
| 83 | + celo?: string; |
| 84 | + moonbeam?: string; |
| 85 | + aurora?: string; |
| 86 | + harmonyOne?: string; |
| 87 | + moonriver?: string; |
| 88 | + arbitrumNova?: string; |
| 89 | + mantle?: string; |
| 90 | + linea?: string; |
| 91 | + scroll?: string; |
| 92 | + filecoin?: string; |
| 93 | + taiko?: string; |
| 94 | + zksync?: string; |
| 95 | + canto?: string; |
| 96 | + alienx?: string; |
| 97 | + }; |
| 98 | + secrets?: { |
| 99 | + EVM_PRIVATE_KEY: string; |
| 100 | + }; |
| 101 | + testMode?: boolean; |
| 102 | + multicall?: { |
| 103 | + batchSize?: number; |
| 104 | + wait?: number; |
| 105 | + }; |
| 106 | +} |
| 107 | +type LiFiStatus = { |
| 108 | + status: "PENDING" | "DONE" | "FAILED"; |
| 109 | + substatus?: string; |
| 110 | + error?: Error; |
| 111 | +}; |
| 112 | +type LiFiRoute = { |
| 113 | + transactionHash: Hash; |
| 114 | + transactionData: `0x${string}`; |
| 115 | + toAddress: Address; |
| 116 | + status: LiFiStatus; |
| 117 | +}; |
| 118 | +interface TokenData extends Token { |
| 119 | + symbol: string; |
| 120 | + decimals: number; |
| 121 | + address: Address; |
| 122 | + name: string; |
| 123 | + logoURI?: string; |
| 124 | + chainId: number; |
| 125 | +} |
| 126 | +interface TokenPriceResponse { |
| 127 | + priceUSD: string; |
| 128 | + token: TokenData; |
| 129 | +} |
| 130 | +interface TokenListResponse { |
| 131 | + tokens: TokenData[]; |
| 132 | +} |
| 133 | +interface ProviderError extends Error { |
| 134 | + code?: number; |
| 135 | + data?: unknown; |
| 136 | +} |
| 137 | + |
| 138 | +declare class WalletProvider { |
| 139 | + private cacheManager; |
| 140 | + private cache; |
| 141 | + private cacheKey; |
| 142 | + private currentChain; |
| 143 | + private CACHE_EXPIRY_SEC; |
| 144 | + chains: Record<string, Chain>; |
| 145 | + account: PrivateKeyAccount; |
| 146 | + constructor(accountOrPrivateKey: PrivateKeyAccount | `0x${string}`, cacheManager: ICacheManager, chains?: Record<string, Chain>); |
| 147 | + getAddress(): Address; |
| 148 | + getCurrentChain(): Chain; |
| 149 | + getPublicClient(chainName: SupportedChain): PublicClient<HttpTransport, Chain, Account | undefined>; |
| 150 | + getWalletClient(chainName: SupportedChain): WalletClient; |
| 151 | + getChainConfigs(chainName: SupportedChain): Chain; |
| 152 | + getWalletBalance(): Promise<string | null>; |
| 153 | + getWalletBalanceForChain(chainName: SupportedChain): Promise<string | null>; |
| 154 | + addChain(chain: Record<string, Chain>): void; |
| 155 | + switchChain(chainName: SupportedChain, customRpcUrl?: string): void; |
| 156 | + private readFromCache; |
| 157 | + private writeToCache; |
| 158 | + private getCachedData; |
| 159 | + private setCachedData; |
| 160 | + private setAccount; |
| 161 | + private setChains; |
| 162 | + private setCurrentChain; |
| 163 | + private createHttpTransport; |
| 164 | + static genChainFromName(chainName: string, customRpcUrl?: string | null): Chain; |
| 165 | +} |
| 166 | +declare const initWalletProvider: (runtime: IAgentRuntime) => Promise<WalletProvider>; |
| 167 | +declare const evmWalletProvider: Provider; |
| 168 | + |
| 169 | +declare const bridgeTemplate = "Given the recent messages and wallet information below:\n\n{{recentMessages}}\n\n{{walletInfo}}\n\nExtract the following information about the requested token bridge:\n- Token symbol or address to bridge\n- Source chain\n- Destination chain\n- Amount to bridge: Must be a string representing the amount in ether (only number without coin symbol, e.g., \"0.1\")\n- Destination address (if specified)\n\nRespond with a JSON markdown block containing only the extracted values:\n\n```json\n{\n \"token\": string | null,\n \"fromChain\": \"ethereum\" | \"abstract\" | \"base\" | \"sepolia\" | \"bsc\" | \"arbitrum\" | \"avalanche\" | \"polygon\" | \"optimism\" | \"cronos\" | \"gnosis\" | \"fantom\" | \"fraxtal\" | \"klaytn\" | \"celo\" | \"moonbeam\" | \"aurora\" | \"harmonyOne\" | \"moonriver\" | \"arbitrumNova\" | \"mantle\" | \"linea\" | \"scroll\" | \"filecoin\" | \"taiko\" | \"zksync\" | \"canto\" | \"alienx\" | null,\n \"toChain\": \"ethereum\" | \"abstract\" | \"base\" | \"sepolia\" | \"bsc\" | \"arbitrum\" | \"avalanche\" | \"polygon\" | \"optimism\" | \"cronos\" | \"gnosis\" | \"fantom\" | \"fraxtal\" | \"klaytn\" | \"celo\" | \"moonbeam\" | \"aurora\" | \"harmonyOne\" | \"moonriver\" | \"arbitrumNova\" | \"mantle\" | \"linea\" | \"scroll\" | \"filecoin\" | \"taiko\" | \"zksync\" | \"canto\" | \"alienx\" | null,\n \"amount\": string | null,\n \"toAddress\": string | null\n}\n```\n"; |
| 170 | +declare const swapTemplate = "Given the recent messages and wallet information below:\n\n{{recentMessages}}\n\n{{walletInfo}}\n\nExtract the following information about the requested token swap:\n- Input token symbol or address (the token being sold)\n- Output token symbol or address (the token being bought)\n- Amount to swap: Must be a string representing the amount in ether (only number without coin symbol, e.g., \"0.1\")\n- Chain to execute on\n\nRespond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined:\n\n```json\n{\n \"inputToken\": string | null,\n \"outputToken\": string | null,\n \"amount\": string | null,\n \"chain\": \"ethereum\" | \"abstract\" | \"base\" | \"sepolia\" | \"bsc\" | \"arbitrum\" | \"avalanche\" | \"polygon\" | \"optimism\" | \"cronos\" | \"gnosis\" | \"fantom\" | \"klaytn\" | \"celo\" | \"moonbeam\" | \"aurora\" | \"harmonyOne\" | \"moonriver\" | \"arbitrumNova\" | \"mantle\" | \"linea\" | \"scroll\" | \"filecoin\" | \"taiko\" | \"zksync\" | \"canto\" | \"alienx\" | null,\n \"slippage\": number | null\n}\n```\n"; |
| 171 | + |
| 172 | +declare class BridgeAction { |
| 173 | + private walletProvider; |
| 174 | + private config; |
| 175 | + constructor(walletProvider: WalletProvider); |
| 176 | + bridge(params: BridgeParams): Promise<Transaction>; |
| 177 | +} |
| 178 | +declare const bridgeAction: { |
| 179 | + name: string; |
| 180 | + description: string; |
| 181 | + handler: (runtime: IAgentRuntime, _message: Memory, state: State, _options: any, callback?: any) => Promise<boolean>; |
| 182 | + template: string; |
| 183 | + validate: (runtime: IAgentRuntime) => Promise<boolean>; |
| 184 | + examples: { |
| 185 | + user: string; |
| 186 | + content: { |
| 187 | + text: string; |
| 188 | + action: string; |
| 189 | + }; |
| 190 | + }[][]; |
| 191 | + similes: string[]; |
| 192 | +}; |
| 193 | + |
| 194 | +declare class SwapAction { |
| 195 | + private walletProvider; |
| 196 | + private config; |
| 197 | + constructor(walletProvider: WalletProvider); |
| 198 | + swap(params: SwapParams): Promise<Transaction>; |
| 199 | +} |
| 200 | +declare const swapAction: { |
| 201 | + name: string; |
| 202 | + description: string; |
| 203 | + handler: (runtime: IAgentRuntime, _message: Memory, state: State, _options: any, callback?: any) => Promise<boolean>; |
| 204 | + template: string; |
| 205 | + validate: (runtime: IAgentRuntime) => Promise<boolean>; |
| 206 | + examples: { |
| 207 | + user: string; |
| 208 | + content: { |
| 209 | + text: string; |
| 210 | + action: string; |
| 211 | + }; |
| 212 | + }[][]; |
| 213 | + similes: string[]; |
| 214 | +}; |
| 215 | + |
| 216 | +declare class TransferAction { |
| 217 | + private walletProvider; |
| 218 | + constructor(walletProvider: WalletProvider); |
| 219 | + transfer(params: TransferParams): Promise<Transaction>; |
| 220 | +} |
| 221 | +declare const transferAction: Action; |
| 222 | + |
| 223 | +declare const evmPlugin: Plugin; |
| 224 | + |
| 225 | +export { BridgeAction, type BridgeParams, type ChainConfig, type ChainMetadata, type EvmPluginConfig, type LiFiRoute, type LiFiStatus, type ProviderError, type SupportedChain, SwapAction, type SwapParams, type TokenData, type TokenListResponse, type TokenPriceResponse, type TokenWithBalance, type Transaction, TransferAction, type TransferParams, type WalletBalance, WalletProvider, bridgeAction, bridgeTemplate, evmPlugin as default, evmPlugin, evmWalletProvider, initWalletProvider, swapAction, swapTemplate, transferAction }; |
0 commit comments