From 6f0c11a4eba73c809f2a0875bd292c28f79ea9f6 Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 16 Jan 2024 18:10:48 +0000 Subject: [PATCH 1/2] Renames Ovl for Ov --- contracts/OverlayV1Market.sol | 4 +- .../uniswapv3/OverlayV1UniswapV3Feed.sol | 48 +++++++++---------- .../uniswapv3/IOverlayV1UniswapV3Feed.sol | 6 +-- tests/feeds/uniswapv3/test_latest.py | 16 +++---- tests/feeds/uniswapv3/test_views.py | 2 +- tests/markets/test_oi_cap.py | 2 +- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/contracts/OverlayV1Market.sol b/contracts/OverlayV1Market.sol index a93743d9..250b7f7c 100644 --- a/contracts/OverlayV1Market.sol +++ b/contracts/OverlayV1Market.sol @@ -633,14 +633,14 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { } /// @dev bound on notional cap to mitigate front-running attack - /// @dev bound = lmbda * reserveInOvl + /// @dev bound = lmbda * reserveInOv function frontRunBound(Oracle.Data memory data) public view returns (uint256) { uint256 lmbda = params.get(Risk.Parameters.Lmbda); return lmbda.mulDown(data.reserveOverMicroWindow); } /// @dev bound on notional cap to mitigate back-running attack - /// @dev bound = macroWindowInBlocks * reserveInOvl * 2 * delta + /// @dev bound = macroWindowInBlocks * reserveInOv * 2 * delta function backRunBound(Oracle.Data memory data) public view returns (uint256) { uint256 averageBlockTime = params.get(Risk.Parameters.AverageBlockTime); uint256 window = (data.macroWindow * ONE) / averageBlockTime; diff --git a/contracts/feeds/uniswapv3/OverlayV1UniswapV3Feed.sol b/contracts/feeds/uniswapv3/OverlayV1UniswapV3Feed.sol index 713e73a5..52231c23 100644 --- a/contracts/feeds/uniswapv3/OverlayV1UniswapV3Feed.sol +++ b/contracts/feeds/uniswapv3/OverlayV1UniswapV3Feed.sol @@ -41,7 +41,7 @@ contract OverlayV1UniswapV3Feed is IOverlayV1UniswapV3Feed, OverlayV1Feed { uint256 _microWindow, uint256 _macroWindow, uint256 _cardinalityMarketMinimum, - uint256 _cardinalityOvlXMinimum + uint256 _cardinalityOvXMinimum ) OverlayV1Feed(_microWindow, _macroWindow) { // determine X token // need OV/X pool for ov vs X price to make reserve conversion from X => OV @@ -72,9 +72,9 @@ contract OverlayV1UniswapV3Feed is IOverlayV1UniswapV3Feed, OverlayV1Feed { // check observation cardinality large enough for market and // ov pool on deploy - (, , , uint16 observationCardinalityOvlX, , , ) = IUniswapV3Pool(_ovXPool).slot0(); + (, , , uint16 observationCardinalityOvX, , , ) = IUniswapV3Pool(_ovXPool).slot0(); require( - observationCardinalityOvlX >= _cardinalityOvlXMinimum, + observationCardinalityOvX >= _cardinalityOvXMinimum, "OVV1: ovXCardinality < min" ); @@ -134,35 +134,35 @@ contract OverlayV1UniswapV3Feed is IOverlayV1UniswapV3Feed, OverlayV1Feed { // reserve calculation done over window: [now - microWindow, now] // needs ovX price over micro to convert into OV terms from X - // get mean ticks of X in OV to convert reserveInX to reserveInOvl - int24 arithmeticMeanTickOvlX; + // get mean ticks of X in OV to convert reserveInX to reserveInOv + int24 arithmeticMeanTickOvX; if (marketPool == ovXPool) { // simply mean ticks over the micro window of market pool // NOTE: saves the additional consult call to ovXPool - arithmeticMeanTickOvlX = arithmeticMeanTicksMarket[2]; + arithmeticMeanTickOvX = arithmeticMeanTicksMarket[2]; } else { // consult to ovX pool // secondsAgo.length = 2; twaps.length = liqs.length = 1 ( - uint32[] memory secondsAgosOvlX, - uint32[] memory windowsOvlX, - uint256[] memory nowIdxsOvlX - ) = _inputsToConsultOvlXPool(microWindow, macroWindow); - (int24[] memory arithmeticMeanTicksOvlX, ) = consult( + uint32[] memory secondsAgosOvX, + uint32[] memory windowsOvX, + uint256[] memory nowIdxsOvX + ) = _inputsToConsultOvXPool(microWindow, macroWindow); + (int24[] memory arithmeticMeanTicksOvX, ) = consult( ovXPool, - secondsAgosOvlX, - windowsOvlX, - nowIdxsOvlX + secondsAgosOvX, + windowsOvX, + nowIdxsOvX ); - arithmeticMeanTickOvlX = arithmeticMeanTicksOvlX[0]; + arithmeticMeanTickOvX = arithmeticMeanTicksOvX[0]; } // reserve is the reserve in marketPool over micro window // window: [now - microWindow, now] - uint256 reserve = getReserveInOvl( + uint256 reserve = getReserveInOv( arithmeticMeanTicksMarket[2], harmonicMeanLiquiditiesMarket[2], - arithmeticMeanTickOvlX + arithmeticMeanTickOvX ); return @@ -225,7 +225,7 @@ contract OverlayV1UniswapV3Feed is IOverlayV1UniswapV3Feed, OverlayV1Feed { } /// @dev returns input params needed for call to ovXPool consult - function _inputsToConsultOvlXPool(uint256 _microWindow, uint256 _macroWindow) + function _inputsToConsultOvXPool(uint256 _microWindow, uint256 _macroWindow) private pure returns ( @@ -247,7 +247,7 @@ contract OverlayV1UniswapV3Feed is IOverlayV1UniswapV3Feed, OverlayV1Feed { // window lengths for each cumulative differencing // in terms of prices, will use for indexes - // 0: priceOvlXOverMicroWindow + // 0: priceOvXOverMicroWindow windows[0] = uint32(_microWindow); // index in secondsAgos which we treat as current time when differencing @@ -332,14 +332,14 @@ contract OverlayV1UniswapV3Feed is IOverlayV1UniswapV3Feed, OverlayV1Feed { } /// @dev virtual balance of X in the pool in OV terms - function getReserveInOvl( + function getReserveInOv( int24 arithmeticMeanTickMarket, uint128 harmonicMeanLiquidityMarket, - int24 arithmeticMeanTickOvlX - ) public view returns (uint256 reserveInOvl_) { + int24 arithmeticMeanTickOvX + ) public view returns (uint256 reserveInOv_) { uint256 reserveInX = getReserveInX(arithmeticMeanTickMarket, harmonicMeanLiquidityMarket); - uint256 amountOfXPerOvl = getQuoteAtTick(arithmeticMeanTickOvlX, ONE, ov, x); - reserveInOvl_ = FullMath.mulDiv(reserveInX, uint256(ONE), amountOfXPerOvl); + uint256 amountOfXPerOv = getQuoteAtTick(arithmeticMeanTickOvX, ONE, ov, x); + reserveInOv_ = FullMath.mulDiv(reserveInX, uint256(ONE), amountOfXPerOv); } /// @dev virtual balance of X in the pool diff --git a/contracts/interfaces/feeds/uniswapv3/IOverlayV1UniswapV3Feed.sol b/contracts/interfaces/feeds/uniswapv3/IOverlayV1UniswapV3Feed.sol index 5c6e5b96..7d1fd5c0 100644 --- a/contracts/interfaces/feeds/uniswapv3/IOverlayV1UniswapV3Feed.sol +++ b/contracts/interfaces/feeds/uniswapv3/IOverlayV1UniswapV3Feed.sol @@ -43,11 +43,11 @@ interface IOverlayV1UniswapV3Feed is IOverlayV1Feed { ) external view returns (uint256 quoteAmount_); // virtual balance of X in the pool in OV terms - function getReserveInOvl( + function getReserveInOv( int24 arithmeticMeanTickMarket, uint128 harmonicMeanLiquidityMarket, - int24 arithmeticMeanTickOvlX - ) external view returns (uint256 reserveInOvl_); + int24 arithmeticMeanTickOvX + ) external view returns (uint256 reserveInOv_); // virtual balance of X in the pool function getReserveInX(int24 arithmeticMeanTickMarket, uint128 harmonicMeanLiquidityMarket) diff --git a/tests/feeds/uniswapv3/test_latest.py b/tests/feeds/uniswapv3/test_latest.py index 40c8d054..109b53fc 100644 --- a/tests/feeds/uniswapv3/test_latest.py +++ b/tests/feeds/uniswapv3/test_latest.py @@ -60,11 +60,11 @@ def test_latest_updates_data_on_first_call_for_quanto_feed(pool_daiweth_30bps, reserves = [] has_reserve = True for i in range(len(now_idxs)): - # NOTE: getQuoteAtTick(), getReserveInOvl() tested in test_views.py + # NOTE: getQuoteAtTick(), getReserveInOv() tested in test_views.py price = quanto_feed.getQuoteAtTick( market_avg_ticks[i], market_base_amount, market_base_token, market_quote_token) - reserve = quanto_feed.getReserveInOvl( + reserve = quanto_feed.getReserveInOv( market_avg_ticks[i], market_avg_liqs[i], ovweth_avg_ticks[i]) prices.append(price) @@ -102,11 +102,11 @@ def test_latest_updates_data_on_first_call_for_inverse_feed(pool_uniweth_30bps, reserves = [] has_reserve = True for i in range(len(now_idxs)): - # NOTE: getQuoteAtTick(), getReserveInOvl() tested in test_views.py + # NOTE: getQuoteAtTick(), getReserveInOv() tested in test_views.py price = inverse_feed.getQuoteAtTick( market_avg_ticks[i], market_base_amount, market_base_token, market_quote_token) - reserve = inverse_feed.getReserveInOvl( + reserve = inverse_feed.getReserveInOv( market_avg_ticks[i], market_avg_liqs[i], ovweth_avg_ticks[i]) prices.append(price) @@ -148,11 +148,11 @@ def test_latest_updates_data_on_many_calls_for_quanto_feed(pool_daiweth_30bps, reserves = [] has_reserve = True for i in range(len(now_idxs)): - # NOTE: getQuoteAtTick(), getReserveInOvl() tested in test_views.py + # NOTE: getQuoteAtTick(), getReserveInOv() tested in test_views.py price = quanto_feed.getQuoteAtTick( market_avg_ticks[i], market_base_amount, market_base_token, market_quote_token) - reserve = quanto_feed.getReserveInOvl( + reserve = quanto_feed.getReserveInOv( market_avg_ticks[i], market_avg_liqs[i], ovweth_avg_ticks[i]) prices.append(price) @@ -229,11 +229,11 @@ def test_latest_updates_data_on_many_calls_for_inverse_feed(pool_uniweth_30bps, reserves = [] has_reserve = True for i in range(len(now_idxs)): - # NOTE: getQuoteAtTick(), getReserveInOvl() tested in test_views.py + # NOTE: getQuoteAtTick(), getReserveInOv() tested in test_views.py price = inverse_feed.getQuoteAtTick( market_avg_ticks[i], market_base_amount, market_base_token, market_quote_token) - reserve = inverse_feed.getReserveInOvl( + reserve = inverse_feed.getReserveInOv( market_avg_ticks[i], market_avg_liqs[i], ovweth_avg_ticks[i]) prices.append(price) diff --git a/tests/feeds/uniswapv3/test_views.py b/tests/feeds/uniswapv3/test_views.py index f6c755b7..ceb17f63 100644 --- a/tests/feeds/uniswapv3/test_views.py +++ b/tests/feeds/uniswapv3/test_views.py @@ -110,7 +110,7 @@ def test_get_reserve_in_ov(uni, weth, quanto_feed): expect_reserve_in_ov = int(expect_reserve * base_amount_ovweth / price_ovweth) - actual_reserve_in_ov = quanto_feed.getReserveInOvl(tick_market, liquidity, + actual_reserve_in_ov = quanto_feed.getReserveInOv(tick_market, liquidity, tick_ovweth) assert approx(expect_reserve_in_ov) == actual_reserve_in_ov diff --git a/tests/markets/test_oi_cap.py b/tests/markets/test_oi_cap.py index c10a2872..a4232acc 100644 --- a/tests/markets/test_oi_cap.py +++ b/tests/markets/test_oi_cap.py @@ -28,7 +28,7 @@ def test_cap_notional_back_run_bound(market, feed): average_block_time = market.params(RiskParameter.AVERAGE_BLOCK_TIME.value) _, _, macro_window, _, _, _, reserve_micro, _ = data - # check back run bound is macroWindowInBlocks * reserveInOvl * 2 * delta + # check back run bound is macroWindowInBlocks * reserveInOv * 2 * delta # when has reserve window = Decimal(macro_window) / Decimal(average_block_time) expect = int(Decimal(2) * delta * Decimal(reserve_micro) * window) From cbda4bf1e9a0af5ad1a0fbe40ab9edfe86ef37d8 Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 16 Jan 2024 20:29:05 +0000 Subject: [PATCH 2/2] fix unused param --- contracts/feeds/uniswapv3/OverlayV1UniswapV3Feed.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/feeds/uniswapv3/OverlayV1UniswapV3Feed.sol b/contracts/feeds/uniswapv3/OverlayV1UniswapV3Feed.sol index 47d96aaa..7a4fd872 100644 --- a/contracts/feeds/uniswapv3/OverlayV1UniswapV3Feed.sol +++ b/contracts/feeds/uniswapv3/OverlayV1UniswapV3Feed.sol @@ -147,7 +147,7 @@ contract OverlayV1UniswapV3Feed is IOverlayV1UniswapV3Feed, OverlayV1Feed { uint32[] memory secondsAgosOvX, uint32[] memory windowsOvX, uint256[] memory nowIdxsOvX - ) = _inputsToConsultOvXPool(microWindow, macroWindow); + ) = _inputsToConsultOvXPool(microWindow); (int24[] memory arithmeticMeanTicksOvX, ) = consult( ovXPool, secondsAgosOvX,