From c43251ee0c803119d4419bc15c0dc2b4f988c612 Mon Sep 17 00:00:00 2001 From: Vignesh Date: Thu, 1 Feb 2024 15:33:56 +0530 Subject: [PATCH] added default bundler provider --- src/sdk/bundler/providers/EtherspotBundler.ts | 7 ++++++- src/sdk/interfaces.ts | 2 +- src/sdk/sdk.ts | 10 +++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/sdk/bundler/providers/EtherspotBundler.ts b/src/sdk/bundler/providers/EtherspotBundler.ts index e750cfb8..36e345da 100644 --- a/src/sdk/bundler/providers/EtherspotBundler.ts +++ b/src/sdk/bundler/providers/EtherspotBundler.ts @@ -1,3 +1,4 @@ +import { Exception } from "../../common"; import { getNetworkConfig } from "../../network/constants"; import { BundlerProvider } from "../interface"; @@ -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; } diff --git a/src/sdk/interfaces.ts b/src/sdk/interfaces.ts index 6b4e4bf0..4ef7301f 100644 --- a/src/sdk/interfaces.ts +++ b/src/sdk/interfaces.ts @@ -15,7 +15,7 @@ export enum Factory { export interface SdkOptions { chainId: number; projectKey: string; - bundlerProvider: BundlerProviderLike; + bundlerProvider?: BundlerProviderLike; stateStorage?: StateStorage; rpcProviderUrl?: string; graphqlEndpoint?: string; diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index 800c5c2d..dc46acbe 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -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 @@ -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; } @@ -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]) { @@ -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); }