-
Notifications
You must be signed in to change notification settings - Fork 60
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
21ab638
commit 19d7db6
Showing
10 changed files
with
1,005 additions
and
1,565 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 |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
||
|
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
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
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,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", | ||
}, | ||
]; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./arbitrum"; | ||
export * from "./optimism"; | ||
export * from "./mantle"; | ||
export * from "./ancient8"; |
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,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; | ||
}; | ||
}; | ||
}; |
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.