Skip to content
LogoLogo

FlashloanAggregator

Git Source

Inherits: IFlashloanAggregator, IFlashLoanRecipient, IMorphoFlashLoanCallback, IERC3156FlashBorrower, IFlashLoanSimpleReceiver

Constants

EXPECTED_DATA_HASH_SLOT

bytes32 private constant EXPECTED_DATA_HASH_SLOT =
        0x1cdc327c404943fa68ab4aca3860b62126227055e2873c38c2fe6dd350687a00;

caliberFactory

The address of the Caliber factory.

address public immutable caliberFactory;

balancerV2Pool

The address of the Balancer V2 pool.

address public immutable balancerV2Pool;

balancerV3Pool

The address of the Balancer V3 pool.

address public immutable balancerV3Pool;

morphoPool

The address of the Morpho pool.

address public immutable morphoPool;

dai

The address of the DAI token.

address public immutable dai;

dssFlash

The address of the Maker DSS Flash.

address public immutable dssFlash;

aaveV3AddressProvider

The address of the Aave V3 address provider.

address public immutable aaveV3AddressProvider;

Functions

onlyCaliber

Modifier to check if the caller is a Caliber.

modifier onlyCaliber();

constructor

The constructor for the FlashloanAggregator.

constructor(
        address _caliberFactory,
        address _balancerV2Pool,
        address _balancerV3Pool,
        address _morphoPool,
        address _dssFlash,
        address _aaveV3AddressProvider,
        address _dai
    );

Parameters

NameTypeDescription
_caliberFactoryaddressThe address of the Caliber factory.
_balancerV2PooladdressThe address of the Balancer V2 pool.
_balancerV3PooladdressThe address of the Balancer V3 pool.
_morphoPooladdressThe address of the Morpho pool.
_dssFlashaddressThe address of the Maker DSS Flash.
_aaveV3AddressProvideraddressThe address of the Aave V3 address provider.
_daiaddressThe address of the DAI token.

requestFlashloan

The function to request a flash loan.

function requestFlashloan(FlashloanRequest calldata request) external override onlyCaliber;

Parameters

NameTypeDescription
requestFlashloanRequestThe request for the flash loan.

_dispatchFlashloanRequest

Function to dispatch the flashloan request to the correct provider.

function _dispatchFlashloanRequest(FlashloanRequest calldata request) internal;

Parameters

NameTypeDescription
requestFlashloanRequestThe request for the flashloan.

_clearExpectedDataHash

Internal function to clear the expected data hash.

function _clearExpectedDataHash() internal;

_setExpectedDataHash

Internal function to set the expected data hash.

function _setExpectedDataHash(bytes memory data) internal;

Parameters

NameTypeDescription
databytesThe data to set the expected data hash to.

_isValidExpectedDataHash

Internal function to check if the expected data hash is valid.

function _isValidExpectedDataHash(bytes memory data) internal view;

Parameters

NameTypeDescription
databytesThe data to check the expected data hash against.

_requestBalancerV2Flashloan

Function to request a flashloan from Balancer V2.

function _requestBalancerV2Flashloan(FlashloanRequest calldata request) internal;

Parameters

NameTypeDescription
requestFlashloanRequestThe request for the flashloan.

_requestBalancerV3Flashloan

Function to request a flashloan from Balancer V3.

function _requestBalancerV3Flashloan(FlashloanRequest calldata request) internal;

Parameters

NameTypeDescription
requestFlashloanRequestThe request for the flashloan.

_requestMorphoFlashloan

Function to request a flashloan from Morpho.

function _requestMorphoFlashloan(FlashloanRequest calldata request) internal;

Parameters

NameTypeDescription
requestFlashloanRequestThe request for the flashloan.

_requestDssFlashloan

Function to request a flashloan from Maker DSS Flash.

function _requestDssFlashloan(FlashloanRequest calldata request) internal;

Parameters

NameTypeDescription
requestFlashloanRequestThe request for the flashloan.

_requestAaveV3Flashloan

Function to request a flashloan from Aave V3.

function _requestAaveV3Flashloan(FlashloanRequest calldata request) internal;

Parameters

NameTypeDescription
requestFlashloanRequestThe request for the flashloan.

_handleFlashloanCallback

Catch-all function to handle the flashloan callback.

function _handleFlashloanCallback(
        address caliber,
        ICaliber.Instruction memory instruction,
        address token,
        uint256 amount
    ) internal;

Parameters

NameTypeDescription
caliberaddressThe address of the Caliber.
instructionICaliber.InstructionThe instruction to execute.
tokenaddressThe token to flashloan.
amountuint256The amount to flashloan.

receiveFlashLoan

When flashLoan is called on the Vault, it invokes the receiveFlashLoan hook on the recipient.

At the time of the call, the Vault will have transferred amounts for tokens to the recipient. Before this call returns, the recipient must have transferred amounts plus feeAmounts for each token back to the Vault, or else the entire flash loan will revert.

userData is the same value passed in the IVault.flashLoan call.

function receiveFlashLoan(
        BalancerIERC20[] memory tokens,
        uint256[] memory amounts,
        uint256[] memory feeAmounts,
        bytes memory userData
    ) external override;

Parameters

NameTypeDescription
tokensBalancerIERC20[]
amountsuint256[]
feeAmountsuint256[]
userDatabytes

balancerV3FlashloanCallback

Callback handler for Balancer V3 flashloan.

function balancerV3FlashloanCallback(
        address caliber,
        ICaliber.Instruction calldata instruction,
        address token,
        uint256 amount
    ) external override;

Parameters

NameTypeDescription
caliberaddressThe address of the Caliber contract that initiated the flashloan.
instructionICaliber.InstructionThe instruction to execute.
tokenaddressThe token borrowed.
amountuint256The amount borrowed.

onMorphoFlashLoan

Callback called when a flash loan occurs.

The callback is called only if data is not empty.

function onMorphoFlashLoan(uint256 assets, bytes calldata data) external override;

Parameters

NameTypeDescription
assetsuint256The amount of assets that was flash loaned.
databytesArbitrary data passed to the flashLoan function.

onFlashLoan

Receive a flash loan.

function onFlashLoan(address initiator, address token, uint256 amount, uint256 fee, bytes calldata data)
        external
        override
        returns (bytes32);

Parameters

NameTypeDescription
initiatoraddressThe initiator of the loan.
tokenaddressThe loan currency.
amountuint256The amount of tokens lent.
feeuint256The additional amount of tokens to repay.
databytesArbitrary data structure, intended to contain user-defined parameters.

Returns

NameTypeDescription
<none>bytes32The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan"

executeOperation

Executes an operation after receiving the flash-borrowed asset

Ensure that the contract can return the debt + premium, e.g., has enough funds to repay and has approved the Pool to pull the total amount

function executeOperation(address asset, uint256 amount, uint256 premium, address initiator, bytes calldata params)
        external
        override
        returns (bool);

Parameters

NameTypeDescription
assetaddressThe address of the flash-borrowed asset
amountuint256The amount of the flash-borrowed asset
premiumuint256The fee of the flash-borrowed asset
initiatoraddressThe address of the flashloan initiator
paramsbytesThe byte-encoded params passed when initiating the flashloan

Returns

NameTypeDescription
<none>boolTrue if the execution of the operation succeeds, false otherwise

ADDRESSES_PROVIDER

function ADDRESSES_PROVIDER() external view override returns (IPoolAddressesProvider);

Returns

NameTypeDescription
<none>IPoolAddressesProvider

POOL

function POOL() external view override returns (IPool);

Returns

NameTypeDescription
<none>IPool