@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.js CHANGED
@@ -2373,16 +2373,19 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2373
2373
  let totalBorrowedPools = 0;
2374
2374
  let totalBorrowedValue = (0, import_bignumber3.default)(0);
2375
2375
  let totalBorrowedValueWithWeight = (0, import_bignumber3.default)(0);
2376
- for (const collateral of obligationQuery.collaterals) {
2377
- const collateralCoinName = query.utils.parseCoinNameFromType(
2378
- collateral.type.name
2379
- );
2380
- const coinDecimal = query.utils.getCoinDecimal(collateralCoinName);
2381
- const marketCollateral = market.collaterals[collateralCoinName];
2382
- const coinPrice = coinPrices?.[collateralCoinName];
2383
- const coinAmount = coinAmounts?.[collateralCoinName] ?? 0;
2376
+ for (const assetCoinName of assetCoinNames) {
2377
+ const collateral = obligationQuery.collaterals.find((collateral2) => {
2378
+ const collateralCoinName = query.utils.parseCoinNameFromType(
2379
+ collateral2.type.name
2380
+ );
2381
+ return assetCoinName === collateralCoinName;
2382
+ });
2383
+ const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
2384
+ const marketCollateral = market.collaterals[assetCoinName];
2385
+ const coinPrice = coinPrices?.[assetCoinName];
2386
+ const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
2384
2387
  if (marketCollateral && coinPrice) {
2385
- const depositedAmount = (0, import_bignumber3.default)(collateral.amount);
2388
+ const depositedAmount = (0, import_bignumber3.default)(collateral?.amount ?? 0);
2386
2389
  const depositedCoin = depositedAmount.shiftedBy(-1 * coinDecimal);
2387
2390
  const depositedValue = depositedCoin.multipliedBy(coinPrice);
2388
2391
  const borrowCapacityValue = depositedValue.multipliedBy(
@@ -2403,10 +2406,10 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2403
2406
  if (depositedAmount.isGreaterThan(0)) {
2404
2407
  totalDepositedPools++;
2405
2408
  }
2406
- collaterals[collateralCoinName] = {
2407
- coinName: collateralCoinName,
2408
- coinType: collateral.type.name,
2409
- symbol: query.utils.parseSymbol(collateralCoinName),
2409
+ collaterals[assetCoinName] = {
2410
+ coinName: assetCoinName,
2411
+ coinType: query.utils.parseCoinType(assetCoinName),
2412
+ symbol: query.utils.parseSymbol(assetCoinName),
2410
2413
  coinDecimal,
2411
2414
  coinPrice,
2412
2415
  depositedAmount: depositedAmount.toNumber(),
@@ -2421,16 +2424,19 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2421
2424
  };
2422
2425
  }
2423
2426
  }
2424
- for (const debt of obligationQuery.debts) {
2425
- const poolCoinName = query.utils.parseCoinNameFromType(
2426
- debt.type.name
2427
- );
2428
- const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
2429
- const marketPool = market.pools[poolCoinName];
2430
- const coinPrice = coinPrices?.[poolCoinName];
2427
+ for (const assetCoinName of assetCoinNames) {
2428
+ const debt = obligationQuery.debts.find((debt2) => {
2429
+ const poolCoinName = query.utils.parseCoinNameFromType(
2430
+ debt2.type.name
2431
+ );
2432
+ return assetCoinName === poolCoinName;
2433
+ });
2434
+ const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
2435
+ const marketPool = market.pools[assetCoinName];
2436
+ const coinPrice = coinPrices?.[assetCoinName];
2431
2437
  if (marketPool && coinPrice) {
2432
- const increasedRate = marketPool.borrowIndex / Number(debt.borrowIndex) - 1;
2433
- const borrowedAmount = (0, import_bignumber3.default)(debt.amount);
2438
+ const increasedRate = debt?.borrowIndex ? marketPool.borrowIndex / Number(debt.borrowIndex) - 1 : 0;
2439
+ const borrowedAmount = (0, import_bignumber3.default)(debt?.amount ?? 0);
2434
2440
  const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
2435
2441
  const availableRepayAmount = borrowedAmount.multipliedBy(
2436
2442
  increasedRate + 1
@@ -2449,17 +2455,17 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2449
2455
  if (borrowedAmount.isGreaterThan(0)) {
2450
2456
  totalBorrowedPools++;
2451
2457
  }
2452
- debts[poolCoinName] = {
2453
- coinName: poolCoinName,
2454
- coinType: debt.type.name,
2455
- symbol: query.utils.parseSymbol(poolCoinName),
2458
+ debts[assetCoinName] = {
2459
+ coinName: assetCoinName,
2460
+ coinType: query.utils.parseCoinType(assetCoinName),
2461
+ symbol: query.utils.parseSymbol(assetCoinName),
2456
2462
  coinDecimal,
2457
2463
  coinPrice,
2458
2464
  borrowedAmount: borrowedAmount.toNumber(),
2459
2465
  borrowedCoin: borrowedCoin.toNumber(),
2460
2466
  borrowedValue: borrowedValue.toNumber(),
2461
2467
  borrowedValueWithWeight: borrowedValueWithWeight.toNumber(),
2462
- borrowIndex: Number(debt.borrowIndex),
2468
+ borrowIndex: Number(debt?.borrowIndex ?? 0),
2463
2469
  availableBorrowAmount: 0,
2464
2470
  availableBorrowCoin: 0,
2465
2471
  availableRepayAmount: availableRepayAmount.toNumber(),
@@ -2910,10 +2916,11 @@ var ScallopQuery = class {
2910
2916
  * borrowing and obligation information for specific pool.
2911
2917
  *
2912
2918
  * @param obligationId - The obligation id.
2919
+ * @param ownerAddress - The owner address.
2913
2920
  * @return Borrowing and collateral information.
2914
2921
  */
2915
- async getObligationAccount(obligationId) {
2916
- return await getObligationAccount(this, obligationId);
2922
+ async getObligationAccount(obligationId, ownerAddress) {
2923
+ return await getObligationAccount(this, obligationId, ownerAddress);
2917
2924
  }
2918
2925
  /**
2919
2926
  * Get total value locked.