Skip to content

Commit

Permalink
remove node client
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshugarg06 committed Oct 7, 2024
1 parent 9669f7d commit 5f6a8d4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 56 deletions.
76 changes: 26 additions & 50 deletions packages/account/src/BiconomySmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
NODE_CLIENT_URL,

Check warning on line 6 in packages/account/src/BiconomySmartAccount.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

'NODE_CLIENT_URL' is defined but never used

Check failure on line 6 in packages/account/src/BiconomySmartAccount.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

'NODE_CLIENT_URL' is defined but never used
RPC_PROVIDER_URLS,
SmartAccountFactory_v100,
SmartAccountFactory_v100__factory,
SmartAccount_v200,
getEntryPointContract,
getSAFactoryContract,
Expand All @@ -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";
Expand All @@ -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;

Expand All @@ -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({
Expand All @@ -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) {
Expand Down Expand Up @@ -127,21 +129,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"];

Check failure on line 146 in packages/account/src/BiconomySmartAccount.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

["V0_0_6"] is better written in dot notation
this.setEntryPointAddress(_entryPointAddress);
if (!ENTRYPOINT_ADDRESSES[_entryPointAddress])
throw new Error(
Expand All @@ -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.",
Expand Down Expand Up @@ -187,26 +189,24 @@ 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);

Check failure on line 193 in packages/account/src/BiconomySmartAccount.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Delete `··`
}
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 +452,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
12 changes: 6 additions & 6 deletions packages/account/src/interfaces/IBiconomySmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ 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>;
// 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>;
}

0 comments on commit 5f6a8d4

Please sign in to comment.