Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renames Ovl for Ov #148

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contracts/OverlayV1Market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 24 additions & 24 deletions contracts/feeds/uniswapv3/OverlayV1UniswapV3Feed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
);

Expand Down Expand Up @@ -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);
(int24[] memory arithmeticMeanTicksOvlX, ) = consult(
uint32[] memory secondsAgosOvX,
uint32[] memory windowsOvX,
uint256[] memory nowIdxsOvX
) = _inputsToConsultOvXPool(microWindow);
(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
Expand Down Expand Up @@ -225,7 +225,7 @@ contract OverlayV1UniswapV3Feed is IOverlayV1UniswapV3Feed, OverlayV1Feed {
}

/// @dev returns input params needed for call to ovXPool consult
function _inputsToConsultOvlXPool(uint256 _microWindow)
function _inputsToConsultOvXPool(uint256 _microWindow)
private
pure
returns (
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions tests/feeds/uniswapv3/test_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/feeds/uniswapv3/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/markets/test_oi_cap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading