From 5ab280df3a791409e694e1310aaf720daba2f024 Mon Sep 17 00:00:00 2001 From: korrrba <88761781+gitcoindev@users.noreply.github.com> Date: Tue, 6 Feb 2024 15:28:31 +0100 Subject: [PATCH] feat: check if collateral is enabled in collectRedemption (#894) Also add a unit test that verifies the check. Resolves: https://github.com/sherlock-audit/2023-12-ubiquity-judging/issues/29 --- .../src/dollar/libraries/LibUbiquityPool.sol | 6 +++- .../diamond/facets/UbiquityPoolFacet.t.sol | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol b/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol index 9773da078..0176efc9c 100644 --- a/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol +++ b/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol @@ -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( diff --git a/packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol b/packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol index 3c6e437fc..84b4d2735 100644 --- a/packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol +++ b/packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol @@ -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 {