From ca23130b4aa95e64a1f3f574c6d8de931842f125 Mon Sep 17 00:00:00 2001 From: rndquu Date: Wed, 20 Mar 2024 10:16:21 +0300 Subject: [PATCH] fix: check collateral exists on chainlink set --- .../src/dollar/libraries/LibUbiquityPool.sol | 5 +++++ .../test/diamond/facets/UbiquityPoolFacet.t.sol | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol b/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol index 447a6ded3..c269fc455 100644 --- a/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol +++ b/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol @@ -750,6 +750,11 @@ library LibUbiquityPool { address chainLinkPriceFeedAddress, uint256 stalenessThreshold ) internal { + require( + collateralExists(collateralAddress), + "Collateral does not exist" + ); + UbiquityPoolStorage storage poolStorage = ubiquityPoolStorage(); uint256 collateralIndex = poolStorage.collateralIndex[ diff --git a/packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol b/packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol index 4520f0077..78309d118 100644 --- a/packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol +++ b/packages/contracts/test/diamond/facets/UbiquityPoolFacet.t.sol @@ -831,6 +831,21 @@ contract UbiquityPoolFacetTest is DiamondTestSetup { vm.stopPrank(); } + function testSetCollateralChainLinkPriceFeed_ShouldRevertIfCollateralDoesNotExist() + public + { + vm.prank(admin); + vm.expectRevert("Collateral does not exist"); + address invalidCollateralAddress = address(0); + address newPriceFeedAddress = address(1); + uint256 newStalenessThreshold = 1 days; + ubiquityPoolFacet.setCollateralChainLinkPriceFeed( + invalidCollateralAddress, + newPriceFeedAddress, + newStalenessThreshold + ); + } + function testSetCollateralChainLinkPriceFeed_ShouldSetPriceFeed() public { vm.startPrank(admin);