FlashLoans
Flashloan documentations
The Risk Protocol provides two types of Flashloans
:
Flashloan of Underlying Assets
Flashloan of Unwanted Assets on Wrapped Smart Tokens
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:
where
receiver: The address of the contract that will receive the
flashloan
and must implement theIFlashLoanReceiver
interfaceamount: self descriptive
params: any parameters that would be used in the
flashloan
receiver
The IFlashLoanReceiver
Interface
IFlashLoanReceiver
InterfaceThe 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:
Flashloan of Unwanted Assets on Wrapped Smart Tokens
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 some alternate smart tokens (the unwanted tokens). This means the wrapped smart token now contains some excess or unwanted tokens.
Flashloan Mechanism
In this context, our flashloan
feature allows users to borrow these unwanted tokens. The borrowed amount must be repaid in the wanted tokens, but with a special discount compared to market prices. This incentivizes rapid liquidation of the unwanted tokens, 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 theIFlashLoanReceiverAlt
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