@mycelium-sdk/core 0.1.0 → 1.0.0-alpha.1

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.ts CHANGED
@@ -4,23 +4,6 @@ import { SmartAccount, BundlerClient, WebAuthnAccount, toCoinbaseSmartAccount }
4
4
  declare const SUPPORTED_CHAIN_IDS: number[];
5
5
  type SupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
6
6
 
7
- /**
8
- * @internal
9
- * @category Types
10
- * Detailed token balance information
11
- *
12
- */
13
- interface TokenBalance {
14
- symbol: string;
15
- totalBalance: bigint;
16
- totalFormattedBalance: string;
17
- chainBalances: Array<{
18
- chainId: SupportedChainId;
19
- balance: bigint;
20
- formattedBalance: string;
21
- }>;
22
- }
23
-
24
7
  /**
25
8
  * Chain configuration
26
9
  * Configuration for each supported chain
@@ -135,6 +118,23 @@ declare class ChainManager {
135
118
  private createPublicClient;
136
119
  }
137
120
 
121
+ /**
122
+ * @internal
123
+ * @category Types
124
+ * Detailed token balance information
125
+ *
126
+ */
127
+ interface TokenBalance {
128
+ symbol: string;
129
+ totalBalance: bigint;
130
+ totalFormattedBalance: string;
131
+ chainBalances: Array<{
132
+ chainId: SupportedChainId;
133
+ balance: bigint;
134
+ formattedBalance: string;
135
+ }>;
136
+ }
137
+
138
138
  /**
139
139
  * Asset identifier - can be a symbol (like 'usdc') or address
140
140
  */
@@ -294,7 +294,7 @@ declare abstract class SmartWallet {
294
294
  * @param amount Amount to deposit in human-readable format
295
295
  * @returns Promise resolving to a {@link VaultTxnResult}
296
296
  */
297
- abstract earn(amount: string): Promise<VaultTxnResult>;
297
+ abstract earn(vaultInfo: VaultInfo, amount: string): Promise<VaultTxnResult>;
298
298
  /**
299
299
  * Retrieves the balance of deposited funds in the selected protocol vault
300
300
  *
@@ -302,7 +302,7 @@ declare abstract class SmartWallet {
302
302
  * @category Yield
303
303
  * @returns Promise resolving to a {@link VaultBalance} or null if none
304
304
  */
305
- abstract getEarnBalance(): Promise<VaultBalance | null>;
305
+ abstract getEarnBalances(): Promise<VaultBalance[] | null>;
306
306
  /**
307
307
  * Withdraws a specific amount of shares from the protocol vault
308
308
  *
@@ -311,7 +311,7 @@ declare abstract class SmartWallet {
311
311
  * @param amount Human-readable amount of shares to withdraw
312
312
  * @returns Promise resolving to a {@link VaultTxnResult}
313
313
  */
314
- abstract withdraw(amount: string): Promise<VaultTxnResult>;
314
+ abstract withdraw(vaultInfo: VaultInfo, amount: string): Promise<VaultTxnResult>;
315
315
  /**
316
316
  * Funds the smart wallet with the specified amount of the specified token via Coinbase CDP on-ramp service
317
317
  *
@@ -350,6 +350,63 @@ declare abstract class SmartWallet {
350
350
  abstract cashOut(country: string, paymentMethod: string, redirectUrl: string, sellAmount: string, cashoutCurrency?: string, sellCurrency?: string): Promise<OffRampUrlResponse>;
351
351
  }
352
352
 
353
+ type ApiResponse<T = unknown> = {
354
+ success: true;
355
+ data: T;
356
+ } | {
357
+ success: false;
358
+ error: string;
359
+ };
360
+ type OperationType = 'config' | 'deposit' | 'withdraw' | 'log' | 'vaults' | 'balances' | 'apiKeyValidation';
361
+
362
+ declare class ApiClient {
363
+ private readonly client;
364
+ /** URL settings for the endpoint: get the best vaults to deposit funds */
365
+ private readonly bestVaultUrlSettings;
366
+ /** URL settings for the endpoint: deposit funds to a provided vault */
367
+ private readonly depositUrlSettings;
368
+ /** URL settings for the endpoint: log a vault-related operation after deposit or withdraw funds */
369
+ private readonly logOperationSettings;
370
+ /** URL settings for the endpoint: withdraw funds from a provided vault */
371
+ private readonly withdrawUrlSettings;
372
+ /** URL settings for the endpoint: get the balances of a user by a provided address */
373
+ private readonly balancesUrlSettings;
374
+ /** URL settings for the endpoint: validate the API key */
375
+ private readonly apiKeyValidUrlSettings;
376
+ /** URL settings for the endpoint: get the config for services */
377
+ private readonly configUrlSettings;
378
+ /** URL settings mapping with operation types */
379
+ private readonly operationTypeToUrlSettings;
380
+ /** API key for the backend API */
381
+ private apiKey;
382
+ constructor(apiKey: string);
383
+ /**
384
+ * Send a request to the backend API
385
+ * @param path Path of the endpoint to send the request to
386
+ * @param method Method of the request
387
+ * @param body Body of the request
388
+ * @returns Response from the backend API
389
+ */
390
+ sendRequest(operationType: OperationType, params?: Record<string, string>, protocolId?: string, body?: Record<string, string | VaultInfo>): Promise<ApiResponse<unknown>>;
391
+ /**
392
+ * Validates whether the provided API key is valid
393
+ *
394
+ * @internal
395
+ * @param apiKey API key from {@link ProtocolsRouterConfig}
396
+ * @returns True if the API key is considered valid
397
+ */
398
+ validate(): Promise<boolean>;
399
+ /**
400
+ *
401
+ * Validates the format of the API key. Must start with 'sk_' and contain only hexadecimal characters
402
+ *
403
+ * @internal
404
+ * @param apiKey API key from {@link ProtocolsRouterConfig}
405
+ * @returns
406
+ */
407
+ private validateApiKeyFormat;
408
+ }
409
+
353
410
  /**
354
411
  * Base Protocol
355
412
  *
@@ -363,56 +420,51 @@ declare abstract class SmartWallet {
363
420
  *
364
421
  * Generic parameters allow protocol-specific typing for vault info, balances, and transaction results
365
422
  */
366
- declare abstract class BaseProtocol<TVaultInfo extends VaultInfo = VaultInfo, TVaultBalance extends VaultBalance = VaultBalance, TVaultTxnResult extends VaultTxnResult = VaultTxnResult> {
367
- /** Chain manager instance injected during initialization */
423
+ declare abstract class BaseProtocol {
424
+ /** Selected chain ID for the protocol */
425
+ protected selectedChainId: SupportedChainId | undefined;
426
+ /** Public client to make requests to RPC */
427
+ protected publicClient: PublicClient | undefined;
428
+ /** Chain manager instance for network access */
368
429
  chainManager: ChainManager | undefined;
369
430
  /**
370
431
  * Initialize the protocol
371
432
  * @param chainManager Chain manager for accessing RPC and bundler clients
372
433
  */
373
- abstract init(chainManager: ChainManager): Promise<void>;
434
+ abstract init(chainManager: ChainManager, protocolsSecurityConfig: ProtocolsSecurityConfig, apiClient?: ApiClient): Promise<void>;
374
435
  /**
375
436
  * Ensure the protocol has been initialized
376
437
  * @throws Error if `init()` has not been called
377
438
  */
378
439
  protected ensureInitialized(): void;
379
- /**
380
- * Get all available vaults
381
- * @returns List of vaults that support deposits
382
- */
383
- abstract getVaults(): Promise<TVaultInfo[]> | TVaultInfo[];
384
440
  /**
385
441
  * Get the best vault for deposits
386
442
  * @returns Single vault considered optimal for deposit
387
443
  */
388
- abstract getBestVault(): Promise<TVaultInfo> | TVaultInfo;
389
- /**
390
- * Get a vault where funds may already be deposited
391
- * @param smartWallet Wallet to check for existing deposits
392
- * @returns Vault info if deposits exist, otherwise null
393
- */
394
- abstract fetchDepositedVaults(smartWallet: SmartWallet): Promise<TVaultInfo | null>;
444
+ abstract getBestVaults(stableVaultsLimit?: number, nonStableVaultsLimit?: number): Promise<Vaults> | Vaults;
395
445
  /**
396
446
  * Deposit funds into a vault
447
+ * @param vaultInfo Vault information
397
448
  * @param amount Amount in human-readable format
398
449
  * @param smartWallet Wallet executing the deposit
399
450
  * @returns Result of the deposit transaction
400
451
  */
401
- abstract deposit(amount: string, smartWallet: SmartWallet): Promise<TVaultTxnResult>;
452
+ abstract deposit(vaultInfo: VaultInfo, amount: string, smartWallet: SmartWallet): Promise<VaultTxnResult>;
402
453
  /**
403
454
  * Withdraw funds from a vault
404
- * @param amountInShares Amount of shares to withdraw
455
+ * @param vaultInfo Vault information
456
+ * @param amount Amount in human-readable format (or undefined to withdraw all)
405
457
  * @param smartWallet Wallet executing the withdrawal
406
458
  * @returns Result of the withdrawal transaction
407
459
  */
408
- abstract withdraw(amountInShares: string, smartWallet: SmartWallet): Promise<TVaultTxnResult>;
460
+ abstract withdraw(vaultInfo: VaultInfo, amountInShares: string, smartWallet: SmartWallet): Promise<VaultTxnResult>;
409
461
  /**
410
462
  * Get deposited balance in a vault
411
- * @param vaultInfo Vault info for a selected protocol
412
463
  * @param walletAddress Wallet address to check the balance of
464
+ * @param protocolId Protocol ID to get balances for
413
465
  * @returns Balance of deposited funds
414
466
  */
415
- abstract getBalance(vaultInfo: TVaultInfo, walletAddress: Address): Promise<TVaultBalance>;
467
+ abstract getBalances(walletAddress: Address, protocolId?: string): Promise<VaultBalance[]>;
416
468
  /**
417
469
  * Approve a token for protocol use
418
470
  * @param tokenAddress Token address
@@ -434,35 +486,14 @@ declare abstract class BaseProtocol<TVaultInfo extends VaultInfo = VaultInfo, TV
434
486
  protected checkAllowance(tokenAddress: Address, spenderAddress: Address, walletAddress: Address, chainId: SupportedChainId): Promise<bigint>;
435
487
  }
436
488
 
437
- /**
438
- * Base information that can be used to identify a protocol
439
- */
440
- interface ProtocolInfo {
441
- id: string;
442
- name: string;
443
- website: string;
444
- logo: string;
445
- supportedChains: number[];
446
- riskLevel: 'low' | 'medium' | 'high';
447
- isPremium: boolean;
448
- }
449
- /**
450
- * Interface with protocol information and instance object
451
- */
452
- interface Protocol {
453
- instance: BaseProtocol;
454
- info: ProtocolInfo;
455
- }
456
489
  /**
457
490
  * The protocols router config that defines which protocols should be used for an integrator
458
491
  */
459
- interface ProtocolsRouterConfig {
492
+ interface ProtocolsSecurityConfig {
460
493
  riskLevel: 'low' | 'medium' | 'high';
461
- minApy?: number;
462
- apiKey?: string;
463
494
  }
464
495
  /**
465
- * @internal
496
+ * @public
466
497
  * The info about a protocol vault
467
498
  * @category Types
468
499
  * @remarks
@@ -470,17 +501,26 @@ interface ProtocolsRouterConfig {
470
501
  */
471
502
  interface VaultInfo {
472
503
  id: string;
473
- chain: string;
474
- chainId?: number;
475
- depositTokenAddress: Address;
476
- depositTokenDecimals: number;
477
- depositTokenSymbol?: string;
504
+ protocolId: string;
478
505
  vaultAddress: Address;
479
- earnTokenAddress?: Address;
480
- earnTokenDecimals?: number;
481
- earnTokenSymbol?: string;
506
+ tokenAddress: Address;
507
+ tokenDecimals: number;
508
+ tokenSymbol?: string;
509
+ name: string;
510
+ type: 'stable' | 'non-stable';
511
+ chain: string;
482
512
  metadata?: Record<string, number | string>;
483
513
  }
514
+ /**
515
+ * @public
516
+ * The array of stable and non-stable vaults for a protocol
517
+ * @remarks Stable and non-stable vaults are @see VaultInfo type
518
+ * @category Types
519
+ */
520
+ interface Vaults {
521
+ stable: VaultInfo[];
522
+ nonStable: VaultInfo[];
523
+ }
484
524
  /**
485
525
  * @public
486
526
  * The info about current user's balance in a protocol vault
@@ -489,10 +529,8 @@ interface VaultInfo {
489
529
  * The generic type that shows fields that should be present in a protocol vault balance
490
530
  */
491
531
  interface VaultBalance {
492
- /** amount of shares in a protocol vault based on a deposited amount */
493
- shares: string;
494
532
  /** amount of deposited tokens in a protocol vault (e.g. sUSDC)*/
495
- depositedAmount: string;
533
+ balance: string | ProxyBalance | null;
496
534
  /** info about a protocol vault where a user deposited funds */
497
535
  vaultInfo: VaultInfo;
498
536
  }
@@ -512,112 +550,75 @@ interface VaultTxnResult {
512
550
  error?: string;
513
551
  }
514
552
 
515
- interface SparkVaultInfo extends VaultInfo {
516
- id: string;
517
- chain: string;
518
- earnTokenAddress: Address;
519
- earnTokenDecimals: number;
520
- depositTokenSymbol: string;
521
- earnTokenSymbol: string;
522
- metadata?: {
523
- apy?: number;
524
- };
553
+ interface ProxyBalance {
554
+ userAddress: Address;
555
+ integratorId: string;
556
+ protocolId: string;
557
+ vaultAddress: Address;
558
+ chainId: number;
559
+ currentBalance: string;
560
+ actualCurrentBalance: string;
561
+ pnl: number;
562
+ balanceInShares: string;
563
+ earnedOverall: string;
564
+ earned7d: string;
565
+ earned30d: string;
566
+ earned90d: string;
567
+ earnedOverallUpdatedAt: string | null;
568
+ earned7dUpdatedAt: string | null;
569
+ earned30dUpdatedAt: string | null;
570
+ earned90dUpdatedAt: string | null;
525
571
  }
572
+
526
573
  /**
527
- * @public
528
- * The result of a Spark vault deposit or withdrawal transaction
529
- * @category Types
574
+ * Options for creating a smart wallet
575
+ * Parameters for creating a new smart wallet with specified owners and signer
530
576
  */
531
- interface SparkVaultTxnResult {
532
- /** the boolean value that indicates if the transaction was successful */
533
- success: boolean;
534
- /** hash of the operation */
535
- hash: string;
536
- }
577
+ type CreateSmartWalletOptions = {
578
+ owners: Array<Address | WebAuthnAccount>;
579
+ signer: LocalAccount;
580
+ nonce?: bigint;
581
+ };
537
582
  /**
538
- * @public
539
- * The info about current user's balance in a Spark vault
540
- * @category Types
583
+ * Options for creating a wallet with embedded signer
584
+ * Parameters for creating both embedded and smart wallets, with embedded wallet automatically added as signer
541
585
  */
542
- interface SparkVaultBalance {
543
- /** amount of shares in sUSDC token that user has in the Spark vault */
544
- shares: string;
545
- /**
546
- * amount of deposited tokens + earned tokens
547
- * @remarks
548
- * To get the amount of earned tokens, you need to store all user's deposits and withdrawals
549
- * on your side and then subtract the amount of deposited tokens from the `depositedAmount` */
550
- depositedAmount: string;
551
- /** detailed info about a Spark vault where a user deposited funds */
552
- vaultInfo: SparkVaultInfo;
553
- }
554
-
586
+ type CreateAccountOptions = {
587
+ owners?: Array<Address | WebAuthnAccount>;
588
+ embeddedWalletIndex?: number;
589
+ nonce?: bigint;
590
+ };
555
591
  /**
556
- * Abstract base class for smart wallet providers
557
- *
558
- * @internal
559
- * @category Wallet Providers
560
- * @remarks
561
- * Defines the interface for factories that create and manage {@link SmartWallet} instances
562
- * Extended by implementations such as {@link DefaultSmartWalletProvider}
592
+ * Options for retrieving a smart wallet with provided signer
593
+ * Parameters for getting an existing smart wallet using a provided LocalAccount signer
563
594
  */
564
- declare abstract class SmartWalletProvider$1 {
565
- /**
566
- * Creates a new smart wallet instance that will be deployed on first transaction
567
- *
568
- * @internal
569
- * @category Creation
570
- * @remarks
571
- * Address is calculated deterministically using owners and nonce
572
- *
573
- * @param params Wallet creation parameters
574
- * @param params.owners Array of wallet owners (addresses or WebAuthn accounts)
575
- * @param params.signer Local account used for signing
576
- * @param params.nonce Optional nonce for address derivation, default 0
577
- * @returns Promise resolving to a {@link SmartWallet} instance
578
- */
579
- abstract createWallet(params: {
580
- owners: Array<Address | WebAuthnAccount>;
581
- signer: LocalAccount;
582
- nonce?: bigint;
583
- }): Promise<SmartWallet>;
584
- /**
585
- * Returns a smart wallet instance for an already deployed contract
586
- *
587
- * @internal
588
- * @category Retrieval
589
- * @remarks
590
- * Use when the wallet address is already known
591
- *
592
- * @param params Wallet retrieval parameters
593
- * @param params.walletAddress Deployed smart wallet address
594
- * @param params.signer Local account to operate the wallet
595
- * @param params.ownerIndex Optional index of signer in the owners list, default 0
596
- * @returns A {@link SmartWallet} instance
597
- */
598
- abstract getWallet(params: {
599
- walletAddress: Address;
600
- signer: LocalAccount;
601
- ownerIndex?: number;
602
- }): SmartWallet;
603
- /**
604
- * Predicts the deterministic address of a smart wallet
605
- *
606
- * @internal
607
- * @category Addressing
608
- * @remarks
609
- * Uses CREATE2 with owners and nonce to calculate the wallet address
610
- *
611
- * @param params Prediction parameters
612
- * @param params.owners Array of wallet owners (addresses or WebAuthn accounts)
613
- * @param params.nonce Optional nonce, default 0
614
- * @returns Promise resolving to the predicted {@link Address}
615
- */
616
- abstract getWalletAddress(params: {
617
- owners: Array<Address | WebAuthnAccount>;
618
- nonce?: bigint;
619
- }): Promise<Address>;
620
- }
595
+ type GetSmartWalletOptions = {
596
+ signer: LocalAccount;
597
+ deploymentOwners?: Array<Address | WebAuthnAccount>;
598
+ signerOwnerIndex?: number;
599
+ walletAddress?: Address;
600
+ nonce?: bigint;
601
+ };
602
+ /**
603
+ * Options for retrieving an embedded wallet
604
+ * Parameters for getting an existing embedded wallet
605
+ */
606
+ type GetEmbeddedWalletOptions = {
607
+ walletId: string;
608
+ };
609
+ /**
610
+ * Options for retrieving a smart wallet with embedded wallet signer
611
+ * Parameters for getting an existing smart wallet using an embedded wallet as signer.
612
+ * If neither walletAddress nor deploymentOwners is provided, defaults to using the embedded wallet as single owner.
613
+ */
614
+ type GetAccountOptions = Omit<GetSmartWalletOptions, 'signer'> & GetEmbeddedWalletOptions;
615
+ /**
616
+ * Result of creating a unified web3 account in {@link WalletProvider.createAccount} and {@link WalletNamespace.createAccount}
617
+ */
618
+ type CreateAccountResult = {
619
+ embeddedWalletId: string;
620
+ smartWallet: SmartWallet;
621
+ };
621
622
 
622
623
  /**
623
624
  * Abstract base class for embedded wallet implementations
@@ -703,47 +704,71 @@ declare abstract class EmbeddedWalletProvider {
703
704
  }
704
705
 
705
706
  /**
706
- * Options for creating a smart wallet
707
- * Parameters for creating a new smart wallet with specified owners and signer
708
- */
709
- type CreateSmartWalletOptions = {
710
- owners: Array<Address | WebAuthnAccount>;
711
- signer: LocalAccount;
712
- nonce?: bigint;
713
- };
714
- /**
715
- * Options for creating a wallet with embedded signer
716
- * Parameters for creating both embedded and smart wallets, with embedded wallet automatically added as signer
717
- */
718
- type CreateWalletWithEmbeddedSignerOptions = {
719
- owners?: Array<Address | WebAuthnAccount>;
720
- embeddedWalletIndex?: number;
721
- nonce?: bigint;
722
- };
723
- /**
724
- * Options for retrieving a smart wallet with provided signer
725
- * Parameters for getting an existing smart wallet using a provided LocalAccount signer
726
- */
727
- type GetSmartWalletOptions = {
728
- signer: LocalAccount;
729
- deploymentOwners?: Array<Address | WebAuthnAccount>;
730
- signerOwnerIndex?: number;
731
- walletAddress?: Address;
732
- nonce?: bigint;
733
- };
734
- /**
735
- * Options for retrieving an embedded wallet
736
- * Parameters for getting an existing embedded wallet
737
- */
738
- type GetEmbeddedWalletOptions = {
739
- walletId: string;
740
- };
741
- /**
742
- * Options for retrieving a smart wallet with embedded wallet signer
743
- * Parameters for getting an existing smart wallet using an embedded wallet as signer.
744
- * If neither walletAddress nor deploymentOwners is provided, defaults to using the embedded wallet as single owner.
707
+ * Abstract base class for smart wallet providers
708
+ *
709
+ * @internal
710
+ * @category Wallet Providers
711
+ * @remarks
712
+ * Defines the interface for factories that create and manage {@link SmartWallet} instances
713
+ * Extended by implementations such as {@link DefaultSmartWalletProvider}
745
714
  */
746
- type GetSmartWalletWithEmbeddedSignerOptions = Omit<GetSmartWalletOptions, 'signer'> & GetEmbeddedWalletOptions;
715
+ declare abstract class SmartWalletProvider$1 {
716
+ /**
717
+ * Creates a new smart wallet instance that will be deployed on first transaction
718
+ *
719
+ * @internal
720
+ * @category Creation
721
+ * @remarks
722
+ * Address is calculated deterministically using owners and nonce
723
+ *
724
+ * @param params Wallet creation parameters
725
+ * @param params.owners Array of wallet owners (addresses or WebAuthn accounts)
726
+ * @param params.signer Local account used for signing
727
+ * @param params.nonce Optional nonce for address derivation, default 0
728
+ * @returns Promise resolving to a {@link SmartWallet} instance
729
+ */
730
+ abstract createWallet(params: {
731
+ owners: Array<Address | WebAuthnAccount>;
732
+ signer: LocalAccount;
733
+ nonce?: bigint;
734
+ }): Promise<SmartWallet>;
735
+ /**
736
+ * Returns a smart wallet instance for an already deployed contract
737
+ *
738
+ * @internal
739
+ * @category Retrieval
740
+ * @remarks
741
+ * Use when the wallet address is already known
742
+ *
743
+ * @param params Wallet retrieval parameters
744
+ * @param params.walletAddress Deployed smart wallet address
745
+ * @param params.signer Local account to operate the wallet
746
+ * @param params.ownerIndex Optional index of signer in the owners list, default 0
747
+ * @returns A {@link SmartWallet} instance
748
+ */
749
+ abstract getWallet(params: {
750
+ walletAddress: Address;
751
+ signer: LocalAccount;
752
+ ownerIndex?: number;
753
+ }): SmartWallet;
754
+ /**
755
+ * Predicts the deterministic address of a smart wallet
756
+ *
757
+ * @internal
758
+ * @category Addressing
759
+ * @remarks
760
+ * Uses CREATE2 with owners and nonce to calculate the wallet address
761
+ *
762
+ * @param params Prediction parameters
763
+ * @param params.owners Array of wallet owners (addresses or WebAuthn accounts)
764
+ * @param params.nonce Optional nonce, default 0
765
+ * @returns Promise resolving to the predicted {@link Address}
766
+ */
767
+ abstract getWalletAddress(params: {
768
+ owners: Array<Address | WebAuthnAccount>;
769
+ nonce?: bigint;
770
+ }): Promise<Address>;
771
+ }
747
772
 
748
773
  /**
749
774
  * Unified Wallet Provider class
@@ -821,9 +846,9 @@ declare class WalletProvider {
821
846
  * @param params.nonce Optional salt/nonce for deterministic address calculation (defaults to 0)
822
847
  * @returns Promise that resolves to the created {@link SmartWallet}
823
848
  */
824
- createWalletWithEmbeddedSigner(params?: CreateWalletWithEmbeddedSignerOptions): Promise<SmartWallet>;
849
+ createAccount(params?: CreateAccountOptions): Promise<CreateAccountResult>;
825
850
  /**
826
- * Gets a smart wallet using an embedded wallet as the signer
851
+ * Gets a unified web3 account: a smart wallet using an embedded wallet as the signer
827
852
  *
828
853
  * @internal
829
854
  * @remarks
@@ -840,7 +865,7 @@ declare class WalletProvider {
840
865
  * @returns Promise that resolves to the {@link SmartWallet}
841
866
  * @throws Error if the embedded wallet cannot be found
842
867
  */
843
- getSmartWalletWithEmbeddedSigner(params: GetSmartWalletWithEmbeddedSignerOptions): Promise<SmartWallet>;
868
+ getAccount(params: GetAccountOptions): Promise<SmartWallet>;
844
869
  /**
845
870
  * Gets an existing embedded wallet by ID
846
871
  *
@@ -873,22 +898,27 @@ declare class WalletProvider {
873
898
  }
874
899
 
875
900
  /**
876
- * Public wallet namespace that exposes unified wallet operations
901
+ * Wallet namespace to create and retrieve different wallet formats and overall web3 account
877
902
  *
878
903
  * @public
879
- * @category Wallets creation and retrieval
904
+ * @category 2. Accounts creation and retrieval
880
905
  * @remarks
881
- * This class is returned by {@link MyceliumSDK} and provides a simplified
882
- * interface for wallet creation and retrieval. Advanced functionality can be accessed through
883
- * the underlying providers via the getters {@link embeddedWalletProvider} and
884
- * {@link smartWalletProvider}
906
+ * This class is returned by {@link MyceliumSDK} and provides a methods to create and retrieve different wallet formats
907
+ * The common methods are:
908
+ * - {@link createAccount} which creates a unified account: a smart wallet with an embedded wallet as signer
909
+ * - {@link getAccount} which retrieves a unified account: a smart wallet using an embedded walletId
910
+ * More advanced option are also available
885
911
  *
886
- * Typical flows:
887
- * - Create embedded wallet only: {@link createEmbeddedWallet}
888
- * - Create smart wallet only (you provide signer/owners): {@link createSmartWallet}
889
- * - Create smart wallet with embedded as signer: {@link createWalletWithEmbeddedSigner}
890
- * - Get smart wallet using embedded as signer: {@link getSmartWalletWithEmbeddedSigner}
891
- * - Get smart wallet using a provided signer: {@link getSmartWallet}
912
+ * @example
913
+ * ```ts
914
+ * // Create a smart wallet and related embedded wallet
915
+ * const { embeddedWalletId, smartWallet } = await myceliumSDK.wallet.createAccount();
916
+ *
917
+ * // Get the smart wallet using the embedded walletId
918
+ * const smartWallet = await myceliumSDK.wallet.getAccount({
919
+ * embeddedWalletId,
920
+ * });
921
+ * ```
892
922
  */
893
923
  declare class WalletNamespace {
894
924
  /**
@@ -901,28 +931,6 @@ declare class WalletNamespace {
901
931
  * @param provider Unified provider that composes embedded & smart providers
902
932
  */
903
933
  constructor(provider: WalletProvider);
904
- /**
905
- * Direct access to the underlying embedded wallet provider
906
- *
907
- * @public
908
- * @category Providers
909
- * @remarks
910
- * Useful when you need advanced functionality beyond the unified namespace. By default, you should use the unified namespace
911
- *
912
- * @returns The configured embedded wallet provider instance
913
- */
914
- get embeddedWalletProvider(): EmbeddedWalletProvider;
915
- /**
916
- * Direct access to the underlying smart wallet provider
917
- *
918
- * @public
919
- * @category Providers
920
- * @remarks
921
- * Useful when you need advanced functionality beyond the unified namespace. By default, you should use the unified namespace
922
- *
923
- * @returns The configured smart wallet provider instance
924
- */
925
- get smartWalletProvider(): SmartWalletProvider$1;
926
934
  /**
927
935
  * Creates an embedded wallet
928
936
  *
@@ -951,7 +959,7 @@ declare class WalletNamespace {
951
959
  */
952
960
  createSmartWallet(params: CreateSmartWalletOptions): Promise<SmartWallet>;
953
961
  /**
954
- * Creates a smart wallet with an embedded wallet as signer
962
+ * A unified a web3 account: creates a smart wallet with an embedded wallet as signer
955
963
  *
956
964
  * @public
957
965
  * @category Creation
@@ -965,9 +973,9 @@ declare class WalletNamespace {
965
973
  * @param params.nonce Optional nonce/salt for deterministic address generation (defaults to 0)
966
974
  * @returns Promise that resolves to the created {@link SmartWallet}
967
975
  */
968
- createWalletWithEmbeddedSigner(params?: CreateWalletWithEmbeddedSignerOptions): Promise<SmartWallet>;
976
+ createAccount(params?: CreateAccountOptions): Promise<CreateAccountResult>;
969
977
  /**
970
- * Gets a smart wallet using an embedded wallet as the signer
978
+ * Gets a unified web3 account: a smart wallet using an embedded wallet as the signer
971
979
  *
972
980
  * @public
973
981
  * @category Retrieval
@@ -985,7 +993,7 @@ declare class WalletNamespace {
985
993
  * @returns Promise that resolves to the {@link SmartWallet}
986
994
  * @throws Error if the embedded wallet cannot be found
987
995
  */
988
- getSmartWalletWithEmbeddedSigner(params: GetSmartWalletWithEmbeddedSignerOptions): Promise<SmartWallet>;
996
+ getAccount(params: GetAccountOptions): Promise<SmartWallet>;
989
997
  /**
990
998
  * Gets an existing embedded wallet by ID
991
999
  *
@@ -1018,6 +1026,22 @@ declare class WalletNamespace {
1018
1026
  getSmartWallet(params: GetSmartWalletOptions): Promise<SmartWallet>;
1019
1027
  }
1020
1028
 
1029
+ /**
1030
+ * Protocol namespace to manage protocol related operations, e.g. get best vaults
1031
+ * @public
1032
+ * @category Protocols
1033
+ */
1034
+ declare class ProtocolsNamespace {
1035
+ private protocol;
1036
+ constructor(protocol: BaseProtocol);
1037
+ /**
1038
+ * Find the best vaults for protocols that were selected based on integrator's settings
1039
+ *
1040
+ * @returns Best vaults for protocols that were selected based on integrator's settings
1041
+ */
1042
+ getBestVaults(stableVaultsLimit?: number, nonStableVaultsLimit?: number): Promise<Vaults>;
1043
+ }
1044
+
1021
1045
  /**
1022
1046
  * Mycelium SDK configuration
1023
1047
  * Configuration object for initializing the Mycelium SDK
@@ -1080,7 +1104,7 @@ interface MyceliumSDKConfig {
1080
1104
  * @remarks
1081
1105
  * If an integrator is not provided any requirements, `low` risk level protocols will be used by default
1082
1106
  */
1083
- protocolsRouterConfig?: ProtocolsRouterConfig;
1107
+ protocolsSecurityConfig?: ProtocolsSecurityConfig;
1084
1108
  /**
1085
1109
  * Coinbase CDP configuration
1086
1110
  * @remarks
@@ -1091,6 +1115,15 @@ interface MyceliumSDKConfig {
1091
1115
  */
1092
1116
  coinbaseCDPConfig?: CoinbaseCDPConfig;
1093
1117
  }
1118
+ /**
1119
+ * Basic Mycelium SDK configuration for a case when a user provided only API key without advanced configurations
1120
+ */
1121
+ interface BasicMyceliumSDKConfig {
1122
+ apiKey: string;
1123
+ chainId?: number;
1124
+ protocolsSecurityConfig: ProtocolsSecurityConfig;
1125
+ overrides?: Partial<MyceliumSDKConfig>;
1126
+ }
1094
1127
  /**
1095
1128
  * Coinbase CDP configuration
1096
1129
  * Configuration for Coinbase CDP API
@@ -1245,7 +1278,7 @@ declare class CoinbaseCDP {
1245
1278
  * Default ERC-4337 smart wallet implementation. Implements main methods that a user can use to interact with DeFi protocols and use all related functionalities
1246
1279
  *
1247
1280
  * @public
1248
- * @category Wallets operations
1281
+ * @category 3. Account operations
1249
1282
  * @remarks
1250
1283
  * Backed by Coinbase Smart Account and compatible with ERC-4337 UserOperations
1251
1284
  * Supports multi-owner wallets (EVM addresses or WebAuthn owners), gas-sponsored flows,
@@ -1280,7 +1313,8 @@ declare class DefaultSmartWallet extends SmartWallet {
1280
1313
  * @param signerOwnerIndex Optional index of `signer` in owners (default 0)
1281
1314
  * @param nonce Optional salt for deterministic address calc (default 0)
1282
1315
  */
1283
- constructor(owners: Array<Address | WebAuthnAccount>, signer: LocalAccount, chainManager: ChainManager, protocolProvider: Protocol['instance'], coinbaseCDP: CoinbaseCDP | null, deploymentAddress?: Address, signerOwnerIndex?: number, nonce?: bigint);
1316
+ constructor(owners: Array<Address | WebAuthnAccount>, signer: LocalAccount, chainManager: ChainManager, protocolProvider: BaseProtocol, // Protocol['instance'],
1317
+ coinbaseCDP: CoinbaseCDP | null, deploymentAddress?: Address, signerOwnerIndex?: number, nonce?: bigint);
1284
1318
  /**
1285
1319
  * Returns the signer account for this smart wallet
1286
1320
  *
@@ -1330,7 +1364,7 @@ declare class DefaultSmartWallet extends SmartWallet {
1330
1364
  * @param amount Human-readable amount string
1331
1365
  * @returns Transaction result for the deposit
1332
1366
  */
1333
- earn(amount: string): Promise<VaultTxnResult>;
1367
+ earn(vaultInfo: VaultInfo, amount: string): Promise<VaultTxnResult>;
1334
1368
  /**
1335
1369
  * Reads current deposit balance from the selected protocol’s vault
1336
1370
  * Method to read the current deposit balance from the selected protocol’s vault for a smart account
@@ -1339,7 +1373,7 @@ declare class DefaultSmartWallet extends SmartWallet {
1339
1373
  * @category Earn
1340
1374
  * @returns Vault balance or `null` if nothing deposited
1341
1375
  */
1342
- getEarnBalance(): Promise<VaultBalance | null>;
1376
+ getEarnBalances(): Promise<VaultBalance[]>;
1343
1377
  /**
1344
1378
  * Withdraws from the selected protocol’s vault
1345
1379
  * @public
@@ -1349,7 +1383,7 @@ declare class DefaultSmartWallet extends SmartWallet {
1349
1383
  * @throws Error if the withdrawal fails
1350
1384
  * @throws Error a user didn't deposit anything
1351
1385
  */
1352
- withdraw(amount: string): Promise<VaultTxnResult>;
1386
+ withdraw(vaultInfo: VaultInfo, amount: string): Promise<VaultTxnResult>;
1353
1387
  /**
1354
1388
  * Builds a UserOperation and submits via the bundler, then waits for inclusion
1355
1389
 
@@ -1379,7 +1413,7 @@ declare class DefaultSmartWallet extends SmartWallet {
1379
1413
  * Funds the smart wallet with the specified amount of the specified token via Coinbase CDP on-ramp service
1380
1414
  *
1381
1415
  * @public
1382
- * @category Ramp
1416
+ * @category Funding
1383
1417
  *
1384
1418
  * @remarks
1385
1419
  * If Coinbase CDP is not initialized, the method will throw an error. For more details, visit @see {@link https://docs.cdp.coinbase.com/api-reference/v2/rest-api/onramp/create-an-onramp-session}
@@ -1400,7 +1434,7 @@ declare class DefaultSmartWallet extends SmartWallet {
1400
1434
  * Cashout token from smart wallet to fiat currency via Coinbase CDP off-ramp service
1401
1435
  *
1402
1436
  * @public
1403
- * @category Ramp
1437
+ * @category Funding
1404
1438
  *
1405
1439
  * @remarks
1406
1440
  * If Coinbase CDP is not initialized, the method will throw an error. For more details, visit @see {@link https://docs.cdp.coinbase.com/api-reference/rest-api/onramp-offramp/create-sell-quote}
@@ -1431,49 +1465,116 @@ declare class DefaultSmartWallet extends SmartWallet {
1431
1465
  sendTokens(amount: number, asset: AssetIdentifier, recipientAddress: Address): Promise<TransactionData>;
1432
1466
  }
1433
1467
 
1468
+ /**
1469
+ * Namespace to manage funding & payouts of an account
1470
+ * @public
1471
+ * @remarks
1472
+ * Contains 2 methods to get available options to top up an account and cash out funds
1473
+ * - {@link getTopUpConfig} to get available options to top up an account
1474
+ * - {@link getCashOutConfig} to get available options to cash out funds
1475
+ *
1476
+ * @example
1477
+ * ```ts
1478
+ * const topUpConfig = await myceliumSDK.funding.getTopUpConfig();
1479
+ * const cashOutConfig = await myceliumSDK.funding.getCashOutConfig();
1480
+ * ```
1481
+ * @category 4. Funding & payouts
1482
+ */
1483
+ declare class FundingNamespace {
1484
+ private readonly coinbaseCDP;
1485
+ constructor(coinbaseCDP: CoinbaseCDP);
1486
+ /**
1487
+ * Return all supported countries and payment methods for on-ramp by Coinbase CDP
1488
+ * @public
1489
+ * @category Funding
1490
+ *
1491
+ * @returns @see {@link RampConfigResponse} with supported countries and payment methods for top-up
1492
+ * @throws If API returned an error
1493
+ */
1494
+ getTopUpConfig(): Promise<RampConfigResponse>;
1495
+ /**
1496
+ * Return all supported countries and payment methods for off-ramp by Coinbase CDP
1497
+ * @public
1498
+ * @category Funding
1499
+ *
1500
+ *
1501
+ * @returns @see {@link RampConfigResponse} with supported countries and payment methods for cash out
1502
+ * @throws If API returned an error
1503
+ */
1504
+ getCashOutConfig(): Promise<RampConfigResponse>;
1505
+ }
1506
+
1507
+ /**
1508
+ * @packageDocumentation
1509
+ * Entry point for the Mycelium SDK
1510
+ *
1511
+ * Exports stable types and the main SDK facade (`MyceliumSDK`)
1512
+ * Internal base classes and implementations are not part of the public API
1513
+ * and are hidden from public documentation
1514
+ */
1515
+
1434
1516
  /**
1435
1517
  * Main SDK facade for integrating wallets and protocols.
1436
1518
  *
1437
1519
  * @public
1438
- * @category Get started
1520
+ * @category 1. Getting started
1439
1521
  * @remarks
1440
1522
  * This class encapsulates:
1441
- * - protocol selection and initialization (`Smart Router`),
1523
+ * - protocol selection and initialization
1442
1524
  * - chain/network management (`ChainManager`),
1443
1525
  * - public wallet namespace (accessible through {@link MyceliumSDK.wallet | wallet}).
1444
1526
  *
1445
1527
  * By default, if no chain config is provided, it uses the public RPC
1446
1528
  * and Bundler for the Base chain
1447
1529
  *
1530
+ * The SDK can be initialized in two ways:
1531
+ * 1. With an API key - fetches configuration from backend automatically
1532
+ * 2. With full configuration - uses provided configuration directly
1533
+ *
1448
1534
  * @example
1449
- * ```ts
1450
- * import { MyceliumSDK, type MyceliumSDKConfig } from '@mycelium-sdk/core';
1451
1535
  *
1536
+ * import { MyceliumSDK, type MyceliumSDKConfig, type BasicMyceliumSDKConfig } from '@mycelium-sdk/core';
1537
+ *
1538
+ * // Option 1: Initialize with API key (fetches config from backend)
1539
+ * const sdk = await MyceliumSDK.init({
1540
+ * apiKey: 'sk_...'
1541
+ * });
1542
+ *
1543
+ * // Option 2: Initialize with full configuration
1452
1544
  * const config: MyceliumSDKConfig = {
1453
1545
  * walletsConfig: { /* ... *\/ },
1454
- * protocolsRouterConfig: { /* ... *\/ },
1546
+ * protocolsSecurityConfig: { riskLevel: 'low' },
1455
1547
  * chain: { /* ... *\/ },
1456
1548
  * coinbaseCDPConfig: { /* ... *\/ },
1457
1549
  * integratorId: 'MyceliumApp',
1458
1550
  * };
1551
+ * const sdk = await MyceliumSDK.init(config);
1459
1552
  *
1460
- * const sdk = new MyceliumSDK(config);
1461
- *
1462
- * const embeddedWallet = await sdk.wallet.createEmbeddedWallet();
1463
- * const wallet = await sdk.wallet.createSmartWallet({
1464
- * owners: [embeddedWallet.address],
1465
- * signer: await embeddedWallet.account(),
1466
- * })
1467
- * const balance = await wallet.getBalance();
1468
- * ```
1469
- */
1553
+ * const {embeddedWalletId, smartWallet} = await sdk.wallet.createAccount();
1554
+ * const balance = await smartWallet.getBalance();
1555
+ * */
1470
1556
  declare class MyceliumSDK {
1471
1557
  /**
1472
- * Unified wallet namespace to manage embedded/smart wallets and related operations
1558
+ * Returns a unified wallet namespace to manage embedded/smart wallets and related operations
1473
1559
  * @public
1474
1560
  * @category Wallets
1475
1561
  */
1476
1562
  readonly wallet: WalletNamespace;
1563
+ /**
1564
+ * Protocol namespace to manage protocol related operations
1565
+ * @public
1566
+ * @category Protocols
1567
+ */
1568
+ readonly protocols: ProtocolsNamespace;
1569
+ /**
1570
+ * Ramp namespace to manage ramp operations. Methods are available on {@link RampNamespace}
1571
+ * @internal
1572
+ * @remarks
1573
+ * If the Coinbase CDP configuration is not provided, the ramp functionality will be disabled.
1574
+ * Calling the respective method will throw an error
1575
+ * @category Tools
1576
+ */
1577
+ readonly fundingNamespace: FundingNamespace | null;
1477
1578
  /**
1478
1579
  * Chain manager instance to manage chain related entities
1479
1580
  * @internal
@@ -1488,6 +1589,8 @@ declare class MyceliumSDK {
1488
1589
  * @internal
1489
1590
  */
1490
1591
  private protocol;
1592
+ /** API client for the backend API */
1593
+ apiClient: ApiClient | undefined;
1491
1594
  /**
1492
1595
  * Coinbase CDP instance to Coinbase related and onchain operations using Coinbase CDP API
1493
1596
  * @remarks
@@ -1496,6 +1599,12 @@ declare class MyceliumSDK {
1496
1599
  * @internal
1497
1600
  */
1498
1601
  private coinbaseCDP;
1602
+ /**
1603
+ * Initializes the SDK
1604
+ * @param config SDK configuration (networks, wallets, protocol router settings)
1605
+ * @returns SDK instance
1606
+ */
1607
+ static init(config: BasicMyceliumSDKConfig | MyceliumSDKConfig): Promise<MyceliumSDK>;
1499
1608
  /**
1500
1609
  * Creates a new SDK instance
1501
1610
  *
@@ -1503,41 +1612,27 @@ declare class MyceliumSDK {
1503
1612
  * @throws Throws if an unsupported wallet provider is given
1504
1613
  * @see MyceliumSDKConfig
1505
1614
  */
1506
- constructor(config: MyceliumSDKConfig);
1615
+ constructor(config: MyceliumSDKConfig, isPremiumAvailable: boolean, apiClient?: ApiClient);
1507
1616
  /**
1508
1617
  * Returns the chain manager instance for multi-chain operations
1509
1618
  * @public
1619
+ * @remarks
1620
+ * More about methods in {@link ChainManager}
1510
1621
  * @category Tools
1511
1622
  *
1512
1623
  * @returns ChainManager instance of the type {@link ChainManager}
1513
1624
  */
1514
1625
  get chainManager(): ChainManager;
1515
1626
  /**
1516
- * Coinbase CDP configuration methods for ramp operations
1627
+ * Returns a funding namespace to manage top ups & cash outs configurations
1517
1628
  * @public
1629
+ * @remarks
1630
+ * More about methods in {@link FundingNamespace}
1518
1631
  * @category Tools
1632
+ *
1633
+ * @returns Funding namespace of the type {@link FundingNamespace}
1519
1634
  */
1520
- readonly rampConfig: {
1521
- /**
1522
- * Return all supported countries and payment methods for on-ramp by Coinbase CDP
1523
- * @public
1524
- * @category Ramp
1525
- *
1526
- * @returns @see {@link RampConfigResponse} with supported countries and payment methods for top-up
1527
- * @throws If API returned an error
1528
- */
1529
- getTopUpConfig: () => Promise<RampConfigResponse>;
1530
- /**
1531
- * Return all supported countries and payment methods for off-ramp by Coinbase CDP
1532
- * @public
1533
- * @category Ramp
1534
- *
1535
- *
1536
- * @returns @see {@link RampConfigResponse} with supported countries and payment methods for cash out
1537
- * @throws If API returned an error
1538
- */
1539
- getCashOutConfig: () => Promise<RampConfigResponse>;
1540
- };
1635
+ get funding(): FundingNamespace;
1541
1636
  /**
1542
1637
  * Recommends and initializes a protocol based on router settings
1543
1638
  *
@@ -1545,7 +1640,7 @@ declare class MyceliumSDK {
1545
1640
  * @param config Protocol router configuration (e.g. risk level)
1546
1641
  * @returns Selected protocol object of the type {@link Protocol}
1547
1642
  */
1548
- private findProtocol;
1643
+ private selectProtocol;
1549
1644
  /**
1550
1645
  * Creates a wallet provider (embedded + smart) and combines them
1551
1646
  *
@@ -1565,4 +1660,4 @@ declare class MyceliumSDK {
1565
1660
  private createWalletNamespace;
1566
1661
  }
1567
1662
 
1568
- export { type OffRampUrlResponse as CashOutUrlResponse, DefaultSmartWallet, EmbeddedWallet, MyceliumSDK, type MyceliumSDKConfig, type RampConfigResponse, SmartWallet, type SparkVaultBalance, type SparkVaultTxnResult, type TokenBalance, type OnRampUrlResponse as TopUpUrlResponse, type VaultBalance, type VaultTxnResult, WalletNamespace };
1663
+ export { type OffRampUrlResponse as CashOutUrlResponse, DefaultSmartWallet, EmbeddedWallet, FundingNamespace, type RampConfigResponse as FundingOptionsResponse, MyceliumSDK, type MyceliumSDKConfig, ProtocolsNamespace, type ProxyBalance, SmartWallet, type TokenBalance, type OnRampUrlResponse as TopUpUrlResponse, type VaultBalance, type VaultInfo, type VaultTxnResult, type Vaults, WalletNamespace };