Skip to content

Commit

Permalink
feat: add pause lib-ubiquity-pool logic
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandr-masl committed Sep 18, 2024
1 parent dd032cf commit b5dc054
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 21 additions & 3 deletions packages/contracts/src/dollar/core/UbiquityPoolSecurityMonitor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Ini
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {AccessControlFacet} from "../facets/AccessControlFacet.sol";
import {UbiquityPoolFacet} from "../facets/UbiquityPoolFacet.sol";

import {LibUbiquityPool} from "../libraries/LibUbiquityPool.sol";
import "../libraries/Constants.sol";
import "forge-std/console.sol";

Expand Down Expand Up @@ -92,8 +92,10 @@ contract UbiquityPoolSecurityMonitor is Initializable, UUPSUpgradeable {
.div(liquidityVertex);

if (liquidityDiffPercentage >= thresholdPercentage) {
// a) Pause the UbiquityDollarToken
// b) Pause LibUbiquityPool by disabling collateral
// TODO: Pause the UbiquityDollarToken

// Pause LibUbiquityPool by disabling collateral
_pauseLibUbiquityPool();

monitorPaused = true;
emit MonitorPaused(
Expand All @@ -103,4 +105,20 @@ contract UbiquityPoolSecurityMonitor is Initializable, UUPSUpgradeable {
}
}
}

function _pauseLibUbiquityPool() internal {
address[] memory allCollaterals = ubiquityPoolFacet.allCollaterals();

for (uint256 i = 0; i < allCollaterals.length; i++) {
try
ubiquityPoolFacet.collateralInformation(allCollaterals[i])
returns (
LibUbiquityPool.CollateralInformation memory collateralInfo
) {
ubiquityPoolFacet.toggleCollateral(collateralInfo.index);
} catch {
continue;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ contract PoolLiquidityMonitorTest is DiamondTestSetup {
address(ubiquityPoolFacet)
);

accessControlFacet.grantRole(DEFAULT_ADMIN_ROLE, address(monitor));

// stop being admin
vm.stopPrank();

Expand Down Expand Up @@ -220,7 +222,11 @@ contract PoolLiquidityMonitorTest is DiamondTestSetup {
vm.prank(defenderRelayer);
monitor.checkLiquidityVertex();

vm.expectRevert("Invalid collateral");
ubiquityPoolFacet.collateralInformation(address(collateralToken));

bool monitorPaused = monitor.monitorPaused();

assertTrue(
monitorPaused,
"Monitor should be paused after liquidity drop"
Expand Down

0 comments on commit b5dc054

Please sign in to comment.