Skip to content

Commit bfff849

Browse files
authored
Merge pull request #9 from elizaos-plugins/pr-7
fix issue with import & tsconfig
2 parents 1349632 + 8942a7c commit bfff849

14 files changed

Lines changed: 2497 additions & 440 deletions

File tree

bun.lock

Lines changed: 2114 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@
2222
"dist"
2323
],
2424
"dependencies": {
25-
"@elizaos/core-plugin-v2": "^1.0.0-beta",
26-
"@elizaos/plugin-tee": "^1.0.0-beta",
25+
"@elizaos/core": "^1.0.0",
2726
"@lifi/data-types": "5.15.5",
28-
"@lifi/sdk": "3.4.1",
29-
"@lifi/types": "16.3.0"
27+
"@lifi/sdk": "^3.7.3",
28+
"@lifi/types": "^17.16.0",
29+
"tsup": "8.3.5"
3030
},
3131
"devDependencies": {
3232
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
3333
"hardhat": "^2.22.19",
3434
"prettier": "3.5.3",
3535
"ts-node": "10.9.2",
3636
"tslib": "2.8.1",
37-
"tsup": "^8.4.0",
3837
"typescript": "5.8.2",
3938
"vitest": "^3.1.1"
4039
},

src/actions/bridge.ts

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
import type {
2-
HandlerCallback,
3-
IAgentRuntime,
4-
Memory,
5-
State,
6-
} from "@elizaos/core-plugin-v2";
7-
import { composePrompt, ModelType } from "@elizaos/core-plugin-v2";
8-
import {
9-
type ExtendedChain,
10-
createConfig,
11-
executeRoute,
12-
getRoutes,
13-
} from "@lifi/sdk";
14-
15-
import { parseEther } from "viem";
16-
import { type WalletProvider, initWalletProvider } from "../providers/wallet";
17-
import { bridgeTemplate } from "../templates";
18-
import type { BridgeParams, Transaction } from "../types";
1+
import type { HandlerCallback, IAgentRuntime, Memory, State } from '@elizaos/core-plugin-v2';
2+
import { composePrompt, ModelType } from '@elizaos/core-plugin-v2';
3+
import { type ExtendedChain, createConfig, executeRoute, getRoutes } from '@lifi/sdk';
4+
5+
import { parseEther } from 'viem';
6+
import { type WalletProvider, initWalletProvider } from '../providers/wallet';
7+
import { bridgeTemplate } from '../templates';
8+
import type { BridgeParams, Transaction } from '../types';
199

2010
export { bridgeTemplate };
2111

@@ -24,26 +14,26 @@ export class BridgeAction {
2414

2515
constructor(private walletProvider: WalletProvider) {
2616
this.config = createConfig({
27-
integrator: "eliza",
17+
integrator: 'eliza',
2818
chains: Object.values(this.walletProvider.chains).map((config) => ({
2919
id: config.id,
3020
name: config.name,
3121
key: config.name.toLowerCase(),
32-
chainType: "EVM",
22+
chainType: 'EVM',
3323
nativeToken: {
3424
...config.nativeCurrency,
3525
chainId: config.id,
36-
address: "0x0000000000000000000000000000000000000000",
26+
address: '0x0000000000000000000000000000000000000000',
3727
coinKey: config.nativeCurrency.symbol,
3828
},
3929
metamask: {
4030
chainId: `0x${config.id.toString(16)}`,
4131
chainName: config.name,
4232
nativeCurrency: config.nativeCurrency,
4333
rpcUrls: [config.rpcUrls.default.http[0]],
44-
blockExplorerUrls: [config.blockExplorers?.default.url],
34+
blockExplorerUrls: [config?.blockExplorers?.default?.url],
4535
},
46-
diamondAddress: "0x0000000000000000000000000000000000000000",
36+
diamondAddress: '0x0000000000000000000000000000000000000000',
4737
coin: config.nativeCurrency.symbol,
4838
mainnet: true,
4939
})) as ExtendedChain[],
@@ -64,13 +54,13 @@ export class BridgeAction {
6454
toAddress: params.toAddress || fromAddress,
6555
});
6656

67-
if (!routes.routes.length) throw new Error("No routes found");
57+
if (!routes.routes.length) throw new Error('No routes found');
6858

6959
const execution = await executeRoute(routes.routes[0], this.config as any);
7060
const process = execution.steps[0]?.execution?.process[0];
7161

72-
if (!process?.status || process.status === "FAILED") {
73-
throw new Error("Transaction failed");
62+
if (!process?.status || process.status === 'FAILED') {
63+
throw new Error('Transaction failed');
7464
}
7565

7666
return {
@@ -89,7 +79,7 @@ const buildBridgeDetails = async (
8979
wp: WalletProvider
9080
): Promise<BridgeParams> => {
9181
const chains = wp.getSupportedChains();
92-
state.supportedChains = chains.map((item) => `"${item}"`).join("|");
82+
state.supportedChains = chains.map((item) => `"${item}"`).join('|');
9383

9484
// Add balances to state for better context in template
9585
const balances = await wp.getWalletBalances();
@@ -98,7 +88,7 @@ const buildBridgeDetails = async (
9888
const chainConfig = wp.getChainConfigs(chain as any);
9989
return `${chain}: ${balance} ${chainConfig.nativeCurrency.symbol}`;
10090
})
101-
.join(", ");
91+
.join(', ');
10292

10393
// Compose bridge context
10494
const bridgeContext = composePrompt({
@@ -116,13 +106,13 @@ const buildBridgeDetails = async (
116106

117107
if (!wp.chains[fromChain]) {
118108
throw new Error(
119-
`Source chain ${fromChain} not configured. Available chains: ${chains.join(", ")}`
109+
`Source chain ${fromChain} not configured. Available chains: ${chains.join(', ')}`
120110
);
121111
}
122112

123113
if (!wp.chains[toChain]) {
124114
throw new Error(
125-
`Destination chain ${toChain} not configured. Available chains: ${chains.join(", ")}`
115+
`Destination chain ${toChain} not configured. Available chains: ${chains.join(', ')}`
126116
);
127117
}
128118

@@ -139,25 +129,25 @@ const buildBridgeDetails = async (
139129
};
140130

141131
export const bridgeAction = {
142-
name: "EVM_BRIDGE_TOKENS",
143-
description: "Bridge tokens between different chains",
132+
name: 'EVM_BRIDGE_TOKENS',
133+
description: 'Bridge tokens between different chains',
144134
handler: async (
145135
runtime: IAgentRuntime,
146136
_message: Memory,
147-
state: State,
148-
_options: Record<string, unknown>,
137+
state?: State,
138+
_options?: Record<string, unknown>,
149139
callback?: HandlerCallback
150140
) => {
151141
const walletProvider = await initWalletProvider(runtime);
152142
const action = new BridgeAction(walletProvider);
153143

144+
if (!state) {
145+
state = await runtime.composeState(_message);
146+
}
147+
154148
try {
155149
// Get bridge parameters
156-
const bridgeOptions = await buildBridgeDetails(
157-
state,
158-
runtime,
159-
walletProvider
160-
);
150+
const bridgeOptions = await buildBridgeDetails(state, runtime, walletProvider);
161151

162152
const bridgeResp = await action.bridge(bridgeOptions);
163153
if (callback) {
@@ -173,33 +163,36 @@ export const bridgeAction = {
173163
});
174164
}
175165
return true;
176-
} catch (error: unknown) {
177-
const errMsg = error instanceof Error ? error.message : String(error);
178-
console.error("Error in bridge handler:", errMsg);
166+
} catch (error) {
167+
console.error(
168+
'Error in bridge handler:',
169+
error instanceof Error ? error.message : 'Unknown error'
170+
);
179171
if (callback) {
180172
callback({
181-
text: `Error: ${errMsg}`,
182-
content: { error: errMsg },
173+
text: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`,
174+
content: { error: error instanceof Error ? error.message : 'Unknown error' },
183175
});
184176
}
185177
return false;
186178
}
187179
},
188180
template: bridgeTemplate,
189181
validate: async (runtime: IAgentRuntime) => {
190-
const privateKey = runtime.getSetting("EVM_PRIVATE_KEY");
191-
return typeof privateKey === "string" && privateKey.startsWith("0x");
182+
const privateKey = runtime.getSetting('EVM_PRIVATE_KEY');
183+
return typeof privateKey === 'string' && privateKey.startsWith('0x');
192184
},
193185
examples: [
194186
[
195187
{
196-
user: "user",
188+
name: 'user',
189+
user: 'user',
197190
content: {
198-
text: "Bridge 1 ETH from Ethereum to Base",
199-
action: "CROSS_CHAIN_TRANSFER",
191+
text: 'Bridge 1 ETH from Ethereum to Base',
192+
action: 'CROSS_CHAIN_TRANSFER',
200193
},
201194
},
202195
],
203196
],
204-
similes: ["CROSS_CHAIN_TRANSFER", "CHAIN_BRIDGE", "MOVE_CROSS_CHAIN"],
197+
similes: ['CROSS_CHAIN_TRANSFER', 'CHAIN_BRIDGE', 'MOVE_CROSS_CHAIN'],
205198
};

src/actions/gov-execute.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export class ExecuteAction {
3131
async execute(params: ExecuteProposalParams): Promise<Transaction> {
3232
const walletClient = this.walletProvider.getWalletClient(params.chain);
3333

34+
if (!walletClient.account) {
35+
throw new Error('Wallet account is not available');
36+
}
37+
3438
const descriptionHash = keccak256(stringToHex(params.description));
3539

3640
const txData = encodeFunctionData({
@@ -51,18 +55,7 @@ export class ExecuteAction {
5155
value: BigInt(0),
5256
data: txData as Hex,
5357
chain: chainConfig,
54-
kzg: {
55-
blobToKzgCommitment: (_blob: ByteArray): ByteArray => {
56-
throw new Error("Function not implemented.");
57-
},
58-
computeBlobKzgProof: (
59-
_blob: ByteArray,
60-
_commitment: ByteArray
61-
): ByteArray => {
62-
throw new Error("Function not implemented.");
63-
},
64-
},
65-
} as any);
58+
});
6659

6760
const receipt = await publicClient.waitForTransactionReceipt({
6861
hash,
@@ -78,9 +71,8 @@ export class ExecuteAction {
7871
logs: receipt.logs,
7972
};
8073
} catch (error: unknown) {
81-
throw new Error(
82-
`Vote failed: ${error instanceof Error ? error.message : String(error)}`
83-
);
74+
const errorMessage = error instanceof Error ? error.message : String(error);
75+
throw new Error(`Vote failed: ${errorMessage}`);
8476
}
8577
}
8678
}
@@ -124,14 +116,11 @@ export const executeAction = {
124116
const walletProvider = new WalletProvider(privateKey, runtime);
125117
const action = new ExecuteAction(walletProvider);
126118
return await action.execute(executeParams);
127-
} catch (error) {
128-
const errMsg = error instanceof Error ? error.message : String(error);
129-
console.error("Error in execute handler:", errMsg);
119+
} catch (error: unknown) {
120+
const errorMessage = error instanceof Error ? error.message : String(error);
121+
console.error('Error in execute handler:', errorMessage);
130122
if (callback) {
131-
callback({
132-
text: `Error: ${errMsg}`,
133-
content: { error: errMsg },
134-
});
123+
callback({ text: `Error: ${errorMessage}` });
135124
}
136125
return false;
137126
}

src/actions/gov-propose.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export class ProposeAction {
2929
async propose(params: ProposeProposalParams): Promise<Transaction> {
3030
const walletClient = this.walletProvider.getWalletClient(params.chain);
3131

32+
if (!walletClient.account) {
33+
throw new Error('Wallet account is not available');
34+
}
35+
3236
const txData = encodeFunctionData({
3337
abi: governorArtifacts.abi,
3438
functionName: "propose",
@@ -52,18 +56,7 @@ export class ProposeAction {
5256
value: BigInt(0),
5357
data: txData as Hex,
5458
chain: chainConfig,
55-
kzg: {
56-
blobToKzgCommitment: (_blob: ByteArray): ByteArray => {
57-
throw new Error("Function not implemented.");
58-
},
59-
computeBlobKzgProof: (
60-
_blob: ByteArray,
61-
_commitment: ByteArray
62-
): ByteArray => {
63-
throw new Error("Function not implemented.");
64-
},
65-
},
66-
} as any);
59+
});
6760

6861
const receipt = await publicClient.waitForTransactionReceipt({
6962
hash,
@@ -79,9 +72,8 @@ export class ProposeAction {
7972
logs: receipt.logs,
8073
};
8174
} catch (error: unknown) {
82-
throw new Error(
83-
`Vote failed: ${error instanceof Error ? error.message : String(error)}`
84-
);
75+
const errorMessage = error instanceof Error ? error.message : String(error);
76+
throw new Error(`Vote failed: ${errorMessage}`);
8577
}
8678
}
8779
}
@@ -124,14 +116,10 @@ export const proposeAction = {
124116
const action = new ProposeAction(walletProvider);
125117
return await action.propose(proposeParams);
126118
} catch (error: unknown) {
127-
console.error(
128-
"Error in propose handler:",
129-
error instanceof Error ? error.message : String(error)
130-
);
119+
const errorMessage = error instanceof Error ? error.message : String(error);
120+
console.error('Error in propose handler:', errorMessage);
131121
if (callback) {
132-
callback({
133-
text: `Error: ${error instanceof Error ? error.message : String(error)}`,
134-
});
122+
callback({ text: `Error: ${errorMessage}` });
135123
}
136124
return false;
137125
}

0 commit comments

Comments
 (0)