@scallop-io/sui-scallop-sdk 0.46.63 → 0.46.65

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/dist/index.js CHANGED
@@ -2309,19 +2309,21 @@ var queryMarket = async (query, indexer = false) => {
2309
2309
  const collaterals = {};
2310
2310
  if (indexer) {
2311
2311
  const marketIndexer = await query.indexer.getMarket();
2312
- for (const pool of Object.values(marketIndexer.pools)) {
2313
- pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
2314
- pool.coinWrappedType = query.utils.getCoinWrappedType(pool.coinName);
2315
- }
2316
- for (const collateral of Object.values(marketIndexer.collaterals)) {
2317
- collateral.coinPrice = coinPrices[collateral.coinName] || collateral.coinPrice;
2318
- collateral.coinWrappedType = query.utils.getCoinWrappedType(
2319
- collateral.coinName
2320
- );
2321
- }
2312
+ const updatePools = (item) => {
2313
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2314
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2315
+ pools[item.coinName] = item;
2316
+ };
2317
+ const updateCollaterals = (item) => {
2318
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2319
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2320
+ collaterals[item.coinName] = item;
2321
+ };
2322
+ Object.values(marketIndexer.pools).forEach(updatePools);
2323
+ Object.values(marketIndexer.collaterals).forEach(updateCollaterals);
2322
2324
  return {
2323
- pools: marketIndexer.pools,
2324
- collaterals: marketIndexer.collaterals
2325
+ pools,
2326
+ collaterals
2325
2327
  };
2326
2328
  }
2327
2329
  const packageId = query.address.get("core.packages.query.id");
@@ -2431,8 +2433,7 @@ var queryMarket = async (query, indexer = false) => {
2431
2433
  data: marketData
2432
2434
  };
2433
2435
  };
2434
- var getMarketPools = async (query, poolCoinNames, indexer = false) => {
2435
- poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
2436
+ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false) => {
2436
2437
  const marketId = query.address.get("core.market");
2437
2438
  const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2438
2439
  showContent: true
@@ -2441,15 +2442,16 @@ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
2441
2442
  const marketPools = {};
2442
2443
  if (indexer) {
2443
2444
  const marketPoolsIndexer = await query.indexer.getMarketPools();
2444
- for (const marketPool of Object.values(marketPoolsIndexer)) {
2445
+ const updateMarketPool = (marketPool) => {
2445
2446
  if (!poolCoinNames.includes(marketPool.coinName))
2446
- continue;
2447
+ return;
2447
2448
  marketPool.coinPrice = coinPrices[marketPool.coinName] || marketPool.coinPrice;
2448
2449
  marketPool.coinWrappedType = query.utils.getCoinWrappedType(
2449
2450
  marketPool.coinName
2450
2451
  );
2451
2452
  marketPools[marketPool.coinName] = marketPool;
2452
- }
2453
+ };
2454
+ Object.values(marketPoolsIndexer).forEach(updateMarketPool);
2453
2455
  return marketPools;
2454
2456
  }
2455
2457
  await Promise.allSettled(
@@ -2474,6 +2476,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2474
2476
  let borrowIndex;
2475
2477
  let interestModel;
2476
2478
  let borrowFeeRate;
2479
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2477
2480
  if (indexer) {
2478
2481
  const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
2479
2482
  marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
@@ -2486,7 +2489,6 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2486
2489
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2487
2490
  showContent: true
2488
2491
  }))?.data;
2489
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2490
2492
  if (marketObject) {
2491
2493
  if (marketObject.content && "fields" in marketObject.content) {
2492
2494
  const fields = marketObject.content.fields;
@@ -2616,29 +2618,27 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2616
2618
  }
2617
2619
  return marketPool;
2618
2620
  };
2619
- var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
2620
- collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
2621
+ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
2621
2622
  const marketId = query.address.get("core.market");
2622
- const [marketObjectResponse, coinPrices] = await Promise.all([
2623
- await query.cache.queryGetObject(marketId, {
2624
- showContent: true
2625
- }),
2626
- await query.utils.getCoinPrices(collateralCoinNames ?? [])
2627
- ]);
2623
+ const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
2628
2624
  const marketCollaterals = {};
2629
2625
  if (indexer) {
2630
2626
  const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
2631
- for (const marketCollateral of Object.values(marketCollateralsIndexer)) {
2627
+ const updateMarketCollateral = (marketCollateral) => {
2632
2628
  if (!collateralCoinNames.includes(marketCollateral.coinName))
2633
- continue;
2629
+ return;
2634
2630
  marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
2635
2631
  marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
2636
2632
  marketCollateral.coinName
2637
2633
  );
2638
2634
  marketCollaterals[marketCollateral.coinName] = marketCollateral;
2639
- }
2635
+ };
2636
+ Object.values(marketCollateralsIndexer).forEach(updateMarketCollateral);
2640
2637
  return marketCollaterals;
2641
2638
  }
2639
+ const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2640
+ showContent: true
2641
+ });
2642
2642
  await Promise.allSettled(
2643
2643
  collateralCoinNames.map(async (collateralCoinName) => {
2644
2644
  const marketCollateral = await getMarketCollateral(
@@ -2656,6 +2656,7 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
2656
2656
  return marketCollaterals;
2657
2657
  };
2658
2658
  var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
2659
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2659
2660
  if (indexer) {
2660
2661
  const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
2661
2662
  marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
@@ -2671,7 +2672,6 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
2671
2672
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2672
2673
  showContent: true
2673
2674
  }))?.data;
2674
- coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2675
2675
  if (marketObject) {
2676
2676
  if (marketObject.content && "fields" in marketObject.content) {
2677
2677
  const fields = marketObject.content.fields;
@@ -2921,8 +2921,7 @@ var getFlashLoanFees = async (query, assetNames) => {
2921
2921
 
2922
2922
  // src/queries/spoolQuery.ts
2923
2923
  var import_utils5 = require("@mysten/sui.js/utils");
2924
- var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2925
- stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
2924
+ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false) => {
2926
2925
  const stakeCoinNames = stakeMarketCoinNames.map(
2927
2926
  (stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
2928
2927
  );
@@ -2937,9 +2936,9 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2937
2936
  const spools = {};
2938
2937
  if (indexer) {
2939
2938
  const spoolsIndexer = await query.indexer.getSpools();
2940
- for (const spool of Object.values(spoolsIndexer)) {
2939
+ const updateSpools = (spool) => {
2941
2940
  if (!stakeMarketCoinNames.includes(spool.marketCoinName))
2942
- continue;
2941
+ return;
2943
2942
  const coinName = query.utils.parseCoinName(
2944
2943
  spool.marketCoinName
2945
2944
  );
@@ -2951,7 +2950,8 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2951
2950
  spool.marketCoinPrice = (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
2952
2951
  spool.rewardCoinPrice = coinPrices[rewardCoinName] || spool.rewardCoinPrice;
2953
2952
  spools[spool.marketCoinName] = spool;
2954
- }
2953
+ };
2954
+ Object.values(spoolsIndexer).forEach(updateSpools);
2955
2955
  return spools;
2956
2956
  }
2957
2957
  for (const stakeMarketCoinName of stakeMarketCoinNames) {
@@ -2977,6 +2977,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
2977
2977
  `spool.pools.${marketCoinName}.rewardPoolId`
2978
2978
  );
2979
2979
  let spool = void 0;
2980
+ coinPrices = coinPrices || await query.utils.getCoinPrices([coinName]);
2980
2981
  if (indexer) {
2981
2982
  const spoolIndexer = await query.indexer.getSpool(marketCoinName);
2982
2983
  const coinName2 = query.utils.parseCoinName(marketCoinName);
@@ -3305,10 +3306,9 @@ var getStakeRewardPool = async ({
3305
3306
  // src/queries/borrowIncentiveQuery.ts
3306
3307
  var import_utils7 = require("@mysten/sui.js/utils");
3307
3308
  var import_bignumber3 = __toESM(require("bignumber.js"));
3308
- var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
3309
- borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
3310
- ...SUPPORT_BORROW_INCENTIVE_POOLS
3311
- ];
3309
+ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
3310
+ ...SUPPORT_BORROW_INCENTIVE_POOLS
3311
+ ], indexer = false) => {
3312
3312
  const borrowIncentivePools = {};
3313
3313
  const coinPrices = await query.utils.getCoinPrices(
3314
3314
  [
@@ -3320,14 +3320,15 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
3320
3320
  );
3321
3321
  if (indexer) {
3322
3322
  const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
3323
- for (const borrowIncentivePool of Object.values(
3324
- borrowIncentivePoolsIndexer
3325
- )) {
3326
- if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
3327
- continue;
3328
- borrowIncentivePool.coinPrice = coinPrices[borrowIncentivePool.coinName] || borrowIncentivePool.coinPrice;
3329
- borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
3330
- }
3323
+ const updateBorrowIncentivePool = (pool) => {
3324
+ if (!borrowIncentiveCoinNames.includes(pool.coinName))
3325
+ return;
3326
+ pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
3327
+ borrowIncentivePools[pool.coinName] = pool;
3328
+ };
3329
+ Object.values(borrowIncentivePoolsIndexer).forEach(
3330
+ updateBorrowIncentivePool
3331
+ );
3331
3332
  return borrowIncentivePools;
3332
3333
  }
3333
3334
  const queryPkgId = query.address.get("borrowIncentive.query");