From a3f58b88ba19ae604dc1a46f55ec5b32cfea3094 Mon Sep 17 00:00:00 2001 From: sicknick99 Date: Sat, 11 Dec 2021 16:43:50 -0500 Subject: [PATCH] Comments on Market _update function and children --- contracts/market/OverlayV1Choreographer.sol | 6 ++ contracts/market/OverlayV1Comptroller.sol | 51 +++++++++--- contracts/market/OverlayV1Market.sol | 86 ++++++++++++--------- contracts/market/OverlayV1OI.sol | 46 ++++++----- contracts/market/OverlayV1PricePoint.sol | 52 +++++++++---- 5 files changed, 162 insertions(+), 79 deletions(-) diff --git a/contracts/market/OverlayV1Choreographer.sol b/contracts/market/OverlayV1Choreographer.sol index c4adb2d9..ec63363b 100644 --- a/contracts/market/OverlayV1Choreographer.sol +++ b/contracts/market/OverlayV1Choreographer.sol @@ -42,11 +42,17 @@ abstract contract OverlayV1Choreographer is _; } + // TODO struct Tempo { + // TODO uint32 updated; + // TODO uint32 compounded; + // TODO uint8 impactCycloid; + // TODO uint8 brrrrdCycloid; + // TODO uint32 brrrrdFiling; } diff --git a/contracts/market/OverlayV1Comptroller.sol b/contracts/market/OverlayV1Comptroller.sol index d0cb52bf..63763187 100644 --- a/contracts/market/OverlayV1Comptroller.sol +++ b/contracts/market/OverlayV1Comptroller.sol @@ -149,6 +149,13 @@ abstract contract OverlayV1Comptroller { } + /** + @dev Called by internal contract function: _oiCap + @dev Calls internal contract function: scry + @param _brrrrdCycloid TODO + @returns brrrrd_ TODO + @returns antiBrrrrd_ TODO + */ function getBrrrrd ( uint8 _brrrrdCycloid ) public view returns ( @@ -156,6 +163,7 @@ abstract contract OverlayV1Comptroller { uint antiBrrrrd_ ) { + // Call to internal contract function ( ,Roller memory _rollerNow, Roller memory _rollerThen ) = scry( getBrrrrdRoller, @@ -176,7 +184,7 @@ abstract contract OverlayV1Comptroller { @dev The impact is a measure of the demand placed on the market over a @dev rolling window. It determines the amount of collateral to be burnt. @dev This is akin to slippage in an order book model. - @dev Called by `OverlayV1Market` contract function: `enterOI` + @dev Called by OverlayV1Market contract function: enterOI @param _isLong Whether it is taking out open interest on the long or short side @param _oi The amount of open interest attempting to be taken out @param _cap The current open interest cap @@ -299,7 +307,7 @@ abstract contract OverlayV1Comptroller { has occurred. @param _brrrrdExpected How much the market expects to print before engaging the dynamic cap. Only passed if printing has occurred. - @dev Called by `OverlayV1Market` contract function: `update` + @dev Called by OverlayV1Market contract function: update */ function _computeOiCap ( bool _dynamic, @@ -320,14 +328,16 @@ abstract contract OverlayV1Comptroller { } - /** - @notice The open interest cap for the market - @dev Returns the open interest cap for the market. - @dev Called by `OverlayV1Market` contract function: `update` - @return cap_ The open interest cap. - */ function oiCap () public virtual view returns (uint cap_); + /** + @notice The open interest cap for the market. + @dev Called by OverlayV1Market contract function: update + @dev Calls internal contract function: getBrrrrd + @param _depth TODO + @param _brrrrdCycloid TODO + @return cap_ The open interest cap for the market + */ function _oiCap ( uint _depth, uint8 _brrrrdCycloid @@ -335,6 +345,7 @@ abstract contract OverlayV1Comptroller { uint cap_ ) { + // Calls internal contract function ( uint _brrrrd, uint _antiBrrrrd ) = getBrrrrd(_brrrrdCycloid); @@ -465,7 +476,9 @@ abstract contract OverlayV1Comptroller { /** @notice First part of retrieving historic roller values @dev Checks to see if the current roller is satisfactory and if not - searches deeper into the roller array. + @dev searches deeper into the roller array. + @dev Called by internal contract function: getBrrrrd + @dev Calls internal contract function: scryRollers @param _getter The getter for either impact or brrrrd rollers @param _chord The length of roller array in question @param _cycloid The current impact or brrrrd cycloid @@ -503,6 +516,7 @@ abstract contract OverlayV1Comptroller { } else if (_time != rollerNow_.time) rollerNow_.time = _time; + // Calls internal contract function rollerThen_ = scryRollers( _getter, _chord, @@ -513,6 +527,15 @@ abstract contract OverlayV1Comptroller { } + /** + @dev Called by internal contract function: scry + @dev Calls internal contract function: binarySearch + @param _getter TODO + @param _chord TODO + @param _cycloid TODO + @param _target TODO + @return beforeOrAt_ TODO + */ function scryRollers ( function (uint) internal view returns(Roller memory) _getter, uint _chord, @@ -542,6 +565,7 @@ abstract contract OverlayV1Comptroller { if ( beforeOrAt_.time <= 1 ) beforeOrAt_ = _getter(0); if (_target <= beforeOrAt_.time) return beforeOrAt_; + // Calls internal contract function else return binarySearch( _getter, uint16(_chord), @@ -551,6 +575,15 @@ abstract contract OverlayV1Comptroller { } + /** + @notice TODO + @dev Called by internal contract function: scryRollers + @param _getter TODO + @param _cycloid TODO + @param _chord TODO + @param _target TODO + @return beforeOrAt_ TODO + */ function binarySearch( function (uint) internal view returns(Roller memory) _getter, uint16 _cycloid, diff --git a/contracts/market/OverlayV1Market.sol b/contracts/market/OverlayV1Market.sol index f6da4186..f2d53035 100644 --- a/contracts/market/OverlayV1Market.sol +++ b/contracts/market/OverlayV1Market.sol @@ -31,18 +31,19 @@ abstract contract OverlayV1Market is OverlayV1Choreographer { @dev This is invoked by Overlay collateral manager contracts, which @dev can be for OVL, ERC20's, Overlay positions, NFTs, or what have you. @dev The calculations for impact and fees are performed here. - @dev Calls `OverlayV1Comptroller` contract function: `intake` - @dev Calls `Position` contract function: `mulDown` - @dev Calls `OverlayV1OI` contract function: `addOi` - @param _isLong The side of the market to enter open interest on. - @param _collateral The amount of collateral in OVL terms to take the position out with. - @param _leverage The leverage with which to take out the position. - @return oiAdjusted_ Amount of open interest after impact and fees. - @return collateralAdjusted_ Amount of collateral after impact and fees. - @return debtAdjusted_ Amount of debt after impact and fees. - @return exactedFee_ The protocol fee to be taken. - @return impact_ The market impact for the build. - @return pricePointNext_ The index of the price point for the position. + @dev Calls OverlayV1Choreographer contract struct: Tempo + @dev Calls OverlayV1Comptroller contract function: intake + @dev Calls Position contract function: mulDown + @dev Calls OverlayV1OI contract function: addOi + @param _isLong The side of the market to enter open interest on + @param _collateral The amount of collateral in OVL terms to take the position out with + @param _leverage The leverage with which to take out the position + @return oiAdjusted_ Amount of open interest after impact and fees + @return collateralAdjusted_ Amount of collateral after impact and fees + @return debtAdjusted_ Amount of debt after impact and fees + @return exactedFee_ The protocol fee to be taken + @return impact_ The market impact for the build + @return pricePointNext_ The index of the price point for the position */ function enterOI ( bool _isLong, @@ -59,13 +60,14 @@ abstract contract OverlayV1Market is OverlayV1Choreographer { ) { uint _cap; - // Call to `Position` contract + // Call to Position contract // Calculate open interest uint _oi = _collateral.mulDown(_leverage); + // TODO OverlayV1Choreographer.Tempo memory _tempo = tempo; - // Call to internal function. + // Call to internal function // Updates the market with the latest price, cap, and pay funding ( _cap, _tempo.updated, @@ -75,7 +77,7 @@ abstract contract OverlayV1Market is OverlayV1Choreographer { _tempo.brrrrdCycloid ); - // Call to `OverlayV1Comptroller` contract + // Call to OverlayV1Comptroller contract // Takes in the OI and applies Overlay's monetary policy ( impact_, _tempo.impactCycloid, @@ -93,7 +95,7 @@ abstract contract OverlayV1Market is OverlayV1Choreographer { pricePointNext_ = _pricePoints.length - 1; - // Call to `Position` contract + // Call to Position contract exactedFee_ = _oi.mulDown(_fee); require(_collateral >= MIN_COLLAT + impact_ + exactedFee_ , "OVLV1:collat