Skip to content

Instantly share code, notes, and snippets.

@coffiasd
Last active February 11, 2023 02:27
Show Gist options
  • Save coffiasd/440c42e5a0211d096080ad5b1b50b4ae to your computer and use it in GitHub Desktop.
Save coffiasd/440c42e5a0211d096080ad5b1b50b4ae to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol";
import "@balancer-labs/v2-interfaces/contracts/vault/IFlashLoanRecipient.sol";
contract Swap is IFlashLoanRecipient {
IVault private constant vault = IVault(0xBA12222222228d8Ba445958a75a0704d566BF2C8);
event eventLog(string eventName);
function makeFlashLoan(
IERC20[] memory tokens,
uint256[] memory amounts,
bytes memory userData
) external {
vault.flashLoan(this, tokens, amounts, userData);
emit eventLog("making flash...");
}
function receiveFlashLoan(
IERC20[] memory tokens,
uint256[] memory amounts,
uint256[] memory feeAmounts,
bytes memory userData
) external override {
require(msg.sender == address(vault));
//do something here...
// return token0
IERC20(tokens[0]).transfer(address(vault), amounts[0]);
emit eventLog("receive done...");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment