@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.mjs CHANGED
@@ -2235,19 +2235,21 @@ var queryMarket = async (query, indexer = false) => {
2235
2235
  const collaterals = {};
2236
2236
  if (indexer) {
2237
2237
  const marketIndexer = await query.indexer.getMarket();
2238
- for (const pool of Object.values(marketIndexer.pools)) {
2239
- pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
2240
- pool.coinWrappedType = query.utils.getCoinWrappedType(pool.coinName);
2241
- }
2242
- for (const collateral of Object.values(marketIndexer.collaterals)) {
2243
- collateral.coinPrice = coinPrices[collateral.coinName] || collateral.coinPrice;
2244
- collateral.coinWrappedType = query.utils.getCoinWrappedType(
2245
- collateral.coinName
2246
- );
2247
- }
2238
+ const updatePools = (item) => {
2239
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2240
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2241
+ pools[item.coinName] = item;
2242
+ };
2243
+ const updateCollaterals = (item) => {
2244
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2245
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2246
+ collaterals[item.coinName] = item;
2247
+ };
2248
+ Object.values(marketIndexer.pools).forEach(updatePools);
2249
+ Object.values(marketIndexer.collaterals).forEach(updateCollaterals);
2248
2250
  return {
2249
- pools: marketIndexer.pools,
2250
- collaterals: marketIndexer.collaterals
2251
+ pools,
2252
+ collaterals
2251
2253
  };
2252
2254
  }
2253
2255
  const packageId = query.address.get("core.packages.query.id");
@@ -2357,8 +2359,7 @@ var queryMarket = async (query, indexer = false) => {
2357
2359
  data: marketData
2358
2360
  };
2359
2361
  };
2360
- var getMarketPools = async (query, poolCoinNames, indexer = false) => {
2361
- poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
2362
+ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false) => {
2362
2363
  const marketId = query.address.get("core.market");
2363
2364
  const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2364
2365
  showContent: true
@@ -2367,15 +2368,16 @@ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
2367
2368
  const marketPools = {};
2368
2369
  if (indexer) {
2369
2370
  const marketPoolsIndexer = await query.indexer.getMarketPools();
2370
- for (const marketPool of Object.values(marketPoolsIndexer)) {
2371
+ const updateMarketPool = (marketPool) => {
2371
2372
  if (!poolCoinNames.includes(marketPool.coinName))
2372
- continue;
2373
+ return;
2373
2374
  marketPool.coinPrice = coinPrices[marketPool.coinName] || marketPool.coinPrice;
2374
2375
  marketPool.coinWrappedType = query.utils.getCoinWrappedType(
2375
2376
  marketPool.coinName
2376
2377
  );
2377
2378
  marketPools[marketPool.coinName] = marketPool;
2378
- }
2379
+ };
2380
+ Object.values(marketPoolsIndexer).forEach(updateMarketPool);
2379
2381
  return marketPools;
2380
2382
  }
2381
2383
  await Promise.allSettled(
@@ -2400,6 +2402,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2400
2402
  let borrowIndex;
2401
2403
  let interestModel;
2402
2404
  let borrowFeeRate;
2405
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2403
2406
  if (indexer) {
2404
2407
  const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
2405
2408
  marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
@@ -2412,7 +2415,6 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2412
2415
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2413
2416
  showContent: true
2414
2417
  }))?.data;
2415
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2416
2418
  if (marketObject) {
2417
2419
  if (marketObject.content && "fields" in marketObject.content) {
2418
2420
  const fields = marketObject.content.fields;
@@ -2542,29 +2544,27 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2542
2544
  }
2543
2545
  return marketPool;
2544
2546
  };
2545
- var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
2546
- collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
2547
+ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
2547
2548
  const marketId = query.address.get("core.market");
2548
- const [marketObjectResponse, coinPrices] = await Promise.all([
2549
- await query.cache.queryGetObject(marketId, {
2550
- showContent: true
2551
- }),
2552
- await query.utils.getCoinPrices(collateralCoinNames ?? [])
2553
- ]);
2549
+ const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
2554
2550
  const marketCollaterals = {};
2555
2551
  if (indexer) {
2556
2552
  const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
2557
- for (const marketCollateral of Object.values(marketCollateralsIndexer)) {
2553
+ const updateMarketCollateral = (marketCollateral) => {
2558
2554
  if (!collateralCoinNames.includes(marketCollateral.coinName))
2559
- continue;
2555
+ return;
2560
2556
  marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
2561
2557
  marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
2562
2558
  marketCollateral.coinName
2563
2559
  );
2564
2560
  marketCollaterals[marketCollateral.coinName] = marketCollateral;
2565
- }
2561
+ };
2562
+ Object.values(marketCollateralsIndexer).forEach(updateMarketCollateral);
2566
2563
  return marketCollaterals;
2567
2564
  }
2565
+ const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2566
+ showContent: true
2567
+ });
2568
2568
  await Promise.allSettled(
2569
2569
  collateralCoinNames.map(async (collateralCoinName) => {
2570
2570
  const marketCollateral = await getMarketCollateral(
@@ -2582,6 +2582,7 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
2582
2582
  return marketCollaterals;
2583
2583
  };
2584
2584
  var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
2585
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2585
2586
  if (indexer) {
2586
2587
  const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
2587
2588
  marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
@@ -2597,7 +2598,6 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
2597
2598
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2598
2599
  showContent: true
2599
2600
  }))?.data;
2600
- coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2601
2601
  if (marketObject) {
2602
2602
  if (marketObject.content && "fields" in marketObject.content) {
2603
2603
  const fields = marketObject.content.fields;
@@ -2847,8 +2847,7 @@ var getFlashLoanFees = async (query, assetNames) => {
2847
2847
 
2848
2848
  // src/queries/spoolQuery.ts
2849
2849
  import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui.js/utils";
2850
- var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2851
- stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
2850
+ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false) => {
2852
2851
  const stakeCoinNames = stakeMarketCoinNames.map(
2853
2852
  (stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
2854
2853
  );
@@ -2863,9 +2862,9 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2863
2862
  const spools = {};
2864
2863
  if (indexer) {
2865
2864
  const spoolsIndexer = await query.indexer.getSpools();
2866
- for (const spool of Object.values(spoolsIndexer)) {
2865
+ const updateSpools = (spool) => {
2867
2866
  if (!stakeMarketCoinNames.includes(spool.marketCoinName))
2868
- continue;
2867
+ return;
2869
2868
  const coinName = query.utils.parseCoinName(
2870
2869
  spool.marketCoinName
2871
2870
  );
@@ -2877,7 +2876,8 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2877
2876
  spool.marketCoinPrice = (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
2878
2877
  spool.rewardCoinPrice = coinPrices[rewardCoinName] || spool.rewardCoinPrice;
2879
2878
  spools[spool.marketCoinName] = spool;
2880
- }
2879
+ };
2880
+ Object.values(spoolsIndexer).forEach(updateSpools);
2881
2881
  return spools;
2882
2882
  }
2883
2883
  for (const stakeMarketCoinName of stakeMarketCoinNames) {
@@ -2903,6 +2903,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
2903
2903
  `spool.pools.${marketCoinName}.rewardPoolId`
2904
2904
  );
2905
2905
  let spool = void 0;
2906
+ coinPrices = coinPrices || await query.utils.getCoinPrices([coinName]);
2906
2907
  if (indexer) {
2907
2908
  const spoolIndexer = await query.indexer.getSpool(marketCoinName);
2908
2909
  const coinName2 = query.utils.parseCoinName(marketCoinName);
@@ -3231,10 +3232,9 @@ var getStakeRewardPool = async ({
3231
3232
  // src/queries/borrowIncentiveQuery.ts
3232
3233
  import { normalizeStructTag as normalizeStructTag5 } from "@mysten/sui.js/utils";
3233
3234
  import BigNumber3 from "bignumber.js";
3234
- var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
3235
- borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
3236
- ...SUPPORT_BORROW_INCENTIVE_POOLS
3237
- ];
3235
+ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
3236
+ ...SUPPORT_BORROW_INCENTIVE_POOLS
3237
+ ], indexer = false) => {
3238
3238
  const borrowIncentivePools = {};
3239
3239
  const coinPrices = await query.utils.getCoinPrices(
3240
3240
  [
@@ -3246,14 +3246,15 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
3246
3246
  );
3247
3247
  if (indexer) {
3248
3248
  const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
3249
- for (const borrowIncentivePool of Object.values(
3250
- borrowIncentivePoolsIndexer
3251
- )) {
3252
- if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
3253
- continue;
3254
- borrowIncentivePool.coinPrice = coinPrices[borrowIncentivePool.coinName] || borrowIncentivePool.coinPrice;
3255
- borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
3256
- }
3249
+ const updateBorrowIncentivePool = (pool) => {
3250
+ if (!borrowIncentiveCoinNames.includes(pool.coinName))
3251
+ return;
3252
+ pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
3253
+ borrowIncentivePools[pool.coinName] = pool;
3254
+ };
3255
+ Object.values(borrowIncentivePoolsIndexer).forEach(
3256
+ updateBorrowIncentivePool
3257
+ );
3257
3258
  return borrowIncentivePools;
3258
3259
  }
3259
3260
  const queryPkgId = query.address.get("borrowIncentive.query");