From 7415191cd6d2c62ceb832051a58d548730ce737f Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 13 Jul 2023 17:23:04 +0200 Subject: [PATCH 1/2] feat(loans): add vault collateral amount field to lend positions --- src/parachain/loans.ts | 15 +++++++++++++-- src/types/loans.ts | 1 + test/unit/parachain/loans.test.ts | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) 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, From 5dc2d372c318f57c61cb947826e9e64378950d15 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 13 Jul 2023 17:25:37 +0200 Subject: [PATCH 2/2] chore: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",