Skip to content
This repository was archived by the owner on Apr 18, 2026. It is now read-only.

Commit a89e697

Browse files
authored
fix: use publicClient for estimate gas (#438)
* fix: use publicClient for estimate gas * fix tests and upgrade prool * fix * changeset
1 parent 0991cd7 commit a89e697

8 files changed

Lines changed: 62 additions & 40 deletions

File tree

.changeset/twelve-foxes-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@abstract-foundation/agw-client": patch
3+
---
4+
5+
Use publicClient for estimate gas instead of internal/wrapped transport

packages/agw-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"devDependencies": {
6161
"@types/node": "^22.12.5",
6262
"@vitest/coverage-v8": "^3.2.4",
63-
"prool": "^0.0.23",
63+
"prool": "^0.2.4",
6464
"viem": "^2.37.0",
6565
"vitest": "^3.2.4"
6666
},

packages/agw-client/src/actions/prepareTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ export async function prepareTransactionRequest<
426426
(async () => {
427427
try {
428428
request.gas = await getAction(
429-
client,
429+
publicClient,
430430
estimateGas,
431431
'estimateGas',
432432
)({

packages/agw-client/test/anvil.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { createServer } from 'prool';
2-
import { type AnvilParameters, anvil } from 'prool/instances';
1+
import { Instance, Server } from 'prool';
32
import {
43
type Account,
54
type Address,
@@ -49,7 +48,7 @@ function getEnv(key: string, fallback: string): string {
4948
}
5049

5150
type DefineAnvilParameters<chain extends Chain> = Omit<
52-
AnvilParameters,
51+
Instance.anvil.Parameters,
5352
'forkBlockNumber' | 'forkUrl'
5453
> & {
5554
chain: chain;
@@ -208,8 +207,8 @@ function defineAnvil<const chain extends Chain>(
208207
await fetch(`${rpcUrl.http}/restart`);
209208
},
210209
async start() {
211-
return await createServer({
212-
instance: anvil({
210+
return await Server.create({
211+
instance: Instance.anvil({
213212
forkUrl,
214213
forkBlockNumber,
215214
...options,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import globalSetup from './globalSetup.ts';
2+
3+
async function main() {
4+
const stop = await globalSetup();
5+
console.log('global setup ok', typeof stop);
6+
if (typeof stop === 'function') await stop();
7+
}
8+
9+
main().catch((error) => {
10+
console.error(error);
11+
process.exit(1);
12+
});

packages/agw-client/test/src/actions/prepareTransaction.test.ts

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {
22
createClient,
3-
createNonceManager,
4-
createPublicClient,
53
createWalletClient,
64
EIP1193RequestFn,
75
encodeFunctionData,
86
http,
97
keccak256,
108
NonceManager,
11-
nonceManager,
9+
PublicClient,
1210
parseEther,
11+
publicActions,
12+
Transport,
1313
toBytes,
1414
toHex,
1515
} from 'viem';
@@ -63,6 +63,12 @@ const baseClientRequestSpy = vi.fn(async ({ method, params }) => {
6363
}
6464
if (method === 'eth_estimateGas') {
6565
return MOCK_ETH_ESTIMATE_GAS_LIMIT;
66+
} else if (method === 'zks_estimateFee') {
67+
throw new Error('zks_estimateFee not supported');
68+
} else if (method === 'eth_gasPrice') {
69+
return toHex(MOCK_FEE_PER_GAS);
70+
} else if (method === 'eth_getBalance') {
71+
return toHex(1000000000000000000n); // 1 ETH
6672
}
6773
return anvilAbstractTestnet.getClient().request({ method, params } as any);
6874
});
@@ -82,23 +88,9 @@ signerClient.request = (async ({ method, params }) => {
8288
return anvilAbstractTestnet.getClient().request({ method, params } as any);
8389
}) as EIP1193RequestFn;
8490

85-
const publicClient = createPublicClient({
86-
chain: anvilAbstractTestnet.chain as ChainEIP712,
87-
transport: anvilAbstractTestnet.clientConfig.transport,
88-
});
89-
90-
publicClient.request = (async ({ method, params }) => {
91-
if (method === 'zks_estimateFee') {
92-
throw new Error('zks_estimateFee not supported');
93-
} else if (method === 'eth_estimateGas') {
94-
return toHex(MOCK_ETH_ESTIMATE_GAS_LIMIT);
95-
} else if (method === 'eth_gasPrice') {
96-
return toHex(MOCK_FEE_PER_GAS);
97-
} else if (method === 'eth_getBalance') {
98-
return toHex(1000000000000000000n); // 1 ETH
99-
}
100-
return anvilAbstractTestnet.getClient().request({ method, params } as any);
101-
}) as EIP1193RequestFn;
91+
const publicClient = baseClient.extend(
92+
publicActions,
93+
) as unknown as PublicClient<Transport, ChainEIP712>;
10294

10395
publicClient.getTransactionCount = vi.fn(async () => {
10496
return MOCK_NONCE;
@@ -354,13 +346,13 @@ test.each([
354346
])('$name', async ({ balance, value, isSponsored, errorType }) => {
355347
vi.mocked(isSmartAccountDeployed).mockResolvedValue(true);
356348

357-
// Create a modified public client that returns a specified balance
358-
const publicClientWithCustomBalance = createPublicClient({
349+
const customBaseClient = createClient({
350+
account: address.smartAccountAddress,
359351
chain: anvilAbstractTestnet.chain as ChainEIP712,
360352
transport: anvilAbstractTestnet.clientConfig.transport,
361353
});
362354

363-
publicClientWithCustomBalance.request = (async ({ method, params }) => {
355+
customBaseClient.request = (async ({ method, params }) => {
364356
if (method === 'zks_estimateFee') {
365357
throw new Error('zks_estimateFee not supported');
366358
} else if (method === 'eth_estimateGas') {
@@ -373,6 +365,11 @@ test.each([
373365
return anvilAbstractTestnet.getClient().request({ method, params } as any);
374366
}) as EIP1193RequestFn;
375367

368+
// Create a modified public client that returns a specified balance
369+
const publicClientWithCustomBalance = customBaseClient.extend(
370+
publicActions,
371+
) as unknown as PublicClient<Transport, ChainEIP712>;
372+
376373
const txWithoutPaymaster = {
377374
...transaction,
378375
...(value !== undefined && { value }),

packages/agw-client/test/src/actions/sendTransactionInternal.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import {
77
encodeAbiParameters,
88
Hex,
99
http,
10+
PublicClient,
1011
parseAbiParameters,
12+
publicActions,
13+
Transport,
1114
toFunctionSelector,
1215
} from 'viem';
1316
import { toAccount } from 'viem/accounts';
@@ -102,13 +105,14 @@ signerClient.request = (async ({ method, params }) => {
102105
return anvilAbstractTestnet.getClient().request({ method, params } as any);
103106
}) as EIP1193RequestFn;
104107

105-
const publicClient = createPublicClient({
106-
chain: anvilAbstractTestnet.chain as ChainEIP712,
107-
transport: anvilAbstractTestnet.clientConfig.transport,
108-
});
108+
const publicClient = baseClient.extend(
109+
publicActions,
110+
) as unknown as PublicClient<Transport, ChainEIP712>;
109111

110112
publicClient.request = (async ({ method, params }) => {
111-
if (method === 'zks_estimateFee') {
113+
if (method === 'eth_estimateGas') {
114+
return 158774n;
115+
} else if (method === 'zks_estimateFee') {
112116
throw new Error('zks_estimateFee not supported');
113117
}
114118
return anvilAbstractTestnet.getClient().request({ method, params } as any);

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)