@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 +36 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -29
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +2 -1
- package/package.json +1 -1
- package/src/models/scallopQuery.ts +6 -2
- package/src/queries/portfolioQuery.ts +38 -29
|
@@ -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
|
@@ -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(
|
|
450
|
-
|
|
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
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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
|
|
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[
|
|
361
|
-
coinName:
|
|
362
|
-
coinType:
|
|
363
|
-
symbol: query.utils.parseSymbol(
|
|
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
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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
|
-
|
|
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[
|
|
413
|
-
coinName:
|
|
414
|
-
coinType:
|
|
415
|
-
symbol: query.utils.parseSymbol(
|
|
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
|
|
431
|
+
borrowIndex: Number(debt?.borrowIndex ?? 0),
|
|
423
432
|
availableBorrowAmount: 0,
|
|
424
433
|
availableBorrowCoin: 0,
|
|
425
434
|
availableRepayAmount: availableRepayAmount.toNumber(),
|