Skip to content

Commit

Permalink
return legacy fees for polygon network deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeyTM authored and kanej committed Apr 30, 2024
1 parent 9bce980 commit 3661c21
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 8 deletions.
12 changes: 8 additions & 4 deletions packages/core/src/internal/execution/jsonrpc-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,14 @@ export class EIP1193JsonRpcClient implements JsonRpcClient {
}

private async _getNetworkFees(): Promise<NetworkFees> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

Expand Down
14 changes: 14 additions & 0 deletions packages/hardhat-plugin/test/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HardhatConfig["ignition"]> = [
"blockPollingInterval",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module.exports = {
mining: {
auto: false,
},
ignition: {
maxFeePerGasLimit: 2n,
maxPriorityFeePerGas: 3n,
},
},
},
ignition: {
Expand Down

0 comments on commit 3661c21

Please sign in to comment.