From f98335cb68e95003b114d31b20218e903c1b5b58 Mon Sep 17 00:00:00 2001 From: eboado Date: Mon, 23 Nov 2020 10:58:04 +0100 Subject: [PATCH] - Improved docs on LendingPool and interface --- contracts/interfaces/ILendingPool.sol | 340 ++++++++++-------- .../ILendingPoolAddressesProvider.sol | 1 - contracts/lendingpool/LendingPool.sol | 288 ++++++++------- .../LendingPoolCollateralManager.sol | 20 +- ...LendingPoolHarnessForVariableDebtToken.sol | 4 +- 5 files changed, 355 insertions(+), 298 deletions(-) diff --git a/contracts/interfaces/ILendingPool.sol b/contracts/interfaces/ILendingPool.sol index 17be57994..8efc8d035 100644 --- a/contracts/interfaces/ILendingPool.sol +++ b/contracts/interfaces/ILendingPool.sol @@ -1,20 +1,20 @@ // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.6.8; +pragma experimental ABIEncoderV2; import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol'; import {UserConfiguration} from '../libraries/configuration/UserConfiguration.sol'; import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol'; import {ILendingPoolAddressesProvider} from './ILendingPoolAddressesProvider.sol'; -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 + * @dev Emitted on deposit() + * @param reserve The address of the underlying asset of the reserve + * @param user The address initiating the deposit + * @param onBehalfOf The beneficiary of the deposit, receiving the aTokens + * @param amount The amount deposited + * @param referral The referral code used **/ event Deposit( address indexed reserve, @@ -25,22 +25,24 @@ interface ILendingPool { ); /** - * @dev emitted during a withdraw action. - * @param reserve the address of the reserve - * @param user the address of the user - * @param to address that will receive the underlying - * @param amount the amount to be withdrawn + * @dev Emitted on withdraw() + * @param reserve The address of the underlyng asset being withdrawn + * @param user The address initiating the withdrawal, owner of aTokens + * @param to Address that will receive the underlying + * @param amount The amount to be withdrawn **/ event Withdraw(address indexed reserve, address indexed user, address indexed to, 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 + * @dev Emitted on borrow() and flashLoan() when debt needs to be opened + * @param reserve The address of the underlying asset being borrowed + * @param user The address of the user initiating the borrow(), receiving the funds on borrow() or just + * initiator of the transaction on flashLoan() + * @param onBehalfOf The address that will be getting the debt + * @param amount The amount borrowed out + * @param borrowRateMode The rate mode: 1 for Stable, 2 for Variable + * @param borrowRate The numeric rate at which the user has borrowed + * @param referral The referral code used **/ event Borrow( address indexed reserve, @@ -51,12 +53,13 @@ interface ILendingPool { 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 + * @dev Emitted on repay() + * @param reserve The address of the underlying asset of the reserve + * @param user The beneficiary of the repayment, getting his debt reduced + * @param repayer The address of the user initiating the repay(), providing the funds + * @param amount The amount repaid **/ event Repay( address indexed reserve, @@ -64,41 +67,44 @@ interface ILendingPool { 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 + * @dev Emitted on swapBorrowRateMode() + * @param reserve The address of the underlying asset of the reserve + * @param user The address of the user swapping his rate mode + * @param rateMode The rate mode that the user wants to swap to **/ event Swap(address indexed reserve, address indexed user, uint256 rateMode); /** - * @dev emitted when a user enables a reserve as collateral - * @param reserve the address of the reserve - * @param user the address of the user + * @dev Emitted on setUserUseReserveAsCollateral() + * @param reserve The address of the underlying asset of the reserve + * @param user The address of the user enabling the usage as collateral **/ 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 + * @dev Emitted on setUserUseReserveAsCollateral() + * @param reserve The address of the underlying asset of the reserve + * @param user The address of the user enabling the usage as collateral **/ 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 + * @dev Emitted on rebalanceStableBorrowRate() + * @param reserve The address of the underlying asset 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 initiator the address initiating the flash loan - * @param asset the address of the asset being flashborrowed - * @param amount the amount requested - * @param premium the total fee on the amount - * @param referralCode the referral code of the caller + * @dev Emitted on flashLoan() + * @param target The address of the flash loan receiver contract + * @param initiator The address initiating the flash loan + * @param asset The address of the asset being flash borrowed + * @param amount The amount flash borrowed + * @param premium The fee flash borrowed + * @param referralCode The referral code used **/ event FlashLoan( address indexed target, @@ -120,23 +126,23 @@ interface ILendingPool { event Unpaused(); /** - * @dev emitted when a borrower is liquidated. Thos evemt is emitted directly by the LendingPool - * but it's declared here as the LendingPoolCollateralManager - * is executed using a delegateCall(). + * @dev Emitted when a borrower is liquidated. This event is emitted by the LendingPool via + * LendingPoolCollateral manager using a DELEGATECALL * This allows to have the events in the generated ABI for LendingPool. - * @param collateral the address of the collateral being liquidated - * @param principal 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 liquidator the address of the liquidator - * @param receiveAToken true if the liquidator wants to receive aTokens, false otherwise + * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation + * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation + * @param user The address of the borrower getting liquidated + * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover + * @param liquidatedCollateralAmount The amount of collateral received by the liiquidator + * @param liquidator The address of the liquidator + * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants + * to receive the underlying collateral asset directly **/ event LiquidationCall( - address indexed collateral, - address indexed principal, + address indexed collateralAsset, + address indexed debtAsset, address indexed user, - uint256 purchaseAmount, + uint256 debtToCover, uint256 liquidatedCollateralAmount, address liquidator, bool receiveAToken @@ -147,12 +153,12 @@ interface ILendingPool { * in the ReserveLogic library and emitted in the updateInterestRates() function. Since the function is internal, * the event will actually be fired by the LendingPool contract. The event is therefore replicated here so it * gets added to the LendingPool ABI - * @param reserve the address of the reserve - * @param liquidityRate the new liquidity rate - * @param stableBorrowRate the new stable borrow rate - * @param variableBorrowRate the new variable borrow rate - * @param liquidityIndex the new liquidity index - * @param variableBorrowIndex the new variable borrow index + * @param reserve The address of the underlying asset of the reserve + * @param liquidityRate The new liquidity rate + * @param stableBorrowRate The new stable borrow rate + * @param variableBorrowRate The new variable borrow rate + * @param liquidityIndex The new liquidity index + * @param variableBorrowIndex The new variable borrow index **/ event ReserveDataUpdated( address indexed reserve, @@ -164,40 +170,56 @@ interface ILendingPool { ); /** - * @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. + * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens. + * - E.g. User deposits 100 USDC and gets in return 100 aUSDC + * @param asset The address of the underlying asset to deposit + * @param amount The amount to be deposited + * @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user + * wants to receive them on his own wallet, or a different address if the beneficiary of aTokens + * is a different wallet + * @param referralCode Code used to register the integrator originating the operation, for potential rewards. + * 0 if the action is executed directly by the user, without any middle-man **/ function deposit( - address reserve, + address asset, uint256 amount, address onBehalfOf, uint16 referralCode ) external; /** - * @dev withdraws the assets of user. - * @param reserve the address of the reserve - * @param amount the underlying amount to be redeemed - * @param to address that will receive the underlying + * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned + * E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC + * @param asset The address of the underlying asset to withdraw + * @param amount The underlying amount to be withdrawn + * - Send the value type(uint256).max in order to withdraw the whole aToken balance + * @param to Address that will receive the underlying, same as msg.sender if the user + * wants to receive it on his own wallet, or a different address if the beneficiary is a + * different wallet **/ function withdraw( - address reserve, + address asset, uint256 amount, address to ) 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) + * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower + * already deposited enough collateral, or he was given enough allowance by a credit delegator on the + * corresponding debt token (StableDebtToken or VariableDebtToken) + * - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet + * and 100 stable/variable debt tokens, depending on the `interestRateMode` + * @param asset The address of the underlying asset to borrow + * @param amount The amount to be borrowed + * @param interestRateMode The interest rate mode at which the user wants to borrow: 1 for Stable, 2 for Variable + * @param referralCode Code used to register the integrator originating the operation, for potential rewards. + * 0 if the action is executed directly by the user, without any middle-man + * @param onBehalfOf Address of the user who will receive the debt. Should be the address of the borrower itself + * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator + * if he has been given credit delegation allowance **/ function borrow( - address reserve, + address asset, uint256 amount, uint256 interestRateMode, uint16 referralCode, @@ -205,73 +227,86 @@ interface ILendingPool { ) 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. + * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned + * - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address + * @param asset The address of the borrowed underlying asset previously borrowed + * @param amount The amount to repay + * - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode` + * @param rateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable + * @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the + * user calling the function if he wants to reduce/remove his own debt, or the address of any other + * other borrower whose debt should be removed **/ function repay( - address reserve, + address asset, 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 + * @dev Allows a borrower to swap his debt between stable and variable mode, or viceversa + * @param asset The address of the underlying asset borrowed + * @param rateMode The rate mode that the user wants to swap to **/ - function swapBorrowRateMode(address reserve, uint256 rateMode) external; + function swapBorrowRateMode(address asset, 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 + * @dev Rebalances the stable interest rate of a user to the current stable rate defined on the reserve. + * - Users can be rebalanced if the following conditions are satisfied: + * 1. Usage ratio is above 95% + * 2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been + * borrowed at a stable rate and depositors are not earning enough + * @param asset The address of the underlying asset borrowed + * @param user The address of the user to be rebalanced **/ - function rebalanceStableBorrowRate(address reserve, address user) external; + function rebalanceStableBorrowRate(address asset, 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. + * @dev Allows depositors to enable/disable a specific deposited asset as collateral + * @param asset The address of the underlying asset deposited + * @param useAsCollateral `true` if the user wants to use the deposit as collateral, `false` otherwise **/ - function setUserUseReserveAsCollateral(address reserve, bool useAsCollateral) external; + function setUserUseReserveAsCollateral(address asset, 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 - * he wants to receive the underlying asset directly + * @dev Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1 + * - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives + * a proportionally amount of the `collateralAsset` plus a bonus to cover market risk + * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation + * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation + * @param user The address of the borrower getting liquidated + * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover + * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants + * to receive the underlying collateral asset directly **/ function liquidationCall( - address collateral, - address reserve, + address collateralAsset, + address debtAsset, address user, - uint256 purchaseAmount, + uint256 debtToCover, 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 assets the address of the principal reserve - * @param amounts the amount requested for this flashloan - * @param modes the flashloan borrow modes - * @param params a bytes array to be sent to the flashloan executor - * @param referralCode the referral code of the caller + * @dev Allows smartcontracts to access the liquidity of the pool within one transaction, + * as long as the amount taken plus a fee is returned. + * IMPORTANT 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 receiverAddress The address of the contract receiving the funds, implementing the IFlashLoanReceiver interface + * @param assets The addresses of the assets being flash-borrowed + * @param amounts The amounts amounts being flash-borrowed + * @param modes Types of the debt to open if the flash loan is not returned: + * 0 -> Don't open any debt, just revert if funds can't be transferred from the receiver + * 1 -> Open debt at stable rate for the value of the amount flash-borrowed to the `onBehalfOf` address + * 2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address + * @param onBehalfOf The address that will receive the debt in the case of using on `modes` 1 or 2 + * @param params Variadic packed params to pass to the receiver as extra information + * @param referralCode Code used to register the integrator originating the operation, for potential rewards. + * 0 if the action is executed directly by the user, without any middle-man **/ function flashLoan( - address receiver, + address receiverAddress, address[] calldata assets, uint256[] calldata amounts, uint256[] calldata modes, @@ -280,24 +315,28 @@ interface ILendingPool { uint16 referralCode ) external; + /** + * @dev Returns the user account data across all the reserves + * @param user The address of the user + * @return totalCollateralETH the total collateral in ETH of the user + * @return totalDebtETH the total debt in ETH of the user + * @return availableBorrowsETH the borrowing power left of the user + * @return currentLiquidationThreshold the liquidation threshold of the user + * @return ltv the loan to value of the user + * @return healthFactor the current health factor of the user + **/ function getUserAccountData(address user) external view returns ( uint256 totalCollateralETH, - uint256 totalBorrowsETH, + uint256 totalDebtETH, uint256 availableBorrowsETH, uint256 currentLiquidationThreshold, uint256 ltv, uint256 healthFactor ); - /** - * @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 - **/ function initReserve( address reserve, address aTokenAddress, @@ -306,28 +345,44 @@ interface ILendingPool { 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 - **/ - function setReserveInterestRateStrategyAddress(address reserve, address rateStrategyAddress) external; function setConfiguration(address reserve, uint256 configuration) external; - function getConfiguration(address reserve) - external - view - returns (ReserveConfiguration.Map memory); + /** + * @dev Returns the configuration of the reserve + * @param asset The address of the underlying asset of the reserve + * @return The configuration of the reserve + **/ + function getConfiguration(address asset) external view returns (ReserveConfiguration.Map memory); + /** + * @dev Returns the configuration of the user across all the reserves + * @param user The user address + * @return The configuration of the user + **/ function getUserConfiguration(address user) external view returns (UserConfiguration.Map memory); - function getReserveNormalizedIncome(address reserve) external view returns (uint256); + /** + * @dev Returns the normalized income normalized income of the reserve + * @param asset The address of the underlying asset of the reserve + * @return The reserve's normalized income + */ + function getReserveNormalizedIncome(address asset) external view returns (uint256); - function getReserveNormalizedVariableDebt(address reserve) external view returns (uint256); + /** + * @dev Returns the normalized variable debt per unit of asset + * @param asset The address of the underlying asset of the reserve + * @return The reserve normalized variable debt + */ + function getReserveNormalizedVariableDebt(address asset) external view returns (uint256); + /** + * @dev Returns the state and configuration of the reserve + * @param asset The address of the underlying asset of the reserve + * @return The state of the reserve + **/ function getReserveData(address asset) external view returns (ReserveLogic.ReserveData memory); function finalizeTransfer( @@ -343,14 +398,7 @@ interface ILendingPool { function getAddressesProvider() external view returns (ILendingPoolAddressesProvider); - /** - * @dev Set the _pause state - * @param val the boolean value to set the current pause state of LendingPool - */ function setPause(bool val) external; - /** - * @dev Returns if the LendingPool is paused - */ function paused() external view returns (bool); } diff --git a/contracts/interfaces/ILendingPoolAddressesProvider.sol b/contracts/interfaces/ILendingPoolAddressesProvider.sol index 092bf72b5..b6a17f4b4 100644 --- a/contracts/interfaces/ILendingPoolAddressesProvider.sol +++ b/contracts/interfaces/ILendingPoolAddressesProvider.sol @@ -14,7 +14,6 @@ interface ILendingPoolAddressesProvider { event EmergencyAdminUpdated(address indexed newAddress); event LendingPoolConfiguratorUpdated(address indexed newAddress); event LendingPoolCollateralManagerUpdated(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); diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 54015687d..61ae891cc 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -18,9 +18,8 @@ import {ReserveConfiguration} from '../libraries/configuration/ReserveConfigurat import {UserConfiguration} from '../libraries/configuration/UserConfiguration.sol'; import {IStableDebtToken} from '../tokenization/interfaces/IStableDebtToken.sol'; import {IVariableDebtToken} from '../tokenization/interfaces/IVariableDebtToken.sol'; -import {DebtTokenBase} from '../tokenization/base/DebtTokenBase.sol'; import {IFlashLoanReceiver} from '../flashloan/interfaces/IFlashLoanReceiver.sol'; -import {LendingPoolCollateralManager} from './LendingPoolCollateralManager.sol'; +import {LendingPoolCollateralManager} from './LendingPoolCollateralManager.sol'; // TODO change to interface import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol'; import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol'; import {ILendingPool} from '../interfaces/ILendingPool.sol'; @@ -29,7 +28,19 @@ import {Address} from '../dependencies/openzeppelin/contracts/Address.sol'; /** * @title LendingPool contract - * @notice Implements the actions of the LendingPool, and exposes accessory methods to fetch the users and reserve data + * @dev Main point of interaction with an Aave protocol's market + * - Users can: + * # Deposit + * # Withdraw + * # Borrow + * # Repay + * # Swap their loans between variable and stable rate + * # Enable/disable their deposits as collateral rebalance stable rate borrow positions + * # Liquidate positions + * # Execute Flash Loans + * - To be covered by a proxy contract, owned by the LendingPoolAddressesProvider of the specific Aave market + * - All admin functions are callable by the LendingPoolConfigurator contract defined also in the + * LendingPoolAddressesProvider * @author Aave **/ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage { @@ -44,25 +55,20 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage uint256 public constant MAX_NUMBER_RESERVES = 128; uint256 public constant LENDINGPOOL_REVISION = 0x2; - /** - * @dev functions marked by this modifier can only be called when the protocol is not paused - **/ modifier whenNotPaused() { _whenNotPaused(); _; } - /** - * @dev functions marked by this modifier can only be called by the LendingPoolConfigurator - **/ modifier onlyLendingPoolConfigurator() { _onlyLendingPoolConfigurator(); _; } - /** - * @dev only lending pools configurator can use functions affected by this modifier - **/ + function _whenNotPaused() internal view { + require(!_paused, Errors.LP_IS_PAUSED); + } + function _onlyLendingPoolConfigurator() internal view { require( _addressesProvider.getLendingPoolConfigurator() == msg.sender, @@ -70,36 +76,31 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage ); } - /** - * @dev Function to make a function callable only when the contract is not paused. - * - * Requirements: - * - * - The contract must not be paused. - */ - function _whenNotPaused() internal view { - require(!_paused, Errors.LP_IS_PAUSED); - } - function getRevision() internal override pure returns (uint256) { return LENDINGPOOL_REVISION; } /** - * @dev this function is invoked by the proxy contract when the LendingPool contract is added to the - * AddressesProvider. - * @param provider the address of the LendingPoolAddressesProvider registry + * @dev Function is invoked by the proxy contract when the LendingPool contract is added to the + * LendingPoolAddressesProvider of the market. + * - Caching the address of the LendingPoolAddressesProvider in order to reduce gas consumption + * on subsequent operations + * @param provider The address of the LendingPoolAddressesProvider **/ function initialize(ILendingPoolAddressesProvider provider) public initializer { _addressesProvider = provider; } /** - * @dev deposits The underlying asset into the reserve. A corresponding amount of the overlying asset (aTokens) - * is minted. - * @param asset 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. + * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens. + * - E.g. User deposits 100 USDC and gets in return 100 aUSDC + * @param asset The address of the underlying asset to deposit + * @param amount The amount to be deposited + * @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user + * wants to receive them on his own wallet, or a different address if the beneficiary of aTokens + * is a different wallet + * @param referralCode Code used to register the integrator originating the operation, for potential rewards. + * 0 if the action is executed directly by the user, without any middle-man **/ function deposit( address asset, @@ -123,17 +124,20 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage emit ReserveUsedAsCollateralEnabled(asset, onBehalfOf); } - //transfer to the aToken contract IERC20(asset).safeTransferFrom(msg.sender, aToken, amount); emit Deposit(asset, msg.sender, onBehalfOf, amount, referralCode); } /** - * @dev withdraws the _reserves of user. - * @param asset the address of the reserve - * @param amount the underlying amount to be redeemed - * @param to address that will receive the underlying + * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned + * E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC + * @param asset The address of the underlying asset to withdraw + * @param amount The underlying amount to be withdrawn + * - Send the value type(uint256).max in order to withdraw the whole aToken balance + * @param to Address that will receive the underlying, same as msg.sender if the user + * wants to receive it on his own wallet, or a different address if the beneficiary is a + * different wallet **/ function withdraw( address asset, @@ -148,7 +152,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage uint256 amountToWithdraw = amount; - //if amount is equal to uint(-1), the user wants to redeem everything if (amount == type(uint256).max) { amountToWithdraw = userBalance; } @@ -179,16 +182,19 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev Allows users to borrow a specific amount of the reserve underlying asset, provided that the borrower + * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower * already deposited enough collateral, or he was given enough allowance by a credit delegator on the * corresponding debt token (StableDebtToken or VariableDebtToken) - * @param asset 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: 1 for Stable, 2 for Variable - * @param referralCode a referral code for integrators - * @param onBehalfOf address of the user who will receive the debt. Should be the address of the borrower itself + * - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet + * and 100 stable/variable debt tokens, depending on the `interestRateMode` + * @param asset The address of the underlying asset to borrow + * @param amount The amount to be borrowed + * @param interestRateMode The interest rate mode at which the user wants to borrow: 1 for Stable, 2 for Variable + * @param referralCode Code used to register the integrator originating the operation, for potential rewards. + * 0 if the action is executed directly by the user, without any middle-man + * @param onBehalfOf Address of the user who will receive the debt. Should be the address of the borrower itself * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator - * if he has been given credit delegation allowance + * if he has been given credit delegation allowance **/ function borrow( address asset, @@ -214,12 +220,15 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @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 asset 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. + * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned + * - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address + * @param asset The address of the borrowed underlying asset previously borrowed + * @param amount The amount to repay + * - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode` + * @param rateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable + * @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the + * user calling the function if he wants to reduce/remove his own debt, or the address of any other + * other borrower whose debt should be removed **/ function repay( address asset, @@ -242,7 +251,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage variableDebt ); - //default to max amount uint256 paybackAmount = interestRateMode == ReserveLogic.InterestRateMode.STABLE ? stableDebt : variableDebt; @@ -253,7 +261,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage reserve.updateState(); - //burns an equivalent amount of debt tokens if (interestRateMode == ReserveLogic.InterestRateMode.STABLE) { IStableDebtToken(reserve.stableDebtTokenAddress).burn(onBehalfOf, paybackAmount); } else { @@ -277,9 +284,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev borrowers can user this function to swap between stable and variable borrow rate modes. - * @param asset the address of the reserve on which the user borrowed - * @param rateMode the rate mode that the user wants to swap + * @dev Allows a borrower to swap his debt between stable and variable mode, or viceversa + * @param asset The address of the underlying asset borrowed + * @param rateMode The rate mode that the user wants to swap to **/ function swapBorrowRateMode(address asset, uint256 rateMode) external override whenNotPaused { ReserveLogic.ReserveData storage reserve = _reserves[asset]; @@ -299,7 +306,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage reserve.updateState(); if (interestRateMode == ReserveLogic.InterestRateMode.STABLE) { - //burn stable rate tokens, mint variable rate tokens IStableDebtToken(reserve.stableDebtTokenAddress).burn(msg.sender, stableDebt); IVariableDebtToken(reserve.variableDebtTokenAddress).mint( msg.sender, @@ -308,7 +314,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage reserve.variableBorrowIndex ); } else { - //do the opposite IVariableDebtToken(reserve.variableDebtTokenAddress).burn( msg.sender, variableDebt, @@ -328,12 +333,13 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev rebalances the stable interest rate of a user. Users can be rebalanced if the following conditions are satisfied: - * 1. Usage ratio is above 95% - * 2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been - * borrowed at a stable rate and depositors are not earning enough. - * @param asset the address of the reserve - * @param user the address of the user to be rebalanced + * @dev Rebalances the stable interest rate of a user to the current stable rate defined on the reserve. + * - Users can be rebalanced if the following conditions are satisfied: + * 1. Usage ratio is above 95% + * 2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been + * borrowed at a stable rate and depositors are not earning enough + * @param asset The address of the underlying asset borrowed + * @param user The address of the user to be rebalanced **/ function rebalanceStableBorrowRate(address asset, address user) external override whenNotPaused { ReserveLogic.ReserveData storage reserve = _reserves[asset]; @@ -368,9 +374,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev allows depositors to enable or disable a specific deposit as collateral. - * @param asset the address of the reserve - * @param useAsCollateral true if the user wants to use the deposit as collateral, false otherwise. + * @dev Allows depositors to enable/disable a specific deposited asset as collateral + * @param asset The address of the underlying asset deposited + * @param useAsCollateral `true` if the user wants to use the deposit as collateral, `false` otherwise **/ function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external @@ -400,19 +406,21 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev users can invoke this function to liquidate an undercollateralized position. - * @param asset the address of the collateral to liquidated - * @param asset 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 + * @dev Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1 + * - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives + * a proportionally amount of the `collateralAsset` plus a bonus to cover market risk + * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation + * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation + * @param user The address of the borrower getting liquidated + * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover + * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants + * to receive the underlying collateral asset directly **/ function liquidationCall( - address collateral, - address asset, + address collateralAsset, + address debtAsset, address user, - uint256 purchaseAmount, + uint256 debtToCover, bool receiveAToken ) external override whenNotPaused { address collateralManager = _addressesProvider.getLendingPoolCollateralManager(); @@ -421,10 +429,10 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage (bool success, bytes memory result) = collateralManager.delegatecall( abi.encodeWithSignature( 'liquidationCall(address,address,address,uint256,bool)', - collateral, - asset, + collateralAsset, + debtAsset, user, - purchaseAmount, + debtToCover, receiveAToken ) ); @@ -448,16 +456,21 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @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 receiverAddress The address of the contract receiving the funds. The receiver should implement the IFlashLoanReceiver interface. - * @param assets The addresss of the assets being flashborrowed - * @param amounts The amounts requested for this flashloan for each asset - * @param modes Types of the debt to open if the flash loan is not returned. 0 -> Don't open any debt, just revert, 1 -> stable, 2 -> variable - * @param onBehalfOf If mode is not 0, then the address to take the debt onBehalfOf. The onBehalfOf address must already have approved `msg.sender` to incur the debt on their behalf. + * @dev Allows smartcontracts to access the liquidity of the pool within one transaction, + * as long as the amount taken plus a fee is returned. + * IMPORTANT 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 receiverAddress The address of the contract receiving the funds, implementing the IFlashLoanReceiver interface + * @param assets The addresses of the assets being flash-borrowed + * @param amounts The amounts amounts being flash-borrowed + * @param modes Types of the debt to open if the flash loan is not returned: + * 0 -> Don't open any debt, just revert if funds can't be transferred from the receiver + * 1 -> Open debt at stable rate for the value of the amount flash-borrowed to the `onBehalfOf` address + * 2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address + * @param onBehalfOf The address that will receive the debt in the case of using on `modes` 1 or 2 * @param params Variadic packed params to pass to the receiver as extra information - * @param referralCode Referral code of the flash loan + * @param referralCode Code used to register the integrator originating the operation, for potential rewards. + * 0 if the action is executed directly by the user, without any middle-man **/ function flashLoan( address receiverAddress, @@ -482,11 +495,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage premiums[vars.i] = amounts[vars.i].mul(FLASHLOAN_PREMIUM_TOTAL).div(10000); - //transfer funds to the receiver IAToken(aTokenAddresses[vars.i]).transferUnderlyingTo(receiverAddress, amounts[vars.i]); } - //execute action of the receiver require( vars.receiver.executeOperation(assets, amounts, premiums, msg.sender, params), Errors.LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN @@ -518,8 +529,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage vars.currentAmountPlusPremium ); } else { - //if the user didn't choose to return the funds, the system checks if there - //is enough collateral and eventually open a position + // If the user chose to not return the funds, the system checks if there is enough collateral and + // eventually opens a debt position _executeBorrow( ExecuteBorrowParams( vars.currentAsset, @@ -545,9 +556,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev returns the state and configuration of the reserve - * @param asset the address of the reserve - * @return the state of the reserve + * @dev Returns the state and configuration of the reserve + * @param asset The address of the underlying asset of the reserve + * @return The state of the reserve **/ function getReserveData(address asset) external @@ -559,8 +570,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev returns the user account data across all the reserves - * @param user the address of the user + * @dev Returns the user account data across all the reserves + * @param user The address of the user * @return totalCollateralETH the total collateral in ETH of the user * @return totalDebtETH the total debt in ETH of the user * @return availableBorrowsETH the borrowing power left of the user @@ -604,9 +615,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev returns the configuration of the reserve - * @param asset the address of the reserve - * @return the configuration of the reserve + * @dev Returns the configuration of the reserve + * @param asset The address of the underlying asset of the reserve + * @return The configuration of the reserve **/ function getConfiguration(address asset) external @@ -618,9 +629,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev returns the configuration of the user across all the reserves - * @param user the user - * @return the configuration of the user + * @dev Returns the configuration of the user across all the reserves + * @param user The user address + * @return The configuration of the user **/ function getUserConfiguration(address user) external @@ -632,9 +643,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @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 normalized income of the reserve + * @param asset The address of the underlying asset of the reserve + * @return The reserve's normalized income */ function getReserveNormalizedIncome(address asset) external @@ -647,9 +658,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @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 underlying asset of the reserve + * @return The reserve normalized variable debt */ function getReserveNormalizedVariableDebt(address asset) external @@ -668,7 +679,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev returns the list of the initialized reserves + * @dev Returns the list of the initialized reserves **/ function getReservesList() external override view returns (address[] memory) { address[] memory _activeReserves = new address[](_reservesCount); @@ -680,20 +691,21 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev returns the addresses provider + * @dev Returns the cached LendingPoolAddressesProvider connected to this contract **/ function getAddressesProvider() external override view returns (ILendingPoolAddressesProvider) { return _addressesProvider; } /** - * @dev validates and finalizes an aToken transfer - * @param asset the address of the reserve - * @param from the user from which the aTokens are transferred - * @param to the user receiving the aTokens - * @param amount the amount being transferred/redeemed - * @param balanceFromBefore the balance of the from user before the transfer - * @param balanceToBefore the balance of the to user before the transfer + * @dev Validates and finalizes an aToken transfer + * - Only callable by the overlying aToken of the `asset` + * @param asset The address of the underlying asset of the aToken + * @param from The user from which the aTokens are transferred + * @param to The user receiving the aTokens + * @param amount The amount being transferred/withdrawn + * @param balanceFromBefore The aToken balance of the `from` user before the transfer + * @param balanceToBefore The aToken balance of the `to` user before the transfer */ function finalizeTransfer( address asset, @@ -732,10 +744,14 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev initializes a reserve - * @param asset the address of the reserve - * @param aTokenAddress the address of the overlying aToken contract - * @param interestRateStrategyAddress the address of the interest rate strategy contract + * @dev Initializes a reserve, activating it, assigning an aToken and debt tokens and an + * interest rate strategy + * - Only callable by the LendingPoolConfigurator contract + * @param asset The address of the underlying asset of the reserve + * @param aTokenAddress The address of the aToken that will be assigned to the reserve + * @param stableDebtAddress The address of the StableDebtToken that will be assigned to the reserve + * @param aTokenAddress The address of the VariableDebtToken that will be assigned to the reserve + * @param interestRateStrategyAddress The address of the interest rate strategy contract **/ function initReserve( address asset, @@ -755,9 +771,10 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev updates the address of the interest rate strategy contract - * @param asset the address of the reserve - * @param rateStrategyAddress the address of the interest rate strategy contract + * @dev Updates the address of the interest rate strategy contract + * - Only callable by the LendingPoolConfigurator contract + * @param asset The address of the underlying asset of the reserve + * @param rateStrategyAddress The address of the interest rate strategy contract **/ function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress) external @@ -768,9 +785,10 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev sets the configuration map of the reserve - * @param asset the address of the reserve - * @param configuration the configuration map + * @dev Sets the configuration bitmap of the reserve as a whole + * - Only callable by the LendingPoolConfigurator contract + * @param asset The address of the underlying asset of the reserve + * @param configuration The new configuration bitmap **/ function setConfiguration(address asset, uint256 configuration) external @@ -781,8 +799,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } /** - * @dev Set the _pause state - * @param val the boolean value to set the current pause state of LendingPool + * @dev Set the _pause state of a reserve + * - Only callable by the LendingPoolConfigurator contract + * @param val `true` to pause the reserve, `false` to un-pause it */ function setPause(bool val) external override onlyLendingPoolConfigurator { _paused = val; @@ -793,7 +812,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage } } - // internal functions struct ExecuteBorrowParams { address asset; address user; @@ -805,10 +823,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage bool releaseUnderlying; } - /** - * @dev Internal function to execute a borrowing action, allowing to transfer or not the underlying - * @param vars Input struct for the borrowing action, in order to avoid STD errors - **/ function _executeBorrow(ExecuteBorrowParams memory vars) internal { ReserveLogic.ReserveData storage reserve = _reserves[vars.asset]; UserConfiguration.Map storage userConfig = _usersConfig[vars.onBehalfOf]; @@ -836,7 +850,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage reserve.updateState(); - //caching the current stable borrow rate uint256 currentStableRate = 0; bool isFirstBorrowing = false; @@ -888,9 +901,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage ); } - /** - * @dev adds a reserve to the array of the _reserves address - **/ function _addReserveToList(address asset) internal { uint256 reservesCount = _reservesCount; diff --git a/contracts/lendingpool/LendingPoolCollateralManager.sol b/contracts/lendingpool/LendingPoolCollateralManager.sol index bf207110c..9c33f0166 100644 --- a/contracts/lendingpool/LendingPoolCollateralManager.sol +++ b/contracts/lendingpool/LendingPoolCollateralManager.sol @@ -42,7 +42,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor * @param collateral the address of the collateral being liquidated * @param principal the address of the reserve * @param user the address of the user being liquidated - * @param purchaseAmount the total amount liquidated + * @param debtToCover the total amount liquidated * @param liquidatedCollateralAmount the amount of collateral being liquidated * @param liquidator the address of the liquidator * @param receiveAToken true if the liquidator wants to receive aTokens, false otherwise @@ -51,7 +51,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor address indexed collateral, address indexed principal, address indexed user, - uint256 purchaseAmount, + uint256 debtToCover, uint256 liquidatedCollateralAmount, address liquidator, bool receiveAToken @@ -107,7 +107,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor * @param collateral the address of the collateral to liquidated * @param principal 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 debtToCover 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 **/ @@ -115,7 +115,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor address collateral, address principal, address user, - uint256 purchaseAmount, + uint256 debtToCover, bool receiveAToken ) external returns (uint256, string memory) { ReserveLogic.ReserveData storage collateralReserve = _reserves[collateral]; @@ -160,9 +160,9 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor LIQUIDATION_CLOSE_FACTOR_PERCENT ); - vars.actualAmountToLiquidate = purchaseAmount > vars.maxPrincipalAmountToLiquidate + vars.actualAmountToLiquidate = debtToCover > vars.maxPrincipalAmountToLiquidate ? vars.maxPrincipalAmountToLiquidate - : purchaseAmount; + : debtToCover; ( vars.maxCollateralToLiquidate, @@ -287,7 +287,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor * all the checks to validate the liquidation have been performed, otherwise it might fail. * @param collateralAddress the collateral to be liquidated * @param principalAddress the principal currency to be liquidated - * @param purchaseAmount the amount of principal being liquidated + * @param debtToCover the amount of principal being liquidated * @param userCollateralBalance the collatera balance for the specific collateral asset of the user being liquidated * @return collateralAmount the maximum amount that is possible to liquidated given all the liquidation constraints (user balance, close factor) * @return principalAmountNeeded the purchase amount @@ -297,7 +297,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor ReserveLogic.ReserveData storage principalReserve, address collateralAddress, address principalAddress, - uint256 purchaseAmount, + uint256 debtToCover, uint256 userCollateralBalance ) internal view returns (uint256, uint256) { uint256 collateralAmount = 0; @@ -318,7 +318,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor //max amount of principal currency that is available for liquidation. vars.maxAmountCollateralToLiquidate = vars .principalCurrencyPrice - .mul(purchaseAmount) + .mul(debtToCover) .mul(10**vars.collateralDecimals) .percentMul(vars.liquidationBonus) .div(vars.collateralPrice.mul(10**vars.principalDecimals)); @@ -333,7 +333,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor .percentDiv(vars.liquidationBonus); } else { collateralAmount = vars.maxAmountCollateralToLiquidate; - principalAmountNeeded = purchaseAmount; + principalAmountNeeded = debtToCover; } return (collateralAmount, principalAmountNeeded); } diff --git a/specs/harness/LendingPoolHarnessForVariableDebtToken.sol b/specs/harness/LendingPoolHarnessForVariableDebtToken.sol index f5ea9be1e..b3e793ee2 100644 --- a/specs/harness/LendingPoolHarnessForVariableDebtToken.sol +++ b/specs/harness/LendingPoolHarnessForVariableDebtToken.sol @@ -71,10 +71,10 @@ contract LendingPoolHarnessForVariableDebtToken is ILendingPool { address collateral, address asset, address user, - uint256 purchaseAmount, + uint256 debtToCover, bool receiveAToken ) external override { - originalPool.liquidationCall(collateral, asset, user, purchaseAmount, receiveAToken); + originalPool.liquidationCall(collateral, asset, user, debtToCover, receiveAToken); } function getReservesList() external override view returns (address[] memory) {