Supply and Borrow

Overview

Suppliers can deposit their assets to Parallel Finance. For providing liquidity, in return, they will receive some of the borrower's interests.
Suppliers can also choose to collateralize their assets for borrowing other currencies. This is useful when the price of a certain currency fluctuates significantly and you want to borrow another currency for hedging. This also solves the liquidity of your cryptocurrency.
Currencies have different Collateral Rate which reflects the stability of their price. The more stable the currency's price, the higher the collateral rate. Stable coins USDT will have a higher Collateral Rate.
CollateralValue=CurrencyPriceβ‹…CollateralRateβ‹…CollateralAmountCollateralValue = CurrencyPrice \cdot CollateralRate \cdot CollateralAmount
After the deposit, users will be given some deposit certificates so that they can redeem the underlying assets. The number of issued deposited certificate is determined by the Exchange Rate
pTokenAmount=CurrencyAmountExchangeRatepTokenAmount = \frac {Currency}{Amount ExchangeRate}
Supply Interest Rate is proportional to Utilization Rate and Borrow Interest Rate
SupplyInterestRate=BorrowInterestRateβ‹…UtilizationRateβ‹…(1βˆ’ReserveFactor)SupplyInterestRate = BorrowInterestRate \cdot UtilizationRate \cdot (1 - ReserveFactor)
​

Supply and Borrow Process

View Data Storage

LastBlockTimestamp

The timestamp of the previous block or defaults to timestamp at genesis.
Code
View Method
1
pub type LastBlockTimestamp<T: Config> = StorageValue<_, Timestamp, ValueQuery>;
Copied!
1
LastBlockTimestamp::<T>::get()
2
Self::last_block_timestamp()
Copied!

TotalSupply

Total number of collateral tokens in circulation, CollateralType -> Balance
Code
View Method
1
pub type TotalSupply<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Balance, ValueQuery>;
Copied!
1
TotalSupply::T::get(currency_id: &CurrencyId)
2
Self::total_supply(currency_id: &CurrencyId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id
Tip: Follow the link to know more about 'CurrencyId'.

TotalBorrows

The total amount of outstanding borrows of the underlying in this market, CurrencyType -> Balance
Code
View Method
1
pub type TotalBorrows<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Balance, ValueQuery>;
Copied!
1
TotalBorrows::T::get(currency_id: &CurrencyId)
2
Self::total_borrows(currency_id: &CurrencyId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id

TotalReserves

Total amount of reserves of the underlying held in this market, CurrencyType -> Balance
Code
View Method
1
pub type TotalReserves<T: Config> =
2
StorageMap<_, Twox64Concat, CurrencyId, Balance, ValueQuery>;
Copied!
1
TotalReserves::T::get(currency_id: &CurrencyId)
2
Self::total_reserves(currency_id: &CurrencyId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id

AccountBorrows

Mapping of account addresses to outstanding borrow balances, CurrencyType -> Owner -> BorrowSnapshot
Code
View Method
1
pub type AccountBorrows<T: Config> = StorageDoubleMap<
2
_,
3
Twox64Concat,
4
CurrencyId,
5
Blake2_128Concat,
6
T::AccountId,
7
BorrowSnapshot,
8
ValueQuery,
9
>;
Copied!
1
AccountBorrows::<T>::get(currency_id: &CurrencyId, account_id: &T::AccountId)
2
Self::account_borrows(currency_id: &CurrencyId, account_id: &T::AccountId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id
account_id
T::AccountId
The borrower's account id

AccountDeposits

Mapping of account addresses to deposit details, CollateralType -> Owner -> Deposits
Code
View Method
1
pub type AccountDeposits<T: Config> = StorageDoubleMap<
2
_,
3
Twox64Concat,
4
CurrencyId,
5
Blake2_128Concat,
6
T::AccountId,
7
Deposits,
8
ValueQuery,
9
>;
Copied!
1
AccountDeposits::<T>::get(currency_id: &CurrencyId, account_id: &T::AccountId)
2
Self::account_deposits(currency_id: &CurrencyId, account_id: &T::AccountId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id
account_id
T::AccountId
The depositor's account id

AccountEarned

Mapping of account addresses to total deposit interest accrual, CurrencyType -> Owner -> EarnedSnapshot
Code
View Method
1
pub type AccountEarned<T: Config> = StorageDoubleMap<
2
_,
3
Twox64Concat,
4
CurrencyId,
5
Blake2_128Concat,
6
T::AccountId,
7
EarnedSnapshot,
8
ValueQuery,
9
>;
Copied!
1
AccountEarned::<T>::get(currency_id: &CurrencyId, account_id: &T::AccountId)
2
Self::account_earned(currency_id: &CurrencyId, account_id: &T::AccountId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id
account_id
T::AccountId
The depositor's account id

BorrowIndex

Accumulator of the total earned interest rate since the opening of the market, CurrencyType -> u128
Code
View Method
1
pub type BorrowIndex<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Rate, ValueQuery>;
Copied!
1
BorrowIndex::T::get(currency_id: &CurrencyId)
2
Self::borrow_index(currency_id: &CurrencyId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id

Currencies

The currency types support on lending markets
Code
View Method
1
pub type Currencies<T: Config> = StorageValue<_, Vec<CurrencyId>, ValueQuery>;
Copied!
1
Currencies::<T>::get()
2
Self::currencies()
Copied!

ExchangeRate

The exchange rate from the underlying to the internal collateral
Code
View Method
1
pub type ExchangeRate<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Rate, ValueQuery>;
Copied!
1
ExchangeRate::T::get(currency_id: &CurrencyId)
2
Self::exchange_rate(currency_id: &CurrencyId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id

CurrencyInterestModel

The utilization point at which the jump multiplier is applied
Code
View Method
1
pub type CurrencyInterestModel<T: Config> =
2
StorageMap<_, Twox64Concat, CurrencyId, InterestRateModel, ValueQuery>;
Copied!
1
CurrencyInterestModel::T::get(currency_id: &CurrencyId)
2
Self::currency_interest_model(currency_id: &CurrencyId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id

BorrowRate

Mapping of borrow rate to currency type
Code
View Method
1
pub type BorrowRate<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Rate, ValueQuery>;
Copied!
1
BorrowRate::T::get(currency_id: &CurrencyId)
2
Self::borrow_rate(currency_id: &CurrencyId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id

SupplyRate

Mapping of supply rate to currency type
Code
View Method
1
pub type SupplyRate<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Rate, ValueQuery>;
Copied!
1
SupplyRate::T::get(currency_id: &CurrencyId)
2
Self::supply_rate(currency_id: &CurrencyId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id

UtilizationRatio

The collateral utilization ratio
Code
View Method
1
pub type UtilizationRatio<T: Config> =
2
StorageMap<_, Twox64Concat, CurrencyId, Ratio, ValueQuery>;
Copied!
1
UtilizationRatio::T::get(currency_id: &CurrencyId)
2
Self::utilization_ratio(currency_id: &CurrencyId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id

CollateralFactor

The collateral utilization ratio
Code
View Method
1
pub type CollateralFactor<T: Config> =
2
StorageMap<_, Twox64Concat, CurrencyId, Ratio, ValueQuery>;
Copied!
1
CollateralFactor::T::get(currency_id: &CurrencyId)
2
Self::collateral_factor(currency_id: &CurrencyId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id

ReserveFactor

Fraction of interest currently set aside for reserves
Code
View Method
1
pub type ReserveFactor<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Ratio, ValueQuery>;
Copied!
1
ReserveFactor::T::get(currency_id: &CurrencyId)
2
Self::reserve_factor(currency_id: &CurrencyId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id

LiquidationIncentive

Liquidation incentive ratio
Code
View Method
1
pub type LiquidationIncentive<T: Config> =
2
StorageMap<_, Twox64Concat, CurrencyId, Rate, ValueQuery>
Copied!
1
LiquidationIncentive::T::get(currency_id: &CurrencyId)
2
Self::liquidation_incentive(currency_id: &CurrencyId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id

CloseFactor

The percent, ranging from 0% to 100%, of a liquidatable account's borrow that can be repaid in a single liquidate transaction.
Code
View Method
1
pub type CloseFactor<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Ratio, ValueQuery>;
Copied!
1
CloseFactor::T::get(currency_id: &CurrencyId)
2
Self::close_factor(currency_id: &CurrencyId)
Copied!
Key Name
Type
Description
currency_id
CurrencyId
The currency's Id

View Methods

Mint()

Sender supplies assets into the market and receives internal supplies in exchange.
1
pub fn mint(origin: OriginFor<T>, currency_id: CurrencyId, mint_amount: Balance,) -> DispatchResultWithPostInfo
Copied!
Name
Substrate Config
Runtime Type
Description
origin
T::Origin
RawOrigin
The account signed this transaction
currency_id
-
CurrencyId
the asset to be deposited
mint_amount
T::Balance
u128
the amount to be deposited
RETURN: Returns Ok() when mint succeeds, otherwise return a substrate error type.
Tip: Follow the link to know more about 'RawOrigin', 'CurrencyId'.

Redeem()

Sender redeems some of internal supplies in exchange for the underlying asset.
1
pub fn redeem(origin: OriginFor<T>, currency_id: CurrencyId, redeem_amount: Balance,) -> DispatchResultWithPostInfo
Copied!
Name
Substrate Config
Runtime Type
Description
origin
T::Origin
RawOrigin
The account signed this transaction
currency_id
-
CurrencyId
the asset to be redeemed
redeem_amount
T::Balance
u128
the amount to be redeemed
RETURN: Returns Ok() when redeem succeeds, otherwise return a substrate error type.

Redeem_all()

Senders redeem all internal supplies in exchange for the underlying asset.
1
pub fn redeem_all(origin: OriginFor<T>, currency_id: CurrencyId,) -> DispatchResultWithPostInfo
Copied!
Name
Substrate Config
Runtime Type
Description
origin
T::Origin
RawOrigin
The account signed this transaction
currency_id
-
CurrencyId
the asset to be redeemed
RETURN: Returns Ok() when redeem_all succeeds, otherwise return a substrate error type.

Borrow()

Sender borrows assets from the protocol to their own address.
1
pub fn borrow(origin: OriginFor<T>, currency_id: CurrencyId, borrow_amount: Balance,) -> DispatchResultWithPostInfo
Copied!
Name
Substrate Config
Runtime Type
Description
origin
T::Origin
RawOrigin
The account signed this transaction
currency_id
-
CurrencyId
the asset to be borrowed
borrow_amount
T::Balance
u128
the amount to be borrowed
RETURN: Returns Ok() when borrow succeeds, otherwise return a substrate error type.

Repay_borrow()

Sender repays some of their debts.
1
pub fn repay_borrow(origin: OriginFor<T>, currency_id: CurrencyId, repay_amount: Balance,) -> DispatchResultWithPostInfo
Copied!
Name
Substrate Config
Runtime Type
Description
origin
T::Origin
RawOrigin
The account signed this transaction
currency_id
-
CurrencyId
the asset to be repaid
repay_amount
T::Balance
u128
the amount to be repaid
RETURN: Returns Ok() when repay_borrow succeeds, otherwise return a substrate error type.

Repay_borrow_all()

Sender repays all of their debts.
1
pub fn repay_borrow_all(origin: OriginFor<T>, currency_id: CurrencyId,) -> DispatchResultWithPostInfo
Copied!
Name
Substrate Config
Runtime Type
Description
origin
T::Origin
RawOrigin
The account signed this transaction
currency_id
-
CurrencyId
the asset to be repaid
RETURN: Returns Ok() when repay_borrow_all succeeds, otherwise return a substrate error type.

Set_liquidation_incentive()

Sets a new liquidation incentive percentage for currency_id. Returns Err if the provided asset is not attached to an existent incentive.
1
pub fn set_liquidation_incentive(origin: OriginFor<T>, currency_id: CurrencyId, liquidate_incentive: Rate,) -> DispatchResultWithPostInfo
Copied!
Name
Substrate Config
Runtime Type
Description
origin
T::Origin
RawOrigin
The account signed this transaction
currency_id
-
CurrencyId
the asset that is going to be modified
liquidate_incentive
-
Rate
FixedU128 type that represents liquidate incentive rate
RETURN: Returns Ok() when set_liquidation_incentive succeeds, otherwise return a substrate error type.
Tip: Follow the link to know more about 'FixedU128'.

Transfer_token()

Using for development
1
pub fn transfer_token(
2
origin: OriginFor<T>,
3
to: T::AccountId,
4
currency_id: CurrencyId,
5
amount: Balance,
6
) -> DispatchResultWithPostInfo
Copied!
Name
Substrate Config
Runtime Type
Description
origin
T::Origin
RawOrigin
The account signed this transaction
to
T::AccountId
AccountId
The received account
currency_id
-
CurrencyId
The transferred asset
amount
T::Balance
u128
The number of transfer assets
RETURN: Returns Ok() when transfer_token succeeds, otherwise return a substrate error type.

Collateral_asset()

Set the collateral asset.
1
pub fn collateral_asset(origin: OriginFor<T>, currency_id: CurrencyId, enable: bool,) -> DispatchResultWithPostInfo
Copied!
Name
Substrate Config
Runtime Type
Description
origin
T::Origin
RawOrigin
The account signed this transaction
currency_id
-
CurrencyId
the asset to be set
enable
-
bool
Turn on/off the collateral option.
RETURN: Returns Ok() when collateral_asset succeeds, otherwise return a substrate error type.

Liquidate_borrow()

The sender liquidates the borrower's collateral.
1
pub fn liquidate_borrow(
2
origin: OriginFor<T>,
3
borrower: T::AccountId,
4
liquidate_token: CurrencyId,
5
repay_amount: Balance,
6
collateral_token: CurrencyId,
7
) -> DispatchResultWithPostInfo
Copied!
Name
Substrate Config
Runtime Type
Description
origin
T::Origin
RawOrigin
The account signed this transaction
borrower
T::AccountId
AccountId
The borrower to be liquidated
liquidate_token
-
CurrencyId
The asset to be liquidated
repay_amount
T::Balance
u128
The amount to be repaid borrow
collateral_token
-
CurrencyId
The collateral to seize from the borrower
RETURN: Returns Ok() when liquidate_borrow succeeds, otherwise return a substrate error type.

Set_rate_model()

Update the interest rate model for a given asset. May only be called from T::UpdateOrigin.
1
pub fn set_rate_model(origin: OriginFor<T>, currency_id: CurrencyId, new_model: InterestRateModel,) -> DispatchResultWithPostInfo
Copied!
Name
Substrate Config
Runtime Type
Description
origin
T::Origin
RawOrigin
The account signed this transaction
currency_id
-
CurrencyId
the asset to be set
new_model
-
InterestRateModel
The interest rate model to be set
RETURN: Returns Ok() when set_rate_model succeeds, otherwise return a substrate error type.
Tip: Follow the link to know more about 'InterestRateModel'.

Add_reserves()

Add reserves by transferring from the payer. May only be called from T::ReserveOrigin.
1
pub fn add_reserves(
2
origin: OriginFor<T>,
3
payer: <T::Lookup as StaticLookup>::Source,
4
currency_id: CurrencyId,
5
add_amount: Balance,
6
) -> DispatchResultWithPostInfo
Copied!
Name
Substrate Config
Runtime Type
Description
origin
T::Origin
RawOrigin
The account signed this transaction
payer
T::Lookup::Source
MultiAddress
The payer account
currency_id
-
CurrencyId
The assets to be added
add_amount
T::Balance
u128
The amount to be added
RETURN: Returns Ok() when add_reserves succeeds, otherwise return a substrate error type.
Tip: Follow the link to know more about 'MultiAddress'.

Reduce_reserves()

Reduces reserves by transferring to receiver. May only be called from T::ReserveOrigin.
1
pub fn reduce_reserves(
2
origin: OriginFor<T>,
3
receiver: <T::Lookup as StaticLookup>::Source,
4
currency_id: CurrencyId,
5
reduce_amount: Balance,
6
) -> DispatchResultWithPostInfo
Copied!
Name
Substrate Config
Runtime Type
Description
origin
T::Origin
RawOrigin
The account signed this transaction
receiver
T::Lookup::Source
MultiAddress
The receiver account
currency_id
-
CurrencyId
The assets to be reduced
reduce_amount
T::Balance
u128
The amount to be reduced
RETURN: Returns Ok() when reduce_reserves succeeds, otherwise return a substrate error type.

View Event

CollateralAssetAdded

Enable collateral for certain asset, [sender, currency_id]
CollateralAssetAdded(T::AccountId, CurrencyId)

CollateralAssetRemoved

Disable collateral for a certain asset, [sender, currency_id]
CollateralAssetRemoved(T::AccountId, CurrencyId)

Deposited

Event emitted when assets are deposited, [sender, currency_id, amount]
Deposited(T::AccountId, CurrencyId, Balance)

Redeemed

Event emitted when assets are redeemed, [sender, currency_id, amount]
Redeemed(T::AccountId, CurrencyId, Balance)

Borrowed

Event emitted when cash is borrowed, [sender, currency_id, amount]
Borrowed(T::AccountId, CurrencyId, Balance)

RepaidBorrow

Event emitted when a borrow is repaid, [sender, currency_id, amount]
RepaidBorrow(T::AccountId, CurrencyId, Balance)

LiquidatedBorrow

Event emitted when a borrow is liquidated,
[liquidator, borrower, liquidate_token, collateral_token, repay_amount, collateral_amount]
LiquidatedBorrow( T::AccountId, T::AccountId, CurrencyId, CurrencyId, Balance, Balance, )

NewInterestRateModel

New interest rate model is set, [new_interest_rate_model]
NewInterestRateModel(InterestRateModel)

ReservesReduced

Event emitted when the reserves are reduced, [admin, currency_id, reduced_amount, total_reserves]
ReservesReduced(T::AccountId, CurrencyId, Balance, Balance)

ReservesAdded

Event emitted when the reserves are added, [admin, currency_id, added_amount, total_reserves]
ReservesAdded(T::AccountId, CurrencyId, Balance, Balance)
​

View Error

Name
Description
InsufficientLiquidity
Insufficient liquidity to borrow more or disable collateral
InsufficientDeposit
Insufficient deposit to redeem
RepayAmountExceedsCloseFactor
Repay amount greater than borrow balance
DuplicateOperation
Asset already enabled/disabled collateral
NoDeposit
No deposit asset
RepayValueGreaterThanCollateral
Repay amount more than collateral amount
LiquidatorIsBorrower
Liquidator is same as borrower
NoBorrowBalance
There is no borrow balance
LiquidateValueOverflow
Liquidate value overflow
InsufficientReserves
Insufficient reserves
InvalidRateModelParam
Invalid rate model params
CurrencyNotEnabled
Currency not enabled
PriceOracleNotReady
Currency's oracle price not ready

​

​

​
​
Last modified 3mo ago