Skip to content

Commit c9b0d40

Browse files
author
Brian Meek
authored
Merge branch 'wagmi-dev:main' into brianatourhut/ismorphic_ws
2 parents 77f18d9 + da45ec2 commit c9b0d40

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

.changeset/dry-ducks-complain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"viem": patch
3+
---
4+
5+
Deduped block retrieval in `estimateMaxPriorityFeePerGas`.

src/actions/public/estimateFeesPerGas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export async function internal_estimateFeesPerGas<
131131
: await internal_estimateMaxPriorityFeePerGas(
132132
client as Client<Transport, Chain>,
133133
{
134+
block,
134135
chain,
135136
request,
136137
},

src/actions/public/estimateMaxPriorityFeePerGas.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { createPublicClient } from '../../clients/createPublicClient.js'
77
import { http } from '../../clients/transports/http.js'
88
import { MethodNotSupportedRpcError } from '../../errors/rpc.js'
99
import { buildRequest } from '../../utils/buildRequest.js'
10-
import { estimateMaxPriorityFeePerGas } from './estimateMaxPriorityFeePerGas.js'
10+
import {
11+
estimateMaxPriorityFeePerGas,
12+
internal_estimateMaxPriorityFeePerGas,
13+
} from './estimateMaxPriorityFeePerGas.js'
1114
import * as getBlock from './getBlock.js'
1215

1316
test('default', async () => {
@@ -151,3 +154,16 @@ describe('mainnet smoke', () => {
151154
expect(await estimateMaxPriorityFeePerGas(mainnetClient)).toBeDefined()
152155
})
153156
})
157+
158+
describe('internal_estimateMaxPriorityFeePerGas', () => {
159+
test('args: block', async () => {
160+
const block = await getBlock.getBlock(publicClient)
161+
const maxPriorityFeePerGas = await internal_estimateMaxPriorityFeePerGas(
162+
publicClient,
163+
{
164+
block,
165+
},
166+
)
167+
expect(maxPriorityFeePerGas).toBeDefined()
168+
})
169+
})

src/actions/public/estimateMaxPriorityFeePerGas.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Client } from '../../clients/createClient.js'
22
import type { Transport } from '../../clients/transports/createTransport.js'
33
import { Eip1559FeesNotSupportedError } from '../../errors/fee.js'
44
import type { Account } from '../../types/account.js'
5+
import type { Block } from '../../types/block.js'
56
import type { Chain, ChainFeesFnParameters } from '../../types/chain.js'
67
import type { GetChain } from '../../types/chain.js'
78
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
@@ -53,16 +54,17 @@ export async function internal_estimateMaxPriorityFeePerGas<
5354
>(
5455
client: Client<Transport, chain>,
5556
args: EstimateMaxPriorityFeePerGasParameters<chain, chainOverride> & {
57+
block?: Block
5658
request?: PrepareRequestParameters<
5759
chain,
5860
Account | undefined,
5961
chainOverride
6062
>
6163
},
6264
): Promise<EstimateMaxPriorityFeePerGasReturnType> {
63-
const { chain = client.chain, request } = args || {}
65+
const { block: block_, chain = client.chain, request } = args || {}
6466
if (typeof chain?.fees?.defaultPriorityFee === 'function') {
65-
const block = await getBlock(client)
67+
const block = block_ || (await getBlock(client))
6668
return chain.fees.defaultPriorityFee({
6769
block,
6870
client,
@@ -81,7 +83,7 @@ export async function internal_estimateMaxPriorityFeePerGas<
8183
// fall back to calculating it manually via `gasPrice - baseFeePerGas`.
8284
// See: https://github.com/ethereum/pm/issues/328#:~:text=eth_maxPriorityFeePerGas%20after%20London%20will%20effectively%20return%20eth_gasPrice%20%2D%20baseFee
8385
const [block, gasPrice] = await Promise.all([
84-
getBlock(client),
86+
block_ ? Promise.resolve(block_) : getBlock(client),
8587
getGasPrice(client),
8688
])
8789

0 commit comments

Comments
 (0)