IdleToken
for the Best Yield strategy. has support for flash loans, which are uncollateralized loans that allow users to borrow the underlying token (e.g DAI
) of an IdleToken
(e.g IdleDAI
).IdleToken
contracts can lend their undelrying tokens to a borrower smart contract as long as the principal amount + a fee are returned within the same transaction.IdleToken
flash loans implementation follows the EIP-3156 which defines a standard interface that the lender and borrower smart contracts must implement.0.02%
, available in the uint256 public flashLoanFee;
variable. You can also call the flashFee
method to ask for the final fee based on the _amount
to be borrowed:function flashFee(address _token, uint256 _amount) public view returns (uint256);
flashLoan
method of an IdleToken
.IdleToken
contract transfers _amount token to the borrower contract and calls its onFlashLoan
method:IdleToken
.principal + fee
of the borrowed token keccak256("ERC3156FlashBorrower.onFlashLoan")
IdleToken
checks that the returned value is the one expected (keccak256("ERC3156FlashBorrower.onFlashLoan")
) and transfers amount + fee
tokens from the borrower to itself.amount + fee
), the transaction is reverted.