diff --git a/CHANGELOG.md b/CHANGELOG.md index b5cb1894..eb27bd74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 9b262cd1..bc3646de 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/examples/01-get-address.ts b/examples/01-get-address.ts index 6e09f902..2785a1a7 100644 --- a/examples/01-get-address.ts +++ b/examples/01-get-address.ts @@ -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(); diff --git a/examples/02-transfer-funds.ts b/examples/02-transfer-funds.ts index 6e34b072..845dcee3 100644 --- a/examples/02-transfer-funds.ts +++ b/examples/02-transfer-funds.ts @@ -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'; @@ -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) diff --git a/examples/03-transfer-erc20.ts b/examples/03-transfer-erc20.ts index d5502798..ad661ded 100644 --- a/examples/03-transfer-erc20.ts +++ b/examples/03-transfer-erc20.ts @@ -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'; @@ -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) diff --git a/examples/04-transfer-nft.ts b/examples/04-transfer-nft.ts index 2a2efb23..b53a320b 100644 --- a/examples/04-transfer-nft.ts +++ b/examples/04-transfer-nft.ts @@ -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'; @@ -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) diff --git a/examples/12-add-guardians.ts b/examples/12-add-guardians.ts index 590e284c..08f94846 100644 --- a/examples/12-add-guardians.ts +++ b/examples/12-add-guardians.ts @@ -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'; @@ -7,10 +7,12 @@ 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); diff --git a/examples/13-paymaster.ts b/examples/13-paymaster.ts index 4096747a..ac01217d 100644 --- a/examples/13-paymaster.ts +++ b/examples/13-paymaster.ts @@ -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'; @@ -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) diff --git a/examples/14-zeroDev-address.ts b/examples/14-zeroDev-address.ts index dd72b2c0..facd2890 100644 --- a/examples/14-zeroDev-address.ts +++ b/examples/14-zeroDev-address.ts @@ -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(); diff --git a/examples/15-simpleAccount-address.ts b/examples/15-simpleAccount-address.ts index 0bca7475..dbf83e1c 100644 --- a/examples/15-simpleAccount-address.ts +++ b/examples/15-simpleAccount-address.ts @@ -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(); diff --git a/examples/16-paymaster-arka.ts b/examples/16-paymaster-arka.ts index 7854f387..bf18e170 100644 --- a/examples/16-paymaster-arka.ts +++ b/examples/16-paymaster-arka.ts @@ -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'; @@ -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 @@ -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) diff --git a/examples/19-paymaster-validUntil-validAfter.ts b/examples/19-paymaster-validUntil-validAfter.ts index 6606f64f..91ec382b 100644 --- a/examples/19-paymaster-validUntil-validAfter.ts +++ b/examples/19-paymaster-validUntil-validAfter.ts @@ -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'; @@ -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'; @@ -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) diff --git a/examples/20-callGasLimit.ts b/examples/20-callGasLimit.ts index 6eca5432..fb749804 100644 --- a/examples/20-callGasLimit.ts +++ b/examples/20-callGasLimit.ts @@ -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'; @@ -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) diff --git a/examples/21-get-multiple-accounts.ts b/examples/21-get-multiple-accounts.ts index 57696c84..98ff06e9 100644 --- a/examples/21-get-multiple-accounts.ts +++ b/examples/21-get-multiple-accounts.ts @@ -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... @@ -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... diff --git a/examples/22-concurrent-userops.ts b/examples/22-concurrent-userops.ts index 779a94bd..5547fe5b 100644 --- a/examples/22-concurrent-userops.ts +++ b/examples/22-concurrent-userops.ts @@ -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'; @@ -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) diff --git a/examples/23-bundlerApiKey.ts b/examples/23-bundlerApiKey.ts new file mode 100644 index 00000000..bb845ebe --- /dev/null +++ b/examples/23-bundlerApiKey.ts @@ -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()); diff --git a/package-lock.json b/package-lock.json index eb854407..e3a6e62c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@etherspot/prime-sdk", - "version": "1.4.1", + "version": "1.5.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@etherspot/prime-sdk", - "version": "1.4.1", + "version": "1.5.1", "license": "MIT", "dependencies": { "@apollo/client": "3.8.7", diff --git a/package.json b/package.json index cafc63bc..995ba200 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@etherspot/prime-sdk", - "version": "1.5.1", + "version": "1.5.2", "description": "Etherspot Prime (Account Abstraction) SDK", "keywords": [ "ether", diff --git a/src/sdk/base/BaseAccountAPI.ts b/src/sdk/base/BaseAccountAPI.ts index be0757a2..a5dfcf95 100644 --- a/src/sdk/base/BaseAccountAPI.ts +++ b/src/sdk/base/BaseAccountAPI.ts @@ -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, }), diff --git a/src/sdk/bundler/index.ts b/src/sdk/bundler/index.ts new file mode 100644 index 00000000..e7adc5a7 --- /dev/null +++ b/src/sdk/bundler/index.ts @@ -0,0 +1,2 @@ +export * from './interface'; +export * from './providers'; \ No newline at end of file diff --git a/src/sdk/bundler/interface.ts b/src/sdk/bundler/interface.ts new file mode 100644 index 00000000..10de729c --- /dev/null +++ b/src/sdk/bundler/interface.ts @@ -0,0 +1,6 @@ + +export interface BundlerProvider { + readonly url: string; +} + +export type BundlerProviderLike = BundlerProvider; \ No newline at end of file diff --git a/src/sdk/bundler/providers/EtherspotBundler.ts b/src/sdk/bundler/providers/EtherspotBundler.ts new file mode 100644 index 00000000..36e345da --- /dev/null +++ b/src/sdk/bundler/providers/EtherspotBundler.ts @@ -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; + } +} \ No newline at end of file diff --git a/src/sdk/bundler/providers/GenericBundler.ts b/src/sdk/bundler/providers/GenericBundler.ts new file mode 100644 index 00000000..2446ad75 --- /dev/null +++ b/src/sdk/bundler/providers/GenericBundler.ts @@ -0,0 +1,9 @@ +import { BundlerProvider } from "../interface"; + + +export class GenericBundler implements BundlerProvider { + readonly url: string; + constructor(bundlerUrl: string) { + this.url = bundlerUrl; + } +} \ No newline at end of file diff --git a/src/sdk/bundler/providers/index.ts b/src/sdk/bundler/providers/index.ts new file mode 100644 index 00000000..4b6685cc --- /dev/null +++ b/src/sdk/bundler/providers/index.ts @@ -0,0 +1,2 @@ +export * from './GenericBundler'; +export * from './EtherspotBundler'; \ No newline at end of file diff --git a/src/sdk/index.ts b/src/sdk/index.ts index 9967fe6e..16f02391 100644 --- a/src/sdk/index.ts +++ b/src/sdk/index.ts @@ -8,6 +8,7 @@ export * from './interfaces'; export * from './network'; export * from './state'; export * from './wallet'; +export * from './bundler'; export { PrimeSdk, DataUtils }; export default PrimeSdk; \ No newline at end of file diff --git a/src/sdk/interfaces.ts b/src/sdk/interfaces.ts index 818c46b6..4ef7301f 100644 --- a/src/sdk/interfaces.ts +++ b/src/sdk/interfaces.ts @@ -1,3 +1,4 @@ +import { BundlerProviderLike } from './bundler'; import { StateStorage } from './state'; export interface PaymasterApi { @@ -13,11 +14,12 @@ export enum Factory { export interface SdkOptions { chainId: number; + projectKey: string; + bundlerProvider?: BundlerProviderLike; stateStorage?: StateStorage; - bundlerRpcUrl?: string; rpcProviderUrl?: string; graphqlEndpoint?: string; - projectKey: string; + etherspotBundlerApiKey?: string; factoryWallet?: Factory; walletFactoryAddress?: string; entryPointAddress?: string; diff --git a/src/sdk/network/constants.ts b/src/sdk/network/constants.ts index 029e0cc1..82de3bbe 100644 --- a/src/sdk/network/constants.ts +++ b/src/sdk/network/constants.ts @@ -147,7 +147,7 @@ export const Networks: { }, [10]: { chainId: 10, - bundler: 'https://optimism-bundler.etherspot.io', + bundler: 'https://rpc.etherspot.io/optimism', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -160,7 +160,7 @@ export const Networks: { }, [137]: { chainId: 137, - bundler: 'https://polygon-bundler.etherspot.io', + bundler: 'https://rpc.etherspot.io/polygon', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -173,7 +173,7 @@ export const Networks: { }, [42161]: { chainId: 42161, - bundler: 'https://arbitrum-bundler.etherspot.io', + bundler: 'https://rpc.etherspot.io/arbitrum', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -199,7 +199,7 @@ export const Networks: { }, [1]: { chainId: 1, - bundler: 'https://ethereum-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/ethereum', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -238,7 +238,7 @@ export const Networks: { }, [122]: { chainId: 122, - bundler: 'https://fuse-bundler.etherspot.io', + bundler: 'https://rpc.etherspot.io/fuse', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -251,7 +251,7 @@ export const Networks: { }, [123]: { chainId: 123, - bundler: '', + bundler: 'https://fusetestnet-bundler.etherspot.io/', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -264,7 +264,7 @@ export const Networks: { }, [100]: { chainId: 100, - bundler: 'https://gnosis-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/gnosis', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -329,7 +329,7 @@ export const Networks: { }, [5000]: { chainId: 5000, - bundler: 'https://mantle-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/mantle', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -355,7 +355,7 @@ export const Networks: { }, [43114]: { chainId: 43114, - bundler: 'https://avalanche-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/avalanche', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -368,7 +368,7 @@ export const Networks: { }, [8453]: { chainId: 8453, - bundler: 'https://base-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/base', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -381,7 +381,7 @@ export const Networks: { }, [56]: { chainId: 56, - bundler: 'https://bnb-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/bnb', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -420,7 +420,7 @@ export const Networks: { }, [59144]: { chainId: 59144, - bundler: 'https://linea-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/linea', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -459,7 +459,7 @@ export const Networks: { }, [14]: { chainId: 14, - bundler: 'https://flare-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/flare', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -485,7 +485,7 @@ export const Networks: { }, [534352]: { chainId: 534352, - bundler: 'https://scroll-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/scroll', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index e012a208..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 @@ -55,9 +56,8 @@ export class PrimeSdk { this.index = index ?? 0; const networkConfig = getNetworkConfig(chainId); - if (!optionsLike.bundlerRpcUrl) { - if (!networkConfig) throw new Exception('No bundler Rpc provided'); - optionsLike.bundlerRpcUrl = networkConfig.bundler; + if (!optionsLike.bundlerProvider) { + optionsLike.bundlerProvider = new EtherspotBundler(chainId); } if (networkConfig) { @@ -70,7 +70,7 @@ export class PrimeSdk { if (rpcProviderUrl) { provider = new providers.JsonRpcProvider(rpcProviderUrl); - } else provider = new providers.JsonRpcProvider(optionsLike.bundlerRpcUrl); + } else provider = new providers.JsonRpcProvider(optionsLike.bundlerProvider.url); let entryPointAddress = '', walletFactoryAddress = ''; if (Networks[chainId]) { @@ -115,7 +115,7 @@ export class PrimeSdk { index: this.index, }) } - this.bundler = new HttpRpcClient(optionsLike.bundlerRpcUrl, entryPointAddress, chainId); + this.bundler = new HttpRpcClient(optionsLike.bundlerProvider.url, entryPointAddress, chainId); }