Skip to content

Commit

Permalink
feat: invariant tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-manuel committed Jul 4, 2024
1 parent 281637b commit 09c95b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions test/invariant/Invariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,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, block.timestamp);
timeBasedRateHandler.setPotData(1e27);

targetContract(address(lpHandler));
targetContract(address(swapperHandler));
Expand All @@ -521,7 +521,7 @@ contract PSMInvariants_TimeBasedRateSetting_NoTransfer is PSMInvariantTestBase {
assertEq(swapperHandler.lp0(), lpHandler.lps(0));
}

function invariant_A() public view {
function invariant_A_test() public view {
_checkInvariant_A();
}

Expand Down Expand Up @@ -575,7 +575,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, block.timestamp);
timeBasedRateHandler.setPotData(1e27);

targetContract(address(lpHandler));
targetContract(address(swapperHandler));
Expand Down
8 changes: 5 additions & 3 deletions test/invariant/handlers/TimeBasedRateHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { IDSROracle } from "lib/xchain-dsr-oracle/src/interfaces/IDSROracle.s
contract TimeBasedRateHandler is HandlerBase, StdCheats {

uint256 public dsr;
uint256 public rho;

uint256 constant ONE_HUNDRED_PCT_APY_DSR = 1.000000021979553151239153027e27;

Expand All @@ -25,10 +24,13 @@ contract TimeBasedRateHandler is HandlerBase, StdCheats {
}

// This acts as a receiver on an L2.
function setPotData(uint256 newDsr, uint256 newRho) external {
// TODO: Discuss if rho should be set to a value between last rho and block.timestamp.
// This was the original approach but was causing the conversion rate to decrease.
function setPotData(uint256 newDsr) external {
// 1. Setup and bounds
dsr = _bound(newDsr, 1e27, ONE_HUNDRED_PCT_APY_DSR);
rho = _bound(newRho, rho, block.timestamp);

uint256 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 at `rho`
Expand Down

0 comments on commit 09c95b2

Please sign in to comment.