Created
March 9, 2020 06:49
-
-
Save what-the-func/028cb78488e1d28ee1c226b758daee7e to your computer and use it in GitHub Desktop.
FlashLoan
This file contains hidden or 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
pragma solidity ^0.5.0; | |
import "openzeppelin-solidity/contracts/math/SafeMath.sol"; | |
import "../../flashloan/base/FlashLoanReceiverBase.sol"; | |
import "../../configuration/LendingPoolAddressesProvider.sol"; | |
import "../../lendingpool/LendingPool.sol"; | |
contract FlashLoanReceiverExample is FlashLoanReceiverBase { | |
using SafeMath for uint256; | |
LendingPoolAddressesProvider provider; | |
address chainlink; | |
constructor(LendingPoolAddressesProvider _provider, address _chainlink) | |
FlashLoanReceiverBase(_provider) | |
public | |
{ | |
provider = LendingPoolAddressesProvider(_provider); | |
chainlink = _chainlink; | |
} | |
function initLoan(uint256 _amount, bytes calldata params) public { | |
LendingPool lendingPool = lendingPool(provider.getLendingPool()); | |
lendingPool.flashLoan(address(this), chainlink, _amount, _params); | |
} | |
function executeOperation( | |
address _reserve, | |
uint256 _amount, | |
uint256 _fee, | |
bytes memory _params) external { | |
//check the contract has the specified balance | |
require(_amount <= getBalanceInternal(address(this), _reserve), | |
"Invalid balance for the contract"); | |
// Buy from exchange A π° | |
// Sell on exchange B π± | |
// PROFIT!!! π€π€π€ππ | |
transferFundsBackToPoolInternal(_reserve, _amount.add(_fee)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment