Skip to content

Commit

Permalink
Merge branch 'wagmi-dev:main' into brianatourhut/ismorphic_ws
Browse files Browse the repository at this point in the history
  • Loading branch information
brianathere authored Aug 24, 2023
2 parents 77f18d9 + da45ec2 commit c9b0d40
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-ducks-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Deduped block retrieval in `estimateMaxPriorityFeePerGas`.
1 change: 1 addition & 0 deletions src/actions/public/estimateFeesPerGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export async function internal_estimateFeesPerGas<
: await internal_estimateMaxPriorityFeePerGas(
client as Client<Transport, Chain>,
{
block,
chain,
request,
},
Expand Down
18 changes: 17 additions & 1 deletion src/actions/public/estimateMaxPriorityFeePerGas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { createPublicClient } from '../../clients/createPublicClient.js'
import { http } from '../../clients/transports/http.js'
import { MethodNotSupportedRpcError } from '../../errors/rpc.js'
import { buildRequest } from '../../utils/buildRequest.js'
import { estimateMaxPriorityFeePerGas } from './estimateMaxPriorityFeePerGas.js'
import {
estimateMaxPriorityFeePerGas,
internal_estimateMaxPriorityFeePerGas,
} from './estimateMaxPriorityFeePerGas.js'
import * as getBlock from './getBlock.js'

test('default', async () => {
Expand Down Expand Up @@ -151,3 +154,16 @@ describe('mainnet smoke', () => {
expect(await estimateMaxPriorityFeePerGas(mainnetClient)).toBeDefined()
})
})

describe('internal_estimateMaxPriorityFeePerGas', () => {
test('args: block', async () => {
const block = await getBlock.getBlock(publicClient)
const maxPriorityFeePerGas = await internal_estimateMaxPriorityFeePerGas(
publicClient,
{
block,
},
)
expect(maxPriorityFeePerGas).toBeDefined()
})
})
8 changes: 5 additions & 3 deletions src/actions/public/estimateMaxPriorityFeePerGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Client } from '../../clients/createClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import { Eip1559FeesNotSupportedError } from '../../errors/fee.js'
import type { Account } from '../../types/account.js'
import type { Block } from '../../types/block.js'
import type { Chain, ChainFeesFnParameters } from '../../types/chain.js'
import type { GetChain } from '../../types/chain.js'
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
Expand Down Expand Up @@ -53,16 +54,17 @@ export async function internal_estimateMaxPriorityFeePerGas<
>(
client: Client<Transport, chain>,
args: EstimateMaxPriorityFeePerGasParameters<chain, chainOverride> & {
block?: Block
request?: PrepareRequestParameters<
chain,
Account | undefined,
chainOverride
>
},
): Promise<EstimateMaxPriorityFeePerGasReturnType> {
const { chain = client.chain, request } = args || {}
const { block: block_, chain = client.chain, request } = args || {}
if (typeof chain?.fees?.defaultPriorityFee === 'function') {
const block = await getBlock(client)
const block = block_ || (await getBlock(client))
return chain.fees.defaultPriorityFee({
block,
client,
Expand All @@ -81,7 +83,7 @@ export async function internal_estimateMaxPriorityFeePerGas<
// fall back to calculating it manually via `gasPrice - baseFeePerGas`.
// See: https://github.com/ethereum/pm/issues/328#:~:text=eth_maxPriorityFeePerGas%20after%20London%20will%20effectively%20return%20eth_gasPrice%20%2D%20baseFee
const [block, gasPrice] = await Promise.all([
getBlock(client),
block_ ? Promise.resolve(block_) : getBlock(client),
getGasPrice(client),
])

Expand Down

0 comments on commit c9b0d40

Please sign in to comment.