Skip to content

Commit

Permalink
Merge pull request #20 from etherspot/mantle
Browse files Browse the repository at this point in the history
Get gas prices from estimation endpoint
  • Loading branch information
0xSulpiride authored Aug 17, 2023
2 parents 489c370 + c0f4ace commit 34a3255
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etherspot/prime-sdk",
"version": "1.1.2",
"version": "1.1.3",
"description": "Etherspot Prime (Account Abstraction) SDK",
"keywords": [
"ether",
Expand Down
17 changes: 13 additions & 4 deletions src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ export class PrimeSdk {
}

async estimate(gasDetails?: TransactionGasInfoForUserOp) {
const gas = await this.getGasFee();

if (this.userOpsBatch.to.length < 1) {
throw new Error("cannot sign empty transaction batch");
}
Expand All @@ -139,14 +137,25 @@ export class PrimeSdk {

let partialtx = await this.etherspotWallet.createUnsignedUserOp({
...tx,
...gas,
maxFeePerGas: 1,
maxPriorityFeePerGas: 1,
});

const bundlerGasEstimate = await this.bundler.getVerificationGasInfo(partialtx);

// if estimation has gas prices use them, otherwise fetch them in a separate call
if (bundlerGasEstimate.maxFeePerGas && bundlerGasEstimate.maxPriorityFeePerGas) {
partialtx.maxFeePerGas = bundlerGasEstimate.maxFeePerGas;
partialtx.maxPriorityFeePerGas = bundlerGasEstimate.maxPriorityFeePerGas;
} else {
const gas = await this.getGasFee();
partialtx.maxFeePerGas = gas.maxFeePerGas;
partialtx.maxPriorityFeePerGas = gas.maxPriorityFeePerGas;
}

if (bundlerGasEstimate.preVerificationGas) {
partialtx.preVerificationGas = BigNumber.from(bundlerGasEstimate.preVerificationGas);
partialtx.verificationGasLimit = BigNumber.from(bundlerGasEstimate.verificationGas);
partialtx.verificationGasLimit = BigNumber.from(bundlerGasEstimate.verificationGasLimit ?? bundlerGasEstimate.verificationGas);
partialtx.callGasLimit = BigNumber.from(bundlerGasEstimate.callGasLimit);
}

Expand Down

0 comments on commit 34a3255

Please sign in to comment.