@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.
@@ -322,9 +322,10 @@ export declare class ScallopQuery {
322
322
  * borrowing and obligation information for specific pool.
323
323
  *
324
324
  * @param obligationId - The obligation id.
325
+ * @param ownerAddress - The owner address.
325
326
  * @return Borrowing and collateral information.
326
327
  */
327
- getObligationAccount(obligationId: string): Promise<import("../types").ObligationAccount>;
328
+ getObligationAccount(obligationId: string, ownerAddress?: string): Promise<import("../types").ObligationAccount>;
328
329
  /**
329
330
  * Get total value locked.
330
331
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "0.44.5",
3
+ "version": "0.44.6",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -444,10 +444,14 @@ export class ScallopQuery {
444
444
  * borrowing and obligation information for specific pool.
445
445
  *
446
446
  * @param obligationId - The obligation id.
447
+ * @param ownerAddress - The owner address.
447
448
  * @return Borrowing and collateral information.
448
449
  */
449
- public async getObligationAccount(obligationId: string) {
450
- return await getObligationAccount(this, obligationId);
450
+ public async getObligationAccount(
451
+ obligationId: string,
452
+ ownerAddress?: string
453
+ ) {
454
+ return await getObligationAccount(this, obligationId, ownerAddress);
451
455
  }
452
456
 
453
457
  /**
@@ -321,18 +321,22 @@ export const getObligationAccount = async (
321
321
  let totalBorrowedValue = BigNumber(0);
322
322
  let totalBorrowedValueWithWeight = BigNumber(0);
323
323
 
324
- for (const collateral of obligationQuery.collaterals) {
325
- const collateralCoinName =
326
- query.utils.parseCoinNameFromType<SupportCollateralCoins>(
327
- collateral.type.name
328
- );
329
- const coinDecimal = query.utils.getCoinDecimal(collateralCoinName);
330
- const marketCollateral = market.collaterals[collateralCoinName];
331
- const coinPrice = coinPrices?.[collateralCoinName];
332
- const coinAmount = coinAmounts?.[collateralCoinName] ?? 0;
324
+ for (const assetCoinName of assetCoinNames) {
325
+ const collateral = obligationQuery.collaterals.find((collateral) => {
326
+ const collateralCoinName =
327
+ query.utils.parseCoinNameFromType<SupportCollateralCoins>(
328
+ collateral.type.name
329
+ );
330
+ return assetCoinName === collateralCoinName;
331
+ });
332
+
333
+ const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
334
+ const marketCollateral = market.collaterals[assetCoinName];
335
+ const coinPrice = coinPrices?.[assetCoinName];
336
+ const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
333
337
 
334
338
  if (marketCollateral && coinPrice) {
335
- const depositedAmount = BigNumber(collateral.amount);
339
+ const depositedAmount = BigNumber(collateral?.amount ?? 0);
336
340
  const depositedCoin = depositedAmount.shiftedBy(-1 * coinDecimal);
337
341
  const depositedValue = depositedCoin.multipliedBy(coinPrice);
338
342
  const borrowCapacityValue = depositedValue.multipliedBy(
@@ -357,10 +361,10 @@ export const getObligationAccount = async (
357
361
  totalDepositedPools++;
358
362
  }
359
363
 
360
- collaterals[collateralCoinName] = {
361
- coinName: collateralCoinName,
362
- coinType: collateral.type.name,
363
- symbol: query.utils.parseSymbol(collateralCoinName),
364
+ collaterals[assetCoinName] = {
365
+ coinName: assetCoinName,
366
+ coinType: query.utils.parseCoinType(assetCoinName),
367
+ symbol: query.utils.parseSymbol(assetCoinName),
364
368
  coinDecimal: coinDecimal,
365
369
  coinPrice: coinPrice,
366
370
  depositedAmount: depositedAmount.toNumber(),
@@ -376,18 +380,23 @@ export const getObligationAccount = async (
376
380
  }
377
381
  }
378
382
 
379
- for (const debt of obligationQuery.debts) {
380
- const poolCoinName = query.utils.parseCoinNameFromType<SupportPoolCoins>(
381
- debt.type.name
382
- );
383
- const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
384
- const marketPool = market.pools[poolCoinName];
385
- const coinPrice = coinPrices?.[poolCoinName];
383
+ for (const assetCoinName of assetCoinNames) {
384
+ const debt = obligationQuery.debts.find((debt) => {
385
+ const poolCoinName = query.utils.parseCoinNameFromType<SupportPoolCoins>(
386
+ debt.type.name
387
+ );
388
+ return assetCoinName === poolCoinName;
389
+ });
390
+
391
+ const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
392
+ const marketPool = market.pools[assetCoinName];
393
+ const coinPrice = coinPrices?.[assetCoinName];
386
394
 
387
395
  if (marketPool && coinPrice) {
388
- const increasedRate =
389
- marketPool.borrowIndex / Number(debt.borrowIndex) - 1;
390
- const borrowedAmount = BigNumber(debt.amount);
396
+ const increasedRate = debt?.borrowIndex
397
+ ? marketPool.borrowIndex / Number(debt.borrowIndex) - 1
398
+ : 0;
399
+ const borrowedAmount = BigNumber(debt?.amount ?? 0);
391
400
  const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
392
401
  const availableRepayAmount = borrowedAmount.multipliedBy(
393
402
  increasedRate + 1
@@ -409,17 +418,17 @@ export const getObligationAccount = async (
409
418
  totalBorrowedPools++;
410
419
  }
411
420
 
412
- debts[poolCoinName] = {
413
- coinName: poolCoinName,
414
- coinType: debt.type.name,
415
- symbol: query.utils.parseSymbol(poolCoinName),
421
+ debts[assetCoinName] = {
422
+ coinName: assetCoinName,
423
+ coinType: query.utils.parseCoinType(assetCoinName),
424
+ symbol: query.utils.parseSymbol(assetCoinName),
416
425
  coinDecimal: coinDecimal,
417
426
  coinPrice: coinPrice,
418
427
  borrowedAmount: borrowedAmount.toNumber(),
419
428
  borrowedCoin: borrowedCoin.toNumber(),
420
429
  borrowedValue: borrowedValue.toNumber(),
421
430
  borrowedValueWithWeight: borrowedValueWithWeight.toNumber(),
422
- borrowIndex: Number(debt.borrowIndex),
431
+ borrowIndex: Number(debt?.borrowIndex ?? 0),
423
432
  availableBorrowAmount: 0,
424
433
  availableBorrowCoin: 0,
425
434
  availableRepayAmount: availableRepayAmount.toNumber(),