From a950e1eb50a359b50cd0668850e477fa8803ccdf Mon Sep 17 00:00:00 2001 From: amanraj1608 Date: Tue, 26 Sep 2023 23:46:58 -0400 Subject: [PATCH 1/8] add simulateion type param --- packages/account/src/BaseSmartAccount.ts | 6 +++--- packages/account/src/BiconomySmartAccountV2.ts | 8 ++++---- packages/account/src/SmartAccount.ts | 10 +++++----- packages/account/src/utils/Types.ts | 7 +++++++ packages/bundler/src/Bundler.ts | 10 ++++++++-- packages/bundler/src/interfaces/IBundler.ts | 4 ++-- packages/bundler/src/utils/Types.ts | 6 ++++++ packages/modules/src/utils/Types.ts | 6 ++++++ 8 files changed, 41 insertions(+), 16 deletions(-) diff --git a/packages/account/src/BaseSmartAccount.ts b/packages/account/src/BaseSmartAccount.ts index 918f6befa..a43901513 100644 --- a/packages/account/src/BaseSmartAccount.ts +++ b/packages/account/src/BaseSmartAccount.ts @@ -7,7 +7,7 @@ import { calcPreVerificationGas, DefaultGasLimits } from "./utils/Preverificaito import { NotPromise, packUserOp, Logger, RPC_PROVIDER_URLS } from "@biconomy/common"; import { IBundler, UserOpResponse } from "@biconomy/bundler"; import { IPaymaster, PaymasterAndDataResponse } from "@biconomy/paymaster"; -import { BaseSmartAccountConfig, Overrides, TransactionDetailsForUserOp } from "./utils/Types"; +import { BaseSmartAccountConfig, Overrides, SendUserOpOptions, TransactionDetailsForUserOp } from "./utils/Types"; import { GasOverheads } from "./utils/Preverificaiton"; import { EntryPoint, EntryPoint__factory } from "@account-abstraction/contracts"; import { DEFAULT_ENTRYPOINT_ADDRESS } from "./utils/Constants"; @@ -176,7 +176,7 @@ export abstract class BaseSmartAccount implements IBaseSmartAccount { * @description This function call will take 'signedUserOp' as input and send it to the bundler * @returns */ - async sendSignedUserOp(userOp: UserOperation): Promise { + async sendSignedUserOp(userOp: UserOperation, params?: SendUserOpOptions): Promise { const requiredFields: UserOperationKey[] = [ "sender", "nonce", @@ -194,7 +194,7 @@ export abstract class BaseSmartAccount implements IBaseSmartAccount { Logger.log("userOp validated"); if (!this.bundler) throw new Error("Bundler is not provided"); Logger.log("userOp being sent to the bundler", userOp); - const bundlerResponse = await this.bundler.sendUserOp(userOp); + const bundlerResponse = await this.bundler.sendUserOp(userOp, params); return bundlerResponse; } diff --git a/packages/account/src/BiconomySmartAccountV2.ts b/packages/account/src/BiconomySmartAccountV2.ts index 6e2df9b71..777151102 100644 --- a/packages/account/src/BiconomySmartAccountV2.ts +++ b/packages/account/src/BiconomySmartAccountV2.ts @@ -11,7 +11,7 @@ import { SmartAccountFactory_v200__factory, } from "@biconomy/common"; import { BiconomyTokenPaymasterRequest, BiconomySmartAccountV2Config, CounterFactualAddressParam, BuildUserOpOptions } from "./utils/Types"; -import { BaseValidationModule, ModuleInfo } from "@biconomy/modules"; +import { BaseValidationModule, ModuleInfo, SendUserOpParams } from "@biconomy/modules"; import { UserOperation, Transaction } from "@biconomy/core-types"; import NodeClient from "@biconomy/node-client"; import INodeClient from "@biconomy/node-client"; @@ -240,7 +240,7 @@ export class BiconomySmartAccountV2 extends BaseSmartAccount { return "0x"; } - async signUserOp(userOp: Partial, params?: ModuleInfo): Promise { + async signUserOp(userOp: Partial, params?: SendUserOpParams): Promise { this.isActiveValidationModuleDefined(); const requiredFields: UserOperationKey[] = [ "sender", @@ -296,7 +296,7 @@ export class BiconomySmartAccountV2 extends BaseSmartAccount { * @description This function call will take 'unsignedUserOp' as an input, sign it with the owner key, and send it to the bundler. * @returns Promise */ - async sendUserOp(userOp: Partial, params?: ModuleInfo): Promise { + async sendUserOp(userOp: Partial, params?: SendUserOpParams): Promise { Logger.log("userOp received in base account ", userOp); delete userOp.signature; const userOperation = await this.signUserOp(userOp, params); @@ -486,7 +486,7 @@ export class BiconomySmartAccountV2 extends BaseSmartAccount { return userOp; } - async signUserOpHash(userOpHash: string, params?: ModuleInfo): Promise { + async signUserOpHash(userOpHash: string, params?: SendUserOpParams): Promise { this.isActiveValidationModuleDefined(); const moduleSig = await this.activeValidationModule.signUserOpHash(userOpHash, params); diff --git a/packages/account/src/SmartAccount.ts b/packages/account/src/SmartAccount.ts index fcc57a242..ad4ec560f 100644 --- a/packages/account/src/SmartAccount.ts +++ b/packages/account/src/SmartAccount.ts @@ -10,7 +10,7 @@ import { IBundler, UserOpResponse } from "@biconomy/bundler"; import { IPaymaster, PaymasterAndDataResponse } from "@biconomy/paymaster"; import { Logger } from "@biconomy/common"; import { IEntryPoint } from "@account-abstraction/contracts"; -import { SmartAccountConfig, Overrides } from "./utils/Types"; +import { SmartAccountConfig, Overrides, SendUserOpOptions } from "./utils/Types"; type UserOperationKey = keyof UserOperation; @@ -239,11 +239,11 @@ export abstract class SmartAccount implements ISmartAccount { * @description This function call will take 'unsignedUserOp' as an input, sign it with the owner key, and send it to the bundler. * @returns Promise */ - async sendUserOp(userOp: Partial): Promise { + async sendUserOp(userOp: Partial, params?: SendUserOpOptions): Promise { Logger.log("userOp received in base account ", userOp); delete userOp.signature; const userOperation = await this.signUserOp(userOp); - const bundlerResponse = await this.sendSignedUserOp(userOperation); + const bundlerResponse = await this.sendSignedUserOp(userOperation, params); return bundlerResponse; } @@ -253,7 +253,7 @@ export abstract class SmartAccount implements ISmartAccount { * @description This function call will take 'signedUserOp' as input and send it to the bundler * @returns */ - async sendSignedUserOp(userOp: UserOperation): Promise { + async sendSignedUserOp(userOp: UserOperation, params?: SendUserOpOptions): Promise { const requiredFields: UserOperationKey[] = [ "sender", "nonce", @@ -271,7 +271,7 @@ export abstract class SmartAccount implements ISmartAccount { Logger.log("userOp validated"); if (!this.bundler) throw new Error("Bundler is not provided"); Logger.log("userOp being sent to the bundler", userOp); - const bundlerResponse = await this.bundler.sendUserOp(userOp); + const bundlerResponse = await this.bundler.sendUserOp(userOp, params); return bundlerResponse; } } diff --git a/packages/account/src/utils/Types.ts b/packages/account/src/utils/Types.ts index 5e4c578e7..3e3c50b63 100644 --- a/packages/account/src/utils/Types.ts +++ b/packages/account/src/utils/Types.ts @@ -87,6 +87,13 @@ export type NonceOptions = { nonceOverride?: number; }; +export type SendUserOpOptions = { + signer?: Signer; + simulationType?: SimulationType; +}; + +export type SimulationType = "validation" | "validation_and_execution"; + export type Overrides = { callGasLimit?: BigNumberish; verificationGasLimit?: BigNumberish; diff --git a/packages/bundler/src/Bundler.ts b/packages/bundler/src/Bundler.ts index 24399febf..2cc834744 100644 --- a/packages/bundler/src/Bundler.ts +++ b/packages/bundler/src/Bundler.ts @@ -10,6 +10,7 @@ import { SendUserOpResponse, UserOpGasResponse, UserOpByHashResponse, + SendUserOpOptions, } from "./utils/Types"; import { resolveProperties } from "ethers/lib/utils"; import { deepHexlify, sendRequest, getTimestampInSeconds, HttpMethod, Logger, RPC_PROVIDER_URLS } from "@biconomy/common"; @@ -78,12 +79,17 @@ export class Bundler implements IBundler { * @description This function will send signed userOp to bundler to get mined on chain * @returns Promise */ - async sendUserOp(userOp: UserOperation): Promise { + async sendUserOp(userOp: UserOperation, simulationParam?: SendUserOpOptions): Promise { const chainId = this.bundlerConfig.chainId; // transformUserOP will convert all bigNumber values to string userOp = transformUserOP(userOp); const hexifiedUserOp = deepHexlify(await resolveProperties(userOp)); - const params = [hexifiedUserOp, this.bundlerConfig.entryPointAddress]; + const simType = { + simulation_type: simulationParam?.simulationType || "validation", + }; + // const params = [hexifiedUserOp, this.bundlerConfig.entryPointAddress, validationSimulation]; + // const params = [hexifiedUserOp, this.bundlerConfig.entryPointAddress, validationAndExecutionSimulation]; + const params = [hexifiedUserOp, this.bundlerConfig.entryPointAddress, simType]; const bundlerUrl = this.getBundlerUrl(); const sendUserOperationResponse: SendUserOpResponse = await sendRequest({ url: bundlerUrl, diff --git a/packages/bundler/src/interfaces/IBundler.ts b/packages/bundler/src/interfaces/IBundler.ts index a64c1151d..4430f9ae3 100644 --- a/packages/bundler/src/interfaces/IBundler.ts +++ b/packages/bundler/src/interfaces/IBundler.ts @@ -1,9 +1,9 @@ -import { UserOpResponse, UserOpGasResponse, UserOpReceipt, UserOpByHashResponse } from "../utils/Types"; +import { UserOpResponse, UserOpGasResponse, UserOpReceipt, UserOpByHashResponse, SendUserOpOptions } from "../utils/Types"; import { UserOperation } from "@biconomy/core-types"; export interface IBundler { estimateUserOpGas(_userOp: Partial): Promise; - sendUserOp(_userOp: UserOperation): Promise; + sendUserOp(_userOp: UserOperation, _params?: SendUserOpOptions): Promise; getUserOpReceipt(_userOpHash: string): Promise; getUserOpByHash(_userOpHash: string): Promise; } diff --git a/packages/bundler/src/utils/Types.ts b/packages/bundler/src/utils/Types.ts index 17e1e8def..2cd6c4e91 100644 --- a/packages/bundler/src/utils/Types.ts +++ b/packages/bundler/src/utils/Types.ts @@ -23,6 +23,12 @@ export type UserOpReceipt = { receipt: ethers.providers.TransactionReceipt; }; +export type SendUserOpOptions = { + simulationType?: SimulationType; +}; + +export type SimulationType = "validation" | "validation_and_execution"; + // Converted to JsonRpcResponse with strict type export type GetUserOperationResponse = { jsonrpc: string; diff --git a/packages/modules/src/utils/Types.ts b/packages/modules/src/utils/Types.ts index 1c4e65b01..1c239ef0f 100644 --- a/packages/modules/src/utils/Types.ts +++ b/packages/modules/src/utils/Types.ts @@ -59,6 +59,12 @@ export type ModuleInfo = { batchSessionParams?: SessionParams[]; }; +export interface SendUserOpParams extends ModuleInfo { + simulationType: SimulationType; +} + +export type SimulationType = "validation" | "validation_and_execution"; + export type CreateSessionDataResponse = { data: string; sessionIDInfo: Array; From 24d2d2018ca4a1f1af6374eaf176ea6765f761b4 Mon Sep 17 00:00:00 2001 From: amanraj1608 Date: Wed, 27 Sep 2023 10:29:24 -0400 Subject: [PATCH 2/8] make SimulationType optional --- packages/modules/src/utils/Types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/modules/src/utils/Types.ts b/packages/modules/src/utils/Types.ts index 1c239ef0f..64b9bb940 100644 --- a/packages/modules/src/utils/Types.ts +++ b/packages/modules/src/utils/Types.ts @@ -60,7 +60,7 @@ export type ModuleInfo = { }; export interface SendUserOpParams extends ModuleInfo { - simulationType: SimulationType; + simulationType?: SimulationType; } export type SimulationType = "validation" | "validation_and_execution"; From 04d49412bfc06e90d03d21d0bc8ec87447352e85 Mon Sep 17 00:00:00 2001 From: amanraj1608 Date: Wed, 27 Sep 2023 11:19:09 -0400 Subject: [PATCH 3/8] minor fixes --- packages/account/src/BiconomySmartAccountV2.ts | 2 +- packages/bundler/src/Bundler.ts | 2 -- packages/bundler/src/interfaces/IBundler.ts | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/account/src/BiconomySmartAccountV2.ts b/packages/account/src/BiconomySmartAccountV2.ts index 777151102..f3782e3ef 100644 --- a/packages/account/src/BiconomySmartAccountV2.ts +++ b/packages/account/src/BiconomySmartAccountV2.ts @@ -300,7 +300,7 @@ export class BiconomySmartAccountV2 extends BaseSmartAccount { Logger.log("userOp received in base account ", userOp); delete userOp.signature; const userOperation = await this.signUserOp(userOp, params); - const bundlerResponse = await this.sendSignedUserOp(userOperation); + const bundlerResponse = await this.sendSignedUserOp(userOperation, params); return bundlerResponse; } diff --git a/packages/bundler/src/Bundler.ts b/packages/bundler/src/Bundler.ts index 2cc834744..37a48d8e5 100644 --- a/packages/bundler/src/Bundler.ts +++ b/packages/bundler/src/Bundler.ts @@ -87,8 +87,6 @@ export class Bundler implements IBundler { const simType = { simulation_type: simulationParam?.simulationType || "validation", }; - // const params = [hexifiedUserOp, this.bundlerConfig.entryPointAddress, validationSimulation]; - // const params = [hexifiedUserOp, this.bundlerConfig.entryPointAddress, validationAndExecutionSimulation]; const params = [hexifiedUserOp, this.bundlerConfig.entryPointAddress, simType]; const bundlerUrl = this.getBundlerUrl(); const sendUserOperationResponse: SendUserOpResponse = await sendRequest({ diff --git a/packages/bundler/src/interfaces/IBundler.ts b/packages/bundler/src/interfaces/IBundler.ts index 4430f9ae3..d34c1321a 100644 --- a/packages/bundler/src/interfaces/IBundler.ts +++ b/packages/bundler/src/interfaces/IBundler.ts @@ -3,7 +3,7 @@ import { UserOperation } from "@biconomy/core-types"; export interface IBundler { estimateUserOpGas(_userOp: Partial): Promise; - sendUserOp(_userOp: UserOperation, _params?: SendUserOpOptions): Promise; + sendUserOp(_userOp: UserOperation, _simulationParam?: SendUserOpOptions): Promise; getUserOpReceipt(_userOpHash: string): Promise; getUserOpByHash(_userOpHash: string): Promise; } From 5f280fa271a6385b494b4ee5a73b23311390e741 Mon Sep 17 00:00:00 2001 From: amanraj1608 Date: Wed, 27 Sep 2023 13:03:47 -0400 Subject: [PATCH 4/8] update type naming --- packages/account/src/BiconomySmartAccountV2.ts | 10 ++++++++-- packages/account/src/SmartAccount.ts | 6 +++--- packages/account/src/utils/Types.ts | 6 +++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/account/src/BiconomySmartAccountV2.ts b/packages/account/src/BiconomySmartAccountV2.ts index f3782e3ef..7c0a70d55 100644 --- a/packages/account/src/BiconomySmartAccountV2.ts +++ b/packages/account/src/BiconomySmartAccountV2.ts @@ -10,7 +10,13 @@ import { SmartAccount_v200__factory, SmartAccountFactory_v200__factory, } from "@biconomy/common"; -import { BiconomyTokenPaymasterRequest, BiconomySmartAccountV2Config, CounterFactualAddressParam, BuildUserOpOptions } from "./utils/Types"; +import { + BiconomyTokenPaymasterRequest, + BiconomySmartAccountV2Config, + CounterFactualAddressParam, + BuildUserOpOptions, + SendUserOpOptions, +} from "./utils/Types"; import { BaseValidationModule, ModuleInfo, SendUserOpParams } from "@biconomy/modules"; import { UserOperation, Transaction } from "@biconomy/core-types"; import NodeClient from "@biconomy/node-client"; @@ -296,7 +302,7 @@ export class BiconomySmartAccountV2 extends BaseSmartAccount { * @description This function call will take 'unsignedUserOp' as an input, sign it with the owner key, and send it to the bundler. * @returns Promise */ - async sendUserOp(userOp: Partial, params?: SendUserOpParams): Promise { + async sendUserOp(userOp: Partial, params?: SendUserOpOptions): Promise { Logger.log("userOp received in base account ", userOp); delete userOp.signature; const userOperation = await this.signUserOp(userOp, params); diff --git a/packages/account/src/SmartAccount.ts b/packages/account/src/SmartAccount.ts index ad4ec560f..065d1f52e 100644 --- a/packages/account/src/SmartAccount.ts +++ b/packages/account/src/SmartAccount.ts @@ -10,7 +10,7 @@ import { IBundler, UserOpResponse } from "@biconomy/bundler"; import { IPaymaster, PaymasterAndDataResponse } from "@biconomy/paymaster"; import { Logger } from "@biconomy/common"; import { IEntryPoint } from "@account-abstraction/contracts"; -import { SmartAccountConfig, Overrides, SendUserOpOptions } from "./utils/Types"; +import { SmartAccountConfig, Overrides, SendUserOpDto } from "./utils/Types"; type UserOperationKey = keyof UserOperation; @@ -239,7 +239,7 @@ export abstract class SmartAccount implements ISmartAccount { * @description This function call will take 'unsignedUserOp' as an input, sign it with the owner key, and send it to the bundler. * @returns Promise */ - async sendUserOp(userOp: Partial, params?: SendUserOpOptions): Promise { + async sendUserOp(userOp: Partial, params?: SendUserOpDto): Promise { Logger.log("userOp received in base account ", userOp); delete userOp.signature; const userOperation = await this.signUserOp(userOp); @@ -253,7 +253,7 @@ export abstract class SmartAccount implements ISmartAccount { * @description This function call will take 'signedUserOp' as input and send it to the bundler * @returns */ - async sendSignedUserOp(userOp: UserOperation, params?: SendUserOpOptions): Promise { + async sendSignedUserOp(userOp: UserOperation, params?: SendUserOpDto): Promise { const requiredFields: UserOperationKey[] = [ "sender", "nonce", diff --git a/packages/account/src/utils/Types.ts b/packages/account/src/utils/Types.ts index 3e3c50b63..c4faa1c32 100644 --- a/packages/account/src/utils/Types.ts +++ b/packages/account/src/utils/Types.ts @@ -87,11 +87,15 @@ export type NonceOptions = { nonceOverride?: number; }; -export type SendUserOpOptions = { +export type SendUserOpDto = { signer?: Signer; simulationType?: SimulationType; }; +export type SendUserOpOptions = { + simulationType?: SimulationType; +}; + export type SimulationType = "validation" | "validation_and_execution"; export type Overrides = { From 1090b7cac6be3fed0fa815674382b25204b7cf3d Mon Sep 17 00:00:00 2001 From: livingrockrises <90545960+livingrockrises@users.noreply.github.com> Date: Wed, 27 Sep 2023 14:01:46 -0400 Subject: [PATCH 5/8] minor refactor --- packages/account/src/utils/Types.ts | 2 ++ packages/node-client/README.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/account/src/utils/Types.ts b/packages/account/src/utils/Types.ts index c4faa1c32..9bd96981b 100644 --- a/packages/account/src/utils/Types.ts +++ b/packages/account/src/utils/Types.ts @@ -87,11 +87,13 @@ export type NonceOptions = { nonceOverride?: number; }; +// Used in AccountV1 export type SendUserOpDto = { signer?: Signer; simulationType?: SimulationType; }; +// Generic options in AccountV2 export type SendUserOpOptions = { simulationType?: SimulationType; }; diff --git a/packages/node-client/README.md b/packages/node-client/README.md index f77c33226..d9aedb44f 100644 --- a/packages/node-client/README.md +++ b/packages/node-client/README.md @@ -69,7 +69,7 @@ const balanceParams: BalancesDto = tokenAddresses: [], }; -const balFromSdk = await nodeClient.getAlltokenBalances(balanceParams); +const balFromSdk = await nodeClient.getAllTokenBalances(balanceParams); console.info("balFromSdk ", balFromSdk); const usdBalFromSdk = await nodeClient.getTotalBalanceInUsd(balanceParams); From 5b1d4bfd7b5062d05bbb97286b833d879cd972b0 Mon Sep 17 00:00:00 2001 From: Ankur Dubey Date: Thu, 28 Sep 2023 16:59:18 +0530 Subject: [PATCH 6/8] fix: optimistic implementation for getNonce() and cache for isAccountDeployed --- packages/account/package.json | 4 +++- packages/account/src/BaseSmartAccount.ts | 15 +++++++++++++-- packages/account/src/BiconomySmartAccountV2.ts | 10 +++++++--- packages/account/src/SmartAccount.ts | 5 +++-- packages/web3-auth-native/src/SocialLogin.ts | 5 +++-- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/packages/account/package.json b/packages/account/package.json index 41d8c2a54..018d66a6d 100644 --- a/packages/account/package.json +++ b/packages/account/package.json @@ -47,6 +47,8 @@ "@biconomy/node-client": "^3.1.0", "@biconomy/paymaster": "^3.1.0", "@ethersproject/providers": "^5.7.2", - "ethers": "^5.7.0" + "ethers": "^5.7.0", + "loglevel": "^1.8.1", + "lru-cache": "^10.0.1" } } diff --git a/packages/account/src/BaseSmartAccount.ts b/packages/account/src/BaseSmartAccount.ts index 918f6befa..e98bbcef2 100644 --- a/packages/account/src/BaseSmartAccount.ts +++ b/packages/account/src/BaseSmartAccount.ts @@ -11,6 +11,7 @@ import { BaseSmartAccountConfig, Overrides, TransactionDetailsForUserOp } from " import { GasOverheads } from "./utils/Preverificaiton"; import { EntryPoint, EntryPoint__factory } from "@account-abstraction/contracts"; import { DEFAULT_ENTRYPOINT_ADDRESS } from "./utils/Constants"; +import LRUCache = require("lru-cache"); type UserOperationKey = keyof UserOperation; @@ -35,6 +36,10 @@ export abstract class BaseSmartAccount implements IBaseSmartAccount { // entryPoint connected to "zero" address. allowed to make static calls (e.g. to getSenderAddress) private readonly entryPoint!: EntryPoint; + private isContractDeployedCache = new LRUCache({ + max: 500, + }); + constructor(_smartAccountConfig: BaseSmartAccountConfig) { this.index = _smartAccountConfig.index ?? 0; this.overheads = _smartAccountConfig.overheads; @@ -242,8 +247,9 @@ export abstract class BaseSmartAccount implements IBaseSmartAccount { delete userOp.maxFeePerGas; delete userOp.maxPriorityFeePerGas; // Making call to bundler to get gas estimations for userOp - const { callGasLimit, verificationGasLimit, preVerificationGas, maxFeePerGas, maxPriorityFeePerGas } = - await this.bundler.estimateUserOpGas(userOp); + const { callGasLimit, verificationGasLimit, preVerificationGas, maxFeePerGas, maxPriorityFeePerGas } = await this.bundler.estimateUserOpGas( + userOp, + ); // if neither user sent gas fee nor the bundler, estimate gas from provider if (!userOp.maxFeePerGas && !userOp.maxPriorityFeePerGas && (!maxFeePerGas || !maxPriorityFeePerGas)) { const feeData = await this.provider.getFeeData(); @@ -270,10 +276,15 @@ export abstract class BaseSmartAccount implements IBaseSmartAccount { } async isAccountDeployed(address: string): Promise { + if (this.isContractDeployedCache.get(address)) { + return true; + } + this.isProviderDefined(); let isDeployed = false; const contractCode = await this.provider.getCode(address); if (contractCode.length > 2) { + this.isContractDeployedCache.set(address, true); isDeployed = true; } else { isDeployed = false; diff --git a/packages/account/src/BiconomySmartAccountV2.ts b/packages/account/src/BiconomySmartAccountV2.ts index 6e2df9b71..0edc34842 100644 --- a/packages/account/src/BiconomySmartAccountV2.ts +++ b/packages/account/src/BiconomySmartAccountV2.ts @@ -32,6 +32,7 @@ import { DEFAULT_FALLBACK_HANDLER_ADDRESS, PROXY_CREATION_CODE, } from "./utils/Constants"; +import log from "loglevel"; type UserOperationKey = keyof UserOperation; export class BiconomySmartAccountV2 extends BaseSmartAccount { @@ -130,11 +131,14 @@ export class BiconomySmartAccountV2 extends BaseSmartAccount { // Could call it nonce space async getNonce(nonceKey?: number): Promise { const nonceSpace = nonceKey ?? 0; - if (await this.isAccountDeployed(await this.getAccountAddress())) { + try { const accountContract = await this._getAccountContract(); - return accountContract.nonce(nonceSpace); + const nonce = await accountContract.nonce(nonceSpace); + return nonce; + } catch (e) { + log.debug("Failed to get nonce from deployed account. Returning 0 as nonce"); + return BigNumber.from(0); } - return BigNumber.from(0); } /** diff --git a/packages/account/src/SmartAccount.ts b/packages/account/src/SmartAccount.ts index fcc57a242..88ab3fcbe 100644 --- a/packages/account/src/SmartAccount.ts +++ b/packages/account/src/SmartAccount.ts @@ -124,8 +124,9 @@ export abstract class SmartAccount implements ISmartAccount { delete userOp.maxFeePerGas; delete userOp.maxPriorityFeePerGas; // Making call to bundler to get gas estimations for userOp - const { callGasLimit, verificationGasLimit, preVerificationGas, maxFeePerGas, maxPriorityFeePerGas } = - await this.bundler.estimateUserOpGas(userOp); + const { callGasLimit, verificationGasLimit, preVerificationGas, maxFeePerGas, maxPriorityFeePerGas } = await this.bundler.estimateUserOpGas( + userOp, + ); if (!userOp.maxFeePerGas && !userOp.maxPriorityFeePerGas && (!maxFeePerGas || !maxPriorityFeePerGas)) { const feeData = await this.provider.getFeeData(); finalUserOp.maxFeePerGas = feeData.maxFeePerGas ?? feeData.gasPrice ?? (await this.provider.getGasPrice()); diff --git a/packages/web3-auth-native/src/SocialLogin.ts b/packages/web3-auth-native/src/SocialLogin.ts index a85530f1e..4222b3b00 100644 --- a/packages/web3-auth-native/src/SocialLogin.ts +++ b/packages/web3-auth-native/src/SocialLogin.ts @@ -31,8 +31,9 @@ class SocialLogin { } async whitelistUrl(origin: string): Promise { - const whiteListUrlResponse: WhiteListSignatureResponse = - await this.nodeClient.whitelistUrl(origin) + const whiteListUrlResponse: WhiteListSignatureResponse = await this.nodeClient.whitelistUrl( + origin + ) return whiteListUrlResponse.data } From a77f0dcecdc15b79aa8f1bc7174d69af2aba0bca Mon Sep 17 00:00:00 2001 From: livingrockrises <90545960+livingrockrises@users.noreply.github.com> Date: Thu, 28 Sep 2023 11:57:07 -0400 Subject: [PATCH 7/8] fix linting --- packages/account/src/BaseSmartAccount.ts | 5 ++--- packages/account/src/SmartAccount.ts | 5 ++--- packages/web3-auth-native/src/SocialLogin.ts | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/account/src/BaseSmartAccount.ts b/packages/account/src/BaseSmartAccount.ts index e98bbcef2..3369572a9 100644 --- a/packages/account/src/BaseSmartAccount.ts +++ b/packages/account/src/BaseSmartAccount.ts @@ -247,9 +247,8 @@ export abstract class BaseSmartAccount implements IBaseSmartAccount { delete userOp.maxFeePerGas; delete userOp.maxPriorityFeePerGas; // Making call to bundler to get gas estimations for userOp - const { callGasLimit, verificationGasLimit, preVerificationGas, maxFeePerGas, maxPriorityFeePerGas } = await this.bundler.estimateUserOpGas( - userOp, - ); + const { callGasLimit, verificationGasLimit, preVerificationGas, maxFeePerGas, maxPriorityFeePerGas } = + await this.bundler.estimateUserOpGas(userOp); // if neither user sent gas fee nor the bundler, estimate gas from provider if (!userOp.maxFeePerGas && !userOp.maxPriorityFeePerGas && (!maxFeePerGas || !maxPriorityFeePerGas)) { const feeData = await this.provider.getFeeData(); diff --git a/packages/account/src/SmartAccount.ts b/packages/account/src/SmartAccount.ts index 88ab3fcbe..fcc57a242 100644 --- a/packages/account/src/SmartAccount.ts +++ b/packages/account/src/SmartAccount.ts @@ -124,9 +124,8 @@ export abstract class SmartAccount implements ISmartAccount { delete userOp.maxFeePerGas; delete userOp.maxPriorityFeePerGas; // Making call to bundler to get gas estimations for userOp - const { callGasLimit, verificationGasLimit, preVerificationGas, maxFeePerGas, maxPriorityFeePerGas } = await this.bundler.estimateUserOpGas( - userOp, - ); + const { callGasLimit, verificationGasLimit, preVerificationGas, maxFeePerGas, maxPriorityFeePerGas } = + await this.bundler.estimateUserOpGas(userOp); if (!userOp.maxFeePerGas && !userOp.maxPriorityFeePerGas && (!maxFeePerGas || !maxPriorityFeePerGas)) { const feeData = await this.provider.getFeeData(); finalUserOp.maxFeePerGas = feeData.maxFeePerGas ?? feeData.gasPrice ?? (await this.provider.getGasPrice()); diff --git a/packages/web3-auth-native/src/SocialLogin.ts b/packages/web3-auth-native/src/SocialLogin.ts index 4222b3b00..a85530f1e 100644 --- a/packages/web3-auth-native/src/SocialLogin.ts +++ b/packages/web3-auth-native/src/SocialLogin.ts @@ -31,9 +31,8 @@ class SocialLogin { } async whitelistUrl(origin: string): Promise { - const whiteListUrlResponse: WhiteListSignatureResponse = await this.nodeClient.whitelistUrl( - origin - ) + const whiteListUrlResponse: WhiteListSignatureResponse = + await this.nodeClient.whitelistUrl(origin) return whiteListUrlResponse.data } From 2a3e8c36cdf9d79b1994d48e6e579ffa6be66b51 Mon Sep 17 00:00:00 2001 From: livingrockrises <90545960+livingrockrises@users.noreply.github.com> Date: Thu, 28 Sep 2023 12:15:23 -0400 Subject: [PATCH 8/8] update import for lru cache --- packages/account/src/BaseSmartAccount.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/account/src/BaseSmartAccount.ts b/packages/account/src/BaseSmartAccount.ts index 3369572a9..7030daa1c 100644 --- a/packages/account/src/BaseSmartAccount.ts +++ b/packages/account/src/BaseSmartAccount.ts @@ -11,7 +11,7 @@ import { BaseSmartAccountConfig, Overrides, TransactionDetailsForUserOp } from " import { GasOverheads } from "./utils/Preverificaiton"; import { EntryPoint, EntryPoint__factory } from "@account-abstraction/contracts"; import { DEFAULT_ENTRYPOINT_ADDRESS } from "./utils/Constants"; -import LRUCache = require("lru-cache"); +import { LRUCache } from 'lru-cache' type UserOperationKey = keyof UserOperation;