Skip to content

Commit

Permalink
Always rewrite PIP_MKR price in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
telome committed Dec 14, 2023
1 parent 767f0c3 commit 4b56174
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/Splitter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,14 @@ contract SplitterTest is DssTest {
(uint256 reserveDai, ) = UniswapV2Library.getReserves(UNIV2_FACTORY, DAI, MKR);
uint256 minimalDaiReserve = 280_000 * WAD;
if (reserveDai < minimalDaiReserve) {
changeMedianizerPrice(727 * WAD);
changeUniV2Price(medianizer.read(), MKR, UNIV2_DAI_MKR_PAIR);
(reserveDai, ) = UniswapV2Library.getReserves(UNIV2_FACTORY, DAI, MKR);
if(reserveDai < minimalDaiReserve) {
topUpLiquidity(minimalDaiReserve - reserveDai, MKR, UNIV2_DAI_MKR_PAIR);
}
} else {
changeMedianizerPrice(uniV2DaiForGem(WAD, MKR));
}

// Create additional surplus if needed
Expand Down Expand Up @@ -218,6 +221,10 @@ contract SplitterTest is DssTest {
PairLike(pair).sync();
}

function changeMedianizerPrice(uint256 daiForGem) internal {
vm.store(address(medianizer), bytes32(uint256(1)), bytes32(block.timestamp << 128 | daiForGem));
}

function topUpLiquidity(uint256 daiAmt, address gem, address pair) internal {
(uint256 reserveDai, uint256 reserveGem) = UniswapV2Library.getReserves(UNIV2_FACTORY, DAI, gem);
uint256 gemAmt = UniswapV2Library.quote(daiAmt, reserveDai, reserveGem);
Expand Down

0 comments on commit 4b56174

Please sign in to comment.