Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickAlphaC committed Aug 4, 2021
1 parent c1a0d44 commit 01fe74a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
40 changes: 21 additions & 19 deletions contracts/v2/FlashloanV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import "../../interfaces/v2/ILendingPoolAddressesProviderV2.sol";
import "../../interfaces/v2/ILendingPoolV2.sol";

contract FlashloanV2 is FlashLoanReceiverBaseV2, Withdrawable {

constructor(address _addressProvider) FlashLoanReceiverBaseV2(_addressProvider) public {}
constructor(address _addressProvider)
public
FlashLoanReceiverBaseV2(_addressProvider)
{}

/**
* @dev This function must be called only be the LENDING_POOL and takes care of repaying
Expand All @@ -24,32 +26,29 @@ contract FlashloanV2 is FlashLoanReceiverBaseV2, Withdrawable {
uint256[] calldata premiums,
address initiator,
bytes calldata params
)
external
override
returns (bool)
{

) external override returns (bool) {
//
// This contract now has the funds requested.
// Your logic goes here.
//

// At the end of your logic above, this contract owes
// the flashloaned amounts + premiums.
// Therefore ensure your contract has enough to repay
// these amounts.

// Approve the LendingPool contract allowance to *pull* the owed amount
for (uint i = 0; i < assets.length; i++) {
uint amountOwing = amounts[i].add(premiums[i]);
for (uint256 i = 0; i < assets.length; i++) {
uint256 amountOwing = amounts[i].add(premiums[i]);
IERC20(assets[i]).approve(address(LENDING_POOL), amountOwing);
}

return true;
}

function _flashloan(address[] memory assets, uint256[] memory amounts) internal {
function _flashloan(address[] memory assets, uint256[] memory amounts)
internal
{
address receiverAddress = address(this);

address onBehalfOf = address(this);
Expand All @@ -75,18 +74,21 @@ contract FlashloanV2 is FlashLoanReceiverBaseV2, Withdrawable {
}

/*
* Flash multiple assets
* Flash multiple assets
*/
function flashloan(address[] memory assets, uint256[] memory amounts) public onlyOwner {
function flashloan(address[] memory assets, uint256[] memory amounts)
public
onlyOwner
{
_flashloan(assets, amounts);
}

/*
* Flash loan 1000000000000000000 wei (1 ether) worth of `_asset`
* Flash loan 100000000000000000 wei (0.1 ether) worth of `_asset`
*/
function flashloan(address _asset) public onlyOwner {
bytes memory data = "";
uint amount = 1 ether;
uint256 amount = 100000000000000000;

address[] memory assets = new address[](1);
assets[0] = _asset;
Expand All @@ -96,4 +98,4 @@ contract FlashloanV2 is FlashLoanReceiverBaseV2, Withdrawable {

_flashloan(assets, amounts);
}
}
}
4 changes: 2 additions & 2 deletions scripts/run_flash_loan_v2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from brownie import FlashloanV2, accounts, config, network, interface

MINIMUM_FLASHLOAN_WETH_BALANCE = 500000000000000000
MINIMUM_FLASHLOAN_WETH_BALANCE = 200000000000000000
ETHERSCAN_TX_URL = "https://kovan.etherscan.io/tx/{}"


Expand All @@ -15,7 +15,7 @@ def main():
# We need to fund it if it doesn't have any token to fund!
if weth.balanceOf(flashloan) < MINIMUM_FLASHLOAN_WETH_BALANCE:
print("Funding Flashloan contract with WETH...")
weth.transfer(flashloan, "1 ether", {"from": acct})
weth.transfer(flashloan, 2000000000000000000, {"from": acct})
print("Executing Flashloan...")
tx = flashloan.flashloan(weth, {"from": acct})
print("You did it! View your tx here: " + ETHERSCAN_TX_URL.format(tx.txid))
Expand Down

0 comments on commit 01fe74a

Please sign in to comment.