Skip to content

Instantly share code, notes, and snippets.

@BeneCollyridam
Created August 10, 2020 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BeneCollyridam/63411f2d4a564fc3358b1d98964c8779 to your computer and use it in GitHub Desktop.
Save BeneCollyridam/63411f2d4a564fc3358b1d98964c8779 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.12+commit.27d51765.js&optimize=false&gist=
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.6;
import "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/FlashLoanReceiverBase.sol";
import "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/ILendingPoolAddressesProvider.sol";
import "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/ILendingPool.sol";
/**
* @title Gordon
* @dev Utilizes Flash loans to get free money
*/
contract Gordon is FlashLoanReceiverBase {
constructor(address _addressProvider) FlashLoanReceiverBase(_addressProvider) public {}
// Kovan
// address private lendingPool = 0x506B0B2CF20FAA8f38a4E2B524EE43e1f4458Cc5;
// Mainnet
// address private lendingPool = 0x24a42fD28C976A61Df5D00D0599C34c4f90748c8;
/**
Flash loan 1000000000000000000 wei (1 ether) worth of `_asset`
*/
function flashloan(address _asset, bytes memory data) public onlyOwner {
uint amount = 1 ether;
ILendingPool lendingPool = ILendingPool(addressesProvider.getLendingPool());
lendingPool.flashLoan(address(this), _asset, amount, data);
}
function executeOperation(
address _reserve,
uint256 _amount,
uint256 _fee,
bytes memory _params
) external override {
require(_amount <= getBalanceInternal(address(this), _reserve), "Invalid balance, was the flashLoan successful?");
// Earn some money
for (uint i = 0; i < _params.length; i++) {
uint8 instruction = uint8(_params[i]);
// Do something with the instruction
}
// Pay back the loan :(
uint totalDebt = _amount.add(_fee);
transferFundsBackToPoolInternal(_reserve, totalDebt);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment