From 3661c215bbc4d1e4d880fcffb9dafb9d66190da5 Mon Sep 17 00:00:00 2001 From: zoeyTM Date: Wed, 24 Apr 2024 02:41:12 -0400 Subject: [PATCH] return legacy fees for polygon network deployments --- .../src/internal/execution/jsonrpc-client.ts | 12 +++-- .../internal/new-execution/jsonrpc-client.ts | 44 +++++++++++++++++-- packages/hardhat-plugin/test/config.ts | 14 ++++++ .../with-config/hardhat.config.js | 4 ++ 4 files changed, 66 insertions(+), 8 deletions(-) diff --git a/packages/core/src/internal/execution/jsonrpc-client.ts b/packages/core/src/internal/execution/jsonrpc-client.ts index 15cceb9ea..b45c1cef9 100644 --- a/packages/core/src/internal/execution/jsonrpc-client.ts +++ b/packages/core/src/internal/execution/jsonrpc-client.ts @@ -630,10 +630,14 @@ export class EIP1193JsonRpcClient implements JsonRpcClient { } private async _getNetworkFees(): Promise { - const latestBlock = await this.getLatestBlock(); - - // We prioritize EIP-1559 fees over legacy gasPrice fees - if (latestBlock.baseFeePerGas !== undefined) { + const [latestBlock, chainId] = await Promise.all([ + this.getLatestBlock(), + this.getChainId(), + ]); + + // We prioritize EIP-1559 fees over legacy gasPrice fees, however, + // polygon (chainId 137) requires legacy gasPrice fees so we skip EIP-1559 logic in that case + if (latestBlock.baseFeePerGas !== undefined && chainId !== 137) { // Logic copied from ethers v6 const maxPriorityFeePerGas = this._config?.maxPriorityFeePerGas ?? 1_000_000_000n; // 1gwei diff --git a/packages/core/test-integrations/new-api/internal/new-execution/jsonrpc-client.ts b/packages/core/test-integrations/new-api/internal/new-execution/jsonrpc-client.ts index 160044d0e..48bd95e73 100644 --- a/packages/core/test-integrations/new-api/internal/new-execution/jsonrpc-client.ts +++ b/packages/core/test-integrations/new-api/internal/new-execution/jsonrpc-client.ts @@ -108,15 +108,51 @@ describe("JSON-RPC client", function () { }); it("Should use the configured maxPriorityFeePerGas", async function () { - const client = new EIP1193JsonRpcClient(this.hre.network.provider, { - maxPriorityFeePerGas: 1n, - }); - const fees = await client.getNetworkFees(); + const maxFeeClient = new EIP1193JsonRpcClient( + this.hre.network.provider, + { + maxPriorityFeePerGas: 1n, + } + ); + const fees = await maxFeeClient.getNetworkFees(); assert("maxPriorityFeePerGas" in fees); assert.equal(fees.maxPriorityFeePerGas, 1n); }); + + it("Should use return legacy fees when deploying to polygon network (chainId 137)", async function () { + const polygonClient = new EIP1193JsonRpcClient( + { + request: async (req) => { + if (req.method === "eth_chainId") { + return "0x89"; // 137 + } + + if (req.method === "eth_getBlockByNumber") { + return { + number: "0x0", + hash: "0x0", + }; + } + + if (req.method === "eth_gasPrice") { + return "0x1"; + } + + throw new Error(`Unimplemented mock for ${req.method}`); + }, + }, + { + maxPriorityFeePerGas: 1n, + } + ); + const fees = await polygonClient.getNetworkFees(); + + assert("gasPrice" in fees); + + assert.equal(fees.gasPrice, 1n); + }); }); }); diff --git a/packages/hardhat-plugin/test/config.ts b/packages/hardhat-plugin/test/config.ts index b5e565c82..d4a96b4bd 100644 --- a/packages/hardhat-plugin/test/config.ts +++ b/packages/hardhat-plugin/test/config.ts @@ -39,6 +39,20 @@ describe("config", () => { }); }); + it("should apply maxFeePerGasLimit", async function () { + assert.equal( + this.hre.config.networks.hardhat.ignition.maxFeePerGasLimit, + 2n + ); + }); + + it("should apply maxPriorityFeePerGas", async function () { + assert.equal( + this.hre.config.networks.hardhat.ignition.maxPriorityFeePerGas, + 3n + ); + }); + it("should only have known config", () => { const configOptions: KeyListOf = [ "blockPollingInterval", diff --git a/packages/hardhat-plugin/test/fixture-projects/with-config/hardhat.config.js b/packages/hardhat-plugin/test/fixture-projects/with-config/hardhat.config.js index 73d80cfc7..c1bfe3856 100644 --- a/packages/hardhat-plugin/test/fixture-projects/with-config/hardhat.config.js +++ b/packages/hardhat-plugin/test/fixture-projects/with-config/hardhat.config.js @@ -6,6 +6,10 @@ module.exports = { mining: { auto: false, }, + ignition: { + maxFeePerGasLimit: 2n, + maxPriorityFeePerGas: 3n, + }, }, }, ignition: {