@scallop-io/sui-scallop-sdk 0.46.37 → 0.46.38

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "0.46.37",
3
+ "version": "0.46.38",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -396,17 +396,18 @@ export class ScallopQuery {
396
396
  ) {
397
397
  stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
398
398
  const stakeRewardPools: StakeRewardPools = {};
399
- for (const stakeMarketCoinName of stakeMarketCoinNames) {
400
- const stakeRewardPool = await getStakeRewardPool(
401
- this,
402
- stakeMarketCoinName
403
- );
404
-
405
- if (stakeRewardPool) {
406
- stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
407
- }
408
- }
409
-
399
+ await Promise.allSettled(
400
+ stakeMarketCoinNames.map(async (stakeMarketCoinName) => {
401
+ const stakeRewardPool = await getStakeRewardPool(
402
+ this,
403
+ stakeMarketCoinName
404
+ );
405
+
406
+ if (stakeRewardPool) {
407
+ stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
408
+ }
409
+ })
410
+ );
410
411
  return stakeRewardPools;
411
412
  }
412
413
 
@@ -37,14 +37,6 @@ export const queryBorrowIncentivePools = async (
37
37
  borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
38
38
  ...SUPPORT_BORROW_INCENTIVE_POOLS,
39
39
  ];
40
- const queryPkgId = query.address.get('borrowIncentive.query');
41
- const incentivePoolsId = query.address.get('borrowIncentive.incentivePools');
42
-
43
- const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
44
- const args = [incentivePoolsId];
45
- const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
46
- const borrowIncentivePoolsQueryData = queryResult.events[0]
47
- .parsedJson as BorrowIncentivePoolsQueryInterface;
48
40
 
49
41
  const borrowIncentivePools: BorrowIncentivePools = {};
50
42
 
@@ -75,6 +67,15 @@ export const queryBorrowIncentivePools = async (
75
67
  return borrowIncentivePools;
76
68
  }
77
69
 
70
+ const queryPkgId = query.address.get('borrowIncentive.query');
71
+ const incentivePoolsId = query.address.get('borrowIncentive.incentivePools');
72
+
73
+ const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
74
+ const args = [incentivePoolsId];
75
+ const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
76
+ const borrowIncentivePoolsQueryData = queryResult.events[0]
77
+ .parsedJson as BorrowIncentivePoolsQueryInterface;
78
+
78
79
  for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
79
80
  const borrowIncentivePoolPoints: OptionalKeys<
80
81
  Record<SupportBorrowIncentiveRewardCoins, BorrowIncentivePoolPoints>
@@ -50,18 +50,6 @@ export const queryMarket = async (
50
50
  query: ScallopQuery,
51
51
  indexer: boolean = false
52
52
  ) => {
53
- const packageId = query.address.get('core.packages.query.id');
54
- const marketId = query.address.get('core.market');
55
- const queryTarget = `${packageId}::market_query::market_data`;
56
- const args = [marketId];
57
-
58
- // const txBlock = new SuiKitTxBlock();
59
- // txBlock.moveCall(queryTarget, args);
60
- const queryResult = await query.cache.queryInspectTxn(
61
- { queryTarget, args }
62
- // txBlock
63
- );
64
- const marketData = queryResult.events[0].parsedJson as MarketQueryInterface;
65
53
  const coinPrices = await query.utils.getCoinPrices();
66
54
 
67
55
  const pools: MarketPools = {};
@@ -86,6 +74,14 @@ export const queryMarket = async (
86
74
  };
87
75
  }
88
76
 
77
+ const packageId = query.address.get('core.packages.query.id');
78
+ const marketId = query.address.get('core.market');
79
+ const queryTarget = `${packageId}::market_query::market_data`;
80
+ const args = [marketId];
81
+
82
+ const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
83
+ const marketData = queryResult.events[0].parsedJson as MarketQueryInterface;
84
+
89
85
  for (const pool of marketData.pools) {
90
86
  const coinType = normalizeStructTag(pool.type.name);
91
87
  const poolCoinName =
@@ -236,19 +232,21 @@ export const getMarketPools = async (
236
232
  return marketPools;
237
233
  }
238
234
 
239
- for (const poolCoinName of poolCoinNames) {
240
- const marketPool = await getMarketPool(
241
- query,
242
- poolCoinName,
243
- indexer,
244
- marketObjectResponse.data,
245
- coinPrices?.[poolCoinName]
246
- );
235
+ Promise.allSettled(
236
+ poolCoinNames.map(async (poolCoinName) => {
237
+ const marketPool = await getMarketPool(
238
+ query,
239
+ poolCoinName,
240
+ indexer,
241
+ marketObjectResponse.data,
242
+ coinPrices?.[poolCoinName]
243
+ );
247
244
 
248
- if (marketPool) {
249
- marketPools[poolCoinName] = marketPool;
250
- }
251
- }
245
+ if (marketPool) {
246
+ marketPools[poolCoinName] = marketPool;
247
+ }
248
+ })
249
+ );
252
250
 
253
251
  return marketPools;
254
252
  };
@@ -475,11 +473,12 @@ export const getMarketCollaterals = async (
475
473
  ) => {
476
474
  collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
477
475
  const marketId = query.address.get('core.market');
478
- const marketObjectResponse = await query.cache.queryGetObject(marketId, {
479
- showContent: true,
480
- });
481
- const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
482
-
476
+ const [marketObjectResponse, coinPrices] = await Promise.all([
477
+ query.cache.queryGetObject(marketId, {
478
+ showContent: true,
479
+ }),
480
+ query.utils.getCoinPrices(collateralCoinNames ?? []),
481
+ ]);
483
482
  const marketCollaterals: MarketCollaterals = {};
484
483
 
485
484
  if (indexer) {
@@ -496,19 +495,21 @@ export const getMarketCollaterals = async (
496
495
  return marketCollaterals;
497
496
  }
498
497
 
499
- for (const collateralCoinName of collateralCoinNames) {
500
- const marketCollateral = await getMarketCollateral(
501
- query,
502
- collateralCoinName,
503
- indexer,
504
- marketObjectResponse.data,
505
- coinPrices?.[collateralCoinName]
506
- );
498
+ await Promise.allSettled(
499
+ collateralCoinNames.map(async (collateralCoinName) => {
500
+ const marketCollateral = await getMarketCollateral(
501
+ query,
502
+ collateralCoinName,
503
+ indexer,
504
+ marketObjectResponse.data,
505
+ coinPrices?.[collateralCoinName]
506
+ );
507
507
 
508
- if (marketCollateral) {
509
- marketCollaterals[collateralCoinName] = marketCollateral;
510
- }
511
- }
508
+ if (marketCollateral) {
509
+ marketCollaterals[collateralCoinName] = marketCollateral;
510
+ }
511
+ })
512
+ );
512
513
 
513
514
  return marketCollaterals;
514
515
  };
@@ -530,6 +531,22 @@ export const getMarketCollateral = async (
530
531
  marketObject?: SuiObjectData | null,
531
532
  coinPrice?: number
532
533
  ) => {
534
+ if (indexer) {
535
+ const marketCollateralIndexer =
536
+ await query.indexer.getMarketCollateral(collateralCoinName);
537
+ marketCollateralIndexer.coinPrice =
538
+ coinPrice || marketCollateralIndexer.coinPrice;
539
+ marketCollateralIndexer.coinWrappedType = query.utils.getCoinWrappedType(
540
+ marketCollateralIndexer.coinName
541
+ );
542
+
543
+ return marketCollateralIndexer;
544
+ }
545
+
546
+ let marketCollateral: MarketCollateral | undefined;
547
+ let riskModel: RiskModel | undefined;
548
+ let collateralStat: CollateralStat | undefined;
549
+
533
550
  const marketId = query.address.get('core.market');
534
551
  marketObject =
535
552
  marketObject ||
@@ -545,22 +562,6 @@ export const getMarketCollateral = async (
545
562
  collateralCoinName
546
563
  ];
547
564
 
548
- let marketCollateral: MarketCollateral | undefined;
549
- let riskModel: RiskModel | undefined;
550
- let collateralStat: CollateralStat | undefined;
551
-
552
- if (indexer) {
553
- const marketCollateralIndexer =
554
- await query.indexer.getMarketCollateral(collateralCoinName);
555
- marketCollateralIndexer.coinPrice =
556
- coinPrice || marketCollateralIndexer.coinPrice;
557
- marketCollateralIndexer.coinWrappedType = query.utils.getCoinWrappedType(
558
- marketCollateralIndexer.coinName
559
- );
560
-
561
- return marketCollateralIndexer;
562
- }
563
-
564
565
  if (marketObject) {
565
566
  if (marketObject.content && 'fields' in marketObject.content) {
566
567
  const fields = marketObject.content.fields as any;
@@ -698,15 +699,18 @@ export const getObligations = async (
698
699
  const keyObjects = await query.cache.queryGetObjects(keyObjectIds);
699
700
 
700
701
  const obligations: Obligation[] = [];
701
- for (const keyObject of keyObjects) {
702
- const keyId = keyObject.objectId;
703
- if (keyObject.content && 'fields' in keyObject.content) {
704
- const fields = keyObject.content.fields as any;
705
- const obligationId = String(fields.ownership.fields.of);
706
- const locked = await getObligationLocked(query, obligationId);
707
- obligations.push({ id: obligationId, keyId, locked });
708
- }
709
- }
702
+ await Promise.allSettled(
703
+ keyObjects.map(async (keyObject) => {
704
+ const keyId = keyObject.objectId;
705
+ if (keyObject.content && 'fields' in keyObject.content) {
706
+ const fields = keyObject.content.fields as any;
707
+ const obligationId = String(fields.ownership.fields.of);
708
+ const locked = await getObligationLocked(query, obligationId);
709
+ obligations.push({ id: obligationId, keyId, locked });
710
+ }
711
+ })
712
+ );
713
+
710
714
  return obligations;
711
715
  };
712
716
 
@@ -49,36 +49,44 @@ export const getLendings = async (
49
49
  (SUPPORT_SPOOLS as readonly SupportMarketCoins[]).includes(marketCoinName)
50
50
  ) as SupportStakeMarketCoins[];
51
51
 
52
- const marketPools = await query.getMarketPools(poolCoinNames, indexer);
53
- const spools = await query.getSpools(stakeMarketCoinNames, indexer);
54
- const coinAmounts = await query.getCoinAmounts(poolCoinNames, ownerAddress);
55
- const marketCoinAmounts = await query.getMarketCoinAmounts(
56
- marketCoinNames,
57
- ownerAddress
58
- );
59
- const allStakeAccounts = await query.getAllStakeAccounts(ownerAddress);
60
- const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
52
+ const [
53
+ marketPools,
54
+ spools,
55
+ coinAmounts,
56
+ marketCoinAmounts,
57
+ allStakeAccounts,
58
+ coinPrices,
59
+ ] = await Promise.all([
60
+ query.getMarketPools(poolCoinNames, indexer),
61
+ query.getSpools(stakeMarketCoinNames, indexer),
62
+ query.getCoinAmounts(poolCoinNames, ownerAddress),
63
+ query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
64
+ query.getAllStakeAccounts(ownerAddress),
65
+ query.utils.getCoinPrices(poolCoinNames),
66
+ ]);
61
67
 
62
68
  const lendings: Lendings = {};
63
- for (const poolCoinName of poolCoinNames) {
64
- const stakeMarketCoinName = stakeMarketCoinNames.find(
65
- (marketCoinName) =>
66
- marketCoinName === query.utils.parseMarketCoinName(poolCoinName)
67
- );
68
- const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
69
- lendings[poolCoinName] = await getLending(
70
- query,
71
- poolCoinName,
72
- ownerAddress,
73
- indexer,
74
- marketPools?.[poolCoinName],
75
- stakeMarketCoinName ? spools[stakeMarketCoinName] : undefined,
76
- stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : undefined,
77
- coinAmounts?.[poolCoinName],
78
- marketCoinAmounts?.[marketCoinName],
79
- coinPrices?.[poolCoinName] ?? 0
80
- );
81
- }
69
+ await Promise.allSettled(
70
+ poolCoinNames.map(async (poolCoinName) => {
71
+ const stakeMarketCoinName = stakeMarketCoinNames.find(
72
+ (marketCoinName) =>
73
+ marketCoinName === query.utils.parseMarketCoinName(poolCoinName)
74
+ );
75
+ const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
76
+ lendings[poolCoinName] = await getLending(
77
+ query,
78
+ poolCoinName,
79
+ ownerAddress,
80
+ indexer,
81
+ marketPools?.[poolCoinName],
82
+ stakeMarketCoinName ? spools[stakeMarketCoinName] : undefined,
83
+ stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : undefined,
84
+ coinAmounts?.[poolCoinName],
85
+ marketCoinAmounts?.[marketCoinName],
86
+ coinPrices?.[poolCoinName] ?? 0
87
+ );
88
+ })
89
+ );
82
90
 
83
91
  return lendings;
84
92
  };
@@ -173,19 +173,20 @@ export const calculateMarketPoolData = (
173
173
  export const parseOriginMarketCollateralData = (
174
174
  originMarketCollateralData: OriginMarketCollateralData
175
175
  ): ParsedMarketCollateralData => {
176
+ const divisor = 2 ** 32;
176
177
  return {
177
178
  coinType: normalizeStructTag(originMarketCollateralData.type.name),
178
179
  collateralFactor:
179
- Number(originMarketCollateralData.collateralFactor.value) / 2 ** 32,
180
+ Number(originMarketCollateralData.collateralFactor.value) / divisor,
180
181
  liquidationFactor:
181
- Number(originMarketCollateralData.liquidationFactor.value) / 2 ** 32,
182
+ Number(originMarketCollateralData.liquidationFactor.value) / divisor,
182
183
  liquidationDiscount:
183
- Number(originMarketCollateralData.liquidationDiscount.value) / 2 ** 32,
184
+ Number(originMarketCollateralData.liquidationDiscount.value) / divisor,
184
185
  liquidationPanelty:
185
- Number(originMarketCollateralData.liquidationPanelty.value) / 2 ** 32,
186
+ Number(originMarketCollateralData.liquidationPanelty.value) / divisor,
186
187
  liquidationReserveFactor:
187
188
  Number(originMarketCollateralData.liquidationReserveFactor.value) /
188
- 2 ** 32,
189
+ divisor,
189
190
  maxCollateralAmount: Number(originMarketCollateralData.maxCollateralAmount),
190
191
  totalCollateralAmount: Number(
191
192
  originMarketCollateralData.totalCollateralAmount