@mycelium-sdk/core 0.1.0 → 1.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.js CHANGED
@@ -461,7 +461,7 @@ var DefaultSmartWallet = class extends SmartWallet {
461
461
  * Funds the smart wallet with the specified amount of the specified token via Coinbase CDP on-ramp service
462
462
  *
463
463
  * @public
464
- * @category Ramp
464
+ * @category Funding
465
465
  *
466
466
  * @remarks
467
467
  * 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}
@@ -499,7 +499,7 @@ var DefaultSmartWallet = class extends SmartWallet {
499
499
  * Cashout token from smart wallet to fiat currency via Coinbase CDP off-ramp service
500
500
  *
501
501
  * @public
502
- * @category Ramp
502
+ * @category Funding
503
503
  *
504
504
  * @remarks
505
505
  * 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}
@@ -575,6 +575,42 @@ var DefaultSmartWallet = class extends SmartWallet {
575
575
  }
576
576
  };
577
577
 
578
+ // src/ramp/FundingNamespace.ts
579
+ var FundingNamespace = class {
580
+ constructor(coinbaseCDP) {
581
+ this.coinbaseCDP = null;
582
+ if (!coinbaseCDP) {
583
+ throw new Error(
584
+ "Coinbase CDP is not initialized. Please, provide the configuration in the SDK initialization"
585
+ );
586
+ }
587
+ this.coinbaseCDP = coinbaseCDP;
588
+ }
589
+ /**
590
+ * Return all supported countries and payment methods for on-ramp by Coinbase CDP
591
+ * @public
592
+ * @category Funding
593
+ *
594
+ * @returns @see {@link RampConfigResponse} with supported countries and payment methods for top-up
595
+ * @throws If API returned an error
596
+ */
597
+ async getTopUpConfig() {
598
+ return await this.coinbaseCDP.getOnRampConfig();
599
+ }
600
+ /**
601
+ * Return all supported countries and payment methods for off-ramp by Coinbase CDP
602
+ * @public
603
+ * @category Funding
604
+ *
605
+ *
606
+ * @returns @see {@link RampConfigResponse} with supported countries and payment methods for cash out
607
+ * @throws If API returned an error
608
+ */
609
+ async getCashOutConfig() {
610
+ return await this.coinbaseCDP.getOffRampConfig();
611
+ }
612
+ };
613
+
578
614
  // src/tools/ChainManager.ts
579
615
  import { createPublicClient, http } from "viem";
580
616
  import {
@@ -882,32 +918,6 @@ var WalletNamespace = class {
882
918
  constructor(provider) {
883
919
  this.provider = provider;
884
920
  }
885
- /**
886
- * Direct access to the underlying embedded wallet provider
887
- *
888
- * @public
889
- * @category Providers
890
- * @remarks
891
- * Useful when you need advanced functionality beyond the unified namespace. By default, you should use the unified namespace
892
- *
893
- * @returns The configured embedded wallet provider instance
894
- */
895
- get embeddedWalletProvider() {
896
- return this.provider.embeddedWalletProvider;
897
- }
898
- /**
899
- * Direct access to the underlying smart wallet provider
900
- *
901
- * @public
902
- * @category Providers
903
- * @remarks
904
- * Useful when you need advanced functionality beyond the unified namespace. By default, you should use the unified namespace
905
- *
906
- * @returns The configured smart wallet provider instance
907
- */
908
- get smartWalletProvider() {
909
- return this.provider.smartWalletProvider;
910
- }
911
921
  /**
912
922
  * Creates an embedded wallet
913
923
  *
@@ -940,7 +950,7 @@ var WalletNamespace = class {
940
950
  return this.provider.createSmartWallet(params);
941
951
  }
942
952
  /**
943
- * Creates a smart wallet with an embedded wallet as signer
953
+ * A unified a web3 account: creates a smart wallet with an embedded wallet as signer
944
954
  *
945
955
  * @public
946
956
  * @category Creation
@@ -954,11 +964,11 @@ var WalletNamespace = class {
954
964
  * @param params.nonce Optional nonce/salt for deterministic address generation (defaults to 0)
955
965
  * @returns Promise that resolves to the created {@link SmartWallet}
956
966
  */
957
- async createWalletWithEmbeddedSigner(params) {
958
- return this.provider.createWalletWithEmbeddedSigner(params);
967
+ async createAccount(params) {
968
+ return this.provider.createAccount(params);
959
969
  }
960
970
  /**
961
- * Gets a smart wallet using an embedded wallet as the signer
971
+ * Gets a unified web3 account: a smart wallet using an embedded wallet as the signer
962
972
  *
963
973
  * @public
964
974
  * @category Retrieval
@@ -976,8 +986,8 @@ var WalletNamespace = class {
976
986
  * @returns Promise that resolves to the {@link SmartWallet}
977
987
  * @throws Error if the embedded wallet cannot be found
978
988
  */
979
- async getSmartWalletWithEmbeddedSigner(params) {
980
- return this.provider.getSmartWalletWithEmbeddedSigner(params);
989
+ async getAccount(params) {
990
+ return this.provider.getAccount(params);
981
991
  }
982
992
  /**
983
993
  * Gets an existing embedded wallet by ID
@@ -1133,18 +1143,6 @@ var DefaultSmartWalletProvider = class extends SmartWalletProvider {
1133
1143
  ownerIndex
1134
1144
  );
1135
1145
  }
1136
- /**
1137
- * Funds a wallet via a faucet if supported by the selected chain
1138
- *
1139
- * @internal
1140
- * @category Funding
1141
- * @remarks
1142
- * Placeholder for testnet faucet integration
1143
- *
1144
- * @returns Future transaction hash or provider response
1145
- */
1146
- fundViaFaucet() {
1147
- }
1148
1146
  };
1149
1147
 
1150
1148
  // src/wallet/WalletProvider.ts
@@ -1208,9 +1206,12 @@ var WalletProvider = class {
1208
1206
  * @param params.nonce Optional salt/nonce for deterministic address calculation (defaults to 0)
1209
1207
  * @returns Promise that resolves to the created {@link SmartWallet}
1210
1208
  */
1211
- async createWalletWithEmbeddedSigner(params) {
1209
+ async createAccount(params) {
1212
1210
  const { owners: ownersParam, embeddedWalletIndex, nonce } = params || {};
1213
1211
  const embeddedWallet = await this.embeddedWalletProvider.createWallet();
1212
+ if (!embeddedWallet.walletId) {
1213
+ throw new Error("Failed to create embedded wallet. No wallet ID returned");
1214
+ }
1214
1215
  const account = await embeddedWallet.account();
1215
1216
  let owners;
1216
1217
  if (ownersParam) {
@@ -1220,14 +1221,18 @@ var WalletProvider = class {
1220
1221
  } else {
1221
1222
  owners = [embeddedWallet.address];
1222
1223
  }
1223
- return this.smartWalletProvider.createWallet({
1224
+ const smartWallet = await this.smartWalletProvider.createWallet({
1224
1225
  owners,
1225
1226
  signer: account,
1226
1227
  nonce
1227
1228
  });
1229
+ return {
1230
+ embeddedWalletId: embeddedWallet.walletId,
1231
+ smartWallet
1232
+ };
1228
1233
  }
1229
1234
  /**
1230
- * Gets a smart wallet using an embedded wallet as the signer
1235
+ * Gets a unified web3 account: a smart wallet using an embedded wallet as the signer
1231
1236
  *
1232
1237
  * @internal
1233
1238
  * @remarks
@@ -1244,7 +1249,7 @@ var WalletProvider = class {
1244
1249
  * @returns Promise that resolves to the {@link SmartWallet}
1245
1250
  * @throws Error if the embedded wallet cannot be found
1246
1251
  */
1247
- async getSmartWalletWithEmbeddedSigner(params) {
1252
+ async getAccount(params) {
1248
1253
  const { walletId, deploymentOwners, walletAddress } = params;
1249
1254
  const embeddedWallet = await this.embeddedWalletProvider.getWallet({
1250
1255
  walletId
@@ -2324,6 +2329,15 @@ var MyceliumSDK = class {
2324
2329
  * @see MyceliumSDKConfig
2325
2330
  */
2326
2331
  constructor(config) {
2332
+ /**
2333
+ * Ramp namespace to manage ramp operations. Methods are available on {@link RampNamespace}
2334
+ * @internal
2335
+ * @remarks
2336
+ * If the Coinbase CDP configuration is not provided, the ramp functionality will be disabled.
2337
+ * Calling the respective method will throw an error
2338
+ * @category Tools
2339
+ */
2340
+ this.fundingNamespace = null;
2327
2341
  /**
2328
2342
  * Coinbase CDP instance to Coinbase related and onchain operations using Coinbase CDP API
2329
2343
  * @remarks
@@ -2332,46 +2346,6 @@ var MyceliumSDK = class {
2332
2346
  * @internal
2333
2347
  */
2334
2348
  this.coinbaseCDP = null;
2335
- /**
2336
- * Coinbase CDP configuration methods for ramp operations
2337
- * @public
2338
- * @category Tools
2339
- */
2340
- this.rampConfig = {
2341
- /**
2342
- * Return all supported countries and payment methods for on-ramp by Coinbase CDP
2343
- * @public
2344
- * @category Ramp
2345
- *
2346
- * @returns @see {@link RampConfigResponse} with supported countries and payment methods for top-up
2347
- * @throws If API returned an error
2348
- */
2349
- getTopUpConfig: async () => {
2350
- if (!this.coinbaseCDP) {
2351
- throw new Error(
2352
- "Coinbase CDP is not initialized. Please, provide the configuration in the SDK initialization"
2353
- );
2354
- }
2355
- return await this.coinbaseCDP.getOnRampConfig();
2356
- },
2357
- /**
2358
- * Return all supported countries and payment methods for off-ramp by Coinbase CDP
2359
- * @public
2360
- * @category Ramp
2361
- *
2362
- *
2363
- * @returns @see {@link RampConfigResponse} with supported countries and payment methods for cash out
2364
- * @throws If API returned an error
2365
- */
2366
- getCashOutConfig: async () => {
2367
- if (!this.coinbaseCDP) {
2368
- throw new Error(
2369
- "Coinbase CDP is not initialized. Please, provide the configuration in the SDK initialization"
2370
- );
2371
- }
2372
- return await this.coinbaseCDP.getOffRampConfig();
2373
- }
2374
- };
2375
2349
  this._chainManager = new ChainManager(
2376
2350
  config.chain || {
2377
2351
  chainId: base3.id,
@@ -2392,6 +2366,7 @@ var MyceliumSDK = class {
2392
2366
  config.integratorId,
2393
2367
  this.chainManager
2394
2368
  );
2369
+ this.fundingNamespace = new FundingNamespace(this.coinbaseCDP);
2395
2370
  }
2396
2371
  const protocolsRouterConfig = config.protocolsRouterConfig || {
2397
2372
  riskLevel: "low"
@@ -2402,6 +2377,8 @@ var MyceliumSDK = class {
2402
2377
  /**
2403
2378
  * Returns the chain manager instance for multi-chain operations
2404
2379
  * @public
2380
+ * @remarks
2381
+ * More about methods in {@link ChainManager}
2405
2382
  * @category Tools
2406
2383
  *
2407
2384
  * @returns ChainManager instance of the type {@link ChainManager}
@@ -2409,6 +2386,23 @@ var MyceliumSDK = class {
2409
2386
  get chainManager() {
2410
2387
  return this._chainManager;
2411
2388
  }
2389
+ /**
2390
+ * Returns a funding namespace to manage top ups & cash outs configurations
2391
+ * @public
2392
+ * @remarks
2393
+ * More about methods in {@link FundingNamespace}
2394
+ * @category Tools
2395
+ *
2396
+ * @returns Funding namespace of the type {@link FundingNamespace}
2397
+ */
2398
+ get funding() {
2399
+ if (!this.fundingNamespace) {
2400
+ throw new Error(
2401
+ "Ramp namespace is not initialized. Please, provide the configuration in the SDK initialization"
2402
+ );
2403
+ }
2404
+ return this.fundingNamespace;
2405
+ }
2412
2406
  /**
2413
2407
  * Recommends and initializes a protocol based on router settings
2414
2408
  *
@@ -2476,6 +2470,7 @@ var MyceliumSDK = class {
2476
2470
  };
2477
2471
  export {
2478
2472
  DefaultSmartWallet,
2473
+ FundingNamespace,
2479
2474
  MyceliumSDK
2480
2475
  };
2481
2476
  //# sourceMappingURL=index.js.map