Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ancient8 oracle #185

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/bundler-spec-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ jobs:

- name: Install Geth
run: |
sudo add-apt-repository -y ppa:ethereum/ethereum && \
sudo apt-get update && \
sudo apt-get install ethereum
wget https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.13.15-c5ba367e.tar.gz
tar -xvf geth-linux-amd64-1.13.15-c5ba367e.tar.gz

- name: Run Geth
run: |
geth \
cd geth-linux-amd64-1.13.15-c5ba367e &&
./geth \
--verbosity 1 \
--http.vhosts '*,localhost,host.docker.internal' \
--http \
Expand All @@ -76,7 +76,8 @@ jobs:

- name: Fund bundler
run: |
geth \
cd geth-linux-amd64-1.13.15-c5ba367e &&
./geth \
--exec "eth.sendTransaction({from: eth.accounts[0], to: \"0x55082761664aEb8062B3427ba5E0455bFb7b68CB\", value: web3.toWei(4337, \"ether\")})" \
attach http://localhost:8545/

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,4 @@ packages/contracts/out-via-ir/
packages/contracts/.env
packages/contracts/broadcast/*/*/*
packages/contracts/out/
packages/cli/.git-data.json
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"name": "root",
"private": false,
"publishConfig": {
"access": "public"
},
"private": true,
"version": "1.5.7",
"engines": {
"node": ">=18.0.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/params/src/gas-price-oracles/getGasFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const getGasFee = async (
try {
const feeData = await provider.getFeeData();
return {
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ?? feeData.gasPrice ?? 0,
maxPriorityFeePerGas:
feeData.maxPriorityFeePerGas ?? feeData.gasPrice ?? 0,
maxFeePerGas: feeData.maxFeePerGas ?? feeData.gasPrice ?? 0,
gasPrice: feeData.gasPrice ?? 0,
};
Expand Down
51 changes: 33 additions & 18 deletions packages/params/src/gas-price-oracles/oracles/ancient8.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
import { fetchJson, hexValue } from "ethers/lib/utils";
import { BigNumber } from "ethers";
import { BigNumber, providers } 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,
};
export const getAncient8GasFee: IOracle = async (
apiKey: string,
provider?: providers.JsonRpcProvider
): Promise<IGetGasFeeResult> => {
try {
if (provider) {
const gasPrice = await provider.getGasPrice();
return {
maxPriorityFeePerGas: gasPrice,
gasPrice: gasPrice,
maxFeePerGas: gasPrice,
};
}
} catch (err) {
/* empty */
}

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.average.priority_fee_wei)
);
const maxFeePerGas = parseGwei(gas_prices.average.priority_fee);
return {
maxPriorityFeePerGas: maxPriorityFeePerGas,
gasPrice: maxFeePerGas,
maxFeePerGas: maxFeePerGas,
};
};

type Ancient8Response = {
gas_prices: {
Expand Down
Loading