View Source: contracts/core/delegates/VaultDelegateWithFlashLoan.sol
↗ Extends: VaultDelegateBase ↘ Derived Contracts: VaultDelegate
VaultDelegateWithFlashLoan
WithFlashLoan contract implements EIP-3156 Flash Loan
.
Using flash loans, you can borrow up to the total available amount of
the stablecoin liquidity available in this cover liquidity pool.
You need to return back the borrowed amount + fee in the same transaction.
The function flashFee
enables you to check, in advance, fee that
you need to pay to take out the loan.
- getFlashFee(address , bytes32 coverKey, address token, uint256 amount)
- getMaxFlashLoan(address , bytes32 coverKey, address token)
- preFlashLoan(address , bytes32 coverKey, IERC3156FlashBorrower , address token, uint256 amount, bytes )
- postFlashLoan(address , bytes32 coverKey, IERC3156FlashBorrower , address , uint256 , bytes )
The fee to be charged for a given loan.
function getFlashFee(address , bytes32 coverKey, address token, uint256 amount) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
address | token The loan currency. | |
coverKey | bytes32 | |
token | address | The loan currency. |
amount | uint256 | The amount of tokens lent. |
Returns
The amount of token
to be charged for the loan, on top of the returned principal.
Source Code
function getFlashFee(
address, /*caller*/
bytes32 coverKey,
address token,
uint256 amount
) external view override returns (uint256) {
s.senderMustBeVaultContract(coverKey);
return s.getFlashFeeInternal(coverKey, token, amount);
}
The amount of currency available to be lent.
function getMaxFlashLoan(address , bytes32 coverKey, address token) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
address | token The loan currency. | |
coverKey | bytes32 | |
token | address | The loan currency. |
Returns
The amount of token
that can be borrowed.
Source Code
function getMaxFlashLoan(
address, /*caller*/
bytes32 coverKey,
address token
) external view override returns (uint256) {
s.senderMustBeVaultContract(coverKey);
return s.getMaxFlashLoanInternal(coverKey, token);
}
function preFlashLoan(address , bytes32 coverKey, IERC3156FlashBorrower , address token, uint256 amount, bytes ) external nonpayable
returns(stablecoin contract IERC20, fee uint256, protocolFee uint256)
Arguments
Name | Type | Description |
---|---|---|
address | ||
coverKey | bytes32 | |
IERC3156FlashBorrower | ||
token | address | |
amount | uint256 | |
bytes |
Source Code
function preFlashLoan(
address, /*caller*/
bytes32 coverKey,
IERC3156FlashBorrower, /*receiver*/
address token,
uint256 amount,
bytes calldata /*data*/
)
external
override
returns (
IERC20 stablecoin,
uint256 fee,
uint256 protocolFee
)
{
s.mustNotBePaused();
s.mustHaveNormalCoverStatus(coverKey);
s.senderMustBeVaultContract(coverKey);
stablecoin = IERC20(s.getStablecoin());
// require(address(stablecoin) == token, "Unknown token"); <-- already checked in `getFlashFeesInternal`
// require(amount > 0, "Loan too small"); <-- already checked in `getFlashFeesInternal`
s.setBoolByKeys(ProtoUtilV1.NS_COVER_HAS_FLASH_LOAN, coverKey, true);
(fee, protocolFee) = s.getFlashFeesInternal(coverKey, token, amount);
require(fee > 0, "Loan too small");
require(protocolFee > 0, "Loan too small");
}
function postFlashLoan(address , bytes32 coverKey, IERC3156FlashBorrower , address , uint256 , bytes ) external nonpayable
Arguments
Name | Type | Description |
---|---|---|
address | ||
coverKey | bytes32 | |
IERC3156FlashBorrower | ||
address | ||
uint256 | ||
bytes |
Source Code
function postFlashLoan(
address, /*caller*/
bytes32 coverKey,
IERC3156FlashBorrower, /*receiver*/
address, /*token*/
uint256, /*amount*/
bytes calldata /*data*/
) external override {
s.senderMustBeVaultContract(coverKey);
s.setBoolByKeys(ProtoUtilV1.NS_COVER_HAS_FLASH_LOAN, coverKey, false);
s.updateStateAndLiquidity(coverKey);
}
- AaveStrategy
- AccessControl
- AccessControlLibV1
- Address
- BaseLibV1
- BokkyPooBahsDateTimeLibrary
- BondPool
- BondPoolBase
- BondPoolLibV1
- CompoundStrategy
- console
- Context
- Cover
- CoverBase
- CoverLibV1
- CoverReassurance
- CoverStake
- CoverUtilV1
- cxToken
- cxTokenFactory
- cxTokenFactoryLibV1
- Delayable
- Destroyable
- ERC165
- ERC20
- FakeAaveLendingPool
- FakeCompoundDaiDelegator
- FakeRecoverable
- FakeStore
- FakeToken
- FakeUniswapPair
- FakeUniswapV2FactoryLike
- FakeUniswapV2PairLike
- FakeUniswapV2RouterLike
- FaultyAaveLendingPool
- FaultyCompoundDaiDelegator
- Finalization
- ForceEther
- Governance
- GovernanceUtilV1
- IAaveV2LendingPoolLike
- IAccessControl
- IBondPool
- IClaimsProcessor
- ICompoundERC20DelegatorLike
- ICover
- ICoverReassurance
- ICoverStake
- ICxToken
- ICxTokenFactory
- IERC165
- IERC20
- IERC20Detailed
- IERC20Metadata
- IERC3156FlashBorrower
- IERC3156FlashLender
- IFinalization
- IGovernance
- ILendingStrategy
- ILiquidityEngine
- IMember
- InvalidStrategy
- IPausable
- IPolicy
- IPolicyAdmin
- IPriceDiscovery
- IProtocol
- IRecoverable
- IReporter
- IResolution
- IResolvable
- IStakingPools
- IStore
- IStoreLike
- IUniswapV2FactoryLike
- IUniswapV2PairLike
- IUniswapV2RouterLike
- IUnstakable
- IVault
- IVaultDelegate
- IVaultFactory
- IWitness
- LiquidityEngine
- MaliciousToken
- MockAccessControlUser
- MockCoverUtilUser
- MockCxToken
- MockCxTokenPolicy
- MockCxTokenStore
- MockFlashBorrower
- MockProcessorStore
- MockProcessorStoreLib
- MockProtocol
- MockRegistryClient
- MockStore
- MockStoreKeyUtilUser
- MockValidationLibUser
- MockVault
- MockVaultLibUser
- NPM
- NPMDistributor
- NTransferUtilV2
- NTransferUtilV2Intermediate
- Ownable
- Pausable
- Policy
- PolicyAdmin
- PolicyHelperV1
- PoorMansERC20
- PriceDiscovery
- PriceLibV1
- Processor
- ProtoBase
- Protocol
- ProtoUtilV1
- Recoverable
- ReentrancyGuard
- RegistryLibV1
- Reporter
- Resolution
- Resolvable
- RoutineInvokerLibV1
- SafeERC20
- StakingPoolBase
- StakingPoolCoreLibV1
- StakingPoolInfo
- StakingPoolLibV1
- StakingPoolReward
- StakingPools
- Store
- StoreBase
- StoreKeyUtil
- StrategyLibV1
- Strings
- TimelockController
- Unstakable
- ValidationLibV1
- Vault
- VaultBase
- VaultDelegate
- VaultDelegateBase
- VaultDelegateWithFlashLoan
- VaultFactory
- VaultFactoryLibV1
- VaultLibV1
- VaultLiquidity
- VaultStrategy
- WithFlashLoan
- WithPausability
- WithRecovery
- Witness