Skip to content

Commit

Permalink
Merge pull request #87 from gerrrg/add-flashloans
Browse files Browse the repository at this point in the history
add flash loans page from old dev docs
  • Loading branch information
mikemcdonald committed May 25, 2023
2 parents f3bb46d + 32bb57d commit 1958b8e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/guides/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ heroImage: /images/backgrounds/blue.png

## Arbitrageurs

- [Flash Loans](/guides/arbitrageurs/flash-loans.md)
- [Get Spot Price of a Pool](/guides/arbitrageurs/get-spot-price.md)

## Aggregators
Expand Down
36 changes: 36 additions & 0 deletions docs/guides/arbitrageurs/flash-loans.md
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);
...
}
}
```

0 comments on commit 1958b8e

Please sign in to comment.