@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.
@@ -7,6 +7,7 @@ export declare const PROTOCOL_OBJECT_ID: "0xc9f859f98ca352a11b97a038c4b4162bee43
7
7
  export declare const BORROW_FEE_PROTOCOL_ID: "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" | "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
8
8
  export declare const SCA_COIN_TYPE: "0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA" | "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA";
9
9
  export declare const OLD_BORROW_INCENTIVE_PROTOCOL_ID: "0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410";
10
+ export declare const NATIVE_USDC: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
10
11
  export declare const SUPPORT_POOLS: readonly ["eth", "btc", "usdc", "usdt", "sui", "apt", "sol", "cetus", "afsui", "hasui", "vsui", "sca"];
11
12
  export declare const SUPPORT_COLLATERALS: readonly ["eth", "btc", "usdc", "usdt", "sui", "apt", "sol", "cetus", "afsui", "hasui", "vsui", "sca"];
12
13
  export declare const SUPPORT_SPOOLS: readonly ["seth", "ssui", "susdc", "susdt", "scetus", "safsui", "shasui", "svsui"];
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ __export(src_exports, {
39
39
  MAX_LOCK_ROUNDS: () => MAX_LOCK_ROUNDS,
40
40
  MIN_INITIAL_LOCK_AMOUNT: () => MIN_INITIAL_LOCK_AMOUNT,
41
41
  MIN_TOP_UP_AMOUNT: () => MIN_TOP_UP_AMOUNT,
42
+ NATIVE_USDC: () => NATIVE_USDC,
42
43
  OLD_BORROW_INCENTIVE_PROTOCOL_ID: () => OLD_BORROW_INCENTIVE_PROTOCOL_ID,
43
44
  PROTOCOL_OBJECT_ID: () => PROTOCOL_OBJECT_ID,
44
45
  SCA_COIN_TYPE: () => SCA_COIN_TYPE,
@@ -86,6 +87,7 @@ var PROTOCOL_OBJECT_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee4
86
87
  var BORROW_FEE_PROTOCOL_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
87
88
  var SCA_COIN_TYPE = IS_VE_SCA_TEST ? `0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA` : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA";
88
89
  var OLD_BORROW_INCENTIVE_PROTOCOL_ID = "0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410";
90
+ var NATIVE_USDC = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
89
91
  var SUPPORT_POOLS = [
90
92
  "eth",
91
93
  "btc",
@@ -2309,19 +2311,21 @@ var queryMarket = async (query, indexer = false) => {
2309
2311
  const collaterals = {};
2310
2312
  if (indexer) {
2311
2313
  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
- }
2314
+ const updatePools = (item) => {
2315
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2316
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2317
+ pools[item.coinName] = item;
2318
+ };
2319
+ const updateCollaterals = (item) => {
2320
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2321
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2322
+ collaterals[item.coinName] = item;
2323
+ };
2324
+ Object.values(marketIndexer.pools).forEach(updatePools);
2325
+ Object.values(marketIndexer.collaterals).forEach(updateCollaterals);
2322
2326
  return {
2323
- pools: marketIndexer.pools,
2324
- collaterals: marketIndexer.collaterals
2327
+ pools,
2328
+ collaterals
2325
2329
  };
2326
2330
  }
2327
2331
  const packageId = query.address.get("core.packages.query.id");
@@ -2332,6 +2336,8 @@ var queryMarket = async (query, indexer = false) => {
2332
2336
  const marketData = queryResult?.events[0].parsedJson;
2333
2337
  for (const pool of marketData?.pools ?? []) {
2334
2338
  const coinType = (0, import_utils3.normalizeStructTag)(pool.type.name);
2339
+ if (coinType === NATIVE_USDC)
2340
+ continue;
2335
2341
  const poolCoinName = query.utils.parseCoinNameFromType(coinType);
2336
2342
  const coinPrice = coinPrices[poolCoinName] ?? 0;
2337
2343
  if (!SUPPORT_POOLS.includes(poolCoinName)) {
@@ -2431,25 +2437,25 @@ var queryMarket = async (query, indexer = false) => {
2431
2437
  data: marketData
2432
2438
  };
2433
2439
  };
2434
- var getMarketPools = async (query, poolCoinNames, indexer = false) => {
2435
- poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
2440
+ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false) => {
2436
2441
  const marketId = query.address.get("core.market");
2437
2442
  const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2438
2443
  showContent: true
2439
2444
  });
2440
- const coinPrices = await query.utils.getCoinPrices(poolCoinNames ?? []);
2445
+ const coinPrices = await query.utils.getCoinPrices(poolCoinNames) ?? {};
2441
2446
  const marketPools = {};
2442
2447
  if (indexer) {
2443
2448
  const marketPoolsIndexer = await query.indexer.getMarketPools();
2444
- for (const marketPool of Object.values(marketPoolsIndexer)) {
2449
+ const updateMarketPool = (marketPool) => {
2445
2450
  if (!poolCoinNames.includes(marketPool.coinName))
2446
- continue;
2451
+ return;
2447
2452
  marketPool.coinPrice = coinPrices[marketPool.coinName] || marketPool.coinPrice;
2448
2453
  marketPool.coinWrappedType = query.utils.getCoinWrappedType(
2449
2454
  marketPool.coinName
2450
2455
  );
2451
2456
  marketPools[marketPool.coinName] = marketPool;
2452
- }
2457
+ };
2458
+ Object.values(marketPoolsIndexer).forEach(updateMarketPool);
2453
2459
  return marketPools;
2454
2460
  }
2455
2461
  await Promise.allSettled(
@@ -2474,6 +2480,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2474
2480
  let borrowIndex;
2475
2481
  let interestModel;
2476
2482
  let borrowFeeRate;
2483
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2477
2484
  if (indexer) {
2478
2485
  const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
2479
2486
  marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
@@ -2486,7 +2493,6 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2486
2493
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2487
2494
  showContent: true
2488
2495
  }))?.data;
2489
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2490
2496
  if (marketObject) {
2491
2497
  if (marketObject.content && "fields" in marketObject.content) {
2492
2498
  const fields = marketObject.content.fields;
@@ -2616,29 +2622,27 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2616
2622
  }
2617
2623
  return marketPool;
2618
2624
  };
2619
- var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
2620
- collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
2625
+ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
2621
2626
  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
- ]);
2627
+ const coinPrices = await query.utils.getCoinPrices(collateralCoinNames) ?? {};
2628
2628
  const marketCollaterals = {};
2629
2629
  if (indexer) {
2630
2630
  const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
2631
- for (const marketCollateral of Object.values(marketCollateralsIndexer)) {
2631
+ const updateMarketCollateral = (marketCollateral) => {
2632
2632
  if (!collateralCoinNames.includes(marketCollateral.coinName))
2633
- continue;
2633
+ return;
2634
2634
  marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
2635
2635
  marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
2636
2636
  marketCollateral.coinName
2637
2637
  );
2638
2638
  marketCollaterals[marketCollateral.coinName] = marketCollateral;
2639
- }
2639
+ };
2640
+ Object.values(marketCollateralsIndexer).forEach(updateMarketCollateral);
2640
2641
  return marketCollaterals;
2641
2642
  }
2643
+ const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2644
+ showContent: true
2645
+ });
2642
2646
  await Promise.allSettled(
2643
2647
  collateralCoinNames.map(async (collateralCoinName) => {
2644
2648
  const marketCollateral = await getMarketCollateral(
@@ -2656,6 +2660,7 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
2656
2660
  return marketCollaterals;
2657
2661
  };
2658
2662
  var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
2663
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2659
2664
  if (indexer) {
2660
2665
  const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
2661
2666
  marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
@@ -2671,7 +2676,6 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
2671
2676
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2672
2677
  showContent: true
2673
2678
  }))?.data;
2674
- coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2675
2679
  if (marketObject) {
2676
2680
  if (marketObject.content && "fields" in marketObject.content) {
2677
2681
  const fields = marketObject.content.fields;
@@ -2921,8 +2925,7 @@ var getFlashLoanFees = async (query, assetNames) => {
2921
2925
 
2922
2926
  // src/queries/spoolQuery.ts
2923
2927
  var import_utils5 = require("@mysten/sui.js/utils");
2924
- var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2925
- stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
2928
+ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false) => {
2926
2929
  const stakeCoinNames = stakeMarketCoinNames.map(
2927
2930
  (stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
2928
2931
  );
@@ -2930,16 +2933,16 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2930
2933
  const rewardCoinName = query.utils.getSpoolRewardCoinName(stakeMarketCoinName);
2931
2934
  return rewardCoinName;
2932
2935
  });
2933
- const coinPrices = await query.utils.getCoinPrices(
2934
- [.../* @__PURE__ */ new Set([...stakeCoinNames, ...rewardCoinNames])]
2935
- );
2936
+ const coinPrices = await query.utils.getCoinPrices([
2937
+ .../* @__PURE__ */ new Set([...stakeCoinNames, ...rewardCoinNames])
2938
+ ]) ?? {};
2936
2939
  const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
2937
2940
  const spools = {};
2938
2941
  if (indexer) {
2939
2942
  const spoolsIndexer = await query.indexer.getSpools();
2940
- for (const spool of Object.values(spoolsIndexer)) {
2943
+ const updateSpools = (spool) => {
2941
2944
  if (!stakeMarketCoinNames.includes(spool.marketCoinName))
2942
- continue;
2945
+ return;
2943
2946
  const coinName = query.utils.parseCoinName(
2944
2947
  spool.marketCoinName
2945
2948
  );
@@ -2951,7 +2954,8 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2951
2954
  spool.marketCoinPrice = (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
2952
2955
  spool.rewardCoinPrice = coinPrices[rewardCoinName] || spool.rewardCoinPrice;
2953
2956
  spools[spool.marketCoinName] = spool;
2954
- }
2957
+ };
2958
+ Object.values(spoolsIndexer).forEach(updateSpools);
2955
2959
  return spools;
2956
2960
  }
2957
2961
  for (const stakeMarketCoinName of stakeMarketCoinNames) {
@@ -2977,6 +2981,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
2977
2981
  `spool.pools.${marketCoinName}.rewardPoolId`
2978
2982
  );
2979
2983
  let spool = void 0;
2984
+ coinPrices = coinPrices || await query.utils.getCoinPrices([coinName]);
2980
2985
  if (indexer) {
2981
2986
  const spoolIndexer = await query.indexer.getSpool(marketCoinName);
2982
2987
  const coinName2 = query.utils.parseCoinName(marketCoinName);
@@ -3305,29 +3310,27 @@ var getStakeRewardPool = async ({
3305
3310
  // src/queries/borrowIncentiveQuery.ts
3306
3311
  var import_utils7 = require("@mysten/sui.js/utils");
3307
3312
  var import_bignumber3 = __toESM(require("bignumber.js"));
3308
- var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
3309
- borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
3310
- ...SUPPORT_BORROW_INCENTIVE_POOLS
3311
- ];
3313
+ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
3314
+ ...SUPPORT_BORROW_INCENTIVE_POOLS
3315
+ ], indexer = false) => {
3312
3316
  const borrowIncentivePools = {};
3313
- const coinPrices = await query.utils.getCoinPrices(
3314
- [
3315
- .../* @__PURE__ */ new Set([
3316
- ...borrowIncentiveCoinNames,
3317
- ...SUPPORT_BORROW_INCENTIVE_REWARDS
3318
- ])
3319
- ]
3320
- );
3317
+ const coinPrices = await query.utils.getCoinPrices([
3318
+ .../* @__PURE__ */ new Set([
3319
+ ...borrowIncentiveCoinNames,
3320
+ ...SUPPORT_BORROW_INCENTIVE_REWARDS
3321
+ ])
3322
+ ]) ?? {};
3321
3323
  if (indexer) {
3322
3324
  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
- }
3325
+ const updateBorrowIncentivePool = (pool) => {
3326
+ if (!borrowIncentiveCoinNames.includes(pool.coinName))
3327
+ return;
3328
+ pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
3329
+ borrowIncentivePools[pool.coinName] = pool;
3330
+ };
3331
+ Object.values(borrowIncentivePoolsIndexer).forEach(
3332
+ updateBorrowIncentivePool
3333
+ );
3331
3334
  return borrowIncentivePools;
3332
3335
  }
3333
3336
  const queryPkgId = query.address.get("borrowIncentive.query");
@@ -5207,7 +5210,7 @@ var generateCoreQuickMethod = ({
5207
5210
  const obligationCoinNames = await builder.utils.getObligationCoinNames(
5208
5211
  obligationInfo.obligationId
5209
5212
  ) ?? [];
5210
- const updateCoinNames = [...obligationCoinNames ?? [], poolCoinName];
5213
+ const updateCoinNames = [...obligationCoinNames, poolCoinName];
5211
5214
  await updateOracles(builder, txBlock, updateCoinNames);
5212
5215
  return txBlock.borrow(
5213
5216
  obligationInfo.obligationId,
@@ -8036,6 +8039,7 @@ var Scallop = class {
8036
8039
  MAX_LOCK_ROUNDS,
8037
8040
  MIN_INITIAL_LOCK_AMOUNT,
8038
8041
  MIN_TOP_UP_AMOUNT,
8042
+ NATIVE_USDC,
8039
8043
  OLD_BORROW_INCENTIVE_PROTOCOL_ID,
8040
8044
  PROTOCOL_OBJECT_ID,
8041
8045
  SCA_COIN_TYPE,