Skip to content

Commit

Permalink
feat: reduce the bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
AmanRaj1608 committed Dec 21, 2023
1 parent 2d3fcfa commit 765a3e3
Show file tree
Hide file tree
Showing 77 changed files with 948 additions and 9,544 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v14.17.0
v18.16.0
13 changes: 2 additions & 11 deletions packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"format": "prettier --write \"{src,tests}/**/*.ts\"",
"lint": "tslint -p tsconfig.json"
},
"author": "talhamalik883 <talha.malik@biconomy.io>",
"author": "Biconomy",
"license": "MIT",
"files": [
"dist/*",
Expand All @@ -37,21 +37,12 @@
"nock": "^13.2.9"
},
"dependencies": {
"@account-abstraction/contracts": "^0.6.0",
"@account-abstraction/utils": "^0.4.0",
"@alchemy/aa-core": "^1.2.2",
"@biconomy-devx/account-contracts-v2": "npm:@biconomy-devx/account-contracts-v2@^1.0.0",
"@biconomy/bundler": "^3.1.1",
"@biconomy/common": "^3.1.1",
"@biconomy/core-types": "^3.1.1",
"@biconomy/modules": "^3.1.1",
"@biconomy/node-client": "^3.1.1",
"@biconomy/paymaster": "^3.1.1",
"@ethersproject/logger": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"ethers": "^5.7.0",
"loglevel": "^1.8.1",
"lru-cache": "^10.0.1",
"viem": "^1.2.0"
"viem": "^1.20.3"
}
}
55 changes: 21 additions & 34 deletions packages/account/src/BiconomySmartAccountV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from "viem";
import { BaseSmartContractAccount, getChain, type BigNumberish, type UserOperationStruct } from "@alchemy/aa-core";
import { isNullOrUndefined, packUserOp } from "./utils/Utils";
import { Logger, RPC_PROVIDER_URLS } from "@biconomy/common";
import { BaseValidationModule, ModuleInfo, SendUserOpParams, ECDSAOwnershipValidationModule } from "@biconomy/modules";
import { IHybridPaymaster, IPaymaster, BiconomyPaymaster, SponsorUserOperationDto } from "@biconomy/paymaster";
import { IBundler, UserOpResponse } from "@biconomy/bundler";
Expand All @@ -41,6 +40,7 @@ import {
DEFAULT_FALLBACK_HANDLER_ADDRESS,
PROXY_CREATION_CODE,
ADDRESS_ZERO,
DEFAULT_ENTRYPOINT_ADDRESS,
} from "./utils/Constants";
import { BiconomyFactoryAbi } from "./abi/Factory";
import { BiconomyAccountAbi } from "./abi/SmartAccount";
Expand Down Expand Up @@ -81,8 +81,8 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
super({
...biconomySmartAccountConfig,
chain: getChain(biconomySmartAccountConfig.chainId),
rpcClient: biconomySmartAccountConfig.rpcUrl || (RPC_PROVIDER_URLS[biconomySmartAccountConfig.chainId] as string),
entryPointAddress: biconomySmartAccountConfig.entryPointAddress as Hex,
rpcClient: biconomySmartAccountConfig.rpcUrl || getChain(biconomySmartAccountConfig.chainId).rpcUrls.public.http[0],
entryPointAddress: (biconomySmartAccountConfig.entryPointAddress as Hex) ?? DEFAULT_ENTRYPOINT_ADDRESS,
accountAddress: (biconomySmartAccountConfig.accountAddress as Hex) ?? undefined,
factoryAddress: biconomySmartAccountConfig.factoryAddress ?? DEFAULT_BICONOMY_FACTORY_ADDRESS,
});
Expand All @@ -108,12 +108,11 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {

this.provider = createPublicClient({
chain: getChain(biconomySmartAccountConfig.chainId),
transport: http(biconomySmartAccountConfig.rpcUrl || (RPC_PROVIDER_URLS[biconomySmartAccountConfig.chainId] as string)),
transport: http(biconomySmartAccountConfig.rpcUrl || getChain(biconomySmartAccountConfig.chainId).rpcUrls.public.http[0]),
});

this.scanForUpgradedAccountsFromV1 = biconomySmartAccountConfig.scanForUpgradedAccountsFromV1 ?? false;
this.maxIndexForScan = biconomySmartAccountConfig.maxIndexForScan ?? 10;
// REVIEW: removed the node client
}

/**
Expand Down Expand Up @@ -186,7 +185,6 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
maxIndexForScan,
};
const accountAddress = await this.getV1AccountsUpgradedToV2(queryParams);
Logger.log("account address from V1 ", accountAddress);
if (accountAddress !== ADDRESS_ZERO) {
return accountAddress;
}
Expand Down Expand Up @@ -259,7 +257,6 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
}

async getV1AccountsUpgradedToV2(params: QueryParamsForAddressResolver): Promise<Hex> {
Logger.log("index to filter ", params.index);
const maxIndexForScan = params.maxIndexForScan ?? this.maxIndexForScan;

const addressResolver = getContract({
Expand Down Expand Up @@ -406,7 +403,6 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
* @returns Promise<UserOpResponse>
*/
async sendUserOp(userOp: Partial<UserOperationStruct>, params?: SendUserOpParams): Promise<UserOpResponse> {
Logger.log("userOp received in base account ", userOp);
delete userOp.signature;
const userOperation = await this.signUserOp(userOp, params);
const bundlerResponse = await this.sendSignedUserOp(userOperation);
Expand Down Expand Up @@ -434,9 +430,8 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
"signature",
];
this.validateUserOp(userOp, requiredFields);
Logger.log("userOp validated");
if (!this.bundler) throw new Error("Bundler is not provided");
Logger.log("userOp being sent to the bundler", userOp);
console.info("userOp being sent to the bundler", userOp);

Check warning on line 434 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement
const bundlerResponse = await this.bundler.sendUserOp(userOp);
return bundlerResponse;
}
Expand Down Expand Up @@ -509,7 +504,7 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
}
} catch (error) {
// Not throwing this error as nonce would be 0 if this.getNonce() throw exception, which is expected flow for undeployed account
Logger.log("Error while getting nonce for the account. This is expected for undeployed accounts set nonce to 0");
console.info("Error while getting nonce for the account. This is expected for undeployed accounts set nonce to 0");

Check warning on line 507 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement
}
return nonce;
}
Expand All @@ -531,7 +526,7 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
return gasFeeValues;
} catch (error: any) {
// TODO: should throw error here?
Logger.error("Error while getting gasFeeValues from bundler. Provided bundler might not have getGasFeeValues endpoint", error);
console.error("Error while getting gasFeeValues from bundler. Provided bundler might not have getGasFeeValues endpoint", error);

Check warning on line 529 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement
return gasFeeValues;
}
}
Expand All @@ -544,11 +539,10 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
const initCodeFetchPromise = this.getInitCode();
const dummySignatureFetchPromise = this.getDummySignatures(buildUseropDto?.params);

const [nonceFromFetch, initCode, signature, finalGasFeeValue] = await Promise.all([
const [nonceFromFetch, initCode, signature] = await Promise.all([
this.getBuildUserOpNonce(buildUseropDto?.nonceOptions),
initCodeFetchPromise,
dummySignatureFetchPromise,
this.getGasFeeValues(buildUseropDto?.overrides, buildUseropDto?.skipBundlerGasEstimation),
]);

if (transactions.length === 0) {
Expand All @@ -569,20 +563,13 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
callData: callData,
};

if (finalGasFeeValue.maxFeePerGas) {
userOp.maxFeePerGas = toHex(Number(finalGasFeeValue.maxFeePerGas));
}
if (finalGasFeeValue.maxPriorityFeePerGas) {
userOp.maxPriorityFeePerGas = toHex(Number(finalGasFeeValue.maxPriorityFeePerGas));
}

// 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);
userOp.paymasterAndData = userOp.paymasterAndData ?? "0x";
Logger.log("UserOp after estimation ", userOp);
console.log("UserOp after estimation ", userOp);

Check warning on line 572 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement

return userOp;
}
Expand All @@ -593,14 +580,14 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
}

const feeTokenAddress = tokenPaymasterRequest?.feeQuote?.tokenAddress;
Logger.log("Requested fee token is ", feeTokenAddress);
console.info("Requested fee token is ", feeTokenAddress);

Check warning on line 583 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement

if (!feeTokenAddress || feeTokenAddress === ADDRESS_ZERO) {
throw new Error("Invalid or missing token address. Token address must be part of the feeQuote in tokenPaymasterRequest");
}

const spender = tokenPaymasterRequest?.spender;
Logger.log("Spender address is ", spender);
console.info("Spender address is ", spender);

Check warning on line 590 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement

if (!spender || spender === ADDRESS_ZERO) {
throw new Error("Invalid or missing spender address. Sepnder address must be part of tokenPaymasterRequest");
Expand All @@ -627,7 +614,7 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
let batchData: Array<Hex> = [];

let newCallData = userOp.callData;
Logger.log("Received information about fee token address and quote ", tokenPaymasterRequest);
console.info("Received information about fee token address and quote ", tokenPaymasterRequest);

Check warning on line 617 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement

if (this.paymaster && this.paymaster instanceof BiconomyPaymaster) {
// Make a call to paymaster.buildTokenApprovalTransaction() with necessary details
Expand All @@ -636,7 +623,7 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
const approvalRequest: Transaction = await (this.paymaster as IHybridPaymaster<SponsorUserOperationDto>).buildTokenApprovalTransaction(
tokenPaymasterRequest,
);
Logger.log("ApprovalRequest is for erc20 token ", approvalRequest.to);
console.info("ApprovalRequest is for erc20 token ", approvalRequest.to);

Check warning on line 626 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement

if (approvalRequest.data === "0x" || approvalRequest.to === ADDRESS_ZERO) {
return userOp;
Expand All @@ -657,7 +644,7 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {

const smartAccountExecFunctionName = decodedSmartAccountData.functionName;

Logger.log(`Originally an ${smartAccountExecFunctionName} method call for Biconomy Account V2`);
console.info(`Originally an ${smartAccountExecFunctionName} method call for Biconomy Account V2`);

Check warning on line 647 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement
if (smartAccountExecFunctionName === "execute" || smartAccountExecFunctionName === "execute_ncC") {
const methodArgsSmartWalletExecuteCall = decodedSmartAccountData.args;
const toOriginal = methodArgsSmartWalletExecuteCall[0];
Expand Down Expand Up @@ -696,16 +683,16 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
callData: newCallData,
};
}
Logger.log("UserOp after estimation ", finalUserOp);
console.info("UserOp after estimation ", finalUserOp);

Check warning on line 686 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement
} catch (error) {
Logger.error("Failed to estimate gas for userOp with updated callData ", error);
Logger.log("Sending updated userOp. calculateGasLimit flag should be sent to the paymaster to be able to update callGasLimit");
console.error("Failed to estimate gas for userOp with updated callData ", error);
console.log("Sending updated userOp. calculateGasLimit flag should be sent to the paymaster to be able to update callGasLimit");
}
return finalUserOp;
}
} catch (error) {
Logger.log("Failed to update userOp. Sending back original op");
Logger.error("Failed to update callData with error", error);
console.log("Failed to update userOp. Sending back original op");
console.error("Failed to update callData with error", error);
return userOp;
}
return userOp;
Expand Down Expand Up @@ -773,8 +760,8 @@ export class BiconomySmartAccountV2 extends BaseSmartContractAccount {
return tx;
}

async disableModule(preModule: Hex, moduleAddress: Hex): Promise<UserOpResponse> {
const tx: Transaction = await this.getDisableModuleData(preModule, moduleAddress);
async disableModule(prevModule: Hex, moduleAddress: Hex): Promise<UserOpResponse> {
const tx: Transaction = await this.getDisableModuleData(prevModule, moduleAddress);
const partialUserOp = await this.buildUserOp([tx]);
return this.sendUserOp(partialUserOp);
}
Expand Down
22 changes: 9 additions & 13 deletions packages/account/src/utils/Types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Signer } from "ethers";
import { ChainId } from "@biconomy/core-types";
import { BigNumberish, UserOperationStruct } from "@alchemy/aa-core";
import { BigNumberish, UserOperationStruct, WalletClientSigner } from "@alchemy/aa-core";
import { IBundler } from "@biconomy/bundler";
import { IPaymaster, PaymasterFeeQuote, SponsorUserOperationDto } from "@biconomy/paymaster";
import { BaseValidationModule, ModuleInfo } from "@biconomy/modules";
import { Provider } from "@ethersproject/providers";
import { Hex } from "viem";
import { Hex, WalletClient } from "viem";

export type EntryPointAddresses = {
[address: string]: string;
Expand Down Expand Up @@ -59,27 +56,26 @@ export interface GasOverheads {
}*/

export type BaseSmartAccountConfig = {
// owner?: Signer // can be in child classes
index?: number;
provider?: Provider;
provider?: WalletClient;
entryPointAddress?: string;
accountAddress?: string;
overheads?: Partial<GasOverheads>;
paymaster?: IPaymaster; // PaymasterAPI
bundler?: IBundler; // like HttpRpcClient
chainId: ChainId;
chainId: number;
};

export type BiconomyTokenPaymasterRequest = {
feeQuote: PaymasterFeeQuote;
spender: string;
spender: Hex;
maxApproval?: boolean;
};

export type BiconomySmartAccountConfig = {
signer: Signer;
signer: WalletClientSigner;
rpcUrl?: string;
chainId: ChainId;
chainId: number;
entryPointAddress?: string;
bundler?: IBundler;
paymaster?: IPaymaster;
Expand All @@ -94,7 +90,7 @@ type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyo
type ConditionalValidationProps = RequireAtLeastOne<
{
defaultValidationModule: BaseValidationModule;
signer: Signer;
signer: WalletClientSigner;
},
"defaultValidationModule" | "signer"
>;
Expand Down Expand Up @@ -129,7 +125,7 @@ export type NonceOptions = {

// Used in AccountV1
export type SendUserOpDto = {
signer?: Signer;
signer?: WalletClientSigner;
simulationType?: SimulationType;
};

Expand Down
Loading

0 comments on commit 765a3e3

Please sign in to comment.