Skip to content

Commit

Permalink
EIP1559 estimation hotfix (#4074)
Browse files Browse the repository at this point in the history
* Fix EIP 1559 estimation rounding error

* Fix E2E gas
  • Loading branch information
FrederikBolding authored Aug 5, 2021
1 parent 5527148 commit c138ca8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion __tests__/hardhat-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export const setupDAI = async () => {
FIXTURE_WEB3_ADDRESS,
'100000000000000000000'
);
const sent = await signer.sendTransaction(tx);
const sent = await signer.sendTransaction({
...tx,
maxFeePerGas: '0xe8990a4600',
maxPriorityFeePerGas: '0xe8990a4600'
});

await sent.wait();

Expand Down
14 changes: 14 additions & 0 deletions src/services/ApiService/Gas/eip1559.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ describe('estimateFees', () => {
});
});

it('uses 1.6 multiplier for base if above 40 gwei', async () => {
(mockProvider.getLatestBlock as jest.MockedFunction<
typeof mockProvider.getLatestBlock
>).mockResolvedValueOnce({ ...block, baseFeePerGas: BigNumber.from('0x11766ffa76') });
(mockProvider.getFeeHistory as jest.MockedFunction<
typeof mockProvider.getFeeHistory
>).mockResolvedValueOnce(feeHistory);
return expect(estimateFees(mockProvider)).resolves.toStrictEqual({
baseFee: bigify('75001494134'),
maxFeePerGas: bigify('120000000000'),
maxPriorityFeePerGas: bigify('3000000000')
});
});

it('uses 1.4 multiplier for base if above 100 gwei', async () => {
(mockProvider.getLatestBlock as jest.MockedFunction<
typeof mockProvider.getLatestBlock
Expand Down
2 changes: 1 addition & 1 deletion src/services/ApiService/Gas/eip1559.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const FALLBACK_ESTIMATE = {
const PRIORITY_FEE_INCREASE_BOUNDARY = 200; // %

const roundToWholeGwei = (wei: BigNumber) => {
const gwei = bigify(fromWei(wei, 'gwei'));
const gwei = bigify(fromWei(wei.integerValue(), 'gwei'));
const rounded = gwei.integerValue(BigNumber.ROUND_HALF_UP);
return bigify(toWei(rounded.toString(10), getDecimalFromEtherUnit('gwei')));
};
Expand Down

0 comments on commit c138ca8

Please sign in to comment.