From 1ad59370b421165fa8235dd484257f710b49ef8a Mon Sep 17 00:00:00 2001 From: "A.L" Date: Thu, 14 Mar 2024 18:37:55 +0800 Subject: [PATCH] docs: update docs --- script/optimized-deployer-meta | 8 ++++---- src/ReservoirDeployer.sol | 8 ++++---- src/ReservoirPair.sol | 16 +++++++--------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/script/optimized-deployer-meta b/script/optimized-deployer-meta index 4d07176d..df22228f 100644 --- a/script/optimized-deployer-meta +++ b/script/optimized-deployer-meta @@ -1,6 +1,6 @@ { - "constant_product_hash": "0x6b37069ad34cca2a7a7d3a8ed052f775eda0bec3d704c9ac5b6f9402c44b4765", - "factory_hash": "0xd8a0495564d5556148a54de0b0074f4171da381bb172a684a90378592e37e0f8", - "oracle_caller_hash": "0x401f8cdddb19e47b49df421d81efc922b706e72f2f7d84af19c3b7ad5cf2b2e1", - "stable_hash": "0x7172144b5b8e564ba70205fa2337a9eab5e081b953d7ca079491221904a402d5" + "constant_product_hash": "0xa0719fd65c4db1b8f15ac06274344fb7c121fa84bcfc2f854a2c7fd3b0a8de13", + "factory_hash": "0xf8f34d4275709774705694daa526ffbb6c91f1c875c3af2049cc1690d9326ffc", + "oracle_caller_hash": "0x2a0f1f77423fb968788cf68a9638c9ed5eb16ab66a050dfde6bf18dfe8bdb2c3", + "stable_hash": "0xff427f388472489d39aaeee6d9f34588d56ca65960369a26e8aa59e36e494078" } \ No newline at end of file diff --git a/src/ReservoirDeployer.sol b/src/ReservoirDeployer.sol index 54a432e2..9b7e04bc 100644 --- a/src/ReservoirDeployer.sol +++ b/src/ReservoirDeployer.sol @@ -17,12 +17,12 @@ contract ReservoirDeployer { uint256 public step = 0; // Bytecode hashes. - bytes32 public constant FACTORY_HASH = bytes32(0xd8a0495564d5556148a54de0b0074f4171da381bb172a684a90378592e37e0f8); + bytes32 public constant FACTORY_HASH = bytes32(0xf8f34d4275709774705694daa526ffbb6c91f1c875c3af2049cc1690d9326ffc); bytes32 public constant CONSTANT_PRODUCT_HASH = - bytes32(0x6b37069ad34cca2a7a7d3a8ed052f775eda0bec3d704c9ac5b6f9402c44b4765); - bytes32 public constant STABLE_HASH = bytes32(0x7172144b5b8e564ba70205fa2337a9eab5e081b953d7ca079491221904a402d5); + bytes32(0xa0719fd65c4db1b8f15ac06274344fb7c121fa84bcfc2f854a2c7fd3b0a8de13); + bytes32 public constant STABLE_HASH = bytes32(0xff427f388472489d39aaeee6d9f34588d56ca65960369a26e8aa59e36e494078); bytes32 public constant ORACLE_CALLER_HASH = - bytes32(0x401f8cdddb19e47b49df421d81efc922b706e72f2f7d84af19c3b7ad5cf2b2e1); + bytes32(0x2a0f1f77423fb968788cf68a9638c9ed5eb16ab66a050dfde6bf18dfe8bdb2c3); // Deployment addresses. GenericFactory public factory; diff --git a/src/ReservoirPair.sol b/src/ReservoirPair.sol index 74923839..97d5aca0 100644 --- a/src/ReservoirPair.sol +++ b/src/ReservoirPair.sol @@ -135,8 +135,11 @@ abstract contract ReservoirPair is IAssetManagedPair, ReservoirERC20 { _writeSlot0Timestamp(sSlot0, aBlockTimestampLast, false); } - // update reserves with new balances - // on the first call per block, update price oracle using previous reserves + /// @notice update reserves with new balances + /// @notice on the first call per block, accumulate price oracle using previous instant prices and write the new instant prices + /// @dev we write an oracle sample even at the time of pair creation. Also we do not update instant prices for + /// subsequent mint/burn/swaps in the same block. the team has assessed that this is a small risk given the very + /// fast block times on L2s and has decided to make the tradeoff to minimize complexity function _updateAndUnlock( Slot0 storage sSlot0, uint256 aBalance0, @@ -156,13 +159,8 @@ abstract contract ReservoirPair is IAssetManagedPair, ReservoirERC20 { lTimeElapsed = lBlockTimestamp - aBlockTimestampLast; // both balance should never be zero, but necessary to check so we don't pass 0 values into arithmetic operations - // on the first activity of every block, accumulate using previous instant prices and write the current instant prices - // we create a new sample even at the time of pair creation - // this implies that we do not update instant prices for subsequent mint/burn/swaps in the same block - // but the team has assessed that this is a small risk given the very fast block times on L2s - // and has decided to make the tradeoff to minimize complexity - if (lTimeElapsed * aBalance0 * aBalance1 > 0 ) { - + // shortcut to calculate lTimeElapsed > 0 && aBalance0 > 0 && aBalance1 > 0 + if (lTimeElapsed * aBalance0 * aBalance1 > 0) { Observation storage lPrevious = _observations[sSlot0.index]; (uint256 lInstantRawPrice, int256 lLogInstantRawPrice) = _calcSpotAndLogPrice(aBalance0, aBalance1);