From db667d1f898c4834bbd34d33d7506b250209281b Mon Sep 17 00:00:00 2001 From: lucas-manuel Date: Thu, 4 Jul 2024 06:40:48 -0400 Subject: [PATCH] fix: increase invariant D tolerance --- test/invariant/Invariants.t.sol | 8 ++++---- test/invariant/handlers/SwapperHandler.sol | 17 ++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/test/invariant/Invariants.t.sol b/test/invariant/Invariants.t.sol index 5f67a3b..f0ff9ee 100644 --- a/test/invariant/Invariants.t.sol +++ b/test/invariant/Invariants.t.sol @@ -85,11 +85,11 @@ abstract contract PSMInvariantTestBase is PSMTestBase { // LPs position value can increase from transfers into the PSM and from swapping rounding // errors increasing the value of the PSM slightly. - // Allow a 4 tolerance for negative rounding on conversion calculations. - assertGe(lpAssetValue + 1e12, lpDeposits); + // Allow a 2e12 tolerance for negative rounding on conversion calculations. + assertGe(lpAssetValue + 2e12, lpDeposits); - // Include seed deposit, allow for 1e12 negative tolerance. - assertGe(psm.getPsmTotalValue() + 1e12, lpDeposits); + // Include seed deposit, allow for 2e12 negative tolerance. + assertGe(psm.getPsmTotalValue() + 2e12, lpDeposits); } function _checkInvariant_E() public view { diff --git a/test/invariant/handlers/SwapperHandler.sol b/test/invariant/handlers/SwapperHandler.sol index 9eec1a6..150b5cc 100644 --- a/test/invariant/handlers/SwapperHandler.sol +++ b/test/invariant/handlers/SwapperHandler.sol @@ -138,13 +138,16 @@ contract SwapperHandler is HandlerBase { "SwapperHandler/swap/conversion-rate-million-decrease" ); - // Position values can fluctuate by up to 0.00000002% on swaps - assertApproxEqRel( - psm.convertToAssetValue(psm.shares(lp0)), - startingConversionLp0, - 0.000002e18, - "SwapperHandler/swap/conversion-rate-change-lp" - ); + // Disregard this assertion if the LP has less than a dollar of value + if (startingConversionLp0 > 1e18) { + // Position values can fluctuate by up to 0.00000002% on swaps + assertApproxEqRel( + psm.convertToAssetValue(psm.shares(lp0)), + startingConversionLp0, + 0.000002e18, + "SwapperHandler/swap/conversion-rate-change-lp" + ); + } // Decrease in value from rounding is capped at 2e12 assertGe(