Skip to content

Commit

Permalink
fix: Update tolerances to pass on longer invariants campaigns (SC-709) (
Browse files Browse the repository at this point in the history
#42)

* feat: optimize for gas

* fix: remove comment

* fix: increase invariant tolerances
  • Loading branch information
lucas-manuel authored Oct 2, 2024
1 parent 2e65f5e commit e7c8060
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
7 changes: 4 additions & 3 deletions test/invariant/Invariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,17 @@ abstract contract PSMInvariantTestBase is PSMTestBase {

// When all funds are completely withdrawn, the sum of all funds withdrawn is equal to the
// sum of value of all LPs including the burn address. All rounding errors get reduced to
// a few wei.
// a few wei. Using 20 as a low tolerance that still allows for high rounding errors with
// large rate changes in long campaigns.
assertApproxEqAbs(
sumLpValue + _getLpTokenValue(BURN_ADDRESS),
sumStartingValue + startingSeedValue,
6
20
);

// All funds can always be withdrawn completely (rounding in withdrawal against users).
assertEq(psm.totalShares(), 0);
assertLe(psm.totalAssets(), 5);
assertLe(psm.totalAssets(), 20);
}

function _warpAndAssertConsistentValueAccrual() public {
Expand Down
16 changes: 8 additions & 8 deletions test/invariant/handlers/SwapperHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ contract SwapperHandler is HandlerBase {
assertApproxEqAbs(
psm.convertToAssetValue(1e18),
startingConversion,
2e12,
3e12,
"SwapperHandler/swapExactIn/conversion-rate-change"
);

// Demonstrate rounding scales with shares
assertApproxEqAbs(
psm.convertToAssetValue(1_000_000e18),
startingConversionMillion,
2_000_000e12, // 2e18 of value
3_000_000e12, // 2e18 of value
"SwapperHandler/swapExactIn/conversion-rate-change-million"
);

Expand Down Expand Up @@ -284,15 +284,15 @@ contract SwapperHandler is HandlerBase {
assertApproxEqAbs(
psm.convertToAssetValue(1e18),
startingConversion,
2e12,
3e12,
"SwapperHandler/swapExactOut/conversion-rate-change"
);

// Demonstrate rounding scales with shares
assertApproxEqAbs(
psm.convertToAssetValue(1_000_000e18),
startingConversionMillion,
2_000_000e12, // 2e18 of value
3_000_000e12, // 2e18 of value
"SwapperHandler/swapExactOut/conversion-rate-change-million"
);

Expand All @@ -305,11 +305,11 @@ contract SwapperHandler is HandlerBase {

// 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
// Position values can fluctuate by up to 0.00000003% on swaps
assertApproxEqRel(
psm.convertToAssetValue(psm.shares(lp0)),
startingConversionLp0,
0.000002e18,
0.000003e18,
"SwapperHandler/swapExactOut/conversion-rate-change-lp"
);
}
Expand All @@ -321,11 +321,11 @@ contract SwapperHandler is HandlerBase {
"SwapperHandler/swapExactOut/conversion-rate-lp-decrease"
);

// PSM value can fluctuate by up to 0.00000002% on swaps because of USDC rounding
// PSM value can fluctuate by up to 0.00000003% on swaps because of USDC rounding
assertApproxEqRel(
psm.totalAssets(),
startingValue,
0.000002e18,
0.000003e18,
"SwapperHandler/swapExactOut/psm-total-value-change"
);

Expand Down

0 comments on commit e7c8060

Please sign in to comment.