diff --git a/packages/account/src/BiconomySmartAccount.ts b/packages/account/src/BiconomySmartAccount.ts index 3307856b7..5524d7f41 100644 --- a/packages/account/src/BiconomySmartAccount.ts +++ b/packages/account/src/BiconomySmartAccount.ts @@ -6,6 +6,7 @@ import { NODE_CLIENT_URL, RPC_PROVIDER_URLS, SmartAccountFactory_v100, + SmartAccountFactory_v100__factory, SmartAccount_v200, getEntryPointContract, getSAFactoryContract, @@ -14,8 +15,8 @@ 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"; @@ -36,13 +37,14 @@ import { 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; @@ -53,7 +55,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({ @@ -68,7 +70,7 @@ export class BiconomySmartAccount extends SmartAccount implements IBiconomySmart ); } this.provider = new JsonRpcProvider(_rpcUrl); - this.nodeClient = new NodeClient({ txServiceUrl: nodeClientUrl ?? NODE_CLIENT_URL }); + // this.nodeClient = new NodeClient({ txServiceUrl: nodeClientUrl ?? NODE_CLIENT_URL }); this.signer = signer; if (paymaster) { @@ -127,13 +129,13 @@ 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, }; @@ -141,7 +143,7 @@ export class BiconomySmartAccount extends SmartAccount implements IBiconomySmart } 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( @@ -157,7 +159,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.", @@ -187,26 +189,24 @@ export class BiconomySmartAccount extends SmartAccount implements IBiconomySmart async getSmartAccountAddress(accountIndex = 0): Promise { 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; @@ -452,30 +452,6 @@ export class BiconomySmartAccount extends SmartAccount implements IBiconomySmart return userOp; } - async getAllTokenBalances(balancesDto: BalancesDto): Promise { - return this.nodeClient.getAllTokenBalances(balancesDto); - } - - async getTotalBalanceInUsd(balancesDto: BalancesDto): Promise { - return this.nodeClient.getTotalBalanceInUsd(balancesDto); - } - - async getSmartAccountsByOwner(smartAccountByOwnerDto: SmartAccountByOwnerDto): Promise { - return this.nodeClient.getSmartAccountsByOwner(smartAccountByOwnerDto); - } - - async getTransactionsByAddress(chainId: number, address: string): Promise { - return this.nodeClient.getTransactionByAddress(chainId, address); - } - - async getTransactionByHash(txHash: string): Promise { - return this.nodeClient.getTransactionByHash(txHash); - } - - async getAllSupportedChains(): Promise { - return this.nodeClient.getAllSupportedChains(); - } - async getUpdateImplementationData(newImplementationAddress?: string): Promise { // 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 diff --git a/packages/account/src/interfaces/IBiconomySmartAccount.ts b/packages/account/src/interfaces/IBiconomySmartAccount.ts index 2534ae461..99876b27b 100644 --- a/packages/account/src/interfaces/IBiconomySmartAccount.ts +++ b/packages/account/src/interfaces/IBiconomySmartAccount.ts @@ -19,11 +19,11 @@ export interface IBiconomySmartAccount extends ISmartAccount { getExecuteCallData(_to: string, _value: BigNumberish, _data: BytesLike): string; getExecuteBatchCallData(_to: Array, _value: Array, _data: Array): string; buildUserOp(_transactions: Transaction[], _overrides?: Overrides): Promise>; - getAllTokenBalances(_balancesDto: BalancesDto): Promise; - getTotalBalanceInUsd(_balancesDto: BalancesDto): Promise; - getSmartAccountsByOwner(_smartAccountByOwnerDto: SmartAccountByOwnerDto): Promise; - getTransactionsByAddress(_chainId: number, _address: string): Promise; - getTransactionByHash(_txHash: string): Promise; - getAllSupportedChains(): Promise; + // getAllTokenBalances(_balancesDto: BalancesDto): Promise; + // getTotalBalanceInUsd(_balancesDto: BalancesDto): Promise; + // getSmartAccountsByOwner(_smartAccountByOwnerDto: SmartAccountByOwnerDto): Promise; + // getTransactionsByAddress(_chainId: number, _address: string): Promise; + // getTransactionByHash(_txHash: string): Promise; + // getAllSupportedChains(): Promise; attachSigner(_signer: Signer): Promise; }