SablierV2FlashLoan
Inherits: IERC3156FlashLender, SablierV2Base
This contract implements the ERC-3156 standard to enable flash loans.
See https://eips.ethereum.org/EIPS/eip-3156.
State Variables
CALLBACK_SUCCESS
bytes32 internal constant CALLBACK_SUCCESS = keccak256("ERC3156FlashBorrower.onFlashLoan");
Functions
flashFee
The amount of fees to charge for a hypothetical flash loan amount.
You might notice a bit of a terminology clash here, since the ERC-3156 standard refers to the "flash fee" as an amount, whereas the flash fee retrieved from the comptroller is a percentage. Throughout the code base, the "amount" suffix is typically appended to variables that represent amounts, but, in this context, the name must be kept unchanged to comply with the ERC. Requirements:
- The ERC-20 asset must be flash loanable.
function flashFee(address asset, uint256 amount) public view override returns (uint256 fee);
Parameters
Name | Type | Description |
---|---|---|
asset | address | The ERC-20 asset to flash loan. |
amount | uint256 | The amount of asset flash loaned. |
Returns
Name | Type | Description |
---|---|---|
fee | uint256 | The amount of asset to charge for the loan on top of the returned principal. |
maxFlashLoan
The amount of ERC-20 assets available for flash loan.
If the ERC-20 asset is not flash loanable, this function returns zero.
function maxFlashLoan(address asset) external view override returns (uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
asset | address | The address of the ERC-20 asset to query. |
Returns
Name | Type | Description |
---|---|---|
amount | uint256 | The amount of asset that can be flash loaned. |
flashLoan
Allows smart contracts to access the entire liquidity of the Sablier V2 contract within one transaction as long as the principal plus a flash fee is returned.
Emits a {FlashLoan} event. Requirements:
- Must not be delegate called.
- Refer to the requirements in {flashFee}.
amount
must be less than 2^128.fee
must be less than 2^128.amount
must not exceed the liquidity available forasset
.msg.sender
must allow this contract to spend at leastamount + fee
assets.receiver
implementation of {IERC3156FlashBorrower.onFlashLoan} must returnCALLBACK_SUCCESS
.
function flashLoan(
IERC3156FlashBorrower receiver,
address asset,
uint256 amount,
bytes calldata data
)
external
override
noDelegateCall
returns (bool success);
Parameters
Name | Type | Description |
---|---|---|
receiver | IERC3156FlashBorrower | The receiver of the flash loaned assets, and the receiver of the callback. |
asset | address | The address of the ERC-20 asset to use for flash borrowing. |
amount | uint256 | The amount of asset to flash loan. |
data | bytes | Arbitrary data structure, intended to contain user-defined parameters. |
Returns
Name | Type | Description |
---|---|---|
success | bool | true on success. |
Events
FlashLoan
Emitted when a flash loan is executed.
event FlashLoan(
address indexed initiator,
IERC3156FlashBorrower indexed receiver,
IERC20 indexed asset,
uint256 amount,
uint256 feeAmount,
bytes data
);