From 2371b230cd5806ec4c7c95ba604d6f924b4be768 Mon Sep 17 00:00:00 2001 From: livingrockrises <90545960+livingrockrises@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:29:24 +0400 Subject: [PATCH] Remove extra call to Bundler for Sponsored User ops (#408) * draft psuedo code * Skip estimateUserOpGas for latency improve * Fixed conflicts * Added test to check for failure of sendTransaction --------- Co-authored-by: GabiDev Co-authored-by: Joe Pegler --- .../account/src/BiconomySmartAccountV2.ts | 27 +++++++++++++------ packages/account/tests/account.e2e.spec.ts | 4 +-- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/account/src/BiconomySmartAccountV2.ts b/packages/account/src/BiconomySmartAccountV2.ts index 76679b043..d02f23cbe 100644 --- a/packages/account/src/BiconomySmartAccountV2.ts +++ b/packages/account/src/BiconomySmartAccountV2.ts @@ -70,7 +70,7 @@ import { BiconomyFactoryAbi } from "./abi/Factory.js"; import { BiconomyAccountAbi } from "./abi/SmartAccount.js"; import { AccountResolverAbi } from "./abi/AccountResolver.js"; import { Logger, StateOverrideSet } from "@biconomy/common"; -import { FeeQuotesOrDataDto, FeeQuotesOrDataResponse } from "@biconomy/paymaster"; +import { BiconomyPaymaster, FeeQuotesOrDataDto, FeeQuotesOrDataResponse } from "@biconomy/paymaster"; type UserOperationKey = keyof UserOperationStruct; @@ -1049,16 +1049,27 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount { // for this Smart Account current validation module dummy signature will be used to estimate gas userOp.signature = signature; - // Note: Can change the default behaviour of calling estimations using bundler/local - userOp = await this.estimateUserOpGas(userOp, buildUseropDto?.stateOverrideSet); + if ( + buildUseropDto?.paymasterServiceData && + buildUseropDto?.paymasterServiceData.mode === PaymasterMode.SPONSORED && + this.paymaster instanceof BiconomyPaymaster + ) { + const gasFeeValues = await this.bundler?.getGasFeeValues(); - if (buildUseropDto?.paymasterServiceData) { - userOp = await this.getPaymasterUserOp(userOp, buildUseropDto.paymasterServiceData); - } + // populate gasfee values and make a call to paymaster + userOp.maxFeePerGas = gasFeeValues?.maxFeePerGas as Hex; + userOp.maxPriorityFeePerGas = gasFeeValues?.maxPriorityFeePerGas as Hex; - Logger.log("UserOp after estimation ", userOp); + userOp = await this.getPaymasterUserOp(userOp, buildUseropDto.paymasterServiceData); + return userOp; + } else { + userOp = await this.estimateUserOpGas(userOp); - return userOp; + if (buildUseropDto?.paymasterServiceData) { + userOp = await this.getPaymasterUserOp(userOp, buildUseropDto.paymasterServiceData); + } + return userOp; + } } private validateUserOpAndPaymasterRequest(userOp: Partial, tokenPaymasterRequest: BiconomyTokenPaymasterRequest): void { diff --git a/packages/account/tests/account.e2e.spec.ts b/packages/account/tests/account.e2e.spec.ts index 148bb18c1..5e6a4a4c7 100644 --- a/packages/account/tests/account.e2e.spec.ts +++ b/packages/account/tests/account.e2e.spec.ts @@ -184,15 +184,13 @@ describe("Account Tests", () => { const { whale: { viemWallet: signer, publicAddress: recipient }, bundlerUrl, - publicClient, - biconomyPaymasterApiKey, nftAddress, } = mumbai; const smartAccount = await createSmartAccountClient({ signer, bundlerUrl, - biconomyPaymasterApiKey, + biconomyPaymasterApiKey: "7K_k68BFN.ed274da8-69a1-496d-a897-508fc2653666", }); const accountAddress = await smartAccount.getAddress();