Skip to content

Commit

Permalink
update lerna & add ancient8 oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride committed May 15, 2024
1 parent 21ab638 commit 19d7db6
Show file tree
Hide file tree
Showing 10 changed files with 1,005 additions and 1,565 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ RUN apk update && apk add --no-cache g++ make python3 && rm -rf /var/cache/apk/*
COPY . .

RUN yarn install --non-interactive --frozen-lockfile && \
yarn bootstrap && \
yarn build && \
yarn install --non-interactive --frozen-lockfile --production

Expand All @@ -16,7 +15,6 @@ RUN apk update && apk add --no-cache g++ make python3 && rm -rf /var/cache/apk/*
COPY --from=build_src /usr/app .

RUN yarn install --non-interactive --frozen-lockfile --production --force
RUN npx [email protected] bootstrap --ignore-scripts -- --production --no-optional

RUN cd node_modules/bcrypto && yarn install

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ curl -fsSL https://skandha.run | bash
Or follow the steps below:

1. install all dependencies by running `yarn`
2. build `yarn build && yarn bootstrap`
2. build `yarn build`
3. `cp config.json.default config.json`
4. edit `config.json`
5. (optional) run local geth-node from `test/geth-dev`
Expand Down
1 change: 0 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"packages/*"
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "2.0.1",
"stream": "true",
"command": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"scripts": {
"clean": "rm -rf ./packages/*/lib ./packages/*/*.tsbuildinfo",
"bootstrap": "lerna bootstrap & lerna link",
"bootstrap": "yarn install",
"prebuild": "yarn workspace @skandha/types run build",
"build-db": "yarn workspace @skandha/db run build",
"build": "yarn prebuild && yarn build-db & lerna run build",
Expand Down Expand Up @@ -40,7 +40,7 @@
"eslint-plugin-import": "2.26.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-mocha": "10.2.0",
"lerna": "6.4.1",
"lerna": "7.3.0",
"ts-node": "10.9.1",
"tsconfig-paths": "4.1.2",
"typescript": "4.8.4",
Expand Down
5 changes: 5 additions & 0 deletions packages/executor/src/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
estimateMantlePVG,
AddressZero,
serializeMempoolId,
estimateAncient8PVG,
} from "@skandha/params/lib";
import { Logger } from "@skandha/types/lib";
import { PerChainMetrics } from "@skandha/monitoring/lib";
Expand Down Expand Up @@ -61,6 +62,10 @@ export class Eth {
if ([5000, 5001].includes(this.chainId)) {
this.pvgEstimator = estimateMantlePVG(this.provider);
}

if ([888888888].includes(this.chainId)) {
this.pvgEstimator = estimateAncient8PVG(this.provider);
}
}

/**
Expand Down
68 changes: 68 additions & 0 deletions packages/params/src/gas-estimation/ancient8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { BigNumber, BigNumberish, Contract } from "ethers";
import { UserOperation } from "@skandha/types/lib/contracts/UserOperation";
import { serializeTransaction } from "ethers/lib/utils";
import { IPVGEstimatorWrapper, IPVGEstimator } from "../types/IPVGEstimator";

export const estimateAncient8PVG: IPVGEstimatorWrapper = (
provider
): IPVGEstimator => {
return async (
contractAddr: string,
data: string,
initial: BigNumberish,
options?: {
contractCreation?: boolean;
userOp?: UserOperation;
}
): Promise<BigNumber> => {
const { chainId } = await provider.getNetwork();
const latestBlock = await provider.getBlock("latest");
if (latestBlock.baseFeePerGas == null) {
throw new Error("no base fee");
}

const serializedTx = serializeTransaction(
{
to: contractAddr,
chainId: chainId,
nonce: 999999,
gasLimit: BigNumber.from(2).pow(64).sub(1), // maxUint64
gasPrice: BigNumber.from(2).pow(64).sub(1), // maxUint64
data: data,
},
{
r: "0x123451234512345123451234512345123451234512345123451234512345",
s: "0x123451234512345123451234512345123451234512345123451234512345",
v: 28,
}
);
const gasOracle = new Contract(GAS_ORACLE, GasOracleABI, provider);
const l1GasCost = BigNumber.from(
await gasOracle.callStatic.getL1Fee(serializedTx)
);

let maxFeePerGas = BigNumber.from(0);
let maxPriorityFeePerGas = BigNumber.from(0);
if (options && options.userOp) {
const { userOp } = options;
maxFeePerGas = BigNumber.from(userOp.maxFeePerGas);
maxPriorityFeePerGas = BigNumber.from(userOp.maxPriorityFeePerGas);
}
const l2MaxFee = BigNumber.from(maxFeePerGas);
const l2PriorityFee = latestBlock.baseFeePerGas.add(maxPriorityFeePerGas);
const l2Price = l2MaxFee.lt(l2PriorityFee) ? l2MaxFee : l2PriorityFee;
return l1GasCost.div(l2Price).add(initial);
};
};

const GAS_ORACLE = "0x420000000000000000000000000000000000000F";

const GasOracleABI = [
{
inputs: [{ internalType: "bytes", name: "_data", type: "bytes" }],
name: "getL1Fee",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
];
1 change: 1 addition & 0 deletions packages/params/src/gas-estimation/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./arbitrum";
export * from "./optimism";
export * from "./mantle";
export * from "./ancient8";
70 changes: 70 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,70 @@
import { fetchJson, hexValue } from "ethers/lib/utils";
import { BigNumber, providers } from "ethers";
import { parseGwei } from "./utils";
import { IGetGasFeeResult, IOracle } from "./interfaces";

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: {
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 @@ -7,6 +7,7 @@ import { getMumbaiGasFee } from "./mumbai";
import { getOptimismGasFee } from "./optimism";
import { IOracle } from "./interfaces";
import { getMantleGasFee } from "./mantle";
import { getAncient8GasFee } from "./ancient8";

export const oracles: {
[chainId: number]: IOracle | undefined;
Expand All @@ -17,4 +18,5 @@ export const oracles: {
42161: getArbitrumGasFee,
5000: getMantleGasFee,
5001: getMantleGasFee,
888888888: getAncient8GasFee,
};
Loading

0 comments on commit 19d7db6

Please sign in to comment.