diff --git a/contracts/protocol/libraries/helpers/Errors.sol b/contracts/protocol/libraries/helpers/Errors.sol index b4c14221..36ac923a 100644 --- a/contracts/protocol/libraries/helpers/Errors.sol +++ b/contracts/protocol/libraries/helpers/Errors.sol @@ -113,7 +113,6 @@ library Errors { string public constant RL_STABLE_DEBT_NOT_ZERO = '89'; string public constant RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO = '90'; string public constant LP_CALLER_NOT_EOA = '91'; - string public constant RC_INVALID_EXPOSURE_CAP = '92'; string public constant VL_LTV_VALIDATION_FAILED = '93'; string public constant VL_SAME_BLOCK_BORROW_REPAY = '94'; string public constant LPC_FLASHLOAN_PREMIUMS_MISMATCH = '95'; diff --git a/contracts/protocol/libraries/logic/GenericLogic.sol b/contracts/protocol/libraries/logic/GenericLogic.sol index 9bef0180..bcb49b24 100644 --- a/contracts/protocol/libraries/logic/GenericLogic.sol +++ b/contracts/protocol/libraries/logic/GenericLogic.sol @@ -60,7 +60,7 @@ library GenericLogic { * @param userConfig The configuration of the user * @param reserves The list of the available reserves * @param oracle The price oracle address - * @return The total collateral and total debt of the user in ETH, the avg ltv, liquidation threshold, the HF and the uncapped avg ltv (without exposure ceiling) + * @return The total collateral and total debt of the user in ETH, the avg ltv, liquidation threshold, the HF and the uncapped avg ltv **/ function calculateUserAccountData( address user, diff --git a/contracts/protocol/libraries/logic/ValidationLogic.sol b/contracts/protocol/libraries/logic/ValidationLogic.sol index 7670a044..4fc4596e 100644 --- a/contracts/protocol/libraries/logic/ValidationLogic.sol +++ b/contracts/protocol/libraries/logic/ValidationLogic.sol @@ -21,7 +21,7 @@ import {IAToken} from '../../../interfaces/IAToken.sol'; import {DataTypes} from '../types/DataTypes.sol'; import {IPriceOracleGetter} from '../../../interfaces/IPriceOracleGetter.sol'; import {Address} from '../../../dependencies/openzeppelin/contracts/Address.sol'; -import "hardhat/console.sol"; + /** * @title ReserveLogic library * @author Aave @@ -517,7 +517,7 @@ library ValidationLogic { /** * @dev Validates the health factor of a user and the ltv of the asset being withdrawn - * @param asset The asset for which the exposure cap will be validated + * @param asset The asset for which the ltv will be validated * @param from The user from which the aTokens are being transferred * @param reservesData The state of all the reserves * @param userConfig The state of the user for the specific reserve @@ -552,9 +552,6 @@ library ValidationLogic { vars.assetLtv = reserve.configuration.getLtvMemory(); - console.log("asset ltv is ", vars.assetLtv); - console.log("has 0 ltv collateral ", vars.hasZeroLtvCollateral); - require(vars.assetLtv == 0 || !vars.hasZeroLtvCollateral, Errors.VL_LTV_VALIDATION_FAILED); } diff --git a/helpers/constants.ts b/helpers/constants.ts index b25ce643..f2568ee0 100644 --- a/helpers/constants.ts +++ b/helpers/constants.ts @@ -17,7 +17,6 @@ export const MAX_UINT_AMOUNT = '115792089237316195423570985008687907853269984665640564039457584007913129639935'; export const MAX_BORROW_CAP = '68719476735'; export const MAX_SUPPLY_CAP = '68719476735'; -export const MAX_EXPOSURE_CAP = '68719476735'; export const ONE_YEAR = '31536000'; export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; export const ONE_ADDRESS = '0x0000000000000000000000000000000000000001'; diff --git a/helpers/init-helpers.ts b/helpers/init-helpers.ts index 4289e68a..dc731b17 100644 --- a/helpers/init-helpers.ts +++ b/helpers/init-helpers.ts @@ -285,7 +285,6 @@ export const configureReservesByHelper = async ( reserveFactor: BigNumberish; borrowCap: BigNumberish; supplyCap: BigNumberish; - exposureCap: BigNumberish; stableBorrowingEnabled: boolean; borrowingEnabled: boolean; }[] = []; @@ -299,7 +298,6 @@ export const configureReservesByHelper = async ( reserveFactor, borrowCap, supplyCap, - exposureCap, stableBorrowRateEnabled, borrowingEnabled, }, @@ -336,7 +334,6 @@ export const configureReservesByHelper = async ( reserveFactor, borrowCap, supplyCap, - exposureCap, stableBorrowingEnabled: stableBorrowRateEnabled, borrowingEnabled: borrowingEnabled, }); diff --git a/helpers/types.ts b/helpers/types.ts index fe779211..68d1ac23 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -188,7 +188,6 @@ export enum ProtocolErrors { RL_STABLE_DEBT_NOT_ZERO = '89', RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO = '90', LP_CALLER_NOT_EOA = '91', - RC_INVALID_EXPOSURE_CAP = '92', VL_LTV_VALIDATION_FAILED = '93', VL_SAME_BLOCK_BORROW_REPAY = '94', LPC_FLASHLOAN_PREMIUMS_MISMATCH = '95', @@ -403,7 +402,6 @@ export interface IReserveCollateralParams { baseLTVAsCollateral: string; liquidationThreshold: string; liquidationBonus: string; - exposureCap: string; } export interface IMarketRates { borrowRate: string; diff --git a/markets/aave/reservesConfigs.ts b/markets/aave/reservesConfigs.ts index cd48a26c..8c04a3c8 100644 --- a/markets/aave/reservesConfigs.ts +++ b/markets/aave/reservesConfigs.ts @@ -24,7 +24,7 @@ export const strategyBUSD: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyDAI: IReserveParams = { @@ -39,7 +39,7 @@ export const strategyDAI: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategySUSD: IReserveParams = { @@ -54,7 +54,7 @@ export const strategySUSD: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyTUSD: IReserveParams = { @@ -69,7 +69,7 @@ export const strategyTUSD: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyUSDC: IReserveParams = { @@ -84,7 +84,7 @@ export const strategyUSDC: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyUSDT: IReserveParams = { @@ -99,7 +99,7 @@ export const strategyUSDT: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyAAVE: IReserveParams = { @@ -114,7 +114,7 @@ export const strategyAAVE: IReserveParams = { reserveFactor: '0', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyBAT: IReserveParams = { @@ -129,7 +129,7 @@ export const strategyBAT: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyENJ: IReserveParams = { @@ -144,7 +144,7 @@ export const strategyENJ: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyWETH: IReserveParams = { @@ -159,7 +159,7 @@ export const strategyWETH: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyKNC: IReserveParams = { @@ -174,7 +174,7 @@ export const strategyKNC: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyLINK: IReserveParams = { @@ -189,7 +189,7 @@ export const strategyLINK: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyMANA: IReserveParams = { @@ -204,7 +204,7 @@ export const strategyMANA: IReserveParams = { reserveFactor: '3500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyMKR: IReserveParams = { @@ -219,7 +219,7 @@ export const strategyMKR: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyREN: IReserveParams = { @@ -234,7 +234,7 @@ export const strategyREN: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategySNX: IReserveParams = { @@ -249,7 +249,7 @@ export const strategySNX: IReserveParams = { reserveFactor: '3500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; // Invalid borrow rates in params currently, replaced with snx params @@ -265,7 +265,7 @@ export const strategyUNI: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyWBTC: IReserveParams = { @@ -280,7 +280,7 @@ export const strategyWBTC: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyYFI: IReserveParams = { @@ -295,7 +295,7 @@ export const strategyYFI: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyZRX: IReserveParams = { @@ -310,7 +310,7 @@ export const strategyZRX: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyXSUSHI: IReserveParams = { @@ -325,5 +325,5 @@ export const strategyXSUSHI: IReserveParams = { reserveFactor: '3500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; diff --git a/markets/amm/reservesConfigs.ts b/markets/amm/reservesConfigs.ts index fcbf8280..22a25020 100644 --- a/markets/amm/reservesConfigs.ts +++ b/markets/amm/reservesConfigs.ts @@ -13,7 +13,7 @@ export const strategyWETH: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyWBTC: IReserveParams = { @@ -28,7 +28,7 @@ export const strategyWBTC: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyDAI: IReserveParams = { @@ -43,7 +43,7 @@ export const strategyDAI: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyUSDC: IReserveParams = { @@ -58,7 +58,7 @@ export const strategyUSDC: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyUSDT: IReserveParams = { @@ -73,7 +73,7 @@ export const strategyUSDT: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyDAIWETH: IReserveParams = { @@ -88,7 +88,7 @@ export const strategyDAIWETH: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyWBTCWETH: IReserveParams = { @@ -103,7 +103,7 @@ export const strategyWBTCWETH: IReserveParams = { reserveFactor: '1500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyAAVEWETH: IReserveParams = { @@ -118,7 +118,7 @@ export const strategyAAVEWETH: IReserveParams = { reserveFactor: '500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyBATWETH: IReserveParams = { @@ -133,7 +133,7 @@ export const strategyBATWETH: IReserveParams = { reserveFactor: '1500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyDAIUSDC: IReserveParams = { @@ -148,7 +148,7 @@ export const strategyDAIUSDC: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyCRVWETH: IReserveParams = { @@ -163,7 +163,7 @@ export const strategyCRVWETH: IReserveParams = { reserveFactor: '1500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyLINKWETH: IReserveParams = { @@ -178,7 +178,7 @@ export const strategyLINKWETH: IReserveParams = { reserveFactor: '1500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyMKRWETH: IReserveParams = { @@ -193,7 +193,7 @@ export const strategyMKRWETH: IReserveParams = { reserveFactor: '1500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyRENWETH: IReserveParams = { @@ -208,7 +208,7 @@ export const strategyRENWETH: IReserveParams = { reserveFactor: '1500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategySNXWETH: IReserveParams = { @@ -223,7 +223,7 @@ export const strategySNXWETH: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyUNIWETH: IReserveParams = { @@ -238,7 +238,7 @@ export const strategyUNIWETH: IReserveParams = { reserveFactor: '1500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyUSDCWETH: IReserveParams = { @@ -253,7 +253,7 @@ export const strategyUSDCWETH: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyWBTCUSDC: IReserveParams = { @@ -268,7 +268,7 @@ export const strategyWBTCUSDC: IReserveParams = { reserveFactor: '1500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyYFIWETH: IReserveParams = { @@ -283,7 +283,7 @@ export const strategyYFIWETH: IReserveParams = { reserveFactor: '1500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyBALWETH: IReserveParams = { @@ -298,5 +298,5 @@ export const strategyBALWETH: IReserveParams = { reserveFactor: '1500', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; diff --git a/markets/matic/reservesConfigs.ts b/markets/matic/reservesConfigs.ts index 0c9da5af..91fee5db 100644 --- a/markets/matic/reservesConfigs.ts +++ b/markets/matic/reservesConfigs.ts @@ -22,7 +22,7 @@ export const strategyDAI: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyUSDC: IReserveParams = { @@ -37,7 +37,7 @@ export const strategyUSDC: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyUSDT: IReserveParams = { @@ -52,7 +52,7 @@ export const strategyUSDT: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyWETH: IReserveParams = { @@ -67,7 +67,7 @@ export const strategyWETH: IReserveParams = { reserveFactor: '1000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyWBTC: IReserveParams = { @@ -82,7 +82,7 @@ export const strategyWBTC: IReserveParams = { reserveFactor: '2000', borrowCap: '0', supplyCap: '0', - exposureCap: '0', + }; export const strategyMATIC: IReserveParams = { @@ -96,7 +96,7 @@ export const strategyMATIC: IReserveParams = { aTokenImpl: eContractid.AToken, borrowCap: '0', supplyCap: '0', - exposureCap: '0', + reserveFactor: '2000', }; @@ -111,6 +111,6 @@ export const strategyAAVE: IReserveParams = { aTokenImpl: eContractid.AToken, borrowCap: '0', supplyCap: '0', - exposureCap: '0', + reserveFactor: '0', }; diff --git a/test-suites/test-aave/configurator.spec.ts b/test-suites/test-aave/configurator.spec.ts index 5b8ba9f9..59c7764b 100644 --- a/test-suites/test-aave/configurator.spec.ts +++ b/test-suites/test-aave/configurator.spec.ts @@ -677,7 +677,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Deactivates the ETH reserve as collateral via pool admin', async () => { const { configurator, helpersContract, weth } = testEnv; - await configurator.configureReserveAsCollateral(weth.address, 0, 0, 0, 0); + await configurator.configureReserveAsCollateral(weth.address, 0, 0, 0); const { decimals, @@ -711,7 +711,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Activates the ETH reserve as collateral via pool admin', async () => { const { configurator, helpersContract, weth } = testEnv; - await configurator.configureReserveAsCollateral(weth.address, '8000', '8250', '10500', '0'); + await configurator.configureReserveAsCollateral(weth.address, '8000', '8250', '10500'); const { decimals, @@ -747,7 +747,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { const { configurator, helpersContract, weth, riskAdmin } = testEnv; await configurator .connect(riskAdmin.signer) - .configureReserveAsCollateral(weth.address, 0, 0, 0, 0); + .configureReserveAsCollateral(weth.address, 0, 0, 0); const { decimals, @@ -783,7 +783,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { const { configurator, helpersContract, weth, riskAdmin } = testEnv; await configurator .connect(riskAdmin.signer) - .configureReserveAsCollateral(weth.address, '8000', '8250', '10500', '0'); + .configureReserveAsCollateral(weth.address, '8000', '8250', '10500'); const { decimals, @@ -820,7 +820,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { await expect( configurator .connect(emergencyAdmin.signer) - .configureReserveAsCollateral(weth.address, '7500', '8000', '10500', '0'), + .configureReserveAsCollateral(weth.address, '7500', '8000', '10500'), CALLER_NOT_POOL_ADMIN ).to.be.revertedWith(LPC_CALLER_NOT_RISK_OR_POOL_ADMIN); }); diff --git a/test-suites/test-aave/ltv-validation.spec.ts b/test-suites/test-aave/ltv-validation.spec.ts index 56e90074..1017fbec 100644 --- a/test-suites/test-aave/ltv-validation.spec.ts +++ b/test-suites/test-aave/ltv-validation.spec.ts @@ -1,32 +1,15 @@ import { TestEnv, makeSuite } from './helpers/make-suite'; import { - APPROVAL_AMOUNT_LENDING_POOL, MAX_UINT_AMOUNT, - RAY, - MAX_EXPOSURE_CAP, - MOCK_CHAINLINK_AGGREGATORS_PRICES, - oneEther, } from '../../helpers/constants'; import { ProtocolErrors } from '../../helpers/types'; -import { MintableERC20, WETH9, WETH9Mocked } from '../../types'; -import { parseEther } from '@ethersproject/units'; -import { BigNumber } from '@ethersproject/bignumber'; -import { strategyDAI } from '../../markets/amm/reservesConfigs'; -import { strategyUSDC } from '../../markets/amm/reservesConfigs'; -import { ethers } from 'ethers'; import { convertToCurrencyDecimals } from '../../helpers/contracts-helpers'; const { expect } = require('chai'); makeSuite('LTV validation tests', (testEnv: TestEnv) => { const { VL_LTV_VALIDATION_FAILED, - RC_INVALID_EXPOSURE_CAP, - VL_COLLATERAL_CANNOT_COVER_NEW_BORROW, } = ProtocolErrors; - const daiPrice = Number(MOCK_CHAINLINK_AGGREGATORS_PRICES.DAI); - const usdcPrice = Number(MOCK_CHAINLINK_AGGREGATORS_PRICES.USDC); - const daiLTV = Number(strategyDAI.baseLTVAsCollateral); - const usdcLTV = Number(strategyUSDC.baseLTVAsCollateral); it('User 1 deposits 10 Dai, 10 USDC, user 2 deposits 1 WETH', async () => { const { @@ -86,7 +69,7 @@ makeSuite('LTV validation tests', (testEnv: TestEnv) => { const { pool, usdc, - users: [user1, , , receiver], + users: [user1], } = testEnv; const withdrawnAmount = await convertToCurrencyDecimals(usdc.address, "1"); @@ -95,4 +78,25 @@ makeSuite('LTV validation tests', (testEnv: TestEnv) => { pool.connect(user1.signer).withdraw(usdc.address, withdrawnAmount, user1.address) ).to.be.revertedWith(VL_LTV_VALIDATION_FAILED); }); + + it('Withdraws DAI', async () => { + const { + pool, + dai, + aDai, + users: [user1], + } = testEnv; + + const aDaiBalanceBefore = await aDai.balanceOf(user1.address); + + const withdrawnAmount = await convertToCurrencyDecimals(dai.address, "1"); + + await pool.connect(user1.signer).withdraw(dai.address, withdrawnAmount, user1.address); + + const aDaiBalanceAfter = await aDai.balanceOf(user1.address); + + expect(aDaiBalanceAfter.toString()).to.be.bignumber.equal(aDaiBalanceBefore.sub(withdrawnAmount)); + + }); + });