Skip to content

Commit

Permalink
Remove extra call to Bundler for Sponsored User ops (#408)
Browse files Browse the repository at this point in the history
* draft psuedo code

* Skip estimateUserOpGas for latency improve

* Fixed conflicts

* Added test to check for failure of sendTransaction

---------

Co-authored-by: GabiDev <gv@popoo.io>
Co-authored-by: Joe Pegler <joepegler123@gmail.com>
  • Loading branch information
3 people authored Mar 4, 2024
1 parent 75698c8 commit 2371b23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
27 changes: 19 additions & 8 deletions packages/account/src/BiconomySmartAccountV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<UserOperationStruct>, tokenPaymasterRequest: BiconomyTokenPaymasterRequest): void {
Expand Down
4 changes: 1 addition & 3 deletions packages/account/tests/account.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 2371b23

Please sign in to comment.