diff --git a/package.json b/package.json index 195f92657..d95bb6f24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@interlay/interbtc-api", - "version": "2.3.6", + "version": "2.3.7", "description": "JavaScript library to interact with interBTC", "main": "build/src/index.js", "typings": "build/src/index.d.ts", diff --git a/src/parachain/loans.ts b/src/parachain/loans.ts index 12ce2effb..74464ebf3 100644 --- a/src/parachain/loans.ts +++ b/src/parachain/loans.ts @@ -303,7 +303,13 @@ export class DefaultLoansAPI implements LoansAPI { lendTokenBalanceInBig, underlyingCurrencyId ); - return [amountInUnderlying, lendTokenBalanceInBig]; + + const reservedAmountInUnderlying = await this.convertLendTokenToUnderlyingCurrency( + Big(lendTokenBalance.reserved.toString()), + underlyingCurrencyId + ); + + return [amountInUnderlying, reservedAmountInUnderlying]; } async getLendTokens(): Promise { @@ -369,7 +375,7 @@ export class DefaultLoansAPI implements LoansAPI { underlyingCurrency: CurrencyExt, lendTokenId: InterbtcPrimitivesCurrencyId ): Promise { - const [underlyingCurrencyAmount] = await this.getLendPositionAmounts( + const [underlyingCurrencyAmount, reservedAmountInUnderlyingCurrency] = await this.getLendPositionAmounts( accountId, lendTokenId, newCurrencyId(this.api, underlyingCurrency) @@ -382,9 +388,14 @@ export class DefaultLoansAPI implements LoansAPI { const isCollateral = !accountDeposits.isZero(); + // MEMO: If position is not used as loan collateral, but has reserved amount it means + // this account uses the qToken as vault collateral. + const amountLockedAsVaultCollateral = isCollateral ? Big(0) : reservedAmountInUnderlyingCurrency; + return { amount: newMonetaryAmount(underlyingCurrencyAmount, underlyingCurrency), isCollateral, + vaultCollateralAmount: newMonetaryAmount(amountLockedAsVaultCollateral, underlyingCurrency), }; } diff --git a/src/types/loans.ts b/src/types/loans.ts index 015d62b0f..efcfd4de8 100644 --- a/src/types/loans.ts +++ b/src/types/loans.ts @@ -9,6 +9,7 @@ interface LoanPosition { interface CollateralPosition extends LoanPosition { isCollateral: boolean; + vaultCollateralAmount: MonetaryAmount; } interface BorrowPosition extends LoanPosition { diff --git a/test/unit/parachain/loans.test.ts b/test/unit/parachain/loans.test.ts index 09b583ab8..06bb2fe68 100644 --- a/test/unit/parachain/loans.test.ts +++ b/test/unit/parachain/loans.test.ts @@ -140,6 +140,7 @@ describe("DefaultLoansAPI", () => { ): CollateralPosition => ({ amount, isCollateral, + vaultCollateralAmount: newMonetaryAmount(0, amount.currency), }); const mockBorrowPosition = (amount: MonetaryAmount): BorrowPosition => ({ amount,