From 5e685b18a09b6da43b4adf264ad26f2ae6e0f2a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Tue, 15 Oct 2024 10:41:26 +0200 Subject: [PATCH] fix: prevetn setCrossPrice to revert. --- test/invariants/handlers/OwnerHandler.sol | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/invariants/handlers/OwnerHandler.sol b/test/invariants/handlers/OwnerHandler.sol index 718a6d9..c5ff255 100644 --- a/test/invariants/handlers/OwnerHandler.sol +++ b/test/invariants/handlers/OwnerHandler.sol @@ -82,7 +82,14 @@ contract OwnerHandler is BaseHandler { // Bound prices uint256 currentPrice = arm.crossPrice(); - uint256 newCrossPrice = _bound(_seed, priceScale - arm.MAX_CROSS_PRICE_DEVIATION(), priceScale); + // Condition 1: 1e36 - 20e32 <= newCrossPrice <= 1e36 + // Condition 2: buyPrice < newCrossPrice <= sellPrice + // <=> + // max(buyPrice, 1e36 - 20e32) < newCrossPrice <= min(sellPrice, 1e36) + uint256 sellPrice = priceScale * priceScale / arm.traderate0(); + uint256 buyPrice = arm.traderate1(); + uint256 newCrossPrice = + _bound(_seed, max(priceScale - arm.MAX_CROSS_PRICE_DEVIATION(), buyPrice) + 1, min(priceScale, sellPrice)); if (newCrossPrice < currentPrice && steth.balanceOf(address(arm)) >= MIN_TOTAL_SUPPLY) { console.log("OwnerHandler.setCrossPrice() - Skipping price decrease");