Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

C4 univ3 fixes #122

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 11 additions & 7 deletions contracts/OverlayV1UniswapV3Market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ contract OverlayV1UniswapV3Market is OverlayV1Market {
_priceFrameCap
) {

require(_microWindow < _macroWindow, "OVLV1:micro>=macro");

// immutables
eth = _eth;
ethIs0 = IUniswapV3Pool(_ovlFeed).token0() == _eth;
ovlFeed = _ovlFeed;
marketFeed = _marketFeed;
baseAmount = _baseAmount;
Expand All @@ -57,6 +58,9 @@ contract OverlayV1UniswapV3Market is OverlayV1Market {
address _token0 = IUniswapV3Pool(_marketFeed).token0();
address _token1 = IUniswapV3Pool(_marketFeed).token1();

require(_token0 == _eth || _token1 == _eth, "OVLV1:token!=WETH");

ethIs0 = _token0 == _eth;
base = _token0 != _quote ? _token0 : _token1;
quote = _token0 == _quote ? _token0 : _token1;

Expand All @@ -67,8 +71,8 @@ contract OverlayV1UniswapV3Market is OverlayV1Market {
);

_pricePoints.push(PricePoint(
_tick,
_tick,
_tick,
_tick,
0
));

Expand Down Expand Up @@ -141,16 +145,16 @@ contract OverlayV1UniswapV3Market is OverlayV1Market {
}

price_ = PricePoint(
_microTick,
_macroTick,
_microTick,
_macroTick,
computeDepth(_marketLiquidity, _ovlPrice)
);

}


/// @notice Arithmetic to get depth
/// @dev Derived from cnstant product formula X*Y=K and tailored
/// @dev Derived from cnstant product formula X*Y=K and tailored
/// to Uniswap V3 selective liquidity provision.
/// @param _marketLiquidity Amount of liquidity in market in ETH terms.
/// @param _ovlPrice Price of OVL against ETH.
Expand All @@ -163,7 +167,7 @@ contract OverlayV1UniswapV3Market is OverlayV1Market {
) {

depth_ = ((_marketLiquidity * 1e18) / _ovlPrice)
.mulUp(lmbda)
.mulUp(lmbda)
.divDown(2e18);

}
Expand Down
6 changes: 3 additions & 3 deletions contracts/shims/ComptrollerShim.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ contract ComptrollerShim is OverlayV1Comptroller {
microWindow = _priceWindowMicro;
marketFeed = _marketFeed;
ovlFeed = _ovlFeed;
ethIs0 = IUniswapV3Pool(_ovlFeed).token0() == _eth;
ethIs0 = IUniswapV3Pool(_marketFeed).token0() == _eth;

}

Expand All @@ -84,14 +84,14 @@ contract ComptrollerShim is OverlayV1Comptroller {
) {

depth_ = ((_marketLiquidity * 1e18) / _ovlPrice)
.mulUp(lmbda)
.mulUp(lmbda)
.divDown(2e18);

}

function readFeed () public view returns (
uint256 depth_
) {
) {

int56[] memory _ticks;
uint160[] memory _liqs;
Expand Down