-
Notifications
You must be signed in to change notification settings - Fork 14
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
1 parent
4961d48
commit bda4843
Showing
1 changed file
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// @note: This test is _not_ run automatically as part of git hooks or CI. | ||
import dotenv from "dotenv"; | ||
import { providers } from "ethers"; | ||
import { getGasPriceEstimate } from "../src/gasPriceOracle"; | ||
import { BigNumber, bnZero, parseUnits } from "../src/utils"; | ||
import { expect, makeCustomTransport } from "../test/utils"; | ||
dotenv.config({ path: ".env" }); | ||
|
||
const stdLastBaseFeePerGas = parseUnits("12", 9); | ||
const stdMaxPriorityFeePerGas = parseUnits("1", 9); // EIP-1559 chains only | ||
const chainIds = [1, 10, 137, 324, 8453, 42161, 534352]; | ||
|
||
const customTransport = makeCustomTransport({ stdLastBaseFeePerGas, stdMaxPriorityFeePerGas }); | ||
|
||
const provider = new providers.StaticJsonRpcProvider("https://eth.llamarpc.com"); | ||
|
||
describe("Gas Price Oracle", function () { | ||
it("Gas Price Retrieval", async function () { | ||
for (const chainId of chainIds) { | ||
const chainKey = `NEW_GAS_PRICE_ORACLE_${chainId}`; | ||
process.env[chainKey] = "true"; | ||
const { maxFeePerGas, maxPriorityFeePerGas } = await getGasPriceEstimate(provider, { | ||
chainId, | ||
transport: customTransport, | ||
}); | ||
|
||
expect(BigNumber.isBigNumber(maxFeePerGas)).to.be.true; | ||
expect(BigNumber.isBigNumber(maxPriorityFeePerGas)).to.be.true; | ||
|
||
if (chainId === 137) { | ||
// The Polygon gas station isn't mocked, so just ensure that the fees have a valid relationship. | ||
expect(maxFeePerGas.gt(0)).to.be.true; | ||
expect(maxPriorityFeePerGas.gt(0)).to.be.true; | ||
expect(maxPriorityFeePerGas.lt(maxFeePerGas)).to.be.true; | ||
} else if (chainId === 42161) { | ||
// Arbitrum priority fees are refunded, so drop the priority fee from estimates. | ||
// Expect a 1.2x multiplier on the last base fee. | ||
expect(maxFeePerGas.eq(stdLastBaseFeePerGas.mul("120").div("100").add(1))).to.be.true; | ||
expect(maxPriorityFeePerGas.eq(1)).to.be.true; | ||
} else { | ||
expect(maxFeePerGas.gt(bnZero)).to.be.true; | ||
expect(maxPriorityFeePerGas.gt(bnZero)).to.be.true; | ||
} | ||
|
||
delete process.env[chainKey]; | ||
} | ||
}); | ||
it("Ethers: applies markup to maxFeePerGas", async function () { | ||
for (const chainId of chainIds) { | ||
const { maxFeePerGas: markedUpMaxFeePerGas, maxPriorityFeePerGas: markedUpMaxPriorityFeePerGas } = | ||
await getGasPriceEstimate(provider, { chainId, baseFeeMultiplier: 2, transport: customTransport }); | ||
const { maxFeePerGas, maxPriorityFeePerGas } = await getGasPriceEstimate(provider, { | ||
chainId, | ||
baseFeeMultiplier: 1, | ||
transport: customTransport, | ||
}); | ||
expect(markedUpMaxFeePerGas.gt(maxFeePerGas)).to.be.true; | ||
expect(markedUpMaxPriorityFeePerGas).to.equal(maxPriorityFeePerGas); | ||
} | ||
}); | ||
}); |