@scallop-io/sui-scallop-sdk 1.5.3 → 2.0.0-alpha.2

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 (60) hide show
  1. package/dist/index.d.mts +451 -602
  2. package/dist/index.d.ts +451 -602
  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 +2 -0
  15. package/src/models/index.ts +1 -0
  16. package/src/models/scallop.ts +23 -19
  17. package/src/models/scallopAddress.ts +7 -4
  18. package/src/models/scallopBuilder.ts +36 -41
  19. package/src/models/scallopCache.ts +1 -1
  20. package/src/models/scallopClient.ts +93 -94
  21. package/src/models/scallopConstants.ts +342 -0
  22. package/src/models/scallopIndexer.ts +11 -24
  23. package/src/models/scallopQuery.ts +70 -77
  24. package/src/models/scallopUtils.ts +122 -249
  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 +49 -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
  60. package/src/models/scallopPrice.ts +0 -0
@@ -1,5 +1,4 @@
1
1
  import { SuiKit, SuiObjectArg } from '@scallop-io/sui-kit';
2
- import { ADDRESS_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,30 @@ 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
+ instance?.cache ??
113
+ new ScallopCache(this.params, {
116
114
  suiKit: this.suiKit,
117
115
  });
118
- this.address = new ScallopAddress(
119
- {
120
- id: params?.addressId ?? ADDRESS_ID,
121
- network: params?.networkType,
122
- forceInterface: params?.forceAddressesInterface,
123
- },
124
- {
125
- cache: this.cache,
126
- }
127
- );
128
- this.utils = new ScallopUtils(this.params, {
116
+
117
+ this.address =
118
+ instance?.utils?.address ??
119
+ new ScallopAddress(this.params, {
120
+ cache: this.cache,
121
+ });
122
+
123
+ this.constants =
124
+ instance?.utils?.constants ??
125
+ new ScallopConstants(this.params, {
129
126
  address: this.address,
130
127
  });
131
- }
128
+
129
+ this.utils =
130
+ instance?.utils ??
131
+ new ScallopUtils(this.params, {
132
+ constants: this.constants,
133
+ });
132
134
  this.indexer =
133
135
  instance?.indexer ??
134
136
  new ScallopIndexer(this.params, { cache: this.cache });
@@ -172,15 +174,12 @@ export class ScallopQuery {
172
174
  * @param force - Whether to force initialization.
173
175
  * @param address - ScallopAddress instance.
174
176
  */
175
- public async init(force: boolean = false, address?: ScallopAddress) {
176
- if (address && !this.address) {
177
- this.address = address;
178
- }
179
- if (force || !this.address.getAddresses()) {
180
- await this.address.read();
177
+ public async init(force: boolean = false) {
178
+ if (force || !this.constants.isInitialized) {
179
+ await this.constants.init();
181
180
  }
182
181
 
183
- await this.utils.init(force, this.address);
182
+ await this.utils.init(force);
184
183
  }
185
184
 
186
185
  /* ==================== Core Query Methods ==================== */
@@ -210,7 +209,7 @@ export class ScallopQuery {
210
209
  * @return Market pools data.
211
210
  */
212
211
  public async getMarketPools(
213
- poolCoinNames: SupportPoolCoins[] = [...SUPPORT_POOLS],
212
+ poolCoinNames: string[] = [...this.constants.whitelist.lending],
214
213
  args?: {
215
214
  coinPrices?: CoinPrices;
216
215
  indexer?: boolean;
@@ -232,7 +231,7 @@ export class ScallopQuery {
232
231
  * @return Market pool data.
233
232
  */
234
233
  public async getMarketPool(
235
- poolCoinName: SupportPoolCoins,
234
+ poolCoinName: string,
236
235
  args?: {
237
236
  coinPrice?: number;
238
237
  indexer?: boolean;
@@ -261,7 +260,7 @@ export class ScallopQuery {
261
260
  * @return Market collaterals data.
262
261
  */
263
262
  public async getMarketCollaterals(
264
- collateralCoinNames?: SupportCollateralCoins[],
263
+ collateralCoinNames: string[] = [...this.constants.whitelist.collateral],
265
264
  args?: { indexer?: boolean }
266
265
  ) {
267
266
  return await getMarketCollaterals(this, collateralCoinNames, args?.indexer);
@@ -275,7 +274,7 @@ export class ScallopQuery {
275
274
  * @return Market collateral data.
276
275
  */
277
276
  public async getMarketCollateral(
278
- collateralCoinName: SupportCollateralCoins,
277
+ collateralCoinName: string,
279
278
  args?: { indexer?: boolean }
280
279
  ) {
281
280
  return await getMarketCollateral(this, collateralCoinName, args?.indexer);
@@ -309,7 +308,7 @@ export class ScallopQuery {
309
308
  * @return All coin amounts.
310
309
  */
311
310
  public async getCoinAmounts(
312
- assetCoinNames?: SupportAssetCoins[],
311
+ assetCoinNames?: string[],
313
312
  ownerAddress: string = this.walletAddress
314
313
  ) {
315
314
  return await getCoinAmounts(this, assetCoinNames, ownerAddress);
@@ -323,7 +322,7 @@ export class ScallopQuery {
323
322
  * @return Coin amount.
324
323
  */
325
324
  public async getCoinAmount(
326
- assetCoinName: SupportAssetCoins,
325
+ assetCoinName: string,
327
326
  ownerAddress: string = this.walletAddress
328
327
  ) {
329
328
  return await getCoinAmount(this, assetCoinName, ownerAddress);
@@ -337,7 +336,7 @@ export class ScallopQuery {
337
336
  * @return All market market coin amounts.
338
337
  */
339
338
  public async getMarketCoinAmounts(
340
- marketCoinNames?: SupportMarketCoins[],
339
+ marketCoinNames?: string[],
341
340
  ownerAddress: string = this.walletAddress
342
341
  ) {
343
342
  return await getMarketCoinAmounts(this, marketCoinNames, ownerAddress);
@@ -351,7 +350,7 @@ export class ScallopQuery {
351
350
  * @return Market market coin amount.
352
351
  */
353
352
  public async getMarketCoinAmount(
354
- marketCoinName: SupportMarketCoins,
353
+ marketCoinName: string,
355
354
  ownerAddress: string = this.walletAddress
356
355
  ) {
357
356
  return await getMarketCoinAmount(this, marketCoinName, ownerAddress);
@@ -363,7 +362,7 @@ export class ScallopQuery {
363
362
  * @param assetCoinName - Specific support asset coin name.
364
363
  * @return Asset coin price.
365
364
  */
366
- public async getPriceFromPyth(assetCoinName: SupportAssetCoins) {
365
+ public async getPriceFromPyth(assetCoinName: string) {
367
366
  return await getPythPrice(this, assetCoinName);
368
367
  }
369
368
 
@@ -373,7 +372,7 @@ export class ScallopQuery {
373
372
  * @param assetCoinNames - Array of supported asset coin names.
374
373
  * @return Array of asset coin prices.
375
374
  */
376
- public async getPricesFromPyth(assetCoinNames: SupportAssetCoins[]) {
375
+ public async getPricesFromPyth(assetCoinNames: string[]) {
377
376
  return await getPythPrices(this, assetCoinNames);
378
377
  }
379
378
 
@@ -387,7 +386,7 @@ export class ScallopQuery {
387
386
  * @return Spools data.
388
387
  */
389
388
  public async getSpools(
390
- stakeMarketCoinNames?: SupportStakeMarketCoins[],
389
+ stakeMarketCoinNames?: string[],
391
390
  args?: {
392
391
  marketPools?: MarketPools;
393
392
  coinPrices?: CoinPrices;
@@ -411,7 +410,7 @@ export class ScallopQuery {
411
410
  * @return Spool data.
412
411
  */
413
412
  public async getSpool(
414
- stakeMarketCoinName: SupportStakeMarketCoins,
413
+ stakeMarketCoinName: string,
415
414
  args?: {
416
415
  marketPool?: MarketPool;
417
416
  coinPrices?: CoinPrices;
@@ -440,7 +439,7 @@ export class ScallopQuery {
440
439
  * @return Stake accounts data.
441
440
  */
442
441
  public async getStakeAccounts(
443
- stakeMarketCoinName: SupportStakeMarketCoins,
442
+ stakeMarketCoinName: string,
444
443
  ownerAddress: string = this.walletAddress
445
444
  ) {
446
445
  const allStakeAccount = await this.getAllStakeAccounts(ownerAddress);
@@ -458,7 +457,7 @@ export class ScallopQuery {
458
457
  * @return Stake pools data.
459
458
  */
460
459
  public async getStakePools(
461
- stakeMarketCoinNames: SupportStakeMarketCoins[] = [...SUPPORT_SPOOLS]
460
+ stakeMarketCoinNames: string[] = [...this.constants.whitelist.spool]
462
461
  ) {
463
462
  const stakePools: StakePools = {};
464
463
  for (const stakeMarketCoinName of stakeMarketCoinNames) {
@@ -482,7 +481,7 @@ export class ScallopQuery {
482
481
  * @param stakeMarketCoinName - Specific support stake market coin name.
483
482
  * @return Stake pool data.
484
483
  */
485
- public async getStakePool(stakeMarketCoinName: SupportStakeMarketCoins) {
484
+ public async getStakePool(stakeMarketCoinName: string) {
486
485
  return await getStakePool(this, stakeMarketCoinName);
487
486
  }
488
487
 
@@ -497,7 +496,7 @@ export class ScallopQuery {
497
496
  * @return Stake reward pools data.
498
497
  */
499
498
  public async getStakeRewardPools(
500
- stakeMarketCoinNames: SupportStakeMarketCoins[] = [...SUPPORT_SPOOLS]
499
+ stakeMarketCoinNames: string[] = [...this.constants.whitelist.spool]
501
500
  ) {
502
501
  const stakeRewardPools: StakeRewardPools = {};
503
502
  await Promise.allSettled(
@@ -525,9 +524,7 @@ export class ScallopQuery {
525
524
  * @param marketCoinName - Specific support stake market coin name.
526
525
  * @return Stake reward pool data.
527
526
  */
528
- public async getStakeRewardPool(
529
- stakeMarketCoinName: SupportStakeMarketCoins
530
- ) {
527
+ public async getStakeRewardPool(stakeMarketCoinName: string) {
531
528
  return await getStakeRewardPool(this, stakeMarketCoinName);
532
529
  }
533
530
 
@@ -539,7 +536,7 @@ export class ScallopQuery {
539
536
  * @return Borrow incentive pools data.
540
537
  */
541
538
  public async getBorrowIncentivePools(
542
- coinNames?: SupportBorrowIncentiveCoins[],
539
+ coinNames: string[] = [...this.constants.whitelist.lending],
543
540
  args?: {
544
541
  coinPrices?: CoinPrices;
545
542
  indexer?: boolean;
@@ -564,7 +561,7 @@ export class ScallopQuery {
564
561
  */
565
562
  public async getBorrowIncentiveAccounts(
566
563
  obligationId: string | SuiObjectRef,
567
- coinNames?: SupportBorrowIncentiveCoins[]
564
+ coinNames?: string[]
568
565
  ) {
569
566
  return await queryBorrowIncentiveAccounts(this, obligationId, coinNames);
570
567
  }
@@ -578,7 +575,7 @@ export class ScallopQuery {
578
575
  * @return All lending and spool infomation.
579
576
  */
580
577
  public async getLendings(
581
- poolCoinNames?: SupportPoolCoins[],
578
+ poolCoinNames?: string[],
582
579
  ownerAddress: string = this.walletAddress,
583
580
  args?: {
584
581
  indexer?: boolean;
@@ -605,7 +602,7 @@ export class ScallopQuery {
605
602
  * @return Lending pool data.
606
603
  */
607
604
  public async getLending(
608
- poolCoinName: SupportPoolCoins,
605
+ poolCoinName: string,
609
606
  ownerAddress: string = this.walletAddress,
610
607
  args?: { indexer?: boolean }
611
608
  ) {
@@ -755,7 +752,7 @@ export class ScallopQuery {
755
752
  * @param sCoinName - Supported sCoin name
756
753
  * @returns Total Supply
757
754
  */
758
- public async getSCoinTotalSupply(sCoinName: SupportSCoin) {
755
+ public async getSCoinTotalSupply(sCoinName: string) {
759
756
  return await getSCoinTotalSupply(this, sCoinName);
760
757
  }
761
758
 
@@ -767,7 +764,7 @@ export class ScallopQuery {
767
764
  * @return All market sCoin amounts.
768
765
  */
769
766
  public async getSCoinAmounts(
770
- sCoinNames?: SupportSCoin[],
767
+ sCoinNames?: string[],
771
768
  ownerAddress: string = this.walletAddress
772
769
  ) {
773
770
  return await getSCoinAmounts(this, sCoinNames, ownerAddress);
@@ -781,7 +778,7 @@ export class ScallopQuery {
781
778
  * @return sCoin amount.
782
779
  */
783
780
  public async getSCoinAmount(
784
- sCoinName: SupportSCoin | SupportMarketCoins,
781
+ sCoinName: string | string,
785
782
  ownerAddress: string = this.walletAddress
786
783
  ) {
787
784
  const parsedSCoinName = this.utils.parseSCoinName(sCoinName);
@@ -795,10 +792,7 @@ export class ScallopQuery {
795
792
  * @param assetCoinNames
796
793
  * @returns
797
794
  */
798
- public async getSCoinSwapRate(
799
- fromSCoin: SupportSCoin,
800
- toSCoin: SupportSCoin
801
- ) {
795
+ public async getSCoinSwapRate(fromSCoin: string, toSCoin: string) {
802
796
  return await getSCoinSwapRate(this, fromSCoin, toSCoin);
803
797
  }
804
798
 
@@ -806,7 +800,7 @@ export class ScallopQuery {
806
800
  * Get flashloan fee for specified assets
807
801
  */
808
802
  public async getFlashLoanFees(
809
- assetCoinNames: SupportAssetCoins[] = [...SUPPORT_POOLS]
803
+ assetCoinNames: string[] = [...this.constants.whitelist.lending]
810
804
  ) {
811
805
  return await getFlashLoanFees(this, assetCoinNames);
812
806
  }
@@ -814,14 +808,14 @@ export class ScallopQuery {
814
808
  /**
815
809
  * Get supply limit of lending pool
816
810
  */
817
- public async getPoolSupplyLimit(poolName: SupportPoolCoins) {
811
+ public async getPoolSupplyLimit(poolName: string) {
818
812
  return await getSupplyLimit(this.utils, poolName);
819
813
  }
820
814
 
821
815
  /**
822
816
  * Get borrow limit of borrow pool
823
817
  */
824
- public async getPoolBorrowLimit(poolName: SupportPoolCoins) {
818
+ public async getPoolBorrowLimit(poolName: string) {
825
819
  return await getBorrowLimit(this.utils, poolName);
826
820
  }
827
821
 
@@ -835,7 +829,7 @@ export class ScallopQuery {
835
829
  /**
836
830
  * Check if asset is an isolated asset
837
831
  */
838
- public async isIsolatedAsset(assetCoinName: SupportAssetCoins) {
832
+ public async isIsolatedAsset(assetCoinName: string) {
839
833
  return isIsolatedAsset(this.utils, assetCoinName);
840
834
  }
841
835
 
@@ -844,7 +838,7 @@ export class ScallopQuery {
844
838
  * @param coinName
845
839
  * @returns price data
846
840
  */
847
- public async getCoinPriceByIndexer(poolName: SupportPoolCoins) {
841
+ public async getCoinPriceByIndexer(poolName: string) {
848
842
  return this.indexer.getCoinPrice(poolName);
849
843
  }
850
844
 
@@ -877,10 +871,9 @@ export class ScallopQuery {
877
871
  * Query all address (lending pool, collateral pool, borrow dynamics, interest models, etc.) of all pool
878
872
  * @returns
879
873
  */
880
- public async getPoolAddresses(
881
- pools: SupportPoolCoins[] = [...SUPPORT_POOLS]
882
- ) {
883
- return getAllAddresses(this, pools);
874
+ public async getPoolAddresses(apiAddressId = this.address.getId()) {
875
+ if (!apiAddressId) throw new Error('apiAddressId is required');
876
+ return getPoolAddresses(apiAddressId);
884
877
  }
885
878
 
886
879
  /**
@@ -915,7 +908,7 @@ export class ScallopQuery {
915
908
  getAssetOracles(this.utils, 'secondary'),
916
909
  ]);
917
910
 
918
- return SUPPORT_POOLS.reduce(
911
+ return [...this.constants.whitelist.lending].reduce(
919
912
  (acc, pool) => {
920
913
  acc[pool] = {
921
914
  primary: primary?.[pool] ?? [],
@@ -923,7 +916,7 @@ export class ScallopQuery {
923
916
  };
924
917
  return acc;
925
918
  },
926
- {} as Record<SupportAssetCoins, xOracleRules>
919
+ {} as Record<string, xOracleRules>
927
920
  );
928
921
  }
929
922
  }