Skip to content

Instantly share code, notes, and snippets.

@yuyasugano
Created September 23, 2020 10:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuyasugano/19a118e24dce91b7bb4d73b521238922 to your computer and use it in GitHub Desktop.
Save yuyasugano/19a118e24dce91b7bb4d73b521238922 to your computer and use it in GitHub Desktop.
Aave FlashLoan.sol sample for Ropsten network
pragma solidity ^0.5.0;
import "./aave/FlashLoanReceiverBase.sol";
import "./aave/ILendingPoolAddressesProvider.sol";
import "./aave/ILendingPool.sol";
contract Flashloan is FlashLoanReceiverBase {
function flashloan(address _asset, uint256 _amount) external {
bytes memory data = "";
ILendingPool lendingPool = ILendingPool(
addressesProvider.getLendingPool()
);
// invoke a flashloadn and receive a loan on this contract itself
lendingPool.flashLoan(address(this), _asset, _amount, data);
}
function executeOperation(
address _reserve,
uint256 _amount,
uint256 _fee,
bytes calldata _params
) external {
require(
_amount <= getBalanceInternal(address(this), _reserve),
"Invalid balance, was the flashload successful?"
);
// arbitrage, refinance loan, swap collaterals
// empty flashloan does nothing but transfer the funds back with fee
// Time to transfer the funds back
uint256 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