View Source: contracts/core/delegates/VaultDelegateWithFlashLoan.sol
↗ Extends: VaultDelegateBase ↘ Derived Contracts: VaultDelegate
VaultDelegateWithFlashLoan
This contract implements EIP-3156 Flash 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. Warning: this function does not validate the cover key supplied.
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. Warning: this function does not validate the cover key supplied.
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);
}
This hook runs before flashLoan
implementation on vault(s)
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 Enter the cover key | |
coverKey | bytes32 | Enter the cover key |
IERC3156FlashBorrower | coverKey Enter the cover key | |
token | address | Enter the token you want to borrow |
amount | uint256 | Enter the flash loan amount to receive |
bytes | coverKey Enter the cover key |
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.mustEnsureAllProductsAreNormal(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");
}
This hook runs after flashLoan
implementation on vault(s)
function postFlashLoan(address , bytes32 coverKey, IERC3156FlashBorrower , address , uint256 , bytes ) external nonpayable
Arguments
Name | Type | Description |
---|---|---|
address | coverKey Enter the cover key | |
coverKey | bytes32 | Enter the cover key |
IERC3156FlashBorrower | coverKey Enter the cover key | |
address | coverKey Enter the cover key | |
uint256 | coverKey Enter the cover key | |
bytes | coverKey Enter the cover key |
Source Code
function postFlashLoan(
address, /*caller*/
bytes32 coverKey,
IERC3156FlashBorrower, /*receiver*/
address, /*token*/
uint256, /*amount*/
bytes calldata /*data*/
) external override {
// @suppress-zero-value-check The `amount` value isn't used and therefore not checked
s.mustNotBePaused();
s.senderMustBeVaultContract(coverKey);
s.mustEnsureAllProductsAreNormal(coverKey);
s.setBoolByKeys(ProtoUtilV1.NS_COVER_HAS_FLASH_LOAN, coverKey, false);
s.updateStateAndLiquidity(coverKey);
}
- AaveStrategy
- AccessControl
- AccessControlLibV1
- Address
- BaseLibV1
- BokkyPooBahsDateTimeLibrary
- BondPool
- BondPoolBase
- BondPoolLibV1
- CompoundStrategy
- Context
- Cover
- CoverBase
- CoverLibV1
- CoverReassurance
- CoverStake
- CoverUtilV1
- cxToken
- cxTokenFactory
- cxTokenFactoryLibV1
- Delayable
- Destroyable
- ERC165
- ERC20
- FakeAaveLendingPool
- FakeCompoundDaiDelegator
- FakePriceOracle
- 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
- IPriceOracle
- IProtocol
- IRecoverable
- IReporter
- IResolution
- IResolvable
- IStakingPools
- IStore
- IStoreLike
- IUniswapV2FactoryLike
- IUniswapV2PairLike
- IUniswapV2RouterLike
- IUnstakable
- IVault
- IVaultDelegate
- IVaultFactory
- IWitness
- LiquidityEngine
- MaliciousToken
- MockAccessControlUser
- MockCoverUtilUser
- MockCxToken
- MockCxTokenPolicy
- MockCxTokenStore
- MockFlashBorrower
- MockLiquidityEngineUser
- MockProcessorStore
- MockProcessorStoreLib
- MockProtocol
- MockRegistryClient
- MockStore
- MockStoreKeyUtilUser
- MockValidationLibUser
- MockVault
- MockVaultLibUser
- NPM
- NpmDistributor
- NTransferUtilV2
- NTransferUtilV2Intermediate
- Ownable
- Pausable
- Policy
- PolicyAdmin
- PolicyHelperV1
- PoorMansERC20
- POT
- 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