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=CurrencyPriceCollateralRateCollateralAmountCollateralValue = 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=BorrowInterestRateUtilizationRate(1ReserveFactor)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.

pub type LastBlockTimestamp<T: Config> = StorageValue<_, Timestamp, ValueQuery>;

TotalSupply

Total number of collateral tokens in circulation, CollateralType -> Balance

pub type TotalSupply<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Balance, ValueQuery>;

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

pub type TotalBorrows<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Balance, ValueQuery>;

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

pub type TotalReserves<T: Config> =
        StorageMap<_, Twox64Concat, CurrencyId, Balance, ValueQuery>;

Key Name

Type

Description

currency_id

CurrencyId

The currency's Id

AccountBorrows

Mapping of account addresses to outstanding borrow balances, CurrencyType -> Owner -> BorrowSnapshot

pub type AccountBorrows<T: Config> = StorageDoubleMap<
        _,
        Twox64Concat,
        CurrencyId,
        Blake2_128Concat,
        T::AccountId,
        BorrowSnapshot,
        ValueQuery,
    >;

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

pub type AccountDeposits<T: Config> = StorageDoubleMap<
        _,
        Twox64Concat,
        CurrencyId,
        Blake2_128Concat,
        T::AccountId,
        Deposits,
        ValueQuery,
    >;

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

pub type AccountEarned<T: Config> = StorageDoubleMap<
        _,
        Twox64Concat,
        CurrencyId,
        Blake2_128Concat,
        T::AccountId,
        EarnedSnapshot,
        ValueQuery,
    >;

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

pub type BorrowIndex<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Rate, ValueQuery>;

Key Name

Type

Description

currency_id

CurrencyId

The currency's Id

Currencies

The currency types support on lending markets

pub type Currencies<T: Config> = StorageValue<_, Vec<CurrencyId>, ValueQuery>;

ExchangeRate

The exchange rate from the underlying to the internal collateral

pub type ExchangeRate<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Rate, ValueQuery>;

Key Name

Type

Description

currency_id

CurrencyId

The currency's Id

CurrencyInterestModel

The utilization point at which the jump multiplier is applied

pub type CurrencyInterestModel<T: Config> =
        StorageMap<_, Twox64Concat, CurrencyId, InterestRateModel, ValueQuery>;

Key Name

Type

Description

currency_id

CurrencyId

The currency's Id

BorrowRate

Mapping of borrow rate to currency type

pub type BorrowRate<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Rate, ValueQuery>;

Key Name

Type

Description

currency_id

CurrencyId

The currency's Id

SupplyRate

Mapping of supply rate to currency type

pub type SupplyRate<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Rate, ValueQuery>;

Key Name

Type

Description

currency_id

CurrencyId

The currency's Id

UtilizationRatio

The collateral utilization ratio

pub type UtilizationRatio<T: Config> =
        StorageMap<_, Twox64Concat, CurrencyId, Ratio, ValueQuery>;

Key Name

Type

Description

currency_id

CurrencyId

The currency's Id

CollateralFactor

The collateral utilization ratio

pub type CollateralFactor<T: Config> =
        StorageMap<_, Twox64Concat, CurrencyId, Ratio, ValueQuery>;

Key Name

Type

Description

currency_id

CurrencyId

The currency's Id

ReserveFactor

Fraction of interest currently set aside for reserves

pub type ReserveFactor<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Ratio, ValueQuery>;

Key Name

Type

Description

currency_id

CurrencyId

The currency's Id

LiquidationIncentive

Liquidation incentive ratio

pub type LiquidationIncentive<T: Config> =
        StorageMap<_, Twox64Concat, CurrencyId, Rate, ValueQuery>

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.

pub type CloseFactor<T: Config> = StorageMap<_, Twox64Concat, CurrencyId, Ratio, ValueQuery>;

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.

pub fn mint(origin: OriginFor<T>, currency_id: CurrencyId, mint_amount: Balance,) -> DispatchResultWithPostInfo

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.

pub fn redeem(origin: OriginFor<T>, currency_id: CurrencyId, redeem_amount: Balance,) -> DispatchResultWithPostInfo

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.

pub fn redeem_all(origin: OriginFor<T>, currency_id: CurrencyId,) -> DispatchResultWithPostInfo

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.

pub fn borrow(origin: OriginFor<T>, currency_id: CurrencyId, borrow_amount: Balance,) -> DispatchResultWithPostInfo

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.

pub fn repay_borrow(origin: OriginFor<T>, currency_id: CurrencyId, repay_amount: Balance,) -> DispatchResultWithPostInfo

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.

pub fn repay_borrow_all(origin: OriginFor<T>, currency_id: CurrencyId,) -> DispatchResultWithPostInfo

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.

pub fn set_liquidation_incentive(origin: OriginFor<T>, currency_id: CurrencyId, liquidate_incentive: Rate,) -> DispatchResultWithPostInfo

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

pub fn transfer_token(
            origin: OriginFor<T>,
            to: T::AccountId,
            currency_id: CurrencyId,
            amount: Balance,
        ) -> DispatchResultWithPostInfo

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.

pub fn collateral_asset(origin: OriginFor<T>, currency_id: CurrencyId, enable: bool,) -> DispatchResultWithPostInfo

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.

pub fn liquidate_borrow(
            origin: OriginFor<T>,
            borrower: T::AccountId,
            liquidate_token: CurrencyId,
            repay_amount: Balance,
            collateral_token: CurrencyId,
        ) -> DispatchResultWithPostInfo

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.

pub fn set_rate_model(origin: OriginFor<T>, currency_id: CurrencyId, new_model: InterestRateModel,) -> DispatchResultWithPostInfo

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.

pub fn add_reserves(
            origin: OriginFor<T>,
            payer: <T::Lookup as StaticLookup>::Source,
            currency_id: CurrencyId,
            add_amount: Balance,
        ) -> DispatchResultWithPostInfo

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.

pub fn reduce_reserves(
            origin: OriginFor<T>,
            receiver: <T::Lookup as StaticLookup>::Source,
            currency_id: CurrencyId,
            reduce_amount: Balance,
        ) -> DispatchResultWithPostInfo

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 updated