@scallop-io/sui-scallop-sdk 0.47.0-alpha.3 → 0.47.0-alpha.5

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
@@ -2328,19 +2328,21 @@ var queryMarket = async (query, indexer = false) => {
2328
2328
  const collaterals = {};
2329
2329
  if (indexer) {
2330
2330
  const marketIndexer = await query.indexer.getMarket();
2331
- for (const pool of Object.values(marketIndexer.pools)) {
2332
- pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
2333
- pool.coinWrappedType = query.utils.getCoinWrappedType(pool.coinName);
2334
- }
2335
- for (const collateral of Object.values(marketIndexer.collaterals)) {
2336
- collateral.coinPrice = coinPrices[collateral.coinName] || collateral.coinPrice;
2337
- collateral.coinWrappedType = query.utils.getCoinWrappedType(
2338
- collateral.coinName
2339
- );
2340
- }
2331
+ const updatePools = (item) => {
2332
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2333
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2334
+ pools[item.coinName] = item;
2335
+ };
2336
+ const updateCollaterals = (item) => {
2337
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2338
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2339
+ collaterals[item.coinName] = item;
2340
+ };
2341
+ Object.values(marketIndexer.pools).forEach(updatePools);
2342
+ Object.values(marketIndexer.collaterals).forEach(updateCollaterals);
2341
2343
  return {
2342
- pools: marketIndexer.pools,
2343
- collaterals: marketIndexer.collaterals
2344
+ pools,
2345
+ collaterals
2344
2346
  };
2345
2347
  }
2346
2348
  const packageId = query.address.get("core.packages.query.id");
@@ -2450,25 +2452,25 @@ var queryMarket = async (query, indexer = false) => {
2450
2452
  data: marketData
2451
2453
  };
2452
2454
  };
2453
- var getMarketPools = async (query, poolCoinNames, indexer = false) => {
2454
- poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
2455
+ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false) => {
2455
2456
  const marketId = query.address.get("core.market");
2456
2457
  const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2457
2458
  showContent: true
2458
2459
  });
2459
- const coinPrices = await query.utils.getCoinPrices(poolCoinNames ?? []);
2460
+ const coinPrices = await query.utils.getCoinPrices(poolCoinNames) ?? {};
2460
2461
  const marketPools = {};
2461
2462
  if (indexer) {
2462
2463
  const marketPoolsIndexer = await query.indexer.getMarketPools();
2463
- for (const marketPool of Object.values(marketPoolsIndexer)) {
2464
+ const updateMarketPool = (marketPool) => {
2464
2465
  if (!poolCoinNames.includes(marketPool.coinName))
2465
- continue;
2466
+ return;
2466
2467
  marketPool.coinPrice = coinPrices[marketPool.coinName] || marketPool.coinPrice;
2467
2468
  marketPool.coinWrappedType = query.utils.getCoinWrappedType(
2468
2469
  marketPool.coinName
2469
2470
  );
2470
2471
  marketPools[marketPool.coinName] = marketPool;
2471
- }
2472
+ };
2473
+ Object.values(marketPoolsIndexer).forEach(updateMarketPool);
2472
2474
  return marketPools;
2473
2475
  }
2474
2476
  await Promise.allSettled(
@@ -2493,6 +2495,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2493
2495
  let borrowIndex;
2494
2496
  let interestModel;
2495
2497
  let borrowFeeRate;
2498
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2496
2499
  if (indexer) {
2497
2500
  const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
2498
2501
  marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
@@ -2505,7 +2508,6 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2505
2508
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2506
2509
  showContent: true
2507
2510
  }))?.data;
2508
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2509
2511
  if (marketObject) {
2510
2512
  if (marketObject.content && "fields" in marketObject.content) {
2511
2513
  const fields = marketObject.content.fields;
@@ -2635,29 +2637,27 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2635
2637
  }
2636
2638
  return marketPool;
2637
2639
  };
2638
- var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
2639
- collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
2640
+ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
2640
2641
  const marketId = query.address.get("core.market");
2641
- const [marketObjectResponse, coinPrices] = await Promise.all([
2642
- await query.cache.queryGetObject(marketId, {
2643
- showContent: true
2644
- }),
2645
- await query.utils.getCoinPrices(collateralCoinNames ?? [])
2646
- ]);
2642
+ const coinPrices = await query.utils.getCoinPrices(collateralCoinNames) ?? {};
2647
2643
  const marketCollaterals = {};
2648
2644
  if (indexer) {
2649
2645
  const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
2650
- for (const marketCollateral of Object.values(marketCollateralsIndexer)) {
2646
+ const updateMarketCollateral = (marketCollateral) => {
2651
2647
  if (!collateralCoinNames.includes(marketCollateral.coinName))
2652
- continue;
2648
+ return;
2653
2649
  marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
2654
2650
  marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
2655
2651
  marketCollateral.coinName
2656
2652
  );
2657
2653
  marketCollaterals[marketCollateral.coinName] = marketCollateral;
2658
- }
2654
+ };
2655
+ Object.values(marketCollateralsIndexer).forEach(updateMarketCollateral);
2659
2656
  return marketCollaterals;
2660
2657
  }
2658
+ const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2659
+ showContent: true
2660
+ });
2661
2661
  await Promise.allSettled(
2662
2662
  collateralCoinNames.map(async (collateralCoinName) => {
2663
2663
  const marketCollateral = await getMarketCollateral(
@@ -2675,6 +2675,7 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
2675
2675
  return marketCollaterals;
2676
2676
  };
2677
2677
  var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
2678
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2678
2679
  if (indexer) {
2679
2680
  const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
2680
2681
  marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
@@ -2690,7 +2691,6 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
2690
2691
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2691
2692
  showContent: true
2692
2693
  }))?.data;
2693
- coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2694
2694
  if (marketObject) {
2695
2695
  if (marketObject.content && "fields" in marketObject.content) {
2696
2696
  const fields = marketObject.content.fields;
@@ -2940,8 +2940,7 @@ var getFlashLoanFees = async (query, assetNames) => {
2940
2940
 
2941
2941
  // src/queries/spoolQuery.ts
2942
2942
  var import_utils5 = require("@mysten/sui.js/utils");
2943
- var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2944
- stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
2943
+ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false) => {
2945
2944
  const stakeCoinNames = stakeMarketCoinNames.map(
2946
2945
  (stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
2947
2946
  );
@@ -2949,16 +2948,16 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2949
2948
  const rewardCoinName = query.utils.getSpoolRewardCoinName(stakeMarketCoinName);
2950
2949
  return rewardCoinName;
2951
2950
  });
2952
- const coinPrices = await query.utils.getCoinPrices(
2953
- [.../* @__PURE__ */ new Set([...stakeCoinNames, ...rewardCoinNames])]
2954
- );
2951
+ const coinPrices = await query.utils.getCoinPrices([
2952
+ .../* @__PURE__ */ new Set([...stakeCoinNames, ...rewardCoinNames])
2953
+ ]) ?? {};
2955
2954
  const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
2956
2955
  const spools = {};
2957
2956
  if (indexer) {
2958
2957
  const spoolsIndexer = await query.indexer.getSpools();
2959
- for (const spool of Object.values(spoolsIndexer)) {
2958
+ const updateSpools = (spool) => {
2960
2959
  if (!stakeMarketCoinNames.includes(spool.marketCoinName))
2961
- continue;
2960
+ return;
2962
2961
  const coinName = query.utils.parseCoinName(
2963
2962
  spool.marketCoinName
2964
2963
  );
@@ -2970,7 +2969,8 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2970
2969
  spool.marketCoinPrice = (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
2971
2970
  spool.rewardCoinPrice = coinPrices[rewardCoinName] || spool.rewardCoinPrice;
2972
2971
  spools[spool.marketCoinName] = spool;
2973
- }
2972
+ };
2973
+ Object.values(spoolsIndexer).forEach(updateSpools);
2974
2974
  return spools;
2975
2975
  }
2976
2976
  for (const stakeMarketCoinName of stakeMarketCoinNames) {
@@ -2996,6 +2996,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
2996
2996
  `spool.pools.${marketCoinName}.rewardPoolId`
2997
2997
  );
2998
2998
  let spool = void 0;
2999
+ coinPrices = coinPrices || await query.utils.getCoinPrices([coinName]);
2999
3000
  if (indexer) {
3000
3001
  const spoolIndexer = await query.indexer.getSpool(marketCoinName);
3001
3002
  const coinName2 = query.utils.parseCoinName(marketCoinName);
@@ -3325,29 +3326,27 @@ var getStakeRewardPool = async ({
3325
3326
  // src/queries/borrowIncentiveQuery.ts
3326
3327
  var import_utils7 = require("@mysten/sui.js/utils");
3327
3328
  var import_bignumber3 = __toESM(require("bignumber.js"));
3328
- var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
3329
- borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
3330
- ...SUPPORT_BORROW_INCENTIVE_POOLS
3331
- ];
3329
+ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
3330
+ ...SUPPORT_BORROW_INCENTIVE_POOLS
3331
+ ], indexer = false) => {
3332
3332
  const borrowIncentivePools = {};
3333
- const coinPrices = await query.utils.getCoinPrices(
3334
- [
3335
- .../* @__PURE__ */ new Set([
3336
- ...borrowIncentiveCoinNames,
3337
- ...SUPPORT_BORROW_INCENTIVE_REWARDS
3338
- ])
3339
- ]
3340
- );
3333
+ const coinPrices = await query.utils.getCoinPrices([
3334
+ .../* @__PURE__ */ new Set([
3335
+ ...borrowIncentiveCoinNames,
3336
+ ...SUPPORT_BORROW_INCENTIVE_REWARDS
3337
+ ])
3338
+ ]) ?? {};
3341
3339
  if (indexer) {
3342
3340
  const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
3343
- for (const borrowIncentivePool of Object.values(
3344
- borrowIncentivePoolsIndexer
3345
- )) {
3346
- if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
3347
- continue;
3348
- borrowIncentivePool.coinPrice = coinPrices[borrowIncentivePool.coinName] || borrowIncentivePool.coinPrice;
3349
- borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
3350
- }
3341
+ const updateBorrowIncentivePool = (pool) => {
3342
+ if (!borrowIncentiveCoinNames.includes(pool.coinName))
3343
+ return;
3344
+ pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
3345
+ borrowIncentivePools[pool.coinName] = pool;
3346
+ };
3347
+ Object.values(borrowIncentivePoolsIndexer).forEach(
3348
+ updateBorrowIncentivePool
3349
+ );
3351
3350
  return borrowIncentivePools;
3352
3351
  }
3353
3352
  const queryPkgId = query.address.get("borrowIncentive.query");
@@ -5227,7 +5226,7 @@ var generateCoreQuickMethod = ({
5227
5226
  const obligationCoinNames = await builder.utils.getObligationCoinNames(
5228
5227
  obligationInfo.obligationId
5229
5228
  ) ?? [];
5230
- const updateCoinNames = [...obligationCoinNames ?? [], poolCoinName];
5229
+ const updateCoinNames = [...obligationCoinNames, poolCoinName];
5231
5230
  await updateOracles(builder, txBlock, updateCoinNames);
5232
5231
  return txBlock.borrow(
5233
5232
  obligationInfo.obligationId,