@scallop-io/sui-scallop-sdk 0.46.37 → 0.46.39

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
@@ -1618,13 +1618,14 @@ var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
1618
1618
  };
1619
1619
  };
1620
1620
  var parseOriginMarketCollateralData = (originMarketCollateralData) => {
1621
+ const divisor = 2 ** 32;
1621
1622
  return {
1622
1623
  coinType: (0, import_utils.normalizeStructTag)(originMarketCollateralData.type.name),
1623
- collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / 2 ** 32,
1624
- liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / 2 ** 32,
1625
- liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / 2 ** 32,
1626
- liquidationPanelty: Number(originMarketCollateralData.liquidationPanelty.value) / 2 ** 32,
1627
- liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) / 2 ** 32,
1624
+ collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / divisor,
1625
+ liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / divisor,
1626
+ liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / divisor,
1627
+ liquidationPanelty: Number(originMarketCollateralData.liquidationPanelty.value) / divisor,
1628
+ liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) / divisor,
1628
1629
  maxCollateralAmount: Number(originMarketCollateralData.maxCollateralAmount),
1629
1630
  totalCollateralAmount: Number(
1630
1631
  originMarketCollateralData.totalCollateralAmount
@@ -1966,15 +1967,6 @@ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
1966
1967
  // src/queries/coreQuery.ts
1967
1968
  var import_bignumber2 = __toESM(require("bignumber.js"));
1968
1969
  var queryMarket = async (query, indexer = false) => {
1969
- const packageId = query.address.get("core.packages.query.id");
1970
- const marketId = query.address.get("core.market");
1971
- const queryTarget = `${packageId}::market_query::market_data`;
1972
- const args = [marketId];
1973
- const queryResult = await query.cache.queryInspectTxn(
1974
- { queryTarget, args }
1975
- // txBlock
1976
- );
1977
- const marketData = queryResult.events[0].parsedJson;
1978
1970
  const coinPrices = await query.utils.getCoinPrices();
1979
1971
  const pools = {};
1980
1972
  const collaterals = {};
@@ -1995,6 +1987,12 @@ var queryMarket = async (query, indexer = false) => {
1995
1987
  collaterals: marketIndexer.collaterals
1996
1988
  };
1997
1989
  }
1990
+ const packageId = query.address.get("core.packages.query.id");
1991
+ const marketId = query.address.get("core.market");
1992
+ const queryTarget = `${packageId}::market_query::market_data`;
1993
+ const args = [marketId];
1994
+ const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
1995
+ const marketData = queryResult.events[0].parsedJson;
1998
1996
  for (const pool of marketData.pools) {
1999
1997
  const coinType = (0, import_utils2.normalizeStructTag)(pool.type.name);
2000
1998
  const poolCoinName = query.utils.parseCoinNameFromType(coinType);
@@ -2109,26 +2107,23 @@ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
2109
2107
  }
2110
2108
  return marketPools;
2111
2109
  }
2112
- for (const poolCoinName of poolCoinNames) {
2113
- const marketPool = await getMarketPool(
2114
- query,
2115
- poolCoinName,
2116
- indexer,
2117
- marketObjectResponse.data,
2118
- coinPrices?.[poolCoinName]
2119
- );
2120
- if (marketPool) {
2121
- marketPools[poolCoinName] = marketPool;
2122
- }
2123
- }
2110
+ await Promise.allSettled(
2111
+ poolCoinNames.map(async (poolCoinName) => {
2112
+ const marketPool = await getMarketPool(
2113
+ query,
2114
+ poolCoinName,
2115
+ indexer,
2116
+ marketObjectResponse.data,
2117
+ coinPrices?.[poolCoinName]
2118
+ );
2119
+ if (marketPool) {
2120
+ marketPools[poolCoinName] = marketPool;
2121
+ }
2122
+ })
2123
+ );
2124
2124
  return marketPools;
2125
2125
  };
2126
2126
  var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
2127
- const marketId = query.address.get("core.market");
2128
- marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2129
- showContent: true
2130
- })).data;
2131
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2132
2127
  let marketPool;
2133
2128
  let balanceSheet;
2134
2129
  let borrowIndex;
@@ -2142,6 +2137,11 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2142
2137
  );
2143
2138
  return marketPoolIndexer;
2144
2139
  }
2140
+ const marketId = query.address.get("core.market");
2141
+ marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2142
+ showContent: true
2143
+ })).data;
2144
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2145
2145
  if (marketObject) {
2146
2146
  if (marketObject.content && "fields" in marketObject.content) {
2147
2147
  const fields = marketObject.content.fields;
@@ -2258,10 +2258,12 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2258
2258
  var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
2259
2259
  collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
2260
2260
  const marketId = query.address.get("core.market");
2261
- const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2262
- showContent: true
2263
- });
2264
- const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
2261
+ const [marketObjectResponse, coinPrices] = await Promise.all([
2262
+ query.cache.queryGetObject(marketId, {
2263
+ showContent: true
2264
+ }),
2265
+ query.utils.getCoinPrices(collateralCoinNames ?? [])
2266
+ ]);
2265
2267
  const marketCollaterals = {};
2266
2268
  if (indexer) {
2267
2269
  const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
@@ -2276,29 +2278,23 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
2276
2278
  }
2277
2279
  return marketCollaterals;
2278
2280
  }
2279
- for (const collateralCoinName of collateralCoinNames) {
2280
- const marketCollateral = await getMarketCollateral(
2281
- query,
2282
- collateralCoinName,
2283
- indexer,
2284
- marketObjectResponse.data,
2285
- coinPrices?.[collateralCoinName]
2286
- );
2287
- if (marketCollateral) {
2288
- marketCollaterals[collateralCoinName] = marketCollateral;
2289
- }
2290
- }
2281
+ await Promise.allSettled(
2282
+ collateralCoinNames.map(async (collateralCoinName) => {
2283
+ const marketCollateral = await getMarketCollateral(
2284
+ query,
2285
+ collateralCoinName,
2286
+ indexer,
2287
+ marketObjectResponse.data,
2288
+ coinPrices?.[collateralCoinName]
2289
+ );
2290
+ if (marketCollateral) {
2291
+ marketCollaterals[collateralCoinName] = marketCollateral;
2292
+ }
2293
+ })
2294
+ );
2291
2295
  return marketCollaterals;
2292
2296
  };
2293
2297
  var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
2294
- const marketId = query.address.get("core.market");
2295
- marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2296
- showContent: true
2297
- })).data;
2298
- coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2299
- let marketCollateral;
2300
- let riskModel;
2301
- let collateralStat;
2302
2298
  if (indexer) {
2303
2299
  const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
2304
2300
  marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
@@ -2307,6 +2303,14 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
2307
2303
  );
2308
2304
  return marketCollateralIndexer;
2309
2305
  }
2306
+ let marketCollateral;
2307
+ let riskModel;
2308
+ let collateralStat;
2309
+ const marketId = query.address.get("core.market");
2310
+ marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2311
+ showContent: true
2312
+ })).data;
2313
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2310
2314
  if (marketObject) {
2311
2315
  if (marketObject.content && "fields" in marketObject.content) {
2312
2316
  const fields = marketObject.content.fields;
@@ -2401,15 +2405,17 @@ var getObligations = async (query, ownerAddress) => {
2401
2405
  const keyObjectIds = keyObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
2402
2406
  const keyObjects = await query.cache.queryGetObjects(keyObjectIds);
2403
2407
  const obligations = [];
2404
- for (const keyObject of keyObjects) {
2405
- const keyId = keyObject.objectId;
2406
- if (keyObject.content && "fields" in keyObject.content) {
2407
- const fields = keyObject.content.fields;
2408
- const obligationId = String(fields.ownership.fields.of);
2409
- const locked = await getObligationLocked(query, obligationId);
2410
- obligations.push({ id: obligationId, keyId, locked });
2411
- }
2412
- }
2408
+ await Promise.allSettled(
2409
+ keyObjects.map(async (keyObject) => {
2410
+ const keyId = keyObject.objectId;
2411
+ if (keyObject.content && "fields" in keyObject.content) {
2412
+ const fields = keyObject.content.fields;
2413
+ const obligationId = String(fields.ownership.fields.of);
2414
+ const locked = await getObligationLocked(query, obligationId);
2415
+ obligations.push({ id: obligationId, keyId, locked });
2416
+ }
2417
+ })
2418
+ );
2413
2419
  return obligations;
2414
2420
  };
2415
2421
  var getObligationLocked = async (query, obligationId) => {
@@ -2462,7 +2468,7 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
2462
2468
  );
2463
2469
  const owner = ownerAddress || query.suiKit.currentAddress();
2464
2470
  const marketCoins2 = {};
2465
- Promise.allSettled(
2471
+ await Promise.allSettled(
2466
2472
  marketCoinNames.map(async (marketCoinName) => {
2467
2473
  const marketCoin = await getMarketCoinAmount(
2468
2474
  query,
@@ -2863,12 +2869,6 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
2863
2869
  borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
2864
2870
  ...SUPPORT_BORROW_INCENTIVE_POOLS
2865
2871
  ];
2866
- const queryPkgId = query.address.get("borrowIncentive.query");
2867
- const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
2868
- const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
2869
- const args = [incentivePoolsId];
2870
- const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
2871
- const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
2872
2872
  const borrowIncentivePools = {};
2873
2873
  const coinPrices = await query.utils.getCoinPrices(
2874
2874
  [
@@ -2890,6 +2890,12 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
2890
2890
  }
2891
2891
  return borrowIncentivePools;
2892
2892
  }
2893
+ const queryPkgId = query.address.get("borrowIncentive.query");
2894
+ const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
2895
+ const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
2896
+ const args = [incentivePoolsId];
2897
+ const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
2898
+ const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
2893
2899
  for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
2894
2900
  const borrowIncentivePoolPoints = {};
2895
2901
  const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
@@ -3099,34 +3105,42 @@ var getLendings = async (query, poolCoinNames, ownerAddress, indexer = false) =>
3099
3105
  const stakeMarketCoinNames = marketCoinNames.filter(
3100
3106
  (marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
3101
3107
  );
3102
- const marketPools = await query.getMarketPools(poolCoinNames, indexer);
3103
- const spools = await query.getSpools(stakeMarketCoinNames, indexer);
3104
- const coinAmounts = await query.getCoinAmounts(poolCoinNames, ownerAddress);
3105
- const marketCoinAmounts = await query.getMarketCoinAmounts(
3106
- marketCoinNames,
3107
- ownerAddress
3108
- );
3109
- const allStakeAccounts = await query.getAllStakeAccounts(ownerAddress);
3110
- const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
3108
+ const [
3109
+ marketPools,
3110
+ spools,
3111
+ coinAmounts,
3112
+ marketCoinAmounts,
3113
+ allStakeAccounts,
3114
+ coinPrices
3115
+ ] = await Promise.all([
3116
+ query.getMarketPools(poolCoinNames, indexer),
3117
+ query.getSpools(stakeMarketCoinNames, indexer),
3118
+ query.getCoinAmounts(poolCoinNames, ownerAddress),
3119
+ query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
3120
+ query.getAllStakeAccounts(ownerAddress),
3121
+ query.utils.getCoinPrices(poolCoinNames)
3122
+ ]);
3111
3123
  const lendings = {};
3112
- for (const poolCoinName of poolCoinNames) {
3113
- const stakeMarketCoinName = stakeMarketCoinNames.find(
3114
- (marketCoinName2) => marketCoinName2 === query.utils.parseMarketCoinName(poolCoinName)
3115
- );
3116
- const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
3117
- lendings[poolCoinName] = await getLending(
3118
- query,
3119
- poolCoinName,
3120
- ownerAddress,
3121
- indexer,
3122
- marketPools?.[poolCoinName],
3123
- stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
3124
- stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : void 0,
3125
- coinAmounts?.[poolCoinName],
3126
- marketCoinAmounts?.[marketCoinName],
3127
- coinPrices?.[poolCoinName] ?? 0
3128
- );
3129
- }
3124
+ await Promise.allSettled(
3125
+ poolCoinNames.map(async (poolCoinName) => {
3126
+ const stakeMarketCoinName = stakeMarketCoinNames.find(
3127
+ (marketCoinName2) => marketCoinName2 === query.utils.parseMarketCoinName(poolCoinName)
3128
+ );
3129
+ const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
3130
+ lendings[poolCoinName] = await getLending(
3131
+ query,
3132
+ poolCoinName,
3133
+ ownerAddress,
3134
+ indexer,
3135
+ marketPools?.[poolCoinName],
3136
+ stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
3137
+ stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : void 0,
3138
+ coinAmounts?.[poolCoinName],
3139
+ marketCoinAmounts?.[marketCoinName],
3140
+ coinPrices?.[poolCoinName] ?? 0
3141
+ );
3142
+ })
3143
+ );
3130
3144
  return lendings;
3131
3145
  };
3132
3146
  var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice) => {
@@ -3603,7 +3617,7 @@ var getVescaKeys = async (query, ownerAddress) => {
3603
3617
  let hasNextPage = false;
3604
3618
  let nextCursor = null;
3605
3619
  do {
3606
- const paginatedKeyObjectsResponse = await query.suiKit.client().getOwnedObjects({
3620
+ const paginatedKeyObjectsResponse = await query.cache.queryGetOwnedObjects({
3607
3621
  owner,
3608
3622
  filter: {
3609
3623
  StructType: veScaKeyType
@@ -4242,15 +4256,17 @@ var ScallopQuery = class {
4242
4256
  async getStakeRewardPools(stakeMarketCoinNames) {
4243
4257
  stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
4244
4258
  const stakeRewardPools = {};
4245
- for (const stakeMarketCoinName of stakeMarketCoinNames) {
4246
- const stakeRewardPool = await getStakeRewardPool(
4247
- this,
4248
- stakeMarketCoinName
4249
- );
4250
- if (stakeRewardPool) {
4251
- stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
4252
- }
4253
- }
4259
+ await Promise.allSettled(
4260
+ stakeMarketCoinNames.map(async (stakeMarketCoinName) => {
4261
+ const stakeRewardPool = await getStakeRewardPool(
4262
+ this,
4263
+ stakeMarketCoinName
4264
+ );
4265
+ if (stakeRewardPool) {
4266
+ stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
4267
+ }
4268
+ })
4269
+ );
4254
4270
  return stakeRewardPools;
4255
4271
  }
4256
4272
  /**