-
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
05b79b6
commit 183f753
Showing
7 changed files
with
99 additions
and
10 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
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,45 @@ | ||
import { NodeInterface__factory } from "@arbitrum/sdk/dist/lib/abi/factories/NodeInterface__factory"; | ||
import { NODE_INTERFACE_ADDRESS } from "@arbitrum/sdk/dist/lib/dataEntities/constants"; | ||
import { UserOperationStruct } from "types/lib/executor/contracts/EntryPoint"; | ||
import { BigNumber, BigNumberish, ethers } from "ethers"; | ||
import { EntryPoint__factory } from "types/lib/executor/contracts"; | ||
import { IPVGEstimator, IPVGEstimatorWrapper } from "../types/IPVGEstimator"; | ||
|
||
export const estimateArbitrumPVG: IPVGEstimatorWrapper = ( | ||
provider | ||
): IPVGEstimator => { | ||
const nodeInterface = NodeInterface__factory.connect( | ||
NODE_INTERFACE_ADDRESS, | ||
provider | ||
); | ||
const dummyWallet = ethers.Wallet.createRandom(); | ||
return async ( | ||
entryPointAddr: string, | ||
userOp: UserOperationStruct, | ||
initial: BigNumberish | ||
): Promise<BigNumber> => { | ||
const entryPoint = EntryPoint__factory.connect(entryPointAddr, provider); | ||
const handleOpsData = entryPoint.interface.encodeFunctionData("handleOps", [ | ||
[userOp], | ||
dummyWallet.address, | ||
]); | ||
|
||
const contractCreation = BigNumber.from(userOp.nonce).eq(0); | ||
try { | ||
const gasEstimateComponents = | ||
await nodeInterface.callStatic.gasEstimateL1Component( | ||
entryPoint.address, | ||
contractCreation, | ||
handleOpsData | ||
); | ||
const l1GasEstimated = gasEstimateComponents.gasEstimateForL1; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const baseFee = gasEstimateComponents.baseFee; | ||
return l1GasEstimated.add(initial); | ||
} catch (err) { | ||
// eslint-disable-next-line no-console | ||
console.error("Error while estimating arbitrum PVG", err); | ||
return BigNumber.from(initial); | ||
} | ||
}; | ||
}; |
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,12 @@ | ||
import { BigNumber, BigNumberish, providers } from "ethers"; | ||
import { UserOperationStruct } from "types/lib/executor/contracts/EntryPoint"; | ||
|
||
export type IPVGEstimatorWrapper = ( | ||
provider: providers.StaticJsonRpcProvider | ||
) => IPVGEstimator; | ||
|
||
export type IPVGEstimator = ( | ||
entryPointAddr: string, | ||
userOp: UserOperationStruct, | ||
initial: BigNumberish // initial amount of gas. It will be added to the estimated gas | ||
) => Promise<BigNumber>; |
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 |
---|---|---|
|
@@ -10,6 +10,16 @@ | |
"@jridgewell/gen-mapping" "^0.1.0" | ||
"@jridgewell/trace-mapping" "^0.3.9" | ||
|
||
"@arbitrum/[email protected]": | ||
version "3.1.4" | ||
resolved "https://registry.yarnpkg.com/@arbitrum/sdk/-/sdk-3.1.4.tgz#2088e09be4feaaf1ba3701290416e26f0407765e" | ||
integrity sha512-G0hWl+rST4/vLIXJrNbw03q1YNwyzrhmLCfEckNOcLxCZzzqUv2iLkwabP3bKbfzFKP71ObepTDIREtmfEGjbA== | ||
dependencies: | ||
"@ethersproject/address" "^5.0.8" | ||
"@ethersproject/bignumber" "^5.1.1" | ||
"@ethersproject/bytes" "^5.0.8" | ||
ethers "^5.1.0" | ||
|
||
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.18.6": | ||
version "7.18.6" | ||
resolved "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.18.6.tgz" | ||
|
@@ -379,7 +389,7 @@ | |
"@ethersproject/logger" "^5.7.0" | ||
"@ethersproject/properties" "^5.7.0" | ||
|
||
"@ethersproject/[email protected]", "@ethersproject/address@^5.7.0": | ||
"@ethersproject/[email protected]", "@ethersproject/address@^5.0.8", "@ethersproject/address@^5.7.0": | ||
version "5.7.0" | ||
resolved "https://registry.npmjs.org/@ethersproject/address/-/address-5.7.0.tgz" | ||
integrity sha512-9wYhYt7aghVGo758POM5nqcOMaE168Q6aRLJZwUmiqSrAungkG74gSSeKEIR7ukixesdRZGPgVqme6vmxs1fkA== | ||
|
@@ -405,7 +415,7 @@ | |
"@ethersproject/bytes" "^5.7.0" | ||
"@ethersproject/properties" "^5.7.0" | ||
|
||
"@ethersproject/[email protected]", "@ethersproject/bignumber@^5.7.0": | ||
"@ethersproject/[email protected]", "@ethersproject/bignumber@^5.1.1", "@ethersproject/bignumber@^5.7.0": | ||
version "5.7.0" | ||
resolved "https://registry.npmjs.org/@ethersproject/bignumber/-/bignumber-5.7.0.tgz" | ||
integrity sha512-n1CAdIHRWjSucQO3MC1zPSVgV/6dy/fjL9pMrPP9peL+QxEg9wOsVqwD4+818B6LUEtaXzVHQiuivzRoxPxUGw== | ||
|
@@ -414,7 +424,7 @@ | |
"@ethersproject/logger" "^5.7.0" | ||
bn.js "^5.2.1" | ||
|
||
"@ethersproject/[email protected]", "@ethersproject/bytes@^5.7.0": | ||
"@ethersproject/[email protected]", "@ethersproject/bytes@^5.0.8", "@ethersproject/bytes@^5.7.0": | ||
version "5.7.0" | ||
resolved "https://registry.npmjs.org/@ethersproject/bytes/-/bytes-5.7.0.tgz" | ||
integrity sha512-nsbxwgFXWh9NyYWo+U8atvmMsSdKJprTcICAkvbBffT75qDocbuggBU0SJiVK2MuTrp0q+xvLkTnGMPK1+uA9A== | ||
|
@@ -3913,7 +3923,7 @@ esutils@^2.0.2: | |
resolved "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz" | ||
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== | ||
|
||
[email protected]: | ||
[email protected], ethers@^5.1.0: | ||
version "5.7.2" | ||
resolved "https://registry.npmjs.org/ethers/-/ethers-5.7.2.tgz" | ||
integrity sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg== | ||
|