Skip to content

Commit

Permalink
ancient8 gas price oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride committed Apr 30, 2024
1 parent fa4757c commit 436d621
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
55 changes: 55 additions & 0 deletions packages/params/src/gas-price-oracles/oracles/ancient8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { fetchJson, hexValue } from "ethers/lib/utils";
import { BigNumber } from "ethers";
import { parseGwei } from "./utils";
import { IGetGasFeeResult, IOracle } from "./interfaces";

export const getAncient8GasFee: IOracle =
async (): Promise<IGetGasFeeResult> => {
const { gas_prices }: Ancient8Response = await fetchJson({
url: "https://scan.ancient8.gg/api/v2/stats",
headers: {
"updated-gas-oracle": "true",
},
});
const maxPriorityFeePerGas = hexValue(
BigNumber.from(gas_prices.fast.priority_fee_wei)
);
const maxFeePerGas = parseGwei(gas_prices.fast.priority_fee);
return {
maxPriorityFeePerGas: maxPriorityFeePerGas,
gasPrice: maxFeePerGas,
maxFeePerGas: maxFeePerGas,
};
};

type Ancient8Response = {
gas_prices: {
average: {
base_fee: number;
fiat_price: string;
price: number;
priority_fee: number;
priority_fee_wei: string;
time: number;
wei: string;
};
fast: {
base_fee: number;
fiat_price: string;
price: number;
priority_fee: number;
priority_fee_wei: string;
time: number;
wei: string;
};
slow: {
base_fee: number;
fiat_price: string;
price: number;
priority_fee: number;
priority_fee_wei: string;
time: number;
wei: string;
};
};
};
2 changes: 2 additions & 0 deletions packages/params/src/gas-price-oracles/oracles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getOptimismGasFee } from "./optimism";
import { IOracle } from "./interfaces";
import { getMantleGasFee } from "./mantle";
import { getBaseGasFee } from "./base";
import { getAncient8GasFee } from "./ancient8";

export const oracles: {
[chainId: number]: IOracle | undefined;
Expand All @@ -19,4 +20,5 @@ export const oracles: {
5000: getMantleGasFee,
5001: getMantleGasFee,
8453: getBaseGasFee,
888888888: getAncient8GasFee,
};

0 comments on commit 436d621

Please sign in to comment.