-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
172 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { getAsapGasPriceLevel } from "../getAsapGasPriceLevel"; | ||
|
||
describe("getAsapGasPriceLevel", () => { | ||
it("should return the asap gas price level", () => { | ||
const result = getAsapGasPriceLevel(100, 20); | ||
|
||
expect(result).toEqual({ | ||
maxPriorityFeePerGas: 32.5, | ||
maxFeePerGas: 232.5, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Inspired from https://www.blocknative.com/blog/eip-1559-fees | ||
|
||
import type { GasPriceLevel } from "./types"; | ||
|
||
// +12.5% is the maximum increase of base fee per block | ||
// This means setting a premium max priority fee bigger by 12.5% of base fee | ||
// means likelyhood of getting into block 2 in a gas spike event is super high | ||
const PREMIUM_BASE_FEE_PERCENTAGE_FOR_MAX_PRIORITY_FEE = 0.125; | ||
|
||
export function getAsapGasPriceLevel( | ||
baseFee: number, | ||
fastMaxPriorityFee: number | ||
): GasPriceLevel { | ||
const maxPriorityFeePerGas = | ||
fastMaxPriorityFee + | ||
baseFee * PREMIUM_BASE_FEE_PERCENTAGE_FOR_MAX_PRIORITY_FEE; | ||
|
||
// Using baseFee * 2 ensures the transaction will remain marketable for six consecutive 100% full blocks | ||
const maxFeePerGas = baseFee * 2 + maxPriorityFeePerGas; | ||
|
||
return { | ||
maxPriorityFeePerGas, | ||
maxFeePerGas, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.