FluidFlashLender

Git Source

Inherits:Structs, IFluidFlashLender, IProtocol, Helpers

contract that provides Flashloans via Fluid. ERC-3156 compatible. In addition also implements a flashLoanMultiple() method which can be used to flash loan multiple tokens at once.

Fee is a constant 0. This contract is not upgradeable.

Functions

constructor

constructor(IFluidLiquidity liquidity_) Helpers(liquidity_);

maxFlashLoan

The amount of currency available to be lent.

function maxFlashLoan(address token_) public view returns (uint256);

Parameters

NameTypeDescription
token_addressThe loan currency.

Returns

NameTypeDescription
<none>uint256The amount of token that can be borrowed.

flashFee

The fee to be charged for a given loan.

function flashFee(address token_, uint256 amount_) external view returns (uint256);

Parameters

NameTypeDescription
token_addressloan currency.
amount_uint256The amount of tokens lent.

Returns

NameTypeDescription
<none>uint256The amount of token to be charged for the loan, on top of the returned principal.

flashLoan

Initiate a flash loan.

receiver_ must approve amount_ of token_ for payback. For native token, it must be send as msg.value.

function flashLoan(IERC3156FlashBorrower receiver_, address token_, uint256 amount_, bytes calldata data_)
    external
    validAddress(address(receiver_))
    validAddress(token_)
    returns (bool);

Parameters

NameTypeDescription
receiver_IERC3156FlashBorrowerThe receiver of the tokens in the loan, and the receiver of the callback.
token_addressThe loan currency.
amount_uint256The amount of tokens lent.
data_bytesArbitrary data structure, intended to contain user-defined parameters.

flashLoanMultiple

Initiate a flash loan with multiple tokens.

receiver_ must approve amount_ of each token for payback. For native token, it must be send as msg.value.

function flashLoanMultiple(IFlashBorrower receiver_, AddressUint256[] calldata tokensWithAmounts_, bytes calldata data_)
    external
    validAddress(address(receiver_))
    returns (bool);

Parameters

NameTypeDescription
receiver_IFlashBorrowerThe receiver of the tokens in the loan, and the receiver of the callback.
tokensWithAmounts_AddressUint256[]An array of token addresses and loan amounts.
data_bytesArbitrary data structure, intended to contain user-defined parameters.

Returns

NameTypeDescription
<none>bool'true' if the flash loans are successful

liquidityCallback

flashLender liquidity callback

function liquidityCallback(address token_, uint256 amount_, bytes calldata data_) external;

Parameters

NameTypeDescription
token_addressThe token being transferred
amount_uint256The amount being transferred
data_bytes

receive

@Fallback function to receive Ether

receive() external payable;

rescueFunds

sends any potentially stuck funds to Liquidity contract. Only callable by Liquidity auths.

function rescueFunds(address token_) external;

repayAtLiquidity

repays repayAmount_ for token_ at Liquidity. Can be used to balance out any leftover rounding differences at Liquidity if ever needed.

function repayAtLiquidity(address token_, uint256 repayAmount_) external payable;

Events

LogRescueFunds

emitted whenever funds for a certain token are rescued to Liquidity

event LogRescueFunds(address indexed token);

LogFlashLoan

emitted when a flashloan has been taken and repaid

event LogFlashLoan(address indexed token, uint256 indexed amount, address indexed receiver);