@scallop-io/sui-scallop-sdk 0.44.5 → 0.44.6

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
@@ -2311,16 +2311,19 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2311
2311
  let totalBorrowedPools = 0;
2312
2312
  let totalBorrowedValue = BigNumber3(0);
2313
2313
  let totalBorrowedValueWithWeight = BigNumber3(0);
2314
- for (const collateral of obligationQuery.collaterals) {
2315
- const collateralCoinName = query.utils.parseCoinNameFromType(
2316
- collateral.type.name
2317
- );
2318
- const coinDecimal = query.utils.getCoinDecimal(collateralCoinName);
2319
- const marketCollateral = market.collaterals[collateralCoinName];
2320
- const coinPrice = coinPrices?.[collateralCoinName];
2321
- const coinAmount = coinAmounts?.[collateralCoinName] ?? 0;
2314
+ for (const assetCoinName of assetCoinNames) {
2315
+ const collateral = obligationQuery.collaterals.find((collateral2) => {
2316
+ const collateralCoinName = query.utils.parseCoinNameFromType(
2317
+ collateral2.type.name
2318
+ );
2319
+ return assetCoinName === collateralCoinName;
2320
+ });
2321
+ const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
2322
+ const marketCollateral = market.collaterals[assetCoinName];
2323
+ const coinPrice = coinPrices?.[assetCoinName];
2324
+ const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
2322
2325
  if (marketCollateral && coinPrice) {
2323
- const depositedAmount = BigNumber3(collateral.amount);
2326
+ const depositedAmount = BigNumber3(collateral?.amount ?? 0);
2324
2327
  const depositedCoin = depositedAmount.shiftedBy(-1 * coinDecimal);
2325
2328
  const depositedValue = depositedCoin.multipliedBy(coinPrice);
2326
2329
  const borrowCapacityValue = depositedValue.multipliedBy(
@@ -2341,10 +2344,10 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2341
2344
  if (depositedAmount.isGreaterThan(0)) {
2342
2345
  totalDepositedPools++;
2343
2346
  }
2344
- collaterals[collateralCoinName] = {
2345
- coinName: collateralCoinName,
2346
- coinType: collateral.type.name,
2347
- symbol: query.utils.parseSymbol(collateralCoinName),
2347
+ collaterals[assetCoinName] = {
2348
+ coinName: assetCoinName,
2349
+ coinType: query.utils.parseCoinType(assetCoinName),
2350
+ symbol: query.utils.parseSymbol(assetCoinName),
2348
2351
  coinDecimal,
2349
2352
  coinPrice,
2350
2353
  depositedAmount: depositedAmount.toNumber(),
@@ -2359,16 +2362,19 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2359
2362
  };
2360
2363
  }
2361
2364
  }
2362
- for (const debt of obligationQuery.debts) {
2363
- const poolCoinName = query.utils.parseCoinNameFromType(
2364
- debt.type.name
2365
- );
2366
- const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
2367
- const marketPool = market.pools[poolCoinName];
2368
- const coinPrice = coinPrices?.[poolCoinName];
2365
+ for (const assetCoinName of assetCoinNames) {
2366
+ const debt = obligationQuery.debts.find((debt2) => {
2367
+ const poolCoinName = query.utils.parseCoinNameFromType(
2368
+ debt2.type.name
2369
+ );
2370
+ return assetCoinName === poolCoinName;
2371
+ });
2372
+ const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
2373
+ const marketPool = market.pools[assetCoinName];
2374
+ const coinPrice = coinPrices?.[assetCoinName];
2369
2375
  if (marketPool && coinPrice) {
2370
- const increasedRate = marketPool.borrowIndex / Number(debt.borrowIndex) - 1;
2371
- const borrowedAmount = BigNumber3(debt.amount);
2376
+ const increasedRate = debt?.borrowIndex ? marketPool.borrowIndex / Number(debt.borrowIndex) - 1 : 0;
2377
+ const borrowedAmount = BigNumber3(debt?.amount ?? 0);
2372
2378
  const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
2373
2379
  const availableRepayAmount = borrowedAmount.multipliedBy(
2374
2380
  increasedRate + 1
@@ -2387,17 +2393,17 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2387
2393
  if (borrowedAmount.isGreaterThan(0)) {
2388
2394
  totalBorrowedPools++;
2389
2395
  }
2390
- debts[poolCoinName] = {
2391
- coinName: poolCoinName,
2392
- coinType: debt.type.name,
2393
- symbol: query.utils.parseSymbol(poolCoinName),
2396
+ debts[assetCoinName] = {
2397
+ coinName: assetCoinName,
2398
+ coinType: query.utils.parseCoinType(assetCoinName),
2399
+ symbol: query.utils.parseSymbol(assetCoinName),
2394
2400
  coinDecimal,
2395
2401
  coinPrice,
2396
2402
  borrowedAmount: borrowedAmount.toNumber(),
2397
2403
  borrowedCoin: borrowedCoin.toNumber(),
2398
2404
  borrowedValue: borrowedValue.toNumber(),
2399
2405
  borrowedValueWithWeight: borrowedValueWithWeight.toNumber(),
2400
- borrowIndex: Number(debt.borrowIndex),
2406
+ borrowIndex: Number(debt?.borrowIndex ?? 0),
2401
2407
  availableBorrowAmount: 0,
2402
2408
  availableBorrowCoin: 0,
2403
2409
  availableRepayAmount: availableRepayAmount.toNumber(),
@@ -2848,10 +2854,11 @@ var ScallopQuery = class {
2848
2854
  * borrowing and obligation information for specific pool.
2849
2855
  *
2850
2856
  * @param obligationId - The obligation id.
2857
+ * @param ownerAddress - The owner address.
2851
2858
  * @return Borrowing and collateral information.
2852
2859
  */
2853
- async getObligationAccount(obligationId) {
2854
- return await getObligationAccount(this, obligationId);
2860
+ async getObligationAccount(obligationId, ownerAddress) {
2861
+ return await getObligationAccount(this, obligationId, ownerAddress);
2855
2862
  }
2856
2863
  /**
2857
2864
  * Get total value locked.