Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cap collateral ratio to 100% #932

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading