Skip to content

Commit

Permalink
Merge pull request #656 from peterslany/peter/loans-feat-add-vault-co…
Browse files Browse the repository at this point in the history
…llateral-to-lend-position

feat(loans): add vault collateral amount field to lend positions
  • Loading branch information
peterslany committed Jul 14, 2023
2 parents 4d699de + 5dc2d37 commit f32bdd2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 13 additions & 2 deletions src/parachain/loans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<LendToken[]> {
Expand Down Expand Up @@ -369,7 +375,7 @@ export class DefaultLoansAPI implements LoansAPI {
underlyingCurrency: CurrencyExt,
lendTokenId: InterbtcPrimitivesCurrencyId
): Promise<CollateralPosition | null> {
const [underlyingCurrencyAmount] = await this.getLendPositionAmounts(
const [underlyingCurrencyAmount, reservedAmountInUnderlyingCurrency] = await this.getLendPositionAmounts(
accountId,
lendTokenId,
newCurrencyId(this.api, underlyingCurrency)
Expand All @@ -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),
};
}

Expand Down
1 change: 1 addition & 0 deletions src/types/loans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface LoanPosition {

interface CollateralPosition extends LoanPosition {
isCollateral: boolean;
vaultCollateralAmount: MonetaryAmount<CurrencyExt>;
}

interface BorrowPosition extends LoanPosition {
Expand Down
1 change: 1 addition & 0 deletions test/unit/parachain/loans.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ describe("DefaultLoansAPI", () => {
): CollateralPosition => ({
amount,
isCollateral,
vaultCollateralAmount: newMonetaryAmount(0, amount.currency),
});
const mockBorrowPosition = (amount: MonetaryAmount<CurrencyExt>): BorrowPosition => ({
amount,
Expand Down

0 comments on commit f32bdd2

Please sign in to comment.