@scallop-io/sui-scallop-sdk 1.5.2 → 2.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.
Files changed (59) hide show
  1. package/dist/index.d.mts +446 -599
  2. package/dist/index.d.ts +446 -599
  3. package/dist/index.js +29 -60
  4. package/dist/index.mjs +6 -6
  5. package/package.json +1 -1
  6. package/src/builders/loyaltyProgramBuilder.ts +5 -3
  7. package/src/builders/oracle.ts +10 -24
  8. package/src/builders/referralBuilder.ts +5 -9
  9. package/src/builders/sCoinBuilder.ts +9 -8
  10. package/src/builders/spoolBuilder.ts +4 -6
  11. package/src/constants/common.ts +114 -126
  12. package/src/constants/index.ts +0 -5
  13. package/src/constants/pyth.ts +25 -34
  14. package/src/constants/queryKeys.ts +4 -2
  15. package/src/models/index.ts +1 -0
  16. package/src/models/scallop.ts +23 -19
  17. package/src/models/scallopAddress.ts +11 -8
  18. package/src/models/scallopBuilder.ts +32 -35
  19. package/src/models/scallopCache.ts +1 -1
  20. package/src/models/scallopClient.ts +87 -89
  21. package/src/models/scallopConstants.ts +341 -0
  22. package/src/models/scallopIndexer.ts +11 -24
  23. package/src/models/scallopQuery.ts +65 -70
  24. package/src/models/scallopUtils.ts +114 -244
  25. package/src/queries/borrowIncentiveQuery.ts +21 -56
  26. package/src/queries/borrowLimitQuery.ts +3 -6
  27. package/src/queries/coreQuery.ts +94 -112
  28. package/src/queries/flashloanFeeQuery.ts +86 -0
  29. package/src/queries/isolatedAssetQuery.ts +12 -11
  30. package/src/queries/poolAddressesQuery.ts +187 -112
  31. package/src/queries/portfolioQuery.ts +65 -67
  32. package/src/queries/priceQuery.ts +16 -22
  33. package/src/queries/sCoinQuery.ts +15 -16
  34. package/src/queries/spoolQuery.ts +49 -59
  35. package/src/queries/supplyLimitQuery.ts +2 -6
  36. package/src/queries/xOracleQuery.ts +4 -15
  37. package/src/types/address.ts +12 -18
  38. package/src/types/builder/borrowIncentive.ts +2 -3
  39. package/src/types/builder/core.ts +20 -27
  40. package/src/types/builder/index.ts +1 -2
  41. package/src/types/builder/referral.ts +4 -8
  42. package/src/types/builder/sCoin.ts +4 -8
  43. package/src/types/builder/spool.ts +7 -10
  44. package/src/types/constant/common.ts +43 -49
  45. package/src/types/constant/enum.ts +15 -27
  46. package/src/types/constant/xOracle.ts +3 -5
  47. package/src/types/model.ts +47 -28
  48. package/src/types/query/borrowIncentive.ts +7 -24
  49. package/src/types/query/core.ts +8 -18
  50. package/src/types/query/portfolio.ts +8 -17
  51. package/src/types/query/spool.ts +5 -11
  52. package/src/types/utils.ts +1 -21
  53. package/src/utils/core.ts +1 -1
  54. package/src/utils/query.ts +13 -20
  55. package/src/utils/util.ts +6 -84
  56. package/src/constants/coinGecko.ts +0 -34
  57. package/src/constants/enum.ts +0 -268
  58. package/src/constants/flashloan.ts +0 -18
  59. package/src/constants/poolAddress.ts +0 -898
@@ -1,5 +1,4 @@
1
1
  import { SuiKit, SuiObjectArg } from '@scallop-io/sui-kit';
2
- import { ADDRESSES_ID, SUPPORT_POOLS, SUPPORT_SPOOLS } from '../constants';
3
2
  import {
4
3
  queryMarket,
5
4
  getObligations,
@@ -33,30 +32,29 @@ import {
33
32
  getBorrowIncentivePools,
34
33
  getBorrowLimit,
35
34
  getIsolatedAssets,
36
- // isIsolatedAsset,
37
35
  getSupplyLimit,
38
36
  getSCoinAmount,
39
37
  getSCoinAmounts,
40
38
  getSCoinSwapRate,
41
39
  getSCoinTotalSupply,
42
40
  getAllCoinPrices,
43
- getAllAddresses,
41
+ getPoolAddresses,
44
42
  isIsolatedAsset,
45
43
  getUserPortfolio,
46
44
  getPriceUpdatePolicies,
47
45
  getAssetOracles,
48
46
  } from '../queries';
49
47
  import {
48
+ // string,
49
+ // string,
50
+ // string,
51
+ // string,
52
+ // string,
53
+ // string,
54
+ // string,
50
55
  ScallopQueryParams,
51
- SupportStakeMarketCoins,
52
- SupportAssetCoins,
53
- SupportPoolCoins,
54
- SupportCollateralCoins,
55
- SupportMarketCoins,
56
56
  StakePools,
57
57
  StakeRewardPools,
58
- SupportBorrowIncentiveCoins,
59
- SupportSCoin,
60
58
  ScallopQueryInstanceParams,
61
59
  MarketPool,
62
60
  CoinPrices,
@@ -73,6 +71,7 @@ import { normalizeSuiAddress } from '@mysten/sui/utils';
73
71
  import { withIndexerFallback } from 'src/utils/indexer';
74
72
  import { newSuiKit } from './suiKit';
75
73
  import { SuiObjectRef } from '@mysten/sui/client';
74
+ import { ScallopConstants } from './scallopConstants';
76
75
  /**
77
76
  * @description
78
77
  * It provides methods for getting on-chain data from the Scallop contract.
@@ -91,12 +90,13 @@ export class ScallopQuery {
91
90
  public suiKit: SuiKit;
92
91
  public address: ScallopAddress;
93
92
  public utils: ScallopUtils;
93
+ public constants: ScallopConstants;
94
94
  public indexer: ScallopIndexer;
95
95
  public cache: ScallopCache;
96
96
  public walletAddress: string;
97
97
 
98
98
  public constructor(
99
- params: ScallopQueryParams = {},
99
+ params: ScallopQueryParams,
100
100
  instance?: ScallopQueryInstanceParams
101
101
  ) {
102
102
  this.params = params;
@@ -107,28 +107,29 @@ export class ScallopQuery {
107
107
  params.walletAddress ?? this.suiKit.currentAddress()
108
108
  );
109
109
 
110
- if (instance?.utils) {
111
- this.utils = instance.utils;
112
- this.address = instance.utils.address;
113
- this.cache = this.address.cache;
114
- } else {
115
- this.cache = new ScallopCache(this.params, {
110
+ this.cache =
111
+ instance?.utils?.cache ??
112
+ new ScallopCache(this.params, {
116
113
  suiKit: this.suiKit,
117
114
  });
118
- this.address = new ScallopAddress(
119
- {
120
- id: params?.addressesId ?? ADDRESSES_ID,
121
- network: params?.networkType,
122
- forceInterface: params?.forceAddressesInterface,
123
- },
124
- {
125
- cache: this.cache,
126
- }
127
- );
128
- this.utils = new ScallopUtils(this.params, {
115
+
116
+ this.address =
117
+ instance?.utils?.address ??
118
+ new ScallopAddress(this.params, {
119
+ cache: this.cache,
120
+ });
121
+
122
+ this.constants =
123
+ instance?.utils?.constants ??
124
+ new ScallopConstants(this.params, {
129
125
  address: this.address,
130
126
  });
131
- }
127
+
128
+ this.utils =
129
+ instance?.utils ??
130
+ new ScallopUtils(this.params, {
131
+ constants: this.constants,
132
+ });
132
133
  this.indexer =
133
134
  instance?.indexer ??
134
135
  new ScallopIndexer(this.params, { cache: this.cache });
@@ -210,7 +211,7 @@ export class ScallopQuery {
210
211
  * @return Market pools data.
211
212
  */
212
213
  public async getMarketPools(
213
- poolCoinNames: SupportPoolCoins[] = [...SUPPORT_POOLS],
214
+ poolCoinNames: string[] = [...this.constants.whitelist.lending],
214
215
  args?: {
215
216
  coinPrices?: CoinPrices;
216
217
  indexer?: boolean;
@@ -232,7 +233,7 @@ export class ScallopQuery {
232
233
  * @return Market pool data.
233
234
  */
234
235
  public async getMarketPool(
235
- poolCoinName: SupportPoolCoins,
236
+ poolCoinName: string,
236
237
  args?: {
237
238
  coinPrice?: number;
238
239
  indexer?: boolean;
@@ -261,7 +262,7 @@ export class ScallopQuery {
261
262
  * @return Market collaterals data.
262
263
  */
263
264
  public async getMarketCollaterals(
264
- collateralCoinNames?: SupportCollateralCoins[],
265
+ collateralCoinNames: string[] = [...this.constants.whitelist.collateral],
265
266
  args?: { indexer?: boolean }
266
267
  ) {
267
268
  return await getMarketCollaterals(this, collateralCoinNames, args?.indexer);
@@ -275,7 +276,7 @@ export class ScallopQuery {
275
276
  * @return Market collateral data.
276
277
  */
277
278
  public async getMarketCollateral(
278
- collateralCoinName: SupportCollateralCoins,
279
+ collateralCoinName: string,
279
280
  args?: { indexer?: boolean }
280
281
  ) {
281
282
  return await getMarketCollateral(this, collateralCoinName, args?.indexer);
@@ -309,7 +310,7 @@ export class ScallopQuery {
309
310
  * @return All coin amounts.
310
311
  */
311
312
  public async getCoinAmounts(
312
- assetCoinNames?: SupportAssetCoins[],
313
+ assetCoinNames?: string[],
313
314
  ownerAddress: string = this.walletAddress
314
315
  ) {
315
316
  return await getCoinAmounts(this, assetCoinNames, ownerAddress);
@@ -323,7 +324,7 @@ export class ScallopQuery {
323
324
  * @return Coin amount.
324
325
  */
325
326
  public async getCoinAmount(
326
- assetCoinName: SupportAssetCoins,
327
+ assetCoinName: string,
327
328
  ownerAddress: string = this.walletAddress
328
329
  ) {
329
330
  return await getCoinAmount(this, assetCoinName, ownerAddress);
@@ -337,7 +338,7 @@ export class ScallopQuery {
337
338
  * @return All market market coin amounts.
338
339
  */
339
340
  public async getMarketCoinAmounts(
340
- marketCoinNames?: SupportMarketCoins[],
341
+ marketCoinNames?: string[],
341
342
  ownerAddress: string = this.walletAddress
342
343
  ) {
343
344
  return await getMarketCoinAmounts(this, marketCoinNames, ownerAddress);
@@ -351,7 +352,7 @@ export class ScallopQuery {
351
352
  * @return Market market coin amount.
352
353
  */
353
354
  public async getMarketCoinAmount(
354
- marketCoinName: SupportMarketCoins,
355
+ marketCoinName: string,
355
356
  ownerAddress: string = this.walletAddress
356
357
  ) {
357
358
  return await getMarketCoinAmount(this, marketCoinName, ownerAddress);
@@ -363,7 +364,7 @@ export class ScallopQuery {
363
364
  * @param assetCoinName - Specific support asset coin name.
364
365
  * @return Asset coin price.
365
366
  */
366
- public async getPriceFromPyth(assetCoinName: SupportAssetCoins) {
367
+ public async getPriceFromPyth(assetCoinName: string) {
367
368
  return await getPythPrice(this, assetCoinName);
368
369
  }
369
370
 
@@ -373,7 +374,7 @@ export class ScallopQuery {
373
374
  * @param assetCoinNames - Array of supported asset coin names.
374
375
  * @return Array of asset coin prices.
375
376
  */
376
- public async getPricesFromPyth(assetCoinNames: SupportAssetCoins[]) {
377
+ public async getPricesFromPyth(assetCoinNames: string[]) {
377
378
  return await getPythPrices(this, assetCoinNames);
378
379
  }
379
380
 
@@ -387,7 +388,7 @@ export class ScallopQuery {
387
388
  * @return Spools data.
388
389
  */
389
390
  public async getSpools(
390
- stakeMarketCoinNames?: SupportStakeMarketCoins[],
391
+ stakeMarketCoinNames?: string[],
391
392
  args?: {
392
393
  marketPools?: MarketPools;
393
394
  coinPrices?: CoinPrices;
@@ -411,7 +412,7 @@ export class ScallopQuery {
411
412
  * @return Spool data.
412
413
  */
413
414
  public async getSpool(
414
- stakeMarketCoinName: SupportStakeMarketCoins,
415
+ stakeMarketCoinName: string,
415
416
  args?: {
416
417
  marketPool?: MarketPool;
417
418
  coinPrices?: CoinPrices;
@@ -440,7 +441,7 @@ export class ScallopQuery {
440
441
  * @return Stake accounts data.
441
442
  */
442
443
  public async getStakeAccounts(
443
- stakeMarketCoinName: SupportStakeMarketCoins,
444
+ stakeMarketCoinName: string,
444
445
  ownerAddress: string = this.walletAddress
445
446
  ) {
446
447
  const allStakeAccount = await this.getAllStakeAccounts(ownerAddress);
@@ -458,7 +459,7 @@ export class ScallopQuery {
458
459
  * @return Stake pools data.
459
460
  */
460
461
  public async getStakePools(
461
- stakeMarketCoinNames: SupportStakeMarketCoins[] = [...SUPPORT_SPOOLS]
462
+ stakeMarketCoinNames: string[] = [...this.constants.whitelist.spool]
462
463
  ) {
463
464
  const stakePools: StakePools = {};
464
465
  for (const stakeMarketCoinName of stakeMarketCoinNames) {
@@ -482,7 +483,7 @@ export class ScallopQuery {
482
483
  * @param stakeMarketCoinName - Specific support stake market coin name.
483
484
  * @return Stake pool data.
484
485
  */
485
- public async getStakePool(stakeMarketCoinName: SupportStakeMarketCoins) {
486
+ public async getStakePool(stakeMarketCoinName: string) {
486
487
  return await getStakePool(this, stakeMarketCoinName);
487
488
  }
488
489
 
@@ -497,7 +498,7 @@ export class ScallopQuery {
497
498
  * @return Stake reward pools data.
498
499
  */
499
500
  public async getStakeRewardPools(
500
- stakeMarketCoinNames: SupportStakeMarketCoins[] = [...SUPPORT_SPOOLS]
501
+ stakeMarketCoinNames: string[] = [...this.constants.whitelist.spool]
501
502
  ) {
502
503
  const stakeRewardPools: StakeRewardPools = {};
503
504
  await Promise.allSettled(
@@ -525,9 +526,7 @@ export class ScallopQuery {
525
526
  * @param marketCoinName - Specific support stake market coin name.
526
527
  * @return Stake reward pool data.
527
528
  */
528
- public async getStakeRewardPool(
529
- stakeMarketCoinName: SupportStakeMarketCoins
530
- ) {
529
+ public async getStakeRewardPool(stakeMarketCoinName: string) {
531
530
  return await getStakeRewardPool(this, stakeMarketCoinName);
532
531
  }
533
532
 
@@ -539,7 +538,7 @@ export class ScallopQuery {
539
538
  * @return Borrow incentive pools data.
540
539
  */
541
540
  public async getBorrowIncentivePools(
542
- coinNames?: SupportBorrowIncentiveCoins[],
541
+ coinNames: string[] = [...this.constants.whitelist.lending],
543
542
  args?: {
544
543
  coinPrices?: CoinPrices;
545
544
  indexer?: boolean;
@@ -564,7 +563,7 @@ export class ScallopQuery {
564
563
  */
565
564
  public async getBorrowIncentiveAccounts(
566
565
  obligationId: string | SuiObjectRef,
567
- coinNames?: SupportBorrowIncentiveCoins[]
566
+ coinNames?: string[]
568
567
  ) {
569
568
  return await queryBorrowIncentiveAccounts(this, obligationId, coinNames);
570
569
  }
@@ -578,7 +577,7 @@ export class ScallopQuery {
578
577
  * @return All lending and spool infomation.
579
578
  */
580
579
  public async getLendings(
581
- poolCoinNames?: SupportPoolCoins[],
580
+ poolCoinNames?: string[],
582
581
  ownerAddress: string = this.walletAddress,
583
582
  args?: {
584
583
  indexer?: boolean;
@@ -605,7 +604,7 @@ export class ScallopQuery {
605
604
  * @return Lending pool data.
606
605
  */
607
606
  public async getLending(
608
- poolCoinName: SupportPoolCoins,
607
+ poolCoinName: string,
609
608
  ownerAddress: string = this.walletAddress,
610
609
  args?: { indexer?: boolean }
611
610
  ) {
@@ -755,7 +754,7 @@ export class ScallopQuery {
755
754
  * @param sCoinName - Supported sCoin name
756
755
  * @returns Total Supply
757
756
  */
758
- public async getSCoinTotalSupply(sCoinName: SupportSCoin) {
757
+ public async getSCoinTotalSupply(sCoinName: string) {
759
758
  return await getSCoinTotalSupply(this, sCoinName);
760
759
  }
761
760
 
@@ -767,7 +766,7 @@ export class ScallopQuery {
767
766
  * @return All market sCoin amounts.
768
767
  */
769
768
  public async getSCoinAmounts(
770
- sCoinNames?: SupportSCoin[],
769
+ sCoinNames?: string[],
771
770
  ownerAddress: string = this.walletAddress
772
771
  ) {
773
772
  return await getSCoinAmounts(this, sCoinNames, ownerAddress);
@@ -781,7 +780,7 @@ export class ScallopQuery {
781
780
  * @return sCoin amount.
782
781
  */
783
782
  public async getSCoinAmount(
784
- sCoinName: SupportSCoin | SupportMarketCoins,
783
+ sCoinName: string | string,
785
784
  ownerAddress: string = this.walletAddress
786
785
  ) {
787
786
  const parsedSCoinName = this.utils.parseSCoinName(sCoinName);
@@ -795,10 +794,7 @@ export class ScallopQuery {
795
794
  * @param assetCoinNames
796
795
  * @returns
797
796
  */
798
- public async getSCoinSwapRate(
799
- fromSCoin: SupportSCoin,
800
- toSCoin: SupportSCoin
801
- ) {
797
+ public async getSCoinSwapRate(fromSCoin: string, toSCoin: string) {
802
798
  return await getSCoinSwapRate(this, fromSCoin, toSCoin);
803
799
  }
804
800
 
@@ -806,7 +802,7 @@ export class ScallopQuery {
806
802
  * Get flashloan fee for specified assets
807
803
  */
808
804
  public async getFlashLoanFees(
809
- assetCoinNames: SupportAssetCoins[] = [...SUPPORT_POOLS]
805
+ assetCoinNames: string[] = [...this.constants.whitelist.lending]
810
806
  ) {
811
807
  return await getFlashLoanFees(this, assetCoinNames);
812
808
  }
@@ -814,14 +810,14 @@ export class ScallopQuery {
814
810
  /**
815
811
  * Get supply limit of lending pool
816
812
  */
817
- public async getPoolSupplyLimit(poolName: SupportPoolCoins) {
813
+ public async getPoolSupplyLimit(poolName: string) {
818
814
  return await getSupplyLimit(this.utils, poolName);
819
815
  }
820
816
 
821
817
  /**
822
818
  * Get borrow limit of borrow pool
823
819
  */
824
- public async getPoolBorrowLimit(poolName: SupportPoolCoins) {
820
+ public async getPoolBorrowLimit(poolName: string) {
825
821
  return await getBorrowLimit(this.utils, poolName);
826
822
  }
827
823
 
@@ -835,7 +831,7 @@ export class ScallopQuery {
835
831
  /**
836
832
  * Check if asset is an isolated asset
837
833
  */
838
- public async isIsolatedAsset(assetCoinName: SupportAssetCoins) {
834
+ public async isIsolatedAsset(assetCoinName: string) {
839
835
  return isIsolatedAsset(this.utils, assetCoinName);
840
836
  }
841
837
 
@@ -844,7 +840,7 @@ export class ScallopQuery {
844
840
  * @param coinName
845
841
  * @returns price data
846
842
  */
847
- public async getCoinPriceByIndexer(poolName: SupportPoolCoins) {
843
+ public async getCoinPriceByIndexer(poolName: string) {
848
844
  return this.indexer.getCoinPrice(poolName);
849
845
  }
850
846
 
@@ -877,10 +873,9 @@ export class ScallopQuery {
877
873
  * Query all address (lending pool, collateral pool, borrow dynamics, interest models, etc.) of all pool
878
874
  * @returns
879
875
  */
880
- public async getPoolAddresses(
881
- pools: SupportPoolCoins[] = [...SUPPORT_POOLS]
882
- ) {
883
- return getAllAddresses(this, pools);
876
+ public async getPoolAddresses(apiAddressId = this.address.getId()) {
877
+ if (!apiAddressId) throw new Error('apiAddressId is required');
878
+ return getPoolAddresses(apiAddressId);
884
879
  }
885
880
 
886
881
  /**
@@ -915,7 +910,7 @@ export class ScallopQuery {
915
910
  getAssetOracles(this.utils, 'secondary'),
916
911
  ]);
917
912
 
918
- return SUPPORT_POOLS.reduce(
913
+ return [...this.constants.whitelist.lending].reduce(
919
914
  (acc, pool) => {
920
915
  acc[pool] = {
921
916
  primary: primary?.[pool] ?? [],
@@ -923,7 +918,7 @@ export class ScallopQuery {
923
918
  };
924
919
  return acc;
925
920
  },
926
- {} as Record<SupportAssetCoins, xOracleRules>
921
+ {} as Record<string, xOracleRules>
927
922
  );
928
923
  }
929
924
  }