@scallop-io/sui-scallop-sdk 1.4.1 → 1.4.2-rc.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 (80) hide show
  1. package/dist/constants/common.d.ts +1 -1
  2. package/dist/constants/poolAddress.d.ts +16 -4
  3. package/dist/constants/queryKeys.d.ts +2 -2
  4. package/dist/constants/tokenBucket.d.ts +2 -2
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +1270 -588
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +1225 -544
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/models/scallopBuilder.d.ts +2 -1
  11. package/dist/models/scallopCache.d.ts +2 -0
  12. package/dist/models/scallopQuery.d.ts +38 -20
  13. package/dist/models/scallopUtils.d.ts +4 -2
  14. package/dist/queries/borrowIncentiveQuery.d.ts +12 -0
  15. package/dist/queries/coreQuery.d.ts +18 -19
  16. package/dist/queries/index.d.ts +2 -0
  17. package/dist/queries/isolatedAssetQuery.d.ts +2 -2
  18. package/dist/queries/objectsQuery.d.ts +3 -0
  19. package/dist/queries/poolAddressesQuery.d.ts +18 -0
  20. package/dist/queries/spoolQuery.d.ts +6 -2
  21. package/dist/test.d.ts +1 -0
  22. package/dist/types/builder/borrowIncentive.d.ts +5 -5
  23. package/dist/types/builder/core.d.ts +20 -16
  24. package/dist/types/builder/loyaltyProgram.d.ts +1 -1
  25. package/dist/types/builder/referral.d.ts +4 -4
  26. package/dist/types/builder/sCoin.d.ts +2 -2
  27. package/dist/types/builder/spool.d.ts +4 -4
  28. package/dist/types/builder/vesca.d.ts +6 -6
  29. package/dist/types/query/core.d.ts +22 -5
  30. package/dist/types/query/spool.d.ts +20 -0
  31. package/dist/types/utils.d.ts +7 -2
  32. package/dist/utils/core.d.ts +2 -0
  33. package/dist/utils/index.d.ts +2 -0
  34. package/dist/utils/query.d.ts +1 -1
  35. package/dist/utils/util.d.ts +1 -0
  36. package/package.json +7 -7
  37. package/src/builders/borrowIncentiveBuilder.ts +28 -15
  38. package/src/builders/coreBuilder.ts +76 -49
  39. package/src/builders/loyaltyProgramBuilder.ts +4 -3
  40. package/src/builders/referralBuilder.ts +23 -10
  41. package/src/builders/sCoinBuilder.ts +8 -6
  42. package/src/builders/spoolBuilder.ts +21 -14
  43. package/src/builders/vescaBuilder.ts +23 -13
  44. package/src/constants/common.ts +1 -12
  45. package/src/constants/poolAddress.ts +336 -10
  46. package/src/constants/queryKeys.ts +9 -5
  47. package/src/constants/testAddress.ts +42 -0
  48. package/src/constants/tokenBucket.ts +2 -2
  49. package/src/index.ts +1 -0
  50. package/src/models/scallopBuilder.ts +59 -2
  51. package/src/models/scallopCache.ts +171 -19
  52. package/src/models/scallopClient.ts +16 -10
  53. package/src/models/scallopQuery.ts +36 -28
  54. package/src/models/scallopUtils.ts +11 -4
  55. package/src/queries/borrowIncentiveQuery.ts +6 -8
  56. package/src/queries/borrowLimitQuery.ts +1 -0
  57. package/src/queries/coreQuery.ts +408 -258
  58. package/src/queries/index.ts +2 -0
  59. package/src/queries/isolatedAssetQuery.ts +37 -31
  60. package/src/queries/objectsQuery.ts +20 -0
  61. package/src/queries/poolAddressesQuery.ts +146 -0
  62. package/src/queries/portfolioQuery.ts +31 -13
  63. package/src/queries/priceQuery.ts +3 -1
  64. package/src/queries/spoolQuery.ts +189 -122
  65. package/src/test.ts +17 -0
  66. package/src/types/builder/borrowIncentive.ts +8 -5
  67. package/src/types/builder/core.ts +23 -17
  68. package/src/types/builder/loyaltyProgram.ts +1 -1
  69. package/src/types/builder/referral.ts +6 -4
  70. package/src/types/builder/sCoin.ts +2 -2
  71. package/src/types/builder/spool.ts +4 -4
  72. package/src/types/builder/vesca.ts +9 -6
  73. package/src/types/query/core.ts +21 -5
  74. package/src/types/query/spool.ts +21 -0
  75. package/src/types/utils.ts +8 -3
  76. package/src/utils/core.ts +18 -0
  77. package/src/utils/index.ts +2 -0
  78. package/src/utils/query.ts +21 -5
  79. package/src/utils/tokenBucket.ts +9 -29
  80. package/src/utils/util.ts +8 -0
@@ -232,13 +232,14 @@ export class ScallopUtils {
232
232
  }
233
233
 
234
234
  /**
235
- * Convert sCoin name to coin name.
235
+ * Convert sCoin name to market coin name.
236
236
  * This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
237
237
  * e.g: `scallop_sui -> ssui
238
+ * if no `scallop_...` is encountered, return coinName
238
239
  * @return sCoin name
239
240
  */
240
- public parseCoinNameFromSCoinName(coinName: string) {
241
- return sCoinRawNameToName[coinName];
241
+ public parseSCoinTypeNameToMarketCoinName(coinName: string) {
242
+ return sCoinRawNameToName[coinName] ?? coinName;
242
243
  }
243
244
 
244
245
  /**
@@ -311,8 +312,14 @@ export class ScallopUtils {
311
312
  public parseCoinNameFromType<T extends SupportCoins>(
312
313
  coinType: string
313
314
  ): T extends SupportCoins ? T : SupportCoins;
315
+ public parseCoinNameFromType<T extends SupportSCoin>(
316
+ coinType: string
317
+ ): T extends SupportSCoin ? T : SupportSCoin;
314
318
  public parseCoinNameFromType(coinType: string) {
315
319
  coinType = normalizeStructTag(coinType);
320
+ if (sCoinTypeToName[coinType]) {
321
+ return sCoinTypeToName[coinType] as SupportSCoin;
322
+ }
316
323
 
317
324
  const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
318
325
  const coinTypeMatch = coinType.match(coinTypeRegex);
@@ -553,7 +560,7 @@ export class ScallopUtils {
553
560
  const priceIds = priceIdPairs.map(([_, priceId]) => priceId);
554
561
 
555
562
  const pythConnection = new SuiPriceServiceConnection(endpoint, {
556
- timeout: 2000,
563
+ timeout: 4000,
557
564
  });
558
565
 
559
566
  try {
@@ -1,6 +1,5 @@
1
1
  import { normalizeStructTag } from '@mysten/sui/utils';
2
2
  import {
3
- sCoinRawNameToName,
4
3
  SUPPORT_BORROW_INCENTIVE_POOLS,
5
4
  SUPPORT_BORROW_INCENTIVE_REWARDS,
6
5
  } from '../constants';
@@ -66,7 +65,7 @@ export const getBorrowIncentivePools = async (
66
65
  const borrowIncentivePools: BorrowIncentivePools = {};
67
66
  marketPools =
68
67
  marketPools ??
69
- (await query.getMarketPools(undefined, { coinPrices, indexer }));
68
+ (await query.getMarketPools(undefined, { coinPrices, indexer })).pools;
70
69
  coinPrices = coinPrices ?? (await query.getAllCoinPrices({ marketPools }));
71
70
 
72
71
  if (indexer) {
@@ -100,8 +99,10 @@ export const getBorrowIncentivePools = async (
100
99
  const borrowIncentivePoolPoints: OptionalKeys<
101
100
  Record<SupportBorrowIncentiveRewardCoins, BorrowIncentivePoolPoints>
102
101
  > = {};
103
- const parsedBorrowIncentivePoolData =
104
- parseOriginBorrowIncentivePoolData(pool);
102
+ const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(
103
+ query.utils,
104
+ pool
105
+ );
105
106
 
106
107
  const poolCoinType = normalizeStructTag(pool.pool_type.name);
107
108
  const poolCoinName =
@@ -121,13 +122,10 @@ export const getBorrowIncentivePools = async (
121
122
  parsedBorrowIncentivePoolData.poolPoints
122
123
  )) {
123
124
  const rewardCoinType = poolPoint.pointType;
124
- let rewardCoinName = query.utils.parseCoinNameFromType(
125
+ const rewardCoinName = query.utils.parseCoinNameFromType(
125
126
  rewardCoinType
126
127
  ) as SupportBorrowIncentiveRewardCoins;
127
128
  // handle for scoin name
128
- if (sCoinRawNameToName[rewardCoinName]) {
129
- rewardCoinName = sCoinRawNameToName[rewardCoinName];
130
- }
131
129
  const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
132
130
  const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
133
131
 
@@ -19,6 +19,7 @@ const borrowLimitZod = zod.object({
19
19
 
20
20
  const borrowLimitKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::BorrowLimitKey`; // prod
21
21
  // const borrowLimitKeyType = `0xb784ea287d944e478a3ceaa071f8885072cce6b7224cf245914dc2f9963f460e::market_dynamic_keys::BorrowLimitKey`;
22
+
22
23
  /**
23
24
  * Return supply limit of a pool (including the decimals)
24
25
  * @param utils