Skip to content

Commit

Permalink
fix: #44
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Jan 1, 2025
1 parent 35df5ed commit d60f747
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions script/optimized-deployer-meta
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"constant_product_hash": "0xfd8e7b0b3c9dcfb5936cdaf3c1cfcffa1e654c45f2f9be25d89297e386bffaa9",
"constant_product_hash": "0x052472f6087a3c2142419a6ff05fb32a4262d608be7a7685cf82cbd033d1c94f",
"factory_hash": "0x87b0f73fafcf4bb41e013c8423dc679f6885527007d6c3f1e1834a670cbaadc5",
"stable_hash": "0x615cc03e937a1417dbd5ffe447a11a868e90c2d537eb336edef0e5bbda053320"
"stable_hash": "0xc933ce2881ba083c171250e7da252ca668b49b855f458e5631fa882a578216b0"
}
4 changes: 2 additions & 2 deletions src/ReservoirDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ contract ReservoirDeployer {
// Bytecode hashes.
bytes32 public constant FACTORY_HASH = bytes32(0x87b0f73fafcf4bb41e013c8423dc679f6885527007d6c3f1e1834a670cbaadc5);
bytes32 public constant CONSTANT_PRODUCT_HASH =
bytes32(0xfd8e7b0b3c9dcfb5936cdaf3c1cfcffa1e654c45f2f9be25d89297e386bffaa9);
bytes32 public constant STABLE_HASH = bytes32(0x615cc03e937a1417dbd5ffe447a11a868e90c2d537eb336edef0e5bbda053320);
bytes32(0x052472f6087a3c2142419a6ff05fb32a4262d608be7a7685cf82cbd033d1c94f);
bytes32 public constant STABLE_HASH = bytes32(0xc933ce2881ba083c171250e7da252ca668b49b855f458e5631fa882a578216b0);

// Deployment addresses.
GenericFactory public factory;
Expand Down
3 changes: 2 additions & 1 deletion src/ReservoirPair.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ abstract contract ReservoirPair is IAssetManagedPair, ReservoirERC20, RGT {
// a new sample is not written for the first mint
// shortcut to calculate lTimeElapsed > 0 && aReserve0 > 0 && aReserve1 > 0
if (lTimeElapsed * aReserve0 * aReserve1 > 0) {
if (lPrevious.timestamp != 0) assert(aBlockTimestampLast == lPrevious.timestamp);
(, int256 lLogInstantClampedPrice) = _calcClampedPrice(
lInstantRawPrice,
lLogInstantRawPrice,
LogCompression.fromLowResLog(lPrevious.logInstantClampedPrice),
lTimeElapsed,
aBlockTimestampLast // assert: aBlockTimestampLast == lPrevious.timestamp
aBlockTimestampLast
);
_updateOracleNewSample(
lPrevious, lLogInstantRawPrice, lLogInstantClampedPrice, lTimeElapsed, lBlockTimestamp, aIndex
Expand Down
25 changes: 25 additions & 0 deletions test/__fixtures/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,31 @@ abstract contract BaseTest is Test {
vm.store(address(aPair), lAccesses[0], lEncoded);
}

function _writeReserves(
ReservoirPair aPair,
uint256 aReserve0,
uint256 aReserve1,
uint32 aBlocktimestampLast,
uint16 aIndex
) internal {
bytes32 lEncoded = bytes32(
bytes.concat(
bytes2(aIndex),
bytes4(aBlocktimestampLast),
bytes13(uint104(aReserve1)),
bytes13(uint104(aReserve0))
)
);

vm.record();
aPair.getReserves();

(bytes32[] memory lAccesses,) = vm.accesses(address(aPair));
if (lAccesses.length != 1) console2.log("warn: invalid number of accesses");

Check failure on line 174 in test/__fixtures/BaseTest.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

vm.store(address(aPair), lAccesses[0], lEncoded);
}

function _skip(uint256 aTime) internal {
vm.roll(vm.getBlockNumber() + 1);
skip(aTime);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/OracleWriter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,9 @@ contract OracleWriterTest is BaseTest {

function testOracle_OverflowAccPrice(uint32 aNewStartTime) public randomizeStartTime(aNewStartTime) allPairs {
// arrange - make the last observation close to overflowing
(,,, uint16 lIndex) = _pair.getReserves();
(uint104 lReserve0, uint104 lReserve1,, uint16 lIndex) = _pair.getReserves();
_writeObservation(_pair, lIndex, 1e3, 1e3, type(int88).max, type(int88).max, uint32(block.timestamp % 2 ** 31));
_writeReserves(_pair, lReserve0, lReserve1, uint32(block.timestamp % 2 ** 31), lIndex);
Observation memory lPrevObs = _pair.observation(lIndex);

// act
Expand Down

0 comments on commit d60f747

Please sign in to comment.