Skip to content

Commit

Permalink
refactor & increase default CGL on amoy
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride committed May 27, 2024
1 parent dea4bd0 commit c66e5cb
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions packages/executor/src/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,52 +148,53 @@ export class Eth {
async estimateUserOperationGas(
args: EstimateUserOperationGasArgs
): Promise<EstimatedUserOperationGas> {
const { userOp, entryPoint } = args;
const { userOp: partialUserOp, entryPoint } = args;
if (!this.validateEntryPoint(entryPoint)) {
throw new RpcError("Invalid Entrypoint", RpcErrorCodes.INVALID_REQUEST);
}

const userOpComplemented: UserOperationStruct = {
paymasterAndData: userOp.paymasterAndData ?? "0x",
...userOp,
const userOp: UserOperationStruct = {
...partialUserOp,
paymasterAndData: partialUserOp.paymasterAndData ?? "0x",
callGasLimit: BigNumber.from(10e6),
preVerificationGas: BigNumber.from(1e6),
verificationGasLimit: BigNumber.from(10e6),
maxFeePerGas: 1,
maxPriorityFeePerGas: 1,
};

if (userOpComplemented.signature.length <= 2) {
userOpComplemented.signature = ECDSA_DUMMY_SIGNATURE;
if (this.chainId == 80002) {
userOp.callGasLimit = BigNumber.from(20e6);
userOp.preVerificationGas = BigNumber.from(50000);
userOp.verificationGasLimit = BigNumber.from(3e6);
}

if (userOp.signature.length <= 2) {
userOp.signature = ECDSA_DUMMY_SIGNATURE;
}

const returnInfo = await this.userOpValidationService.validateForEstimation(
userOpComplemented,
userOp,
entryPoint
);

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

const verificationGasLimit = BigNumber.from(preOpGas)
.sub(userOpComplemented.preVerificationGas)
.sub(userOp.preVerificationGas)
.mul(130)
.div(100) // 130% markup
.add(this.config.vglMarkup)
.toNumber();

let preVerificationGas: BigNumberish =
this.calcPreVerificationGas(userOpComplemented);
userOpComplemented.preVerificationGas = preVerificationGas;
let callGasLimit: BigNumber = BigNumber.from(0);

// calculate callGasLimit based on paid fee
const { cglMarkup } = this.config;
callGasLimit = BigNumber.from(paid).div(userOpComplemented.maxFeePerGas);
callGasLimit = callGasLimit.sub(preOpGas).add(cglMarkup || 0);
const totalGas: BigNumber = BigNumber.from(paid).div(userOp.maxFeePerGas);
let callGasLimit = totalGas.sub(preOpGas).add(cglMarkup || 0);

if (callGasLimit.lt(0)) {
callGasLimit = BigNumber.from(cglMarkup || 0);
if (callGasLimit.lt(cglMarkup)) {
callGasLimit = BigNumber.from(cglMarkup);
}

//< checking for execution revert
Expand All @@ -210,14 +211,16 @@ export class Eth {
});
//>

userOp.callGasLimit = callGasLimit;
let preVerificationGas: BigNumberish = this.calcPreVerificationGas(userOp);
const gasFee = await this.skandhaModule.getGasPrice();

if (this.pvgEstimator) {
userOpComplemented.maxFeePerGas = gasFee.maxFeePerGas;
userOpComplemented.maxPriorityFeePerGas = gasFee.maxPriorityFeePerGas;
userOp.maxFeePerGas = gasFee.maxFeePerGas;
userOp.maxPriorityFeePerGas = gasFee.maxPriorityFeePerGas;
preVerificationGas = await this.pvgEstimator(
entryPoint,
userOpComplemented,
userOp,
preVerificationGas
);
}
Expand All @@ -226,13 +229,13 @@ export class Eth {

return {
preVerificationGas,
verificationGasLimit: verificationGasLimit,
verificationGasLimit,
callGasLimit,
verificationGas: verificationGasLimit,
validAfter: validAfter ? BigNumber.from(validAfter) : undefined,
validUntil: validUntil ? BigNumber.from(validUntil) : undefined,
callGasLimit: callGasLimit,
maxFeePerGas: gasFee.maxFeePerGas,
maxPriorityFeePerGas: gasFee.maxPriorityFeePerGas,
validAfter: validAfter ? BigNumber.from(validAfter) : undefined,
validUntil: validUntil ? BigNumber.from(validUntil) : undefined,
};
}

Expand Down

0 comments on commit c66e5cb

Please sign in to comment.