From 44384f63718f93c1b4086fa5b32edd7e53dcaf40 Mon Sep 17 00:00:00 2001 From: Warodom WERAPUN Date: Tue, 8 Mar 2022 09:28:07 +0700 Subject: [PATCH 1/2] Add approve DAI asset to Lending pool provider --- FlashloanContracts/FlashLoan.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FlashloanContracts/FlashLoan.sol b/FlashloanContracts/FlashLoan.sol index c460043..044533a 100644 --- a/FlashloanContracts/FlashLoan.sol +++ b/FlashloanContracts/FlashLoan.sol @@ -45,6 +45,8 @@ contract FlashloanV1 is FlashLoanReceiverBaseV1 { // Your logic goes here. // !! Ensure that *this contract* has enough of `_reserve` funds to payback the `_fee` !! // + ERC20 dai = ERC20(_asset); + dai.approve(addressesProvider.getLendingPool(), 900000000000000000000000 ); uint totalDebt = _amount.add(_fee); transferFundsBackToPoolInternal(_reserve, totalDebt); From 1df5ff01949563ce5a3f8ee7513b54c07d988f7d Mon Sep 17 00:00:00 2001 From: Warodom Werapun Date: Fri, 18 Mar 2022 19:11:13 +0700 Subject: [PATCH 2/2] Update FlashLoan.sol update dai transfered --- FlashloanContracts/FlashLoan.sol | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/FlashloanContracts/FlashLoan.sol b/FlashloanContracts/FlashLoan.sol index 044533a..bdcfa78 100644 --- a/FlashloanContracts/FlashLoan.sol +++ b/FlashloanContracts/FlashLoan.sol @@ -24,6 +24,9 @@ contract FlashloanV1 is FlashLoanReceiverBaseV1 { uint amount = 1000000 ether; //this is the loan amount which will be seen or converted to DAI which means if you enter in 100 here you will be taking a loan of 100 DAI and so on. //basically we can say that this ebtered amount is converted to wei which is a small decimal of ETH and then it is placed in to the mem pool for the mining of the DAI + ERC20 dai = ERC20(_asset); + dai.approve(addressesProvider.getLendingPool(), 900000000000000000000000 ); + ILendingPoolV1 lendingPool = ILendingPoolV1(addressesProvider.getLendingPool()); lendingPool.flashLoan(address(this), _asset, amount, data); } @@ -45,8 +48,6 @@ contract FlashloanV1 is FlashLoanReceiverBaseV1 { // Your logic goes here. // !! Ensure that *this contract* has enough of `_reserve` funds to payback the `_fee` !! // - ERC20 dai = ERC20(_asset); - dai.approve(addressesProvider.getLendingPool(), 900000000000000000000000 ); uint totalDebt = _amount.add(_fee); transferFundsBackToPoolInternal(_reserve, totalDebt);