Skip to main content

SablierV2FlashLoan

Git Source

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

NameTypeDescription
assetaddressThe ERC-20 asset to flash loan.
amountuint256The amount of asset flash loaned.

Returns

NameTypeDescription
feeuint256The 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

NameTypeDescription
assetaddressThe address of the ERC-20 asset to query.

Returns

NameTypeDescription
amountuint256The 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 for asset.
  • msg.sender must allow this contract to spend at least amount + fee assets.
  • receiver implementation of {IERC3156FlashBorrower.onFlashLoan} must return CALLBACK_SUCCESS.
function flashLoan(
IERC3156FlashBorrower receiver,
address asset,
uint256 amount,
bytes calldata data
)
external
override
noDelegateCall
returns (bool success);

Parameters

NameTypeDescription
receiverIERC3156FlashBorrowerThe receiver of the flash loaned assets, and the receiver of the callback.
assetaddressThe address of the ERC-20 asset to use for flash borrowing.
amountuint256The amount of asset to flash loan.
databytesArbitrary data structure, intended to contain user-defined parameters.

Returns

NameTypeDescription
successbooltrue 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
);