diff --git a/packages/contracts/src/dollar/core/UbiquityPoolSecurityMonitor.sol b/packages/contracts/src/dollar/core/UbiquityPoolSecurityMonitor.sol index 1d24e7ffe..99ce0b076 100644 --- a/packages/contracts/src/dollar/core/UbiquityPoolSecurityMonitor.sol +++ b/packages/contracts/src/dollar/core/UbiquityPoolSecurityMonitor.sol @@ -106,28 +106,38 @@ contract UbiquityPoolSecurityMonitor is Initializable, UUPSUpgradeable { require(!monitorPaused, "Monitor paused"); if (currentCollateralLiquidity > liquidityVertex) { - liquidityVertex = currentCollateralLiquidity; - emit LiquidityVertexUpdated(liquidityVertex); + _updateLiquidityVertex(currentCollateralLiquidity); } else { - uint256 liquidityDiffPercentage = liquidityVertex - .sub(currentCollateralLiquidity) - .mul(100) - .div(liquidityVertex); + _checkThresholdPercentage(currentCollateralLiquidity); + } + } + + function _updateLiquidityVertex(uint256 _newLiquidityVertex) internal { + liquidityVertex = _newLiquidityVertex; + emit LiquidityVertexUpdated(liquidityVertex); + } - if (liquidityDiffPercentage >= thresholdPercentage) { - monitorPaused = true; + function _checkThresholdPercentage( + uint256 _currentCollateralLiquidity + ) internal { + uint256 liquidityDiffPercentage = liquidityVertex + .sub(_currentCollateralLiquidity) + .mul(100) + .div(liquidityVertex); - // Pause the UbiquityDollarToken - _pauseUbiquityDollarToken(); + if (liquidityDiffPercentage >= thresholdPercentage) { + monitorPaused = true; - // Pause LibUbiquityPool by disabling collateral - _pauseLibUbiquityPool(); + // Pause the UbiquityDollarToken + _pauseUbiquityDollarToken(); - emit MonitorPaused( - currentCollateralLiquidity, - liquidityDiffPercentage - ); - } + // Pause LibUbiquityPool by disabling collateral + _pauseLibUbiquityPool(); + + emit MonitorPaused( + _currentCollateralLiquidity, + liquidityDiffPercentage + ); } }