diff --git a/.gitignore b/.gitignore index b3d84f00fb7..21bb1feb4b7 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,7 @@ packages/plugin-coinbase/package-lock.json tsup.config.bundled_*.mjs .turbo + +# IDE +.vscode +.idea diff --git a/packages/plugin-evm/src/actions/baseLifi.ts b/packages/plugin-evm/src/actions/baseLifi.ts new file mode 100644 index 00000000000..f8df80b420c --- /dev/null +++ b/packages/plugin-evm/src/actions/baseLifi.ts @@ -0,0 +1,45 @@ +import { createConfig, type ExtendedChain, type SDKConfig } from "@lifi/sdk"; +import { getChainConfigs, WalletProvider } from "../providers/wallet"; + +export class BaseLifiAction { + protected config: SDKConfig; + + constructor(protected walletProvider: WalletProvider) { + this.config = createConfig({ + integrator: "eliza", + chains: Object.values( + getChainConfigs(this.walletProvider.runtime) + ).map((config) => ({ + id: config.chainId, + name: config.name, + key: config.name.toLowerCase(), + chainType: "EVM" as const, + nativeToken: { + ...config.nativeCurrency, + chainId: config.chainId, + address: "0x0000000000000000000000000000000000000000", + coinKey: config.nativeCurrency.symbol, + priceUSD: "0", + logoURI: "", + symbol: config.nativeCurrency.symbol, + decimals: config.nativeCurrency.decimals, + name: config.nativeCurrency.name, + }, + rpcUrls: { + public: { http: [config.rpcUrl] }, + }, + blockExplorerUrls: [config.blockExplorerUrl], + metamask: { + chainId: `0x${config.chainId.toString(16)}`, + chainName: config.name, + nativeCurrency: config.nativeCurrency, + rpcUrls: [config.rpcUrl], + blockExplorerUrls: [config.blockExplorerUrl], + }, + coin: config.nativeCurrency.symbol, + mainnet: true, + diamondAddress: "0x0000000000000000000000000000000000000000", + })) as ExtendedChain[], + }); + } +} diff --git a/packages/plugin-evm/src/actions/bridge.ts b/packages/plugin-evm/src/actions/bridge.ts index 3d0a38582d6..52237fa18c1 100644 --- a/packages/plugin-evm/src/actions/bridge.ts +++ b/packages/plugin-evm/src/actions/bridge.ts @@ -1,50 +1,14 @@ import type { IAgentRuntime, Memory, State } from "@ai16z/eliza"; -import { - ChainId, - createConfig, - executeRoute, - ExtendedChain, - getRoutes, -} from "@lifi/sdk"; +import { ChainId, executeRoute, getRoutes } from "@lifi/sdk"; + +import { BaseLifiAction } from "./baseLifi"; import { getChainConfigs, WalletProvider } from "../providers/wallet"; import { bridgeTemplate } from "../templates"; import type { BridgeParams, Transaction } from "../types"; export { bridgeTemplate }; -export class BridgeAction { - private config; - - constructor(private walletProvider: WalletProvider) { - this.config = createConfig({ - integrator: "eliza", - chains: Object.values( - getChainConfigs(this.walletProvider.runtime) - ).map((config) => ({ - id: config.chainId, - name: config.name, - key: config.name.toLowerCase(), - chainType: "EVM", - nativeToken: { - ...config.nativeCurrency, - chainId: config.chainId, - address: "0x0000000000000000000000000000000000000000", - coinKey: config.nativeCurrency.symbol, - }, - metamask: { - chainId: `0x${config.chainId.toString(16)}`, - chainName: config.name, - nativeCurrency: config.nativeCurrency, - rpcUrls: [config.rpcUrl], - blockExplorerUrls: [config.blockExplorerUrl], - }, - diamondAddress: "0x0000000000000000000000000000000000000000", - coin: config.nativeCurrency.symbol, - mainnet: true, - })) as ExtendedChain[], - }); - } - +export class BridgeAction extends BaseLifiAction { async bridge(params: BridgeParams): Promise<Transaction> { const walletClient = this.walletProvider.getWalletClient(); const [fromAddress] = await walletClient.getAddresses(); @@ -65,7 +29,7 @@ export class BridgeAction { if (!routes.routes.length) throw new Error("No routes found"); - const execution = await executeRoute(routes.routes[0], this.config); + const execution = await executeRoute(routes.routes[0]); const process = execution.steps[0]?.execution?.process[0]; if (!process?.status || process.status === "FAILED") { diff --git a/packages/plugin-evm/src/actions/swap.ts b/packages/plugin-evm/src/actions/swap.ts index 4bc23080942..8886329c0ac 100644 --- a/packages/plugin-evm/src/actions/swap.ts +++ b/packages/plugin-evm/src/actions/swap.ts @@ -1,59 +1,14 @@ import type { IAgentRuntime, Memory, State } from "@ai16z/eliza"; -import { - ChainId, - createConfig, - executeRoute, - ExtendedChain, - getRoutes, -} from "@lifi/sdk"; +import { ChainId, executeRoute, getRoutes } from "@lifi/sdk"; + +import { BaseLifiAction } from "./baseLifi"; import { getChainConfigs, WalletProvider } from "../providers/wallet"; import { swapTemplate } from "../templates"; import type { SwapParams, Transaction } from "../types"; export { swapTemplate }; -export class SwapAction { - private config; - - constructor(private walletProvider: WalletProvider) { - this.config = createConfig({ - integrator: "eliza", - chains: Object.values( - getChainConfigs(this.walletProvider.runtime) - ).map((config) => ({ - id: config.chainId, - name: config.name, - key: config.name.toLowerCase(), - chainType: "EVM" as const, - nativeToken: { - ...config.nativeCurrency, - chainId: config.chainId, - address: "0x0000000000000000000000000000000000000000", - coinKey: config.nativeCurrency.symbol, - priceUSD: "0", - logoURI: "", - symbol: config.nativeCurrency.symbol, - decimals: config.nativeCurrency.decimals, - name: config.nativeCurrency.name, - }, - rpcUrls: { - public: { http: [config.rpcUrl] }, - }, - blockExplorerUrls: [config.blockExplorerUrl], - metamask: { - chainId: `0x${config.chainId.toString(16)}`, - chainName: config.name, - nativeCurrency: config.nativeCurrency, - rpcUrls: [config.rpcUrl], - blockExplorerUrls: [config.blockExplorerUrl], - }, - coin: config.nativeCurrency.symbol, - mainnet: true, - diamondAddress: "0x0000000000000000000000000000000000000000", - })) as ExtendedChain[], - }); - } - +export class SwapAction extends BaseLifiAction { async swap(params: SwapParams): Promise<Transaction> { const walletClient = this.walletProvider.getWalletClient(); const [fromAddress] = await walletClient.getAddresses(); @@ -77,7 +32,7 @@ export class SwapAction { if (!routes.routes.length) throw new Error("No routes found"); - const execution = await executeRoute(routes.routes[0], this.config); + const execution = await executeRoute(routes.routes[0]); const process = execution.steps[0]?.execution?.process[0]; if (!process?.status || process.status === "FAILED") { diff --git a/packages/plugin-evm/src/actions/transfer.ts b/packages/plugin-evm/src/actions/transfer.ts index 18321097fe9..448e652e7d8 100644 --- a/packages/plugin-evm/src/actions/transfer.ts +++ b/packages/plugin-evm/src/actions/transfer.ts @@ -1,8 +1,9 @@ +import type { IAgentRuntime, Memory, State } from "@ai16z/eliza"; import { ByteArray, parseEther, type Hex } from "viem"; + import { WalletProvider } from "../providers/wallet"; -import type { Transaction, TransferParams } from "../types"; import { transferTemplate } from "../templates"; -import type { IAgentRuntime, Memory, State } from "@ai16z/eliza"; +import type { Transaction, TransferParams } from "../types"; export { transferTemplate }; export class TransferAction {