Skip to content

Commit

Permalink
PRO-2136 - Bundler Api Key (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
vignesha22 authored Feb 12, 2024
1 parent 1d92797 commit 514bc23
Show file tree
Hide file tree
Showing 28 changed files with 149 additions and 53 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## [1.5.2] - 2024-02-12
### New
- Added `GenericBundler` and `EtherspotBundler` as bundlerProviders and removed bundlerUrl params from SdkOptions

## [1.5.1] - 2024-02-08
### Bug fixes
- Added `key` param on SimpleAccount and ZeroDev wallets
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ npm i @etherspot/prime-sdk
Or follow our introductory guide on our docs [here](https://etherspot.fyi/getting-started) which walk you through
cloning down an example repo and setting up a dapp in your own environment.

The mainnet bundler API key `eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9` is included in the example programs which is a public API key with rate limits, to get higher limits register to https://portal.etherspot.io

## 📖 Documentation

- [Quick Start](https://etherspot.fyi/getting-started)
Expand Down
6 changes: 4 additions & 2 deletions examples/01-get-address.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { PrimeSdk } from '../src';
import { EtherspotBundler, PrimeSdk } from '../src';
import * as dotenv from 'dotenv';

dotenv.config();


async function main() {
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';
const customBundlerUrl = '';
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' })
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey, customBundlerUrl) }) // Testnets dont need apiKey on bundlerProvider

// get EtherspotWallet address...
const address: string = await primeSdk.getCounterFactualAddress();
Expand Down
5 changes: 3 additions & 2 deletions examples/02-transfer-funds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers';
import { PrimeSdk } from '../src';
import { EtherspotBundler, PrimeSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';
Expand All @@ -8,10 +8,11 @@ dotenv.config();

const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const value = '0.00001'; // transfer value
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

async function main() {
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' })
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) })

console.log('address: ', primeSdk.state.EOAAddress)

Expand Down
5 changes: 3 additions & 2 deletions examples/03-transfer-erc20.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers';
import { PrimeSdk } from '../src';
import { EtherspotBundler, PrimeSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import { ERC20_ABI } from '../src/sdk/helpers/abi/ERC20_ABI';
import * as dotenv from 'dotenv';
Expand All @@ -11,10 +11,11 @@ dotenv.config();
const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const value = '0.1'; // transfer value
const tokenAddress = '0x326C977E6efc84E512bB9C30f76E30c160eD06FB';
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

async function main() {
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' })
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) })

console.log('address: ', primeSdk.state.EOAAddress)

Expand Down
5 changes: 3 additions & 2 deletions examples/04-transfer-nft.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers';
import { PrimeSdk } from '../src';
import { EtherspotBundler, PrimeSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';
Expand All @@ -10,10 +10,11 @@ dotenv.config();
const recipient = '0xD129dB5e418e389c3F7D3ae0B8771B3f76799A52'; // recipient wallet address
const tokenAddress = '0xe55C5793a52AF819fBf3e87a23B36708E6FDd2Cc';
const tokenId = 4;
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

async function main() {
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' })
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) })

console.log('address: ', primeSdk.state.EOAAddress)

Expand Down
6 changes: 4 additions & 2 deletions examples/12-add-guardians.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { ethers } from 'ethers';
import { PrimeSdk } from '../src';
import { EtherspotBundler, PrimeSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';

dotenv.config();

async function main() {
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

// initializating sdk...
const primeSdk = new PrimeSdk(
{ privateKey: process.env.WALLET_PRIVATE_KEY },
{ chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' },
{ chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) },
);

console.log('address: ', primeSdk.state.EOAAddress);
Expand Down
4 changes: 3 additions & 1 deletion examples/13-paymaster.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers';
import { PrimeSdk } from '../src';
import { EtherspotBundler, PrimeSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';
Expand All @@ -9,11 +9,13 @@ dotenv.config();
const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const value = '0.01'; // transfer value
const api_key = 'arka_public_key'; // Only testnets are available, if you need further assistance in setting up a paymaster service for your dapp, please reach out to us on discord or https://etherspot.fyi/arka/intro
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

async function main() {
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, {
chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key',
bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey)
})

console.log('address: ', primeSdk.state.EOAAddress)
Expand Down
7 changes: 5 additions & 2 deletions examples/14-zeroDev-address.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Factory, PrimeSdk } from '../src';
import { EtherspotBundler, Factory, PrimeSdk } from '../src';
import * as dotenv from 'dotenv';

dotenv.config();


async function main() {
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', factoryWallet: Factory.ZERO_DEV })
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', factoryWallet: Factory.ZERO_DEV,
bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey)
})

// get ZeroDev address...
const address: string = await primeSdk.getCounterFactualAddress();
Expand Down
7 changes: 5 additions & 2 deletions examples/15-simpleAccount-address.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Factory, PrimeSdk } from '../src';
import { EtherspotBundler, Factory, PrimeSdk } from '../src';
import * as dotenv from 'dotenv';

dotenv.config();


async function main() {
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', factoryWallet: Factory.SIMPLE_ACCOUNT })
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', factoryWallet: Factory.SIMPLE_ACCOUNT,
bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey)
})

// get SimpleAccount address...
const address: string = await primeSdk.getCounterFactualAddress();
Expand Down
4 changes: 3 additions & 1 deletion examples/16-paymaster-arka.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers, utils } from 'ethers';
import { PrimeSdk } from '../src';
import { EtherspotBundler, PrimeSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';
Expand All @@ -9,6 +9,7 @@ dotenv.config();

const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const value = '0.0001'; // transfer value
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

const arka_api_key = 'arka_public_key';
const arka_url = 'https://arka.etherspot.io'; // Only testnets are available, if you need further assistance in setting up a paymaster service for your dapp, please reach out to us on discord or https://etherspot.fyi/arka/intro
Expand All @@ -18,6 +19,7 @@ async function main() {
// initializing sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, {
chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key',
bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey)
})

console.log('address: ', primeSdk.state.EOAAddress)
Expand Down
5 changes: 3 additions & 2 deletions examples/19-paymaster-validUntil-validAfter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers';
import { PrimeSdk } from '../src';
import { EtherspotBundler, PrimeSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';
Expand All @@ -8,6 +8,7 @@ dotenv.config();

const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const value = '0.0001'; // transfer value
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

const arka_api_key = 'arka_public_key'; // Only testnets are available, if you need further assistance in setting up a paymaster service for your dapp, please reach out to us on discord or https://etherspot.fyi/arka/intro
const arka_url = 'https://arka.etherspot.io';
Expand All @@ -16,7 +17,7 @@ const queryString = `?apiKey=${arka_api_key}&chainId=${Number(process.env.CHAIN_
async function main() {
// initializing sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, {
chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key',
chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey)
})

console.log('address: ', primeSdk.state.EOAAddress)
Expand Down
7 changes: 5 additions & 2 deletions examples/20-callGasLimit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers';
import { PrimeSdk } from '../src';
import { EtherspotBundler, PrimeSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';
Expand All @@ -8,10 +8,13 @@ dotenv.config();

const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const value = '0.0001'; // transfer value
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

async function main() {
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' })
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key',
bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey)
})

console.log('address: ', primeSdk.state.EOAAddress)

Expand Down
8 changes: 5 additions & 3 deletions examples/21-get-multiple-accounts.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { PrimeSdk } from '../src';
import { EtherspotBundler, PrimeSdk } from '../src';
import * as dotenv from 'dotenv';

dotenv.config();

const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

async function main() {
// initializating sdk for index 0...
const primeSdk = new PrimeSdk(
{ privateKey: process.env.WALLET_PRIVATE_KEY },
{ chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' },
{ chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) },
);

// get EtherspotWallet address for index 0...
Expand All @@ -17,7 +19,7 @@ async function main() {
// initializating sdk for index 1...
const primeSdk1 = new PrimeSdk(
{ privateKey: process.env.WALLET_PRIVATE_KEY },
{ chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', index: 1 },
{ chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', index: 1, bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) },
);

// get EtherspotWallet address for index 1...
Expand Down
7 changes: 5 additions & 2 deletions examples/22-concurrent-userops.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers, providers } from 'ethers';
import { PrimeSdk } from '../src';
import { EtherspotBundler, PrimeSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';
Expand All @@ -8,11 +8,14 @@ dotenv.config();

const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const value = '0.000001'; // transfer value
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

async function main() {
const provider = new providers.JsonRpcProvider(process.env.RPC_PROVIDER_URL);
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' })
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key',
bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey)
})

console.log('address: ', primeSdk.state.EOAAddress)

Expand Down
21 changes: 21 additions & 0 deletions examples/23-bundlerApiKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { EtherspotBundler, PrimeSdk } from '../src';
import * as dotenv from 'dotenv';

dotenv.config();


async function main() {
const etherspotBundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key',
bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), etherspotBundlerApiKey)
})

// get EtherspotWallet address...
const address: string = await primeSdk.getCounterFactualAddress();
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`);
}

main()
.catch(console.error)
.finally(() => process.exit());
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etherspot/prime-sdk",
"version": "1.5.1",
"version": "1.5.2",
"description": "Etherspot Prime (Account Abstraction) SDK",
"keywords": [
"ether",
Expand Down
6 changes: 2 additions & 4 deletions src/sdk/base/BaseAccountAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,19 @@ export abstract class BaseAccountAPI {
throw new Exception('Invalid wallet provider');
}

// const env = Env.prepare(optionsLike.env);

const {
chainId, //
stateStorage,
rpcProviderUrl,
bundlerRpcUrl,
factoryWallet,
bundlerProvider,
} = optionsLike;

this.services = {
networkService: new NetworkService(chainId),
walletService: new WalletService(params.walletProvider, {
provider: rpcProviderUrl,
}, bundlerRpcUrl, chainId),
}, bundlerProvider.url, chainId),
stateService: new StateService({
storage: stateStorage,
}),
Expand Down
2 changes: 2 additions & 0 deletions src/sdk/bundler/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './interface';
export * from './providers';
6 changes: 6 additions & 0 deletions src/sdk/bundler/interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

export interface BundlerProvider {
readonly url: string;
}

export type BundlerProviderLike = BundlerProvider;
23 changes: 23 additions & 0 deletions src/sdk/bundler/providers/EtherspotBundler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Exception } from "../../common";
import { getNetworkConfig } from "../../network/constants";
import { BundlerProvider } from "../interface";

export class EtherspotBundler implements BundlerProvider {
readonly url: string;
readonly apiKey: string;
readonly chainId: string;

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) {
if (bundlerUrl.includes('?api-key=')) this.url = bundlerUrl + apiKey;
else this.url = bundlerUrl + '?api-key=' + apiKey;
}
else this.url = bundlerUrl;
this.apiKey = apiKey;
}
}
Loading

0 comments on commit 514bc23

Please sign in to comment.