-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from gerrrg/add-flashloans
add flash loans page from old dev docs
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Flash Loans | ||
|
||
## Overview | ||
|
||
Since the Vault holds all tokens for all pools, the consolidated token balances are available as Flash Loans. | ||
|
||
## Example Code | ||
|
||
```solidity | ||
pragma solidity ^0.7.0; | ||
import "@balancer-labs/v2-vault/contracts/interfaces/IVault.sol"; | ||
import "@balancer-labs/v2-vault/contracts/interfaces/IFlashLoanRecipient.sol"; | ||
contract FlashLoanRecipient is IFlashLoanRecipient { | ||
IVault private constant vault = "0xBA12222222228d8Ba445958a75a0704d566BF2C8"; | ||
function makeFlashLoan( | ||
IERC20[] memory tokens, | ||
uint256[] memory amounts, | ||
bytes memory userData | ||
) external { | ||
vault.flashLoan(this, tokens, amounts, userData); | ||
} | ||
function receiveFlashLoan( | ||
IERC20[] memory tokens, | ||
uint256[] memory amounts, | ||
uint256[] memory feeAmounts, | ||
bytes memory userData | ||
) external override { | ||
require(msg.sender == vault); | ||
... | ||
} | ||
} | ||
``` |