Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRO-2136 - Bundler Api Key #99

Merged
merged 8 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## [1.4.3] - 2024-01-30
### New
- Added `GenericBundler` and `EtherspotBundler` as bundlerProviders and removed bundlerUrl params from SdkOptions

## [1.4.2] - 2024-01-26
### Breaking changes
- Refactored `estimate` method
Expand Down
4 changes: 2 additions & 2 deletions examples/01-get-address.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { PrimeSdk } from '../src';
import { EtherspotBundler, PrimeSdk } from '../src';
import * as dotenv from 'dotenv';

dotenv.config();


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), '') }) // Testnets dont need apiKey on bundlerProvider

// get EtherspotWallet address...
const address: string = await primeSdk.getCounterFactualAddress();
Expand Down
4 changes: 2 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 @@ -11,7 +11,7 @@ const value = '0.00001'; // transfer value

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)) })

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

Expand Down
4 changes: 2 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 @@ -14,7 +14,7 @@ const tokenAddress = '0x326C977E6efc84E512bB9C30f76E30c160eD06FB';

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)) })

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

Expand Down
4 changes: 2 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 @@ -13,7 +13,7 @@ const tokenId = 4;

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)) })

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

Expand Down
4 changes: 2 additions & 2 deletions examples/12-add-guardians.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,7 +10,7 @@ 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' },
{ chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) },
);

console.log('address: ', primeSdk.state.EOAAddress);
Expand Down
3 changes: 2 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 @@ -14,6 +14,7 @@ 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))
})

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

dotenv.config();


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', 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))
})

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

dotenv.config();


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', 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))
})

// get SimpleAccount address...
const address: string = await primeSdk.getCounterFactualAddress();
Expand Down
3 changes: 2 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 @@ -18,6 +18,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))
})

console.log('address: ', primeSdk.state.EOAAddress)
Expand Down
4 changes: 2 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 @@ -16,7 +16,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))
})

console.log('address: ', primeSdk.state.EOAAddress)
Expand Down
6 changes: 4 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 @@ -11,7 +11,9 @@ const value = '0.0001'; // transfer value

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))
})

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

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

dotenv.config();
Expand All @@ -7,7 +7,7 @@ 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)) },
);

// get EtherspotWallet address for index 0...
Expand All @@ -17,7 +17,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)) },
);

// get EtherspotWallet address for index 1...
Expand Down
6 changes: 4 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 @@ -12,7 +12,9 @@ const value = '0.000001'; // transfer value
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))
})

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 = '';
// 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.0",
"version": "1.5.1",
"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;
18 changes: 18 additions & 0 deletions src/sdk/bundler/providers/EtherspotBundler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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);
bundlerUrl = networkConfig.bundler;
}
if (apiKey) this.url = bundlerUrl + '?api-key=' + apiKey;
else this.url = bundlerUrl;
this.apiKey = apiKey;
}
}
9 changes: 9 additions & 0 deletions src/sdk/bundler/providers/GenericBundler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BundlerProvider } from "../interface";


export class GenericBundler implements BundlerProvider {
readonly url: string;
constructor(bundlerUrl: string) {
this.url = bundlerUrl;
}
}
2 changes: 2 additions & 0 deletions src/sdk/bundler/providers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './GenericBundler';
export * from './EtherspotBundler';
1 change: 1 addition & 0 deletions src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 4 additions & 2 deletions src/sdk/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BundlerProviderLike } from './bundler';
import { StateStorage } from './state';

export interface PaymasterApi {
Expand All @@ -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;
Expand Down
Loading
Loading