Flashloans

The Risk Protocol provides two types of Flashloans:

  1. Flashloan of Underlying Assets

  2. Flashloan of Unwanted Assets in Wrapped Smart Tokens

1. Flashloan of Underlying Assets

This type of flashloan is similar to those offered by protocols like AAVE. We provide access to the underlying tokens locked in our smart contracts as flashloans. These loans are issued against a fixed fee and must be repaid within the same transaction.

  • The flashLoan method is exposed on the smart token contracts, making it accessible via the RiskON/RiskOFF token contracts.

Flashloan Method on Smart Contracts

The flashloan method to be called on the smart contract is as follows:

function flashLoan(
    address receiver,
    uint256 amount,
    bytes memory params
) external

where

  • receiver: The address of the contract that will receive the flashloan and must implement the IFlashLoanReceiver interface

  • amount: self descriptive

  • params: any parameters that would be used in the flashloan receiver

The IFlashLoanReceiver Interface

The receiver contract must implement the following interface to handle the flashloan:

Note:

The receiver contract must approve the smart token contract to spend the underlying token on it's behalf.

Sample FlashLoan Receiver Contract

Below is an example of a simple receiver contract that implements the IFlashLoanReceiver interface:

2. Flashloan of Unwanted Assets in Wrapped Smart Token contracts

This type of flashloan is unique to our protocol, offering users access to pools of excess or unwanted smart tokens on the wrapped smart token contracts.

Scenario Explanation

To understand this concept better, let's consider an example involving BTC:

  • We have BTC RiskON and BTC RiskOFF as smart tokens.

  • Correspondingly, we have wBTC RiskON and wBTC RiskOFF as wrapped ERC20 tokens.

Each wrapped token contract (wBTC RiskON and wBTC RiskOFF) functions like a separate wallet, holding a certain amount of their respective smart tokens. (More details can be found in the Wrapped Smart Token section).

During a rebalance, depending on market conditions, one of the wrapped smart token contracts might end up holding not only its respective smart tokens (the "wanted" tokens) but also the other SMART Token in the SMART Token pair (the "unwanted" tokens. See "Why This Allocation?" section in Rebalance for explanation). This means one of the Wrapped Smart Token contract now contains some excess or unwanted tokens.

Flashloan Mechanism

In this context, our flashloan feature allows users to borrow these unwanted tokens at a discount to NTV. The borrowed amount must be repaid in the wanted tokens. The discount on the unwanted tokens progressively increases in order to incentivize rapid liquidation of the unwanted tokens from the wrapped contracts, helping to maintain balance in the system.

The flashloan method is exposed on the Wrapped SMART Token contracts, making it accessible via the wRiskON/wRiskOFF token contracts.

Flashloan Method on Wrapped SMART Token Contracts

The flashloan method available on these contracts is as follows:

where

  • receiver: The address of the contract that will receive the flashloan and must implement the IFlashLoanReceiverAlt interface.

  • amount: self descriptive

  • params: Any additional parameters that would be used within the flashloan receiver.

  • encodedData: Encoded market prices retrieved from our API.

  • signature: The signature of the encoded market prices from our API.

The IFlashLoanReceiverAlt Interface

The receiver contract must implement the IFlashLoanReceiverAlt interface to handle the flashloan operation for unwanted assets on wrapped smart tokens.

Interface Parameters

  • loanAmount: The amount of unwanted tokens borrowed through the flashloan.

  • repayToken: The address of the token to be used for repayment (the wanted token).

  • repayAmount: The total amount of the repayToken that needs to be repaid, including any fees or discounts.

  • initiator: The address of the entity that initiated the flashloan.

  • params: Additional parameters that may be required by the receiver contract during the flashloan operation.

Note: The receiver contract must approve the wrapped smart token contract to spend the wanted smart tokens for the repayment of the loan.

Sample FlashLoan Receiver Contract

Below is an example of a simple receiver contract that implements the IFlashLoanReceiverAlt interface:

Last updated