Skip to content

Commit 5420b6a

Browse files
committed
Initial commit
1 parent 29fc7e5 commit 5420b6a

25 files changed

Lines changed: 6026 additions & 168 deletions

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,71 @@ Swap tokens on the same chain using LiFi:
111111
Swap 1 ETH for USDC on Base
112112
```
113113

114+
### 4. Propose
115+
116+
Propose a proposal to a governor on a specific chain.
117+
118+
- **Proposal**
119+
- **Targets**
120+
- **Values**
121+
- **Calldatas**
122+
- **Description**
123+
- **Chain**
124+
- **Governor**
125+
126+
**Example usage:**
127+
128+
```bash
129+
Propose a proposal to the 0xdeadbeef00000000000000000000000000000000 governor on Ethereum to transfer 1 ETH to 0xRecipient.
130+
```
131+
132+
### 5. Vote
133+
134+
Vote on a proposal to a governor on a specific chain.
135+
136+
- **Proposal ID**
137+
- **Support**
138+
- **Chain**
139+
- **Governor**
140+
141+
**Example usage:**
142+
143+
```bash
144+
Vote on the proposal with ID 1 to support the proposal on the 0xdeadbeef00000000000000000000000000000000 governor on Ethereum.
145+
```
146+
147+
### 6. Queue
148+
149+
Queue a proposal to a governor on a specific chain.
150+
151+
- **Proposal**
152+
- **Targets**
153+
- **Values**
154+
- **Calldatas**
155+
- **Description**
156+
- **Chain**
157+
- **Governor**
158+
159+
**Example usage:**
160+
161+
```bash
162+
Queue the proposal to the 0xdeadbeef00000000000000000000000000000000 governor on Ethereum.
163+
```
164+
165+
### 7. Execute
166+
167+
Execute a proposal to a governor on a specific chain.
168+
169+
- **Proposal ID**
170+
- **Chain**
171+
- **Governor**
172+
173+
**Example usage:**
174+
175+
```bash
176+
Execute the proposal with ID 1 on the 0xdeadbeef00000000000000000000000000000000 governor on Ethereum.
177+
```
178+
114179
## Development
115180

116181
1. Clone the repository

biome.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
3+
"organizeImports": {
4+
"enabled": false
5+
},
6+
"linter": {
7+
"enabled": true,
8+
"rules": {
9+
"recommended": true,
10+
"correctness": {
11+
"noUnusedVariables": "error"
12+
},
13+
"suspicious": {
14+
"noExplicitAny": "error"
15+
},
16+
"style": {
17+
"useConst": "error",
18+
"useImportType": "off"
19+
}
20+
}
21+
},
22+
"formatter": {
23+
"enabled": true,
24+
"indentStyle": "space",
25+
"indentWidth": 4,
26+
"lineWidth": 100
27+
},
28+
"javascript": {
29+
"formatter": {
30+
"quoteStyle": "single",
31+
"trailingCommas": "es5"
32+
}
33+
},
34+
"files": {
35+
"ignore": [
36+
"dist/**/*",
37+
"extra/**/*",
38+
"node_modules/**/*"
39+
]
40+
}
41+
}

eslint.config.mjs

Lines changed: 0 additions & 3 deletions
This file was deleted.

package.json

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,44 @@
11
{
2-
"name": "@elizaos-plugins/plugin-evm",
3-
"version": "0.1.8+build.1",
4-
"type": "module",
5-
"main": "dist/index.js",
6-
"module": "dist/index.js",
7-
"types": "dist/index.d.ts",
8-
"exports": {
9-
"./package.json": "./package.json",
10-
"./plugin.json": "./plugin.json",
11-
".": {
12-
"import": {
13-
"@elizaos/source": "./src/index.ts",
14-
"types": "./dist/index.d.ts",
15-
"default": "./dist/index.js"
16-
}
17-
}
18-
},
19-
"files": [
20-
"dist",
21-
"plugin.json"
22-
],
23-
"dependencies": {
24-
"@lifi/data-types": "5.15.5",
25-
"@lifi/sdk": "3.4.1",
26-
"@lifi/types": "16.3.0",
27-
"tsup": "8.3.5"
28-
},
29-
"scripts": {
30-
"build": "tsup --format esm --dts",
31-
"dev": "tsup --format esm --dts --watch",
32-
"test": "vitest run",
33-
"lint": "eslint --fix --cache ."
34-
},
35-
"peerDependencies": {
36-
"whatwg-url": "7.1.0"
37-
},
38-
"agentConfig": {
39-
"pluginType": "elizaos:plugin:1.0.0",
40-
"pluginParameters": {
41-
"EVM_PRIVATE_KEY": {
42-
"type": "string"
43-
},
44-
"EVM_PROVIDER_URL": {
45-
"type": "string"
46-
}
47-
}
48-
}
49-
}
2+
"name": "@elizaos/plugin-evm",
3+
"version": "0.1.9",
4+
"type": "module",
5+
"main": "dist/index.js",
6+
"module": "dist/index.js",
7+
"types": "dist/index.d.ts",
8+
"exports": {
9+
"./package.json": "./package.json",
10+
".": {
11+
"import": {
12+
"@elizaos/source": "./src/index.ts",
13+
"types": "./dist/index.d.ts",
14+
"default": "./dist/index.js"
15+
}
16+
}
17+
},
18+
"files": [
19+
"dist"
20+
],
21+
"dependencies": {
22+
"@elizaos/core": "workspace:*",
23+
"@elizaos/plugin-tee": "workspace:*",
24+
"@lifi/data-types": "5.15.5",
25+
"@lifi/sdk": "3.4.1",
26+
"@lifi/types": "16.3.0",
27+
"tsup": "8.3.5"
28+
},
29+
"devDependencies": {
30+
"@biomejs/biome": "1.9.4"
31+
},
32+
"scripts": {
33+
"build": "tsup --format esm --dts",
34+
"dev": "tsup --format esm --dts --watch",
35+
"test": "vitest run",
36+
"lint": "biome lint .",
37+
"lint:fix": "biome check --apply .",
38+
"format": "biome format .",
39+
"format:fix": "biome format --write ."
40+
},
41+
"peerDependencies": {
42+
"whatwg-url": "7.1.0"
43+
}
44+
}

src/actions/bridge.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { IAgentRuntime, Memory, State } from "@elizaos/core";
1+
import type { IAgentRuntime, Memory, State, HandlerCallback } from "@elizaos/core";
22
import {
33
composeContext,
44
generateObjectDeprecated,
@@ -7,11 +7,11 @@ import {
77
import {
88
createConfig,
99
executeRoute,
10-
ExtendedChain,
10+
type ExtendedChain,
1111
getRoutes,
1212
} from "@lifi/sdk";
1313

14-
import { initWalletProvider, WalletProvider } from "../providers/wallet";
14+
import { initWalletProvider, type WalletProvider } from "../providers/wallet";
1515
import { bridgeTemplate } from "../templates";
1616
import type { BridgeParams, Transaction } from "../types";
1717
import { parseEther } from "viem";
@@ -93,8 +93,8 @@ export const bridgeAction = {
9393
runtime: IAgentRuntime,
9494
_message: Memory,
9595
state: State,
96-
_options: any,
97-
callback?: any
96+
_options: Record<string, unknown>,
97+
callback?: HandlerCallback
9898
) => {
9999
console.log("Bridge action handler called");
100100
const walletProvider = await initWalletProvider(runtime);

src/actions/gov-execute.ts

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import type { IAgentRuntime, Memory, State, HandlerCallback } from "@elizaos/core";
2+
import { WalletProvider } from "../providers/wallet";
3+
import { executeProposalTemplate } from "../templates";
4+
import type { ExecuteProposalParams, SupportedChain, Transaction } from "../types";
5+
import governorArtifacts from "../contracts/artifacts/OZGovernor.json";
6+
import {
7+
type ByteArray,
8+
type Hex,
9+
type Address,
10+
encodeFunctionData,
11+
keccak256,
12+
stringToHex,
13+
} from "viem";
14+
15+
export { executeProposalTemplate };
16+
17+
export class ExecuteAction {
18+
constructor(private walletProvider: WalletProvider) {
19+
this.walletProvider = walletProvider;
20+
}
21+
22+
async execute(params: ExecuteProposalParams): Promise<Transaction> {
23+
const walletClient = this.walletProvider.getWalletClient(params.chain);
24+
25+
const descriptionHash = keccak256(stringToHex(params.description));
26+
27+
const txData = encodeFunctionData({
28+
abi: governorArtifacts.abi,
29+
functionName: "execute",
30+
args: [
31+
params.targets,
32+
params.values,
33+
params.calldatas,
34+
descriptionHash,
35+
],
36+
});
37+
38+
try {
39+
const chainConfig = this.walletProvider.getChainConfigs(
40+
params.chain
41+
);
42+
43+
// Log current block before sending transaction
44+
const publicClient = this.walletProvider.getPublicClient(
45+
params.chain
46+
);
47+
48+
const hash = await walletClient.sendTransaction({
49+
account: walletClient.account,
50+
to: params.governor,
51+
value: BigInt(0),
52+
data: txData as Hex,
53+
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+
});
66+
67+
const receipt = await publicClient.waitForTransactionReceipt({
68+
hash,
69+
});
70+
71+
return {
72+
hash,
73+
from: walletClient.account.address,
74+
to: params.governor,
75+
value: BigInt(0),
76+
data: txData as Hex,
77+
chainId: this.walletProvider.getChainConfigs(params.chain).id,
78+
logs: receipt.logs,
79+
};
80+
} catch (error) {
81+
throw new Error(`Vote failed: ${error.message}`);
82+
}
83+
}
84+
}
85+
86+
export const executeAction = {
87+
name: "execute",
88+
description: "Execute a DAO governance proposal",
89+
handler: async (
90+
runtime: IAgentRuntime,
91+
_message: Memory,
92+
_state: State,
93+
options: Record<string, unknown>,
94+
callback?: HandlerCallback
95+
) => {
96+
try {
97+
// Validate required fields
98+
if (!options.chain || !options.governor || !options.proposalId ||
99+
!options.targets || !options.values || !options.calldatas || !options.description) {
100+
throw new Error("Missing required parameters for execute proposal");
101+
}
102+
103+
// Convert options to ExecuteProposalParams
104+
const executeParams: ExecuteProposalParams = {
105+
chain: options.chain as SupportedChain,
106+
governor: options.governor as Address,
107+
proposalId: String(options.proposalId),
108+
targets: options.targets as Address[],
109+
values: (options.values as string[]).map(v => BigInt(v)),
110+
calldatas: options.calldatas as `0x${string}`[],
111+
description: String(options.description)
112+
};
113+
114+
const privateKey = runtime.getSetting(
115+
"EVM_PRIVATE_KEY"
116+
) as `0x${string}`;
117+
const walletProvider = new WalletProvider(
118+
privateKey,
119+
runtime.cacheManager
120+
);
121+
const action = new ExecuteAction(walletProvider);
122+
return await action.execute(executeParams);
123+
} catch (error) {
124+
console.error("Error in execute handler:", error.message);
125+
if (callback) {
126+
callback({ text: `Error: ${error.message}` });
127+
}
128+
return false;
129+
}
130+
},
131+
template: executeProposalTemplate,
132+
validate: async (runtime: IAgentRuntime) => {
133+
const privateKey = runtime.getSetting("EVM_PRIVATE_KEY");
134+
return typeof privateKey === "string" && privateKey.startsWith("0x");
135+
},
136+
examples: [
137+
[
138+
{
139+
user: "user",
140+
content: {
141+
text: "Execute proposal 123 on the governor at 0x1234567890123456789012345678901234567890 on Ethereum",
142+
action: "EXECUTE_PROPOSAL",
143+
},
144+
},
145+
],
146+
],
147+
similes: ["EXECUTE_PROPOSAL", "GOVERNANCE_EXECUTE"],
148+
}; // TODO: add more examples

0 commit comments

Comments
 (0)