Merge branch 'fix/flash-loan-guideline' into 'master'

Refactoring flashloan folder to fit current guideline, move events to interfaces

See merge request aave-tech/protocol-v2!29
This commit is contained in:
The-3D 2020-08-21 16:31:47 +00:00
commit 704aae7dba
14 changed files with 334 additions and 341 deletions

View File

@ -16,17 +16,6 @@ import '../interfaces/ILendingPoolAddressesProvider.sol';
contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider {
mapping(bytes32 => address) private _addresses;
//events
event LendingPoolUpdated(address indexed newAddress);
event LendingPoolManagerUpdated(address indexed newAddress);
event LendingPoolConfiguratorUpdated(address indexed newAddress);
event LendingPoolLiquidationManagerUpdated(address indexed newAddress);
event EthereumAddressUpdated(address indexed newAddress);
event PriceOracleUpdated(address indexed newAddress);
event LendingRateOracleUpdated(address indexed newAddress);
event ProxyCreated(bytes32 id, address indexed newAddress);
bytes32 private constant LENDING_POOL = 'LENDING_POOL';
bytes32 private constant LENDING_POOL_CORE = 'LENDING_POOL_CORE';
bytes32 private constant LENDING_POOL_CONFIGURATOR = 'LENDING_POOL_CONFIGURATOR';

View File

@ -11,10 +11,6 @@ import '../interfaces/ILendingPoolAddressesProviderRegistry.sol';
**/
contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesProviderRegistry {
//events
event AddressesProviderRegistered(address indexed newAddress);
event AddressesProviderUnregistered(address indexed newAddress);
mapping(address => uint256) addressesProviders;
address[] addressesProvidersList;

View File

@ -14,25 +14,25 @@ abstract contract FlashLoanReceiverBase is IFlashLoanReceiver {
ILendingPoolAddressesProvider public addressesProvider;
constructor(ILendingPoolAddressesProvider _provider) public {
addressesProvider = _provider;
constructor(ILendingPoolAddressesProvider provider) public {
addressesProvider = provider;
}
receive() external payable {}
function transferFundsBackInternal(
address _reserve,
address _destination,
uint256 _amount
address reserve,
address destination,
uint256 amount
) internal {
transferInternal(_destination, _reserve, _amount);
transferInternal(destination, reserve, amount);
}
function transferInternal(
address _destination,
address _reserve,
uint256 _amount
address destination,
address reserve,
uint256 amount
) internal {
IERC20(_reserve).safeTransfer(_destination, _amount);
IERC20(reserve).safeTransfer(destination, amount);
}
}

View File

@ -9,10 +9,10 @@ pragma solidity ^0.6.8;
**/
interface IFlashLoanReceiver {
function executeOperation(
address _reserve,
address _destination,
uint256 _amount,
uint256 _fee,
bytes calldata _params
address reserve,
address destination,
uint256 amount,
uint256 fee,
bytes calldata params
) external;
}

View File

@ -6,6 +6,142 @@ import {ReserveConfiguration} from '../libraries/configuration/ReserveConfigurat
pragma experimental ABIEncoderV2;
interface ILendingPool {
/**
* @dev emitted on deposit
* @param reserve the address of the reserve
* @param user the address of the user
* @param amount the amount to be deposited
* @param referral the referral number of the action
**/
event Deposit(
address indexed reserve,
address indexed user,
uint256 amount,
uint16 indexed referral
);
/**
* @dev emitted during a withdraw action.
* @param reserve the address of the reserve
* @param user the address of the user
* @param amount the amount to be withdrawn
**/
event Withdraw(address indexed reserve, address indexed user, uint256 amount);
/**
* @dev emitted on borrow
* @param reserve the address of the reserve
* @param user the address of the user
* @param amount the amount to be deposited
* @param borrowRateMode the rate mode, can be either 1-stable or 2-variable
* @param borrowRate the rate at which the user has borrowed
* @param referral the referral number of the action
**/
event Borrow(
address indexed reserve,
address indexed user,
uint256 amount,
uint256 borrowRateMode,
uint256 borrowRate,
uint16 indexed referral
);
/**
* @dev emitted on repay
* @param reserve the address of the reserve
* @param user the address of the user for which the repay has been executed
* @param repayer the address of the user that has performed the repay action
* @param amount the amount repaid
**/
event Repay(
address indexed reserve,
address indexed user,
address indexed repayer,
uint256 amount
);
/**
* @dev emitted when a user performs a rate swap
* @param reserve the address of the reserve
* @param user the address of the user executing the swap
**/
event Swap(address indexed reserve, address indexed user, uint256 timestamp);
/**
* @dev emitted when a user enables a reserve as collateral
* @param reserve the address of the reserve
* @param user the address of the user
**/
event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user);
/**
* @dev emitted when a user disables a reserve as collateral
* @param reserve the address of the reserve
* @param user the address of the user
**/
event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user);
/**
* @dev emitted when the stable rate of a user gets rebalanced
* @param reserve the address of the reserve
* @param user the address of the user for which the rebalance has been executed
**/
event RebalanceStableBorrowRate(address indexed reserve, address indexed user);
/**
* @dev emitted when a flashloan is executed
* @param target the address of the flashLoanReceiver
* @param reserve the address of the reserve
* @param amount the amount requested
* @param totalFee the total fee on the amount
**/
event FlashLoan(
address indexed target,
address indexed reserve,
uint256 amount,
uint256 totalFee
);
/**
* @dev these events are not emitted directly by the LendingPool
* but they are declared here as the LendingPoolLiquidationManager
* is executed using a delegateCall().
* This allows to have the events in the generated ABI for LendingPool.
**/
/**
* @dev emitted when a borrow fee is liquidated
* @param collateral the address of the collateral being liquidated
* @param reserve the address of the reserve
* @param user the address of the user being liquidated
* @param feeLiquidated the total fee liquidated
* @param liquidatedCollateralForFee the amount of collateral received by the protocol in exchange for the fee
**/
event OriginationFeeLiquidated(
address indexed collateral,
address indexed reserve,
address indexed user,
uint256 feeLiquidated,
uint256 liquidatedCollateralForFee
);
/**
* @dev emitted when a borrower is liquidated
* @param collateral the address of the collateral being liquidated
* @param reserve the address of the reserve
* @param user the address of the user being liquidated
* @param purchaseAmount the total amount liquidated
* @param liquidatedCollateralAmount the amount of collateral being liquidated
* @param accruedBorrowInterest the amount of interest accrued by the borrower since the last action
* @param liquidator the address of the liquidator
* @param receiveAToken true if the liquidator wants to receive aTokens, false otherwise
**/
event LiquidationCall(
address indexed collateral,
address indexed reserve,
address indexed user,
uint256 purchaseAmount,
uint256 liquidatedCollateralAmount,
uint256 accruedBorrowInterest,
address liquidator,
bool receiveAToken
);
/**
* @dev deposits The underlying asset into the reserve. A corresponding amount of the overlying asset (aTokens)
* is minted.

View File

@ -7,6 +7,17 @@ pragma solidity ^0.6.8;
*/
interface ILendingPoolAddressesProvider {
//events
event LendingPoolUpdated(address indexed newAddress);
event LendingPoolManagerUpdated(address indexed newAddress);
event LendingPoolConfiguratorUpdated(address indexed newAddress);
event LendingPoolLiquidationManagerUpdated(address indexed newAddress);
event EthereumAddressUpdated(address indexed newAddress);
event PriceOracleUpdated(address indexed newAddress);
event LendingRateOracleUpdated(address indexed newAddress);
event ProxyCreated(bytes32 id, address indexed newAddress);
function getLendingPool() external view returns (address);
function setLendingPoolImpl(address pool) external;

View File

@ -7,6 +7,10 @@ pragma solidity ^0.6.8;
**/
interface ILendingPoolAddressesProviderRegistry {
//events
event AddressesProviderRegistered(address indexed newAddress);
event AddressesProviderUnregistered(address indexed newAddress);
function getAddressesProvidersList() external view returns (address[] memory);
function isAddressesProviderRegistered(address _provider) external view returns (uint256);

View File

@ -51,141 +51,6 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
address[] internal reservesList;
/**
* @dev emitted on deposit
* @param reserve the address of the reserve
* @param user the address of the user
* @param amount the amount to be deposited
* @param referral the referral number of the action
**/
event Deposit(
address indexed reserve,
address indexed user,
uint256 amount,
uint16 indexed referral
);
/**
* @dev emitted during a withdraw action.
* @param reserve the address of the reserve
* @param user the address of the user
* @param amount the amount to be withdrawn
**/
event Withdraw(address indexed reserve, address indexed user, uint256 amount);
/**
* @dev emitted on borrow
* @param reserve the address of the reserve
* @param user the address of the user
* @param amount the amount to be deposited
* @param borrowRateMode the rate mode, can be either 1-stable or 2-variable
* @param borrowRate the rate at which the user has borrowed
* @param referral the referral number of the action
**/
event Borrow(
address indexed reserve,
address indexed user,
uint256 amount,
uint256 borrowRateMode,
uint256 borrowRate,
uint16 indexed referral
);
/**
* @dev emitted on repay
* @param reserve the address of the reserve
* @param user the address of the user for which the repay has been executed
* @param repayer the address of the user that has performed the repay action
* @param amount the amount repaid
**/
event Repay(
address indexed reserve,
address indexed user,
address indexed repayer,
uint256 amount
);
/**
* @dev emitted when a user performs a rate swap
* @param reserve the address of the reserve
* @param user the address of the user executing the swap
**/
event Swap(address indexed reserve, address indexed user, uint256 timestamp);
/**
* @dev emitted when a user enables a reserve as collateral
* @param reserve the address of the reserve
* @param user the address of the user
**/
event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user);
/**
* @dev emitted when a user disables a reserve as collateral
* @param reserve the address of the reserve
* @param user the address of the user
**/
event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user);
/**
* @dev emitted when the stable rate of a user gets rebalanced
* @param reserve the address of the reserve
* @param user the address of the user for which the rebalance has been executed
**/
event RebalanceStableBorrowRate(address indexed reserve, address indexed user);
/**
* @dev emitted when a flashloan is executed
* @param target the address of the flashLoanReceiver
* @param reserve the address of the reserve
* @param amount the amount requested
* @param totalFee the total fee on the amount
**/
event FlashLoan(
address indexed target,
address indexed reserve,
uint256 amount,
uint256 totalFee
);
/**
* @dev these events are not emitted directly by the LendingPool
* but they are declared here as the LendingPoolLiquidationManager
* is executed using a delegateCall().
* This allows to have the events in the generated ABI for LendingPool.
**/
/**
* @dev emitted when a borrow fee is liquidated
* @param collateral the address of the collateral being liquidated
* @param reserve the address of the reserve
* @param user the address of the user being liquidated
* @param feeLiquidated the total fee liquidated
* @param liquidatedCollateralForFee the amount of collateral received by the protocol in exchange for the fee
**/
event OriginationFeeLiquidated(
address indexed collateral,
address indexed reserve,
address indexed user,
uint256 feeLiquidated,
uint256 liquidatedCollateralForFee
);
/**
* @dev emitted when a borrower is liquidated
* @param collateral the address of the collateral being liquidated
* @param reserve the address of the reserve
* @param user the address of the user being liquidated
* @param purchaseAmount the total amount liquidated
* @param liquidatedCollateralAmount the amount of collateral being liquidated
* @param accruedBorrowInterest the amount of interest accrued by the borrower since the last action
* @param liquidator the address of the liquidator
* @param receiveAToken true if the liquidator wants to receive aTokens, false otherwise
**/
event LiquidationCall(
address indexed collateral,
address indexed reserve,
address indexed user,
uint256 purchaseAmount,
uint256 liquidatedCollateralAmount,
uint256 accruedBorrowInterest,
address liquidator,
bool receiveAToken
);
/**
* @dev only lending pools configurator can use functions affected by this modifier
**/
@ -415,12 +280,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
IERC20(asset).safeTransferFrom(msg.sender, reserve.aTokenAddress, paybackAmount);
emit Repay(
asset,
_onBehalfOf,
msg.sender,
paybackAmount
);
emit Repay(asset, _onBehalfOf, msg.sender, paybackAmount);
}
/**
@ -511,10 +371,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
reserve.updateInterestRates(asset, 0, 0);
emit RebalanceStableBorrowRate(
asset,
_user
);
emit RebalanceStableBorrowRate(asset, _user);
return;
}
@ -875,18 +732,18 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
}
/**
* @dev returns the normalized income per unit of asset
* @param asset the address of the reserve
* @return the reserve normalized income
* @dev returns the normalized income per unit of asset
* @param asset the address of the reserve
* @return the reserve normalized income
*/
function getReserveNormalizedIncome(address asset) external override view returns (uint256) {
return _reserves[asset].getNormalizedIncome();
}
/**
* @dev returns the normalized variable debt per unit of asset
* @param asset the address of the reserve
* @return the reserve normalized debt
* @dev returns the normalized variable debt per unit of asset
* @param asset the address of the reserve
* @return the reserve normalized debt
*/
function getReserveNormalizedVariableDebt(address asset)
external
@ -898,11 +755,11 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
}
/**
* @dev validate if a balance decrease for an asset is allowed
* @param asset the address of the reserve
* @param user the user related to the balance decrease
* @param amount the amount being transferred/redeemed
* @return true if the balance decrease can be allowed, false otherwise
* @dev validate if a balance decrease for an asset is allowed
* @param asset the address of the reserve
* @param user the user related to the balance decrease
* @param amount the amount being transferred/redeemed
* @return true if the balance decrease can be allowed, false otherwise
*/
function balanceDecreaseAllowed(
address asset,
@ -922,16 +779,16 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
}
/**
* @dev returns the list of the initialized reserves
**/
function getReservesList() external view returns(address[] memory){
return reservesList;
* @dev returns the list of the initialized reserves
**/
function getReservesList() external view returns (address[] memory) {
return reservesList;
}
/**
* @dev returns the addresses provider
**/
function getAddressesProvider() external view returns(ILendingPoolAddressesProvider){
* @dev returns the addresses provider
**/
function getAddressesProvider() external view returns (ILendingPoolAddressesProvider) {
return addressesProvider;
}
}

View File

@ -22,84 +22,6 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
uint256 public constant UINT_MAX_VALUE = uint256(-1);
/**
* @dev emitted after aTokens are burned
* @param from the address performing the redeem
* @param value the amount to be redeemed
* @param fromBalanceIncrease the cumulated balance since the last update of the user
* @param fromIndex the last index of the user
**/
event Burn(
address indexed from,
address indexed target,
uint256 value,
uint256 fromBalanceIncrease,
uint256 fromIndex
);
/**
* @dev emitted after the mint action
* @param from the address performing the mint
* @param value the amount to be minted
* @param fromBalanceIncrease the cumulated balance since the last update of the user
* @param fromIndex the last index of the user
**/
event Mint(address indexed from, uint256 value, uint256 fromBalanceIncrease, uint256 fromIndex);
/**
* @dev emitted during the transfer action
* @param from the address from which the tokens are being transferred
* @param to the adress of the destination
* @param value the amount to be minted
* @param fromBalanceIncrease the cumulated balance since the last update of the user
* @param toBalanceIncrease the cumulated balance since the last update of the destination
* @param fromIndex the last index of the user
* @param toIndex the last index of the liquidator
**/
event BalanceTransfer(
address indexed from,
address indexed to,
uint256 value,
uint256 fromBalanceIncrease,
uint256 toBalanceIncrease,
uint256 fromIndex,
uint256 toIndex
);
/**
* @dev emitted when the accumulation of the interest
* by an user is redirected to another user
* @param from the address from which the interest is being redirected
* @param to the adress of the destination
* @param fromBalanceIncrease the cumulated balance since the last update of the user
* @param fromIndex the last index of the user
**/
event InterestStreamRedirected(
address indexed from,
address indexed to,
uint256 redirectedBalance,
uint256 fromBalanceIncrease,
uint256 fromIndex
);
/**
* @dev emitted when the redirected balance of an user is being updated
* @param targetAddress the address of which the balance is being updated
* @param targetBalanceIncrease the cumulated balance since the last update of the target
* @param targetIndex the last index of the user
* @param redirectedBalanceAdded the redirected balance being added
* @param redirectedBalanceRemoved the redirected balance being removed
**/
event RedirectedBalanceUpdated(
address indexed targetAddress,
uint256 targetBalanceIncrease,
uint256 targetIndex,
uint256 redirectedBalanceAdded,
uint256 redirectedBalanceRemoved
);
event InterestRedirectionAllowanceChanged(address indexed from, address indexed to);
address public immutable UNDERLYING_ASSET_ADDRESS;
mapping(address => uint256) private _userIndexes;

View File

@ -33,40 +33,6 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
mapping(address => UserData) private _usersData;
/**
* @dev emitted when new stable debt is minted
* @param user the address of the user
* @param amount the amount minted
* @param previousBalance the previous balance of the user
* @param currentBalance the current balance of the user
* @param balanceIncrease the debt increase since the last update
* @param newRate the rate of the debt after the minting
**/
event MintDebt(
address user,
uint256 amount,
uint256 previousBalance,
uint256 currentBalance,
uint256 balanceIncrease,
uint256 newRate
);
/**
* @dev emitted when new stable debt is burned
* @param user the address of the user
* @param amount the amount minted
* @param previousBalance the previous balance of the user
* @param currentBalance the current balance of the user
* @param balanceIncrease the debt increase since the last update
**/
event BurnDebt(
address user,
uint256 amount,
uint256 previousBalance,
uint256 currentBalance,
uint256 balanceIncrease
);
constructor(
address pool,
address underlyingAsset,

View File

@ -22,42 +22,6 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
mapping(address => uint256) private _userIndexes;
/**
* @dev emitted when new variable debt is minted
* @param user the user receiving the debt
* @param amount the amount of debt being minted
* @param previousBalance the previous balance of the user
* @param currentBalance the current balance of the user
* @param balanceIncrease the debt accumulated since the last action
* @param index the index of the user
**/
event MintDebt(
address user,
uint256 amount,
uint256 previousBalance,
uint256 currentBalance,
uint256 balanceIncrease,
uint256 index
);
/**
* @dev emitted when variable debt is burnt
* @param user the user which debt has been burned
* @param amount the amount of debt being burned
* @param previousBalance the previous balance of the user
* @param currentBalance the current balance of the user
* @param balanceIncrease the debt accumulated since the last action
* @param index the index of the user
**/
event BurnDebt(
address user,
uint256 amount,
uint256 previousBalance,
uint256 currentBalance,
uint256 balanceIncrease,
uint256 index
);
constructor(
address pool,
address underlyingAsset,

View File

@ -4,6 +4,84 @@ pragma solidity ^0.6.8;
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
interface IAToken is IERC20 {
/**
* @dev emitted after aTokens are burned
* @param from the address performing the redeem
* @param value the amount to be redeemed
* @param fromBalanceIncrease the cumulated balance since the last update of the user
* @param fromIndex the last index of the user
**/
event Burn(
address indexed from,
address indexed target,
uint256 value,
uint256 fromBalanceIncrease,
uint256 fromIndex
);
/**
* @dev emitted after the mint action
* @param from the address performing the mint
* @param value the amount to be minted
* @param fromBalanceIncrease the cumulated balance since the last update of the user
* @param fromIndex the last index of the user
**/
event Mint(address indexed from, uint256 value, uint256 fromBalanceIncrease, uint256 fromIndex);
/**
* @dev emitted during the transfer action
* @param from the address from which the tokens are being transferred
* @param to the adress of the destination
* @param value the amount to be minted
* @param fromBalanceIncrease the cumulated balance since the last update of the user
* @param toBalanceIncrease the cumulated balance since the last update of the destination
* @param fromIndex the last index of the user
* @param toIndex the last index of the liquidator
**/
event BalanceTransfer(
address indexed from,
address indexed to,
uint256 value,
uint256 fromBalanceIncrease,
uint256 toBalanceIncrease,
uint256 fromIndex,
uint256 toIndex
);
/**
* @dev emitted when the accumulation of the interest
* by an user is redirected to another user
* @param from the address from which the interest is being redirected
* @param to the adress of the destination
* @param fromBalanceIncrease the cumulated balance since the last update of the user
* @param fromIndex the last index of the user
**/
event InterestStreamRedirected(
address indexed from,
address indexed to,
uint256 redirectedBalance,
uint256 fromBalanceIncrease,
uint256 fromIndex
);
/**
* @dev emitted when the redirected balance of an user is being updated
* @param targetAddress the address of which the balance is being updated
* @param targetBalanceIncrease the cumulated balance since the last update of the target
* @param targetIndex the last index of the user
* @param redirectedBalanceAdded the redirected balance being added
* @param redirectedBalanceRemoved the redirected balance being removed
**/
event RedirectedBalanceUpdated(
address indexed targetAddress,
uint256 targetBalanceIncrease,
uint256 targetIndex,
uint256 redirectedBalanceAdded,
uint256 redirectedBalanceRemoved
);
event InterestRedirectionAllowanceChanged(address indexed from, address indexed to);
/**
* @dev redirects the interest generated to a target address.
* when the interest is redirected, the user balance is added to

View File

@ -13,6 +13,40 @@ pragma solidity ^0.6.8;
**/
interface IStableDebtToken {
/**
* @dev emitted when new stable debt is minted
* @param user the address of the user
* @param amount the amount minted
* @param previousBalance the previous balance of the user
* @param currentBalance the current balance of the user
* @param balanceIncrease the debt increase since the last update
* @param newRate the rate of the debt after the minting
**/
event MintDebt(
address user,
uint256 amount,
uint256 previousBalance,
uint256 currentBalance,
uint256 balanceIncrease,
uint256 newRate
);
/**
* @dev emitted when new stable debt is burned
* @param user the address of the user
* @param amount the amount minted
* @param previousBalance the previous balance of the user
* @param currentBalance the current balance of the user
* @param balanceIncrease the debt increase since the last update
**/
event BurnDebt(
address user,
uint256 amount,
uint256 previousBalance,
uint256 currentBalance,
uint256 balanceIncrease
);
/**
* @dev mints debt token to the target user. The resulting rate is the weighted average
* between the rate of the new debt and the rate of the previous debt

View File

@ -8,6 +8,42 @@ pragma solidity ^0.6.8;
* @dev does not inherit from IERC20 to save in contract size
**/
interface IVariableDebtToken {
/**
* @dev emitted when new variable debt is minted
* @param user the user receiving the debt
* @param amount the amount of debt being minted
* @param previousBalance the previous balance of the user
* @param currentBalance the current balance of the user
* @param balanceIncrease the debt accumulated since the last action
* @param index the index of the user
**/
event MintDebt(
address user,
uint256 amount,
uint256 previousBalance,
uint256 currentBalance,
uint256 balanceIncrease,
uint256 index
);
/**
* @dev emitted when variable debt is burnt
* @param user the user which debt has been burned
* @param amount the amount of debt being burned
* @param previousBalance the previous balance of the user
* @param currentBalance the current balance of the user
* @param balanceIncrease the debt accumulated since the last action
* @param index the index of the user
**/
event BurnDebt(
address user,
uint256 amount,
uint256 previousBalance,
uint256 currentBalance,
uint256 balanceIncrease,
uint256 index
);
/**
* @dev mints new variable debt
* @param user the user receiving the debt