Skip to content

Commit

Permalink
Merge pull request #55 from etherspot/callGasLimit-fix
Browse files Browse the repository at this point in the history
fix callGasLimit calculation
  • Loading branch information
0xSulpiride authored Jul 21, 2023
2 parents 7719f03 + e8a37de commit 90dc5fc
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 48 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.0.18",
"version": "0.0.19",
"stream": "true",
"command": {
"version": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "root",
"private": true,
"version": "0.0.18",
"version": "0.0.19",
"engines": {
"node": ">=18.0.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api",
"version": "0.0.18",
"version": "0.0.19",
"description": "The API module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -35,12 +35,12 @@
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
"ethers": "5.7.2",
"executor": "^0.0.18",
"executor": "^0.0.19",
"fastify": "4.14.1",
"pino": "8.11.0",
"pino-pretty": "10.0.0",
"reflect-metadata": "0.1.13",
"types": "^0.0.18"
"types": "^0.0.19"
},
"devDependencies": {
"@types/connect": "3.4.35"
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cli",
"version": "0.0.18",
"version": "0.0.19",
"description": "> TODO: description",
"author": "zincoshine <[email protected]>",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -31,13 +31,13 @@
"url": "https://https://github.com/etherspot/skandha/issues"
},
"dependencies": {
"api": "^0.0.18",
"db": "^0.0.18",
"executor": "^0.0.18",
"api": "^0.0.19",
"db": "^0.0.19",
"executor": "^0.0.19",
"find-up": "5.0.0",
"got": "12.5.3",
"js-yaml": "4.1.0",
"types": "^0.0.18",
"types": "^0.0.19",
"yargs": "17.6.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/db/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "db",
"version": "0.0.18",
"version": "0.0.19",
"description": "The DB module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/etherspot-bundler#readme",
Expand Down Expand Up @@ -37,6 +37,6 @@
"devDependencies": {
"@types/rocksdb": "3.0.1",
"prettier": "^2.8.4",
"types": "^0.0.18"
"types": "^0.0.19"
}
}
6 changes: 3 additions & 3 deletions packages/executor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "executor",
"version": "0.0.18",
"version": "0.0.19",
"description": "The Relayer module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"async-mutex": "0.4.0",
"ethers": "5.7.2",
"params": "^0.0.18",
"types": "^0.0.18"
"params": "^0.0.19",
"types": "^0.0.19"
}
}
75 changes: 45 additions & 30 deletions packages/executor/src/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,40 +129,40 @@ export class Eth {
// eslint-disable-next-line prefer-const
let { preOpGas, validAfter, validUntil, paid } = returnInfo;

const block = await this.provider.getBlock("latest");

const { estimationBaseFeeDivisor, estimationStaticBuffer } = this.config;
const estimatedBaseFee = block.baseFeePerGas
?.mul(100)
.div(100 + (estimationBaseFeeDivisor || 0));

let callGasLimit: BigNumber;
if (!estimatedBaseFee) {
callGasLimit = BigNumber.from(paid).div(userOpComplemented.maxFeePerGas);
} else {
const lhs = BigNumber.from(userOpComplemented.maxFeePerGas);
const rhs = estimatedBaseFee.add(userOpComplemented.maxPriorityFeePerGas);
const divisor = lhs.lt(rhs) ? lhs : rhs; // min(maxFeePerGas, base + priorityFee)
callGasLimit = BigNumber.from(paid).div(divisor);
}
callGasLimit = callGasLimit.sub(preOpGas).add(estimationStaticBuffer || 0);

if (callGasLimit.lt(0)) {
callGasLimit = BigNumber.from(estimationStaticBuffer || 0);
}
let callGasLimit: BigNumber = BigNumber.from(0);

// calculate callGasLimit based on paid fee
// only for undeployed wallets
if (BigNumber.from(userOp.nonce).eq(0)) {
const block = await this.provider.getBlock("latest");
const { estimationBaseFeeDivisor, estimationStaticBuffer } = this.config;
const estimatedBaseFee = block.baseFeePerGas
?.mul(100)
.div(100 + (estimationBaseFeeDivisor || 0));

if (!estimatedBaseFee) {
callGasLimit = BigNumber.from(paid).div(
userOpComplemented.maxFeePerGas
);
} else {
const lhs = BigNumber.from(userOpComplemented.maxFeePerGas);
const rhs = estimatedBaseFee.add(
userOpComplemented.maxPriorityFeePerGas
);
const divisor = lhs.lt(rhs) ? lhs : rhs; // min(maxFeePerGas, base + priorityFee)
callGasLimit = BigNumber.from(paid).div(divisor);
}
callGasLimit = callGasLimit
.sub(preOpGas)
.add(estimationStaticBuffer || 0);

const verificationGas = BigNumber.from(preOpGas).toNumber();
validAfter = BigNumber.from(validAfter);
validUntil = BigNumber.from(validUntil);
if (validUntil === BigNumber.from(0)) {
validUntil = undefined;
}
if (validAfter === BigNumber.from(0)) {
validAfter = undefined;
if (callGasLimit.lt(0)) {
callGasLimit = BigNumber.from(estimationStaticBuffer || 0);
}
}

//< checking for execution revert
await this.provider
const estimatedCallGasLimit = await this.provider
.estimateGas({
from: entryPoint,
to: userOp.sender,
Expand All @@ -175,6 +175,21 @@ export class Eth {
});
//>

// if wallet is deployed it's better to use more precise estimateGas
if (callGasLimit.eq(0)) {
callGasLimit = estimatedCallGasLimit;
}

const verificationGas = BigNumber.from(preOpGas).toNumber();
validAfter = BigNumber.from(validAfter);
validUntil = BigNumber.from(validUntil);
if (validUntil === BigNumber.from(0)) {
validUntil = undefined;
}
if (validAfter === BigNumber.from(0)) {
validAfter = undefined;
}

return {
preVerificationGas,
verificationGas,
Expand Down
4 changes: 2 additions & 2 deletions packages/params/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "params",
"version": "0.0.18",
"version": "0.0.19",
"description": "Various bundler parameters",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/skandha#readme",
Expand All @@ -24,7 +24,7 @@
"@arbitrum/sdk": "3.1.4",
"@eth-optimism/sdk": "3.0.0",
"ethers": "5.7.2",
"types": "^0.0.18"
"types": "^0.0.19"
},
"scripts": {
"clean": "rm -rf lib && rm -f *.tsbuildinfo",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "types",
"version": "0.0.18",
"version": "0.0.19",
"description": "The types of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down

0 comments on commit 90dc5fc

Please sign in to comment.