diff --git a/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol b/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol index ae736accf..695fc75cc 100644 --- a/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol +++ b/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol @@ -994,7 +994,8 @@ library LibUbiquityPool { /** * @notice Sets collateral ratio - * @dev How much collateral/governance tokens user should provide/get to mint/redeem Dollar tokens, 1e6 precision + * @dev How much collateral/governance tokens user should provide/get to mint/redeem Dollar tokens, 1e6 precision. + * @dev Collateral ratio is capped to 100%. * * @dev Example (1_000_000 = 100%): * - Mint: user provides 1 collateral token to get 1 Dollar @@ -1007,6 +1008,7 @@ library LibUbiquityPool { * @param newCollateralRatio New collateral ratio */ function setCollateralRatio(uint256 newCollateralRatio) internal { + require(newCollateralRatio <= 1_000_000, "Collateral ratio too large"); UbiquityPoolStorage storage poolStorage = ubiquityPoolStorage(); poolStorage.collateralRatio = newCollateralRatio; diff --git a/packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol b/packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol index ae481d082..de0cf1807 100644 --- a/packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol +++ b/packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol @@ -1387,6 +1387,20 @@ contract UbiquityPoolFacetTest is DiamondTestSetup { vm.stopPrank(); } + function testSetCollateralRatio_ShouldRevertIfRatioLargerThanOneHundredPercent() + public + { + vm.startPrank(admin); + uint256 oldCollateralRatio = ubiquityPoolFacet.collateralRatio(); + assertEq(oldCollateralRatio, 1_000_000); + + uint256 newCollateralRatio = 1_000_001; + vm.expectRevert("Collateral ratio too large"); + ubiquityPoolFacet.setCollateralRatio(newCollateralRatio); + + vm.stopPrank(); + } + function testSetEthUsdChainLinkPriceFeed_ShouldSetEthUsdChainLinkPriceFeed() public {