Skip to content

Commit

Permalink
feat: cap collateral ratio to 100%
Browse files Browse the repository at this point in the history
Resolves: #929
  • Loading branch information
gitcoindev committed Apr 20, 2024
1 parent d65516f commit f6af72a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/contracts/src/dollar/libraries/LibUbiquityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit f6af72a

Please sign in to comment.