From 8d199595e2f4248867c26ad71d85bdfc02689331 Mon Sep 17 00:00:00 2001 From: jmendiola222 Date: Wed, 27 Nov 2024 12:47:57 -0300 Subject: [PATCH] chore: add dust tolerance on invariants --- test/invariant/BaseInvariants.sol | 2 ++ test/invariant/RewardInvariants.t.sol | 15 +++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/test/invariant/BaseInvariants.sol b/test/invariant/BaseInvariants.sol index efa160ae..9e48d875 100644 --- a/test/invariant/BaseInvariants.sol +++ b/test/invariant/BaseInvariants.sol @@ -10,6 +10,8 @@ import { DistributionHandler } from "./handlers/DistributionHandler.sol"; import { IncentivizeHandler } from "./handlers/IncentivizeHandler.sol"; contract BaseInvariants is BaseTest { + uint256 constant DUST = 10_000; + TimeManager public timeManager; BuilderHandler public builderHandler; AllocateHandler public allocateHandler; diff --git a/test/invariant/RewardInvariants.t.sol b/test/invariant/RewardInvariants.t.sol index c47d7996..f4edab2e 100644 --- a/test/invariant/RewardInvariants.t.sol +++ b/test/invariant/RewardInvariants.t.sol @@ -43,19 +43,18 @@ contract RewardInvariants is BaseInvariants { _totalGaugesBalances + _backersManagerBalance + _totalBuilderBalances + _totalBackersBalances ); - assertLe(_backersManagerBalance, 10_000); + assertLe(_backersManagerBalance, DUST); for (uint256 i = 0; i < gaugesArray.length; i++) { + uint256 _gaugeBalance = rewardToken.balanceOf(address(gaugesArray[i])); + uint256 _gaugeAccountedBalance; if (gaugesArray[i].totalAllocation() > 0) { - uint256 _gaugeBalance = rewardToken.balanceOf(address(gaugesArray[i])) - - gaugesArray[i].rewardMissing(address(rewardToken)) / 10 ** 18; - assertLe(_gaugeBalance, 10_000); + _gaugeAccountedBalance = gaugesArray[i].rewardMissing(address(rewardToken)) / 10 ** 18; } else { - assertEq( - rewardToken.balanceOf(address(gaugesArray[i])), - incentivizeHandler.rewardTokenIncentives(gaugesArray[i]) - ); + _gaugeAccountedBalance = incentivizeHandler.rewardTokenIncentives(gaugesArray[i]); } + // There might be dust from previous cycles + assertLe(_gaugeBalance - _gaugeAccountedBalance, DUST); } } }