Skip to main content

FlashloanAggregator

Git Source

Inherits: IFlashloanAggregator, BalancerV2FlashloanRecipient, IMorphoFlashLoanCallback, IERC3156FlashBorrower, IFlashLoanSimpleReceiver

State Variables

_EXPECTED_DATA_HASH_SLOT

Hash of the user data we expect to receive in onFlashLoan.

bytes32 public constant _EXPECTED_DATA_HASH_SLOT = 0x82495b57f77c85cf8c0395fbfa4aaf855e2e402a9c6668de75d52c07a0b11300;

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 pool.

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.
_aaveV3AddressProvideraddress
_daiaddress

requestFlashloan

The function to request a flashloan.

function requestFlashloan(FlashloanRequest calldata request) external override onlyCaliber;

Parameters

NameTypeDescription
requestFlashloanRequestThe request for the flashloan.

_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

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

balancerV3FlashloanCallback

Callback handler for Balancer V3 flashloan.

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

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;

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
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
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 returns (IPoolAddressesProvider);

POOL

function POOL() external view returns (IPool);