Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: zero base fee #1280

Merged
merged 6 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
}