diff --git a/contracts/configuration/LendingPoolAddressesProvider.sol b/contracts/configuration/LendingPoolAddressesProvider.sol index 7d2d3ad9..c398f578 100644 --- a/contracts/configuration/LendingPoolAddressesProvider.sol +++ b/contracts/configuration/LendingPoolAddressesProvider.sol @@ -1,10 +1,12 @@ // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.6.8; -import '@openzeppelin/contracts/access/Ownable.sol'; -import '../libraries/openzeppelin-upgradeability/InitializableAdminUpgradeabilityProxy.sol'; +import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol'; +import { + InitializableAdminUpgradeabilityProxy +} from '../libraries/openzeppelin-upgradeability/InitializableAdminUpgradeabilityProxy.sol'; -import '../interfaces/ILendingPoolAddressesProvider.sol'; +import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol'; /** * @title LendingPoolAddressesProvider contract @@ -16,17 +18,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'; diff --git a/contracts/configuration/LendingPoolAddressesProviderRegistry.sol b/contracts/configuration/LendingPoolAddressesProviderRegistry.sol index 02e0bafc..07d416f8 100644 --- a/contracts/configuration/LendingPoolAddressesProviderRegistry.sol +++ b/contracts/configuration/LendingPoolAddressesProviderRegistry.sol @@ -1,8 +1,10 @@ // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.6.8; -import '@openzeppelin/contracts/access/Ownable.sol'; -import '../interfaces/ILendingPoolAddressesProviderRegistry.sol'; +import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol'; +import { + ILendingPoolAddressesProviderRegistry +} from '../interfaces/ILendingPoolAddressesProviderRegistry.sol'; /** * @title LendingPoolAddressesProviderRegistry contract @@ -11,25 +13,21 @@ 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; /** * @dev returns if an addressesProvider is registered or not - * @param _provider the addresses provider + * @param provider the addresses provider * @return true if the addressesProvider is registered, false otherwise **/ - function isAddressesProviderRegistered(address _provider) + function isAddressesProviderRegistered(address provider) external override view returns (uint256) { - return addressesProviders[_provider]; + return addressesProviders[provider]; } /** @@ -52,35 +50,35 @@ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesP /** * @dev adds a lending pool to the list of registered lending pools - * @param _provider the pool address to be registered + * @param provider the pool address to be registered **/ - function registerAddressesProvider(address _provider, uint256 _id) public override onlyOwner { - addressesProviders[_provider] = _id; - _addToAddressesProvidersList(_provider); - emit AddressesProviderRegistered(_provider); + function registerAddressesProvider(address provider, uint256 id) external override onlyOwner { + addressesProviders[provider] = id; + _addToAddressesProvidersList(provider); + emit AddressesProviderRegistered(provider); } /** * @dev removes a lending pool from the list of registered lending pools - * @param _provider the pool address to be unregistered + * @param provider the pool address to be unregistered **/ - function unregisterAddressesProvider(address _provider) public override onlyOwner { - require(addressesProviders[_provider] > 0, 'Provider is not registered'); - addressesProviders[_provider] = 0; - emit AddressesProviderUnregistered(_provider); + function unregisterAddressesProvider(address provider) external override onlyOwner { + require(addressesProviders[provider] > 0, 'Provider is not registered'); + addressesProviders[provider] = 0; + emit AddressesProviderUnregistered(provider); } /** * @dev adds to the list of the addresses providers, if it wasn't already added before - * @param _provider the pool address to be added + * @param provider the pool address to be added **/ - function _addToAddressesProvidersList(address _provider) internal { + function _addToAddressesProvidersList(address provider) internal { for (uint256 i = 0; i < addressesProvidersList.length; i++) { - if (addressesProvidersList[i] == _provider) { + if (addressesProvidersList[i] == provider) { return; } } - addressesProvidersList.push(_provider); + addressesProvidersList.push(provider); } } diff --git a/contracts/flashloan/base/FlashLoanReceiverBase.sol b/contracts/flashloan/base/FlashLoanReceiverBase.sol index 530cf980..9bccc014 100644 --- a/contracts/flashloan/base/FlashLoanReceiverBase.sol +++ b/contracts/flashloan/base/FlashLoanReceiverBase.sol @@ -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 _transferFundsBack( - address _reserve, - address _destination, - uint256 _amount + function transferFundsBackInternal( + address reserve, + address destination, + uint256 amount ) internal { - _transfer(_destination, _reserve, _amount); + transferInternal(destination, reserve, amount); } - function _transfer( - address _destination, - address _reserve, - uint256 _amount + function transferInternal( + address destination, + address reserve, + uint256 amount ) internal { - IERC20(_reserve).safeTransfer(_destination, _amount); + IERC20(reserve).safeTransfer(destination, amount); } } diff --git a/contracts/flashloan/interfaces/IFlashLoanReceiver.sol b/contracts/flashloan/interfaces/IFlashLoanReceiver.sol index 4392c348..95fe6f3d 100644 --- a/contracts/flashloan/interfaces/IFlashLoanReceiver.sol +++ b/contracts/flashloan/interfaces/IFlashLoanReceiver.sol @@ -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; } diff --git a/contracts/interfaces/IExchangeAdapter.sol b/contracts/interfaces/IExchangeAdapter.sol index b1a0d208..90b03be5 100644 --- a/contracts/interfaces/IExchangeAdapter.sol +++ b/contracts/interfaces/IExchangeAdapter.sol @@ -12,12 +12,12 @@ interface IExchangeAdapter { uint256 toAmount ); - function approveExchange(IERC20[] calldata _tokens) external; + function approveExchange(IERC20[] calldata tokens) external; function exchange( - address _from, - address _to, - uint256 _amount, - uint256 _maxSlippage + address from, + address to, + uint256 amount, + uint256 maxSlippage ) external returns (uint256); } diff --git a/contracts/interfaces/ILendingPool.sol b/contracts/interfaces/ILendingPool.sol index 831c4fdc..43bfb554 100644 --- a/contracts/interfaces/ILendingPool.sol +++ b/contracts/interfaces/ILendingPool.sol @@ -6,115 +6,251 @@ 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. - * @param _reserve the address of the reserve - * @param _amount the amount to be deposited - * @param _referralCode integrators are assigned a referral code and can potentially receive rewards. + * @param reserve the address of the reserve + * @param amount the amount to be deposited + * @param referralCode integrators are assigned a referral code and can potentially receive rewards. **/ function deposit( - address _reserve, - uint256 _amount, - uint16 _referralCode + address reserve, + uint256 amount, + uint16 referralCode ) external; /** - * @dev withdraws the assets of _user. - * @param _reserve the address of the reserve - * @param _amount the underlying amount to be redeemed + * @dev withdraws the assets of user. + * @param reserve the address of the reserve + * @param amount the underlying amount to be redeemed **/ - function withdraw(address _reserve, uint256 _amount) external; + function withdraw(address reserve, uint256 amount) external; /** * @dev Allows users to borrow a specific amount of the reserve currency, provided that the borrower * already deposited enough collateral. - * @param _reserve the address of the reserve - * @param _amount the amount to be borrowed - * @param _interestRateMode the interest rate mode at which the user wants to borrow. Can be 0 (STABLE) or 1 (VARIABLE) + * @param reserve the address of the reserve + * @param amount the amount to be borrowed + * @param interestRateMode the interest rate mode at which the user wants to borrow. Can be 0 (STABLE) or 1 (VARIABLE) **/ function borrow( - address _reserve, - uint256 _amount, - uint256 _interestRateMode, - uint16 _referralCode + address reserve, + uint256 amount, + uint256 interestRateMode, + uint16 referralCode ) external; /** * @notice repays a borrow on the specific reserve, for the specified amount (or for the whole amount, if uint256(-1) is specified). - * @dev the target user is defined by _onBehalfOf. If there is no repayment on behalf of another account, - * _onBehalfOf must be equal to msg.sender. - * @param _reserve the address of the reserve on which the user borrowed - * @param _amount the amount to repay, or uint256(-1) if the user wants to repay everything - * @param _onBehalfOf the address for which msg.sender is repaying. + * @dev the target user is defined by onBehalfOf. If there is no repayment on behalf of another account, + * onBehalfOf must be equal to msg.sender. + * @param reserve the address of the reserve on which the user borrowed + * @param amount the amount to repay, or uint256(-1) if the user wants to repay everything + * @param onBehalfOf the address for which msg.sender is repaying. **/ function repay( - address _reserve, - uint256 _amount, - uint256 _rateMode, - address _onBehalfOf + address reserve, + uint256 amount, + uint256 rateMode, + address onBehalfOf ) external; /** * @dev borrowers can user this function to swap between stable and variable borrow rate modes. - * @param _reserve the address of the reserve on which the user borrowed - * @param _rateMode the rate mode that the user wants to swap + * @param reserve the address of the reserve on which the user borrowed + * @param rateMode the rate mode that the user wants to swap **/ - function swapBorrowRateMode(address _reserve, uint256 _rateMode) external; + function swapBorrowRateMode(address reserve, uint256 rateMode) external; /** * @dev rebalances the stable interest rate of a user if current liquidity rate > user stable rate. * this is regulated by Aave to ensure that the protocol is not abused, and the user is paying a fair * rate. Anyone can call this function. - * @param _reserve the address of the reserve - * @param _user the address of the user to be rebalanced + * @param reserve the address of the reserve + * @param user the address of the user to be rebalanced **/ - function rebalanceStableBorrowRate(address _reserve, address _user) external; + function rebalanceStableBorrowRate(address reserve, address user) external; /** * @dev allows depositors to enable or disable a specific deposit as collateral. - * @param _reserve the address of the reserve - * @param _useAsCollateral true if the user wants to user the deposit as collateral, false otherwise. + * @param reserve the address of the reserve + * @param useAsCollateral true if the user wants to user the deposit as collateral, false otherwise. **/ - function setUserUseReserveAsCollateral(address _reserve, bool _useAsCollateral) external; + function setUserUseReserveAsCollateral(address reserve, bool useAsCollateral) external; /** * @dev users can invoke this function to liquidate an undercollateralized position. - * @param _reserve the address of the collateral to liquidated - * @param _reserve the address of the principal reserve - * @param _user the address of the borrower - * @param _purchaseAmount the amount of principal that the liquidator wants to repay - * @param _receiveAToken true if the liquidators wants to receive the aTokens, false if + * @param reserve the address of the collateral to liquidated + * @param reserve the address of the principal reserve + * @param user the address of the borrower + * @param purchaseAmount the amount of principal that the liquidator wants to repay + * @param receiveAToken true if the liquidators wants to receive the aTokens, false if * he wants to receive the underlying asset directly **/ function liquidationCall( - address _collateral, - address _reserve, - address _user, - uint256 _purchaseAmount, - bool _receiveAToken + address collateral, + address reserve, + address user, + uint256 purchaseAmount, + bool receiveAToken ) external; /** * @dev allows smartcontracts to access the liquidity of the pool within one transaction, * as long as the amount taken plus a fee is returned. NOTE There are security concerns for developers of flashloan receiver contracts * that must be kept into consideration. For further details please visit https://developers.aave.com - * @param _receiver The address of the contract receiving the funds. The receiver should implement the IFlashLoanReceiver interface. - * @param _reserve the address of the principal reserve - * @param _amount the amount requested for this flashloan + * @param receiver The address of the contract receiving the funds. The receiver should implement the IFlashLoanReceiver interface. + * @param reserve the address of the principal reserve + * @param amount the amount requested for this flashloan **/ function flashLoan( - address _receiver, - address _reserve, - uint256 _amount, - bytes calldata _params + address receiver, + address reserve, + uint256 amount, + bytes calldata params ) external; /** * @dev accessory functions to fetch data from the core contract **/ - function getReserveConfigurationData(address _reserve) + function getReserveConfigurationData(address reserve) external view returns ( @@ -130,7 +266,7 @@ interface ILendingPool { bool isFreezed ); - function getReserveTokensAddresses(address _reserve) + function getReserveTokensAddresses(address reserve) external view returns ( @@ -139,7 +275,7 @@ interface ILendingPool { address variableDebtTokenAddress ); - function getReserveData(address _reserve) + function getReserveData(address reserve) external view returns ( @@ -155,7 +291,7 @@ interface ILendingPool { uint40 lastUpdateTimestamp ); - function getUserAccountData(address _user) + function getUserAccountData(address user) external view returns ( @@ -167,7 +303,7 @@ interface ILendingPool { uint256 healthFactor ); - function getUserReserveData(address _reserve, address _user) + function getUserReserveData(address reserve, address user) external view returns ( @@ -185,42 +321,42 @@ interface ILendingPool { /** * @dev initializes a reserve - * @param _reserve the address of the reserve - * @param _aTokenAddress the address of the overlying aToken contract - * @param _interestRateStrategyAddress the address of the interest rate strategy contract + * @param reserve the address of the reserve + * @param aTokenAddress the address of the overlying aToken contract + * @param interestRateStrategyAddress the address of the interest rate strategy contract **/ function initReserve( - address _reserve, - address _aTokenAddress, - address _stableDebtAddress, - address _variableDebtAddress, - address _interestRateStrategyAddress + address reserve, + address aTokenAddress, + address stableDebtAddress, + address variableDebtAddress, + address interestRateStrategyAddress ) external; /** * @dev updates the address of the interest rate strategy contract - * @param _reserve the address of the reserve - * @param _rateStrategyAddress the address of the interest rate strategy contract + * @param reserve the address of the reserve + * @param rateStrategyAddress the address of the interest rate strategy contract **/ - function setReserveInterestRateStrategyAddress(address _reserve, address _rateStrategyAddress) + function setReserveInterestRateStrategyAddress(address reserve, address rateStrategyAddress) external; - function setConfiguration(address _reserve, uint256 _configuration) external; + function setConfiguration(address reserve, uint256 configuration) external; - function getConfiguration(address _reserve) + function getConfiguration(address reserve) external view returns (ReserveConfiguration.Map memory); - function getReserveNormalizedIncome(address _reserve) external view returns (uint256); + function getReserveNormalizedIncome(address reserve) external view returns (uint256); - function getReserveNormalizedVariableDebt(address _reserve) external view returns (uint256); + function getReserveNormalizedVariableDebt(address reserve) external view returns (uint256); function balanceDecreaseAllowed( - address _reserve, - address _user, - uint256 _amount + address reserve, + address user, + uint256 amount ) external view returns (bool); function getReserves() external view returns (address[] memory); diff --git a/contracts/interfaces/ILendingPoolAddressesProvider.sol b/contracts/interfaces/ILendingPoolAddressesProvider.sol index 9978c60e..78e336f9 100644 --- a/contracts/interfaces/ILendingPoolAddressesProvider.sol +++ b/contracts/interfaces/ILendingPoolAddressesProvider.sol @@ -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; diff --git a/contracts/interfaces/ILendingPoolAddressesProviderRegistry.sol b/contracts/interfaces/ILendingPoolAddressesProviderRegistry.sol index 859fdf79..ec26dd07 100644 --- a/contracts/interfaces/ILendingPoolAddressesProviderRegistry.sol +++ b/contracts/interfaces/ILendingPoolAddressesProviderRegistry.sol @@ -7,11 +7,15 @@ 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); + function isAddressesProviderRegistered(address provider) external view returns (uint256); - function registerAddressesProvider(address _provider, uint256 _id) external; + function registerAddressesProvider(address provider, uint256 id) external; - function unregisterAddressesProvider(address _provider) external; + function unregisterAddressesProvider(address provider) external; } diff --git a/contracts/interfaces/ILendingRateOracle.sol b/contracts/interfaces/ILendingRateOracle.sol index b06a381b..a3fd1407 100644 --- a/contracts/interfaces/ILendingRateOracle.sol +++ b/contracts/interfaces/ILendingRateOracle.sol @@ -10,10 +10,10 @@ interface ILendingRateOracle { /** @dev returns the market borrow rate in ray **/ - function getMarketBorrowRate(address _asset) external view returns (uint256); + function getMarketBorrowRate(address asset) external view returns (uint256); /** @dev sets the market borrow rate. Rate value must be in ray **/ - function setMarketBorrowRate(address _asset, uint256 _rate) external; + function setMarketBorrowRate(address asset, uint256 rate) external; } diff --git a/contracts/interfaces/IPriceOracle.sol b/contracts/interfaces/IPriceOracle.sol index f81b4453..a6452d78 100644 --- a/contracts/interfaces/IPriceOracle.sol +++ b/contracts/interfaces/IPriceOracle.sol @@ -8,10 +8,10 @@ interface IPriceOracle { /*********** @dev returns the asset price in ETH */ - function getAssetPrice(address _asset) external view returns (uint256); + function getAssetPrice(address asset) external view returns (uint256); /*********** @dev sets the asset price, in wei */ - function setAssetPrice(address _asset, uint256 _price) external; + function setAssetPrice(address asset, uint256 price) external; } diff --git a/contracts/interfaces/IPriceOracleGetter.sol b/contracts/interfaces/IPriceOracleGetter.sol index a2948ed7..fdb64279 100644 --- a/contracts/interfaces/IPriceOracleGetter.sol +++ b/contracts/interfaces/IPriceOracleGetter.sol @@ -9,8 +9,8 @@ pragma solidity ^0.6.8; interface IPriceOracleGetter { /** * @dev returns the asset price in ETH - * @param _asset the address of the asset + * @param asset the address of the asset * @return the ETH price of the asset **/ - function getAssetPrice(address _asset) external view returns (uint256); + function getAssetPrice(address asset) external view returns (uint256); } diff --git a/contracts/interfaces/IReserveInterestRateStrategy.sol b/contracts/interfaces/IReserveInterestRateStrategy.sol index 2392ecdb..5d41c100 100644 --- a/contracts/interfaces/IReserveInterestRateStrategy.sol +++ b/contracts/interfaces/IReserveInterestRateStrategy.sol @@ -19,11 +19,11 @@ interface IReserveInterestRateStrategy { * */ function calculateInterestRates( - address _reserve, - uint256 _utilizationRate, - uint256 _totalBorrowsStable, - uint256 _totalBorrowsVariable, - uint256 _averageStableBorrowRate + address reserve, + uint256 utilizationRate, + uint256 totalBorrowsStable, + uint256 totalBorrowsVariable, + uint256 averageStableBorrowRate ) external view diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index e4520e56..34dc769b 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -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 **/ @@ -413,12 +278,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); } /** @@ -509,10 +369,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool { reserve.updateInterestRates(asset, 0, 0); - emit RebalanceStableBorrowRate( - asset, - _user - ); + emit RebalanceStableBorrowRate(asset, _user); return; } @@ -884,18 +741,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 @@ -907,11 +764,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, @@ -931,16 +788,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; } } diff --git a/contracts/tokenization/AToken.sol b/contracts/tokenization/AToken.sol index bd4a2c79..0deb6dc2 100644 --- a/contracts/tokenization/AToken.sol +++ b/contracts/tokenization/AToken.sol @@ -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; diff --git a/contracts/tokenization/StableDebtToken.sol b/contracts/tokenization/StableDebtToken.sol index b8021b33..318c7e04 100644 --- a/contracts/tokenization/StableDebtToken.sol +++ b/contracts/tokenization/StableDebtToken.sol @@ -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, diff --git a/contracts/tokenization/VariableDebtToken.sol b/contracts/tokenization/VariableDebtToken.sol index 87d92889..9a4ffd2c 100644 --- a/contracts/tokenization/VariableDebtToken.sol +++ b/contracts/tokenization/VariableDebtToken.sol @@ -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, diff --git a/contracts/tokenization/interfaces/IAToken.sol b/contracts/tokenization/interfaces/IAToken.sol index f4196f80..868f81dc 100644 --- a/contracts/tokenization/interfaces/IAToken.sol +++ b/contracts/tokenization/interfaces/IAToken.sol @@ -4,109 +4,187 @@ 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 * the recepient redirected balance. - * @param _to the address to which the interest will be redirected + * @param to the address to which the interest will be redirected **/ - function redirectInterestStream(address _to) external; + function redirectInterestStream(address to) external; /** - * @dev redirects the interest generated by _from to a target address. + * @dev redirects the interest generated by from to a target address. * when the interest is redirected, the user balance is added to * the recepient redirected balance. The caller needs to have allowance on * the interest redirection to be able to execute the function. - * @param _from the address of the user whom interest is being redirected - * @param _to the address to which the interest will be redirected + * @param from the address of the user whom interest is being redirected + * @param to the address to which the interest will be redirected **/ - function redirectInterestStreamOf(address _from, address _to) external; + function redirectInterestStreamOf(address from, address to) external; /** * @dev gives allowance to an address to execute the interest redirection * on behalf of the caller. - * @param _to the address to which the interest will be redirected. Pass address(0) to reset + * @param to the address to which the interest will be redirected. Pass address(0) to reset * the allowance. **/ - function allowInterestRedirectionTo(address _to) external; + function allowInterestRedirectionTo(address to) external; /** * @dev burns the aTokens and sends the equivalent amount of underlying to the target. * only lending pools can call this function - * @param _amount the amount being burned + * @param amount the amount being burned **/ function burn( - address _user, - address _underlyingTarget, - uint256 _amount + address user, + address underlyingTarget, + uint256 amount ) external; /** - * @dev mints aTokens to _user + * @dev mints aTokens to user * only lending pools can call this function - * @param _user the address receiving the minted tokens - * @param _amount the amount of tokens to mint + * @param user the address receiving the minted tokens + * @param amount the amount of tokens to mint */ - function mint(address _user, uint256 _amount) external; + function mint(address user, uint256 amount) external; /** * @dev transfers tokens in the event of a borrow being liquidated, in case the liquidators reclaims the aToken * only lending pools can call this function - * @param _from the address from which transfer the aTokens - * @param _to the destination address - * @param _value the amount to transfer + * @param from the address from which transfer the aTokens + * @param to the destination address + * @param value the amount to transfer **/ function transferOnLiquidation( - address _from, - address _to, - uint256 _value + address from, + address to, + uint256 value ) external; /** * @dev returns the principal balance of the user. The principal balance is the last * updated stored balance, which does not consider the perpetually accruing interest. - * @param _user the address of the user + * @param user the address of the user * @return the principal balance of the user **/ - function principalBalanceOf(address _user) external view returns (uint256); + function principalBalanceOf(address user) external view returns (uint256); /** * @dev Used to validate transfers before actually executing them. - * @param _user address of the user to check - * @param _amount the amount to check - * @return true if the _user can transfer _amount, false otherwise + * @param user address of the user to check + * @param amount the amount to check + * @return true if the user can transfer amount, false otherwise **/ - function isTransferAllowed(address _user, uint256 _amount) external view returns (bool); + function isTransferAllowed(address user, uint256 amount) external view returns (bool); /** * @dev returns the last index of the user, used to calculate the balance of the user - * @param _user address of the user + * @param user address of the user * @return the last user index **/ - function getUserIndex(address _user) external view returns (uint256); + function getUserIndex(address user) external view returns (uint256); /** * @dev returns the address to which the interest is redirected - * @param _user address of the user + * @param user address of the user * @return 0 if there is no redirection, an address otherwise **/ - function getInterestRedirectionAddress(address _user) external view returns (address); + function getInterestRedirectionAddress(address user) external view returns (address); /** * @dev returns the redirected balance of the user. The redirected balance is the balance * redirected by other accounts to the user, that is accrueing interest for him. - * @param _user address of the user + * @param user address of the user * @return the total redirected balance **/ - function getRedirectedBalance(address _user) external view returns (uint256); + function getRedirectedBalance(address user) external view returns (uint256); /** * @dev transfers the underlying asset to the target. Used by the lendingpool to transfer * assets in borrow(), redeem() and flashLoan() - * @param _target the target of the transfer - * @param _amount the amount to transfer + * @param target the target of the transfer + * @param amount the amount to transfer * @return the amount transferred **/ - function transferUnderlyingTo(address _target, uint256 _amount) external returns (uint256); + function transferUnderlyingTo(address target, uint256 amount) external returns (uint256); } diff --git a/contracts/tokenization/interfaces/IStableDebtToken.sol b/contracts/tokenization/interfaces/IStableDebtToken.sol index 57e8fb74..0aaccd26 100644 --- a/contracts/tokenization/interfaces/IStableDebtToken.sol +++ b/contracts/tokenization/interfaces/IStableDebtToken.sol @@ -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 diff --git a/contracts/tokenization/interfaces/IVariableDebtToken.sol b/contracts/tokenization/interfaces/IVariableDebtToken.sol index f434aa8c..fdd86a0d 100644 --- a/contracts/tokenization/interfaces/IVariableDebtToken.sol +++ b/contracts/tokenization/interfaces/IVariableDebtToken.sol @@ -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