Developers
Search…
Flash Loans

Overview

Since the Vault holds all tokens for all pools, the consolidated token balances are available as Flash Loans.

Example Code

1
pragma solidity ^0.7.0;
2
3
import "@balancer-labs/v2-vault/contracts/interfaces/IVault.sol";
4
import "@balancer-labs/v2-vault/contracts/interfaces/IFlashLoanRecipient.sol";
5
6
contract FlashLoanRecipient is IFlashLoanRecipient {
7
IVault private constant vault = "0xBA12222222228d8Ba445958a75a0704d566BF2C8";
8
9
function makeFlashLoan(
10
IERC20[] memory tokens,
11
uint256[] memory amounts,
12
bytes memory userData
13
) external {
14
vault.flashLoan(this, tokens, amounts, userData);
15
}
16
17
function receiveFlashLoan(
18
IERC20[] memory tokens,
19
uint256[] memory amounts,
20
uint256[] memory feeAmounts,
21
bytes memory userData
22
) external override {
23
require(msg.sender == vault);
24
...
25
}
26
}
Copied!
Copy link