@mycelium-sdk/core 1.0.0 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { PublicClient, Chain, Address, Hex, LocalAccount, Hash, WalletClient } from 'viem';
2
2
  import { SmartAccount, BundlerClient, WebAuthnAccount, toCoinbaseSmartAccount } from 'viem/account-abstraction';
3
+ import { PimlicoClient } from 'permissionless/clients/pimlico';
3
4
 
4
5
  declare const SUPPORTED_CHAIN_IDS: number[];
5
6
  type SupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
@@ -15,6 +16,8 @@ interface ChainConfig {
15
16
  rpcUrl: string;
16
17
  /** Bundler URL for the chain */
17
18
  bundlerUrl: string;
19
+ /** Paymaster URL for the chain */
20
+ paymasterUrl?: string;
18
21
  }
19
22
 
20
23
  /**
@@ -116,6 +119,26 @@ declare class ChainManager {
116
119
  * @returns PublicClient instance
117
120
  */
118
121
  private createPublicClient;
122
+ /**
123
+ * Returns the paymaster URL for the given chain ID
124
+ *
125
+ * @internal
126
+ * @category URLs
127
+ * @param chainId Target chain ID
128
+ * @returns Paymaster URL string
129
+ * @throws Error if chain config is missing or URL is invalid
130
+ */
131
+ private getPaymasterUrl;
132
+ /**
133
+ * Creates a {@link PimlicoClient} for the given chain ID
134
+ *
135
+ * @internal
136
+ * @category Clients
137
+ * @param chainId Target chain ID
138
+ * @returns PimlicoClient instance
139
+ * @throws Error if no paymaster URL is configured
140
+ */
141
+ getPaymasterClient(chainId: (typeof SUPPORTED_CHAIN_IDS)[number]): PimlicoClient;
119
142
  }
120
143
 
121
144
  /**
@@ -258,9 +281,13 @@ declare abstract class SmartWallet {
258
281
  *
259
282
  * @param transactionData Transaction data to execute
260
283
  * @param chainId Target blockchain chain ID
284
+ * @param options Optional parameters
285
+ * @param options.paymasterToken ERC-20 token address to use for gas payment (e.g., USDC)
261
286
  * @returns Promise resolving to the transaction {@link Hash}
262
287
  */
263
- abstract send(transactionData: TransactionData, chainId: SupportedChainId): Promise<Hash>;
288
+ abstract send(transactionData: TransactionData, chainId: SupportedChainId, options?: {
289
+ paymasterToken?: Address;
290
+ }): Promise<Hash>;
264
291
  /**
265
292
  * Executes a batch of transactions through the smart wallet
266
293
  *
@@ -272,9 +299,13 @@ declare abstract class SmartWallet {
272
299
  *
273
300
  * @param transactionData Array of transaction data objects
274
301
  * @param chainId Target blockchain chain ID
302
+ * @param options Optional parameters
303
+ * @param options.paymasterToken ERC-20 token address to use for gas payment (e.g., USDC)
275
304
  * @returns Promise resolving to the transaction {@link Hash}
276
305
  */
277
- abstract sendBatch(transactionData: TransactionData[], chainId: SupportedChainId): Promise<Hash>;
306
+ abstract sendBatch(transactionData: TransactionData[], chainId: SupportedChainId, options?: {
307
+ paymasterToken?: Address;
308
+ }): Promise<Hash>;
278
309
  /**
279
310
  * Prepares transaction data for sending tokens to another address
280
311
  *
@@ -572,11 +603,7 @@ interface ProxyBalance {
572
603
 
573
604
  /**
574
605
  * Options for creating a smart wallet
575
- <<<<<<< HEAD
576
606
  * Parameters for creating a new smart wallet with specified owners and signer
577
- =======
578
- * Parameters for creating a new smart wallet with specified owners and signer
579
- >>>>>>> main
580
607
  */
581
608
  type CreateSmartWalletOptions = {
582
609
  owners: Array<Address | WebAuthnAccount>;
@@ -585,11 +612,7 @@ type CreateSmartWalletOptions = {
585
612
  };
586
613
  /**
587
614
  * Options for creating a wallet with embedded signer
588
- <<<<<<< HEAD
589
615
  * Parameters for creating both embedded and smart wallets, with embedded wallet automatically added as signer
590
- =======
591
- * Parameters for creating both embedded and smart wallets, with embedded wallet automatically added as signer
592
- >>>>>>> main
593
616
  */
594
617
  type CreateAccountOptions = {
595
618
  owners?: Array<Address | WebAuthnAccount>;
@@ -598,11 +621,7 @@ type CreateAccountOptions = {
598
621
  };
599
622
  /**
600
623
  * Options for retrieving a smart wallet with provided signer
601
- <<<<<<< HEAD
602
624
  * Parameters for getting an existing smart wallet using a provided LocalAccount signer
603
- =======
604
- * Parameters for getting an existing smart wallet using a provided LocalAccount signer
605
- >>>>>>> main
606
625
  */
607
626
  type GetSmartWalletOptions = {
608
627
  signer: LocalAccount;
@@ -613,22 +632,14 @@ type GetSmartWalletOptions = {
613
632
  };
614
633
  /**
615
634
  * Options for retrieving an embedded wallet
616
- <<<<<<< HEAD
617
635
  * Parameters for getting an existing embedded wallet
618
- =======
619
- * Parameters for getting an existing embedded wallet
620
- >>>>>>> main
621
636
  */
622
637
  type GetEmbeddedWalletOptions = {
623
638
  walletId: string;
624
639
  };
625
640
  /**
626
641
  * Options for retrieving a smart wallet with embedded wallet signer
627
- <<<<<<< HEAD
628
642
  * Parameters for getting an existing smart wallet using an embedded wallet as signer.
629
- =======
630
- * Parameters for getting an existing smart wallet using an embedded wallet as signer.
631
- >>>>>>> main
632
643
  * If neither walletAddress nor deploymentOwners is provided, defaults to using the embedded wallet as single owner.
633
644
  */
634
645
  type GetAccountOptions = Omit<GetSmartWalletOptions, 'signer'> & GetEmbeddedWalletOptions;
@@ -1089,6 +1100,7 @@ declare class ProtocolsNamespace {
1089
1100
  * chainId: parseInt(process.env.NEXT_PUBLIC_CHAIN_ID!),
1090
1101
  * rpcUrl: process.env.NEXT_PUBLIC_RPC_URL!,
1091
1102
  * bundlerUrl: process.env.NEXT_PUBLIC_BUNDLER_URL!,
1103
+ * paymasterUrl: process.env.NEXT_PUBLIC_PAYMASTER_URL!,
1092
1104
  * },
1093
1105
  * protocolsRouterConfig: {
1094
1106
  * riskLevel: 'low',
@@ -1321,6 +1333,8 @@ declare class DefaultSmartWallet extends SmartWallet {
1321
1333
  private protocolProvider;
1322
1334
  /** Coinbase CDP instance to interact with Coinbase CDP API */
1323
1335
  private coinbaseCDP;
1336
+ /** Paymaster instance for gas sponsoring */
1337
+ private paymaster;
1324
1338
  /**
1325
1339
  * Creates a smart wallet instance
1326
1340
  *
@@ -1333,8 +1347,7 @@ declare class DefaultSmartWallet extends SmartWallet {
1333
1347
  * @param signerOwnerIndex Optional index of `signer` in owners (default 0)
1334
1348
  * @param nonce Optional salt for deterministic address calc (default 0)
1335
1349
  */
1336
- constructor(owners: Array<Address | WebAuthnAccount>, signer: LocalAccount, chainManager: ChainManager, protocolProvider: BaseProtocol, // Protocol['instance'],
1337
- coinbaseCDP: CoinbaseCDP | null, deploymentAddress?: Address, signerOwnerIndex?: number, nonce?: bigint);
1350
+ constructor(owners: Array<Address | WebAuthnAccount>, signer: LocalAccount, chainManager: ChainManager, protocolProvider: BaseProtocol, coinbaseCDP: CoinbaseCDP | null, deploymentAddress?: Address, signerOwnerIndex?: number, nonce?: bigint);
1338
1351
  /**
1339
1352
  * Returns the signer account for this smart wallet
1340
1353
  *
@@ -1358,6 +1371,7 @@ declare class DefaultSmartWallet extends SmartWallet {
1358
1371
  * @throws Error if an owner has an invalid type
1359
1372
  */
1360
1373
  getAddress(): Promise<`0x${string}`>;
1374
+ private bumpGasLimits;
1361
1375
  /**
1362
1376
  * Builds a Coinbase Smart Account for a specific chain
1363
1377
  *
@@ -1413,10 +1427,14 @@ declare class DefaultSmartWallet extends SmartWallet {
1413
1427
  *
1414
1428
  * @param transactionData Transaction details (`to`, `value`, `data`)
1415
1429
  * @param chainId Target chain ID
1430
+ * @param options Optional parameters
1431
+ * @param options.paymasterToken ERC-20 token address to use for gas payment (e.g., USDC)
1416
1432
  * @returns Promise that resolves to the UserOperation hash
1417
1433
  * @throws Error with a readable message if submission or inclusion fails
1418
1434
  */
1419
- send(transactionData: TransactionData, chainId: SupportedChainId): Promise<Hash>;
1435
+ send(transactionData: TransactionData, chainId: SupportedChainId, options?: {
1436
+ paymasterToken?: Address;
1437
+ }): Promise<Hash>;
1420
1438
  /**
1421
1439
  * Builds a UserOperation from several onchain transactions and submits via the bundler, then waits for inclusion
1422
1440
  *
@@ -1425,10 +1443,14 @@ declare class DefaultSmartWallet extends SmartWallet {
1425
1443
  *
1426
1444
  * @param transactionData An array of calls to execute
1427
1445
  * @param chainId Target chain ID
1446
+ * @param options Optional parameters
1447
+ * @param options.paymasterToken ERC-20 token address to use for gas payment (e.g., USDC)
1428
1448
  * @returns Promise that resolves to the UserOperation hash for the batch
1429
1449
  * @throws Error with a readable message if submission or inclusion fails
1430
1450
  */
1431
- sendBatch(transactionData: TransactionData[], chainId: SupportedChainId): Promise<Hash>;
1451
+ sendBatch(transactionData: TransactionData[], chainId: SupportedChainId, options?: {
1452
+ paymasterToken?: Address;
1453
+ }): Promise<Hash>;
1432
1454
  /**
1433
1455
  * Funds the smart wallet with the specified amount of the specified token via Coinbase CDP on-ramp service
1434
1456
  *
@@ -1557,7 +1579,11 @@ declare class FundingNamespace {
1557
1579
  *
1558
1580
  * // Option 1: Initialize with API key (fetches config from backend)
1559
1581
  * const sdk = await MyceliumSDK.init({
1560
- * apiKey: 'sk_...'
1582
+ * apiKey: 'sk_...',
1583
+ * chainId: 8453,
1584
+ * protocolsSecurityConfig: {
1585
+ * riskLevel: "low",
1586
+ * },
1561
1587
  * });
1562
1588
  *
1563
1589
  * // Option 2: Initialize with full configuration
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { PublicClient, Chain, Address, Hex, LocalAccount, Hash, WalletClient } from 'viem';
2
2
  import { SmartAccount, BundlerClient, WebAuthnAccount, toCoinbaseSmartAccount } from 'viem/account-abstraction';
3
+ import { PimlicoClient } from 'permissionless/clients/pimlico';
3
4
 
4
5
  declare const SUPPORTED_CHAIN_IDS: number[];
5
6
  type SupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
@@ -15,6 +16,8 @@ interface ChainConfig {
15
16
  rpcUrl: string;
16
17
  /** Bundler URL for the chain */
17
18
  bundlerUrl: string;
19
+ /** Paymaster URL for the chain */
20
+ paymasterUrl?: string;
18
21
  }
19
22
 
20
23
  /**
@@ -116,6 +119,26 @@ declare class ChainManager {
116
119
  * @returns PublicClient instance
117
120
  */
118
121
  private createPublicClient;
122
+ /**
123
+ * Returns the paymaster URL for the given chain ID
124
+ *
125
+ * @internal
126
+ * @category URLs
127
+ * @param chainId Target chain ID
128
+ * @returns Paymaster URL string
129
+ * @throws Error if chain config is missing or URL is invalid
130
+ */
131
+ private getPaymasterUrl;
132
+ /**
133
+ * Creates a {@link PimlicoClient} for the given chain ID
134
+ *
135
+ * @internal
136
+ * @category Clients
137
+ * @param chainId Target chain ID
138
+ * @returns PimlicoClient instance
139
+ * @throws Error if no paymaster URL is configured
140
+ */
141
+ getPaymasterClient(chainId: (typeof SUPPORTED_CHAIN_IDS)[number]): PimlicoClient;
119
142
  }
120
143
 
121
144
  /**
@@ -258,9 +281,13 @@ declare abstract class SmartWallet {
258
281
  *
259
282
  * @param transactionData Transaction data to execute
260
283
  * @param chainId Target blockchain chain ID
284
+ * @param options Optional parameters
285
+ * @param options.paymasterToken ERC-20 token address to use for gas payment (e.g., USDC)
261
286
  * @returns Promise resolving to the transaction {@link Hash}
262
287
  */
263
- abstract send(transactionData: TransactionData, chainId: SupportedChainId): Promise<Hash>;
288
+ abstract send(transactionData: TransactionData, chainId: SupportedChainId, options?: {
289
+ paymasterToken?: Address;
290
+ }): Promise<Hash>;
264
291
  /**
265
292
  * Executes a batch of transactions through the smart wallet
266
293
  *
@@ -272,9 +299,13 @@ declare abstract class SmartWallet {
272
299
  *
273
300
  * @param transactionData Array of transaction data objects
274
301
  * @param chainId Target blockchain chain ID
302
+ * @param options Optional parameters
303
+ * @param options.paymasterToken ERC-20 token address to use for gas payment (e.g., USDC)
275
304
  * @returns Promise resolving to the transaction {@link Hash}
276
305
  */
277
- abstract sendBatch(transactionData: TransactionData[], chainId: SupportedChainId): Promise<Hash>;
306
+ abstract sendBatch(transactionData: TransactionData[], chainId: SupportedChainId, options?: {
307
+ paymasterToken?: Address;
308
+ }): Promise<Hash>;
278
309
  /**
279
310
  * Prepares transaction data for sending tokens to another address
280
311
  *
@@ -572,11 +603,7 @@ interface ProxyBalance {
572
603
 
573
604
  /**
574
605
  * Options for creating a smart wallet
575
- <<<<<<< HEAD
576
606
  * Parameters for creating a new smart wallet with specified owners and signer
577
- =======
578
- * Parameters for creating a new smart wallet with specified owners and signer
579
- >>>>>>> main
580
607
  */
581
608
  type CreateSmartWalletOptions = {
582
609
  owners: Array<Address | WebAuthnAccount>;
@@ -585,11 +612,7 @@ type CreateSmartWalletOptions = {
585
612
  };
586
613
  /**
587
614
  * Options for creating a wallet with embedded signer
588
- <<<<<<< HEAD
589
615
  * Parameters for creating both embedded and smart wallets, with embedded wallet automatically added as signer
590
- =======
591
- * Parameters for creating both embedded and smart wallets, with embedded wallet automatically added as signer
592
- >>>>>>> main
593
616
  */
594
617
  type CreateAccountOptions = {
595
618
  owners?: Array<Address | WebAuthnAccount>;
@@ -598,11 +621,7 @@ type CreateAccountOptions = {
598
621
  };
599
622
  /**
600
623
  * Options for retrieving a smart wallet with provided signer
601
- <<<<<<< HEAD
602
624
  * Parameters for getting an existing smart wallet using a provided LocalAccount signer
603
- =======
604
- * Parameters for getting an existing smart wallet using a provided LocalAccount signer
605
- >>>>>>> main
606
625
  */
607
626
  type GetSmartWalletOptions = {
608
627
  signer: LocalAccount;
@@ -613,22 +632,14 @@ type GetSmartWalletOptions = {
613
632
  };
614
633
  /**
615
634
  * Options for retrieving an embedded wallet
616
- <<<<<<< HEAD
617
635
  * Parameters for getting an existing embedded wallet
618
- =======
619
- * Parameters for getting an existing embedded wallet
620
- >>>>>>> main
621
636
  */
622
637
  type GetEmbeddedWalletOptions = {
623
638
  walletId: string;
624
639
  };
625
640
  /**
626
641
  * Options for retrieving a smart wallet with embedded wallet signer
627
- <<<<<<< HEAD
628
642
  * Parameters for getting an existing smart wallet using an embedded wallet as signer.
629
- =======
630
- * Parameters for getting an existing smart wallet using an embedded wallet as signer.
631
- >>>>>>> main
632
643
  * If neither walletAddress nor deploymentOwners is provided, defaults to using the embedded wallet as single owner.
633
644
  */
634
645
  type GetAccountOptions = Omit<GetSmartWalletOptions, 'signer'> & GetEmbeddedWalletOptions;
@@ -1089,6 +1100,7 @@ declare class ProtocolsNamespace {
1089
1100
  * chainId: parseInt(process.env.NEXT_PUBLIC_CHAIN_ID!),
1090
1101
  * rpcUrl: process.env.NEXT_PUBLIC_RPC_URL!,
1091
1102
  * bundlerUrl: process.env.NEXT_PUBLIC_BUNDLER_URL!,
1103
+ * paymasterUrl: process.env.NEXT_PUBLIC_PAYMASTER_URL!,
1092
1104
  * },
1093
1105
  * protocolsRouterConfig: {
1094
1106
  * riskLevel: 'low',
@@ -1321,6 +1333,8 @@ declare class DefaultSmartWallet extends SmartWallet {
1321
1333
  private protocolProvider;
1322
1334
  /** Coinbase CDP instance to interact with Coinbase CDP API */
1323
1335
  private coinbaseCDP;
1336
+ /** Paymaster instance for gas sponsoring */
1337
+ private paymaster;
1324
1338
  /**
1325
1339
  * Creates a smart wallet instance
1326
1340
  *
@@ -1333,8 +1347,7 @@ declare class DefaultSmartWallet extends SmartWallet {
1333
1347
  * @param signerOwnerIndex Optional index of `signer` in owners (default 0)
1334
1348
  * @param nonce Optional salt for deterministic address calc (default 0)
1335
1349
  */
1336
- constructor(owners: Array<Address | WebAuthnAccount>, signer: LocalAccount, chainManager: ChainManager, protocolProvider: BaseProtocol, // Protocol['instance'],
1337
- coinbaseCDP: CoinbaseCDP | null, deploymentAddress?: Address, signerOwnerIndex?: number, nonce?: bigint);
1350
+ constructor(owners: Array<Address | WebAuthnAccount>, signer: LocalAccount, chainManager: ChainManager, protocolProvider: BaseProtocol, coinbaseCDP: CoinbaseCDP | null, deploymentAddress?: Address, signerOwnerIndex?: number, nonce?: bigint);
1338
1351
  /**
1339
1352
  * Returns the signer account for this smart wallet
1340
1353
  *
@@ -1358,6 +1371,7 @@ declare class DefaultSmartWallet extends SmartWallet {
1358
1371
  * @throws Error if an owner has an invalid type
1359
1372
  */
1360
1373
  getAddress(): Promise<`0x${string}`>;
1374
+ private bumpGasLimits;
1361
1375
  /**
1362
1376
  * Builds a Coinbase Smart Account for a specific chain
1363
1377
  *
@@ -1413,10 +1427,14 @@ declare class DefaultSmartWallet extends SmartWallet {
1413
1427
  *
1414
1428
  * @param transactionData Transaction details (`to`, `value`, `data`)
1415
1429
  * @param chainId Target chain ID
1430
+ * @param options Optional parameters
1431
+ * @param options.paymasterToken ERC-20 token address to use for gas payment (e.g., USDC)
1416
1432
  * @returns Promise that resolves to the UserOperation hash
1417
1433
  * @throws Error with a readable message if submission or inclusion fails
1418
1434
  */
1419
- send(transactionData: TransactionData, chainId: SupportedChainId): Promise<Hash>;
1435
+ send(transactionData: TransactionData, chainId: SupportedChainId, options?: {
1436
+ paymasterToken?: Address;
1437
+ }): Promise<Hash>;
1420
1438
  /**
1421
1439
  * Builds a UserOperation from several onchain transactions and submits via the bundler, then waits for inclusion
1422
1440
  *
@@ -1425,10 +1443,14 @@ declare class DefaultSmartWallet extends SmartWallet {
1425
1443
  *
1426
1444
  * @param transactionData An array of calls to execute
1427
1445
  * @param chainId Target chain ID
1446
+ * @param options Optional parameters
1447
+ * @param options.paymasterToken ERC-20 token address to use for gas payment (e.g., USDC)
1428
1448
  * @returns Promise that resolves to the UserOperation hash for the batch
1429
1449
  * @throws Error with a readable message if submission or inclusion fails
1430
1450
  */
1431
- sendBatch(transactionData: TransactionData[], chainId: SupportedChainId): Promise<Hash>;
1451
+ sendBatch(transactionData: TransactionData[], chainId: SupportedChainId, options?: {
1452
+ paymasterToken?: Address;
1453
+ }): Promise<Hash>;
1432
1454
  /**
1433
1455
  * Funds the smart wallet with the specified amount of the specified token via Coinbase CDP on-ramp service
1434
1456
  *
@@ -1557,7 +1579,11 @@ declare class FundingNamespace {
1557
1579
  *
1558
1580
  * // Option 1: Initialize with API key (fetches config from backend)
1559
1581
  * const sdk = await MyceliumSDK.init({
1560
- * apiKey: 'sk_...'
1582
+ * apiKey: 'sk_...',
1583
+ * chainId: 8453,
1584
+ * protocolsSecurityConfig: {
1585
+ * riskLevel: "low",
1586
+ * },
1561
1587
  * });
1562
1588
  *
1563
1589
  * // Option 2: Initialize with full configuration