From 4a1e43d6a936ec25734708634f3d434cfcdf21bf Mon Sep 17 00:00:00 2001 From: lucas-manuel Date: Thu, 4 Jul 2024 06:29:10 -0400 Subject: [PATCH] fix: update dsr value, change chi approach --- test/invariant/Invariants.t.sol | 4 ++-- test/invariant/handlers/TimeBasedRateHandler.sol | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/test/invariant/Invariants.t.sol b/test/invariant/Invariants.t.sol index e336e92..39c6faf 100644 --- a/test/invariant/Invariants.t.sol +++ b/test/invariant/Invariants.t.sol @@ -352,7 +352,7 @@ contract PSMInvariants_TimeBasedRateSetting_NoTransfer is PSMInvariantTestBase { rateProvider = IRateProviderLike(address(dsrOracle)); // Manually set initial values for the oracle through the handler to start - timeBasedRateHandler.setPotData(1e27, 1e27, block.timestamp); + timeBasedRateHandler.setPotData(1e27, block.timestamp); targetContract(address(lpHandler)); targetContract(address(swapperHandler)); @@ -402,7 +402,7 @@ contract PSMInvariants_TimeBasedRateSetting_WithTransfers is PSMInvariantTestBas rateProvider = IRateProviderLike(address(dsrOracle)); // Manually set initial values for the oracle through the handler to start - timeBasedRateHandler.setPotData(1e27, 1e27, block.timestamp); + timeBasedRateHandler.setPotData(1e27, block.timestamp); targetContract(address(lpHandler)); targetContract(address(swapperHandler)); diff --git a/test/invariant/handlers/TimeBasedRateHandler.sol b/test/invariant/handlers/TimeBasedRateHandler.sol index e97298a..2eee7d2 100644 --- a/test/invariant/handlers/TimeBasedRateHandler.sol +++ b/test/invariant/handlers/TimeBasedRateHandler.sol @@ -13,7 +13,7 @@ contract TimeBasedRateHandler is StdCheats, StdUtils { uint256 public chi; uint256 public rho; - uint256 constant ONE_HUNDRED_PCT_APY_DSR = 1.00000002197955315123915302e27; + uint256 constant ONE_HUNDRED_PCT_APY_DSR = 1.000000021979553151239153027e27; DSRAuthOracle public dsrOracle; @@ -24,13 +24,15 @@ contract TimeBasedRateHandler is StdCheats, StdUtils { } // This acts as a receiver on an L2. - // Note that the chi value is not derived from previous values, this is to test if - // PSM will work as expected with different chi values. - function setPotData(uint256 newDsr, uint256 newChi, uint256 newRho) external { + function setPotData(uint256 newDsr, uint256 newRho) external { dsr = _bound(newDsr, 1e27, ONE_HUNDRED_PCT_APY_DSR); - chi = _bound(newChi, chi, 1e27); rho = _bound(newRho, rho, block.timestamp); + // If chi hasn't been set yet, set to 1e27, else recalculate it in the same way it would + // happen during a refresh. + uint256 rate = dsrOracle.getConversionRate(); + uint256 chi = rate == 0 ? 1e27 : rate; + dsrOracle.setPotData(IDSROracle.PotData({ dsr: uint96(dsr), chi: uint120(chi),