From d60f7475095061f183d5421a8a8e0233acafff31 Mon Sep 17 00:00:00 2001 From: "A.L." Date: Thu, 2 Jan 2025 02:38:11 +0800 Subject: [PATCH] fix: #44 --- script/optimized-deployer-meta | 4 ++-- src/ReservoirDeployer.sol | 4 ++-- src/ReservoirPair.sol | 3 ++- test/__fixtures/BaseTest.sol | 25 +++++++++++++++++++++++++ test/unit/OracleWriter.t.sol | 3 ++- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/script/optimized-deployer-meta b/script/optimized-deployer-meta index 9c806c49..57663017 100644 --- a/script/optimized-deployer-meta +++ b/script/optimized-deployer-meta @@ -1,5 +1,5 @@ { - "constant_product_hash": "0xfd8e7b0b3c9dcfb5936cdaf3c1cfcffa1e654c45f2f9be25d89297e386bffaa9", + "constant_product_hash": "0x052472f6087a3c2142419a6ff05fb32a4262d608be7a7685cf82cbd033d1c94f", "factory_hash": "0x87b0f73fafcf4bb41e013c8423dc679f6885527007d6c3f1e1834a670cbaadc5", - "stable_hash": "0x615cc03e937a1417dbd5ffe447a11a868e90c2d537eb336edef0e5bbda053320" + "stable_hash": "0xc933ce2881ba083c171250e7da252ca668b49b855f458e5631fa882a578216b0" } \ No newline at end of file diff --git a/src/ReservoirDeployer.sol b/src/ReservoirDeployer.sol index 2c260fbd..b7e6af68 100644 --- a/src/ReservoirDeployer.sol +++ b/src/ReservoirDeployer.sol @@ -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; diff --git a/src/ReservoirPair.sol b/src/ReservoirPair.sol index 3c7a1f19..1c122c2c 100644 --- a/src/ReservoirPair.sol +++ b/src/ReservoirPair.sol @@ -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 diff --git a/test/__fixtures/BaseTest.sol b/test/__fixtures/BaseTest.sol index 3c896543..fe0324e5 100644 --- a/test/__fixtures/BaseTest.sol +++ b/test/__fixtures/BaseTest.sol @@ -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"); + + vm.store(address(aPair), lAccesses[0], lEncoded); + } + function _skip(uint256 aTime) internal { vm.roll(vm.getBlockNumber() + 1); skip(aTime); diff --git a/test/unit/OracleWriter.t.sol b/test/unit/OracleWriter.t.sol index 0f218f06..c50545fb 100644 --- a/test/unit/OracleWriter.t.sol +++ b/test/unit/OracleWriter.t.sol @@ -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