Skip to content

Commit b139995

Browse files
authored
Merge pull request elizaOS#1171 from nicky-ru/develop
fix: add lint script for plugin evm and fix lint errors
2 parents c675e9d + 7c11963 commit b139995

File tree

8 files changed

+61
-67
lines changed

8 files changed

+61
-67
lines changed

packages/plugin-evm/eslint.config.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintGlobalConfig from "../../eslint.config.mjs";
2+
3+
export default [...eslintGlobalConfig];

packages/plugin-evm/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"scripts": {
1616
"build": "tsup --format esm --dts",
1717
"dev": "tsup --format esm --dts --watch",
18-
"test": "vitest run"
18+
"test": "vitest run",
19+
"lint": "eslint --fix --cache ."
1920
},
2021
"peerDependencies": {
2122
"whatwg-url": "7.1.0"

packages/plugin-evm/src/actions/swap.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { IAgentRuntime, Memory, State } from "@ai16z/eliza";
22
import {
3-
ChainId,
43
createConfig,
54
executeRoute,
65
ExtendedChain,

packages/plugin-evm/src/actions/transfer.ts

+11-24
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class TransferAction {
2828
params.data = "0x";
2929
}
3030

31-
await this.walletProvider.switchChain(params.fromChain);
31+
this.walletProvider.switchChain(params.fromChain);
3232

3333
const walletClient = this.walletProvider.getWalletClient(
3434
params.fromChain
@@ -41,12 +41,12 @@ export class TransferAction {
4141
value: parseEther(params.amount),
4242
data: params.data as Hex,
4343
kzg: {
44-
blobToKzgCommitment: function (blob: ByteArray): ByteArray {
44+
blobToKzgCommitment: function (_: ByteArray): ByteArray {
4545
throw new Error("Function not implemented.");
4646
},
4747
computeBlobKzgProof: function (
48-
blob: ByteArray,
49-
commitment: ByteArray
48+
_blob: ByteArray,
49+
_commitment: ByteArray
5050
): ByteArray {
5151
throw new Error("Function not implemented.");
5252
},
@@ -81,7 +81,7 @@ const buildTransferDetails = async (
8181

8282
const contextWithChains = context.replace(
8383
"SUPPORTED_CHAINS",
84-
chains.toString()
84+
chains.map((item) => `"${item}"`).join("|")
8585
);
8686

8787
const transferDetails = (await generateObjectDeprecated({
@@ -109,34 +109,21 @@ export const transferAction = {
109109
description: "Transfer tokens between addresses on the same chain",
110110
handler: async (
111111
runtime: IAgentRuntime,
112-
message: Memory,
112+
_message: Memory,
113113
state: State,
114-
options: any,
114+
_options: any,
115115
callback?: HandlerCallback
116116
) => {
117117
console.log("Transfer action handler called");
118118
const walletProvider = initWalletProvider(runtime);
119119
const action = new TransferAction(walletProvider);
120120

121121
// Compose transfer context
122-
const transferContext = composeContext({
122+
const paramOptions = await buildTransferDetails(
123123
state,
124-
template: transferTemplate,
125-
});
126-
127-
// Generate transfer content
128-
const content = await generateObjectDeprecated({
129124
runtime,
130-
context: transferContext,
131-
modelClass: ModelClass.LARGE,
132-
});
133-
134-
const paramOptions: TransferParams = {
135-
fromChain: content.fromChain,
136-
toAddress: content.toAddress,
137-
amount: content.amount,
138-
data: content.data,
139-
};
125+
walletProvider
126+
);
140127

141128
try {
142129
const transferResp = await action.transfer(paramOptions);
@@ -148,7 +135,7 @@ export const transferAction = {
148135
hash: transferResp.hash,
149136
amount: formatEther(transferResp.value),
150137
recipient: transferResp.to,
151-
chain: content.fromChain,
138+
chain: paramOptions.fromChain,
152139
},
153140
});
154141
}

packages/plugin-evm/src/providers/wallet.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ export const initWalletProvider = (runtime: IAgentRuntime) => {
211211
export const evmWalletProvider: Provider = {
212212
async get(
213213
runtime: IAgentRuntime,
214-
message: Memory,
215-
state?: State
214+
_message: Memory,
215+
_state?: State
216216
): Promise<string | null> {
217217
try {
218218
const walletProvider = initWalletProvider(runtime);

packages/plugin-evm/src/tests/transfer.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe("Transfer Action", () => {
1717
it("should initialize with wallet provider", () => {
1818
const ta = new TransferAction(wp);
1919

20-
expect(ta).to.toBeDefined();
20+
expect(ta).toBeDefined();
2121
});
2222
});
2323
describe("Transfer", () => {
@@ -44,7 +44,7 @@ describe("Transfer Action", () => {
4444
});
4545

4646
const prepareChains = () => {
47-
let customChains: Record<string, Chain> = {};
47+
const customChains: Record<string, Chain> = {};
4848
const chainNames = ["iotexTestnet"];
4949
chainNames.forEach(
5050
(chain) =>

packages/plugin-evm/src/tests/wallet.test.ts

+39-35
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const customRpcUrls = {
1313
describe("Wallet provider", () => {
1414
let walletProvider: WalletProvider;
1515
let pk: `0x${string}`;
16-
let customChains: Record<string, Chain> = {};
16+
const customChains: Record<string, Chain> = {};
1717

1818
beforeAll(() => {
1919
pk = generatePrivateKey();
@@ -32,24 +32,24 @@ describe("Wallet provider", () => {
3232

3333
walletProvider = new WalletProvider(pk);
3434

35-
expect(walletProvider.getAddress()).to.be.eq(expectedAddress);
35+
expect(walletProvider.getAddress()).toEqual(expectedAddress);
3636
});
3737
it("sets default chain to ethereum mainnet", () => {
3838
walletProvider = new WalletProvider(pk);
3939

40-
expect(walletProvider.chains.mainnet.id).to.be.eq(mainnet.id);
41-
expect(walletProvider.getCurrentChain().id).to.be.eq(mainnet.id);
40+
expect(walletProvider.chains.mainnet.id).toEqual(mainnet.id);
41+
expect(walletProvider.getCurrentChain().id).toEqual(mainnet.id);
4242
});
4343
it("sets custom chains", () => {
4444
walletProvider = new WalletProvider(pk, customChains);
4545

46-
expect(walletProvider.chains.iotex.id).to.be.eq(iotex.id);
47-
expect(walletProvider.chains.arbitrum.id).to.be.eq(arbitrum.id);
46+
expect(walletProvider.chains.iotex.id).toEqual(iotex.id);
47+
expect(walletProvider.chains.arbitrum.id).toEqual(arbitrum.id);
4848
});
4949
it("sets the first provided custom chain as current chain", () => {
5050
walletProvider = new WalletProvider(pk, customChains);
5151

52-
expect(walletProvider.getCurrentChain().id).to.be.eq(iotex.id);
52+
expect(walletProvider.getCurrentChain().id).toEqual(iotex.id);
5353
});
5454
});
5555
describe("Clients", () => {
@@ -58,7 +58,7 @@ describe("Wallet provider", () => {
5858
});
5959
it("generates public client", () => {
6060
const client = walletProvider.getPublicClient("mainnet");
61-
expect(client.chain.id).to.be.equal(mainnet.id);
61+
expect(client.chain.id).toEqual(mainnet.id);
6262
expect(client.transport.url).toEqual(
6363
mainnet.rpcUrls.default.http[0]
6464
);
@@ -71,11 +71,11 @@ describe("Wallet provider", () => {
7171
const wp = new WalletProvider(pk, { ["mainnet"]: chain });
7272

7373
const client = wp.getPublicClient("mainnet");
74-
expect(client.chain.id).to.be.equal(mainnet.id);
75-
expect(client.chain.rpcUrls.default.http[0]).to.eq(
74+
expect(client.chain.id).toEqual(mainnet.id);
75+
expect(client.chain.rpcUrls.default.http[0]).toEqual(
7676
mainnet.rpcUrls.default.http[0]
7777
);
78-
expect(client.chain.rpcUrls.custom.http[0]).to.eq(
78+
expect(client.chain.rpcUrls.custom.http[0]).toEqual(
7979
customRpcUrls.mainnet
8080
);
8181
expect(client.transport.url).toEqual(customRpcUrls.mainnet);
@@ -86,7 +86,7 @@ describe("Wallet provider", () => {
8686

8787
const client = walletProvider.getWalletClient("mainnet");
8888

89-
expect(client.account.address).to.be.equal(expectedAddress);
89+
expect(client.account.address).toEqual(expectedAddress);
9090
expect(client.transport.url).toEqual(
9191
mainnet.rpcUrls.default.http[0]
9292
);
@@ -102,12 +102,12 @@ describe("Wallet provider", () => {
102102

103103
const client = wp.getWalletClient("mainnet");
104104

105-
expect(client.account.address).to.be.equal(expectedAddress);
106-
expect(client.chain.id).to.be.equal(mainnet.id);
107-
expect(client.chain.rpcUrls.default.http[0]).to.eq(
105+
expect(client.account.address).toEqual(expectedAddress);
106+
expect(client.chain.id).toEqual(mainnet.id);
107+
expect(client.chain.rpcUrls.default.http[0]).toEqual(
108108
mainnet.rpcUrls.default.http[0]
109109
);
110-
expect(client.chain.rpcUrls.custom.http[0]).to.eq(
110+
expect(client.chain.rpcUrls.custom.http[0]).toEqual(
111111
customRpcUrls.mainnet
112112
);
113113
expect(client.transport.url).toEqual(customRpcUrls.mainnet);
@@ -120,16 +120,16 @@ describe("Wallet provider", () => {
120120
it("should fetch balance", async () => {
121121
const bal = await walletProvider.getWalletBalance();
122122

123-
expect(bal).to.be.eq("0");
123+
expect(bal).toEqual("0");
124124
});
125125
it("should fetch balance for a specific added chain", async () => {
126126
const bal = await walletProvider.getWalletBalanceForChain("iotex");
127127

128-
expect(bal).to.be.eq("0");
128+
expect(bal).toEqual("0");
129129
});
130130
it("should return null if chain is not added", async () => {
131131
const bal = await walletProvider.getWalletBalanceForChain("base");
132-
expect(bal).to.be.null;
132+
expect(bal).toBeNull();
133133
});
134134
});
135135
describe("Chain", () => {
@@ -140,7 +140,7 @@ describe("Wallet provider", () => {
140140
const chainName = "iotex";
141141
const chain: Chain = WalletProvider.genChainFromName(chainName);
142142

143-
expect(chain.rpcUrls.default.http[0]).to.eq(
143+
expect(chain.rpcUrls.default.http[0]).toEqual(
144144
iotex.rpcUrls.default.http[0]
145145
);
146146
});
@@ -152,59 +152,63 @@ describe("Wallet provider", () => {
152152
customRpcUrl
153153
);
154154

155-
expect(chain.rpcUrls.default.http[0]).to.eq(
155+
expect(chain.rpcUrls.default.http[0]).toEqual(
156156
iotex.rpcUrls.default.http[0]
157157
);
158-
expect(chain.rpcUrls.custom.http[0]).to.eq(customRpcUrl);
158+
expect(chain.rpcUrls.custom.http[0]).toEqual(customRpcUrl);
159159
});
160160
it("switches chain", () => {
161161
const initialChain = walletProvider.getCurrentChain().id;
162-
expect(initialChain).to.be.eq(iotex.id);
162+
expect(initialChain).toEqual(iotex.id);
163163

164164
walletProvider.switchChain("mainnet");
165165

166166
const newChain = walletProvider.getCurrentChain().id;
167-
expect(newChain).to.be.eq(mainnet.id);
167+
expect(newChain).toEqual(mainnet.id);
168168
});
169169
it("switches chain (by adding new chain)", () => {
170170
const initialChain = walletProvider.getCurrentChain().id;
171-
expect(initialChain).to.be.eq(iotex.id);
171+
expect(initialChain).toEqual(iotex.id);
172172

173173
walletProvider.switchChain("arbitrum");
174174

175175
const newChain = walletProvider.getCurrentChain().id;
176-
expect(newChain).to.be.eq(arbitrum.id);
176+
expect(newChain).toEqual(arbitrum.id);
177177
});
178178
it("adds chain", () => {
179179
const initialChains = walletProvider.chains;
180-
expect(initialChains.base).to.be.undefined;
180+
expect(initialChains.base).toBeUndefined();
181181

182182
const base = WalletProvider.genChainFromName("base");
183183
walletProvider.addChain({ base });
184184
const newChains = walletProvider.chains;
185-
expect(newChains.arbitrum.id).to.be.eq(arbitrum.id);
185+
expect(newChains.arbitrum.id).toEqual(arbitrum.id);
186186
});
187187
it("gets chain configs", () => {
188188
const chain = walletProvider.getChainConfigs("iotex");
189189

190-
expect(chain.id).to.eq(iotex.id);
190+
expect(chain.id).toEqual(iotex.id);
191191
});
192192
it("throws if tries to switch to an invalid chain", () => {
193193
const initialChain = walletProvider.getCurrentChain().id;
194-
expect(initialChain).to.be.eq(iotex.id);
194+
expect(initialChain).toEqual(iotex.id);
195195

196+
// intentionally set incorrect chain, ts will complain
197+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
196198
// @ts-ignore
197-
expect(() => walletProvider.switchChain("eth")).to.throw();
199+
expect(() => walletProvider.switchChain("eth")).toThrow();
198200
});
199201
it("throws if unsupported chain name", () => {
202+
// intentionally set incorrect chain, ts will complain
203+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
200204
// @ts-ignore
201-
expect(() =>
202-
WalletProvider.genChainFromName("ethereum")
203-
).to.throw();
205+
expect(() => WalletProvider.genChainFromName("ethereum")).toThrow();
204206
});
205207
it("throws if invalid chain name", () => {
208+
// intentionally set incorrect chain, ts will complain
209+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
206210
// @ts-ignore
207-
expect(() => WalletProvider.genChainFromName("eth")).to.throw();
211+
expect(() => WalletProvider.genChainFromName("eth")).toThrow();
208212
});
209213
});
210214
});

packages/plugin-evm/src/types/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import type {
1010
} from "viem";
1111
import * as viemChains from "viem/chains";
1212

13-
const SupportedChainList = Object.keys(viemChains) as Array<keyof typeof viemChains>;
14-
export type SupportedChain = (typeof SupportedChainList)[number];
13+
const _SupportedChainList = Object.keys(viemChains) as Array<keyof typeof viemChains>;
14+
export type SupportedChain = (typeof _SupportedChainList)[number];
1515

1616
// Transaction types
1717
export interface Transaction {

0 commit comments

Comments
 (0)