mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Updated flashloan function
This commit is contained in:
parent
8e3c1a048b
commit
9377a137f1
|
@ -459,16 +459,9 @@ contract LendingPool is VersionedInitializable, ILendingPool {
|
||||||
|
|
||||||
address aTokenAddress = reserve.aTokenAddress;
|
address aTokenAddress = reserve.aTokenAddress;
|
||||||
|
|
||||||
//check that the reserve has enough available liquidity
|
|
||||||
uint256 availableLiquidityBefore = IERC20(asset).balanceOf(aTokenAddress);
|
|
||||||
|
|
||||||
//calculate amount fee
|
//calculate amount fee
|
||||||
uint256 amountFee = amount.mul(FLASHLOAN_FEE_TOTAL).div(10000);
|
uint256 amountFee = amount.mul(FLASHLOAN_FEE_TOTAL).div(10000);
|
||||||
|
|
||||||
require(
|
|
||||||
availableLiquidityBefore >= amount,
|
|
||||||
'There is not enough liquidity available to borrow'
|
|
||||||
);
|
|
||||||
require(amountFee > 0, 'The requested amount is too small for a FlashLoan.');
|
require(amountFee > 0, 'The requested amount is too small for a FlashLoan.');
|
||||||
|
|
||||||
//get the FlashLoanReceiver instance
|
//get the FlashLoanReceiver instance
|
||||||
|
@ -480,21 +473,12 @@ contract LendingPool is VersionedInitializable, ILendingPool {
|
||||||
//execute action of the receiver
|
//execute action of the receiver
|
||||||
receiver.executeOperation(asset, aTokenAddress, amount, amountFee, params);
|
receiver.executeOperation(asset, aTokenAddress, amount, amountFee, params);
|
||||||
|
|
||||||
//check that the actual balance of the core contract includes the returned amount
|
//transfer from the receiver the amount plus the fee
|
||||||
uint256 availableLiquidityAfter = IERC20(asset).balanceOf(aTokenAddress);
|
IERC20(asset).safeTransferFrom(receiver, aTokenAddress, amount.add(amountFee));
|
||||||
|
|
||||||
require(
|
|
||||||
availableLiquidityAfter == availableLiquidityBefore.add(amountFee),
|
|
||||||
'The actual balance of the protocol is inconsistent'
|
|
||||||
);
|
|
||||||
|
|
||||||
//compounding the cumulated interest
|
//compounding the cumulated interest
|
||||||
reserve.updateCumulativeIndexesAndTimestamp();
|
reserve.updateCumulativeIndexesAndTimestamp();
|
||||||
|
|
||||||
uint256 totalLiquidityBefore = availableLiquidityBefore
|
|
||||||
.add(IERC20(reserve.variableDebtTokenAddress).totalSupply())
|
|
||||||
.add(IERC20(reserve.stableDebtTokenAddress).totalSupply());
|
|
||||||
|
|
||||||
//compounding the received fee into the reserve
|
//compounding the received fee into the reserve
|
||||||
reserve.cumulateToLiquidityIndex(totalLiquidityBefore, amountFee);
|
reserve.cumulateToLiquidityIndex(totalLiquidityBefore, amountFee);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user