@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.mjs CHANGED
@@ -1545,13 +1545,14 @@ var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
1545
1545
  };
1546
1546
  };
1547
1547
  var parseOriginMarketCollateralData = (originMarketCollateralData) => {
1548
+ const divisor = 2 ** 32;
1548
1549
  return {
1549
1550
  coinType: normalizeStructTag2(originMarketCollateralData.type.name),
1550
- collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / 2 ** 32,
1551
- liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / 2 ** 32,
1552
- liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / 2 ** 32,
1553
- liquidationPanelty: Number(originMarketCollateralData.liquidationPanelty.value) / 2 ** 32,
1554
- liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) / 2 ** 32,
1551
+ collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / divisor,
1552
+ liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / divisor,
1553
+ liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / divisor,
1554
+ liquidationPanelty: Number(originMarketCollateralData.liquidationPanelty.value) / divisor,
1555
+ liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) / divisor,
1555
1556
  maxCollateralAmount: Number(originMarketCollateralData.maxCollateralAmount),
1556
1557
  totalCollateralAmount: Number(
1557
1558
  originMarketCollateralData.totalCollateralAmount
@@ -1893,15 +1894,6 @@ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
1893
1894
  // src/queries/coreQuery.ts
1894
1895
  import BigNumber2 from "bignumber.js";
1895
1896
  var queryMarket = async (query, indexer = false) => {
1896
- const packageId = query.address.get("core.packages.query.id");
1897
- const marketId = query.address.get("core.market");
1898
- const queryTarget = `${packageId}::market_query::market_data`;
1899
- const args = [marketId];
1900
- const queryResult = await query.cache.queryInspectTxn(
1901
- { queryTarget, args }
1902
- // txBlock
1903
- );
1904
- const marketData = queryResult.events[0].parsedJson;
1905
1897
  const coinPrices = await query.utils.getCoinPrices();
1906
1898
  const pools = {};
1907
1899
  const collaterals = {};
@@ -1922,6 +1914,12 @@ var queryMarket = async (query, indexer = false) => {
1922
1914
  collaterals: marketIndexer.collaterals
1923
1915
  };
1924
1916
  }
1917
+ const packageId = query.address.get("core.packages.query.id");
1918
+ const marketId = query.address.get("core.market");
1919
+ const queryTarget = `${packageId}::market_query::market_data`;
1920
+ const args = [marketId];
1921
+ const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
1922
+ const marketData = queryResult.events[0].parsedJson;
1925
1923
  for (const pool of marketData.pools) {
1926
1924
  const coinType = normalizeStructTag3(pool.type.name);
1927
1925
  const poolCoinName = query.utils.parseCoinNameFromType(coinType);
@@ -2036,26 +2034,23 @@ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
2036
2034
  }
2037
2035
  return marketPools;
2038
2036
  }
2039
- for (const poolCoinName of poolCoinNames) {
2040
- const marketPool = await getMarketPool(
2041
- query,
2042
- poolCoinName,
2043
- indexer,
2044
- marketObjectResponse.data,
2045
- coinPrices?.[poolCoinName]
2046
- );
2047
- if (marketPool) {
2048
- marketPools[poolCoinName] = marketPool;
2049
- }
2050
- }
2037
+ await Promise.allSettled(
2038
+ poolCoinNames.map(async (poolCoinName) => {
2039
+ const marketPool = await getMarketPool(
2040
+ query,
2041
+ poolCoinName,
2042
+ indexer,
2043
+ marketObjectResponse.data,
2044
+ coinPrices?.[poolCoinName]
2045
+ );
2046
+ if (marketPool) {
2047
+ marketPools[poolCoinName] = marketPool;
2048
+ }
2049
+ })
2050
+ );
2051
2051
  return marketPools;
2052
2052
  };
2053
2053
  var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
2054
- const marketId = query.address.get("core.market");
2055
- marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2056
- showContent: true
2057
- })).data;
2058
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2059
2054
  let marketPool;
2060
2055
  let balanceSheet;
2061
2056
  let borrowIndex;
@@ -2069,6 +2064,11 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2069
2064
  );
2070
2065
  return marketPoolIndexer;
2071
2066
  }
2067
+ const marketId = query.address.get("core.market");
2068
+ marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2069
+ showContent: true
2070
+ })).data;
2071
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2072
2072
  if (marketObject) {
2073
2073
  if (marketObject.content && "fields" in marketObject.content) {
2074
2074
  const fields = marketObject.content.fields;
@@ -2185,10 +2185,12 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2185
2185
  var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
2186
2186
  collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
2187
2187
  const marketId = query.address.get("core.market");
2188
- const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2189
- showContent: true
2190
- });
2191
- const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
2188
+ const [marketObjectResponse, coinPrices] = await Promise.all([
2189
+ query.cache.queryGetObject(marketId, {
2190
+ showContent: true
2191
+ }),
2192
+ query.utils.getCoinPrices(collateralCoinNames ?? [])
2193
+ ]);
2192
2194
  const marketCollaterals = {};
2193
2195
  if (indexer) {
2194
2196
  const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
@@ -2203,29 +2205,23 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
2203
2205
  }
2204
2206
  return marketCollaterals;
2205
2207
  }
2206
- for (const collateralCoinName of collateralCoinNames) {
2207
- const marketCollateral = await getMarketCollateral(
2208
- query,
2209
- collateralCoinName,
2210
- indexer,
2211
- marketObjectResponse.data,
2212
- coinPrices?.[collateralCoinName]
2213
- );
2214
- if (marketCollateral) {
2215
- marketCollaterals[collateralCoinName] = marketCollateral;
2216
- }
2217
- }
2208
+ await Promise.allSettled(
2209
+ collateralCoinNames.map(async (collateralCoinName) => {
2210
+ const marketCollateral = await getMarketCollateral(
2211
+ query,
2212
+ collateralCoinName,
2213
+ indexer,
2214
+ marketObjectResponse.data,
2215
+ coinPrices?.[collateralCoinName]
2216
+ );
2217
+ if (marketCollateral) {
2218
+ marketCollaterals[collateralCoinName] = marketCollateral;
2219
+ }
2220
+ })
2221
+ );
2218
2222
  return marketCollaterals;
2219
2223
  };
2220
2224
  var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
2221
- const marketId = query.address.get("core.market");
2222
- marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2223
- showContent: true
2224
- })).data;
2225
- coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2226
- let marketCollateral;
2227
- let riskModel;
2228
- let collateralStat;
2229
2225
  if (indexer) {
2230
2226
  const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
2231
2227
  marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
@@ -2234,6 +2230,14 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
2234
2230
  );
2235
2231
  return marketCollateralIndexer;
2236
2232
  }
2233
+ let marketCollateral;
2234
+ let riskModel;
2235
+ let collateralStat;
2236
+ const marketId = query.address.get("core.market");
2237
+ marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2238
+ showContent: true
2239
+ })).data;
2240
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2237
2241
  if (marketObject) {
2238
2242
  if (marketObject.content && "fields" in marketObject.content) {
2239
2243
  const fields = marketObject.content.fields;
@@ -2328,15 +2332,17 @@ var getObligations = async (query, ownerAddress) => {
2328
2332
  const keyObjectIds = keyObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
2329
2333
  const keyObjects = await query.cache.queryGetObjects(keyObjectIds);
2330
2334
  const obligations = [];
2331
- for (const keyObject of keyObjects) {
2332
- const keyId = keyObject.objectId;
2333
- if (keyObject.content && "fields" in keyObject.content) {
2334
- const fields = keyObject.content.fields;
2335
- const obligationId = String(fields.ownership.fields.of);
2336
- const locked = await getObligationLocked(query, obligationId);
2337
- obligations.push({ id: obligationId, keyId, locked });
2338
- }
2339
- }
2335
+ await Promise.allSettled(
2336
+ keyObjects.map(async (keyObject) => {
2337
+ const keyId = keyObject.objectId;
2338
+ if (keyObject.content && "fields" in keyObject.content) {
2339
+ const fields = keyObject.content.fields;
2340
+ const obligationId = String(fields.ownership.fields.of);
2341
+ const locked = await getObligationLocked(query, obligationId);
2342
+ obligations.push({ id: obligationId, keyId, locked });
2343
+ }
2344
+ })
2345
+ );
2340
2346
  return obligations;
2341
2347
  };
2342
2348
  var getObligationLocked = async (query, obligationId) => {
@@ -2389,7 +2395,7 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
2389
2395
  );
2390
2396
  const owner = ownerAddress || query.suiKit.currentAddress();
2391
2397
  const marketCoins2 = {};
2392
- Promise.allSettled(
2398
+ await Promise.allSettled(
2393
2399
  marketCoinNames.map(async (marketCoinName) => {
2394
2400
  const marketCoin = await getMarketCoinAmount(
2395
2401
  query,
@@ -2790,12 +2796,6 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
2790
2796
  borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
2791
2797
  ...SUPPORT_BORROW_INCENTIVE_POOLS
2792
2798
  ];
2793
- const queryPkgId = query.address.get("borrowIncentive.query");
2794
- const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
2795
- const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
2796
- const args = [incentivePoolsId];
2797
- const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
2798
- const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
2799
2799
  const borrowIncentivePools = {};
2800
2800
  const coinPrices = await query.utils.getCoinPrices(
2801
2801
  [
@@ -2817,6 +2817,12 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
2817
2817
  }
2818
2818
  return borrowIncentivePools;
2819
2819
  }
2820
+ const queryPkgId = query.address.get("borrowIncentive.query");
2821
+ const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
2822
+ const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
2823
+ const args = [incentivePoolsId];
2824
+ const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
2825
+ const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
2820
2826
  for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
2821
2827
  const borrowIncentivePoolPoints = {};
2822
2828
  const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
@@ -3026,34 +3032,42 @@ var getLendings = async (query, poolCoinNames, ownerAddress, indexer = false) =>
3026
3032
  const stakeMarketCoinNames = marketCoinNames.filter(
3027
3033
  (marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
3028
3034
  );
3029
- const marketPools = await query.getMarketPools(poolCoinNames, indexer);
3030
- const spools = await query.getSpools(stakeMarketCoinNames, indexer);
3031
- const coinAmounts = await query.getCoinAmounts(poolCoinNames, ownerAddress);
3032
- const marketCoinAmounts = await query.getMarketCoinAmounts(
3033
- marketCoinNames,
3034
- ownerAddress
3035
- );
3036
- const allStakeAccounts = await query.getAllStakeAccounts(ownerAddress);
3037
- const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
3035
+ const [
3036
+ marketPools,
3037
+ spools,
3038
+ coinAmounts,
3039
+ marketCoinAmounts,
3040
+ allStakeAccounts,
3041
+ coinPrices
3042
+ ] = await Promise.all([
3043
+ query.getMarketPools(poolCoinNames, indexer),
3044
+ query.getSpools(stakeMarketCoinNames, indexer),
3045
+ query.getCoinAmounts(poolCoinNames, ownerAddress),
3046
+ query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
3047
+ query.getAllStakeAccounts(ownerAddress),
3048
+ query.utils.getCoinPrices(poolCoinNames)
3049
+ ]);
3038
3050
  const lendings = {};
3039
- for (const poolCoinName of poolCoinNames) {
3040
- const stakeMarketCoinName = stakeMarketCoinNames.find(
3041
- (marketCoinName2) => marketCoinName2 === query.utils.parseMarketCoinName(poolCoinName)
3042
- );
3043
- const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
3044
- lendings[poolCoinName] = await getLending(
3045
- query,
3046
- poolCoinName,
3047
- ownerAddress,
3048
- indexer,
3049
- marketPools?.[poolCoinName],
3050
- stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
3051
- stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : void 0,
3052
- coinAmounts?.[poolCoinName],
3053
- marketCoinAmounts?.[marketCoinName],
3054
- coinPrices?.[poolCoinName] ?? 0
3055
- );
3056
- }
3051
+ await Promise.allSettled(
3052
+ poolCoinNames.map(async (poolCoinName) => {
3053
+ const stakeMarketCoinName = stakeMarketCoinNames.find(
3054
+ (marketCoinName2) => marketCoinName2 === query.utils.parseMarketCoinName(poolCoinName)
3055
+ );
3056
+ const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
3057
+ lendings[poolCoinName] = await getLending(
3058
+ query,
3059
+ poolCoinName,
3060
+ ownerAddress,
3061
+ indexer,
3062
+ marketPools?.[poolCoinName],
3063
+ stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
3064
+ stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : void 0,
3065
+ coinAmounts?.[poolCoinName],
3066
+ marketCoinAmounts?.[marketCoinName],
3067
+ coinPrices?.[poolCoinName] ?? 0
3068
+ );
3069
+ })
3070
+ );
3057
3071
  return lendings;
3058
3072
  };
3059
3073
  var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice) => {
@@ -3530,7 +3544,7 @@ var getVescaKeys = async (query, ownerAddress) => {
3530
3544
  let hasNextPage = false;
3531
3545
  let nextCursor = null;
3532
3546
  do {
3533
- const paginatedKeyObjectsResponse = await query.suiKit.client().getOwnedObjects({
3547
+ const paginatedKeyObjectsResponse = await query.cache.queryGetOwnedObjects({
3534
3548
  owner,
3535
3549
  filter: {
3536
3550
  StructType: veScaKeyType
@@ -4169,15 +4183,17 @@ var ScallopQuery = class {
4169
4183
  async getStakeRewardPools(stakeMarketCoinNames) {
4170
4184
  stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
4171
4185
  const stakeRewardPools = {};
4172
- for (const stakeMarketCoinName of stakeMarketCoinNames) {
4173
- const stakeRewardPool = await getStakeRewardPool(
4174
- this,
4175
- stakeMarketCoinName
4176
- );
4177
- if (stakeRewardPool) {
4178
- stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
4179
- }
4180
- }
4186
+ await Promise.allSettled(
4187
+ stakeMarketCoinNames.map(async (stakeMarketCoinName) => {
4188
+ const stakeRewardPool = await getStakeRewardPool(
4189
+ this,
4190
+ stakeMarketCoinName
4191
+ );
4192
+ if (stakeRewardPool) {
4193
+ stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
4194
+ }
4195
+ })
4196
+ );
4181
4197
  return stakeRewardPools;
4182
4198
  }
4183
4199
  /**