Skip to content

Commit e2d7141

Browse files
committed
Make ABI autocompletion work on any chain
1 parent 4cf163b commit e2d7141

File tree

5 files changed

+12
-63
lines changed

5 files changed

+12
-63
lines changed

bun.lockb

59.1 KB
Binary file not shown.

packages/evmcrispr/src/modules/aragonos/commands/act.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,7 @@ export const act: ICommand<AragonOS> = {
140140
}
141141

142142
const result = await tryAndCacheNotFound(
143-
() =>
144-
fetchAbi(
145-
resolvedTargetAddress,
146-
client,
147-
// TODO: use etherscan API to fetch the abis
148-
"",
149-
),
143+
() => fetchAbi(resolvedTargetAddress, client),
150144
resolvedTargetAddress,
151145
ABI,
152146
cache,

packages/evmcrispr/src/modules/std/commands/exec.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,11 @@ export const exec: ICommand<Std> = {
7575

7676
finalSignature = getFunctionFragment(func);
7777
} else {
78-
const etherscanAPI = module.getConfigBinding("etherscanAPI");
7978
let fetchedAbi: Abi;
8079
try {
8180
[targetAddress, fetchedAbi] = await fetchAbi(
8281
contractAddress,
8382
await module.getClient(),
84-
etherscanAPI,
8583
);
8684
} catch (err) {
8785
const err_ = err as Error;
@@ -217,13 +215,7 @@ export const exec: ICommand<Std> = {
217215
}
218216

219217
const result = await tryAndCacheNotFound(
220-
() =>
221-
fetchAbi(
222-
resolvedTargetAddress,
223-
client,
224-
// TODO: use etherscan API to fetch the abis
225-
"",
226-
),
218+
() => fetchAbi(resolvedTargetAddress, client),
227219
resolvedTargetAddress,
228220
ABI,
229221
cache,

packages/evmcrispr/src/utils/abis.ts

+10-43
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,23 @@
11
import type { PublicClient } from "viem";
22

3-
import { ErrorConnection, ErrorException } from "../errors";
3+
import { ErrorException } from "../errors";
44
import type { Abi, Address } from "../types";
55
import { fetchImplementationAddress } from "./proxies";
66

7-
async function getAbiEntries(
8-
etherscanAPI: string,
9-
address: string,
10-
chainId: number,
11-
): Promise<Abi> {
12-
let baseUrl: string;
13-
// TODO: Do not rely on etherscan and use https://github.com/cdump/evmole
14-
switch (chainId) {
15-
case 1:
16-
baseUrl = "https://api.etherscan.io/api";
17-
break;
18-
case 5:
19-
baseUrl = "https://api-goerli.etherscan.io/api";
20-
break;
21-
case 10:
22-
baseUrl = "https://api-optimistic.etherscan.io/api";
23-
break;
24-
case 100:
25-
baseUrl = "https://blockscout.com/xdai/mainnet/api";
26-
break;
27-
default:
28-
throw new ErrorException("network not supported in Etherscan.");
29-
}
30-
31-
const apiKeySegment = chainId !== 100 ? `&apikey=${etherscanAPI}` : "";
32-
33-
const response = (await fetch(
34-
`${baseUrl}?module=contract&action=getabi&address=${address}${apiKeySegment}`,
7+
async function getAbiEntries(address: string, chainId: number): Promise<Abi> {
8+
return await fetch(
9+
`https://abi.functions.on-fleek.app/v0/${chainId}/${address}`,
3510
)
36-
.then((response) => response.json())
37-
.then((data) => data)) as {
38-
status: string;
39-
message: string;
40-
result: string;
41-
};
42-
43-
if (response.status == "0") {
44-
throw new ErrorConnection(response.result);
45-
}
46-
47-
return JSON.parse(response.result);
11+
.then((res) => res.json())
12+
.catch((err) => {
13+
console.error(err);
14+
throw new ErrorException("Failed to fetch ABI");
15+
});
4816
}
4917

5018
export const fetchAbi = async (
5119
contractAddress: Address,
5220
client: PublicClient,
53-
etherscanAPI: string,
5421
): Promise<[Address, Abi]> => {
5522
const implementationAddress = await fetchImplementationAddress(
5623
contractAddress,
@@ -63,7 +30,7 @@ export const fetchAbi = async (
6330
throw new ErrorException("Chain id is not supported");
6431
}
6532

66-
const fetchedAbi = await getAbiEntries(etherscanAPI, targetAddress, chainId);
33+
const fetchedAbi = await getAbiEntries(targetAddress, chainId);
6734

6835
return [targetAddress, fetchedAbi];
6936
};

packages/evmcrispr/test/modules/std/commands/exec.test.ts

-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import { expectThrowAsync } from "../../../test-helpers/expects";
1616
import { findStdCommandNode } from "../../../test-helpers/std";
1717
import { TEST_ACCOUNT_ADDRESS } from "../../../test-helpers/constants";
1818

19-
const ETHERSCAN_API = process.env.ETHERSCAN_API;
20-
2119
describe("Std > commands > exec <target> <fnSignature> [<...params>] [--from <sender>]", () => {
2220
let client: PublicClient;
2321

@@ -127,7 +125,6 @@ describe("Std > commands > exec <target> <fnSignature> [<...params>] [--from <se
127125
it("should return exec action when receiving just the method's name", async () => {
128126
const interpreter = createInterpreter(
129127
`
130-
set $std:etherscanAPI ${ETHERSCAN_API}
131128
exec ${target} transfer @me 1500e18
132129
`,
133130
client,
@@ -178,7 +175,6 @@ describe("Std > commands > exec <target> <fnSignature> [<...params>] [--from <se
178175
const invalidSignature = "invalid(uint256,)";
179176
const interpreter = createInterpreter(
180177
`
181-
set $std:etherscanAPI ${ETHERSCAN_API}
182178
exec ${target} ${invalidSignature} 1e18`,
183179
client,
184180
);

0 commit comments

Comments
 (0)