Skip to content

Commit

Permalink
feat(api): Implement eth_maxPriorityFeePerGas (#3135)
Browse files Browse the repository at this point in the history
## What ❔

Fixes #13 
Implements `eth_maxPriorityFeePerGas` method.

## Why ❔

This method is a de-facto standard now, and SDKs (e.g. viem) can use it
assuming that it's supported.
Even given that we're not really using EIP1559, we should still support
it and return 0.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zkstack dev fmt` and `zkstack dev
lint`.
  • Loading branch information
popzxc authored Oct 23, 2024
1 parent 11e525e commit 35e84cc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions core/lib/web3_decl/src/namespaces/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ pub trait EthNamespace {
newest_block: BlockNumber,
reward_percentiles: Vec<f32>,
) -> RpcResult<FeeHistory>;

#[method(name = "maxPriorityFeePerGas")]
async fn max_priority_fee_per_gas(&self) -> RpcResult<U256>;
}

#[cfg(feature = "server")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,8 @@ impl EthNamespaceServer for EthNamespace {
.await
.map_err(|err| self.current_method().map_err(err))
}

async fn max_priority_fee_per_gas(&self) -> RpcResult<U256> {
Ok(self.max_priority_fee_per_gas_impl())
}
}
5 changes: 5 additions & 0 deletions core/node/api_server/src/web3/namespaces/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,11 @@ impl EthNamespace {
}
})
}

pub fn max_priority_fee_per_gas_impl(&self) -> U256 {
// ZKsync does not require priority fee.
0u64.into()
}
}

// Bogus methods.
Expand Down
6 changes: 4 additions & 2 deletions core/tests/ts-integration/tests/api/web3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ describe('web3 API compatibility tests', () => {
['eth_getCompilers', [], []],
['eth_hashrate', [], '0x0'],
['eth_mining', [], false],
['eth_getUncleCountByBlockNumber', ['0x0'], '0x0']
['eth_getUncleCountByBlockNumber', ['0x0'], '0x0'],
['eth_maxPriorityFeePerGas', [], '0x0']
])('Should test bogus web3 methods (%s)', async (method: string, input: string[], output: string) => {
await expect(alice.provider.send(method, input)).resolves.toEqual(output);
});
Expand Down Expand Up @@ -271,7 +272,8 @@ describe('web3 API compatibility tests', () => {

const eip1559ApiReceipt = await alice.provider.getTransaction(eip1559Tx.hash);
expect(eip1559ApiReceipt.maxFeePerGas).toEqual(eip1559Tx.maxFeePerGas!);
expect(eip1559ApiReceipt.maxPriorityFeePerGas).toEqual(eip1559Tx.maxPriorityFeePerGas!);
// `ethers` will use value provided by `eth_maxPriorityFeePerGas`, and we return 0 there.
expect(eip1559ApiReceipt.maxPriorityFeePerGas).toEqual(0n);
});

test('Should test getFilterChanges for pending transactions', async () => {
Expand Down

0 comments on commit 35e84cc

Please sign in to comment.