From 03103fb63ddf10efe2a4c7b66da3edf51190f74f Mon Sep 17 00:00:00 2001 From: Hadrien Charlanes Date: Tue, 27 Apr 2021 18:26:08 +0200 Subject: [PATCH] adding stack too deep --- contracts/protocol/libraries/helpers/Errors.sol | 1 + .../protocol/libraries/logic/ValidationLogic.sol | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/contracts/protocol/libraries/helpers/Errors.sol b/contracts/protocol/libraries/helpers/Errors.sol index 304f0a33..6ee6cced 100644 --- a/contracts/protocol/libraries/helpers/Errors.sol +++ b/contracts/protocol/libraries/helpers/Errors.sol @@ -103,6 +103,7 @@ library Errors { string public constant LP_NOT_CONTRACT = '78'; string public constant SDT_STABLE_DEBT_OVERFLOW = '79'; string public constant SDT_BURN_EXCEEDS_BALANCE = '80'; + string public constant VL_BORROW_CAP_EXCEEDED = '81'; string public constant RC_INVALID_BORROW_CAP = '82'; enum CollateralManagerErrors { diff --git a/contracts/protocol/libraries/logic/ValidationLogic.sol b/contracts/protocol/libraries/logic/ValidationLogic.sol index 080b792d..564759c3 100644 --- a/contracts/protocol/libraries/logic/ValidationLogic.sol +++ b/contracts/protocol/libraries/logic/ValidationLogic.sol @@ -14,6 +14,8 @@ import {UserConfiguration} from '../configuration/UserConfiguration.sol'; import {Errors} from '../helpers/Errors.sol'; import {Helpers} from '../helpers/Helpers.sol'; import {IReserveInterestRateStrategy} from '../../../interfaces/IReserveInterestRateStrategy.sol'; +import {IVariableDebtToken} from '../../../interfaces/IVariableDebtToken.sol'; +import {IStableDebtToken} from '../../../interfaces/IStableDebtToken.sol'; import {DataTypes} from '../types/DataTypes.sol'; /** @@ -149,6 +151,20 @@ library ValidationLogic { uint256(DataTypes.InterestRateMode.STABLE) == interestRateMode, Errors.VL_INVALID_INTEREST_RATE_MODE_SELECTED ); + + // not using this because stack too deep + // uint256 totalStableDebt; + // (totalStableDebt, ) = IStableDebtToken(reserve.stableDebtTokenAddress) + // .getTotalSupplyAndAvgRate(); + + require( + IERC20(reserve.stableDebtTokenAddress).totalSupply() + .add(IVariableDebtToken(reserve.variableDebtTokenAddress) + .scaledTotalSupply() + .rayMul(reserve.variableBorrowIndex) + ).add(amount) + < reserve.configuration.getBorrowCap(), + Errors.VL_BORROW_CAP_EXCEEDED); ( vars.userCollateralBalanceETH,