Skip to content

Commit

Permalink
added default bundler provider
Browse files Browse the repository at this point in the history
  • Loading branch information
vignesha22 committed Feb 1, 2024
1 parent 0a69088 commit c43251e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/sdk/bundler/providers/EtherspotBundler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Exception } from "../../common";
import { getNetworkConfig } from "../../network/constants";
import { BundlerProvider } from "../interface";

Expand All @@ -9,9 +10,13 @@ export class EtherspotBundler implements BundlerProvider {
constructor(chainId: number, apiKey?: string, bundlerUrl?: string) {
if (!bundlerUrl) {
const networkConfig = getNetworkConfig(chainId);
if (!networkConfig || networkConfig.bundler == '') throw new Exception('No bundler url provided')
bundlerUrl = networkConfig.bundler;
}
if (apiKey) this.url = bundlerUrl + '?api-key=' + apiKey;
if (apiKey) {
if (bundlerUrl.includes('?api-key=')) this.url = bundlerUrl + apiKey;
else this.url = bundlerUrl + '?api-key=' + apiKey;
}
else this.url = bundlerUrl;
this.apiKey = apiKey;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export enum Factory {
export interface SdkOptions {
chainId: number;
projectKey: string;
bundlerProvider: BundlerProviderLike;
bundlerProvider?: BundlerProviderLike;
stateStorage?: StateStorage;
rpcProviderUrl?: string;
graphqlEndpoint?: string;
Expand Down
10 changes: 7 additions & 3 deletions src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { OnRamperDto, SignMessageDto, validateDto } from './dto';
import { ZeroDevWalletAPI } from './base/ZeroDevWalletAPI';
import { SimpleAccountAPI } from './base/SimpleAccountWalletAPI';
import { ErrorHandler } from './errorHandler/errorHandler.service';
import { EtherspotBundler } from './bundler';

/**
* Prime-Sdk
Expand Down Expand Up @@ -49,13 +50,16 @@ export class PrimeSdk {
chainId,
rpcProviderUrl,
accountAddress,
bundlerProvider,
} = optionsLike;

this.chainId = chainId;
this.index = index ?? 0;
const networkConfig = getNetworkConfig(chainId);

if (!optionsLike.bundlerProvider) {
optionsLike.bundlerProvider = new EtherspotBundler(chainId);
}

if (networkConfig) {
optionsLike.graphqlEndpoint = networkConfig.graphqlEndpoint;
}
Expand All @@ -66,7 +70,7 @@ export class PrimeSdk {

if (rpcProviderUrl) {
provider = new providers.JsonRpcProvider(rpcProviderUrl);
} else provider = new providers.JsonRpcProvider(bundlerProvider.url);
} else provider = new providers.JsonRpcProvider(optionsLike.bundlerProvider.url);

let entryPointAddress = '', walletFactoryAddress = '';
if (Networks[chainId]) {
Expand Down Expand Up @@ -111,7 +115,7 @@ export class PrimeSdk {
index: this.index,
})
}
this.bundler = new HttpRpcClient(bundlerProvider.url, entryPointAddress, chainId);
this.bundler = new HttpRpcClient(optionsLike.bundlerProvider.url, entryPointAddress, chainId);

}

Expand Down

0 comments on commit c43251e

Please sign in to comment.