Skip to content

Commit

Permalink
fix: zero base fee (#1280)
Browse files Browse the repository at this point in the history
* fix: package.json

* add test for zero base fee

* add async zero base fee test

* add more failing tests

* maybe fix zero base fee

* test

---------

Co-authored-by: moxey.eth <[email protected]>
  • Loading branch information
holic and jxom authored Oct 3, 2023
1 parent 64d3712 commit 309b583
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 48 deletions.
54 changes: 54 additions & 0 deletions src/actions/public/estimateMaxPriorityFeePerGas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ test('args: chain `defaultPriorityFee` override', async () => {
},
}),
).toBe(69420n)

// zero base fee
const client_4 = createPublicClient({
transport: http(localHttpUrl),
})
expect(
await estimateMaxPriorityFeePerGas(client_4, {
chain: {
...anvilChain,
fees: {
defaultPriorityFee: 0n,
},
},
}),
).toBe(0n)

// async zero base fee
const client_5 = createPublicClient({
transport: http(localHttpUrl),
})
expect(
await estimateMaxPriorityFeePerGas(client_5, {
chain: {
...anvilChain,
fees: {
defaultPriorityFee: async () => 0n,
},
},
}),
).toBe(0n)
})

test('client: chain `defaultPriorityFee` override', async () => {
Expand Down Expand Up @@ -112,6 +142,30 @@ test('client: chain `defaultPriorityFee` override', async () => {
transport: http(),
})
expect(await estimateMaxPriorityFeePerGas(client_3)).toBe(69420n)

// zero base fee
const client_4 = createPublicClient({
chain: {
...anvilChain,
fees: {
defaultPriorityFee: 0n,
},
},
transport: http(),
})
expect(await estimateMaxPriorityFeePerGas(client_4)).toBe(0n)

// async zero base fee
const client_5 = createPublicClient({
chain: {
...anvilChain,
fees: {
defaultPriorityFee: async () => 0n,
},
},
transport: http(),
})
expect(await estimateMaxPriorityFeePerGas(client_5)).toBe(0n)
})

test('chain does not support eip1559', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/estimateMaxPriorityFeePerGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function internal_estimateMaxPriorityFeePerGas<
client,
request,
} as ChainFeesFnParameters)
} else if (chain?.fees?.defaultPriorityFee)
} else if (typeof chain?.fees?.defaultPriorityFee !== 'undefined')
return chain?.fees?.defaultPriorityFee

try {
Expand Down
28 changes: 28 additions & 0 deletions src/actions/wallet/prepareTransactionRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,34 @@ describe('prepareTransactionRequest', () => {
expect(request_6.maxFeePerGas).toEqual(
(block.baseFeePerGas! * 120n) / 100n + parseGwei('69'),
)

// chain override (bigint zero base fee)
const request_7 = await prepareTransactionRequest(walletClient, {
account: privateKeyToAccount(sourceAccount.privateKey),
chain: {
...anvilChain,
fees: {
defaultPriorityFee: 0n,
},
},
to: targetAccount.address,
value: parseEther('1'),
})
expect(request_7.maxPriorityFeePerGas).toEqual(0n)

// chain override (async zero base fee)
const request_8 = await prepareTransactionRequest(walletClient, {
account: privateKeyToAccount(sourceAccount.privateKey),
chain: {
...anvilChain,
fees: {
defaultPriorityFee: async () => 0n,
},
},
to: targetAccount.address,
value: parseEther('1'),
})
expect(request_8.maxPriorityFeePerGas).toEqual(0n)
})

test('no account', async () => {
Expand Down
61 changes: 14 additions & 47 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,42 +86,18 @@
},
"typesVersions": {
"*": {
"abi": [
"./_types/abi/index.d.ts"
],
"accounts": [
"./_types/accounts/index.d.ts"
],
"actions": [
"./_types/actions/index.d.ts"
],
"chains": [
"./_types/chains/index.d.ts"
],
"chains/utils": [
"./_types/chains/utils/index.d.ts"
],
"contract": [
"./_types/contract/index.d.ts"
],
"ens": [
"./_types/ens/index.d.ts"
],
"public": [
"./_types/public/index.d.ts"
],
"test": [
"./_types/test/index.d.ts"
],
"utils": [
"./_types/utils/index.d.ts"
],
"wallet": [
"./_types/wallet/index.d.ts"
],
"window": [
"./_types/window/index.d.ts"
]
"abi": ["./_types/abi/index.d.ts"],
"accounts": ["./_types/accounts/index.d.ts"],
"actions": ["./_types/actions/index.d.ts"],
"chains": ["./_types/chains/index.d.ts"],
"chains/utils": ["./_types/chains/utils/index.d.ts"],
"contract": ["./_types/contract/index.d.ts"],
"ens": ["./_types/ens/index.d.ts"],
"public": ["./_types/public/index.d.ts"],
"test": ["./_types/test/index.d.ts"],
"utils": ["./_types/utils/index.d.ts"],
"wallet": ["./_types/wallet/index.d.ts"],
"window": ["./_types/window/index.d.ts"]
}
},
"peerDependencies": {
Expand All @@ -145,21 +121,12 @@
},
"license": "MIT",
"repository": "wagmi-dev/viem",
"authors": [
"awkweb.eth",
"jxom.eth"
],
"authors": ["awkweb.eth", "jxom.eth"],
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/wagmi-dev"
}
],
"keywords": [
"eth",
"ethereum",
"dapps",
"wallet",
"web3"
]
"keywords": ["eth", "ethereum", "dapps", "wallet", "web3"]
}

1 comment on commit 309b583

@vercel
Copy link

@vercel vercel bot commented on 309b583 Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.