@interlay/interbtc-api / Exports / DefaultLoansAPI
• new DefaultLoansAPI(api
, wrappedCurrency
, oracleAPI
): DefaultLoansAPI
Name | Type |
---|---|
api |
ApiPromise |
wrappedCurrency |
Currency |
oracleAPI |
OracleAPI |
• Private
api: ApiPromise
• Private
oracleAPI: OracleAPI
• Private
wrappedCurrency: Currency
▸ _calculateAccumulatedDebt(borrowedAmount
, snapshotBorrowIndex
, currentBorrowIndex
): Big
Name | Type |
---|---|
borrowedAmount |
Big |
snapshotBorrowIndex |
Big |
currentBorrowIndex |
Big |
Big
▸ _calculateLiquidityAndCapacityAmounts(underlyingCurrency
, lendTokenTotalIssuance
, totalBorrows
, exchangeRate
): [MonetaryAmount
<CurrencyExt
>, MonetaryAmount
<CurrencyExt
>]
Name | Type |
---|---|
underlyingCurrency |
CurrencyExt |
lendTokenTotalIssuance |
Big |
totalBorrows |
Big |
exchangeRate |
Big |
[MonetaryAmount
<CurrencyExt
>, MonetaryAmount
<CurrencyExt
>]
▸ _checkLoanAssetDataAvailability(positions
, loanAssets
): void
Name | Type |
---|---|
positions |
LoanPosition [] |
loanAssets |
TickerToData <LoanAsset > |
void
▸ _checkMarketState(currency
, action
): Promise
<void
>
Name | Type |
---|---|
currency |
CurrencyExt |
action |
string |
Promise
<void
>
▸ _getAccruedBorrowReward(accountId
, underlyingCurrencyId
, rewardCurrency
, currentBlock
): Promise
<MonetaryAmount
<CurrencyExt
>>
Name | Type |
---|---|
accountId |
AccountId |
underlyingCurrencyId |
CurrencyId |
rewardCurrency |
CurrencyExt |
currentBlock |
number |
Promise
<MonetaryAmount
<CurrencyExt
>>
▸ _getAccruedSupplyReward(accountId
, underlyingCurrencyId
, lendTokenId
, rewardCurrency
, currentBlock
): Promise
<MonetaryAmount
<CurrencyExt
>>
Name | Type |
---|---|
accountId |
AccountId |
underlyingCurrencyId |
CurrencyId |
lendTokenId |
CurrencyId |
rewardCurrency |
CurrencyExt |
currentBlock |
number |
Promise
<MonetaryAmount
<CurrencyExt
>>
▸ _getBorrowApy(underlyingCurrencyId
): Promise
<Big
>
Name | Type |
---|---|
underlyingCurrencyId |
InterbtcPrimitivesCurrencyId |
Promise
<Big
>
▸ _getBorrowPosition(accountId
, underlyingCurrency
): Promise
<null
| BorrowPosition
>
Name | Type |
---|---|
accountId |
AccountId |
underlyingCurrency |
CurrencyExt |
Promise
<null
| BorrowPosition
>
▸ _getLatestBorrowIndex(underlyingCurrencyId
, currentBlockNumber
): Promise
<Big
>
Name | Type |
---|---|
underlyingCurrencyId |
CurrencyId |
currentBlockNumber |
number |
Promise
<Big
>
▸ _getLatestSupplyIndex(underlyingCurrencyId
, lendTokenId
, currentBlockNumber
): Promise
<Big
>
Name | Type |
---|---|
underlyingCurrencyId |
CurrencyId |
lendTokenId |
CurrencyId |
currentBlockNumber |
number |
Promise
<Big
>
▸ _getLendAndBorrowYearlyRewardAmount(underlyingCurrencyId
, totalLiquidity
, totalBorrows
): Promise
<[Big
, Big
]>
Get the lend and borrow annual rewards for 1 UNIT of a given underlying currency id.
Name | Type | Description |
---|---|---|
underlyingCurrencyId |
InterbtcPrimitivesCurrencyId |
currency id to get reward amounts for. |
totalLiquidity |
Big |
- |
totalBorrows |
Big |
- |
Promise
<[Big
, Big
]>
Annualized lend and borrow rewards for 1 unit of the given underlying currency.
▸ _getLendApy(underlyingCurrencyId
): Promise
<Big
>
Name | Type |
---|---|
underlyingCurrencyId |
InterbtcPrimitivesCurrencyId |
Promise
<Big
>
▸ _getLendPosition(accountId
, underlyingCurrency
, lendTokenId
): Promise
<null
| CollateralPosition
>
Name | Type |
---|---|
accountId |
AccountId |
underlyingCurrency |
CurrencyExt |
lendTokenId |
InterbtcPrimitivesCurrencyId |
Promise
<null
| CollateralPosition
>
▸ _getLoanAsset(underlyingCurrencyId
, marketData
): Promise
<[CurrencyExt
, LoanAsset
]>
Name | Type |
---|---|
underlyingCurrencyId |
InterbtcPrimitivesCurrencyId |
marketData |
LoansMarket |
Promise
<[CurrencyExt
, LoanAsset
]>
▸ _getPositionsOfAccount<Position
>(accountId
, getSinglePosition
): Promise
<Position
[]>
Name | Type |
---|---|
Position |
extends LoanPosition |
Name | Type |
---|---|
accountId |
AccountId |
getSinglePosition |
(accountId : AccountId , underlyingCurrency : CurrencyExt , lendTokenId : InterbtcPrimitivesCurrencyId ) => Promise <null | Position > |
Promise
<Position
[]>
▸ _getRewardCurrency(): Promise
<CurrencyExt
>
Promise
<CurrencyExt
>
▸ _getSubsidyReward(amount
, rewardCurrency
): null
| MonetaryAmount
<CurrencyExt
>
Name | Type |
---|---|
amount |
Big |
rewardCurrency |
CurrencyExt |
null
| MonetaryAmount
<CurrencyExt
>
▸ _getTotalLiquidityCapacityAndBorrows(underlyingCurrency
, underlyingCurrencyId
): Promise
<[MonetaryAmount
<CurrencyExt
>, MonetaryAmount
<CurrencyExt
>, MonetaryAmount
<CurrencyExt
>]>
Name | Type |
---|---|
underlyingCurrency |
CurrencyExt |
underlyingCurrencyId |
InterbtcPrimitivesCurrencyId |
Promise
<[MonetaryAmount
<CurrencyExt
>, MonetaryAmount
<CurrencyExt
>, MonetaryAmount
<CurrencyExt
>]>
▸ borrow(underlyingCurrency
, amount
): Promise
<ExtrinsicData
>
Borrow currency from the protocol.
Name | Type | Description |
---|---|---|
underlyingCurrency |
CurrencyExt |
Currency to borrow. |
amount |
MonetaryAmount <CurrencyExt > |
Amount of currency to borrow. |
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.
▸ claimAllSubsidyRewards(): ExtrinsicData
Claim subsidy rewards for all markets available for account.
A submittable extrinsic and an event that is emitted when extrinsic is submitted.
LoansAPI.claimAllSubsidyRewards
▸ convertLendTokenToUnderlyingCurrency(amount
, underlyingCurrencyId
): Promise
<Big
>
Name | Type |
---|---|
amount |
Big |
underlyingCurrencyId |
InterbtcPrimitivesCurrencyId |
Promise
<Big
>
▸ disableAsCollateral(underlyingCurrency
): Promise
<ExtrinsicData
>
Enable lend position of account as collateral for borrowing.
Name | Type | Description |
---|---|---|
underlyingCurrency |
CurrencyExt |
Currency to enable as collateral. |
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.
▸ enableAsCollateral(underlyingCurrency
): Promise
<ExtrinsicData
>
Enable lend position of account as collateral for borrowing.
Name | Type | Description |
---|---|---|
underlyingCurrency |
CurrencyExt |
Currency to enable as collateral. |
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
.
▸ getAccruedRewardsOfAccount(accountId
): Promise
<AccruedRewards
>
Get accrued subsidy rewards amounts for the account.
Name | Type | Description |
---|---|---|
accountId |
AccountId |
Account to get rewards for |
Promise
<AccruedRewards
>
Total amount how much rewards the account can claim and rewards per market.
LoansAPI.getAccruedRewardsOfAccount
▸ getBorrowPositionsOfAccount(accountId
): Promise
<BorrowPosition
[]>
Get the borrow positions for given account.
Name | Type | Description |
---|---|---|
accountId |
AccountId |
the account Id for which to get borrow positions |
Promise
<BorrowPosition
[]>
Array of borrow positions of account.
LoansAPI.getBorrowPositionsOfAccount
▸ getBorrowerAccountIds(): Promise
<AccountId
[]>
Promise
<AccountId
[]>
An array of AccountId
s which historically borrowed from the lending protocol.
This includes accounts with zero outstanding debt.
LoansAPI.getBorrowerAccountIds
▸ getLendPositionAmounts(accountId
, lendTokenId
, underlyingCurrencyId
): Promise
<[Big
, Big
]>
Get lend position amounts in both underlying and lend currencies.
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 |
Promise
<[Big
, Big
]>
Lend position amounts in underlying currency and lend token
▸ getLendPositionsOfAccount(accountId
): Promise
<CollateralPosition
[]>
Get the lend positions for given account.
Name | Type | Description |
---|---|---|
accountId |
AccountId |
the account Id for which to get supply positions |
Promise
<CollateralPosition
[]>
Array of lend positions of account.
LoansAPI.getLendPositionsOfAccount
▸ getLendTokenExchangeRates(): Promise
<TickerToData
<Big
>>
Promise
<TickerToData
<Big
>>
Exchange rates for underlying currency -> lend token. Representing amount of lend token equal to 1 of underlying currency.
LoansAPI.getLendTokenExchangeRates
▸ getLendTokenIdFromUnderlyingCurrency(currency
): Promise
<InterbtcPrimitivesCurrencyId
>
Name | Type |
---|---|
currency |
CurrencyExt |
Promise
<InterbtcPrimitivesCurrencyId
>
▸ getLendTokens(): Promise
<LendToken
[]>
Get all lend token currencies.
Promise
<LendToken
[]>
Array of all LendToken currencies.
▸ getLendingStats(lendPositions
, borrowPositions
, loanAssets
): LendingStats
Get collateralization information about account’s loans.
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. |
Collateral information about account based on passed positions.
Throws
When loanAssets
does not contain all of the loan positions currencies.
▸ getLiquidationThresholdLiquidity(accountId
): Promise
<AccountLiquidity
>
Name | Type | Description |
---|---|---|
accountId |
AccountId |
The account whose liquidity to query from the chain |
Promise
<AccountLiquidity
>
An AccountLiquidity
object, which is valid even for accounts that didn’t use the loans pallet at all
LoansAPI.getLiquidationThresholdLiquidity
▸ getLoanAssets(): Promise
<TickerToData
<LoanAsset
>>
Get all loan assets.
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?
▸ getLoansMarkets(): Promise
<[CurrencyExt
, LoansMarket
][]>
Promise
<[CurrencyExt
, LoansMarket
][]>
An array of tuples denoting the underlying currency of a market, and the configuration of that market
▸ getUndercollateralizedBorrowers(): Promise
<UndercollateralizedPosition
[]>
Promise
<UndercollateralizedPosition
[]>
An array of UndercollateralizedPosition
s, with all details needed to
liquidate them (accountId, shortfall - expressed in the wrapped currency, open borrow positions, collateral
deposits).
LoansAPI.getUndercollateralizedBorrowers
▸ lend(underlyingCurrency
, amount
): Promise
<ExtrinsicData
>
Lend currency to protocol for borrowing.
Name | Type | Description |
---|---|---|
underlyingCurrency |
CurrencyExt |
Currency to lend. |
amount |
MonetaryAmount <CurrencyExt > |
Amount of currency to lend. |
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.
▸ liquidateBorrowPosition(borrower
, liquidationCurrency
, repayAmount
, collateralCurrency
): ExtrinsicData
Liquidates borrow position for exchange of collateral.
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. |
A submittable extrinsic and an event that is emitted when extrinsic is submitted.
LoansAPI.liquidateBorrowPosition
▸ repay(underlyingCurrency
, amount
): Promise
<ExtrinsicData
>
Repay borrowed loan.
Name | Type | Description |
---|---|---|
underlyingCurrency |
CurrencyExt |
Currency to repay. |
amount |
MonetaryAmount <CurrencyExt > |
Amount of currency to repay. |
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.
▸ repayAll(underlyingCurrency
): Promise
<ExtrinsicData
>
Same as repay
, but repays full loan.
Name | Type | Description |
---|---|---|
underlyingCurrency |
CurrencyExt |
Currency to repay. |
Promise
<ExtrinsicData
>
A submittable extrinsic and an event that is emitted when extrinsic is submitted.
▸ withdraw(underlyingCurrency
, amount
): Promise
<ExtrinsicData
>
Withdraw previously lent currency from protocol.
Name | Type | Description |
---|---|---|
underlyingCurrency |
CurrencyExt |
Currency to witdhraw. |
amount |
MonetaryAmount <CurrencyExt > |
Amount of currency to withdraw. |
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.
▸ withdrawAll(underlyingCurrency
): Promise
<ExtrinsicData
>
Same as withdraw
, but exits full position.
Name | Type | Description |
---|---|---|
underlyingCurrency |
CurrencyExt |
Currency to fully withdraw. |
Promise
<ExtrinsicData
>
A submittable extrinsic and an event that is emitted when extrinsic is submitted.
▸ getLendTokenFromUnderlyingCurrency(currency
, lendTokenId
): LendToken
Name | Type |
---|---|
currency |
CurrencyExt |
lendTokenId |
InterbtcPrimitivesCurrencyId |