Skip to content

Commit

Permalink
Feat/remove node client (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler committed Oct 11, 2024
1 parent 9669f7d commit 4d41831
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 161 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
"link:all": "./linkAll.sh",
"build": "lerna run build",
"clean": "lerna clean && lerna run unbuild",
"format": "lerna run format --npm-client=yarn",
"format": "lerna run format",
"prettier": "npx prettier --write .",
"lint": "eslint -c .eslintrc.js 'packages/*/src/**/*.{ts,tsx}'",
"lint:fix": "eslint -c .eslintrc.js 'packages/*/src/**/*.{ts,tsx}' --fix",
"test:run": "yarn jest --runInBand",
"test": "concurrently -k --success first 'yarn start:ganache' 'yarn test:run'",
"start:ganache": "ganache -m 'direct buyer cliff train rice spirit census refuse glare expire innocent quote'",
"test:ci": "FORCE_COLOR=1 lerna run test:ci --stream --npm-client=yarn",
"test:ci": "FORCE_COLOR=1 lerna run test:ci --stream",
"test:coverage": "concurrently -k --success first 'yarn start:ganache' 'yarn jest --runInBand --coverage'",
"diff": "lerna diff",
"release": "lerna version patch --no-git-tag-version --no-push --conventional-commits --yes"
Expand All @@ -59,6 +59,7 @@
"typescript": "^5.2.2"
},
"devDependencies": {
"@nx/nx-darwin-arm64": "^20.0.0",
"@types/debug": "^4.1.9",
"@types/jest": "^29.5.4",
"@typescript-eslint/eslint-plugin": "^6.7.0",
Expand Down
14 changes: 7 additions & 7 deletions packages/account/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@biconomy/account",
"version": "3.1.3",
"version": "3.1.4",
"description": "This package provides apis for ERC-4337 based smart account implementations",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts",
Expand Down Expand Up @@ -42,12 +42,12 @@
"@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.3",
"@biconomy/common": "^3.1.3",
"@biconomy/core-types": "^3.1.3",
"@biconomy/modules": "^3.1.3",
"@biconomy/node-client": "^3.1.3",
"@biconomy/paymaster": "^3.1.3",
"@biconomy/bundler": "^3.1.4",
"@biconomy/common": "^3.1.4",
"@biconomy/core-types": "^3.1.4",
"@biconomy/modules": "^3.1.4",
"@biconomy/node-client": "^3.1.4",
"@biconomy/paymaster": "^3.1.4",
"@ethersproject/logger": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"ethers": "^5.7.0",
Expand Down
83 changes: 22 additions & 61 deletions packages/account/src/BiconomySmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { ethers, BigNumberish, BytesLike, BigNumber } from "ethers";
import { SmartAccount } from "./SmartAccount";
import {
Logger,
NODE_CLIENT_URL,
RPC_PROVIDER_URLS,
SmartAccountFactory_v100,
SmartAccountFactory_v100__factory,
SmartAccount_v200,
getEntryPointContract,
getSAFactoryContract,
Expand All @@ -14,35 +14,27 @@ import {
} from "@biconomy/common";
import { BiconomySmartAccountConfig, Overrides, BiconomyTokenPaymasterRequest, InitilizationData } from "./utils/Types";
import { UserOperation, Transaction, SmartAccountType } from "@biconomy/core-types";
import NodeClient from "@biconomy/node-client";
import INodeClient from "@biconomy/node-client";
// import NodeClient from "@biconomy/node-client";
// import INodeClient from "@biconomy/node-client";
import { IHybridPaymaster, BiconomyPaymaster, SponsorUserOperationDto } from "@biconomy/paymaster";
import { DEFAULT_ECDSA_OWNERSHIP_MODULE, ECDSAOwnershipValidationModule } from "@biconomy/modules";
import { IBiconomySmartAccount } from "./interfaces/IBiconomySmartAccount";
import {
ISmartAccount,
SupportedChainsResponse,
BalancesResponse,
BalancesDto,
UsdBalanceResponse,
SmartAccountByOwnerDto,
SmartAccountsResponse,
SCWTransactionResponse,
} from "@biconomy/node-client";
import { ISmartAccount } from "@biconomy/node-client";
import {
ENTRYPOINT_ADDRESSES,
BICONOMY_FACTORY_ADDRESSES,
BICONOMY_IMPLEMENTATION_ADDRESSES,
DEFAULT_ENTRYPOINT_ADDRESS,
DEFAULT_BICONOMY_IMPLEMENTATION_ADDRESS,
BICONOMY_IMPLEMENTATION_ADDRESSES_BY_VERSION,
ENTRYPOINT_ADDRESSES_BY_VERSION,
} from "./utils/Constants";
import { Signer } from "ethers";

export class BiconomySmartAccount extends SmartAccount implements IBiconomySmartAccount {
private factory!: SmartAccountFactory_v100;

private nodeClient: INodeClient;
// private nodeClient: INodeClient;

private accountIndex!: number;

Expand All @@ -53,7 +45,7 @@ export class BiconomySmartAccount extends SmartAccount implements IBiconomySmart
private _isInitialised!: boolean;

constructor(readonly biconomySmartAccountConfig: BiconomySmartAccountConfig) {
const { signer, rpcUrl, entryPointAddress, bundler, paymaster, chainId, nodeClientUrl } = biconomySmartAccountConfig;
const { signer, rpcUrl, entryPointAddress, bundler, paymaster, chainId } = biconomySmartAccountConfig;

const _entryPointAddress = entryPointAddress ?? DEFAULT_ENTRYPOINT_ADDRESS;
super({
Expand All @@ -68,7 +60,6 @@ export class BiconomySmartAccount extends SmartAccount implements IBiconomySmart
);
}
this.provider = new JsonRpcProvider(_rpcUrl);
this.nodeClient = new NodeClient({ txServiceUrl: nodeClientUrl ?? NODE_CLIENT_URL });
this.signer = signer;

if (paymaster) {
Expand Down Expand Up @@ -127,21 +118,21 @@ export class BiconomySmartAccount extends SmartAccount implements IBiconomySmart
}

private setProxyContractState(): void {
if (!BICONOMY_IMPLEMENTATION_ADDRESSES[this.smartAccountInfo.implementationAddress])
if (!BICONOMY_IMPLEMENTATION_ADDRESSES["0x00006b7e42e01957da540dc6a8f7c30c4d816af5"])
throw new Error(
"Could not find attached implementation address against your smart account. Please raise an issue on https://github.com/bcnmy/biconomy-client-sdk for further investigation.",
);
const proxyInstanceDto = {
smartAccountType: SmartAccountType.BICONOMY,
version: BICONOMY_IMPLEMENTATION_ADDRESSES[this.smartAccountInfo.implementationAddress],
version: BICONOMY_IMPLEMENTATION_ADDRESSES["0x00006b7e42e01957da540dc6a8f7c30c4d816af5"],
contractAddress: this.address,
provider: this.provider,
};
this.proxy = getSAProxyContract(proxyInstanceDto);
}

private setEntryPointContractState(): void {
const _entryPointAddress = this.smartAccountInfo.entryPointAddress;
const _entryPointAddress = ENTRYPOINT_ADDRESSES_BY_VERSION.V0_0_6;
this.setEntryPointAddress(_entryPointAddress);
if (!ENTRYPOINT_ADDRESSES[_entryPointAddress])
throw new Error(
Expand All @@ -157,7 +148,7 @@ export class BiconomySmartAccount extends SmartAccount implements IBiconomySmart
}

private setFactoryContractState(): void {
const _factoryAddress = this.smartAccountInfo.factoryAddress;
const _factoryAddress = "0x000000f9ee1842bb72f6bbdd75e6d3d4e3e9594c";
if (!BICONOMY_FACTORY_ADDRESSES[_factoryAddress])
throw new Error(
"Could not find attached factory address against your smart account. Please raise an issue on https://github.com/bcnmy/biconomy-client-sdk for further investigation.",
Expand Down Expand Up @@ -187,26 +178,20 @@ export class BiconomySmartAccount extends SmartAccount implements IBiconomySmart
async getSmartAccountAddress(accountIndex = 0): Promise<string> {
try {
this.isSignerDefined();
let smartAccountsList: ISmartAccount[] = (
await this.getSmartAccountsByOwner({
chainId: this.chainId,
owner: this.owner,
index: accountIndex,
})
).data;
if (!smartAccountsList)
throw new Error(
"Failed to get smart account address. Please raise an issue on https://github.com/bcnmy/biconomy-client-sdk for further investigation.",
);
smartAccountsList = smartAccountsList.filter((smartAccount: ISmartAccount) => {
return accountIndex === smartAccount.index;
});
if (smartAccountsList.length === 0)
if (this.factory == null) {
this.factory = SmartAccountFactory_v100__factory.connect("0x000000f9ee1842bb72f6bbdd75e6d3d4e3e9594c", this.provider);
}
const smartAccountAddress = await this.factory.getAddressForCounterFactualAccount(this.owner, ethers.BigNumber.from(accountIndex));

Logger.log("smart account address: ", smartAccountAddress);

if (smartAccountAddress) {
return smartAccountAddress;
} else {
throw new Error(
"Failed to get smart account address. Please raise an issue on https://github.com/bcnmy/biconomy-client-sdk for further investigation.",
);
this.smartAccountInfo = smartAccountsList[0];
return this.smartAccountInfo.smartAccountAddress;
}
} catch (error) {
Logger.error(`Failed to get smart account address: ${error}`);
throw error;
Expand Down Expand Up @@ -452,30 +437,6 @@ export class BiconomySmartAccount extends SmartAccount implements IBiconomySmart
return userOp;
}

async getAllTokenBalances(balancesDto: BalancesDto): Promise<BalancesResponse> {
return this.nodeClient.getAllTokenBalances(balancesDto);
}

async getTotalBalanceInUsd(balancesDto: BalancesDto): Promise<UsdBalanceResponse> {
return this.nodeClient.getTotalBalanceInUsd(balancesDto);
}

async getSmartAccountsByOwner(smartAccountByOwnerDto: SmartAccountByOwnerDto): Promise<SmartAccountsResponse> {
return this.nodeClient.getSmartAccountsByOwner(smartAccountByOwnerDto);
}

async getTransactionsByAddress(chainId: number, address: string): Promise<SCWTransactionResponse[]> {
return this.nodeClient.getTransactionByAddress(chainId, address);
}

async getTransactionByHash(txHash: string): Promise<SCWTransactionResponse> {
return this.nodeClient.getTransactionByHash(txHash);
}

async getAllSupportedChains(): Promise<SupportedChainsResponse> {
return this.nodeClient.getAllSupportedChains();
}

async getUpdateImplementationData(newImplementationAddress?: string): Promise<Transaction> {
// V2 address or latest implementation if possible to jump from V1 -> Vn without upgrading to V2
// If needed we can fetch this from backend config
Expand Down
39 changes: 2 additions & 37 deletions packages/account/src/BiconomySmartAccountV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,7 @@ import {
} from "./utils/Types";
import { BaseValidationModule, ECDSAOwnershipValidationModule, ModuleInfo, SendUserOpParams } from "@biconomy/modules";
import { UserOperation, Transaction } from "@biconomy/core-types";
import NodeClient from "@biconomy/node-client";
import INodeClient from "@biconomy/node-client";
import { IHybridPaymaster, BiconomyPaymaster, SponsorUserOperationDto } from "@biconomy/paymaster";
import {
SupportedChainsResponse,
BalancesResponse,
BalancesDto,
UsdBalanceResponse,
SmartAccountByOwnerDto,
SmartAccountsResponse,
SCWTransactionResponse,
} from "@biconomy/node-client";
import { UserOpResponse } from "@biconomy/bundler";
import {
ADDRESS_RESOLVER_ADDRESS,
Expand All @@ -49,7 +38,7 @@ import log from "loglevel";

type UserOperationKey = keyof UserOperation;
export class BiconomySmartAccountV2 extends BaseSmartAccount {
private nodeClient!: INodeClient;
// private nodeClient!: INodeClient;

private SENTINEL_MODULE = "0x0000000000000000000000000000000000000001";

Expand Down Expand Up @@ -132,7 +121,7 @@ export class BiconomySmartAccountV2 extends BaseSmartAccount {
instance.provider = new JsonRpcProvider(rpcUrl);
}

instance.nodeClient = new NodeClient({ txServiceUrl: nodeClientUrl ?? NODE_CLIENT_URL });
// instance.nodeClient = new NodeClient({ txServiceUrl: nodeClientUrl ?? NODE_CLIENT_URL });

instance.scanForUpgradedAccountsFromV1 = biconomySmartAccountConfig.scanForUpgradedAccountsFromV1 ?? false;

Expand Down Expand Up @@ -650,30 +639,6 @@ export class BiconomySmartAccountV2 extends BaseSmartAccount {
return signature;
}

async getAllTokenBalances(balancesDto: BalancesDto): Promise<BalancesResponse> {
return this.nodeClient.getAllTokenBalances(balancesDto);
}

async getTotalBalanceInUsd(balancesDto: BalancesDto): Promise<UsdBalanceResponse> {
return this.nodeClient.getTotalBalanceInUsd(balancesDto);
}

async getSmartAccountsByOwner(smartAccountByOwnerDto: SmartAccountByOwnerDto): Promise<SmartAccountsResponse> {
return this.nodeClient.getSmartAccountsByOwner(smartAccountByOwnerDto);
}

async getTransactionsByAddress(chainId: number, address: string): Promise<SCWTransactionResponse[]> {
return this.nodeClient.getTransactionByAddress(chainId, address);
}

async getTransactionByHash(txHash: string): Promise<SCWTransactionResponse> {
return this.nodeClient.getTransactionByHash(txHash);
}

async getAllSupportedChains(): Promise<SupportedChainsResponse> {
return this.nodeClient.getAllSupportedChains();
}

getImplementationAddress(): string {
return this.implementationAddress;
}
Expand Down
15 changes: 0 additions & 15 deletions packages/account/src/interfaces/IBiconomySmartAccount.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import { UserOperation, Transaction } from "@biconomy/core-types";
import {
SupportedChainsResponse,
BalancesResponse,
BalancesDto,
UsdBalanceResponse,
SmartAccountByOwnerDto,
SmartAccountsResponse,
SCWTransactionResponse,
} from "@biconomy/node-client";
import { Overrides, InitilizationData } from "../utils/Types";
import { BigNumberish, BytesLike } from "ethers";
import { ISmartAccount } from "./ISmartAccount";
Expand All @@ -19,11 +10,5 @@ export interface IBiconomySmartAccount extends ISmartAccount {
getExecuteCallData(_to: string, _value: BigNumberish, _data: BytesLike): string;
getExecuteBatchCallData(_to: Array<string>, _value: Array<BigNumberish>, _data: Array<BytesLike>): string;
buildUserOp(_transactions: Transaction[], _overrides?: Overrides): Promise<Partial<UserOperation>>;
getAllTokenBalances(_balancesDto: BalancesDto): Promise<BalancesResponse>;
getTotalBalanceInUsd(_balancesDto: BalancesDto): Promise<UsdBalanceResponse>;
getSmartAccountsByOwner(_smartAccountByOwnerDto: SmartAccountByOwnerDto): Promise<SmartAccountsResponse>;
getTransactionsByAddress(_chainId: number, _address: string): Promise<SCWTransactionResponse[]>;
getTransactionByHash(_txHash: string): Promise<SCWTransactionResponse>;
getAllSupportedChains(): Promise<SupportedChainsResponse>;
attachSigner(_signer: Signer): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ describe("BiconomySmartAccountV2 Paymaster Abstraction", () => {
}, 30000);

it("Create a smart account with paymaster through api key", async () => {

account = await BiconomySmartAccountV2.create({
chainId: ChainId.GANACHE,
rpcUrl: "http://127.0.0.1:8545",
Expand All @@ -62,25 +61,24 @@ describe("BiconomySmartAccountV2 Paymaster Abstraction", () => {
defaultFallbackHandler: await accountFactory.minimalHandler(),
defaultValidationModule: module1,
activeValidationModule: module1,
bundlerUrl: "https://bundler.biconomy.io/api/v2/1337/..."
bundlerUrl: "https://bundler.biconomy.io/api/v2/1337/...",
});

const address = await account.getAccountAddress();
console.log("account address ", address);

const paymaster = account.paymaster;

expect(paymaster).not.toBeNull()
expect(paymaster).not.toBeUndefined()
expect(paymaster).not.toBeNull();
expect(paymaster).not.toBeUndefined();

expect(address).toBe(account.accountAddress);
}, 10000);

it("Create a smart account with paymaster by creating instance", async () => {

const paymaster = new BiconomyPaymaster({
paymasterUrl: "https://paymaster.biconomy.io/api/v1/80001/7K_k68BFN.ed274da8-69a1-496d-a897-508fc2213216",
})
});

account = await BiconomySmartAccountV2.create({
chainId: ChainId.GANACHE,
Expand All @@ -91,16 +89,15 @@ describe("BiconomySmartAccountV2 Paymaster Abstraction", () => {
defaultValidationModule: module1,
activeValidationModule: module1,
paymaster: paymaster,
bundlerUrl: "https://bundler.biconomy.io/api/v2/1337/..."
bundlerUrl: "https://bundler.biconomy.io/api/v2/1337/...",
});

const address = await account.getAccountAddress();
console.log("account address ", address);

expect(account.paymaster).not.toBeNull()
expect(account.paymaster).not.toBeUndefined()
expect(account.paymaster).not.toBeNull();
expect(account.paymaster).not.toBeUndefined();

expect(address).toBe(account.accountAddress);
}, 10000);

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("BiconomySmartAccountV2 Module Abstraction", () => {
rpcUrl: "http://127.0.0.1:8545",
entryPointAddress: entryPoint.address,
signer,
bundlerUrl: "https://bundler.biconomy.io/api/v2/1337/..."
bundlerUrl: "https://bundler.biconomy.io/api/v2/1337/...",
/*defaultValidationModule: await ECDSAOwnershipValidationModule.create({
signer: signer,
moduleAddress: ecdsaModule.address,
Expand All @@ -73,7 +73,7 @@ describe("BiconomySmartAccountV2 Module Abstraction", () => {
rpcUrl: "http://127.0.0.1:8545",
entryPointAddress: entryPoint.address,
signer,
bundlerUrl: "https://bundler.biconomy.io/api/v2/1337/..."
bundlerUrl: "https://bundler.biconomy.io/api/v2/1337/...",
});

const address = await account.getAccountAddress();
Expand Down
Loading

0 comments on commit 4d41831

Please sign in to comment.