Skip to content

Commit

Permalink
feat: check if collateral is enabled in collectRedemption (#894)
Browse files Browse the repository at this point in the history
Also add a unit test that verifies the check.

Resolves: sherlock-audit/2023-12-ubiquity-judging#29
  • Loading branch information
gitcoindev authored Feb 6, 2024
1 parent 682354e commit 5ab280d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/contracts/src/dollar/libraries/LibUbiquityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,11 @@ library LibUbiquityPool {
*/
function collectRedemption(
uint256 collateralIndex
) internal returns (uint256 collateralAmount) {
)
internal
collateralEnabled(collateralIndex)
returns (uint256 collateralAmount)
{
UbiquityPoolStorage storage poolStorage = ubiquityPoolStorage();

require(
Expand Down
33 changes: 33 additions & 0 deletions packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,39 @@ contract UbiquityPoolFacetTest is DiamondTestSetup {
assertEq(collateralToken.balanceOf(user), 97.02e18);
}

function testCollectRedemption_ShouldRevert_IfCollateralDisabled() public {
vm.prank(admin);
ubiquityPoolFacet.setPriceThresholds(
1000000, // mint threshold
1000000 // redeem threshold
);

vm.prank(user);
ubiquityPoolFacet.mintDollar(
0, // collateral index
100e18, // Dollar amount
99e18, // min amount of Dollars to mint
100e18 // max collateral to send
);

vm.prank(user);
ubiquityPoolFacet.redeemDollar(
0, // collateral index
99e18, // Dollar amount
90e18 // min collateral out
);

// wait 3 blocks for collecting redemption to become active
vm.roll(3);

vm.prank(admin);
ubiquityPoolFacet.toggleCollateral(0);

vm.prank(user);
vm.expectRevert("Collateral disabled");
ubiquityPoolFacet.collectRedemption(0);
}

function testUpdateChainLinkCollateralPrice_ShouldRevert_IfChainlinkAnswerIsInvalid()
public
{
Expand Down

0 comments on commit 5ab280d

Please sign in to comment.