@scallop-io/sui-scallop-sdk 1.3.3 → 1.3.4-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 (103) hide show
  1. package/dist/index.js +1258 -1092
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +1249 -1092
  4. package/dist/index.mjs.map +1 -1
  5. package/package.json +2 -2
  6. package/src/builders/loyaltyProgramBuilder.ts +1 -1
  7. package/src/constants/coinGecko.ts +18 -0
  8. package/src/constants/common.ts +0 -1
  9. package/src/constants/enum.ts +8 -0
  10. package/src/constants/index.ts +6 -0
  11. package/src/constants/poolAddress.ts +94 -0
  12. package/src/constants/pyth.ts +19 -0
  13. package/src/constants/queryKeys.ts +1 -5
  14. package/src/constants/rpc.ts +16 -0
  15. package/src/constants/tokenBucket.ts +1 -1
  16. package/src/models/scallop.ts +3 -2
  17. package/src/models/scallopAddress.ts +2 -2
  18. package/src/models/scallopBuilder.ts +4 -3
  19. package/src/models/scallopCache.ts +1 -1
  20. package/src/models/scallopClient.ts +27 -26
  21. package/src/models/scallopQuery.ts +58 -15
  22. package/src/models/scallopUtils.ts +96 -96
  23. package/src/models/suiKit.ts +11 -0
  24. package/src/queries/borrowIncentiveQuery.ts +6 -13
  25. package/src/queries/coreQuery.ts +37 -22
  26. package/src/queries/loyaltyProgramQuery.ts +1 -1
  27. package/src/queries/portfolioQuery.ts +55 -34
  28. package/src/queries/spoolQuery.ts +17 -17
  29. package/src/types/utils.ts +13 -0
  30. package/src/utils/tokenBucket.ts +2 -1
  31. package/src/utils/util.ts +2 -1
  32. package/dist/builders/borrowIncentiveBuilder.d.ts +0 -12
  33. package/dist/builders/coreBuilder.d.ts +0 -12
  34. package/dist/builders/index.d.ts +0 -12
  35. package/dist/builders/loyaltyProgramBuilder.d.ts +0 -12
  36. package/dist/builders/oracle.d.ts +0 -14
  37. package/dist/builders/referralBuilder.d.ts +0 -12
  38. package/dist/builders/sCoinBuilder.d.ts +0 -4
  39. package/dist/builders/spoolBuilder.d.ts +0 -12
  40. package/dist/builders/vescaBuilder.d.ts +0 -25
  41. package/dist/constants/cache.d.ts +0 -14
  42. package/dist/constants/common.d.ts +0 -20
  43. package/dist/constants/enum.d.ts +0 -13
  44. package/dist/constants/flashloan.d.ts +0 -2
  45. package/dist/constants/index.d.ts +0 -5
  46. package/dist/constants/pyth.d.ts +0 -3
  47. package/dist/constants/queryKeys.d.ts +0 -58
  48. package/dist/constants/testAddress.d.ts +0 -2
  49. package/dist/constants/tokenBucket.d.ts +0 -2
  50. package/dist/constants/vesca.d.ts +0 -5
  51. package/dist/index.d.ts +0 -3
  52. package/dist/models/index.d.ts +0 -8
  53. package/dist/models/scallop.d.ts +0 -74
  54. package/dist/models/scallopAddress.d.ts +0 -150
  55. package/dist/models/scallopBuilder.d.ts +0 -89
  56. package/dist/models/scallopCache.d.ts +0 -74
  57. package/dist/models/scallopClient.d.ts +0 -321
  58. package/dist/models/scallopIndexer.d.ts +0 -89
  59. package/dist/models/scallopPrice.d.ts +0 -0
  60. package/dist/models/scallopQuery.d.ts +0 -474
  61. package/dist/models/scallopUtils.d.ts +0 -217
  62. package/dist/queries/borrowIncentiveQuery.d.ts +0 -61
  63. package/dist/queries/coreQuery.d.ts +0 -167
  64. package/dist/queries/index.d.ts +0 -8
  65. package/dist/queries/isolatedAsset.d.ts +0 -14
  66. package/dist/queries/loyaltyProgramQuery.d.ts +0 -10
  67. package/dist/queries/portfolioQuery.d.ts +0 -73
  68. package/dist/queries/priceQuery.d.ts +0 -16
  69. package/dist/queries/referralQuery.d.ts +0 -7
  70. package/dist/queries/sCoinQuery.d.ts +0 -41
  71. package/dist/queries/spoolQuery.d.ts +0 -70
  72. package/dist/queries/supplyLimit.d.ts +0 -9
  73. package/dist/queries/vescaQuery.d.ts +0 -36
  74. package/dist/types/address.d.ts +0 -107
  75. package/dist/types/builder/borrowIncentive.d.ts +0 -35
  76. package/dist/types/builder/core.d.ts +0 -56
  77. package/dist/types/builder/index.d.ts +0 -24
  78. package/dist/types/builder/loyaltyProgram.d.ts +0 -23
  79. package/dist/types/builder/referral.d.ts +0 -30
  80. package/dist/types/builder/sCoin.d.ts +0 -37
  81. package/dist/types/builder/spool.d.ts +0 -29
  82. package/dist/types/builder/vesca.d.ts +0 -51
  83. package/dist/types/constant/common.d.ts +0 -24
  84. package/dist/types/constant/enum.d.ts +0 -48
  85. package/dist/types/constant/index.d.ts +0 -2
  86. package/dist/types/index.d.ts +0 -6
  87. package/dist/types/model.d.ts +0 -54
  88. package/dist/types/query/borrowIncentive.d.ts +0 -124
  89. package/dist/types/query/core.d.ts +0 -361
  90. package/dist/types/query/index.d.ts +0 -7
  91. package/dist/types/query/loyaltyProgram.d.ts +0 -5
  92. package/dist/types/query/portfolio.d.ts +0 -115
  93. package/dist/types/query/sCoin.d.ts +0 -1
  94. package/dist/types/query/spool.d.ts +0 -122
  95. package/dist/types/query/vesca.d.ts +0 -26
  96. package/dist/types/utils.d.ts +0 -9
  97. package/dist/utils/builder.d.ts +0 -15
  98. package/dist/utils/index.d.ts +0 -5
  99. package/dist/utils/indexer.d.ts +0 -17
  100. package/dist/utils/query.d.ts +0 -62
  101. package/dist/utils/tokenBucket.d.ts +0 -11
  102. package/dist/utils/util.d.ts +0 -26
  103. package/src/models/scallopPrice.ts +0 -0
@@ -35,6 +35,7 @@ import {
35
35
  CollateralStat,
36
36
  SupportMarketCoins,
37
37
  OptionalKeys,
38
+ CoinPrices,
38
39
  } from '../types';
39
40
  import BigNumber from 'bignumber.js';
40
41
  import { getSupplyLimit } from './supplyLimit';
@@ -52,9 +53,10 @@ import { getSupplyLimit } from './supplyLimit';
52
53
  */
53
54
  export const queryMarket = async (
54
55
  query: ScallopQuery,
55
- indexer: boolean = false
56
+ indexer: boolean = false,
57
+ coinPrices?: CoinPrices
56
58
  ) => {
57
- const coinPrices = await query.utils.getCoinPrices();
59
+ coinPrices = coinPrices ?? (await query.utils.getCoinPrices()) ?? {};
58
60
 
59
61
  const pools: MarketPools = {};
60
62
  const collaterals: MarketCollaterals = {};
@@ -63,13 +65,13 @@ export const queryMarket = async (
63
65
  const marketIndexer = await query.indexer.getMarket();
64
66
 
65
67
  const updatePools = (item: MarketPool) => {
66
- item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
68
+ item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
67
69
  item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
68
70
  pools[item.coinName] = item;
69
71
  };
70
72
 
71
73
  const updateCollaterals = (item: MarketCollateral) => {
72
- item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
74
+ item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
73
75
  item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
74
76
  collaterals[item.coinName] = item;
75
77
  };
@@ -230,13 +232,14 @@ export const queryMarket = async (
230
232
  export const getMarketPools = async (
231
233
  query: ScallopQuery,
232
234
  poolCoinNames: SupportPoolCoins[] = [...SUPPORT_POOLS],
233
- indexer: boolean = false
235
+ indexer: boolean = false,
236
+ coinPrices?: CoinPrices
234
237
  ) => {
235
238
  const marketId = query.address.get('core.market');
236
239
  const marketObjectResponse = await query.cache.queryGetObject(marketId, {
237
240
  showContent: true,
238
241
  });
239
- const coinPrices = (await query.utils.getCoinPrices(poolCoinNames)) ?? {};
242
+ coinPrices = (await query.utils.getCoinPrices(poolCoinNames)) ?? {};
240
243
 
241
244
  const marketPools: MarketPools = {};
242
245
 
@@ -246,7 +249,7 @@ export const getMarketPools = async (
246
249
  const updateMarketPool = (marketPool: MarketPool) => {
247
250
  if (!poolCoinNames.includes(marketPool.coinName)) return;
248
251
  marketPool.coinPrice =
249
- coinPrices[marketPool.coinName] || marketPool.coinPrice;
252
+ coinPrices[marketPool.coinName] ?? marketPool.coinPrice;
250
253
  marketPool.coinWrappedType = query.utils.getCoinWrappedType(
251
254
  marketPool.coinName
252
255
  );
@@ -301,12 +304,12 @@ export const getMarketPool = async (
301
304
  let borrowFeeRate: { value: string } | undefined;
302
305
 
303
306
  coinPrice =
304
- coinPrice ||
307
+ coinPrice ??
305
308
  (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
306
309
 
307
310
  if (indexer) {
308
311
  const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
309
- marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
312
+ marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
310
313
  marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
311
314
  marketPoolIndexer.coinName
312
315
  );
@@ -316,7 +319,7 @@ export const getMarketPool = async (
316
319
 
317
320
  const marketId = query.address.get('core.market');
318
321
  marketObject =
319
- marketObject ||
322
+ marketObject ??
320
323
  (
321
324
  await query.cache.queryGetObject(marketId, {
322
325
  showContent: true,
@@ -340,7 +343,10 @@ export const getMarketPool = async (
340
343
  },
341
344
  },
342
345
  });
343
- if (!balanceSheetDynamicFieldObjectResponse) return undefined;
346
+ if (!balanceSheetDynamicFieldObjectResponse)
347
+ throw new Error(
348
+ `Failed to fetch balanceSheetDynamicFieldObjectResponse for ${poolCoinName}`
349
+ );
344
350
 
345
351
  const balanceSheetDynamicFieldObject =
346
352
  balanceSheetDynamicFieldObjectResponse.data;
@@ -367,7 +373,10 @@ export const getMarketPool = async (
367
373
  },
368
374
  },
369
375
  });
370
- if (!borrowIndexDynamicFieldObjectResponse) return undefined;
376
+ if (!borrowIndexDynamicFieldObjectResponse)
377
+ throw new Error(
378
+ `Failed to fetch borrowIndexDynamicFieldObjectResponse for ${poolCoinName}`
379
+ );
371
380
 
372
381
  const borrowIndexDynamicFieldObject =
373
382
  borrowIndexDynamicFieldObjectResponse.data;
@@ -395,7 +404,10 @@ export const getMarketPool = async (
395
404
  },
396
405
  });
397
406
 
398
- if (!interestModelDynamicFieldObjectResponse) return undefined;
407
+ if (!interestModelDynamicFieldObjectResponse)
408
+ throw new Error(
409
+ `Failed to fetch interestModelDynamicFieldObjectResponse for ${poolCoinName}`
410
+ );
399
411
  const interestModelDynamicFieldObject =
400
412
  interestModelDynamicFieldObjectResponse.data;
401
413
  if (
@@ -422,7 +434,10 @@ export const getMarketPool = async (
422
434
  },
423
435
  });
424
436
 
425
- if (!borrowFeeDynamicFieldObjectResponse) return undefined;
437
+ if (!borrowFeeDynamicFieldObjectResponse)
438
+ throw new Error(
439
+ `Failed to fetch borrowFeeDynamicFieldObjectResponse for ${poolCoinName}`
440
+ );
426
441
  const borrowFeeDynamicFieldObject =
427
442
  borrowFeeDynamicFieldObjectResponse.data;
428
443
  if (
@@ -455,7 +470,7 @@ export const getMarketPool = async (
455
470
  reserve: balanceSheet.revenue,
456
471
  reserveFactor: interestModel.revenue_factor.fields,
457
472
  borrowWeight: interestModel.borrow_weight.fields,
458
- borrowFeeRate: borrowFeeRate || { value: '0' },
473
+ borrowFeeRate: borrowFeeRate ?? { value: '0' },
459
474
  baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
460
475
  borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
461
476
  borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
@@ -531,7 +546,7 @@ export const getMarketCollaterals = async (
531
546
  const updateMarketCollateral = (marketCollateral: MarketCollateral) => {
532
547
  if (!collateralCoinNames.includes(marketCollateral.coinName)) return;
533
548
  marketCollateral.coinPrice =
534
- coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
549
+ coinPrices[marketCollateral.coinName] ?? marketCollateral.coinPrice;
535
550
  marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
536
551
  marketCollateral.coinName
537
552
  );
@@ -590,7 +605,7 @@ export const getMarketCollateral = async (
590
605
  const marketCollateralIndexer =
591
606
  await query.indexer.getMarketCollateral(collateralCoinName);
592
607
  marketCollateralIndexer.coinPrice =
593
- coinPrice || marketCollateralIndexer.coinPrice;
608
+ coinPrice ?? marketCollateralIndexer.coinPrice;
594
609
  marketCollateralIndexer.coinWrappedType = query.utils.getCoinWrappedType(
595
610
  marketCollateralIndexer.coinName
596
611
  );
@@ -724,7 +739,7 @@ export const getObligations = async (
724
739
  ownerAddress: string
725
740
  ) => {
726
741
  const owner = ownerAddress;
727
- const protocolObjectId = address.get('core.object') || PROTOCOL_OBJECT_ID;
742
+ const protocolObjectId = address.get('core.object') ?? PROTOCOL_OBJECT_ID;
728
743
  const keyObjectsResponse: SuiObjectResponse[] = [];
729
744
  let hasNextPage = false;
730
745
  let nextCursor: string | null | undefined = null;
@@ -854,7 +869,7 @@ export const getCoinAmounts = async (
854
869
  assetCoinNames: SupportAssetCoins[] = [...SUPPORT_POOLS],
855
870
  ownerAddress?: string
856
871
  ) => {
857
- const owner = ownerAddress || query.suiKit.currentAddress();
872
+ const owner = ownerAddress ?? query.suiKit.currentAddress();
858
873
  const assetCoins = {} as OptionalKeys<Record<SupportAssetCoins, number>>;
859
874
 
860
875
  await Promise.allSettled(
@@ -880,7 +895,7 @@ export const getCoinAmount = async (
880
895
  assetCoinName: SupportAssetCoins,
881
896
  ownerAddress?: string
882
897
  ) => {
883
- const owner = ownerAddress || query.suiKit.currentAddress();
898
+ const owner = ownerAddress ?? query.suiKit.currentAddress();
884
899
  const coinType = query.utils.parseCoinType(assetCoinName);
885
900
  const amount = await query.cache.queryGetCoinBalance({
886
901
  owner,
@@ -907,7 +922,7 @@ export const getMarketCoinAmounts = async (
907
922
  [...SUPPORT_POOLS].map((poolCoinName) =>
908
923
  query.utils.parseMarketCoinName(poolCoinName)
909
924
  );
910
- const owner = ownerAddress || query.suiKit.currentAddress();
925
+ const owner = ownerAddress ?? query.suiKit.currentAddress();
911
926
  const marketCoins = {} as OptionalKeys<Record<SupportMarketCoins, number>>;
912
927
 
913
928
  await Promise.allSettled(
@@ -937,7 +952,7 @@ export const getMarketCoinAmount = async (
937
952
  marketCoinName: SupportMarketCoins,
938
953
  ownerAddress?: string
939
954
  ) => {
940
- const owner = ownerAddress || query.suiKit.currentAddress();
955
+ const owner = ownerAddress ?? query.suiKit.currentAddress();
941
956
  const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
942
957
  const amount = await query.cache.queryGetCoinBalance({
943
958
  owner,
@@ -53,7 +53,7 @@ export const getLoyaltyProgramInformations = async (
53
53
  };
54
54
 
55
55
  // query the user pending reward if exist
56
- veScaKey = veScaKey || (await query.getVeScas())[0]?.keyObject;
56
+ veScaKey = veScaKey ?? (await query.getVeScas())[0]?.keyObject;
57
57
  if (!veScaKey) return result;
58
58
 
59
59
  const userRewardTableId = query.address.get(
@@ -1,6 +1,7 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import {
3
3
  SUPPORT_BORROW_INCENTIVE_REWARDS,
4
+ SUPPORT_COLLATERALS,
4
5
  SUPPORT_POOLS,
5
6
  SUPPORT_SPOOLS,
6
7
  } from '../constants';
@@ -49,20 +50,18 @@ export const getLendings = async (
49
50
  (SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
50
51
  ) as SupportStakeMarketCoins[];
51
52
 
52
- const [
53
+ const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
54
+ const marketPools = await query.getMarketPools(poolCoinNames, indexer, {
55
+ coinPrices,
56
+ });
57
+ const spools = await query.getSpools(stakeMarketCoinNames, indexer, {
53
58
  marketPools,
54
- spools,
55
- coinAmounts,
56
- marketCoinAmounts,
57
- allStakeAccounts,
58
59
  coinPrices,
59
- ] = await Promise.all([
60
- query.getMarketPools(poolCoinNames, indexer),
61
- query.getSpools(stakeMarketCoinNames, indexer),
60
+ });
61
+ const [coinAmounts, marketCoinAmounts, allStakeAccounts] = await Promise.all([
62
62
  query.getCoinAmounts(poolCoinNames, ownerAddress),
63
63
  query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
64
64
  query.getAllStakeAccounts(ownerAddress),
65
- query.utils.getCoinPrices(poolCoinNames),
66
65
  ]);
67
66
 
68
67
  const lendings: Lendings = {};
@@ -80,7 +79,7 @@ export const getLendings = async (
80
79
  indexer,
81
80
  marketPools?.[poolCoinName],
82
81
  stakeMarketCoinName ? spools[stakeMarketCoinName] : undefined,
83
- stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : undefined,
82
+ stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : [],
84
83
  coinAmounts?.[poolCoinName],
85
84
  marketCoinAmounts?.[marketCoinName],
86
85
  coinPrices?.[poolCoinName] ?? 0
@@ -122,12 +121,37 @@ export const getLending = async (
122
121
  sCoinAmount?: number
123
122
  ) => {
124
123
  const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
125
- marketPool = marketPool || (await query.getMarketPool(poolCoinName, indexer));
124
+ coinPrice =
125
+ coinPrice ??
126
+ (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ??
127
+ 0;
128
+
129
+ marketPool =
130
+ marketPool ??
131
+ (await query.getMarketPool(poolCoinName, indexer, {
132
+ coinPrice,
133
+ }));
134
+
135
+ if (!marketPool)
136
+ throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
137
+
126
138
  spool =
127
- spool ||
128
- (SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
129
- ? await query.getSpool(marketCoinName as SupportStakeMarketCoins, indexer)
139
+ (spool ??
140
+ (SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName))
141
+ ? await query.getSpool(
142
+ marketCoinName as SupportStakeMarketCoins,
143
+ indexer,
144
+ {
145
+ marketPool,
146
+ coinPrices: {
147
+ [poolCoinName]: coinPrice,
148
+ },
149
+ }
150
+ )
130
151
  : undefined;
152
+ // some pool does not have spool
153
+ // if (!spool) throw new Error(`Failed to fetch spool for ${poolCoinName}`);
154
+
131
155
  stakeAccounts =
132
156
  stakeAccounts ||
133
157
  (SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
@@ -143,9 +167,6 @@ export const getLending = async (
143
167
  (await query.getMarketCoinAmount(marketCoinName, ownerAddress));
144
168
  sCoinAmount =
145
169
  sCoinAmount || (await query.getSCoinAmount(marketCoinName, ownerAddress));
146
- coinPrice =
147
- coinPrice ||
148
- (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
149
170
  const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
150
171
 
151
172
  // Handle staked scoin
@@ -289,10 +310,12 @@ export const getObligationAccounts = async (
289
310
  ownerAddress?: string,
290
311
  indexer: boolean = false
291
312
  ) => {
292
- const market = await query.queryMarket(indexer);
293
313
  const coinPrices = await query.utils.getCoinPrices();
294
- const coinAmounts = await query.getCoinAmounts(undefined, ownerAddress);
295
- const obligations = await query.getObligations(ownerAddress);
314
+ const market = await query.queryMarket(indexer, { coinPrices });
315
+ const [coinAmounts, obligations] = await Promise.all([
316
+ query.getCoinAmounts(undefined, ownerAddress),
317
+ query.getObligations(ownerAddress),
318
+ ]);
296
319
 
297
320
  const obligationAccounts: ObligationAccounts = {};
298
321
  await Promise.allSettled(
@@ -329,27 +352,25 @@ export const getObligationAccount = async (
329
352
  coinPrices?: CoinPrices,
330
353
  coinAmounts?: CoinAmounts
331
354
  ) => {
332
- market = market || (await query.queryMarket(indexer));
333
355
  const collateralAssetCoinNames: SupportCollateralCoins[] = [
334
- ...new Set([
335
- ...Object.values(market.collaterals).map(
336
- (collateral) => collateral.coinName
337
- ),
338
- ]),
356
+ ...SUPPORT_COLLATERALS,
339
357
  ];
340
- const obligationQuery = await query.queryObligation(obligationId);
341
- const borrowIncentivePools = await query.getBorrowIncentivePools(
342
- undefined,
343
- indexer
344
- );
345
- const borrowIncentiveAccounts =
346
- await query.getBorrowIncentiveAccounts(obligationId);
347
358
  coinPrices =
348
- coinPrices || (await query.utils.getCoinPrices(collateralAssetCoinNames));
359
+ coinPrices ?? (await query.utils.getCoinPrices(collateralAssetCoinNames));
360
+ market = market ?? (await query.queryMarket(indexer, { coinPrices }));
349
361
  coinAmounts =
350
362
  coinAmounts ||
351
363
  (await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress));
352
364
 
365
+ const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] =
366
+ await Promise.all([
367
+ query.queryObligation(obligationId),
368
+ query.getBorrowIncentivePools(undefined, indexer, {
369
+ coinPrices,
370
+ }),
371
+ query.getBorrowIncentiveAccounts(obligationId),
372
+ ]);
373
+
353
374
  const collaterals: ObligationAccount['collaterals'] = {};
354
375
  const debts: ObligationAccount['debts'] = {};
355
376
  const borrowIncentives: ObligationAccount['borrowIncentives'] = {};
@@ -19,6 +19,7 @@ import type {
19
19
  SupportStakeMarketCoins,
20
20
  SupportStakeCoins,
21
21
  CoinPrices,
22
+ MarketPools,
22
23
  } from '../types';
23
24
 
24
25
  /**
@@ -32,22 +33,20 @@ import type {
32
33
  export const getSpools = async (
33
34
  query: ScallopQuery,
34
35
  stakeMarketCoinNames: SupportStakeMarketCoins[] = [...SUPPORT_SPOOLS],
35
- indexer: boolean = false
36
+ indexer: boolean = false,
37
+ marketPools?: MarketPools,
38
+ coinPrices?: CoinPrices
36
39
  ) => {
37
40
  const stakeCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) =>
38
41
  query.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName)
39
42
  );
40
- const rewardCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) => {
41
- const rewardCoinName =
42
- query.utils.getSpoolRewardCoinName(stakeMarketCoinName);
43
- return rewardCoinName;
44
- });
45
- const coinPrices =
46
- (await query.utils.getCoinPrices([
47
- ...new Set([...stakeCoinNames, ...rewardCoinNames]),
48
- ])) ?? {};
43
+ coinPrices = coinPrices ?? (await query.utils.getCoinPrices()) ?? {};
44
+
45
+ marketPools =
46
+ marketPools ?? (await query.getMarketPools(stakeCoinNames, indexer));
47
+ if (!marketPools)
48
+ throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
49
49
 
50
- const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
51
50
  const spools: Spools = {};
52
51
 
53
52
  if (indexer) {
@@ -61,12 +60,13 @@ export const getSpools = async (
61
60
  spool.marketCoinName
62
61
  );
63
62
  const marketPool = marketPools[coinName];
64
- spool.coinPrice = coinPrices[coinName] || spool.coinPrice;
65
- spool.marketCoinPrice =
66
- (coinPrices[coinName] ?? 0) *
67
- (marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
63
+ spool.coinPrice = coinPrices[coinName] ?? spool.coinPrice;
64
+ spool.marketCoinPrice = coinPrices[coinName]
65
+ ? (coinPrices[coinName] ?? 0) *
66
+ (marketPool ? marketPool.conversionRate : 0)
67
+ : spool.marketCoinPrice;
68
68
  spool.rewardCoinPrice =
69
- coinPrices[rewardCoinName] || spool.rewardCoinPrice;
69
+ coinPrices[rewardCoinName] ?? spool.rewardCoinPrice;
70
70
  spools[spool.marketCoinName] = spool;
71
71
  };
72
72
  Object.values(spoolsIndexer).forEach(updateSpools);
@@ -114,7 +114,7 @@ export const getSpool = async (
114
114
  const coinName = query.utils.parseCoinName<SupportStakeCoins>(marketCoinName);
115
115
  marketPool = marketPool || (await query.getMarketPool(coinName, indexer));
116
116
  if (!marketPool) {
117
- throw new Error('Fail to fetch marketPool');
117
+ throw new Error(`Fail to fetch marketPool for ${coinName}`);
118
118
  }
119
119
 
120
120
  const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
@@ -13,3 +13,16 @@ export type PriceMap = Map<
13
13
  publishTime: number;
14
14
  }
15
15
  >;
16
+
17
+ export type PoolAddressInfo = {
18
+ name: string;
19
+ coingeckoId: string;
20
+ decimal: number;
21
+ pythFeedId: string;
22
+ lendingPoolAddress: string;
23
+ collateralPoolAddress: string;
24
+ sCoinAddress: string | undefined;
25
+ marketCoinAddress: string;
26
+ coinAddress: string;
27
+ sCoinName: string | undefined;
28
+ };
@@ -38,7 +38,7 @@ const callWithRateLimit = async <T>(
38
38
  tokenBucket: TokenBucket,
39
39
  fn: () => Promise<T>,
40
40
  retryDelayInMs = DEFAULT_INTERVAL_IN_MS,
41
- maxRetries = 15,
41
+ maxRetries = 30,
42
42
  backoffFactor = 1.25 // The factor by which to increase the delay
43
43
  ): Promise<T | null> => {
44
44
  let retries = 0;
@@ -65,6 +65,7 @@ const callWithRateLimit = async <T>(
65
65
  await new Promise((resolve) => setTimeout(resolve, delay));
66
66
  return tryRequest();
67
67
  } else {
68
+ // console.error(error);
68
69
  console.error('An error occurred:', error.message);
69
70
  return null;
70
71
  }
package/src/utils/util.ts CHANGED
@@ -14,6 +14,7 @@ import type {
14
14
  SupportAssetCoins,
15
15
  SupportCoins,
16
16
  SupportMarketCoins,
17
+ SupportSCoin,
17
18
  SupportSuiBridgeCoins,
18
19
  SupportWormholeCoins,
19
20
  } from '../types';
@@ -30,7 +31,7 @@ const COIN_SET = Array.from(
30
31
 
31
32
  export const isMarketCoin = (
32
33
  coinName: SupportCoins
33
- ): coinName is SupportMarketCoins => {
34
+ ): coinName is SupportMarketCoins | SupportSCoin => {
34
35
  const assetCoinName = coinName.slice(1).toLowerCase() as SupportAssetCoins;
35
36
  return (
36
37
  coinName.charAt(0).toLowerCase() === 's' && COIN_SET.includes(assetCoinName)
@@ -1,12 +0,0 @@
1
- import { Transaction } from '@mysten/sui/transactions';
2
- import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
3
- import type { ScallopBuilder } from 'src/models';
4
- import type { BorrowIncentiveTxBlock, ScallopTxBlock } from '../types';
5
- /**
6
- * Create an enhanced transaction block instance for interaction with borrow incentive modules of the Scallop contract.
7
- *
8
- * @param builder - Scallop builder instance.
9
- * @param initTxBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
10
- * @return Scallop borrow incentive txBlock.
11
- */
12
- export declare const newBorrowIncentiveTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction) => BorrowIncentiveTxBlock;
@@ -1,12 +0,0 @@
1
- import { Transaction } from '@mysten/sui/transactions';
2
- import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
3
- import type { ScallopBuilder } from '../models';
4
- import type { CoreTxBlock, ScallopTxBlock, SuiTxBlockWithSpool } from '../types';
5
- /**
6
- * Create an enhanced transaction block instance for interaction with core modules of the Scallop contract.
7
- *
8
- * @param builder - Scallop builder instance.
9
- * @param initTxBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
10
- * @return Scallop core txBlock.
11
- */
12
- export declare const newCoreTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction | SuiTxBlockWithSpool) => CoreTxBlock;
@@ -1,12 +0,0 @@
1
- import { Transaction } from '@mysten/sui/transactions';
2
- import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
3
- import type { ScallopBuilder } from '../models';
4
- import type { ScallopTxBlock } from '../types';
5
- /**
6
- * Create a new ScallopTxBlock instance.
7
- *
8
- * @param builder - Scallop builder instance.
9
- * @param txBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
10
- * @return ScallopTxBlock.
11
- */
12
- export declare const newScallopTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction) => ScallopTxBlock;
@@ -1,12 +0,0 @@
1
- import { Transaction } from '@mysten/sui/transactions';
2
- import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
3
- import { ScallopBuilder } from 'src/models';
4
- import { LoyaltyProgramTxBlock, ScallopTxBlock } from 'src/types';
5
- /**
6
- * Create an enhanced transaction block instance for interaction with loyalty program modules of the Scallop contract.
7
- *
8
- * @param builder - Scallop builder instance.
9
- * @param initTxBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
10
- * @return Scallop loyalty program txBlock.
11
- */
12
- export declare const newLoyaltyProgramTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction) => LoyaltyProgramTxBlock;
@@ -1,14 +0,0 @@
1
- import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
2
- import type { ScallopBuilder } from '../models';
3
- import type { SupportAssetCoins } from '../types';
4
- /**
5
- * Update the price of the oracle for multiple coin.
6
- *
7
- * @param builder - The scallop builder.
8
- * @param txBlock - TxBlock created by SuiKit.
9
- * @param assetCoinNames - Specific an array of support asset coin name.
10
- * @param options - The options for update oracles.
11
- */
12
- export declare const updateOracles: (builder: ScallopBuilder, txBlock: SuiKitTxBlock, assetCoinNames?: SupportAssetCoins[], options?: {
13
- usePythPullModel: boolean;
14
- }) => Promise<void>;
@@ -1,12 +0,0 @@
1
- import { ScallopBuilder } from 'src/models';
2
- import { ScallopTxBlock } from 'src/types';
3
- import { SuiTxBlock as SuiKitTxBlock, Transaction } from '@scallop-io/sui-kit';
4
- import { ReferralTxBlock } from 'src/types/builder/referral';
5
- /**
6
- * Create an enhanced transaction block instance for interaction with borrow incentive modules of the Scallop contract.
7
- *
8
- * @param builder - Scallop builder instance.
9
- * @param initTxBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
10
- * @return Scallop referral txBlock.
11
- */
12
- export declare const newReferralTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction) => ReferralTxBlock;
@@ -1,4 +0,0 @@
1
- import { Transaction, SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
2
- import { ScallopBuilder } from 'src/models';
3
- import { BaseScallopTxBlock, SCoinTxBlock, ScallopTxBlock } from 'src/types';
4
- export declare const newSCoinTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction | BaseScallopTxBlock) => SCoinTxBlock;
@@ -1,12 +0,0 @@
1
- import { Transaction } from '@mysten/sui/transactions';
2
- import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
3
- import type { ScallopBuilder } from '../models';
4
- import type { SpoolTxBlock, ScallopTxBlock, SuiTxBlockWithSCoin } from '../types';
5
- /**
6
- * Create an enhanced transaction block instance for interaction with spool modules of the Scallop contract.
7
- *
8
- * @param builder - Scallop builder instance.
9
- * @param initTxBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
10
- * @return Scallop spool txBlock.
11
- */
12
- export declare const newSpoolTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction | SuiTxBlockWithSCoin) => SpoolTxBlock;
@@ -1,25 +0,0 @@
1
- import { SuiTxBlock, Transaction, SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
2
- import { ScallopBuilder } from '../models';
3
- import type { SuiObjectArg } from '@scallop-io/sui-kit';
4
- import type { ScallopTxBlock, VeScaTxBlock } from 'src/types';
5
- /**
6
- * Check and get veSCA data from transaction block.
7
- *
8
- * @description
9
- * If the veScaKey id is provided, directly return it.
10
- * Otherwise, automatically get veScaKey from the sender.
11
- *
12
- * @param builder - Scallop builder instance.
13
- * @param txBlock - TxBlock created by SuiKit.
14
- * @param veScaKey - veSCA key.
15
- * @return veSCA key, ID, locked amount and unlock at timestamp.
16
- */
17
- export declare const requireVeSca: (builder: ScallopBuilder, SuiTxBlock: SuiTxBlock, veScaKey?: SuiObjectArg | undefined) => Promise<import("src/types").Vesca | undefined>;
18
- /**
19
- * Create an enhanced transaction block instance for interaction with veSCA modules of the Scallop contract.
20
- *
21
- * @param builder - Scallop builder instance.
22
- * @param initTxBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
23
- * @return Scallop borrow incentive txBlock.
24
- */
25
- export declare const newVeScaTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction) => VeScaTxBlock;
@@ -1,14 +0,0 @@
1
- /**
2
- * Default cache options for the QueryClient.
3
- * @type {QueryClientConfig}
4
- * @description Default cache options for the QueryClient
5
- * We set the default to 5s to prevent duplicate requests from being requested (e.g. query MarketObject, etc.)
6
- */
7
- export declare const DEFAULT_CACHE_OPTIONS: {
8
- defaultOptions: {
9
- queries: {
10
- staleTime: number;
11
- gcTime: number;
12
- };
13
- };
14
- };
@@ -1,20 +0,0 @@
1
- export declare const API_BASE_URL: "https://sui.apis.scallop.io";
2
- export declare const SDK_API_BASE_URL: "https://sdk.api.scallop.io";
3
- export declare const IS_VE_SCA_TEST: boolean;
4
- export declare const USE_TEST_ADDRESS: boolean;
5
- export declare const ADDRESSES_ID: "65fb07c39c845425d71d7b18" | "66f8e7ed9bb9e07fdfb86bbb";
6
- export declare const PROTOCOL_OBJECT_ID: "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" | "0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";
7
- export declare const BORROW_FEE_PROTOCOL_ID: "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" | "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
8
- export declare const SCA_COIN_TYPE: "0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA" | "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA";
9
- export declare const OLD_BORROW_INCENTIVE_PROTOCOL_ID: "0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410";
10
- export declare const SUPPORT_POOLS: readonly ["usdc", "sbeth", "weth", "wbtc", "wusdc", "wusdt", "sui", "wapt", "wsol", "cetus", "afsui", "hasui", "vsui", "sca"];
11
- export declare const SUPPORT_COLLATERALS: readonly ["usdc", "sbeth", "weth", "wbtc", "wusdc", "wusdt", "sui", "wapt", "wsol", "cetus", "afsui", "hasui", "vsui", "sca"];
12
- export declare const SUPPORT_SPOOLS: readonly ["susdc", "sweth", "ssui", "swusdc", "swusdt", "scetus", "safsui", "shasui", "svsui"];
13
- export declare const SUPPORT_SCOIN: readonly ["susdc", "ssbeth", "ssui", "swusdc", "swusdt", "safsui", "shasui", "svsui", "sweth", "ssca", "scetus", "swsol", "swbtc"];
14
- export declare const SUPPORT_SUI_BRIDGE: readonly ["sbeth"];
15
- export declare const SUPPORT_WORMHOLE: readonly ["wusdc", "wusdt", "weth", "wbtc", "wapt", "wsol"];
16
- export declare const SUPPORT_SPOOLS_REWARDS: readonly ["sui"];
17
- export declare const SUPPORT_BORROW_INCENTIVE_POOLS: readonly ["sui", "wusdc", "wusdt", "afsui", "hasui", "vsui", "weth", "sbeth", "sca", "usdc"];
18
- export declare const SUPPORT_BORROW_INCENTIVE_REWARDS: readonly ["sui", "sca"];
19
- export declare const SUPPORT_ORACLES: readonly ["supra", "switchboard", "pyth"];
20
- export declare const SUPPORT_PACKAGES: readonly ["coinDecimalsRegistry", "math", "whitelist", "x", "protocol", "protocolWhitelist", "query", "supra", "pyth", "switchboard", "xOracle", "testCoin"];