Skip to content

Instantly share code, notes, and snippets.

@what-the-func
Created March 9, 2020 06:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save what-the-func/028cb78488e1d28ee1c226b758daee7e to your computer and use it in GitHub Desktop.
Save what-the-func/028cb78488e1d28ee1c226b758daee7e to your computer and use it in GitHub Desktop.
FlashLoan
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