@upshiftfinance/sdk 0.3.0 → 0.4.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.
Files changed (54) hide show
  1. package/README.md +1 -1
  2. package/lib/abis/KycRegistry.d.ts +109 -0
  3. package/lib/abis/KycRegistry.js +73 -0
  4. package/lib/abis/index.d.ts +1 -0
  5. package/lib/abis/index.js +1 -0
  6. package/lib/adapters/sui/actions.d.ts +174 -0
  7. package/lib/adapters/sui/actions.js +382 -0
  8. package/lib/adapters/sui/getters.d.ts +166 -0
  9. package/lib/adapters/sui/getters.js +391 -0
  10. package/lib/adapters/sui/index.d.ts +95 -2
  11. package/lib/adapters/sui/index.js +92 -2
  12. package/lib/adapters/sui/targets.d.ts +35 -0
  13. package/lib/adapters/sui/targets.js +35 -0
  14. package/lib/core/analytics/method-taxonomy.d.ts +1 -1
  15. package/lib/core/analytics/method-taxonomy.js +7 -0
  16. package/lib/core/analytics/version.d.ts +1 -1
  17. package/lib/core/analytics/version.js +1 -1
  18. package/lib/core/constants/core.d.ts +5 -0
  19. package/lib/core/constants/core.js +5 -0
  20. package/lib/core/constants/kyc.d.ts +9 -0
  21. package/lib/core/constants/kyc.js +12 -0
  22. package/lib/core/constants/web3.d.ts +2 -2
  23. package/lib/core/constants/web3.js +9 -2
  24. package/lib/core/errors/index.d.ts +77 -1
  25. package/lib/core/errors/index.js +94 -1
  26. package/lib/core/fetcher.d.ts +5 -0
  27. package/lib/core/fetcher.js +1 -1
  28. package/lib/core/helpers/chain-support.d.ts +2 -2
  29. package/lib/core/helpers/chain-support.js +3 -3
  30. package/lib/core/helpers/kyc.d.ts +47 -0
  31. package/lib/core/helpers/kyc.js +111 -0
  32. package/lib/core/helpers/revert-decode.js +3 -2
  33. package/lib/core/index.d.ts +2 -0
  34. package/lib/core/index.js +2 -0
  35. package/lib/main.d.ts +31 -3
  36. package/lib/main.js +32 -0
  37. package/lib/modules/api/kyc.d.ts +4 -0
  38. package/lib/modules/api/kyc.js +148 -0
  39. package/lib/modules/api/main.d.ts +63 -1
  40. package/lib/modules/api/main.js +64 -0
  41. package/lib/modules/vaults/getters.d.ts +3 -1
  42. package/lib/modules/vaults/getters.js +53 -9
  43. package/lib/modules/vaults/main.d.ts +39 -3
  44. package/lib/modules/vaults/main.js +79 -5
  45. package/lib/modules/vaults/types.d.ts +7 -1
  46. package/lib/modules/vaults/utils.js +4 -1
  47. package/lib/sdk.d.ts +15131 -14393
  48. package/lib/types/index.d.ts +1 -0
  49. package/lib/types/index.js +1 -0
  50. package/lib/types/kyc.d.ts +61 -0
  51. package/lib/types/kyc.js +3 -0
  52. package/lib/types/vaults.d.ts +2 -0
  53. package/lib/types/webserver.d.ts +5 -0
  54. package/package.json +1 -1
@@ -77,6 +77,8 @@ class UpshiftVaults extends core_1.UpshiftBase {
77
77
  * vaults (see `IVaultBaseOptions.stellarRpc`).
78
78
  */
79
79
  _stellarRpc;
80
+ /** The SDK's `sui` config, for Sui vault reads (see `IVaultBaseOptions.sui`). */
81
+ _sui;
80
82
  constructor(baseConfig, solana) {
81
83
  super(baseConfig);
82
84
  this.solanaService = solana;
@@ -87,6 +89,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
87
89
  network: baseConfig.stellar.network ?? 'mainnet',
88
90
  }
89
91
  : undefined;
92
+ this._sui = baseConfig.sui;
90
93
  this.headers = {
91
94
  'x-environment': this.monitoring?.['x-environment'],
92
95
  'x-user-id': this.monitoring?.['x-user-id'],
@@ -134,8 +137,10 @@ class UpshiftVaults extends core_1.UpshiftBase {
134
137
  // if (!(this.authorized && this.upshiftKey)) // @todo: commented out for integrators
135
138
  const allVaults = await (0, core_1.fetchTokenizedVaults)(undefined, this.headers, options?.loadSubaccounts, options?.loadSnapshots);
136
139
  const vaultsPerAvailableProviders = allVaults.filter((v) =>
137
- // Stellar vaults are backend-only (no RPC provider required)
140
+ // Stellar and Sui vaults use their own endpoints, not this.providers.
141
+ // Sui rows without sui_vault_metadata are legacy Ember/Gamma vaults.
138
142
  v?.chain_type === 'stellar' ||
143
+ (v?.chain_type === 'sui' && !!v.sui_vault_metadata) ||
139
144
  // Solana vaults use this.solanaService (not this.providers). Without
140
145
  // an explicit pass-through here they get silently dropped on any
141
146
  // instance whose ACTIVE_RPC_URLS() doesn't register chainId -1.
@@ -202,6 +207,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
202
207
  rpcUrl,
203
208
  solanaService: this.solanaService,
204
209
  stellarRpc: this._stellarRpc,
210
+ sui: this._sui,
205
211
  env: this.monitoring?.env,
206
212
  upshiftKey: this.keys?.upshift,
207
213
  subgraphKey: this.keys?.graph,
@@ -294,6 +300,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
294
300
  rpcUrl: this.providers?.[v.chain],
295
301
  solanaService: this.solanaService,
296
302
  stellarRpc: this._stellarRpc,
303
+ sui: this._sui,
297
304
  env: this.monitoring?.env,
298
305
  upshiftKey: this.keys?.upshift,
299
306
  subgraphKey: this.keys?.graph,
@@ -361,7 +368,6 @@ class UpshiftVaults extends core_1.UpshiftBase {
361
368
  // `Vault input parameter is not an address: ${String(vault)}`,
362
369
  // );
363
370
  (0, core_1.assertKnownChainId)(chainId, this.providers, 'getVault');
364
- (0, core_1.assertSuiReadsSupported)(chainId, vault, 'getVault');
365
371
  (0, core_1.assertEvmProviderConfigured)(chainId, this.providers, 'getVault');
366
372
  // get vault data
367
373
  const vaultResponse = await (0, getters_1.getVault)({
@@ -376,6 +382,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
376
382
  : this.activeNetwork?.rpcUrl,
377
383
  solanaService: this.solanaService,
378
384
  stellarRpc: this._stellarRpc,
385
+ sui: this._sui,
379
386
  env: this.monitoring?.env,
380
387
  upshiftKey: this.keys?.upshift,
381
388
  subgraphKey: this.keys?.graph,
@@ -404,6 +411,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
404
411
  : this.activeNetwork?.rpcUrl,
405
412
  solanaService: this.solanaService,
406
413
  stellarRpc: this._stellarRpc,
414
+ sui: this._sui,
407
415
  env: this.monitoring?.env,
408
416
  upshiftKey: this.keys?.upshift,
409
417
  subgraphKey: this.keys?.graph,
@@ -453,6 +461,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
453
461
  chainId: chainId,
454
462
  solanaService: this.solanaService,
455
463
  stellarRpc: this._stellarRpc,
464
+ sui: this._sui,
456
465
  headers: this.headers,
457
466
  });
458
467
  return vaultResponse;
@@ -486,6 +495,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
486
495
  chainId: chainId,
487
496
  solanaService: this.solanaService,
488
497
  stellarRpc: this._stellarRpc,
498
+ sui: this._sui,
489
499
  headers: this.headers,
490
500
  });
491
501
  return vaultResponse;
@@ -519,6 +529,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
519
529
  : this.activeNetwork?.rpcUrl,
520
530
  solanaService: this.solanaService,
521
531
  stellarRpc: this._stellarRpc,
532
+ sui: this._sui,
522
533
  env: this.monitoring?.env,
523
534
  upshiftKey: this.keys?.upshift,
524
535
  subgraphKey: this.keys?.graph,
@@ -601,6 +612,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
601
612
  throw new Error('Vault input parameter is undefined.');
602
613
  if (!(0, ethers_1.isAddress)(vault) &&
603
614
  !(0, utils_2.isStellarAddress)(vault) &&
615
+ !(0, chain_address_1.isSuiAddress)(vault) &&
604
616
  !utils_1.SolanaUtils.isSolanaAddress(vault))
605
617
  throw new Error(`Vault input parameter is not an address: ${String(vault)}`);
606
618
  return await (0, getters_1.getVaultAvailableRedemptions)({
@@ -612,6 +624,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
612
624
  : this.activeNetwork?.rpcUrl,
613
625
  solanaService: this.solanaService,
614
626
  stellarRpc: this._stellarRpc,
627
+ sui: this._sui,
615
628
  env: this.monitoring?.env,
616
629
  upshiftKey: this.keys?.upshift,
617
630
  subgraphKey: this.keys?.graph,
@@ -654,7 +667,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
654
667
  throw new Error('Not authorized.');
655
668
  if (!vault)
656
669
  throw new Error('Vault input parameter is undefined.');
657
- if (!(0, ethers_1.isAddress)(vault) && !(0, utils_2.isStellarAddress)(vault)) {
670
+ if (!(0, ethers_1.isAddress)(vault) && !(0, utils_2.isStellarAddress)(vault) && !(0, chain_address_1.isSuiAddress)(vault)) {
658
671
  throw new Error(`Vault input parameter is not an address: ${String(vault)}`);
659
672
  }
660
673
  return await (0, getters_1.getVaultRedemptionHistory)({
@@ -705,12 +718,14 @@ class UpshiftVaults extends core_1.UpshiftBase {
705
718
  wallet,
706
719
  solanaWallet,
707
720
  stellarWallet,
721
+ suiWallet,
708
722
  options: {
709
723
  rpcUrl: chainId
710
724
  ? this.providers?.[chainId]
711
725
  : this.activeNetwork?.rpcUrl,
712
726
  solanaService: this.solanaService,
713
727
  stellarRpc: this._stellarRpc,
728
+ sui: this._sui,
714
729
  env: this.monitoring?.env,
715
730
  upshiftKey: this.keys?.upshift,
716
731
  subgraphKey: this.keys?.graph,
@@ -735,11 +750,13 @@ class UpshiftVaults extends core_1.UpshiftBase {
735
750
  vault: v.address,
736
751
  solanaWallet,
737
752
  stellarWallet,
753
+ suiWallet,
738
754
  wallet,
739
755
  options: {
740
756
  rpcUrl: this.providers?.[v.chain],
741
757
  solanaService: this.solanaService,
742
758
  stellarRpc: this._stellarRpc,
759
+ sui: this._sui,
743
760
  env: this.monitoring?.env,
744
761
  upshiftKey: this.keys?.upshift,
745
762
  subgraphKey: this.keys?.graph,
@@ -757,8 +774,10 @@ class UpshiftVaults extends core_1.UpshiftBase {
757
774
  return final;
758
775
  }
759
776
  const vaultsPerAvailableProviders = allVaults.filter((v) =>
760
- // Stellar vaults are backend-only (no RPC provider required)
777
+ // Stellar and Sui vaults use their own endpoints, not this.providers.
778
+ // Sui rows without sui_vault_metadata are legacy Ember/Gamma vaults.
761
779
  v?.chain_type === 'stellar' ||
780
+ (v?.chain_type === 'sui' && !!v.sui_vault_metadata) ||
762
781
  // Solana vaults use this.solanaService (not this.providers). Without
763
782
  // this clause every Solana position is dropped on any instance where
764
783
  // ACTIVE_RPC_URLS() doesn't register chainId -1 — which is exactly
@@ -779,11 +798,13 @@ class UpshiftVaults extends core_1.UpshiftBase {
779
798
  vault: v.address,
780
799
  solanaWallet,
781
800
  stellarWallet,
801
+ suiWallet,
782
802
  wallet,
783
803
  options: {
784
804
  rpcUrl: this.providers?.[v.chain],
785
805
  solanaService: this.solanaService,
786
806
  stellarRpc: this._stellarRpc,
807
+ sui: this._sui,
787
808
  env: this.monitoring?.env,
788
809
  upshiftKey: this.keys?.upshift,
789
810
  subgraphKey: this.keys?.graph,
@@ -963,6 +984,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
963
984
  : this.requireActiveNetwork().rpcUrl,
964
985
  solanaService: this.solanaService,
965
986
  stellarRpc: this._stellarRpc,
987
+ sui: this._sui,
966
988
  env: this.monitoring?.env,
967
989
  upshiftKey: this.keys?.upshift,
968
990
  subgraphKey: this.keys?.graph,
@@ -989,6 +1011,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
989
1011
  : this.requireActiveNetwork().rpcUrl,
990
1012
  solanaService: this.solanaService,
991
1013
  stellarRpc: this._stellarRpc,
1014
+ sui: this._sui,
992
1015
  env: this.monitoring?.env,
993
1016
  upshiftKey: this.keys?.upshift,
994
1017
  subgraphKey: this.keys?.graph,
@@ -1208,6 +1231,52 @@ class UpshiftVaults extends core_1.UpshiftBase {
1208
1231
  rpcUrl: this.providers[options.chainId],
1209
1232
  });
1210
1233
  }
1234
+ /**
1235
+ * Read a wallet's KYC status through this instance's provider for
1236
+ * `chainId`. See {@link getKycStatus}.
1237
+ *
1238
+ * @param options - `chainId` and `wallet`.
1239
+ * @returns The wallet's {@link IKycStatus}.
1240
+ * @throws UpshiftValidationError (`INVALID_CHAIN`) when no provider is
1241
+ * configured or no registry is deployed for `chainId`;
1242
+ * (`INVALID_ADDRESS`) for a malformed wallet.
1243
+ * @throws UpshiftSDKError when the `statusOf` read fails.
1244
+ * @worstCaseRpcCalls 1
1245
+ * @example
1246
+ * ```ts
1247
+ * const status = await upshiftSdk.getKycStatus({ chainId: 1, wallet });
1248
+ * ```
1249
+ */
1250
+ async getKycStatus(options) {
1251
+ (0, core_1.assertEvmProviderConfigured)(options.chainId, this.providers, 'getKycStatus');
1252
+ return (0, core_1.getKycStatus)({
1253
+ ...options,
1254
+ rpcUrl: this.providers[options.chainId],
1255
+ });
1256
+ }
1257
+ /**
1258
+ * Read a wallet's raw KYC record through this instance's provider for
1259
+ * `chainId`. See {@link getKycRecord}.
1260
+ *
1261
+ * @param options - `chainId` and `wallet`.
1262
+ * @returns The wallet's {@link IKycRecord}.
1263
+ * @throws UpshiftValidationError (`INVALID_CHAIN`) when no provider is
1264
+ * configured or no registry is deployed for `chainId`;
1265
+ * (`INVALID_ADDRESS`) for a malformed wallet.
1266
+ * @throws UpshiftSDKError when the `getRecord` read fails.
1267
+ * @worstCaseRpcCalls 1
1268
+ * @example
1269
+ * ```ts
1270
+ * const record = await upshiftSdk.getKycRecord({ chainId: 1, wallet });
1271
+ * ```
1272
+ */
1273
+ async getKycRecord(options) {
1274
+ (0, core_1.assertEvmProviderConfigured)(options.chainId, this.providers, 'getKycRecord');
1275
+ return (0, core_1.getKycRecord)({
1276
+ ...options,
1277
+ rpcUrl: this.providers[options.chainId],
1278
+ });
1279
+ }
1211
1280
  /**
1212
1281
  * @function getStakingPositions gets all available reward staking positions
1213
1282
  * @param wallet optionally passed user wallet address
@@ -1243,7 +1312,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
1243
1312
  throw new Error('Not authorized.');
1244
1313
  if (!vault)
1245
1314
  throw new Error('Pool input parameter is undefined.');
1246
- if (!(0, ethers_1.isAddress)(vault) && !(0, utils_2.isStellarAddress)(vault))
1315
+ if (!(0, ethers_1.isAddress)(vault) && !(0, utils_2.isStellarAddress)(vault) && !(0, chain_address_1.isSuiAddress)(vault))
1247
1316
  throw new Error(`Pool input parameter is not an address: ${String(vault)}`);
1248
1317
  const resolvedChainId = chainId ?? this.activeNetwork?.chainId;
1249
1318
  const rpcUrl = chainId
@@ -1256,6 +1325,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
1256
1325
  chainId: resolvedChainId,
1257
1326
  solanaService: this.solanaService,
1258
1327
  stellarRpc: this._stellarRpc,
1328
+ sui: this._sui,
1259
1329
  env: this.monitoring?.env,
1260
1330
  upshiftKey: this.keys?.upshift,
1261
1331
  subgraphKey: this.keys?.graph,
@@ -1280,6 +1350,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
1280
1350
  rpcUrl: rpcUrl,
1281
1351
  solanaService: this.solanaService,
1282
1352
  stellarRpc: this._stellarRpc,
1353
+ sui: this._sui,
1283
1354
  env: this.monitoring?.env,
1284
1355
  upshiftKey: this.keys?.upshift,
1285
1356
  subgraphKey: this.keys?.graph,
@@ -1328,6 +1399,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
1328
1399
  : rpcUrl || this.requireActiveNetwork().rpcUrl,
1329
1400
  solanaService: this.solanaService,
1330
1401
  stellarRpc: this._stellarRpc,
1402
+ sui: this._sui,
1331
1403
  env: this.monitoring?.env,
1332
1404
  upshiftKey: this.keys?.upshift,
1333
1405
  subgraphKey: this.keys?.graph,
@@ -1602,6 +1674,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
1602
1674
  rpcUrl: chainId ? this.providers?.[chainId] : this.activeNetwork.rpcUrl,
1603
1675
  solanaService: this.solanaService,
1604
1676
  stellarRpc: this._stellarRpc,
1677
+ sui: this._sui,
1605
1678
  env: this.monitoring?.env,
1606
1679
  upshiftKey: this.keys?.upshift,
1607
1680
  subgraphKey: this.keys?.graph,
@@ -1655,6 +1728,7 @@ class UpshiftVaults extends core_1.UpshiftBase {
1655
1728
  rpcUrl,
1656
1729
  solanaService: this.solanaService,
1657
1730
  stellarRpc: this._stellarRpc,
1731
+ sui: this._sui,
1658
1732
  env: this.monitoring?.env,
1659
1733
  upshiftKey: this.keys?.upshift,
1660
1734
  subgraphKey: this.keys?.graph,
@@ -1,5 +1,5 @@
1
1
  import type { Connection } from '@solana/web3.js';
2
- import type { IAddress, IEnv, ISolanaNetwork, IStellarNetwork, IWSMonitorHeaders } from '../../types';
2
+ import type { IAddress, IEnv, ISolanaNetwork, IStellarNetwork, ISuiConfig, IWSMonitorHeaders } from '../../types';
3
3
  /**
4
4
  * Structural interface for the Solana adapter surface used by vault operations.
5
5
  * Avoids importing the concrete SolanaAdapter class to prevent circular dependencies.
@@ -63,6 +63,12 @@ export interface IVaultBaseOptions {
63
63
  rpcUrl: string;
64
64
  network: IStellarNetwork;
65
65
  };
66
+ /**
67
+ * The SDK's `sui` config for Sui vault reads: endpoint override and contract
68
+ * IDs. Applied only to vaults on its `network`; other Sui vaults use the
69
+ * built-in endpoint and contract IDs.
70
+ */
71
+ sui?: ISuiConfig;
66
72
  headers?: IWSMonitorHeaders;
67
73
  /**
68
74
  * Portfolio mode: when true, the per-vault EVM getter does NOT null out a
@@ -209,7 +209,8 @@ async function getYieldLastRealizedOn(provider, vaultAddress) {
209
209
  break;
210
210
  }
211
211
  case 'sol-0':
212
- case 'stellar-0': {
212
+ case 'stellar-0':
213
+ case 'sui-0': {
213
214
  return 0;
214
215
  }
215
216
  default: {
@@ -392,6 +393,7 @@ function buildBackendVault(tokenizedVault, overrides) {
392
393
  isFeatured: tokenizedVault.is_featured || false,
393
394
  isSpotlighted: tokenizedVault.is_spotlighted ?? false,
394
395
  withdrawalOnly: tokenizedVault.withdrawal_only ?? false,
396
+ requiresKyc: tokenizedVault.requires_kyc ?? false,
395
397
  isVisible: tokenizedVault.is_visible || false,
396
398
  reserveTarget: tokenizedVault.reserve_target || 0,
397
399
  reserveTolerance: tokenizedVault.reserve_tolerance || 0,
@@ -527,6 +529,7 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
527
529
  isFeatured: tokenizedVault.is_featured,
528
530
  withdrawalOnly: tokenizedVault.withdrawal_only ?? false,
529
531
  isSpotlighted: tokenizedVault.is_spotlighted ?? false,
532
+ requiresKyc: tokenizedVault.requires_kyc ?? false,
530
533
  isVisible: tokenizedVault.is_visible,
531
534
  reserveTarget: tokenizedVault.reserve_target,
532
535
  reserveTolerance: tokenizedVault.reserve_tolerance,