Skip to content

Commit

Permalink
fix: fallback to cgl based on paid fee
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride committed Jul 26, 2024
1 parent 5d8e008 commit e647981
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions packages/executor/src/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ export class Eth {
}

// eslint-disable-next-line prefer-const
let { returnInfo, callGasLimit } =
let { returnInfo, callGasLimit: binarySearchCGL } =
await this.userOpValidationService.validateForEstimation(
userOp,
entryPoint
);

// eslint-disable-next-line prefer-const
let { preOpGas, validAfter, validUntil } = returnInfo;
let { preOpGas, validAfter, validUntil, paid } = returnInfo;

const verificationGasLimit = BigNumber.from(preOpGas)
.sub(userOp.preVerificationGas)
Expand All @@ -194,15 +194,23 @@ export class Eth {
.add(this.config.vglMarkup)
.toNumber();

// calculate callGasLimit based on paid fee
const { cglMarkup } = this.config;
callGasLimit = callGasLimit
// calculate callGasLimit based on paid fee
const totalGas: BigNumber = BigNumber.from(paid).div(userOp.maxFeePerGas);
const paidFeeCGL = totalGas
.sub(preOpGas)
.mul(10000 + this.config.cglMarkupPercent)
.div(10000) // % markup
.add(cglMarkup || 0);

if (callGasLimit.lt(cglMarkup)) {
callGasLimit = BigNumber.from(cglMarkup);
// callGasLimit based on binary search
binarySearchCGL = binarySearchCGL
.mul(10000 + this.config.cglMarkupPercent)
.div(10000) // % markup
.add(cglMarkup || 0);

if (binarySearchCGL.lt(cglMarkup)) {
binarySearchCGL = BigNumber.from(cglMarkup);
}

//< checking for execution revert
Expand All @@ -219,6 +227,10 @@ export class Eth {
});
//>

let callGasLimit = binarySearchCGL;
if (callGasLimit.gt(paidFeeCGL)) {
callGasLimit = paidFeeCGL;
}
userOp.callGasLimit = callGasLimit;
let preVerificationGas: BigNumberish =
this.entryPointService.calcPreverificationGas(entryPoint, userOp);
Expand Down

0 comments on commit e647981

Please sign in to comment.