@@ -4,6 +4,7 @@ pragma solidity 0.8.23;
44import {Vm} from "forge-std/Vm.sol " ;
55import {Base_Test_} from "../base/Base.t.sol " ;
66import {IERC4626 } from "@openzeppelin/contracts/interfaces/IERC4626.sol " ;
7+ import {Math} from "@openzeppelin/contracts/utils/math/Math.sol " ;
78
89// Mocks
910import {MockERC20} from "@solmate/test/utils/mocks/MockERC20.sol " ;
@@ -17,11 +18,19 @@ abstract contract Helpers is Base_Test_ {
1718 ////////////////////////////////////////////////////
1819
1920 modifier ensureSharePriceNotDecreased () {
21+ uint256 marketRoundingLossBefore = sum_weth_marketRoundingLoss;
2022 uint256 priceBefore = lidoARM.totalAssets () * 1e18 / lidoARM.totalSupply ();
2123 _;
22- uint256 priceAfter = lidoARM.totalAssets () * 1e18 / lidoARM.totalSupply ();
24+ uint256 totalSupplyAfter = lidoARM.totalSupply ();
25+ uint256 priceAfter = lidoARM.totalAssets () * 1e18 / totalSupplyAfter;
2326 // Allow 2 wei tolerance for ERC4626 convertToAssets rounding on split operations
24- require (priceAfter + 2 >= priceBefore, "SHARE_PRICE_DECREASED " );
27+ // plus the share-price impact of any market rounding loss tracked by the inner modifier.
28+ if (priceAfter < priceBefore) {
29+ uint256 marketRoundingLoss = sum_weth_marketRoundingLoss - marketRoundingLossBefore;
30+ uint256 marketRoundingPriceTolerance =
31+ Math.mulDiv (marketRoundingLoss, 1e18 , totalSupplyAfter, Math.Rounding.Ceil);
32+ require (priceBefore - priceAfter <= 2 + marketRoundingPriceTolerance, "SHARE_PRICE_DECREASED " );
33+ }
2534 ghost_lastSharePrice = priceAfter;
2635 }
2736
0 commit comments