@scallop-io/sui-scallop-sdk 0.46.64 → 0.46.66

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
@@ -8,6 +8,7 @@ var PROTOCOL_OBJECT_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee4
8
8
  var BORROW_FEE_PROTOCOL_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
9
9
  var SCA_COIN_TYPE = IS_VE_SCA_TEST ? `0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA` : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA";
10
10
  var OLD_BORROW_INCENTIVE_PROTOCOL_ID = "0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410";
11
+ var NATIVE_USDC = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
11
12
  var SUPPORT_POOLS = [
12
13
  "eth",
13
14
  "btc",
@@ -2235,19 +2236,21 @@ var queryMarket = async (query, indexer = false) => {
2235
2236
  const collaterals = {};
2236
2237
  if (indexer) {
2237
2238
  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
- }
2239
+ const updatePools = (item) => {
2240
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2241
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2242
+ pools[item.coinName] = item;
2243
+ };
2244
+ const updateCollaterals = (item) => {
2245
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2246
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2247
+ collaterals[item.coinName] = item;
2248
+ };
2249
+ Object.values(marketIndexer.pools).forEach(updatePools);
2250
+ Object.values(marketIndexer.collaterals).forEach(updateCollaterals);
2248
2251
  return {
2249
- pools: marketIndexer.pools,
2250
- collaterals: marketIndexer.collaterals
2252
+ pools,
2253
+ collaterals
2251
2254
  };
2252
2255
  }
2253
2256
  const packageId = query.address.get("core.packages.query.id");
@@ -2258,6 +2261,8 @@ var queryMarket = async (query, indexer = false) => {
2258
2261
  const marketData = queryResult?.events[0].parsedJson;
2259
2262
  for (const pool of marketData?.pools ?? []) {
2260
2263
  const coinType = normalizeStructTag3(pool.type.name);
2264
+ if (coinType === NATIVE_USDC)
2265
+ continue;
2261
2266
  const poolCoinName = query.utils.parseCoinNameFromType(coinType);
2262
2267
  const coinPrice = coinPrices[poolCoinName] ?? 0;
2263
2268
  if (!SUPPORT_POOLS.includes(poolCoinName)) {
@@ -2357,25 +2362,25 @@ var queryMarket = async (query, indexer = false) => {
2357
2362
  data: marketData
2358
2363
  };
2359
2364
  };
2360
- var getMarketPools = async (query, poolCoinNames, indexer = false) => {
2361
- poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
2365
+ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false) => {
2362
2366
  const marketId = query.address.get("core.market");
2363
2367
  const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2364
2368
  showContent: true
2365
2369
  });
2366
- const coinPrices = await query.utils.getCoinPrices(poolCoinNames ?? []);
2370
+ const coinPrices = await query.utils.getCoinPrices(poolCoinNames) ?? {};
2367
2371
  const marketPools = {};
2368
2372
  if (indexer) {
2369
2373
  const marketPoolsIndexer = await query.indexer.getMarketPools();
2370
- for (const marketPool of Object.values(marketPoolsIndexer)) {
2374
+ const updateMarketPool = (marketPool) => {
2371
2375
  if (!poolCoinNames.includes(marketPool.coinName))
2372
- continue;
2376
+ return;
2373
2377
  marketPool.coinPrice = coinPrices[marketPool.coinName] || marketPool.coinPrice;
2374
2378
  marketPool.coinWrappedType = query.utils.getCoinWrappedType(
2375
2379
  marketPool.coinName
2376
2380
  );
2377
2381
  marketPools[marketPool.coinName] = marketPool;
2378
- }
2382
+ };
2383
+ Object.values(marketPoolsIndexer).forEach(updateMarketPool);
2379
2384
  return marketPools;
2380
2385
  }
2381
2386
  await Promise.allSettled(
@@ -2400,6 +2405,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2400
2405
  let borrowIndex;
2401
2406
  let interestModel;
2402
2407
  let borrowFeeRate;
2408
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2403
2409
  if (indexer) {
2404
2410
  const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
2405
2411
  marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
@@ -2412,7 +2418,6 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2412
2418
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2413
2419
  showContent: true
2414
2420
  }))?.data;
2415
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2416
2421
  if (marketObject) {
2417
2422
  if (marketObject.content && "fields" in marketObject.content) {
2418
2423
  const fields = marketObject.content.fields;
@@ -2542,29 +2547,27 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2542
2547
  }
2543
2548
  return marketPool;
2544
2549
  };
2545
- var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
2546
- collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
2550
+ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
2547
2551
  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
- ]);
2552
+ const coinPrices = await query.utils.getCoinPrices(collateralCoinNames) ?? {};
2554
2553
  const marketCollaterals = {};
2555
2554
  if (indexer) {
2556
2555
  const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
2557
- for (const marketCollateral of Object.values(marketCollateralsIndexer)) {
2556
+ const updateMarketCollateral = (marketCollateral) => {
2558
2557
  if (!collateralCoinNames.includes(marketCollateral.coinName))
2559
- continue;
2558
+ return;
2560
2559
  marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
2561
2560
  marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
2562
2561
  marketCollateral.coinName
2563
2562
  );
2564
2563
  marketCollaterals[marketCollateral.coinName] = marketCollateral;
2565
- }
2564
+ };
2565
+ Object.values(marketCollateralsIndexer).forEach(updateMarketCollateral);
2566
2566
  return marketCollaterals;
2567
2567
  }
2568
+ const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2569
+ showContent: true
2570
+ });
2568
2571
  await Promise.allSettled(
2569
2572
  collateralCoinNames.map(async (collateralCoinName) => {
2570
2573
  const marketCollateral = await getMarketCollateral(
@@ -2582,6 +2585,7 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
2582
2585
  return marketCollaterals;
2583
2586
  };
2584
2587
  var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
2588
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2585
2589
  if (indexer) {
2586
2590
  const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
2587
2591
  marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
@@ -2597,7 +2601,6 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
2597
2601
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2598
2602
  showContent: true
2599
2603
  }))?.data;
2600
- coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2601
2604
  if (marketObject) {
2602
2605
  if (marketObject.content && "fields" in marketObject.content) {
2603
2606
  const fields = marketObject.content.fields;
@@ -2847,8 +2850,7 @@ var getFlashLoanFees = async (query, assetNames) => {
2847
2850
 
2848
2851
  // src/queries/spoolQuery.ts
2849
2852
  import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui.js/utils";
2850
- var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2851
- stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
2853
+ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false) => {
2852
2854
  const stakeCoinNames = stakeMarketCoinNames.map(
2853
2855
  (stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
2854
2856
  );
@@ -2856,16 +2858,16 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2856
2858
  const rewardCoinName = query.utils.getSpoolRewardCoinName(stakeMarketCoinName);
2857
2859
  return rewardCoinName;
2858
2860
  });
2859
- const coinPrices = await query.utils.getCoinPrices(
2860
- [.../* @__PURE__ */ new Set([...stakeCoinNames, ...rewardCoinNames])]
2861
- );
2861
+ const coinPrices = await query.utils.getCoinPrices([
2862
+ .../* @__PURE__ */ new Set([...stakeCoinNames, ...rewardCoinNames])
2863
+ ]) ?? {};
2862
2864
  const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
2863
2865
  const spools = {};
2864
2866
  if (indexer) {
2865
2867
  const spoolsIndexer = await query.indexer.getSpools();
2866
- for (const spool of Object.values(spoolsIndexer)) {
2868
+ const updateSpools = (spool) => {
2867
2869
  if (!stakeMarketCoinNames.includes(spool.marketCoinName))
2868
- continue;
2870
+ return;
2869
2871
  const coinName = query.utils.parseCoinName(
2870
2872
  spool.marketCoinName
2871
2873
  );
@@ -2877,7 +2879,8 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2877
2879
  spool.marketCoinPrice = (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
2878
2880
  spool.rewardCoinPrice = coinPrices[rewardCoinName] || spool.rewardCoinPrice;
2879
2881
  spools[spool.marketCoinName] = spool;
2880
- }
2882
+ };
2883
+ Object.values(spoolsIndexer).forEach(updateSpools);
2881
2884
  return spools;
2882
2885
  }
2883
2886
  for (const stakeMarketCoinName of stakeMarketCoinNames) {
@@ -2903,6 +2906,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
2903
2906
  `spool.pools.${marketCoinName}.rewardPoolId`
2904
2907
  );
2905
2908
  let spool = void 0;
2909
+ coinPrices = coinPrices || await query.utils.getCoinPrices([coinName]);
2906
2910
  if (indexer) {
2907
2911
  const spoolIndexer = await query.indexer.getSpool(marketCoinName);
2908
2912
  const coinName2 = query.utils.parseCoinName(marketCoinName);
@@ -3231,29 +3235,27 @@ var getStakeRewardPool = async ({
3231
3235
  // src/queries/borrowIncentiveQuery.ts
3232
3236
  import { normalizeStructTag as normalizeStructTag5 } from "@mysten/sui.js/utils";
3233
3237
  import BigNumber3 from "bignumber.js";
3234
- var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
3235
- borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
3236
- ...SUPPORT_BORROW_INCENTIVE_POOLS
3237
- ];
3238
+ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
3239
+ ...SUPPORT_BORROW_INCENTIVE_POOLS
3240
+ ], indexer = false) => {
3238
3241
  const borrowIncentivePools = {};
3239
- const coinPrices = await query.utils.getCoinPrices(
3240
- [
3241
- .../* @__PURE__ */ new Set([
3242
- ...borrowIncentiveCoinNames,
3243
- ...SUPPORT_BORROW_INCENTIVE_REWARDS
3244
- ])
3245
- ]
3246
- );
3242
+ const coinPrices = await query.utils.getCoinPrices([
3243
+ .../* @__PURE__ */ new Set([
3244
+ ...borrowIncentiveCoinNames,
3245
+ ...SUPPORT_BORROW_INCENTIVE_REWARDS
3246
+ ])
3247
+ ]) ?? {};
3247
3248
  if (indexer) {
3248
3249
  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
- }
3250
+ const updateBorrowIncentivePool = (pool) => {
3251
+ if (!borrowIncentiveCoinNames.includes(pool.coinName))
3252
+ return;
3253
+ pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
3254
+ borrowIncentivePools[pool.coinName] = pool;
3255
+ };
3256
+ Object.values(borrowIncentivePoolsIndexer).forEach(
3257
+ updateBorrowIncentivePool
3258
+ );
3257
3259
  return borrowIncentivePools;
3258
3260
  }
3259
3261
  const queryPkgId = query.address.get("borrowIncentive.query");
@@ -5136,7 +5138,7 @@ var generateCoreQuickMethod = ({
5136
5138
  const obligationCoinNames = await builder.utils.getObligationCoinNames(
5137
5139
  obligationInfo.obligationId
5138
5140
  ) ?? [];
5139
- const updateCoinNames = [...obligationCoinNames ?? [], poolCoinName];
5141
+ const updateCoinNames = [...obligationCoinNames, poolCoinName];
5140
5142
  await updateOracles(builder, txBlock, updateCoinNames);
5141
5143
  return txBlock.borrow(
5142
5144
  obligationInfo.obligationId,
@@ -7975,6 +7977,7 @@ export {
7975
7977
  MAX_LOCK_ROUNDS,
7976
7978
  MIN_INITIAL_LOCK_AMOUNT,
7977
7979
  MIN_TOP_UP_AMOUNT,
7980
+ NATIVE_USDC,
7978
7981
  OLD_BORROW_INCENTIVE_PROTOCOL_ID,
7979
7982
  PROTOCOL_OBJECT_ID,
7980
7983
  SCA_COIN_TYPE,