interbtc-api

@interlay/interbtc-api / Exports / DefaultLoansAPI

Class: DefaultLoansAPI

Implements

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new DefaultLoansAPI(api, wrappedCurrency, oracleAPI): DefaultLoansAPI

Parameters

Name Type
api ApiPromise
wrappedCurrency Currency
oracleAPI OracleAPI

Returns

DefaultLoansAPI

Defined in

src/parachain/loans.ts:241

Properties

api

Private api: ApiPromise

Defined in

src/parachain/loans.ts:241


oracleAPI

Private oracleAPI: OracleAPI

Defined in

src/parachain/loans.ts:241


wrappedCurrency

Private wrappedCurrency: Currency

Defined in

src/parachain/loans.ts:241

Methods

_calculateAccumulatedDebt

_calculateAccumulatedDebt(borrowedAmount, snapshotBorrowIndex, currentBorrowIndex): Big

Parameters

Name Type
borrowedAmount Big
snapshotBorrowIndex Big
currentBorrowIndex Big

Returns

Big

Defined in

src/parachain/loans.ts:402


_calculateLiquidityAndCapacityAmounts

_calculateLiquidityAndCapacityAmounts(underlyingCurrency, lendTokenTotalIssuance, totalBorrows, exchangeRate): [MonetaryAmount<CurrencyExt>, MonetaryAmount<CurrencyExt>]

Parameters

Name Type
underlyingCurrency CurrencyExt
lendTokenTotalIssuance Big
totalBorrows Big
exchangeRate Big

Returns

[MonetaryAmount<CurrencyExt>, MonetaryAmount<CurrencyExt>]

Defined in

src/parachain/loans.ts:583


_checkLoanAssetDataAvailability

_checkLoanAssetDataAvailability(positions, loanAssets): void

Parameters

Name Type
positions LoanPosition[]
loanAssets TickerToData<LoanAsset>

Returns

void

Defined in

src/parachain/loans.ts:459


_checkMarketState

_checkMarketState(currency, action): Promise<void>

Parameters

Name Type
currency CurrencyExt
action string

Returns

Promise<void>

Defined in

src/parachain/loans.ts:843


_getAccruedBorrowReward

_getAccruedBorrowReward(accountId, underlyingCurrencyId, rewardCurrency, currentBlock): Promise<MonetaryAmount<CurrencyExt>>

Parameters

Name Type
accountId AccountId
underlyingCurrencyId CurrencyId
rewardCurrency CurrencyExt
currentBlock number

Returns

Promise<MonetaryAmount<CurrencyExt>>

Defined in

src/parachain/loans.ts:784


_getAccruedSupplyReward

_getAccruedSupplyReward(accountId, underlyingCurrencyId, lendTokenId, rewardCurrency, currentBlock): Promise<MonetaryAmount<CurrencyExt>>

Parameters

Name Type
accountId AccountId
underlyingCurrencyId CurrencyId
lendTokenId CurrencyId
rewardCurrency CurrencyExt
currentBlock number

Returns

Promise<MonetaryAmount<CurrencyExt>>

Defined in

src/parachain/loans.ts:740


_getBorrowApy

_getBorrowApy(underlyingCurrencyId): Promise<Big>

Parameters

Name Type
underlyingCurrencyId InterbtcPrimitivesCurrencyId

Returns

Promise<Big>

Defined in

src/parachain/loans.ts:553


_getBorrowPosition

_getBorrowPosition(accountId, underlyingCurrency): Promise<null | BorrowPosition>

Parameters

Name Type
accountId AccountId
underlyingCurrency CurrencyExt

Returns

Promise<null | BorrowPosition>

Defined in

src/parachain/loans.ts:412


_getLatestBorrowIndex

_getLatestBorrowIndex(underlyingCurrencyId, currentBlockNumber): Promise<Big>

Parameters

Name Type
underlyingCurrencyId CurrencyId
currentBlockNumber number

Returns

Promise<Big>

Defined in

src/parachain/loans.ts:761


_getLatestSupplyIndex

_getLatestSupplyIndex(underlyingCurrencyId, lendTokenId, currentBlockNumber): Promise<Big>

Parameters

Name Type
underlyingCurrencyId CurrencyId
lendTokenId CurrencyId
currentBlockNumber number

Returns

Promise<Big>

Defined in

src/parachain/loans.ts:713


_getLendAndBorrowYearlyRewardAmount

_getLendAndBorrowYearlyRewardAmount(underlyingCurrencyId, totalLiquidity, totalBorrows): Promise<[Big, Big]>

Get the lend and borrow annual rewards for 1 UNIT of a given underlying currency id.

Parameters

Name Type Description
underlyingCurrencyId InterbtcPrimitivesCurrencyId currency id to get reward amounts for.
totalLiquidity Big -
totalBorrows Big -

Returns

Promise<[Big, Big]>

Annualized lend and borrow rewards for 1 unit of the given underlying currency.

Defined in

src/parachain/loans.ts:605


_getLendApy

_getLendApy(underlyingCurrencyId): Promise<Big>

Parameters

Name Type
underlyingCurrencyId InterbtcPrimitivesCurrencyId

Returns

Promise<Big>

Defined in

src/parachain/loans.ts:546


_getLendPosition

_getLendPosition(accountId, underlyingCurrency, lendTokenId): Promise<null | CollateralPosition>

Parameters

Name Type
accountId AccountId
underlyingCurrency CurrencyExt
lendTokenId InterbtcPrimitivesCurrencyId

Returns

Promise<null | CollateralPosition>

Defined in

src/parachain/loans.ts:373


_getLoanAsset

_getLoanAsset(underlyingCurrencyId, marketData): Promise<[CurrencyExt, LoanAsset]>

Parameters

Name Type
underlyingCurrencyId InterbtcPrimitivesCurrencyId
marketData LoansMarket

Returns

Promise<[CurrencyExt, LoanAsset]>

Defined in

src/parachain/loans.ts:647


_getPositionsOfAccount

_getPositionsOfAccount<Position>(accountId, getSinglePosition): Promise<Position[]>

Type parameters

Name Type
Position extends LoanPosition

Parameters

Name Type
accountId AccountId
getSinglePosition (accountId: AccountId, underlyingCurrency: CurrencyExt, lendTokenId: InterbtcPrimitivesCurrencyId) => Promise<null | Position>

Returns

Promise<Position[]>

Defined in

src/parachain/loans.ts:433


_getRewardCurrency

_getRewardCurrency(): Promise<CurrencyExt>

Returns

Promise<CurrencyExt>

Defined in

src/parachain/loans.ts:632


_getSubsidyReward

_getSubsidyReward(amount, rewardCurrency): null | MonetaryAmount<CurrencyExt>

Parameters

Name Type
amount Big
rewardCurrency CurrencyExt

Returns

null | MonetaryAmount<CurrencyExt>

Defined in

src/parachain/loans.ts:638


_getTotalLiquidityCapacityAndBorrows

_getTotalLiquidityCapacityAndBorrows(underlyingCurrency, underlyingCurrencyId): Promise<[MonetaryAmount<CurrencyExt>, MonetaryAmount<CurrencyExt>, MonetaryAmount<CurrencyExt>]>

Parameters

Name Type
underlyingCurrency CurrencyExt
underlyingCurrencyId InterbtcPrimitivesCurrencyId

Returns

Promise<[MonetaryAmount<CurrencyExt>, MonetaryAmount<CurrencyExt>, MonetaryAmount<CurrencyExt>]>

Defined in

src/parachain/loans.ts:560


borrow

borrow(underlyingCurrency, amount): Promise<ExtrinsicData>

Borrow currency from the protocol.

Parameters

Name Type Description
underlyingCurrency CurrencyExt Currency to borrow.
amount MonetaryAmount<CurrencyExt> Amount of currency to borrow.

Returns

Promise<ExtrinsicData>

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Throws

If there is no active market for underlyingCurrency.

Throws

If there is not enough collateral provided by account for amount of underlyingCurrency.

Throws

If amount is higher than available amount of underlyingCurrency in the protocol.

Implementation of

LoansAPI.borrow

Defined in

src/parachain/loans.ts:906


claimAllSubsidyRewards

claimAllSubsidyRewards(): ExtrinsicData

Claim subsidy rewards for all markets available for account.

Returns

ExtrinsicData

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Implementation of

LoansAPI.claimAllSubsidyRewards

Defined in

src/parachain/loans.ts:900


convertLendTokenToUnderlyingCurrency

convertLendTokenToUnderlyingCurrency(amount, underlyingCurrencyId): Promise<Big>

Parameters

Name Type
amount Big
underlyingCurrencyId InterbtcPrimitivesCurrencyId

Returns

Promise<Big>

Defined in

src/parachain/loans.ts:275


disableAsCollateral

disableAsCollateral(underlyingCurrency): Promise<ExtrinsicData>

Enable lend position of account as collateral for borrowing.

Parameters

Name Type Description
underlyingCurrency CurrencyExt Currency to enable as collateral.

Returns

Promise<ExtrinsicData>

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Throws

If there is no existing lend position for currency.

Throws

If disabling lend position of currency would bring account under collateral threshold.

Implementation of

LoansAPI.disableAsCollateral

Defined in

src/parachain/loans.ts:891


enableAsCollateral

enableAsCollateral(underlyingCurrency): Promise<ExtrinsicData>

Enable lend position of account as collateral for borrowing.

Parameters

Name Type Description
underlyingCurrency CurrencyExt Currency to enable as collateral.

Returns

Promise<ExtrinsicData>

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Throws

If there is no existing lend position for currency.

Implementation of

LoansAPI.enableAsCollateral

Defined in

src/parachain/loans.ts:882


getAccruedRewardsOfAccount

getAccruedRewardsOfAccount(accountId): Promise<AccruedRewards>

Get accrued subsidy rewards amounts for the account.

Parameters

Name Type Description
accountId AccountId Account to get rewards for

Returns

Promise<AccruedRewards>

Total amount how much rewards the account can claim and rewards per market.

Implementation of

LoansAPI.getAccruedRewardsOfAccount

Defined in

src/parachain/loans.ts:803


getBorrowPositionsOfAccount

getBorrowPositionsOfAccount(accountId): Promise<BorrowPosition[]>

Get the borrow positions for given account.

Parameters

Name Type Description
accountId AccountId the account Id for which to get borrow positions

Returns

Promise<BorrowPosition[]>

Array of borrow positions of account.

Implementation of

LoansAPI.getBorrowPositionsOfAccount

Defined in

src/parachain/loans.ts:455


getBorrowerAccountIds

getBorrowerAccountIds(): Promise<AccountId[]>

Returns

Promise<AccountId[]>

An array of AccountIds which historically borrowed from the lending protocol. This includes accounts with zero outstanding debt.

Implementation of

LoansAPI.getBorrowerAccountIds

Defined in

src/parachain/loans.ts:337


getLendPositionAmounts

getLendPositionAmounts(accountId, lendTokenId, underlyingCurrencyId): Promise<[Big, Big]>

Get lend position amounts in both underlying and lend currencies.

Parameters

Name Type Description
accountId AccountId AccountId to get position information about
lendTokenId InterbtcPrimitivesCurrencyId LendToken CurrencyId of the position
underlyingCurrencyId InterbtcPrimitivesCurrencyId Underlying CurrencyId of the position

Returns

Promise<[Big, Big]>

Lend position amounts in underlying currency and lend token

Defined in

src/parachain/loans.ts:293


getLendPositionsOfAccount

getLendPositionsOfAccount(accountId): Promise<CollateralPosition[]>

Get the lend positions for given account.

Parameters

Name Type Description
accountId AccountId the account Id for which to get supply positions

Returns

Promise<CollateralPosition[]>

Array of lend positions of account.

Implementation of

LoansAPI.getLendPositionsOfAccount

Defined in

src/parachain/loans.ts:451


getLendTokenExchangeRates

getLendTokenExchangeRates(): Promise<TickerToData<Big>>

Returns

Promise<TickerToData<Big>>

Exchange rates for underlying currency -> lend token. Representing amount of lend token equal to 1 of underlying currency.

Implementation of

LoansAPI.getLendTokenExchangeRates

Defined in

src/parachain/loans.ts:322


getLendTokenIdFromUnderlyingCurrency

getLendTokenIdFromUnderlyingCurrency(currency): Promise<InterbtcPrimitivesCurrencyId>

Parameters

Name Type
currency CurrencyExt

Returns

Promise<InterbtcPrimitivesCurrencyId>

Defined in

src/parachain/loans.ts:269


getLendTokens

getLendTokens(): Promise<LendToken[]>

Get all lend token currencies.

Returns

Promise<LendToken[]>

Array of all LendToken currencies.

Implementation of

LoansAPI.getLendTokens

Defined in

src/parachain/loans.ts:315


getLendingStats

getLendingStats(lendPositions, borrowPositions, loanAssets): LendingStats

Get collateralization information about account’s loans.

Parameters

Name Type Description
lendPositions CollateralPosition[] Lend positions of account.
borrowPositions BorrowPosition[] Borrow positions of account.
loanAssets TickerToData<LoanAsset> All loan assets data in TickerToData structure.

Returns

LendingStats

Collateral information about account based on passed positions.

Throws

When loanAssets does not contain all of the loan positions currencies.

Implementation of

LoansAPI.getLendingStats

Defined in

src/parachain/loans.ts:467


getLiquidationThresholdLiquidity

getLiquidationThresholdLiquidity(accountId): Promise<AccountLiquidity>

Parameters

Name Type Description
accountId AccountId The account whose liquidity to query from the chain

Returns

Promise<AccountLiquidity>

An AccountLiquidity object, which is valid even for accounts that didn’t use the loans pallet at all

Implementation of

LoansAPI.getLiquidationThresholdLiquidity

Defined in

src/parachain/loans.ts:365


getLoanAssets

getLoanAssets(): Promise<TickerToData<LoanAsset>>

Get all loan assets.

Returns

Promise<TickerToData<LoanAsset>>

Array of all assets that can be lent and borrowed.

Remarks

Method could be refactored to compute APR in lib if we can get underlyingCurrency/rewardCurrency exchange rate, but is it safe to assume that exchange rate for btc/underlyingCurrency will be always fed to the oracle and available?

Implementation of

LoansAPI.getLoanAssets

Defined in

src/parachain/loans.ts:697


getLoansMarkets

getLoansMarkets(): Promise<[CurrencyExt, LoansMarket][]>

Returns

Promise<[CurrencyExt, LoansMarket][]>

An array of tuples denoting the underlying currency of a market, and the configuration of that market

Implementation of

LoansAPI.getLoansMarkets

Defined in

src/parachain/loans.ts:243


getUndercollateralizedBorrowers

getUndercollateralizedBorrowers(): Promise<UndercollateralizedPosition[]>

Returns

Promise<UndercollateralizedPosition[]>

An array of UndercollateralizedPositions, with all details needed to liquidate them (accountId, shortfall - expressed in the wrapped currency, open borrow positions, collateral deposits).

Implementation of

LoansAPI.getUndercollateralizedBorrowers

Defined in

src/parachain/loans.ts:346


lend

lend(underlyingCurrency, amount): Promise<ExtrinsicData>

Lend currency to protocol for borrowing.

Parameters

Name Type Description
underlyingCurrency CurrencyExt Currency to lend.
amount MonetaryAmount<CurrencyExt> Amount of currency to lend.

Returns

Promise<ExtrinsicData>

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Throws

If there is not active market for underlyingCurrency.

Throws

If amount is exceeding available balance of account.

Implementation of

LoansAPI.lend

Defined in

src/parachain/loans.ts:855


liquidateBorrowPosition

liquidateBorrowPosition(borrower, liquidationCurrency, repayAmount, collateralCurrency): ExtrinsicData

Liquidates borrow position for exchange of collateral.

Parameters

Name Type Description
borrower AccountId AccountId of borrower whose position will be liquidated.
liquidationCurrency CurrencyExt Currency of position that will be liquidated.
repayAmount MonetaryAmount<CurrencyExt> Amount to be repaid.
collateralCurrency CurrencyExt Collateral currency which will be claimed by liquidator.

Returns

ExtrinsicData

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Implementation of

LoansAPI.liquidateBorrowPosition

Defined in

src/parachain/loans.ts:933


repay

repay(underlyingCurrency, amount): Promise<ExtrinsicData>

Repay borrowed loan.

Parameters

Name Type Description
underlyingCurrency CurrencyExt Currency to repay.
amount MonetaryAmount<CurrencyExt> Amount of currency to repay.

Returns

Promise<ExtrinsicData>

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Throws

If there is no active market for underlyingCurrency.

Throws

If amount is higher than available balance of account.

Throws

If amount is higher than outstanding loan.

Implementation of

LoansAPI.repay

Defined in

src/parachain/loans.ts:915


repayAll

repayAll(underlyingCurrency): Promise<ExtrinsicData>

Same as repay, but repays full loan.

Parameters

Name Type Description
underlyingCurrency CurrencyExt Currency to repay.

Returns

Promise<ExtrinsicData>

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Implementation of

LoansAPI.repayAll

Defined in

src/parachain/loans.ts:924


withdraw

withdraw(underlyingCurrency, amount): Promise<ExtrinsicData>

Withdraw previously lent currency from protocol.

Parameters

Name Type Description
underlyingCurrency CurrencyExt Currency to witdhraw.
amount MonetaryAmount<CurrencyExt> Amount of currency to withdraw.

Returns

Promise<ExtrinsicData>

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Throws

If there is not active market for underlyingCurrency.

Throws

If amount is exceeding lent amount of account.

Throws

If underlyingCurrency is used as collateral and withdrawal of amount would bring account under collateral threshold.

Throws

If there is not enough of underlying currency currently available in the protocol.

Implementation of

LoansAPI.withdraw

Defined in

src/parachain/loans.ts:864


withdrawAll

withdrawAll(underlyingCurrency): Promise<ExtrinsicData>

Same as withdraw, but exits full position.

Parameters

Name Type Description
underlyingCurrency CurrencyExt Currency to fully withdraw.

Returns

Promise<ExtrinsicData>

A submittable extrinsic and an event that is emitted when extrinsic is submitted.

Implementation of

LoansAPI.withdrawAll

Defined in

src/parachain/loans.ts:873


getLendTokenFromUnderlyingCurrency

getLendTokenFromUnderlyingCurrency(currency, lendTokenId): LendToken

Parameters

Name Type
currency CurrencyExt
lendTokenId InterbtcPrimitivesCurrencyId

Returns

LendToken

Defined in

src/parachain/loans.ts:255