Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-evm): base LiFi class inheritance #991

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ packages/plugin-coinbase/package-lock.json
tsup.config.bundled_*.mjs

.turbo

# IDE
.vscode
.idea
45 changes: 45 additions & 0 deletions packages/plugin-evm/src/actions/baseLifi.ts
Original file line number Diff line number Diff line change
@@ -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[],
});
}
}
46 changes: 5 additions & 41 deletions packages/plugin-evm/src/actions/bridge.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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") {
Expand Down
55 changes: 5 additions & 50 deletions packages/plugin-evm/src/actions/swap.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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") {
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-evm/src/actions/transfer.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down