Skip to content

Commit

Permalink
added contract address parameter for new owner
Browse files Browse the repository at this point in the history
  • Loading branch information
vignesha22 committed Dec 27, 2023
1 parent 1934acb commit 64b3908
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/sdk/base/EtherspotWalletAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { BaseApiParams, BaseAccountAPI } from './BaseAccountAPI';
export interface EtherspotWalletApiParams extends BaseApiParams {
factoryAddress?: string;
index?: number;
predefinedAccountAddress?: string;
}

/**
Expand All @@ -30,6 +31,7 @@ export class EtherspotWalletAPI extends BaseAccountAPI {
factoryAddress?: string;
index: number;
accountAddress?: string;
predefinedAccountAddress?: string;

/**
* our account contract.
Expand All @@ -43,6 +45,17 @@ export class EtherspotWalletAPI extends BaseAccountAPI {
super(params);
this.factoryAddress = params.factoryAddress;
this.index = params.index ?? 0;
this.predefinedAccountAddress = params.predefinedAccountAddress ?? null;
}

async checkAccountAddress(address: string): Promise<void> {
const accountContract = EtherspotWallet__factory.connect(address, this.provider);
if (!(await accountContract.isOwner(this.services.walletService.walletAddress))) {
throw new Error('the specified accountAddress does not belong to the given EOA provider')
}
else {
this.accountAddress = address;
}
}

async _getAccountContract(): Promise<EtherspotWallet | Contract> {
Expand Down Expand Up @@ -73,11 +86,16 @@ export class EtherspotWalletAPI extends BaseAccountAPI {
}

async getCounterFactualAddress(): Promise<string> {
if (this.predefinedAccountAddress) {
await this.checkAccountAddress(this.predefinedAccountAddress);
}
if (!this.accountAddress) {
this.factory = EtherspotWalletFactory__factory.connect(this.factoryAddress, this.provider);
this.accountAddress = await this.factory.getAddress(
this.services.walletService.walletAddress,
this.index,
);
}
return this.accountAddress;
}

Expand Down
1 change: 1 addition & 0 deletions src/sdk/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export interface SdkOptions {
factoryWallet?: Factory;
walletFactoryAddress?: string;
entryPointAddress?: string;
accountAddress?: string;
}
2 changes: 2 additions & 0 deletions src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class PrimeSdk {
const {
chainId, //
rpcProviderUrl,
accountAddress,
} = optionsLike;

this.chainId = chainId;
Expand Down Expand Up @@ -106,6 +107,7 @@ export class PrimeSdk {
optionsLike,
entryPointAddress,
factoryAddress: walletFactoryAddress,
predefinedAccountAddress: accountAddress,
})
}
this.bundler = new HttpRpcClient(optionsLike.bundlerRpcUrl, entryPointAddress, chainId);
Expand Down

0 comments on commit 64b3908

Please sign in to comment.