@mycelium-sdk/core 1.0.0-alpha.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/README.md +190 -49
- package/dist/index.cjs +618 -278
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +194 -128
- package/dist/index.d.ts +194 -128
- package/dist/index.js +619 -284
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
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
|
|
367
|
-
/**
|
|
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
|
|
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<
|
|
452
|
+
abstract deposit(vaultInfo: VaultInfo, amount: string, smartWallet: SmartWallet): Promise<VaultTxnResult>;
|
|
402
453
|
/**
|
|
403
454
|
* Withdraw funds from a vault
|
|
404
|
-
* @param
|
|
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<
|
|
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
|
|
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
|
|
492
|
+
interface ProtocolsSecurityConfig {
|
|
460
493
|
riskLevel: 'low' | 'medium' | 'high';
|
|
461
|
-
minApy?: number;
|
|
462
|
-
apiKey?: string;
|
|
463
494
|
}
|
|
464
495
|
/**
|
|
465
|
-
* @
|
|
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
|
-
|
|
474
|
-
chainId?: number;
|
|
475
|
-
depositTokenAddress: Address;
|
|
476
|
-
depositTokenDecimals: number;
|
|
477
|
-
depositTokenSymbol?: string;
|
|
504
|
+
protocolId: string;
|
|
478
505
|
vaultAddress: Address;
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
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
|
-
|
|
533
|
+
balance: string | ProxyBalance | null;
|
|
496
534
|
/** info about a protocol vault where a user deposited funds */
|
|
497
535
|
vaultInfo: VaultInfo;
|
|
498
536
|
}
|
|
@@ -512,44 +550,24 @@ interface VaultTxnResult {
|
|
|
512
550
|
error?: string;
|
|
513
551
|
}
|
|
514
552
|
|
|
515
|
-
interface
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
success: boolean;
|
|
534
|
-
/** hash of the operation */
|
|
535
|
-
hash: string;
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
* @public
|
|
539
|
-
* The info about current user's balance in a Spark vault
|
|
540
|
-
* @category Types
|
|
541
|
-
*/
|
|
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
|
+
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;
|
|
553
571
|
}
|
|
554
572
|
|
|
555
573
|
/**
|
|
@@ -1008,6 +1026,22 @@ declare class WalletNamespace {
|
|
|
1008
1026
|
getSmartWallet(params: GetSmartWalletOptions): Promise<SmartWallet>;
|
|
1009
1027
|
}
|
|
1010
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
|
+
|
|
1011
1045
|
/**
|
|
1012
1046
|
* Mycelium SDK configuration
|
|
1013
1047
|
* Configuration object for initializing the Mycelium SDK
|
|
@@ -1070,7 +1104,7 @@ interface MyceliumSDKConfig {
|
|
|
1070
1104
|
* @remarks
|
|
1071
1105
|
* If an integrator is not provided any requirements, `low` risk level protocols will be used by default
|
|
1072
1106
|
*/
|
|
1073
|
-
|
|
1107
|
+
protocolsSecurityConfig?: ProtocolsSecurityConfig;
|
|
1074
1108
|
/**
|
|
1075
1109
|
* Coinbase CDP configuration
|
|
1076
1110
|
* @remarks
|
|
@@ -1081,6 +1115,15 @@ interface MyceliumSDKConfig {
|
|
|
1081
1115
|
*/
|
|
1082
1116
|
coinbaseCDPConfig?: CoinbaseCDPConfig;
|
|
1083
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
|
+
}
|
|
1084
1127
|
/**
|
|
1085
1128
|
* Coinbase CDP configuration
|
|
1086
1129
|
* Configuration for Coinbase CDP API
|
|
@@ -1270,7 +1313,8 @@ declare class DefaultSmartWallet extends SmartWallet {
|
|
|
1270
1313
|
* @param signerOwnerIndex Optional index of `signer` in owners (default 0)
|
|
1271
1314
|
* @param nonce Optional salt for deterministic address calc (default 0)
|
|
1272
1315
|
*/
|
|
1273
|
-
constructor(owners: Array<Address | WebAuthnAccount>, signer: LocalAccount, chainManager: ChainManager, protocolProvider: Protocol['instance'],
|
|
1316
|
+
constructor(owners: Array<Address | WebAuthnAccount>, signer: LocalAccount, chainManager: ChainManager, protocolProvider: BaseProtocol, // Protocol['instance'],
|
|
1317
|
+
coinbaseCDP: CoinbaseCDP | null, deploymentAddress?: Address, signerOwnerIndex?: number, nonce?: bigint);
|
|
1274
1318
|
/**
|
|
1275
1319
|
* Returns the signer account for this smart wallet
|
|
1276
1320
|
*
|
|
@@ -1320,7 +1364,7 @@ declare class DefaultSmartWallet extends SmartWallet {
|
|
|
1320
1364
|
* @param amount Human-readable amount string
|
|
1321
1365
|
* @returns Transaction result for the deposit
|
|
1322
1366
|
*/
|
|
1323
|
-
earn(amount: string): Promise<VaultTxnResult>;
|
|
1367
|
+
earn(vaultInfo: VaultInfo, amount: string): Promise<VaultTxnResult>;
|
|
1324
1368
|
/**
|
|
1325
1369
|
* Reads current deposit balance from the selected protocol’s vault
|
|
1326
1370
|
* Method to read the current deposit balance from the selected protocol’s vault for a smart account
|
|
@@ -1329,7 +1373,7 @@ declare class DefaultSmartWallet extends SmartWallet {
|
|
|
1329
1373
|
* @category Earn
|
|
1330
1374
|
* @returns Vault balance or `null` if nothing deposited
|
|
1331
1375
|
*/
|
|
1332
|
-
|
|
1376
|
+
getEarnBalances(): Promise<VaultBalance[]>;
|
|
1333
1377
|
/**
|
|
1334
1378
|
* Withdraws from the selected protocol’s vault
|
|
1335
1379
|
* @public
|
|
@@ -1339,7 +1383,7 @@ declare class DefaultSmartWallet extends SmartWallet {
|
|
|
1339
1383
|
* @throws Error if the withdrawal fails
|
|
1340
1384
|
* @throws Error a user didn't deposit anything
|
|
1341
1385
|
*/
|
|
1342
|
-
withdraw(amount: string): Promise<VaultTxnResult>;
|
|
1386
|
+
withdraw(vaultInfo: VaultInfo, amount: string): Promise<VaultTxnResult>;
|
|
1343
1387
|
/**
|
|
1344
1388
|
* Builds a UserOperation and submits via the bundler, then waits for inclusion
|
|
1345
1389
|
|
|
@@ -1476,31 +1520,39 @@ declare class FundingNamespace {
|
|
|
1476
1520
|
* @category 1. Getting started
|
|
1477
1521
|
* @remarks
|
|
1478
1522
|
* This class encapsulates:
|
|
1479
|
-
* - protocol selection and initialization
|
|
1523
|
+
* - protocol selection and initialization
|
|
1480
1524
|
* - chain/network management (`ChainManager`),
|
|
1481
1525
|
* - public wallet namespace (accessible through {@link MyceliumSDK.wallet | wallet}).
|
|
1482
1526
|
*
|
|
1483
1527
|
* By default, if no chain config is provided, it uses the public RPC
|
|
1484
1528
|
* and Bundler for the Base chain
|
|
1485
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
|
+
*
|
|
1486
1534
|
* @example
|
|
1487
|
-
* ```ts
|
|
1488
|
-
* import { MyceliumSDK, type MyceliumSDKConfig } from '@mycelium-sdk/core';
|
|
1489
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
|
|
1490
1544
|
* const config: MyceliumSDKConfig = {
|
|
1491
1545
|
* walletsConfig: { /* ... *\/ },
|
|
1492
|
-
*
|
|
1546
|
+
* protocolsSecurityConfig: { riskLevel: 'low' },
|
|
1493
1547
|
* chain: { /* ... *\/ },
|
|
1494
1548
|
* coinbaseCDPConfig: { /* ... *\/ },
|
|
1495
1549
|
* integratorId: 'MyceliumApp',
|
|
1496
1550
|
* };
|
|
1497
|
-
*
|
|
1498
|
-
* const sdk = new MyceliumSDK(config);
|
|
1551
|
+
* const sdk = await MyceliumSDK.init(config);
|
|
1499
1552
|
*
|
|
1500
1553
|
* const {embeddedWalletId, smartWallet} = await sdk.wallet.createAccount();
|
|
1501
1554
|
* const balance = await smartWallet.getBalance();
|
|
1502
|
-
*
|
|
1503
|
-
*/
|
|
1555
|
+
* */
|
|
1504
1556
|
declare class MyceliumSDK {
|
|
1505
1557
|
/**
|
|
1506
1558
|
* Returns a unified wallet namespace to manage embedded/smart wallets and related operations
|
|
@@ -1508,6 +1560,12 @@ declare class MyceliumSDK {
|
|
|
1508
1560
|
* @category Wallets
|
|
1509
1561
|
*/
|
|
1510
1562
|
readonly wallet: WalletNamespace;
|
|
1563
|
+
/**
|
|
1564
|
+
* Protocol namespace to manage protocol related operations
|
|
1565
|
+
* @public
|
|
1566
|
+
* @category Protocols
|
|
1567
|
+
*/
|
|
1568
|
+
readonly protocols: ProtocolsNamespace;
|
|
1511
1569
|
/**
|
|
1512
1570
|
* Ramp namespace to manage ramp operations. Methods are available on {@link RampNamespace}
|
|
1513
1571
|
* @internal
|
|
@@ -1531,6 +1589,8 @@ declare class MyceliumSDK {
|
|
|
1531
1589
|
* @internal
|
|
1532
1590
|
*/
|
|
1533
1591
|
private protocol;
|
|
1592
|
+
/** API client for the backend API */
|
|
1593
|
+
apiClient: ApiClient | undefined;
|
|
1534
1594
|
/**
|
|
1535
1595
|
* Coinbase CDP instance to Coinbase related and onchain operations using Coinbase CDP API
|
|
1536
1596
|
* @remarks
|
|
@@ -1539,6 +1599,12 @@ declare class MyceliumSDK {
|
|
|
1539
1599
|
* @internal
|
|
1540
1600
|
*/
|
|
1541
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>;
|
|
1542
1608
|
/**
|
|
1543
1609
|
* Creates a new SDK instance
|
|
1544
1610
|
*
|
|
@@ -1546,7 +1612,7 @@ declare class MyceliumSDK {
|
|
|
1546
1612
|
* @throws Throws if an unsupported wallet provider is given
|
|
1547
1613
|
* @see MyceliumSDKConfig
|
|
1548
1614
|
*/
|
|
1549
|
-
constructor(config: MyceliumSDKConfig);
|
|
1615
|
+
constructor(config: MyceliumSDKConfig, isPremiumAvailable: boolean, apiClient?: ApiClient);
|
|
1550
1616
|
/**
|
|
1551
1617
|
* Returns the chain manager instance for multi-chain operations
|
|
1552
1618
|
* @public
|
|
@@ -1574,7 +1640,7 @@ declare class MyceliumSDK {
|
|
|
1574
1640
|
* @param config Protocol router configuration (e.g. risk level)
|
|
1575
1641
|
* @returns Selected protocol object of the type {@link Protocol}
|
|
1576
1642
|
*/
|
|
1577
|
-
private
|
|
1643
|
+
private selectProtocol;
|
|
1578
1644
|
/**
|
|
1579
1645
|
* Creates a wallet provider (embedded + smart) and combines them
|
|
1580
1646
|
*
|
|
@@ -1594,4 +1660,4 @@ declare class MyceliumSDK {
|
|
|
1594
1660
|
private createWalletNamespace;
|
|
1595
1661
|
}
|
|
1596
1662
|
|
|
1597
|
-
export { type OffRampUrlResponse as CashOutUrlResponse, DefaultSmartWallet, EmbeddedWallet, FundingNamespace, type RampConfigResponse as FundingOptionsResponse, MyceliumSDK, type MyceliumSDKConfig,
|
|
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 };
|