From 896c0aae0a4c21c46cf0ac8035d6d8f7b4672cee Mon Sep 17 00:00:00 2001 From: "Arthur G." Date: Mon, 6 Jan 2025 13:02:12 +0100 Subject: [PATCH 1/4] refactor: `contracts' --- contracts/OverlayV1Deployer.sol | 12 +-- contracts/OverlayV1Factory.sol | 52 +++++------ contracts/OverlayV1Market.sol | 90 +++++++++---------- contracts/OverlayV1Token.sol | 2 +- contracts/feeds/OverlayV1FeedFactory.sol | 6 +- .../chainlink/OverlayV1ChainlinkFeed.sol | 8 +- .../OverlayV1ChainlinkFeedFactory.sol | 12 +-- contracts/interfaces/IOverlayV1Deployer.sol | 2 +- contracts/interfaces/IOverlayV1Factory.sol | 2 +- contracts/interfaces/IOverlayV1Market.sol | 2 +- contracts/libraries/FixedCast.sol | 2 +- contracts/libraries/Oracle.sol | 2 +- contracts/libraries/Risk.sol | 2 +- contracts/libraries/Tick.sol | 4 +- contracts/mocks/OverlayV1FeedFactoryMock.sol | 2 +- 15 files changed, 100 insertions(+), 100 deletions(-) diff --git a/contracts/OverlayV1Deployer.sol b/contracts/OverlayV1Deployer.sol index ef1271e0..a49d0665 100644 --- a/contracts/OverlayV1Deployer.sol +++ b/contracts/OverlayV1Deployer.sol @@ -6,23 +6,23 @@ import "./OverlayV1Market.sol"; contract OverlayV1Deployer is IOverlayV1Deployer { address public immutable factory; // factory that has gov permissions - address public immutable ov; // ov token + address public immutable ovl; // ovl token address public feed; // cached feed deploying market on // factory modifier for governance sensitive functions modifier onlyFactory() { - require(msg.sender == factory, "OVV1: !factory"); + require(msg.sender == factory, "OVLV1: !factory"); _; } - constructor(address _ov) { + constructor(address _ovl) { factory = msg.sender; - ov = _ov; + ovl = _ovl; } - function parameters() external view returns (address ov_, address feed_, address factory_) { - ov_ = ov; + function parameters() external view returns (address ovl_, address feed_, address factory_) { + ovl_ = ovl; feed_ = feed; factory_ = factory; } diff --git a/contracts/OverlayV1Factory.sol b/contracts/OverlayV1Factory.sol index 694b4eb2..58ecee0e 100644 --- a/contracts/OverlayV1Factory.sol +++ b/contracts/OverlayV1Factory.sol @@ -22,15 +22,15 @@ contract OverlayV1Factory is IOverlayV1Factory { 0.01e18, // MIN_LMBDA = 0.01 0, // MIN_DELTA = 0 1e18, // MIN_CAP_PAYOFF = 1x - 0, // MIN_CAP_NOTIONAL = 0 OV + 0, // MIN_CAP_NOTIONAL = 0 OVL 1e18, // MIN_CAP_LEVERAGE = 1x 86400, // MIN_CIRCUIT_BREAKER_WINDOW = 1 day - 0, // MIN_CIRCUIT_BREAKER_MINT_TARGET = 0 OV + 0, // MIN_CIRCUIT_BREAKER_MINT_TARGET = 0 OVL 0.01e18, // MIN_MAINTENANCE_MARGIN_FRACTION = 1% 0.01e18, // MIN_MAINTENANCE_MARGIN_BURN_RATE = 1% 0.001e18, // MIN_LIQUIDATION_FEE_RATE = 0.10% (10 bps) 1e14, // MIN_TRADING_FEE_RATE = 0.01% (1 bps) - 0.000_1e18, // MIN_MINIMUM_COLLATERAL = 1e-4 OV + 0.000_1e18, // MIN_MINIMUM_COLLATERAL = 1e-4 OVL 0.01e14, // MIN_PRICE_DRIFT_UPPER_LIMIT = 0.01 bps/s 100 // MIN_AVERAGE_BLOCK_TIME = 0.1s ]; @@ -39,15 +39,15 @@ contract OverlayV1Factory is IOverlayV1Factory { 10e18, // MAX_LMBDA = 10 200e14, // MAX_DELTA = 2% (200 bps) 100e18, // MAX_CAP_PAYOFF = 100x - 88_888_888e18, // MAX_CAP_NOTIONAL = 88,888,888 OV (initial supply) + 88_888_888e18, // MAX_CAP_NOTIONAL = 88,888,888 OVL (initial supply) 99e18, // MAX_CAP_LEVERAGE = 99x 31536000, // MAX_CIRCUIT_BREAKER_WINDOW = 365 days - 88_888_888e18, // MAX_CIRCUIT_BREAKER_MINT_TARGET = 88,888,888 OV (initial supply) + 88_888_888e18, // MAX_CIRCUIT_BREAKER_MINT_TARGET = 88,888,888 OVL (initial supply) 0.2e18, // MAX_MAINTENANCE_MARGIN_FRACTION = 20% 0.5e18, // MAX_MAINTENANCE_MARGIN_BURN_RATE = 50% 0.2e18, // MAX_LIQUIDATION_FEE_RATE = 20.00% (2000 bps) 100e14, // MAX_TRADING_FEE_RATE = 1% (100 bps) - 100_000e18, // MAX_MINIMUM_COLLATERAL = 100,000 OV + 100_000e18, // MAX_MINIMUM_COLLATERAL = 100,000 OVL 1e14, // MAX_PRICE_DRIFT_UPPER_LIMIT = 1 bps/s 3600000 // MAX_AVERAGE_BLOCK_TIME = 1h (arbitrary but large) ]; @@ -60,8 +60,8 @@ contract OverlayV1Factory is IOverlayV1Factory { // event for emergency shutdown event EmergencyShutdown(address indexed user, address indexed market); - // ov token - IOverlayV1Token public immutable ov; + // ovl token + IOverlayV1Token public immutable ovl; // market deployer IOverlayV1Deployer public immutable deployer; @@ -94,42 +94,42 @@ contract OverlayV1Factory is IOverlayV1Factory { // governor modifier for governance sensitive functions modifier onlyGovernor() { - require(ov.hasRole(GOVERNOR_ROLE, msg.sender), "OVV1: !governor"); + require(ovl.hasRole(GOVERNOR_ROLE, msg.sender), "OVLV1: !governor"); _; } // governor modifier for governance sensitive functions modifier onlyGuardian() { - require(ov.hasRole(GUARDIAN_ROLE, msg.sender), "OVV1: !guardian"); + require(ovl.hasRole(GUARDIAN_ROLE, msg.sender), "OVLV1: !guardian"); _; } // pauser modifier for pausable functions modifier onlyPauser() { - require(ov.hasRole(PAUSER_ROLE, msg.sender), "OVV1: !pauser"); + require(ovl.hasRole(PAUSER_ROLE, msg.sender), "OVLV1: !pauser"); _; } // risk manager modifier for risk parameters modifier onlyRiskManager() { - require(ov.hasRole(RISK_MANAGER_ROLE, msg.sender), "OVV1: !riskManager"); + require(ovl.hasRole(RISK_MANAGER_ROLE, msg.sender), "OVLV1: !riskManager"); _; } constructor( - address _ov, + address _ovl, address _feeRecipient, address _sequencerOracle, uint256 _gracePeriod ) { - // set ov - ov = IOverlayV1Token(_ov); + // set ovl + ovl = IOverlayV1Token(_ovl); // set the fee recipient _setFeeRecipient(_feeRecipient); // create a new deployer to use when deploying markets - deployer = new OverlayV1Deployer(_ov); + deployer = new OverlayV1Deployer(_ovl); // set the sequencer oracle sequencerOracle = AggregatorV3Interface(_sequencerOracle); @@ -138,14 +138,14 @@ contract OverlayV1Factory is IOverlayV1Factory { /// @dev adds a supported feed factory function addFeedFactory(address feedFactory) external onlyGovernor { - require(!isFeedFactory[feedFactory], "OVV1: feed factory already supported"); + require(!isFeedFactory[feedFactory], "OVLV1: feed factory already supported"); isFeedFactory[feedFactory] = true; emit FeedFactoryAdded(msg.sender, feedFactory); } /// @dev removes a supported feed factory function removeFeedFactory(address feedFactory) external onlyGovernor { - require(isFeedFactory[feedFactory], "OVV1: address not feed factory"); + require(isFeedFactory[feedFactory], "OVLV1: address not feed factory"); isFeedFactory[feedFactory] = false; emit FeedFactoryRemoved(msg.sender, feedFactory); } @@ -169,9 +169,9 @@ contract OverlayV1Factory is IOverlayV1Factory { // initialize the new market IOverlayV1Market(market_).initialize(params); - // grant market mint and burn priveleges on ov - ov.grantRole(MINTER_ROLE, market_); - ov.grantRole(BURNER_ROLE, market_); + // grant market mint and burn priveleges on ovl + ovl.grantRole(MINTER_ROLE, market_); + ovl.grantRole(BURNER_ROLE, market_); // store market registry record for given feed // and record address as a deployed market @@ -182,9 +182,9 @@ contract OverlayV1Factory is IOverlayV1Factory { /// @notice checks market doesn't exist on feed and feed is from a supported factory function _checkFeed(address feedFactory, address feed) private view { - require(getMarket[feed] == address(0), "OVV1: market already exists"); - require(isFeedFactory[feedFactory], "OVV1: feed factory not supported"); - require(IOverlayV1FeedFactory(feedFactory).isFeed(feed), "OVV1: feed does not exist"); + require(getMarket[feed] == address(0), "OVLV1: market already exists"); + require(isFeedFactory[feedFactory], "OVLV1: feed factory not supported"); + require(IOverlayV1FeedFactory(feedFactory).isFeed(feed), "OVLV1: feed does not exist"); } /// @notice Checks all risk params are within acceptable bounds @@ -199,7 +199,7 @@ contract OverlayV1Factory is IOverlayV1Factory { function _checkRiskParam(Risk.Parameters name, uint256 value) private view { uint256 minValue = PARAMS_MIN.get(name); uint256 maxValue = PARAMS_MAX.get(name); - require(value >= minValue && value <= maxValue, "OVV1: param out of bounds"); + require(value >= minValue && value <= maxValue, "OVLV1: param out of bounds"); } /// @notice Setter for per-market risk parameters adjustable by governance @@ -219,7 +219,7 @@ contract OverlayV1Factory is IOverlayV1Factory { } function _setFeeRecipient(address _feeRecipient) internal { - require(_feeRecipient != address(0), "OVV1: feeRecipient should not be zero address"); + require(_feeRecipient != address(0), "OVLV1: feeRecipient should not be zero address"); feeRecipient = _feeRecipient; emit FeeRecipientUpdated(msg.sender, _feeRecipient); } diff --git a/contracts/OverlayV1Market.sol b/contracts/OverlayV1Market.sol index f31baf79..f81e0d2c 100644 --- a/contracts/OverlayV1Market.sol +++ b/contracts/OverlayV1Market.sol @@ -35,7 +35,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { uint256 internal constant MAX_NATURAL_EXPONENT = 20e18; // immutables - IOverlayV1Token public immutable ov; // ov token + IOverlayV1Token public immutable ovl; // ovl token address public immutable feed; // oracle feed address public immutable factory; // factory that deployed this market @@ -68,19 +68,19 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { // factory modifier for governance sensitive functions modifier onlyFactory() { - require(msg.sender == factory, "OVV1: !factory"); + require(msg.sender == factory, "OVLV1: !factory"); _; } // not shutdown modifier for regular functionality modifier notShutdown() { - require(!isShutdown, "OVV1: shutdown"); + require(!isShutdown, "OVLV1: shutdown"); _; } // shutdown modifier for emergencies modifier hasShutdown() { - require(isShutdown, "OVV1: !shutdown"); + require(isShutdown, "OVLV1: !shutdown"); _; } @@ -151,9 +151,9 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { event Update(uint256 oiLong, uint256 oiShort); constructor() { - (address _ov, address _feed, address _factory) = + (address _ovl, address _feed, address _factory) = IOverlayV1Deployer(msg.sender).parameters(); - ov = IOverlayV1Token(_ov); + ovl = IOverlayV1Token(_ovl); feed = _feed; factory = _factory; } @@ -163,7 +163,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { function initialize(uint256[15] memory _params) external onlyFactory { // initialize update data Oracle.Data memory data = IOverlayV1Feed(feed).latest(); - require(_midFromFeed(data) > 0, "OVV1:!data"); + require(_midFromFeed(data) > 0, "OVLV1:!data"); timestampUpdateLast = block.timestamp; // check risk params valid @@ -177,13 +177,13 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { <= ONE.divDown( 2 * _delta + _maintenanceMarginFraction.divDown(ONE - _liquidationFeeRate) ), - "OVV1: max lev immediately liquidatable" + "OVLV1: max lev immediately liquidatable" ); uint256 _priceDriftUpperLimit = _params[uint256(Risk.Parameters.PriceDriftUpperLimit)]; require( _priceDriftUpperLimit * data.macroWindow < MAX_NATURAL_EXPONENT, - "OVV1: price drift exceeds max exp" + "OVLV1: price drift exceeds max exp" ); _cacheRiskCalc(Risk.Parameters.PriceDriftUpperLimit, _priceDriftUpperLimit); @@ -199,9 +199,9 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { notShutdown returns (uint256 positionId_) { - require(leverage >= ONE, "OVV1:levmax"); - require(collateral >= params.get(Risk.Parameters.MinCollateral), "OVV1:collateral= ONE, "OVLV1:levmax"); + require(collateral >= params.get(Risk.Parameters.MinCollateral), "OVLV1:collateral 0, "OVV1:oi==0"); + require(oi > 0, "OVLV1:oi==0"); // calculate debt and trading fees. fees charged on notional // and added to collateral transferred in @@ -240,7 +240,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { ? ask(data, _registerVolumeAsk(data, oi, capOi)) : bid(data, _registerVolumeBid(data, oi, capOi)); // check price hasn't changed more than max slippage specified by trader - require(isLong ? price <= priceLimit : price >= priceLimit, "OVV1:slippage>max"); + require(isLong ? price <= priceLimit : price >= priceLimit, "OVLV1:slippage>max"); // add new position's open interest to the side's aggregate oi value // and increase number of oi shares issued @@ -268,7 +268,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { params.get(Risk.Parameters.MaintenanceMarginFraction), params.get(Risk.Parameters.LiquidationFeeRate) ), - "OVV1:liquidatable" + "OVLV1:liquidatable" ); // store the position info data @@ -289,12 +289,12 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { isLong ? oiLongShares : oiShortShares ); - // transfer in the OV collateral needed to back the position + fees + // transfer in the OVL collateral needed to back the position + fees // trading fees charged as a percentage on notional size of position - ov.transferFrom(msg.sender, address(this), collateral + tradingFee); + ovl.transferFrom(msg.sender, address(this), collateral + tradingFee); // send trading fees to trading fee recipient - ov.transfer(IOverlayV1Factory(factory).feeRecipient(), tradingFee); + ovl.transfer(IOverlayV1Factory(factory).feeRecipient(), tradingFee); } /// @dev unwinds fraction of an existing position @@ -302,11 +302,11 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { external notShutdown { - require(fraction <= ONE, "OVV1:fraction>max"); + require(fraction <= ONE, "OVLV1:fraction>max"); // only keep 4 decimal precision (1 bps) for fraction given // pos.fractionRemaining only to 4 decimals fraction -= fraction % 1e14; - require(fraction > 0, "OVV1:fraction 0, "OVLV1:fraction= priceLimit : price <= priceLimit, "OVV1:slippage>max"); + require(pos.isLong ? price >= priceLimit : price <= priceLimit, "OVLV1:slippage>max"); // calculate the value and cost of the position for pnl determinations // and amount to transfer @@ -411,16 +411,16 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { // mint or burn the pnl for the position if (value >= cost) { - ov.mint(address(this), value - cost); + ovl.mint(address(this), value - cost); } else { - ov.burn(cost - value); + ovl.burn(cost - value); } // transfer out the unwound position value less fees to trader - ov.transfer(msg.sender, value - tradingFee); + ovl.transfer(msg.sender, value - tradingFee); // send trading fees to trading fee recipient - ov.transfer(IOverlayV1Factory(factory).feeRecipient(), tradingFee); + ovl.transfer(IOverlayV1Factory(factory).feeRecipient(), tradingFee); } /// @dev liquidates a liquidatable position @@ -436,7 +436,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { { // check position exists pos = positions.get(owner, positionId); - require(pos.exists(), "OVV1:!position"); + require(pos.exists(), "OVLV1:!position"); // call to update before any effects Oracle.Data memory data = update(); @@ -463,7 +463,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { params.get(Risk.Parameters.MaintenanceMarginFraction), params.get(Risk.Parameters.LiquidationFeeRate) ), - "OVV1:!liquidatable" + "OVLV1:!liquidatable" ); // calculate the value and cost of the position for pnl determinations @@ -508,13 +508,13 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { ); // burn the pnl for the position + insurance margin - ov.burn(cost - value + marginToBurn); + ovl.burn(cost - value + marginToBurn); // transfer out the liquidation fee to liquidator for reward - ov.transfer(msg.sender, liquidationFee); + ovl.transfer(msg.sender, liquidationFee); // send remaining margin to trading fee recipient - ov.transfer(IOverlayV1Factory(factory).feeRecipient(), marginRemaining); + ovl.transfer(IOverlayV1Factory(factory).feeRecipient(), marginRemaining); } /// @dev updates market: pays funding and fetches freshest data from feed @@ -525,12 +525,12 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { // check Arbitrum sequencer is up and grace period has // passed before fetching new data from feed - require(IOverlayV1Factory(factory).isUpAndGracePeriodPassed(), "OVV1:!sequencer"); + require(IOverlayV1Factory(factory).isUpAndGracePeriodPassed(), "OVLV1:!sequencer"); // fetch new oracle data from feed // applies sanity check in case of data manipulation Oracle.Data memory data = IOverlayV1Feed(feed).latest(); - require(dataIsValid(data), "OVV1:!data"); + require(dataIsValid(data), "OVLV1:!data"); emit Update(oiLong, oiShort); // return the latest data from feed @@ -702,7 +702,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { uint256 delta = params.get(Risk.Parameters.Delta); uint256 lmbda = params.get(Risk.Parameters.Lmbda); uint256 pow = delta + lmbda.mulUp(volume); - require(pow < MAX_NATURAL_EXPONENT, "OVV1:slippage>max"); + require(pow < MAX_NATURAL_EXPONENT, "OVLV1:slippage>max"); bid_ = bid_.mulDown(ONE.divDown(pow.expUp())); // bid * e**(-pow) } @@ -715,7 +715,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { uint256 delta = params.get(Risk.Parameters.Delta); uint256 lmbda = params.get(Risk.Parameters.Lmbda); uint256 pow = delta + lmbda.mulUp(volume); - require(pow < MAX_NATURAL_EXPONENT, "OVV1:slippage>max"); + require(pow < MAX_NATURAL_EXPONENT, "OVLV1:slippage>max"); ask_ = ask_.mulUp(pow.expUp()); // ask * e**(pow) } @@ -849,7 +849,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { // check new total oi on side does not exceed capOi after // adjusted for circuit breaker uint256 capOiCircuited = capOiAdjustedForCircuitBreaker(capOi); - require(oiTotalOnSide <= capOiCircuited, "OVV1:oi>cap"); + require(oiTotalOnSide <= capOiCircuited, "OVLV1:oi>cap"); // update total aggregate oi and oi shares storage vars if (isLong) { @@ -894,7 +894,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { <= ONE.divDown( 2 * _delta + maintenanceMarginFraction.divDown(ONE - liquidationFeeRate) ), - "OVV1: max lev immediately liquidatable" + "OVLV1: max lev immediately liquidatable" ); } @@ -913,7 +913,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { <= ONE.divDown( 2 * delta + maintenanceMarginFraction.divDown(ONE - liquidationFeeRate) ), - "OVV1: max lev immediately liquidatable" + "OVLV1: max lev immediately liquidatable" ); } @@ -931,7 +931,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { <= ONE.divDown( 2 * delta + _maintenanceMarginFraction.divDown(ONE - liquidationFeeRate) ), - "OVV1: max lev immediately liquidatable" + "OVLV1: max lev immediately liquidatable" ); } @@ -950,7 +950,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { <= ONE.divDown( 2 * delta + maintenanceMarginFraction.divDown(ONE - _liquidationFeeRate) ), - "OVV1: max lev immediately liquidatable" + "OVLV1: max lev immediately liquidatable" ); } @@ -961,7 +961,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { uint256 _priceDriftUpperLimit = value; require( _priceDriftUpperLimit * data.macroWindow < MAX_NATURAL_EXPONENT, - "OVV1: price drift exceeds max exp" + "OVLV1: price drift exceeds max exp" ); } } @@ -1002,11 +1002,11 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { function emergencyWithdraw(uint256 positionId) external hasShutdown { // check position exists Position.Info memory pos = positions.get(msg.sender, positionId); - require(pos.exists(), "OVV1:!position"); + require(pos.exists(), "OVLV1:!position"); // calculate remaining collateral backing position uint256 cost = pos.cost(ONE); - cost = Math.min(ov.balanceOf(address(this)), cost); // if cost > balance + cost = Math.min(ovl.balanceOf(address(this)), cost); // if cost > balance // set fraction remaining to zero so position no longer exists pos.fractionRemaining = 0; @@ -1016,6 +1016,6 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { emit EmergencyWithdraw(msg.sender, positionId, cost); // transfer available collateral out to position owner - ov.transfer(msg.sender, cost); + ovl.transfer(msg.sender, cost); } } diff --git a/contracts/OverlayV1Token.sol b/contracts/OverlayV1Token.sol index 43972604..e9360aa2 100644 --- a/contracts/OverlayV1Token.sol +++ b/contracts/OverlayV1Token.sol @@ -6,7 +6,7 @@ import "@openzeppelin/contracts/access/AccessControl.sol"; import "./interfaces/IOverlayV1Token.sol"; -contract OverlayV1Token is IOverlayV1Token, AccessControl, ERC20("Overlay", "OV") { +contract OverlayV1Token is IOverlayV1Token, AccessControl, ERC20("Overlay", "OVL") { constructor() { _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); } diff --git a/contracts/feeds/OverlayV1FeedFactory.sol b/contracts/feeds/OverlayV1FeedFactory.sol index fab15dfc..3bb0cd59 100644 --- a/contracts/feeds/OverlayV1FeedFactory.sol +++ b/contracts/feeds/OverlayV1FeedFactory.sol @@ -15,9 +15,9 @@ abstract contract OverlayV1FeedFactory is IOverlayV1FeedFactory { constructor(uint256 _microWindow, uint256 _macroWindow) { // sanity checks on micro and macroWindow - require(_microWindow > 0, "OVV1: microWindow == 0"); - require(_macroWindow >= _microWindow, "OVV1: macroWindow < microWindow"); - require(_macroWindow <= 86400, "OVV1: macroWindow > 1 day"); + require(_microWindow > 0, "OVLV1: microWindow == 0"); + require(_macroWindow >= _microWindow, "OVLV1: macroWindow < microWindow"); + require(_macroWindow <= 86400, "OVLV1: macroWindow > 1 day"); microWindow = _microWindow; macroWindow = _macroWindow; diff --git a/contracts/feeds/chainlink/OverlayV1ChainlinkFeed.sol b/contracts/feeds/chainlink/OverlayV1ChainlinkFeed.sol index 61a5487c..39b8ef38 100644 --- a/contracts/feeds/chainlink/OverlayV1ChainlinkFeed.sol +++ b/contracts/feeds/chainlink/OverlayV1ChainlinkFeed.sol @@ -6,7 +6,7 @@ import "../../interfaces/IOverlayV1Token.sol"; import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; contract OverlayV1ChainlinkFeed is OverlayV1Feed { - IOverlayV1Token public immutable ov; + IOverlayV1Token public immutable ovl; AggregatorV3Interface public immutable aggregator; uint8 public immutable decimals; uint256 public heartbeat; @@ -15,12 +15,12 @@ contract OverlayV1ChainlinkFeed is OverlayV1Feed { event HeartbeatSet(uint256 heartbeat); modifier onlyGovernor() { - require(ov.hasRole(GOVERNOR_ROLE, msg.sender), "OVV1: !governor"); + require(ovl.hasRole(GOVERNOR_ROLE, msg.sender), "OVLV1: !governor"); _; } constructor( - address _ov, + address _ovl, address _aggregator, uint256 _microWindow, uint256 _macroWindow, @@ -32,7 +32,7 @@ contract OverlayV1ChainlinkFeed is OverlayV1Feed { decimals = aggregator.decimals(); description = aggregator.description(); _setHeartbeat(_heartbeat); - ov = IOverlayV1Token(_ov); + ovl = IOverlayV1Token(_ovl); } function _fetch() internal view virtual override returns (Oracle.Data memory) { diff --git a/contracts/feeds/chainlink/OverlayV1ChainlinkFeedFactory.sol b/contracts/feeds/chainlink/OverlayV1ChainlinkFeedFactory.sol index f0b3d68c..29936fa3 100644 --- a/contracts/feeds/chainlink/OverlayV1ChainlinkFeedFactory.sol +++ b/contracts/feeds/chainlink/OverlayV1ChainlinkFeedFactory.sol @@ -6,15 +6,15 @@ import "./OverlayV1ChainlinkFeed.sol"; import "../../interfaces/feeds/chainlink/IOverlayV1ChainlinkFeedFactory.sol"; contract OverlayV1ChainlinkFeedFactory is IOverlayV1ChainlinkFeedFactory, OverlayV1FeedFactory { - address public immutable OV; + address public immutable ovl; // registry of feeds; for a given aggregator pair, returns associated feed mapping(address => address) public getFeed; - constructor(address _ov, uint256 _microWindow, uint256 _macroWindow) + constructor(address _ovl, uint256 _microWindow, uint256 _macroWindow) OverlayV1FeedFactory(_microWindow, _macroWindow) { - require(_ov != address(0), "OVV1: invalid ov"); - OV = _ov; + require(_ovl != address(0), "OVLV1: invalid ovl"); + ovl = _ovl; } /// @dev deploys a new feed contract @@ -26,11 +26,11 @@ contract OverlayV1ChainlinkFeedFactory is IOverlayV1ChainlinkFeedFactory, Overla returns (address _feed) { // check feed doesn't already exist - require(getFeed[_aggregator] == address(0), "OVV1: feed already exists"); + require(getFeed[_aggregator] == address(0), "OVLV1: feed already exists"); // Create a new Feed contract _feed = address( - new OverlayV1ChainlinkFeed(OV, _aggregator, microWindow, macroWindow, _heartbeat) + new OverlayV1ChainlinkFeed(ovl, _aggregator, microWindow, macroWindow, _heartbeat) ); // store feed registry record for _aggregator and record address as deployed feed diff --git a/contracts/interfaces/IOverlayV1Deployer.sol b/contracts/interfaces/IOverlayV1Deployer.sol index 441b1625..3b2b733d 100644 --- a/contracts/interfaces/IOverlayV1Deployer.sol +++ b/contracts/interfaces/IOverlayV1Deployer.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.10; interface IOverlayV1Deployer { function factory() external view returns (address); - function ov() external view returns (address); + function ovl() external view returns (address); function deploy(address feed) external returns (address); diff --git a/contracts/interfaces/IOverlayV1Factory.sol b/contracts/interfaces/IOverlayV1Factory.sol index a796bd7d..55a89cd7 100644 --- a/contracts/interfaces/IOverlayV1Factory.sol +++ b/contracts/interfaces/IOverlayV1Factory.sol @@ -13,7 +13,7 @@ interface IOverlayV1Factory { function PARAMS_MAX(uint256 idx) external view returns (uint256); // immutables - function ov() external view returns (IOverlayV1Token); + function ovl() external view returns (IOverlayV1Token); function deployer() external view returns (IOverlayV1Deployer); diff --git a/contracts/interfaces/IOverlayV1Market.sol b/contracts/interfaces/IOverlayV1Market.sol index 483a7d0e..f3c182ea 100644 --- a/contracts/interfaces/IOverlayV1Market.sol +++ b/contracts/interfaces/IOverlayV1Market.sol @@ -9,7 +9,7 @@ import "./IOverlayV1Token.sol"; interface IOverlayV1Market { // immutables - function ov() external view returns (IOverlayV1Token); + function ovl() external view returns (IOverlayV1Token); function feed() external view returns (address); diff --git a/contracts/libraries/FixedCast.sol b/contracts/libraries/FixedCast.sol index d020ac0f..c7ef2301 100644 --- a/contracts/libraries/FixedCast.sol +++ b/contracts/libraries/FixedCast.sol @@ -14,7 +14,7 @@ library FixedCast { /// @dev decreases precision by 14 decimals function toUint16Fixed(uint256 value) internal pure returns (uint16) { uint256 ret256 = value / PRECISION_CHANGER; - require(ret256 <= type(uint16).max, "OVV1: FixedCast out of bounds"); + require(ret256 <= type(uint16).max, "OVLV1: FixedCast out of bounds"); return uint16(ret256); } } diff --git a/contracts/libraries/Oracle.sol b/contracts/libraries/Oracle.sol index f162581b..e8fff6a6 100644 --- a/contracts/libraries/Oracle.sol +++ b/contracts/libraries/Oracle.sol @@ -9,7 +9,7 @@ library Oracle { uint256 priceOverMicroWindow; // p(now) averaged over micro uint256 priceOverMacroWindow; // p(now) averaged over macro uint256 priceOneMacroWindowAgo; // p(now - macro) avg over macro - uint256 reserveOverMicroWindow; // r(now) in ov averaged over micro + uint256 reserveOverMicroWindow; // r(now) in ovl averaged over micro bool hasReserve; // whether oracle has manipulable reserve pool } } diff --git a/contracts/libraries/Risk.sol b/contracts/libraries/Risk.sol index c57c6ae8..0cdd0b7e 100644 --- a/contracts/libraries/Risk.sol +++ b/contracts/libraries/Risk.sol @@ -15,7 +15,7 @@ library Risk { MaintenanceMarginBurnRate, // burn rate for mm constant LiquidationFeeRate, // liquidation fee charged on liquidate TradingFeeRate, // trading fee charged on build/unwind - MinCollateral, // minimum ov collateral to open position + MinCollateral, // minimum ovl collateral to open position PriceDriftUpperLimit, // upper limit for feed price changes since last update AverageBlockTime // average block time of the respective chain diff --git a/contracts/libraries/Tick.sol b/contracts/libraries/Tick.sol index 46634bce..890ed266 100644 --- a/contracts/libraries/Tick.sol +++ b/contracts/libraries/Tick.sol @@ -21,7 +21,7 @@ library Tick { /// @dev -41e18/ln(1.0001), 130e18/ln(1.0001), respectively (w some buffer) function priceToTick(uint256 price) internal pure returns (int24) { int256 tick256 = price.logDown(PRICE_BASE); - require(tick256 >= MIN_TICK_256 && tick256 <= MAX_TICK_256, "OVV1: tick out of bounds"); + require(tick256 >= MIN_TICK_256 && tick256 <= MAX_TICK_256, "OVLV1: tick out of bounds"); // tick256 is FixedPoint format with 18 decimals. Divide by ONE // then truncate to int24 @@ -37,7 +37,7 @@ library Tick { // tick needs to be converted to Fixed point format with 18 decimals // to use FixedPoint powUp int256 tick256 = int256(tick) * int256(ONE); - require(tick256 >= MIN_TICK_256 && tick256 <= MAX_TICK_256, "OVV1: tick out of bounds"); + require(tick256 >= MIN_TICK_256 && tick256 <= MAX_TICK_256, "OVLV1: tick out of bounds"); uint256 pow = uint256(tick256.abs()); return (tick256 >= 0 ? PRICE_BASE.powDown(pow) : ONE.divDown(PRICE_BASE.powUp(pow))); diff --git a/contracts/mocks/OverlayV1FeedFactoryMock.sol b/contracts/mocks/OverlayV1FeedFactoryMock.sol index 730bd604..1dbeca78 100644 --- a/contracts/mocks/OverlayV1FeedFactoryMock.sol +++ b/contracts/mocks/OverlayV1FeedFactoryMock.sol @@ -13,7 +13,7 @@ contract OverlayV1FeedFactoryMock is OverlayV1FeedFactory { /// @dev deploy mock feed function deployFeed(uint256 price, uint256 reserve) external returns (address feed_) { - require(getFeed[price][reserve] == address(0), "OVV1: feed already exists"); + require(getFeed[price][reserve] == address(0), "OVLV1: feed already exists"); // Use the CREATE2 opcode to deploy a new Feed contract. // Will revert if feed which accepts (price, reserve) From ae5b8869723868551b142eb4d1c5d6369190c3f5 Mon Sep 17 00:00:00 2001 From: "Arthur G." Date: Mon, 6 Jan 2025 13:49:14 +0100 Subject: [PATCH 2/4] refactor: `scripts' --- scripts/deploy.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/deploy.py b/scripts/deploy.py index 9e8f5891..93dfa7e0 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -37,24 +37,24 @@ def main(): dev = accounts.load(click.prompt( "Account", type=click.Choice(accounts.load()))) - # deploy OV - ov = OverlayV1Token.deploy({"from": dev}, publish_source=True) - click.echo(f"OV Token deployed [{ov.address}]") + # deploy OVL + ovl = OverlayV1Token.deploy({"from": dev}, publish_source=True) + click.echo(f"OVL Token deployed [{ovl.address}]") # deploy market factory factory = OverlayV1Factory.deploy( - ov, FEE_RECIPIENT, {"from": dev}, publish_source=True) + ovl, FEE_RECIPIENT, {"from": dev}, publish_source=True) click.echo(f"Factory deployed [{factory.address}]") # grant market factory admin role to grant minter + burner roles to markets # on deployMarket calls - ov.grantRole(_role(ADMIN), factory, {"from": dev}) + ovl.grantRole(_role(ADMIN), factory, {"from": dev}) # grant admin rights to gov - ov.grantRole(_role(ADMIN), GOV, {"from": dev}) - ov.grantRole(_role(MINTER), GOV, {"from": dev}) - ov.grantRole(_role(GOVERNOR), GOV, {"from": dev}) - click.echo(f"OV Token roles granted to [{GOV}]") + ovl.grantRole(_role(ADMIN), GOV, {"from": dev}) + ovl.grantRole(_role(MINTER), GOV, {"from": dev}) + ovl.grantRole(_role(GOVERNOR), GOV, {"from": dev}) + click.echo(f"OVL Token roles granted to [{GOV}]") # renounce admin rights so only gov has roles - ov.renounceRole(_role(ADMIN), dev, {"from": dev}) + ovl.renounceRole(_role(ADMIN), dev, {"from": dev}) From 6ac9324e91954c94ac6a43032d2f43b12e755048 Mon Sep 17 00:00:00 2001 From: "Arthur G." Date: Mon, 6 Jan 2025 14:12:16 +0100 Subject: [PATCH 3/4] refactor: `tests' --- tests/OverlayV1ChainlinkFeed.t.sol | 8 +- tests/OverlayV1Market.t.sol | 46 ++--- tests/OverlayV1Token.t.sol | 32 ++-- tests/Sequencer.t.sol | 27 +-- tests/deployers/market/conftest.py | 6 +- tests/deployers/market/test_conftest.py | 6 +- tests/deployers/market/test_deploy.py | 10 +- .../feed/mock/test_deploy_factory.py | 6 +- tests/factories/feed/mock/test_deploy_feed.py | 2 +- tests/factories/market/conftest.py | 10 +- .../market/test_add_remove_feed_factory.py | 8 +- tests/factories/market/test_conftest.py | 30 ++-- tests/factories/market/test_deploy_market.py | 22 +-- tests/factories/market/test_setters.py | 12 +- tests/feeds/chainlink/conftest.py | 6 +- tests/libraries/fixedcast/test_views.py | 2 +- tests/libraries/tick/test_views.py | 8 +- tests/markets/conftest.py | 26 +-- tests/markets/test_build.py | 98 +++++------ tests/markets/test_conftest.py | 40 ++--- tests/markets/test_initialize.py | 18 +- tests/markets/test_liquidate.py | 92 +++++----- tests/markets/test_oi_cap.py | 4 +- tests/markets/test_price.py | 4 +- tests/markets/test_setters.py | 16 +- tests/markets/test_slippage.py | 12 +- tests/markets/test_unwind.py | 160 +++++++++--------- tests/markets/test_update.py | 6 +- tests/markets/test_withdraw.py | 56 +++--- tests/token/test_conftest.py | 2 +- 30 files changed, 388 insertions(+), 387 deletions(-) diff --git a/tests/OverlayV1ChainlinkFeed.t.sol b/tests/OverlayV1ChainlinkFeed.t.sol index 88065a6c..a050de0c 100644 --- a/tests/OverlayV1ChainlinkFeed.t.sol +++ b/tests/OverlayV1ChainlinkFeed.t.sol @@ -12,17 +12,17 @@ contract MarketTest is Test { AggregatorMock aggregator; OverlayV1ChainlinkFeed feed; OverlayV1ChainlinkFeedFactory feedFactory; - OverlayV1Token ov; + OverlayV1Token ovl; bytes32 constant GOVERNOR_ROLE = keccak256("GOVERNOR"); address immutable GOVERNOR = makeAddr("governor"); function setUp() public { vm.createSelectFork(vm.envString("RPC"), 169_490_320); - ov = new OverlayV1Token(); + ovl = new OverlayV1Token(); aggregator = new AggregatorMock(); - feedFactory = new OverlayV1ChainlinkFeedFactory(address(ov), 600, 3600); + feedFactory = new OverlayV1ChainlinkFeedFactory(address(ovl), 600, 3600); feed = OverlayV1ChainlinkFeed(feedFactory.deployFeed(address(aggregator), 60 minutes)); - ov.grantRole(GOVERNOR_ROLE, GOVERNOR); + ovl.grantRole(GOVERNOR_ROLE, GOVERNOR); } function testStalePrice() public { diff --git a/tests/OverlayV1Market.t.sol b/tests/OverlayV1Market.t.sol index 82a7dfa6..f2a86951 100644 --- a/tests/OverlayV1Market.t.sol +++ b/tests/OverlayV1Market.t.sol @@ -24,21 +24,21 @@ contract MarketTest is Test { address constant FEED = 0x46B4143CAf2fE2965349FCa53730e83f91247E2C; address constant SEQUENCER_ORACLE = 0xFdB631F5EE196F0ed6FAa767959853A9F217697D; - OverlayV1Token ov; + OverlayV1Token ovl; OverlayV1Factory factory; OverlayV1Market market; OverlayV1Deployer deployer; function setUp() public { vm.createSelectFork(vm.envString("RPC"), 169_490_320); - ov = new OverlayV1Token(); - factory = new OverlayV1Factory(address(ov), FEE_RECIPIENT, SEQUENCER_ORACLE, 0); + ovl = new OverlayV1Token(); + factory = new OverlayV1Factory(address(ovl), FEE_RECIPIENT, SEQUENCER_ORACLE, 0); - ov.grantRole(ADMIN, address(factory)); - ov.grantRole(ADMIN, GOVERNOR); - ov.grantRole(MINTER_ROLE, GOVERNOR); - ov.grantRole(GOVERNOR_ROLE, GOVERNOR); - ov.grantRole(PAUSER_ROLE, PAUSER); + ovl.grantRole(ADMIN, address(factory)); + ovl.grantRole(ADMIN, GOVERNOR); + ovl.grantRole(MINTER_ROLE, GOVERNOR); + ovl.grantRole(GOVERNOR_ROLE, GOVERNOR); + ovl.grantRole(PAUSER_ROLE, PAUSER); uint256[15] memory params; params[0] = 115740740740; @@ -62,14 +62,14 @@ contract MarketTest is Test { market = OverlayV1Market(factory.deployMarket(FEED_FACTORY, FEED, params)); - ov.mint(USER, 100e18); + ovl.mint(USER, 100e18); } // Test pausable markets function testPause() public { vm.startPrank(USER); - ov.approve(address(market), type(uint256).max); + ovl.approve(address(market), type(uint256).max); // Build postion 0 market.build(1e18, 1e18, true, type(uint256).max); // Build postion 1 @@ -128,7 +128,7 @@ contract MarketTest is Test { vm.startPrank(USER); - ov.approve(address(market), type(uint256).max); + ovl.approve(address(market), type(uint256).max); // Build postion 0 market.build(1e18, 1e18, true, type(uint256).max); // Build postion 1 @@ -140,36 +140,36 @@ contract MarketTest is Test { // Unwind _fraction of postion 1 market.unwind(1, _fraction, 0); - vm.expectRevert("OVV1: !shutdown"); + vm.expectRevert("OVLV1: !shutdown"); market.emergencyWithdraw(1); vm.startPrank(GOVERNOR); - vm.expectRevert("OVV1: !guardian"); + vm.expectRevert("OVLV1: !guardian"); factory.shutdown(FEED); - ov.grantRole(GUARDIAN_ROLE, GOVERNOR); + ovl.grantRole(GUARDIAN_ROLE, GOVERNOR); factory.shutdown(FEED); vm.startPrank(USER); - vm.expectRevert("OVV1: shutdown"); + vm.expectRevert("OVLV1: shutdown"); market.build(1e18, 1e18, true, type(uint256).max); - vm.expectRevert("OVV1: shutdown"); + vm.expectRevert("OVLV1: shutdown"); market.unwind(1, 1e18, 0); - vm.expectRevert("OVV1: shutdown"); + vm.expectRevert("OVLV1: shutdown"); market.liquidate(USER, 1); - uint256 balanceBefore = ov.balanceOf(USER); + uint256 balanceBefore = ovl.balanceOf(USER); (uint96 notionalInitial,,,,,,, uint16 fractionRemaining) = market.positions(keccak256(abi.encodePacked(USER, uint256(1)))); market.emergencyWithdraw(1); - assertEq(balanceBefore + notionalInitial * fractionRemaining / 1e4, ov.balanceOf(USER)); - balanceBefore = ov.balanceOf(USER); + assertEq(balanceBefore + notionalInitial * fractionRemaining / 1e4, ovl.balanceOf(USER)); + balanceBefore = ovl.balanceOf(USER); (notionalInitial,,,,,,, fractionRemaining) = market.positions(keccak256(abi.encodePacked(USER, uint256(2)))); market.emergencyWithdraw(2); - assertEq(balanceBefore + notionalInitial * fractionRemaining / 1e4, ov.balanceOf(USER)); + assertEq(balanceBefore + notionalInitial * fractionRemaining / 1e4, ovl.balanceOf(USER)); - assertEq(ov.balanceOf(address(market)), 0); + assertEq(ovl.balanceOf(address(market)), 0); } event Update(uint256 oiLong, uint256 oiShort); @@ -177,7 +177,7 @@ contract MarketTest is Test { function testUpdateEventEmitting() public { vm.startPrank(USER); - ov.approve(address(market), type(uint256).max); + ovl.approve(address(market), type(uint256).max); market.build(1e18, 1e18, true, type(uint256).max); uint256 oiLong = market.oiLong(); diff --git a/tests/OverlayV1Token.t.sol b/tests/OverlayV1Token.t.sol index 6576109c..65aec9a2 100644 --- a/tests/OverlayV1Token.t.sol +++ b/tests/OverlayV1Token.t.sol @@ -5,7 +5,7 @@ import {Test, console2} from "forge-std/Test.sol"; import {OverlayV1Token} from "contracts/OverlayV1Token.sol"; contract TokenTest is Test { - OverlayV1Token ov; + OverlayV1Token ovl; address immutable MINTER = makeAddr("minter"); address immutable BURNER = makeAddr("burner"); address immutable USER = makeAddr("user"); @@ -13,44 +13,44 @@ contract TokenTest is Test { bytes32 constant BURNER_ROLE = keccak256("BURNER"); function setUp() public { - ov = new OverlayV1Token(); + ovl = new OverlayV1Token(); - ov.grantRole(MINTER_ROLE, MINTER); - ov.grantRole(BURNER_ROLE, BURNER); + ovl.grantRole(MINTER_ROLE, MINTER); + ovl.grantRole(BURNER_ROLE, BURNER); } function testMinter() public { vm.startPrank(MINTER); - ov.mint(USER, 100); - assertEq(ov.balanceOf(USER), 100); + ovl.mint(USER, 100); + assertEq(ovl.balanceOf(USER), 100); } function testBurner() public { vm.startPrank(MINTER); - ov.mint(BURNER, 100); - assertEq(ov.balanceOf(BURNER), 100); + ovl.mint(BURNER, 100); + assertEq(ovl.balanceOf(BURNER), 100); vm.startPrank(BURNER); - ov.burn(100); - assertEq(ov.balanceOf(BURNER), 0); + ovl.burn(100); + assertEq(ovl.balanceOf(BURNER), 0); } function testUser() public { vm.startPrank(MINTER); - ov.mint(USER, 100); - assertEq(ov.balanceOf(USER), 100); + ovl.mint(USER, 100); + assertEq(ovl.balanceOf(USER), 100); vm.startPrank(USER); vm.expectRevert( "AccessControl: account 0x6ca6d1e2d5347bfab1d91e883f1915560e09129d is missing role 0xf0887ba65ee2024ea881d91b74c2450ef19e1557f03bed3ea9f16b037cbe2dc9" ); - ov.mint(USER, 100); - assertEq(ov.balanceOf(USER), 100); + ovl.mint(USER, 100); + assertEq(ovl.balanceOf(USER), 100); vm.expectRevert( "AccessControl: account 0x6ca6d1e2d5347bfab1d91e883f1915560e09129d is missing role 0x9667e80708b6eeeb0053fa0cca44e028ff548e2a9f029edfeac87c118b08b7c8" ); - ov.burn(100); - assertEq(ov.balanceOf(USER), 100); + ovl.burn(100); + assertEq(ovl.balanceOf(USER), 100); } } diff --git a/tests/Sequencer.t.sol b/tests/Sequencer.t.sol index d8705975..fec4af36 100644 --- a/tests/Sequencer.t.sol +++ b/tests/Sequencer.t.sol @@ -25,23 +25,24 @@ contract SequencerTest is Test { address constant FEED = 0x46B4143CAf2fE2965349FCa53730e83f91247E2C; AggregatorMock sequencer_oracle; - OverlayV1Token ov; + OverlayV1Token ovl; OverlayV1Factory factory; OverlayV1Market market; OverlayV1Deployer deployer; function setUp() public { vm.createSelectFork(vm.envString("RPC"), 169_490_320); - ov = new OverlayV1Token(); + ovl = new OverlayV1Token(); sequencer_oracle = new AggregatorMock(); - factory = - new OverlayV1Factory(address(ov), FEE_RECIPIENT, address(sequencer_oracle), 30 minutes); + factory = new OverlayV1Factory( + address(ovl), FEE_RECIPIENT, address(sequencer_oracle), 30 minutes + ); - ov.grantRole(ADMIN, address(factory)); - ov.grantRole(ADMIN, GOVERNOR); - ov.grantRole(MINTER_ROLE, GOVERNOR); - ov.grantRole(GOVERNOR_ROLE, GOVERNOR); - ov.grantRole(PAUSER_ROLE, PAUSER); + ovl.grantRole(ADMIN, address(factory)); + ovl.grantRole(ADMIN, GOVERNOR); + ovl.grantRole(MINTER_ROLE, GOVERNOR); + ovl.grantRole(GOVERNOR_ROLE, GOVERNOR); + ovl.grantRole(PAUSER_ROLE, PAUSER); uint256[15] memory params; params[0] = 115740740740; @@ -65,14 +66,14 @@ contract SequencerTest is Test { market = OverlayV1Market(factory.deployMarket(FEED_FACTORY, FEED, params)); - ov.mint(USER, 100e18); + ovl.mint(USER, 100e18); } function testSequencerDown() public { sequencer_oracle.setData(1, 1); //Sequencer Down vm.startPrank(USER); - ov.approve(address(market), type(uint256).max); - vm.expectRevert("OVV1:!sequencer"); + ovl.approve(address(market), type(uint256).max); + vm.expectRevert("OVLV1:!sequencer"); market.build(1e18, 1e18, true, type(uint256).max); vm.stopPrank(); @@ -101,6 +102,6 @@ contract SequencerTest is Test { vm.startPrank(USER); market.unwind(0, 1e18, 0); - assertLt(ov.balanceOf(USER), 100e18); + assertLt(ovl.balanceOf(USER), 100e18); } } diff --git a/tests/deployers/market/conftest.py b/tests/deployers/market/conftest.py index 0a92a2ea..846ccc5d 100644 --- a/tests/deployers/market/conftest.py +++ b/tests/deployers/market/conftest.py @@ -62,7 +62,7 @@ def create_token(supply=sup): @pytest.fixture(scope="module") -def ov(create_token): +def ovl(create_token): yield create_token() @@ -85,9 +85,9 @@ def feed(create_feed): @pytest.fixture(scope="module") -def create_deployer(factory, ov): +def create_deployer(factory, ovl): def create_deployer(): - deployer = factory.deploy(OverlayV1Deployer, ov) + deployer = factory.deploy(OverlayV1Deployer, ovl) return deployer yield create_deployer diff --git a/tests/deployers/market/test_conftest.py b/tests/deployers/market/test_conftest.py index 51c6e6e7..6dcffe65 100644 --- a/tests/deployers/market/test_conftest.py +++ b/tests/deployers/market/test_conftest.py @@ -1,8 +1,8 @@ -def test_deployer_fixture(deployer, factory, ov): +def test_deployer_fixture(deployer, factory, ovl): assert deployer.factory() == factory - assert deployer.ov() == ov + assert deployer.ovl() == ovl tok, feed, fact = deployer.parameters() - assert tok == ov + assert tok == ovl assert feed == "0x0000000000000000000000000000000000000000" assert fact == factory diff --git a/tests/deployers/market/test_deploy.py b/tests/deployers/market/test_deploy.py index e7bafd76..69d78631 100644 --- a/tests/deployers/market/test_deploy.py +++ b/tests/deployers/market/test_deploy.py @@ -1,25 +1,25 @@ from brownie import reverts, OverlayV1Market -def test_deploy_creates_market(deployer, ov, feed, factory): +def test_deploy_creates_market(deployer, ovl, feed, factory): # deploy the market tx = deployer.deploy(feed, {"from": factory}) market_addr = tx.return_value market = OverlayV1Market.at(market_addr) # check market deployed correctly with immutables - assert market.ov() == ov + assert market.ovl() == ovl assert market.feed() == feed assert market.factory() == factory # test parameters reverts back to zero address tok, feed, fact = deployer.parameters() - assert tok == ov + assert tok == ovl assert feed == "0x0000000000000000000000000000000000000000" assert fact == factory -def test_deploy_reverts_when_not_factory(deployer, ov, feed, rando): +def test_deploy_reverts_when_not_factory(deployer, ovl, feed, rando): # check attempting to deploy - with reverts("OVV1: !factory"): + with reverts("OVLV1: !factory"): deployer.deploy(feed, {"from": rando}) diff --git a/tests/factories/feed/mock/test_deploy_factory.py b/tests/factories/feed/mock/test_deploy_factory.py index bbfc1c02..2cf5c8f1 100644 --- a/tests/factories/feed/mock/test_deploy_factory.py +++ b/tests/factories/feed/mock/test_deploy_factory.py @@ -5,7 +5,7 @@ def test_deploy_factory_reverts_when_micro_window_zero(rando): micro_window = 0 macro_window = 3600 - with reverts("OVV1: microWindow == 0"): + with reverts("OVLV1: microWindow == 0"): _ = rando.deploy(OverlayV1FeedFactoryMock, micro_window, macro_window) @@ -14,7 +14,7 @@ def test_deploy_factory_reverts_when_macro_lt_micro(rando): # check reverts when micro > macro micro_window = 3601 - with reverts("OVV1: macroWindow < microWindow"): + with reverts("OVLV1: macroWindow < microWindow"): _ = rando.deploy(OverlayV1FeedFactoryMock, micro_window, macro_window) # check succeeds when micro == macro @@ -27,7 +27,7 @@ def test_deploy_factory_reverts_when_macro_gt_1_day(rando): # check reverts when macro > 1d macro_window = 86401 - with reverts("OVV1: macroWindow > 1 day"): + with reverts("OVLV1: macroWindow > 1 day"): _ = rando.deploy(OverlayV1FeedFactoryMock, micro_window, macro_window) # check succeeds when macro <= 1d diff --git a/tests/factories/feed/mock/test_deploy_feed.py b/tests/factories/feed/mock/test_deploy_feed.py index c6073b8d..13dd8003 100644 --- a/tests/factories/feed/mock/test_deploy_feed.py +++ b/tests/factories/feed/mock/test_deploy_feed.py @@ -38,5 +38,5 @@ def test_deploy_feed_reverts_when_feed_already_exists(factory, alice): assert factory.isFeed(feed) is True # check reverts when attempt to deploy again - with reverts("OVV1: feed already exists"): + with reverts("OVLV1: feed already exists"): _ = factory.deployFeed(price, reserve, {"from": alice}) diff --git a/tests/factories/market/conftest.py b/tests/factories/market/conftest.py index 588c0d17..0201c31a 100644 --- a/tests/factories/market/conftest.py +++ b/tests/factories/market/conftest.py @@ -94,7 +94,7 @@ def create_token(supply=sup): @pytest.fixture(scope="module") -def ov(create_token): +def ovl(create_token): yield create_token() @@ -103,7 +103,7 @@ def ov(create_token): 2000000000000000000, 2000000000000000000, 3000000000000000000, 3000000000000000000) ]) -def create_feed_factory(gov, request, ov): +def create_feed_factory(gov, request, ovl): """ Creates a new feed factory and deploys three mock feeds for testing. Below, third mock is used in creating a market for test_setters.py @@ -111,7 +111,7 @@ def create_feed_factory(gov, request, ov): (micro, macro, price_one, reserve_one, price_two, reserve_two, price_three, reserve_three) = request.param - def create_feed_factory(tok=ov, micro_window=micro, macro_window=macro, + def create_feed_factory(tok=ovl, micro_window=micro, macro_window=macro, mock_price_one=price_one, mock_reserve_one=reserve_one, mock_price_two=price_two, @@ -155,11 +155,11 @@ def feed_three(feed_factory): @pytest.fixture(scope="module") -def create_factory(gov, guardian, fee_recipient, request, ov, governor_role, +def create_factory(gov, guardian, fee_recipient, request, ovl, governor_role, guardian_role, feed_factory, feed_three, sequencer_aggregator): - def create_factory(tok=ov, recipient=fee_recipient, feeds=feed_factory, + def create_factory(tok=ovl, recipient=fee_recipient, feeds=feed_factory, feed=feed_three): # create the market factory factory = gov.deploy(OverlayV1Factory, tok, recipient, diff --git a/tests/factories/market/test_add_remove_feed_factory.py b/tests/factories/market/test_add_remove_feed_factory.py index 0a618bee..1043bc3a 100644 --- a/tests/factories/market/test_add_remove_feed_factory.py +++ b/tests/factories/market/test_add_remove_feed_factory.py @@ -17,7 +17,7 @@ def test_add_feed_factory_adds_factory(factory, rando, gov): def test_add_feed_factory_reverts_when_not_gov(factory, charlie, alice): # check reverts when non governor account attempts to add - with reverts("OVV1: !governor"): + with reverts("OVLV1: !governor"): _ = factory.addFeedFactory(charlie, {"from": alice}) @@ -27,7 +27,7 @@ def test_add_feed_factory_reverts_when_factory_already_exists(factory, assert factory.isFeedFactory(feed_factory) is True # check reverts when already supporting factory - with reverts("OVV1: feed factory already supported"): + with reverts("OVLV1: feed factory already supported"): _ = factory.addFeedFactory(feed_factory, {"from": gov}) @@ -47,12 +47,12 @@ def test_remove_feed_factory_reverts_when_not_gov(factory, rando, gov): assert factory.isFeedFactory(rando) is True - with reverts("OVV1: !governor"): + with reverts("OVLV1: !governor"): _ = factory.removeFeedFactory(rando, {"from": rando}) def test_remove_feed_factory_reverts_when_not_feed_factory(factory, alice, gov): - with reverts("OVV1: address not feed factory"): + with reverts("OVLV1: address not feed factory"): _ = factory.removeFeedFactory(alice, {"from": gov}) diff --git a/tests/factories/market/test_conftest.py b/tests/factories/market/test_conftest.py index 0532f271..a4f07bac 100644 --- a/tests/factories/market/test_conftest.py +++ b/tests/factories/market/test_conftest.py @@ -1,7 +1,7 @@ -def test_factory_fixture(factory, fee_recipient, feed_factory, feed_three, ov, +def test_factory_fixture(factory, fee_recipient, feed_factory, feed_three, ovl, gov, market, deployer, governor_role): - # check ov immutable set - assert factory.ov() == ov + # check ovl immutable set + assert factory.ovl() == ovl # check fee recipient set assert factory.feeRecipient() == fee_recipient @@ -10,11 +10,11 @@ def test_factory_fixture(factory, fee_recipient, feed_factory, feed_three, ov, assert factory.deployer() != "0x0000000000000000000000000000000000000000" assert deployer.factory() == factory - # check factory has been given admin role on ov token - assert ov.hasRole(ov.DEFAULT_ADMIN_ROLE(), factory) is True + # check factory has been given admin role on ovl token + assert ovl.hasRole(ovl.DEFAULT_ADMIN_ROLE(), factory) is True - # check gov has been given governance role on ov token - assert ov.hasRole(governor_role, gov) is True + # check gov has been given governance role on ovl token + assert ovl.hasRole(governor_role, gov) is True # check feed factory has been added to registry assert factory.isFeedFactory(feed_factory) is True @@ -29,15 +29,15 @@ def test_factory_fixture(factory, fee_recipient, feed_factory, feed_three, ov, 10000000000000000, # MIN_LMBDA = 0.01 0, # MIN_DELTA = 0 1000000000000000000, # MIN_CAP_PAYOFF = 1x - 0, # MIN_CAP_NOTIONAL = 0 OV + 0, # MIN_CAP_NOTIONAL = 0 OVL 1000000000000000000, # MIN_CAP_LEVERAGE= 1x 86400, # MIN_CIRCUIT_BREAKER_WINDOW= 1 day - 0, # MIN_CIRCUIT_BREAKER_MINT_TARGET= 0 OV + 0, # MIN_CIRCUIT_BREAKER_MINT_TARGET= 0 OVL 10000000000000000, # MIN_MAINTENANCE_MARGIN_FRACTION = 1 % 10000000000000000, # MIN_MAINTENANCE_MARGIN_BURN_RATE = 1 % 1000000000000000, # MIN_LIQUIDATION_FEE_RATE = 0.10 % (10 bps) 100000000000000, # MIN_TRADING_FEE_RATE = 0.01 % (1 bps) - 100000000000000, # MIN_MINIMUM_COLLATERAL= 1e-4 OV + 100000000000000, # MIN_MINIMUM_COLLATERAL= 1e-4 OVL 1000000000000, # MIN_PRICE_DRIFT_UPPER_LIMIT= 0.01 bps/s 100 # MIN_AVERAGE_BLOCK_TIME = 0.1s ] @@ -52,17 +52,17 @@ def test_factory_fixture(factory, fee_recipient, feed_factory, feed_three, ov, 10000000000000000000, # MAX_LMBDA = 10 20000000000000000, # MAX_DELTA = 2% (200 bps) 100000000000000000000, # MAX_CAP_PAYOFF = 100x - # MAX_CAP_NOTIONAL = 88,888,888 OV (initial supply) + # MAX_CAP_NOTIONAL = 88,888,888 OVL (initial supply) 88888888000000000000000000, 99000000000000000000, # MAX_CAP_LEVERAGE = 99x 31536000, # MAX_CIRCUIT_BREAKER_WINDOW = 365 days - # MAX_CIRCUIT_BREAKER_MINT_TARGET = 88,888,888 OV + # MAX_CIRCUIT_BREAKER_MINT_TARGET = 88,888,888 OVL 88888888000000000000000000, 200000000000000000, # MAX_MAINTENANCE_MARGIN_FRACTION = 20% 500000000000000000, # MAX_MAINTENANCE_MARGIN_BURN_RATE = 50% 200000000000000000, # MAX_LIQUIDATION_FEE_RATE = 20.00% (1000 bps) 10000000000000000, # MAX_TRADING_FEE_RATE = 1% (100 bps) - 100000000000000000000000, # MAX_MINIMUM_COLLATERAL = 100,000 OV + 100000000000000000000000, # MAX_MINIMUM_COLLATERAL = 100,000 OVL 100000000000000, # MAX_PRICE_DRIFT_UPPER_LIMIT = 1 bps/s 3600000 # MAX_AVERAGE_BLOCK_TIME = 1h ] @@ -83,10 +83,10 @@ def test_feed_factory_fixture(feed_factory, feed_one, feed_two, feed_three): assert feed_factory.isFeed(feed_three) is True -def test_market_fixture(market, factory, feed_three, ov, gov): +def test_market_fixture(market, factory, feed_three, ovl, gov): # check params set properly # NOTE: market fixture uses feed three - assert market.ov() == ov + assert market.ovl() == ovl assert market.factory() == factory assert market.feed() == feed_three diff --git a/tests/factories/market/test_deploy_market.py b/tests/factories/market/test_deploy_market.py index 895d534e..c2fdb384 100644 --- a/tests/factories/market/test_deploy_market.py +++ b/tests/factories/market/test_deploy_market.py @@ -12,7 +12,7 @@ def isolation(fn_isolation): pass -def test_deploy_market_creates_market(factory, feed_factory, feed_one, ov, +def test_deploy_market_creates_market(factory, feed_factory, feed_one, ovl, minter_role, burner_role, gov): # NOTE: feed_one will have a successfully deployed market on it for # remainder of test_deploy_market.py @@ -61,9 +61,9 @@ def test_deploy_market_creates_market(factory, feed_factory, feed_one, ov, assert expect_market == actual_market assert factory.isMarket(expect_market) is True - # check market granted mint/burn roles on ov - assert ov.hasRole(minter_role, actual_market) is True - assert ov.hasRole(burner_role, actual_market) is True + # check market granted mint/burn roles on ovl + assert ovl.hasRole(minter_role, actual_market) is True + assert ovl.hasRole(burner_role, actual_market) is True # check event emitted assert 'MarketDeployed' in tx.events @@ -79,7 +79,7 @@ def test_deploy_market_creates_market(factory, feed_factory, feed_one, ov, market_contract = OverlayV1Market.at(actual_market) # check immutables set in constructor - assert market_contract.ov() == ov + assert market_contract.ovl() == ovl assert market_contract.feed() == expect_feed assert market_contract.factory() == factory @@ -128,7 +128,7 @@ def test_deploy_market_reverts_when_not_gov(factory, feed_factory, feed_two, expect_average_block_time] # check can't deploy from rando account - with reverts("OVV1: !governor"): + with reverts("OVLV1: !governor"): _ = factory.deployMarket( expect_feed_factory, expect_feed, @@ -177,7 +177,7 @@ def test_deploy_market_reverts_when_market_already_exists(factory, expect_average_block_time] # check can't deploy from rando account - with reverts("OVV1: market already exists"): + with reverts("OVLV1: market already exists"): _ = factory.deployMarket( expect_feed_factory, expect_feed, @@ -222,7 +222,7 @@ def test_deploy_market_reverts_when_feed_factory_not_supported(factory, rando, expect_average_block_time] # check can't deploy with rando factory feed - with reverts("OVV1: feed factory not supported"): + with reverts("OVLV1: feed factory not supported"): _ = factory.deployMarket( expect_feed_factory, expect_feed, @@ -265,7 +265,7 @@ def test_deploy_market_reverts_when_feed_does_not_exist(factory, feed_factory, expect_average_block_time] # check can't deploy with rando feed not in factory feed registry - with reverts("OVV1: feed does not exist"): + with reverts("OVLV1: feed does not exist"): _ = factory.deployMarket( expect_feed_factory, expect_feed, @@ -308,7 +308,7 @@ def test_deploy_market_reverts_when_param_less_than_min(factory, feed_factory, expect_param = factory.PARAMS_MIN(i) - 1 if expect_param >= 0: expect_params[i] = expect_param - with reverts("OVV1: param out of bounds"): + with reverts("OVLV1: param out of bounds"): _ = factory.deployMarket( expect_feed_factory, expect_feed, @@ -362,7 +362,7 @@ def test_deploy_market_reverts_when_param_greater_than_max(factory, feed_one, # check can't deploy with param greater than max expect_param = factory.PARAMS_MAX(i) + 1 expect_params[i] = expect_param - with reverts("OVV1: param out of bounds"): + with reverts("OVLV1: param out of bounds"): _ = factory.deployMarket( expect_feed_factory, expect_feed, diff --git a/tests/factories/market/test_setters.py b/tests/factories/market/test_setters.py index 879b1455..a15e8479 100644 --- a/tests/factories/market/test_setters.py +++ b/tests/factories/market/test_setters.py @@ -35,7 +35,7 @@ def test_set_fee_recipient_reverts_when_not_gov(factory, alice): expect_fee_recipient = alice # check can't set fee recipient with non gov account - with reverts("OVV1: !governor"): + with reverts("OVLV1: !governor"): _ = factory.setFeeRecipient(expect_fee_recipient, {"from": alice}) @@ -43,7 +43,7 @@ def test_set_fee_recipient_reverts_when_zero_address(factory, gov): expect_fee_recipient = "0x0000000000000000000000000000000000000000" # check can't set fee recipient as zero address - with reverts("OVV1: feeRecipient should not be zero address"): + with reverts("OVLV1: feeRecipient should not be zero address"): _ = factory.setFeeRecipient(expect_fee_recipient, {"from": gov}) @@ -96,7 +96,7 @@ def test_set_risk_param_reverts_when_not_gov(factory, market, alice): expect_k = 361250000000 # check can't set k with non gov account - with reverts("OVV1: !riskManager"): + with reverts("OVLV1: !riskManager"): _ = factory.setRiskParam(feed, 0, expect_k, {"from": alice}) @@ -108,7 +108,7 @@ def test_set_risk_param_reverts_when_less_than_min(factory, market, gov): if expect_param >= 0: # check can't set param less than min - with reverts("OVV1: param out of bounds"): + with reverts("OVLV1: param out of bounds"): _ = factory.setRiskParam(feed, i, expect_param, {"from": gov}) # check can set param when equal to min @@ -129,7 +129,7 @@ def test_set_risk_param_reverts_when_greater_than_max(factory, market, gov): expect_param = factory.PARAMS_MAX(i) + 1 # check can't set param greater than max - with reverts("OVV1: param out of bounds"): + with reverts("OVLV1: param out of bounds"): _ = factory.setRiskParam(feed, i, expect_param, {"from": gov}) # check can set param when equal to max @@ -179,5 +179,5 @@ def test_shutdown_reverts_when_not_guardian(factory, market, rando): feed = market.feed() # can't shutdown when not a guardian - with reverts("OVV1: !guardian"): + with reverts("OVLV1: !guardian"): _ = factory.shutdown(feed, {"from": rando}) diff --git a/tests/feeds/chainlink/conftest.py b/tests/feeds/chainlink/conftest.py index 0b8e30ad..48deaaa4 100644 --- a/tests/feeds/chainlink/conftest.py +++ b/tests/feeds/chainlink/conftest.py @@ -57,7 +57,7 @@ def create_token(supply=sup): @pytest.fixture(scope="module") -def ov(create_token): +def ovl(create_token): yield create_token() @@ -78,11 +78,11 @@ def mock_aggregator(create_mock_aggregator): @pytest.fixture(scope="module", params=[(600, 3600)]) -def create_chainlink_feed(ov, gov, mock_aggregator, request): +def create_chainlink_feed(ovl, gov, mock_aggregator, request): micro, macro = request.param aggregator_address = mock_aggregator.address - def create_chainlink_feed(tok=ov, aggregator=aggregator_address, + def create_chainlink_feed(tok=ovl, aggregator=aggregator_address, micro_window=micro, macro_window=macro): feed = gov.deploy(OverlayV1ChainlinkFeed, tok, aggregator, micro_window, macro_window, 3601) diff --git a/tests/libraries/fixedcast/test_views.py b/tests/libraries/fixedcast/test_views.py index b4fc0a8e..13795243 100644 --- a/tests/libraries/fixedcast/test_views.py +++ b/tests/libraries/fixedcast/test_views.py @@ -42,5 +42,5 @@ def test_to_uint16_fixed_reverts_when_gt_max(fixed_cast): # should fail for type(uint16).max + 1 value = 2**16 input_value = value * Decimal(1e14) - with reverts("OVV1: FixedCast out of bounds"): + with reverts("OVLV1: FixedCast out of bounds"): fixed_cast.toUint16Fixed(input_value) diff --git a/tests/libraries/tick/test_views.py b/tests/libraries/tick/test_views.py index 75df5884..70db9862 100644 --- a/tests/libraries/tick/test_views.py +++ b/tests/libraries/tick/test_views.py @@ -55,7 +55,7 @@ def test_price_to_tick_reverts_when_lt_min(tick_mock): # check reverts when input price 1 less (equal to zero) input_price = 1 - with reverts("OVV1: tick out of bounds"): + with reverts("OVLV1: tick out of bounds"): tick_mock.priceToTick(input_price) @@ -69,14 +69,14 @@ def test_price_to_tick_reverts_when_gt_max(tick_mock): # check reverts when input price is 1 bps less input_price = int(input_price * (1.0001)) - with reverts("OVV1: tick out of bounds"): + with reverts("OVLV1: tick out of bounds"): tick_mock.priceToTick(input_price) def test_tick_to_price_reverts_when_lt_min(tick_mock): # reverts when smaller than min tick input_tick = -(410000 + 1) - with reverts("OVV1: tick out of bounds"): + with reverts("OVLV1: tick out of bounds"): tick_mock.tickToPrice(input_tick) # doesn't revert when equal to min tick @@ -90,7 +90,7 @@ def test_tick_to_price_reverts_when_gt_max(tick_mock): base = Decimal(1.0001) # reverts when larger than max tick input_tick = (1200000 + 1) - with reverts("OVV1: tick out of bounds"): + with reverts("OVLV1: tick out of bounds"): tick_mock.tickToPrice(input_tick) # doesn't revert when equal to max tick diff --git a/tests/markets/conftest.py b/tests/markets/conftest.py index f47b3547..bdc68ec5 100644 --- a/tests/markets/conftest.py +++ b/tests/markets/conftest.py @@ -94,7 +94,7 @@ def create_token(supply=sup): @pytest.fixture(scope="module") -def ov(create_token): +def ovl(create_token): yield create_token() @@ -120,7 +120,7 @@ def fake_feed(create_fake_feed): @pytest.fixture(scope="module") def uni(): - # to be used as example ov + # to be used as example ovl yield Contract.from_explorer("0xFa7F8980b0f1E64A2062791cc3b0871572f1F7f0") @@ -175,10 +175,10 @@ def mock_feed(create_mock_feed): @pytest.fixture(scope="module") -def create_factory(gov, guardian, fee_recipient, request, ov, governor_role, +def create_factory(gov, guardian, fee_recipient, request, ovl, governor_role, guardian_role, feed_factory, mock_feed_factory, sequencer_aggregator): - def create_factory(tok=ov, recipient=fee_recipient): + def create_factory(tok=ovl, recipient=fee_recipient): # create the market factory factory = gov.deploy(OverlayV1Factory, tok, recipient, sequencer_aggregator.address, 0) @@ -205,9 +205,9 @@ def factory(create_factory): @pytest.fixture(scope="module") -def create_fake_deployer(fake_factory, ov): - def create_fake_deployer(fake_factory=fake_factory, ov=ov): - return fake_factory.deploy(OverlayV1Deployer, ov) +def create_fake_deployer(fake_factory, ovl): + def create_fake_deployer(fake_factory=fake_factory, ovl=ovl): + return fake_factory.deploy(OverlayV1Deployer, ovl) yield create_fake_deployer @@ -218,9 +218,9 @@ def fake_deployer(create_fake_deployer): @pytest.fixture(scope="module") -def create_market(gov, ov): +def create_market(gov, ovl): def create_market(feed, factory, feed_factory, risk_params, - governance=gov, ov=ov): + governance=gov, ovl=ovl): tx = factory.deployMarket( feed_factory, feed, risk_params, {"from": gov}) market_addr = tx.return_value @@ -247,12 +247,12 @@ def create_market(feed, factory, feed_factory, risk_params, 25000000000000, # priceDriftUpperLimit 250, # averageBlockTime )]) -def mock_market(gov, mock_feed, mock_feed_factory, factory, ov, +def mock_market(gov, mock_feed, mock_feed_factory, factory, ovl, create_market, request): risk_params = request.param yield create_market(feed=mock_feed, feed_factory=mock_feed_factory, factory=factory, risk_params=risk_params, - governance=gov, ov=ov) + governance=gov, ovl=ovl) @pytest.fixture(scope="module", params=[( @@ -272,8 +272,8 @@ def mock_market(gov, mock_feed, mock_feed_factory, factory, ov, 25000000000000, # priceDriftUpperLimit 250, # averageBlockTime )]) -def market(gov, feed, feed_factory, factory, ov, create_market, request): +def market(gov, feed, feed_factory, factory, ovl, create_market, request): risk_params = request.param yield create_market(feed=feed, feed_factory=feed_factory, factory=factory, risk_params=risk_params, - governance=gov, ov=ov) + governance=gov, ovl=ovl) diff --git a/tests/markets/test_build.py b/tests/markets/test_build.py index f1842b7c..486e4203 100644 --- a/tests/markets/test_build.py +++ b/tests/markets/test_build.py @@ -28,7 +28,7 @@ def isolation(fn_isolation): places=3), leverage=strategy('decimal', min_value='1.0', max_value='5.0', places=3), is_long=strategy('bool')) -def test_build_creates_position(market, feed, ov, alice, notional, leverage, +def test_build_creates_position(market, feed, ovl, alice, notional, leverage, is_long): # NOTE: current position id is zero given isolation fixture expect_pos_id = 0 @@ -52,7 +52,7 @@ def test_build_creates_position(market, feed, ov, alice, notional, leverage, approve_collateral = int((collateral + trade_fee) * Decimal(1e18)) # approve market for spending then build - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -129,7 +129,7 @@ def test_build_creates_position(market, feed, ov, alice, notional, leverage, places=3), leverage=strategy('decimal', min_value='1.0', max_value='5.0', places=3), is_long=strategy('bool')) -def test_build_adds_oi(market, feed, ov, alice, notional, leverage, is_long): +def test_build_adds_oi(market, feed, ovl, alice, notional, leverage, is_long): # calculate expected pos info data idx_trade = RiskParameter.TRADING_FEE_RATE.value trading_fee_rate = Decimal(market.params(idx_trade) / 1e18) @@ -155,7 +155,7 @@ def test_build_adds_oi(market, feed, ov, alice, notional, leverage, is_long): if is_long else market.oiShortShares() # approve market for spending then build - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -199,7 +199,7 @@ def test_build_adds_oi(market, feed, ov, alice, notional, leverage, is_long): if is_long else market.oiShortShares() # approve market for spending then build again - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -235,7 +235,7 @@ def test_build_adds_oi(market, feed, ov, alice, notional, leverage, is_long): assert actual_oi_shares == actual_total_pos_oi_shares -def test_build_updates_market(market, ov, alice): +def test_build_updates_market(market, ovl, alice): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -267,7 +267,7 @@ def test_build_updates_market(market, ov, alice): # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -284,7 +284,7 @@ def test_build_updates_market(market, ov, alice): places=3), leverage=strategy('decimal', min_value='1.0', max_value='5.0', places=3), is_long=strategy('bool')) -def test_build_registers_volume(market, feed, ov, alice, notional, leverage, +def test_build_registers_volume(market, feed, ovl, alice, notional, leverage, is_long): # calculate expected pos info data idx_trade = RiskParameter.TRADING_FEE_RATE.value @@ -313,7 +313,7 @@ def test_build_registers_volume(market, feed, ov, alice, notional, leverage, last_timestamp, last_window, last_volume = snapshot_volume # approve market for spending then build - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -365,7 +365,7 @@ def test_build_registers_volume(market, feed, ov, alice, notional, leverage, places=3), leverage=strategy('decimal', min_value='1.0', max_value='5.0', places=3), is_long=strategy('bool')) -def test_build_executes_transfers(market, factory, ov, alice, notional, +def test_build_executes_transfers(market, factory, ovl, alice, notional, leverage, is_long): # calculate expected pos info data idx_trade = RiskParameter.TRADING_FEE_RATE.value @@ -387,7 +387,7 @@ def test_build_executes_transfers(market, factory, ov, alice, notional, approve_collateral = int((collateral + trade_fee) * Decimal(1e18)) # approve market for spending then build - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -417,7 +417,7 @@ def test_build_executes_transfers(market, factory, ov, alice, notional, places=3), leverage=strategy('decimal', min_value='1.0', max_value='5.0', places=3), is_long=strategy('bool')) -def test_build_transfers_collateral_to_market(market, ov, alice, notional, +def test_build_transfers_collateral_to_market(market, ovl, alice, notional, leverage, is_long): # calculate expected pos info data idx_trade = RiskParameter.TRADING_FEE_RATE.value @@ -439,11 +439,11 @@ def test_build_transfers_collateral_to_market(market, ov, alice, notional, approve_collateral = int((collateral + trade_fee) * Decimal(1e18)) # priors actual values - expect_balance_alice = ov.balanceOf(alice) - expect_balance_market = ov.balanceOf(market) + expect_balance_alice = ovl.balanceOf(alice) + expect_balance_market = ovl.balanceOf(market) # approve market for spending then build - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) _ = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -452,8 +452,8 @@ def test_build_transfers_collateral_to_market(market, ov, alice, notional, expect_balance_alice -= expect_collateral_in expect_balance_market += int(collateral * Decimal(1e18)) - actual_balance_alice = ov.balanceOf(alice) - actual_balance_market = ov.balanceOf(market) + actual_balance_alice = ovl.balanceOf(alice) + actual_balance_market = ovl.balanceOf(market) assert int(actual_balance_alice) == approx(expect_balance_alice) assert int(actual_balance_market) == approx(expect_balance_market) @@ -464,7 +464,7 @@ def test_build_transfers_collateral_to_market(market, ov, alice, notional, places=3), leverage=strategy('decimal', min_value='1.0', max_value='5.0', places=3), is_long=strategy('bool')) -def test_build_transfers_trading_fees(market, factory, ov, alice, notional, +def test_build_transfers_trading_fees(market, factory, ovl, alice, notional, leverage, is_long): # calculate expected pos info data idx_trade = RiskParameter.TRADING_FEE_RATE.value @@ -487,20 +487,20 @@ def test_build_transfers_trading_fees(market, factory, ov, alice, notional, # priors actual values recipient = factory.feeRecipient() - expect = ov.balanceOf(recipient) + expect = ovl.balanceOf(recipient) # approve market for spending then build - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) _ = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) expect += int(trade_fee * Decimal(1e18)) - actual = ov.balanceOf(recipient) + actual = ovl.balanceOf(recipient) assert int(actual) == approx(expect) -def test_build_reverts_when_leverage_less_than_one(market, ov, alice): +def test_build_reverts_when_leverage_less_than_one(market, ovl, alice): # NOTE: current position id is zero given isolation fixture expect_pos_id = 0 @@ -512,11 +512,11 @@ def test_build_reverts_when_leverage_less_than_one(market, ov, alice): input_price_limit = 2**256-1 if input_is_long else 0 # approve market for spending before build - ov.approve(market, 2**256-1, {"from": alice}) + ovl.approve(market, 2**256-1, {"from": alice}) # check build reverts when input leverage is less than one (ONE = 1e18) input_leverage = int(Decimal(1e18) - 1) - with reverts("OVV1:levmax"): + with reverts("OVLV1:lev>max"): _ = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -564,7 +564,7 @@ def test_build_reverts_when_leverage_greater_than_cap(market, ov, alice): @given( leverage=strategy('decimal', min_value='1.0', max_value='5.0', places=3), is_long=strategy('bool')) -def test_build_reverts_when_collateral_less_than_min(market, ov, alice, +def test_build_reverts_when_collateral_less_than_min(market, ovl, alice, leverage, is_long): # NOTE: current position id is zero given isolation fixture expect_pos_id = 0 @@ -579,10 +579,10 @@ def test_build_reverts_when_collateral_less_than_min(market, ov, alice, input_price_limit = 2**256-1 if is_long else 0 # approve market for spending then build. use max - ov.approve(market, 2**256 - 1, {"from": alice}) + ovl.approve(market, 2**256 - 1, {"from": alice}) # check build reverts for min_collat > collat - with reverts("OVV1:collateralcap"): + with reverts("OVLV1:oi>cap"): _ = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -631,7 +631,7 @@ def test_build_reverts_when_oi_greater_than_cap(market, ov, alice, is_long): def test_build_reverts_when_oi_greater_than_cap_w_circuit_breaker( - mock_market, mock_feed, factory, ov, alice, rando, gov): + mock_market, mock_feed, factory, ovl, alice, rando, gov): # set circuit breaker mint target much lower to see effects idx_mint = RiskParameter.CIRCUIT_BREAKER_MINT_TARGET.value mint_target = int(Decimal(1000) * Decimal(1e18)) @@ -663,7 +663,7 @@ def test_build_reverts_when_oi_greater_than_cap_w_circuit_breaker( # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -717,8 +717,8 @@ def test_build_reverts_when_oi_greater_than_cap_w_circuit_breaker( # approve then test build fails when greater than circuited cap # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) - with reverts("OVV1:oi>cap"): + ovl.approve(mock_market, approve_collateral, {"from": alice}) + with reverts("OVLV1:oi>cap"): _ = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -734,7 +734,7 @@ def test_build_reverts_when_oi_greater_than_cap_w_circuit_breaker( # NOTE: use mock_market so price doesn't move during test @given(is_long=strategy('bool')) -def test_build_reverts_when_liquidatable(mock_market, feed, ov, alice, +def test_build_reverts_when_liquidatable(mock_market, feed, ovl, alice, is_long): idx_delta = RiskParameter.DELTA.value idx_lmbda = RiskParameter.LMBDA.value @@ -792,12 +792,12 @@ def test_build_reverts_when_liquidatable(mock_market, feed, ov, alice, input_price_limit = 2**256-1 if is_long else 0 # approve market for spending before build. use max - ov.approve(mock_market, 2**256 - 1, {"from": alice}) + ovl.approve(mock_market, 2**256 - 1, {"from": alice}) # check build reverts when position is liquidatable input_notional = Decimal(cap_notional) * volume * Decimal(1 + tol) input_collateral = int((input_notional / leverage)) - with reverts("OVV1:liquidatable"): + with reverts("OVLV1:liquidatable"): _ = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -811,7 +811,7 @@ def test_build_reverts_when_liquidatable(mock_market, feed, ov, alice, assert tx.return_value == expect_pos_id -def test_build_reverts_when_oi_zero(mock_market, mock_feed, ov, alice, bob): +def test_build_reverts_when_oi_zero(mock_market, mock_feed, ovl, alice, bob): # NOTE: current position id is zero given isolation fixture expect_pos_id = 0 @@ -826,7 +826,7 @@ def test_build_reverts_when_oi_zero(mock_market, mock_feed, ov, alice, bob): input_price_limit = 2**256-1 # approve market for spending before build. use max - ov.approve(mock_market, 2**256 - 1, {"from": alice}) + ovl.approve(mock_market, 2**256 - 1, {"from": alice}) # check build reverts when price so large that # notional / price rounds down to zero @@ -834,7 +834,7 @@ def test_build_reverts_when_oi_zero(mock_market, mock_feed, ov, alice, bob): * Decimal(input_leverage) * Decimal(1 + tol)) mock_feed.setPrice(price, {"from": bob}) - with reverts("OVV1:oi==0"): + with reverts("OVLV1:oi==0"): _ = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -851,7 +851,7 @@ def test_build_reverts_when_oi_zero(mock_market, mock_feed, ov, alice, bob): assert expect_pos_id == actual_pos_id -def test_build_reverts_when_has_shutdown(factory, feed, market, ov, +def test_build_reverts_when_has_shutdown(factory, feed, market, ovl, alice, guardian): # build inputs input_collateral = int(1e18) @@ -863,7 +863,7 @@ def test_build_reverts_when_has_shutdown(factory, feed, market, ov, input_price_limit = 2**256-1 # approve market for spending before build. use max - ov.approve(market, 2**256 - 1, {"from": alice}) + ovl.approve(market, 2**256 - 1, {"from": alice}) # build one position prior to shutdown market.build(input_collateral, input_leverage, input_is_long, @@ -874,12 +874,12 @@ def test_build_reverts_when_has_shutdown(factory, feed, market, ov, factory.shutdown(feed, {"from": guardian}) # attempt to build again - with reverts("OVV1: shutdown"): + with reverts("OVLV1: shutdown"): market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) -def test_multiple_build_creates_multiple_positions(market, factory, ov, +def test_multiple_build_creates_multiple_positions(market, factory, ovl, feed, alice, bob): # loop through 10 times n = 10 @@ -906,8 +906,8 @@ def test_multiple_build_creates_multiple_positions(market, factory, ov, * (1 + trading_fee_rate))) # approve market for spending then build - ov.approve(market, approve_collateral_alice, {"from": alice}) - ov.approve(market, approve_collateral_bob, {"from": bob}) + ovl.approve(market, approve_collateral_alice, {"from": alice}) + ovl.approve(market, approve_collateral_bob, {"from": bob}) # per trade notional values notional_alice = total_notional_long / Decimal(n) diff --git a/tests/markets/test_conftest.py b/tests/markets/test_conftest.py index 261563bb..404606a6 100644 --- a/tests/markets/test_conftest.py +++ b/tests/markets/test_conftest.py @@ -1,19 +1,19 @@ from .utils import RiskParameter -def test_ov_fixture(ov): - assert ov.decimals() == 18 - assert ov.name() == "Overlay" - assert ov.symbol() == "OV" - assert ov.totalSupply() == 88888888000000000000000000 +def test_ov_fixture(ovl): + assert ovl.decimals() == 18 + assert ovl.name() == "Overlay" + assert ovl.symbol() == "OVL" + assert ovl.totalSupply() == 88888888000000000000000000 def test_token_fixtures(uni): assert uni.name() == "Uniswap" -def test_factory_fixture(factory, ov, fee_recipient): - assert factory.ov() == ov +def test_factory_fixture(factory, ovl, fee_recipient): + assert factory.ovl() == ovl assert factory.feeRecipient() == fee_recipient @@ -36,20 +36,20 @@ def test_fake_feed_fixture(fake_feed): assert fake_feed.reserve() == 2000000000000000000000000 -def test_fake_deployer_fixture(fake_deployer, fake_factory, ov): +def test_fake_deployer_fixture(fake_deployer, fake_factory, ovl): assert fake_deployer.factory() == fake_factory - assert fake_deployer.ov() == ov + assert fake_deployer.ovl() == ovl tok, feed, fact = fake_deployer.parameters() - assert tok == ov + assert tok == ovl assert feed == "0x0000000000000000000000000000000000000000" assert fact == fake_factory -def test_mock_market_fixture(mock_market, mock_feed, ov, factory, +def test_mock_market_fixture(mock_market, mock_feed, ovl, factory, minter_role, burner_role, gov): # check addresses set properly - assert mock_market.ov() == ov + assert mock_market.ovl() == ovl assert mock_market.feed() == mock_feed assert mock_market.factory() == factory @@ -74,9 +74,9 @@ def test_mock_market_fixture(mock_market, mock_feed, ov, factory, actual_params = [mock_market.params(name.value) for name in RiskParameter] assert expect_params == actual_params - # check mock market has minter and burner roles on ov token - assert ov.hasRole(minter_role, mock_market) is True - assert ov.hasRole(burner_role, mock_market) is True + # check mock market has minter and burner roles on ovl token + assert ovl.hasRole(minter_role, mock_market) is True + assert ovl.hasRole(burner_role, mock_market) is True # check oi related quantities are zero assert mock_market.oiLong() == 0 @@ -92,10 +92,10 @@ def test_mock_market_fixture(mock_market, mock_feed, ov, factory, assert mock_market.timestampUpdateLast() != 0 -def test_market_fixture(market, feed, ov, factory, minter_role, +def test_market_fixture(market, feed, ovl, factory, minter_role, burner_role, gov): # check addresses set properly - assert market.ov() == ov + assert market.ovl() == ovl assert market.feed() == feed assert market.factory() == factory @@ -120,9 +120,9 @@ def test_market_fixture(market, feed, ov, factory, minter_role, actual_params = [market.params(name.value) for name in RiskParameter] assert expect_params == actual_params - # check market has minter and burner roles on ov token - assert ov.hasRole(minter_role, market) is True - assert ov.hasRole(burner_role, market) is True + # check market has minter and burner roles on ovl token + assert ovl.hasRole(minter_role, market) is True + assert ovl.hasRole(burner_role, market) is True # check oi related quantities are zero assert market.oiLong() == 0 diff --git a/tests/markets/test_initialize.py b/tests/markets/test_initialize.py index b4627be9..9e3f3efe 100644 --- a/tests/markets/test_initialize.py +++ b/tests/markets/test_initialize.py @@ -13,7 +13,7 @@ def isolation(fn_isolation): pass -def test_initialize_creates_market(fake_deployer, ov, fake_feed, +def test_initialize_creates_market(fake_deployer, ovl, fake_feed, fake_factory, gov): # risk params k = 1220000000000 @@ -44,7 +44,7 @@ def test_initialize_creates_market(fake_deployer, ov, fake_feed, market = OverlayV1Market.at(market_addr) # check market deployed correctly with immutables - assert market.ov() == ov + assert market.ovl() == ovl assert market.feed() == fake_feed assert market.factory() == fake_factory @@ -93,11 +93,11 @@ def test_initialize_reverts_when_not_factory(fake_deployer, fake_feed, market = OverlayV1Market.at(market_addr) # attempt to initialize not from factory - with reverts("OVV1: !factory"): + with reverts("OVLV1: !factory"): _ = market.initialize(params, {"from": rando}) -def test_initialize_reverts_when_price_is_zero(ov, fake_deployer, fake_feed, +def test_initialize_reverts_when_price_is_zero(ovl, fake_deployer, fake_feed, fake_factory, gov): # risk params k = 1220000000000 @@ -132,11 +132,11 @@ def test_initialize_reverts_when_price_is_zero(ov, fake_deployer, fake_feed, fake_feed.setPrice(price, {"from": gov}) # check can not deploy the market - with reverts("OVV1:!data"): + with reverts("OVLV1:!data"): market.initialize(params, {"from": fake_factory}) -def test_deploy_reverts_when_max_leverage_is_liquidatable(ov, fake_feed, +def test_deploy_reverts_when_max_leverage_is_liquidatable(ovl, fake_feed, fake_deployer, fake_factory, gov): @@ -169,11 +169,11 @@ def test_deploy_reverts_when_max_leverage_is_liquidatable(ov, fake_feed, market = OverlayV1Market.at(market_addr) # check can not deploy the market - with reverts("OVV1: max lev immediately liquidatable"): + with reverts("OVLV1: max lev immediately liquidatable"): market.initialize(params, {"from": fake_factory}) -def test_deploy_reverts_when_price_drift_exceeds_max_exp(ov, fake_feed, +def test_deploy_reverts_when_price_drift_exceeds_max_exp(ovl, fake_feed, fake_deployer, fake_factory, gov): @@ -206,5 +206,5 @@ def test_deploy_reverts_when_price_drift_exceeds_max_exp(ov, fake_feed, market = OverlayV1Market.at(market_addr) # check can not deploy the market - with reverts("OVV1: price drift exceeds max exp"): + with reverts("OVLV1: price drift exceeds max exp"): market.initialize(params, {"from": fake_factory}) diff --git a/tests/markets/test_liquidate.py b/tests/markets/test_liquidate.py index 46c0a5e6..820bc63c 100644 --- a/tests/markets/test_liquidate.py +++ b/tests/markets/test_liquidate.py @@ -22,7 +22,7 @@ def isolation(fn_isolation): @given(is_long=strategy('bool')) def test_liquidate_updates_position(mock_market, mock_feed, alice, rando, - ov, is_long): + ovl, is_long): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -50,7 +50,7 @@ def test_liquidate_updates_position(mock_market, mock_feed, alice, rando, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -197,7 +197,7 @@ def test_liquidate_updates_position(mock_market, mock_feed, alice, rando, @given(is_long=strategy('bool')) -def test_liquidate_removes_oi(mock_market, mock_feed, alice, rando, ov, +def test_liquidate_removes_oi(mock_market, mock_feed, alice, rando, ovl, is_long): # position build attributes notional_initial = Decimal(1000) @@ -226,7 +226,7 @@ def test_liquidate_removes_oi(mock_market, mock_feed, alice, rando, ov, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -330,7 +330,7 @@ def test_liquidate_removes_oi(mock_market, mock_feed, alice, rando, ov, assert actual_liq_oi_shares == actual_liq_pos_oi_shares -def test_liquidate_updates_market(mock_market, mock_feed, alice, rando, ov): +def test_liquidate_updates_market(mock_market, mock_feed, alice, rando, ovl): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -359,7 +359,7 @@ def test_liquidate_updates_market(mock_market, mock_feed, alice, rando, ov): # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -445,7 +445,7 @@ def test_liquidate_updates_market(mock_market, mock_feed, alice, rando, ov): @given(is_long=strategy('bool')) def test_liquidate_registers_zero_volume(mock_market, mock_feed, alice, rando, - ov, is_long): + ovl, is_long): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -474,7 +474,7 @@ def test_liquidate_registers_zero_volume(mock_market, mock_feed, alice, rando, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -579,7 +579,7 @@ def test_liquidate_registers_zero_volume(mock_market, mock_feed, alice, rando, @given(is_long=strategy('bool')) def test_liquidate_registers_mint_or_burn(mock_market, mock_feed, alice, rando, - ov, is_long): + ovl, is_long): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -608,7 +608,7 @@ def test_liquidate_registers_mint_or_burn(mock_market, mock_feed, alice, rando, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -729,7 +729,7 @@ def test_liquidate_registers_mint_or_burn(mock_market, mock_feed, alice, rando, @given(is_long=strategy('bool')) def test_liquidate_executes_transfers(mock_market, mock_feed, alice, rando, - factory, ov, is_long): + factory, ovl, is_long): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -758,7 +758,7 @@ def test_liquidate_executes_transfers(mock_market, mock_feed, alice, rando, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -914,7 +914,7 @@ def test_liquidate_executes_transfers(mock_market, mock_feed, alice, rando, # TODO: check for correctness again @given(is_long=strategy('bool')) def test_liquidate_transfers_fee_to_liquidator(mock_market, mock_feed, alice, - rando, ov, is_long): + rando, ovl, is_long): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -943,7 +943,7 @@ def test_liquidate_transfers_fee_to_liquidator(mock_market, mock_feed, alice, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1016,8 +1016,8 @@ def test_liquidate_transfers_fee_to_liquidator(mock_market, mock_feed, alice, mock_feed.setPrice(liq_price, {"from": rando}) # priors actual values - expect_balance_rando = ov.balanceOf(rando) - expect_balance_market = ov.balanceOf(mock_market) + expect_balance_rando = ovl.balanceOf(rando) + expect_balance_market = ovl.balanceOf(mock_market) # calculate position attributes at the current time # ignore payoff cap @@ -1059,8 +1059,8 @@ def test_liquidate_transfers_fee_to_liquidator(mock_market, mock_feed, alice, expect_balance_rando += expect_liq_fee expect_balance_market -= expect_cost_plus_mint - actual_balance_rando = ov.balanceOf(rando) - actual_balance_market = ov.balanceOf(mock_market) + actual_balance_rando = ovl.balanceOf(rando) + actual_balance_market = ovl.balanceOf(mock_market) assert int(actual_balance_rando) == approx( expect_balance_rando, rel=1.05e-6) @@ -1071,7 +1071,7 @@ def test_liquidate_transfers_fee_to_liquidator(mock_market, mock_feed, alice, # TODO: check for correctness again @given(is_long=strategy('bool')) def test_liquidate_transfers_remaining_margin(mock_market, mock_feed, alice, - factory, rando, ov, is_long): + factory, rando, ovl, is_long): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -1100,7 +1100,7 @@ def test_liquidate_transfers_remaining_margin(mock_market, mock_feed, alice, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1174,8 +1174,8 @@ def test_liquidate_transfers_remaining_margin(mock_market, mock_feed, alice, # priors actual values recipient = factory.feeRecipient() - expect_balance_recipient = ov.balanceOf(recipient) - expect_balance_market = ov.balanceOf(mock_market) + expect_balance_recipient = ovl.balanceOf(recipient) + expect_balance_market = ovl.balanceOf(mock_market) # input values for liquidate input_owner = alice.address @@ -1223,8 +1223,8 @@ def test_liquidate_transfers_remaining_margin(mock_market, mock_feed, alice, expect_balance_recipient += expect_margin_remaining expect_balance_market -= expect_cost_plus_mint - actual_balance_recipient = ov.balanceOf(recipient) - actual_balance_market = ov.balanceOf(mock_market) + actual_balance_recipient = ovl.balanceOf(recipient) + actual_balance_market = ovl.balanceOf(mock_market) assert int(actual_balance_recipient) == approx( expect_balance_recipient, rel=1.05e-6) @@ -1235,7 +1235,7 @@ def test_liquidate_transfers_remaining_margin(mock_market, mock_feed, alice, def test_liquidate_floors_value_to_zero_when_position_underwater(mock_market, mock_feed, alice, rando, - ov, factory): + ovl, factory): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(5.0) @@ -1268,7 +1268,7 @@ def test_liquidate_floors_value_to_zero_when_position_underwater(mock_market, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1305,9 +1305,9 @@ def test_liquidate_floors_value_to_zero_when_position_underwater(mock_market, # priors actual values recipient = factory.feeRecipient() - expect_balance_recipient = ov.balanceOf(recipient) - expect_balance_market = ov.balanceOf(mock_market) - expect_balance_rando = ov.balanceOf(rando) + expect_balance_recipient = ovl.balanceOf(recipient) + expect_balance_market = ovl.balanceOf(mock_market) + expect_balance_rando = ovl.balanceOf(rando) # calculate position attributes at the current time # ignore payoff cap @@ -1342,9 +1342,9 @@ def test_liquidate_floors_value_to_zero_when_position_underwater(mock_market, expect_balance_recipient += expect_liq_fee expect_balance_market -= expect_value - actual_balance_recipient = ov.balanceOf(recipient) - actual_balance_market = ov.balanceOf(mock_market) - actual_balance_rando = ov.balanceOf(rando) + actual_balance_recipient = ovl.balanceOf(recipient) + actual_balance_market = ovl.balanceOf(mock_market) + actual_balance_rando = ovl.balanceOf(rando) assert int(actual_balance_recipient) == approx(expect_balance_recipient) assert int(actual_balance_market) == approx(expect_balance_market) @@ -1353,7 +1353,7 @@ def test_liquidate_floors_value_to_zero_when_position_underwater(mock_market, def test_liquidate_reverts_when_not_position_owner(mock_market, mock_feed, alice, bob, - rando, ov): + rando, ovl): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -1382,7 +1382,7 @@ def test_liquidate_reverts_when_not_position_owner(mock_market, mock_feed, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1457,7 +1457,7 @@ def test_liquidate_reverts_when_not_position_owner(mock_market, mock_feed, # check liquidate reverts when owner is assumed to be bob input_owner = bob.address - with reverts("OVV1:!position"): + with reverts("OVLV1:!position"): mock_market.liquidate(input_owner, input_pos_id, {"from": rando}) # check liquidate succeeds when owner is specified as alice @@ -1466,17 +1466,17 @@ def test_liquidate_reverts_when_not_position_owner(mock_market, mock_feed, def test_liquidate_reverts_when_position_not_exists(mock_market, alice, rando, - ov): + ovl): pos_id = 100 # check liquidate reverts when position does not exist - with reverts("OVV1:!position"): + with reverts("OVLV1:!position"): mock_market.liquidate(alice, pos_id, {"from": rando}) def test_liquidate_reverts_when_position_liquidated(mock_market, mock_feed, alice, rando, - ov): + ovl): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -1505,7 +1505,7 @@ def test_liquidate_reverts_when_position_liquidated(mock_market, mock_feed, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1583,13 +1583,13 @@ def test_liquidate_reverts_when_position_liquidated(mock_market, mock_feed, mock_market.liquidate(input_owner, input_pos_id, {"from": rando}) # check attempting to liquidate again reverts - with reverts("OVV1:!position"): + with reverts("OVLV1:!position"): mock_market.liquidate(input_owner, input_pos_id, {"from": rando}) def test_liquidate_reverts_when_position_not_liquidatable(mock_market, mock_feed, alice, - rando, ov): + rando, ovl): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -1618,7 +1618,7 @@ def test_liquidate_reverts_when_position_not_liquidatable(mock_market, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1692,7 +1692,7 @@ def test_liquidate_reverts_when_position_not_liquidatable(mock_market, input_owner = alice.address # check attempting to liquidate position reverts when not liquidatable - with reverts("OVV1:!liquidatable"): + with reverts("OVLV1:!liquidatable"): mock_market.liquidate(input_owner, input_pos_id, {"from": rando}) # calculate the liquidation price factor @@ -1728,7 +1728,7 @@ def test_liquidate_reverts_when_position_not_liquidatable(mock_market, def test_liquidate_reverts_when_has_shutdown(factory, mock_feed, mock_market, - ov, alice, guardian, rando): + ovl, alice, guardian, rando): # build inputs input_collateral = int(1e18) input_leverage = int(2e18) @@ -1739,7 +1739,7 @@ def test_liquidate_reverts_when_has_shutdown(factory, mock_feed, mock_market, input_price_limit = 2**256-1 # approve market for spending before build. use max - ov.approve(mock_market, 2**256 - 1, {"from": alice}) + ovl.approve(mock_market, 2**256 - 1, {"from": alice}) # build two positions prior to shutdown tx_0 = mock_market.build(input_collateral, input_leverage, input_is_long, @@ -1763,7 +1763,7 @@ def test_liquidate_reverts_when_has_shutdown(factory, mock_feed, mock_market, factory.shutdown(mock_feed, {"from": guardian}) # attempt to liquidate - with reverts("OVV1: shutdown"): + with reverts("OVLV1: shutdown"): mock_market.liquidate(alice, input_pos_id_1, {"from": rando}) diff --git a/tests/markets/test_oi_cap.py b/tests/markets/test_oi_cap.py index 75bc735f..f8577b84 100644 --- a/tests/markets/test_oi_cap.py +++ b/tests/markets/test_oi_cap.py @@ -156,7 +156,7 @@ def test_cap_oi_adjusted_for_circuit_breaker(market, feed): def test_cap_oi_adjusted_for_circuit_breaker_after_mint( - ov, alice, rando, mock_market, mock_feed, factory, gov): + ovl, alice, rando, mock_market, mock_feed, factory, gov): # set circuit breaker mint target much lower to see effects idx_mint = RiskParameter.CIRCUIT_BREAKER_MINT_TARGET.value mint_target = int(Decimal(1000) * Decimal(1e18)) @@ -186,7 +186,7 @@ def test_cap_oi_adjusted_for_circuit_breaker_after_mint( # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value diff --git a/tests/markets/test_price.py b/tests/markets/test_price.py index 73035074..02575a74 100644 --- a/tests/markets/test_price.py +++ b/tests/markets/test_price.py @@ -75,7 +75,7 @@ def test_bid_reverts_when_slippage_greater_than_max(market, rando): # check reverts when volume produces slippage greater than max volume = Decimal(max_volume) * Decimal(1 + tol) input_volume = volume * Decimal(1e18) - with reverts("OVV1:slippage>max"): + with reverts("OVLV1:slippage>max"): market.bid(data, input_volume) # check does not revert when volume produces slippage about equal to max @@ -152,7 +152,7 @@ def test_ask_reverts_when_impact_greater_than_max_slippage(market, rando): # check reverts when volume produces slippage greater than max volume = Decimal(max_volume) * Decimal(1 + tol) input_volume = volume * Decimal(1e18) - with reverts("OVV1:slippage>max"): + with reverts("OVLV1:slippage>max"): market.ask(data, input_volume) # check does not revert when volume produces slippage about equal to max diff --git a/tests/markets/test_setters.py b/tests/markets/test_setters.py index 1d2f8214..da623b37 100644 --- a/tests/markets/test_setters.py +++ b/tests/markets/test_setters.py @@ -47,7 +47,7 @@ def test_set_risk_param(market, factory): chain.undo() -def test_set_risk_param_pays_funding(market, feed, factory, ov, alice): +def test_set_risk_param_pays_funding(market, feed, factory, ovl, alice): # risk params expect_params = [ 2220000000000, # expect_k @@ -93,7 +93,7 @@ def test_set_risk_param_pays_funding(market, feed, factory, ov, alice): # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) _ = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -165,7 +165,7 @@ def test_set_risk_param_caches_calc(market, feed, factory): def test_set_risk_param_reverts_when_not_factory(market, alice): expect_k = 2220000000000 - with reverts("OVV1: !factory"): + with reverts("OVLV1: !factory"): _ = market.setRiskParam(0, expect_k, {"from": alice}) @@ -186,7 +186,7 @@ def test_set_delta_reverts_when_max_lev_liquidatable(market, factory): # check reverts when delta just above max input_delta = int(max_delta * Decimal(1e18) * Decimal(1 + tol)) - with reverts("OVV1: max lev immediately liquidatable"): + with reverts("OVLV1: max lev immediately liquidatable"): market.setRiskParam(idx_delta, input_delta, {"from": factory}) # check doesn't revert when delta just below max @@ -215,7 +215,7 @@ def test_set_cap_leverage_reverts_when_max_lev_liquidatable(market, factory): # check reverts when one cap leverage greater than max input_cap_leverage = int(max_cap_leverage * Decimal(1e18) * Decimal(1+tol)) - with reverts("OVV1: max lev immediately liquidatable"): + with reverts("OVLV1: max lev immediately liquidatable"): market.setRiskParam(idx_cap_leverage, input_cap_leverage, {"from": factory}) @@ -248,7 +248,7 @@ def test_set_maintenance_margin_fraction_reverts_when_max_lev_liquidatable( # check reverts when mmf greater than max input_mmf = int(max_mmf * Decimal(1e18) * Decimal(1 + tol)) - with reverts("OVV1: max lev immediately liquidatable"): + with reverts("OVLV1: max lev immediately liquidatable"): market.setRiskParam(idx_mmf, input_mmf, {"from": factory}) # check doesn't revert when maitenance margin fraction less than max @@ -279,7 +279,7 @@ def test_set_liquidation_fee_rate_reverts_when_max_lev_liquidatable( # check reverts when greater than liquidationFeeRate max input_lfr = int(max_lfr * Decimal(1e18) * Decimal(1 + tol)) - with reverts("OVV1: max lev immediately liquidatable"): + with reverts("OVLV1: max lev immediately liquidatable"): market.setRiskParam(idx_lfr, input_lfr, {"from": factory}) # check doesn't revert when liquidation fee rate less than max @@ -304,7 +304,7 @@ def test_set_price_drift_upper_limit_reverts_when_exceeds_max_exp( + 1 # check reverts when one more than max - with reverts("OVV1: price drift exceeds max exp"): + with reverts("OVLV1: price drift exceeds max exp"): market.setRiskParam( idx_price_drift_upper_limit, max_price_drift_upper_limit, {"from": factory}) diff --git a/tests/markets/test_slippage.py b/tests/markets/test_slippage.py index c1d224e1..6fb98c40 100644 --- a/tests/markets/test_slippage.py +++ b/tests/markets/test_slippage.py @@ -15,7 +15,7 @@ def isolation(fn_isolation): @given(is_long=strategy('bool')) -def test_build_when_price_limit_is_breached(market, feed, alice, ov, is_long): +def test_build_when_price_limit_is_breached(market, feed, alice, ovl, is_long): # NOTE: current position id is zero given isolation fixture expect_pos_id = 0 @@ -55,11 +55,11 @@ def test_build_when_price_limit_is_breached(market, feed, alice, ov, is_long): approve_collateral = int((collateral + trade_fee) * Decimal(1e18)) # approve market for spending then build - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) # check build reverts when price surpasses limit input_price_limit = price * (1 - tol) if is_long else price * (1 + tol) - with reverts("OVV1:slippage>max"): + with reverts("OVLV1:slippage>max"): market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) @@ -74,7 +74,7 @@ def test_build_when_price_limit_is_breached(market, feed, alice, ov, is_long): @given(is_long=strategy('bool')) -def test_unwind_when_price_limit_is_breached(market, feed, alice, factory, ov, +def test_unwind_when_price_limit_is_breached(market, feed, alice, factory, ovl, is_long): # build attributes notional = Decimal(100) @@ -102,7 +102,7 @@ def test_unwind_when_price_limit_is_breached(market, feed, alice, factory, ov, approve_collateral = int((collateral + trade_fee) * Decimal(1e18)) # approve market for spending then build - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -132,7 +132,7 @@ def test_unwind_when_price_limit_is_breached(market, feed, alice, factory, ov, # check unwind reverts when price surpasses limit input_price_limit = price * (1 + tol) if is_long else price * (1 - tol) - with reverts("OVV1:slippage>max"): + with reverts("OVLV1:slippage>max"): market.unwind(input_pos_id, input_fraction, input_price_limit, {"from": alice}) diff --git a/tests/markets/test_unwind.py b/tests/markets/test_unwind.py index a227a159..ec4ddefb 100644 --- a/tests/markets/test_unwind.py +++ b/tests/markets/test_unwind.py @@ -25,7 +25,7 @@ def isolation(fn_isolation): fraction=strategy('decimal', min_value='0.0001', max_value='1.0000', places=4), is_long=strategy('bool')) -def test_unwind_updates_position(market, feed, alice, rando, ov, +def test_unwind_updates_position(market, feed, alice, rando, ovl, fraction, is_long): # position build attributes notional_initial = Decimal(1000) @@ -51,7 +51,7 @@ def test_unwind_updates_position(market, feed, alice, rando, ov, # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -162,7 +162,7 @@ def test_unwind_updates_position(market, feed, alice, rando, ov, # unwind fraction of shares again # check remaining fraction is (1 - fraction)**2 if fraction == int(1e18): - with reverts("OVV1:!position"): + with reverts("OVLV1:!position"): _ = market.unwind(input_pos_id, input_fraction, input_price_limit, {"from": alice}) else: @@ -190,7 +190,7 @@ def test_unwind_updates_position(market, feed, alice, rando, ov, fraction=strategy('decimal', min_value='0.0001', max_value='1.0000', places=4), is_long=strategy('bool')) -def test_unwind_removes_oi(market, feed, alice, rando, ov, +def test_unwind_removes_oi(market, feed, alice, rando, ovl, fraction, is_long): # position build attributes notional_initial = Decimal(1000) @@ -216,7 +216,7 @@ def test_unwind_removes_oi(market, feed, alice, rando, ov, # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -283,7 +283,7 @@ def test_unwind_removes_oi(market, feed, alice, rando, ov, assert actual_unwound_oi_shares == actual_unwound_pos_oi_shares -def test_unwind_updates_market(market, alice, ov): +def test_unwind_updates_market(market, alice, ovl): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -310,7 +310,7 @@ def test_unwind_updates_market(market, alice, ov): # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -346,7 +346,7 @@ def test_unwind_updates_market(market, alice, ov): fraction=strategy('decimal', min_value='0.0001', max_value='1.0000', places=4), is_long=strategy('bool')) -def test_unwind_registers_volume(market, feed, alice, rando, ov, +def test_unwind_registers_volume(market, feed, alice, rando, ovl, fraction, is_long): # position build attributes notional_initial = Decimal(1000) @@ -372,7 +372,7 @@ def test_unwind_registers_volume(market, feed, alice, rando, ov, # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -459,7 +459,7 @@ def test_unwind_registers_volume(market, feed, alice, rando, ov, fraction=strategy('decimal', min_value='0.0001', max_value='1.0000', places=4), is_long=strategy('bool')) -def test_unwind_registers_mint_or_burn(market, feed, alice, rando, ov, +def test_unwind_registers_mint_or_burn(market, feed, alice, rando, ovl, fraction, is_long): # position build attributes notional_initial = Decimal(1000) @@ -485,7 +485,7 @@ def test_unwind_registers_mint_or_burn(market, feed, alice, rando, ov, # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -552,7 +552,7 @@ def test_unwind_registers_mint_or_burn(market, feed, alice, rando, ov, fraction=strategy('decimal', min_value='0.0001', max_value='1.0000', places=4), is_long=strategy('bool')) -def test_unwind_executes_transfers(market, feed, alice, rando, ov, +def test_unwind_executes_transfers(market, feed, alice, rando, ovl, factory, fraction, is_long): # position build attributes notional_initial = Decimal(1000) @@ -578,7 +578,7 @@ def test_unwind_executes_transfers(market, feed, alice, rando, ov, # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -703,7 +703,7 @@ def test_unwind_executes_transfers(market, feed, alice, rando, ov, fraction=strategy('decimal', min_value='0.0001', max_value='1.0000', places=4), is_long=strategy('bool')) -def test_unwind_transfers_value_to_trader(market, feed, alice, rando, ov, +def test_unwind_transfers_value_to_trader(market, feed, alice, rando, ovl, fraction, is_long): # position build attributes notional_initial = Decimal(1000) @@ -729,7 +729,7 @@ def test_unwind_transfers_value_to_trader(market, feed, alice, rando, ov, # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -749,8 +749,8 @@ def test_unwind_transfers_value_to_trader(market, feed, alice, rando, ov, tx = market.update({"from": rando}) # priors actual values - expect_balance_alice = ov.balanceOf(alice) - expect_balance_market = ov.balanceOf(market) + expect_balance_alice = ovl.balanceOf(alice) + expect_balance_market = ovl.balanceOf(market) # calculate position attributes at the current time for fraction # ignore payoff cap @@ -783,8 +783,8 @@ def test_unwind_transfers_value_to_trader(market, feed, alice, rando, ov, expect_balance_alice += expect_value_out expect_balance_market -= expect_value - actual_balance_alice = ov.balanceOf(alice) - actual_balance_market = ov.balanceOf(market) + actual_balance_alice = ovl.balanceOf(alice) + actual_balance_market = ovl.balanceOf(market) assert int(actual_balance_alice) == approx(expect_balance_alice) assert int(actual_balance_market) == approx(expect_balance_market) @@ -792,7 +792,7 @@ def test_unwind_transfers_value_to_trader(market, feed, alice, rando, ov, @given(is_long=strategy('bool')) def test_unwind_transfers_full_value_to_trader_when_fraction_one( - market, feed, alice, rando, ov, is_long): + market, feed, alice, rando, ovl, is_long): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -818,7 +818,7 @@ def test_unwind_transfers_full_value_to_trader_when_fraction_one( # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -838,8 +838,8 @@ def test_unwind_transfers_full_value_to_trader_when_fraction_one( tx = market.update({"from": rando}) # priors actual values - expect_balance_alice = ov.balanceOf(alice) - expect_balance_market = ov.balanceOf(market) + expect_balance_alice = ovl.balanceOf(alice) + expect_balance_market = ovl.balanceOf(market) # calculate position attributes at the current time for fraction # ignore payoff cap @@ -872,8 +872,8 @@ def test_unwind_transfers_full_value_to_trader_when_fraction_one( expect_balance_alice += expect_value_out expect_balance_market -= expect_value - actual_balance_alice = ov.balanceOf(alice) - actual_balance_market = ov.balanceOf(market) + actual_balance_alice = ovl.balanceOf(alice) + actual_balance_market = ovl.balanceOf(market) assert int(actual_balance_alice) == approx(expect_balance_alice) assert int(actual_balance_market) == approx(expect_balance_market) @@ -883,7 +883,7 @@ def test_unwind_transfers_full_value_to_trader_when_fraction_one( fraction=strategy('decimal', min_value='0.0001', max_value='1.0000', places=4), is_long=strategy('bool')) -def test_unwind_transfers_trading_fees(market, feed, alice, rando, ov, +def test_unwind_transfers_trading_fees(market, feed, alice, rando, ovl, factory, fraction, is_long): # position build attributes notional_initial = Decimal(1000) @@ -909,7 +909,7 @@ def test_unwind_transfers_trading_fees(market, feed, alice, rando, ov, # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -930,8 +930,8 @@ def test_unwind_transfers_trading_fees(market, feed, alice, rando, ov, # priors actual values recipient = factory.feeRecipient() - expect_balance_recipient = ov.balanceOf(recipient) - expect_balance_market = ov.balanceOf(market) + expect_balance_recipient = ovl.balanceOf(recipient) + expect_balance_market = ovl.balanceOf(market) # calculate position attributes at the current time for fraction # ignore payoff cap @@ -962,8 +962,8 @@ def test_unwind_transfers_trading_fees(market, feed, alice, rando, ov, expect_balance_recipient += expect_trade_fee expect_balance_market -= expect_value - actual_balance_recipient = ov.balanceOf(recipient) - actual_balance_market = ov.balanceOf(market) + actual_balance_recipient = ovl.balanceOf(recipient) + actual_balance_market = ovl.balanceOf(market) assert int(actual_balance_recipient) == approx(expect_balance_recipient) assert int(actual_balance_market) == approx(expect_balance_market) @@ -978,7 +978,7 @@ def test_unwind_transfers_trading_fees(market, feed, alice, rando, ov, max_value='5.0000', places=4)) def test_unwind_mints_when_profitable(mock_market, mock_feed, alice, rando, - ov, fraction, is_long, + ovl, fraction, is_long, price_multiplier): # position build attributes notional_initial = Decimal(1000) @@ -1004,7 +1004,7 @@ def test_unwind_mints_when_profitable(mock_market, mock_feed, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1092,7 +1092,7 @@ def test_unwind_mints_when_profitable(mock_market, mock_feed, max_value='1.50000', places=4)) def test_unwind_burns_when_not_profitable(mock_market, mock_feed, alice, rando, - ov, fraction, is_long, + ovl, fraction, is_long, price_multiplier): # position build attributes notional_initial = Decimal(1000) @@ -1118,7 +1118,7 @@ def test_unwind_burns_when_not_profitable(mock_market, mock_feed, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1210,7 +1210,7 @@ def test_unwind_burns_when_not_profitable(mock_market, mock_feed, max_value='10.0000', places=4)) def test_unwind_mints_when_greater_than_cap_payoff(mock_market, mock_feed, alice, rando, - ov, fraction, + ovl, fraction, price_multiplier): # position build attributes notional_initial = Decimal(1000) @@ -1237,7 +1237,7 @@ def test_unwind_mints_when_greater_than_cap_payoff(mock_market, mock_feed, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1321,7 +1321,7 @@ def test_unwind_mints_when_greater_than_cap_payoff(mock_market, mock_feed, def test_unwind_transfers_fees_when_fees_greater_than_value(mock_market, mock_feed, alice, factory, rando, - ov): + ovl): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(5.0) @@ -1354,7 +1354,7 @@ def test_unwind_transfers_fees_when_fees_greater_than_value(mock_market, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1379,9 +1379,9 @@ def test_unwind_transfers_fees_when_fees_greater_than_value(mock_market, # priors actual values recipient = factory.feeRecipient() - expect_balance_recipient = ov.balanceOf(recipient) - expect_balance_market = ov.balanceOf(mock_market) - expect_balance_alice = ov.balanceOf(alice) + expect_balance_recipient = ovl.balanceOf(recipient) + expect_balance_market = ovl.balanceOf(mock_market) + expect_balance_alice = ovl.balanceOf(alice) # change price by factor price = mock_feed.price() * price_multiplier if is_long \ @@ -1444,9 +1444,9 @@ def test_unwind_transfers_fees_when_fees_greater_than_value(mock_market, # check amount burnt + unwound_value sent to recipient == unwound_cost assert approx(int(unwound_cost)) == actual_burn + int(unwound_value) - actual_balance_recipient = ov.balanceOf(recipient) - actual_balance_market = ov.balanceOf(mock_market) - actual_balance_alice = ov.balanceOf(alice) + actual_balance_recipient = ovl.balanceOf(recipient) + actual_balance_market = ovl.balanceOf(mock_market) + actual_balance_alice = ovl.balanceOf(alice) assert int(actual_balance_recipient) == approx(expect_balance_recipient) assert int(actual_balance_market) == approx(expect_balance_market) @@ -1456,7 +1456,7 @@ def test_unwind_transfers_fees_when_fees_greater_than_value(mock_market, # test for when value is underwater and unwind def test_unwind_floors_value_to_zero_when_position_underwater(mock_market, mock_feed, alice, - rando, ov, + rando, ovl, factory): # position build attributes notional_initial = Decimal(1000) @@ -1490,7 +1490,7 @@ def test_unwind_floors_value_to_zero_when_position_underwater(mock_market, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1511,9 +1511,9 @@ def test_unwind_floors_value_to_zero_when_position_underwater(mock_market, # priors actual values recipient = factory.feeRecipient() - expect_balance_recipient = ov.balanceOf(recipient) - expect_balance_market = ov.balanceOf(mock_market) - expect_balance_alice = ov.balanceOf(alice) + expect_balance_recipient = ovl.balanceOf(recipient) + expect_balance_market = ovl.balanceOf(mock_market) + expect_balance_alice = ovl.balanceOf(alice) # change price by factor price = mock_feed.price() * price_multiplier if is_long \ @@ -1557,16 +1557,16 @@ def test_unwind_floors_value_to_zero_when_position_underwater(mock_market, expect_balance_recipient += expect_trade_fee expect_balance_market -= expect_value - actual_balance_recipient = ov.balanceOf(recipient) - actual_balance_market = ov.balanceOf(mock_market) - actual_balance_alice = ov.balanceOf(alice) + actual_balance_recipient = ovl.balanceOf(recipient) + actual_balance_market = ovl.balanceOf(mock_market) + actual_balance_alice = ovl.balanceOf(alice) assert int(actual_balance_recipient) == approx(expect_balance_recipient) assert int(actual_balance_market) == approx(expect_balance_market) assert int(actual_balance_alice) == approx(expect_balance_alice) -def test_unwind_reverts_when_fraction_zero(market, alice, ov): +def test_unwind_reverts_when_fraction_zero(market, alice, ovl): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -1592,7 +1592,7 @@ def test_unwind_reverts_when_fraction_zero(market, alice, ov): # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1603,13 +1603,13 @@ def test_unwind_reverts_when_fraction_zero(market, alice, ov): # check unwind reverts when fraction is zero input_fraction = 0 - with reverts("OVV1:fractionmax"): + with reverts("OVLV1:fraction>max"): market.unwind(pos_id, input_fraction, input_price_limit, {"from": alice}) @@ -1665,7 +1665,7 @@ def test_unwind_reverts_when_fraction_greater_than_one(market, alice, ov): market.unwind(pos_id, input_fraction, input_price_limit, {"from": alice}) -def test_unwind_reverts_when_not_position_owner(market, alice, bob, ov): +def test_unwind_reverts_when_not_position_owner(market, alice, bob, ovl): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -1691,7 +1691,7 @@ def test_unwind_reverts_when_not_position_owner(market, alice, bob, ov): # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1702,24 +1702,24 @@ def test_unwind_reverts_when_not_position_owner(market, alice, bob, ov): # check unwind reverts when bob attempts input_fraction = 1000000000000000000 - with reverts("OVV1:!position"): + with reverts("OVLV1:!position"): market.unwind(pos_id, input_fraction, input_price_limit, {"from": bob}) # check unwind succeeds when alice attempts market.unwind(pos_id, input_fraction, input_price_limit, {"from": alice}) -def test_unwind_reverts_when_position_never_built(market, alice, ov): +def test_unwind_reverts_when_position_never_built(market, alice, ovl): pos_id = 100 # check unwind reverts when position does not exist since never built input_fraction = 1000000000000000000 - with reverts("OVV1:!position"): + with reverts("OVLV1:!position"): market.unwind(pos_id, input_fraction, 0, {"from": alice}) def test_unwind_reverts_when_position_already_unwound_fully( - market, alice, ov): + market, alice, ovl): # build a position and unwind it fully # check unwind reverts after unwound fully (fractionRemaining == 0) # position build attributes @@ -1747,7 +1747,7 @@ def test_unwind_reverts_when_position_already_unwound_fully( # approve then build # NOTE: build() tests in test_build.py - ov.approve(market, approve_collateral, {"from": alice}) + ovl.approve(market, approve_collateral, {"from": alice}) tx = market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1761,7 +1761,7 @@ def test_unwind_reverts_when_position_already_unwound_fully( market.unwind(pos_id, input_fraction, input_price_limit, {"from": alice}) # Attempting to unwind again should revert - with reverts("OVV1:!position"): + with reverts("OVLV1:!position"): market.unwind(pos_id, input_fraction, input_price_limit, {"from": alice}) @@ -1769,7 +1769,7 @@ def test_unwind_reverts_when_position_already_unwound_fully( @given(is_long=strategy('bool')) def test_unwind_reverts_when_position_liquidated(mock_market, mock_feed, is_long, - factory, alice, rando, ov): + factory, alice, rando, ovl): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -1800,7 +1800,7 @@ def test_unwind_reverts_when_position_liquidated(mock_market, mock_feed, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1878,7 +1878,7 @@ def test_unwind_reverts_when_position_liquidated(mock_market, mock_feed, # check attempting to unwind after liquidate reverts input_fraction = 1000000000000000000 input_price_limit = 0 if is_long else 2**256-1 - with reverts("OVV1:!position"): + with reverts("OVLV1:!position"): mock_market.unwind(input_pos_id, input_fraction, input_price_limit, {"from": alice}) @@ -1886,7 +1886,7 @@ def test_unwind_reverts_when_position_liquidated(mock_market, mock_feed, @given(is_long=strategy('bool')) def test_unwind_reverts_when_position_liquidatable(mock_market, mock_feed, is_long, factory, - alice, rando, ov): + alice, rando, ovl): # position build attributes notional_initial = Decimal(1000) leverage = Decimal(1.5) @@ -1917,7 +1917,7 @@ def test_unwind_reverts_when_position_liquidatable(mock_market, mock_feed, # approve then build # NOTE: build() tests in test_build.py - ov.approve(mock_market, approve_collateral, {"from": alice}) + ovl.approve(mock_market, approve_collateral, {"from": alice}) tx = mock_market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) pos_id = tx.return_value @@ -1989,7 +1989,7 @@ def test_unwind_reverts_when_position_liquidatable(mock_market, mock_feed, # check attempting to unwind when liquidatable reverts input_fraction = 1000000000000000000 - with reverts("OVV1:liquidatable"): + with reverts("OVLV1:liquidatable"): mock_market.unwind(input_pos_id, input_fraction, 0, {"from": alice}) # check attempting to unwind succeeds when no longer liquidatable @@ -2008,7 +2008,7 @@ def test_unwind_reverts_when_position_liquidatable(mock_market, mock_feed, {"from": alice}) -def test_unwind_reverts_when_has_shutdown(factory, feed, market, ov, +def test_unwind_reverts_when_has_shutdown(factory, feed, market, ovl, alice, guardian): # build inputs input_collateral = int(1e18) @@ -2020,7 +2020,7 @@ def test_unwind_reverts_when_has_shutdown(factory, feed, market, ov, input_price_limit = 2**256-1 # approve market for spending before build. use max - ov.approve(market, 2**256 - 1, {"from": alice}) + ovl.approve(market, 2**256 - 1, {"from": alice}) # build one position prior to shutdown tx = market.build(input_collateral, input_leverage, input_is_long, @@ -2038,12 +2038,12 @@ def test_unwind_reverts_when_has_shutdown(factory, feed, market, ov, factory.shutdown(feed, {"from": guardian}) # attempt to unwind again - with reverts("OVV1: shutdown"): + with reverts("OVLV1: shutdown"): market.unwind(input_pos_id, input_fraction, input_price_limit, {"from": alice}) -def test_multiple_unwind_unwinds_multiple_positions(market, factory, ov, +def test_multiple_unwind_unwinds_multiple_positions(market, factory, ovl, alice, bob, rando): # loop through 10 times n = 10 @@ -2068,8 +2068,8 @@ def test_multiple_unwind_unwinds_multiple_positions(market, factory, ov, * (1 + trading_fee_rate))) # approve market for spending then build - ov.approve(market, approve_collateral_alice, {"from": alice}) - ov.approve(market, approve_collateral_bob, {"from": bob}) + ovl.approve(market, approve_collateral_alice, {"from": alice}) + ovl.approve(market, approve_collateral_bob, {"from": bob}) # per trade notional values notional_alice = total_notional_long / Decimal(n) diff --git a/tests/markets/test_update.py b/tests/markets/test_update.py index 678954a0..257419eb 100644 --- a/tests/markets/test_update.py +++ b/tests/markets/test_update.py @@ -20,7 +20,7 @@ def test_update_fetches_from_feed(market, feed, rando): places=3), notional_short=strategy('decimal', min_value='0.001', max_value='80000', places=3)) -def test_update_pays_funding(market, feed, ov, alice, bob, rando, +def test_update_pays_funding(market, feed, ovl, alice, bob, rando, notional_long, notional_short): idx_trade = RiskParameter.TRADING_FEE_RATE.value @@ -33,8 +33,8 @@ def test_update_pays_funding(market, feed, ov, alice, bob, rando, approve_collateral_short = notional_short * (1 + trading_fee_rate) # approve collateral amounts - ov.approve(market, approve_collateral_long, {"from": alice}) - ov.approve(market, approve_collateral_short, {"from": bob}) + ovl.approve(market, approve_collateral_long, {"from": alice}) + ovl.approve(market, approve_collateral_short, {"from": bob}) # build long and short positions for oi # NOTE: build() tests in test_build.py diff --git a/tests/markets/test_withdraw.py b/tests/markets/test_withdraw.py index 3ed0f524..4dd0765b 100644 --- a/tests/markets/test_withdraw.py +++ b/tests/markets/test_withdraw.py @@ -14,7 +14,7 @@ def isolation(fn_isolation): # shutdown tests -def test_shutdown(market, factory, ov, alice): +def test_shutdown(market, factory, ovl, alice): # shutdown the market through factory market.shutdown({"from": factory}) @@ -28,20 +28,20 @@ def test_shutdown(market, factory, ov, alice): input_price_limit = 2**256-1 # approve market for spending before build. use max - ov.approve(market, 2**256 - 1, {"from": alice}) - with reverts("OVV1: shutdown"): + ovl.approve(market, 2**256 - 1, {"from": alice}) + with reverts("OVLV1: shutdown"): market.build(input_collateral, input_leverage, input_is_long, input_price_limit, {"from": alice}) def test_shutdown_reverts_when_not_factory(market, rando): - with reverts("OVV1: !factory"): + with reverts("OVLV1: !factory"): market.shutdown({"from": rando}) # emergency withdraw tests def test_emergency_withdraw_transfers_collateral( - mock_market, mock_feed, factory, ov, alice, guardian, rando): + mock_market, mock_feed, factory, ovl, alice, guardian, rando): # input build parameters input_collateral = int(1e18) input_leverage = int(1e18) @@ -49,7 +49,7 @@ def test_emergency_withdraw_transfers_collateral( input_price_limit = 2**256-1 # approve market for spending before build. use max - ov.approve(mock_market, 2**256 - 1, {"from": alice}) + ovl.approve(mock_market, 2**256 - 1, {"from": alice}) # build a position tx = mock_market.build(input_collateral, input_leverage, input_is_long, @@ -77,9 +77,9 @@ def test_emergency_withdraw_transfers_collateral( Decimal(input_collateral) * (Decimal(1e18) - Decimal(fraction)) / Decimal(1e18)) - # cache alice and market balances of ov prior - expect_balance_alice = ov.balanceOf(alice) - expect_balance_market = ov.balanceOf(mock_market) + # cache alice and market balances of ovl prior + expect_balance_alice = ovl.balanceOf(alice) + expect_balance_market = ovl.balanceOf(mock_market) # emergency withdraw collateral tx = mock_market.emergencyWithdraw(input_pos_id, {"from": alice}) @@ -89,8 +89,8 @@ def test_emergency_withdraw_transfers_collateral( expect_balance_alice += expect_collateral_out expect_balance_market -= expect_collateral_out - actual_balance_alice = ov.balanceOf(alice) - actual_balance_market = ov.balanceOf(mock_market) + actual_balance_alice = ovl.balanceOf(alice) + actual_balance_market = ovl.balanceOf(mock_market) # check balances match expectations assert actual_balance_alice == expect_balance_alice @@ -105,7 +105,7 @@ def test_emergency_withdraw_transfers_collateral( def test_emergency_withdraw_updates_position( - mock_market, mock_feed, factory, ov, alice, guardian, rando): + mock_market, mock_feed, factory, ovl, alice, guardian, rando): # input build parameters input_collateral = int(1e18) input_leverage = int(1e18) @@ -113,7 +113,7 @@ def test_emergency_withdraw_updates_position( input_price_limit = 2**256-1 # approve market for spending before build. use max - ov.approve(mock_market, 2**256 - 1, {"from": alice}) + ovl.approve(mock_market, 2**256 - 1, {"from": alice}) # build a position tx = mock_market.build(input_collateral, input_leverage, input_is_long, @@ -153,7 +153,7 @@ def test_emergency_withdraw_updates_position( def test_emergency_withdraw_executes_transfers( - mock_market, mock_feed, factory, ov, alice, guardian, rando): + mock_market, mock_feed, factory, ovl, alice, guardian, rando): # input build parameters input_collateral = int(1e18) input_leverage = int(1e18) @@ -161,7 +161,7 @@ def test_emergency_withdraw_executes_transfers( input_price_limit = 2**256-1 # approve market for spending before build. use max - ov.approve(mock_market, 2**256 - 1, {"from": alice}) + ovl.approve(mock_market, 2**256 - 1, {"from": alice}) # build a position tx = mock_market.build(input_collateral, input_leverage, input_is_long, @@ -200,7 +200,7 @@ def test_emergency_withdraw_executes_transfers( assert tx.events["Transfer"]["value"] == expect_collateral_out -def test_emergency_withdraw_reverts_when_not_shutdown(market, ov, alice): +def test_emergency_withdraw_reverts_when_not_shutdown(market, ovl, alice): # input build parameters input_collateral = int(1e18) input_leverage = int(1e18) @@ -208,7 +208,7 @@ def test_emergency_withdraw_reverts_when_not_shutdown(market, ov, alice): input_price_limit = 2**256-1 # approve market for spending before build. use max - ov.approve(market, 2**256 - 1, {"from": alice}) + ovl.approve(market, 2**256 - 1, {"from": alice}) # build a position tx = market.build(input_collateral, input_leverage, input_is_long, @@ -216,11 +216,11 @@ def test_emergency_withdraw_reverts_when_not_shutdown(market, ov, alice): input_pos_id = tx.return_value # check can't withdraw collateral from built position when not shutdown - with reverts("OVV1: !shutdown"): + with reverts("OVLV1: !shutdown"): market.emergencyWithdraw(input_pos_id, {"from": alice}) -def test_emergency_withdraw_reverts_when_position_not_exists(market, feed, ov, +def test_emergency_withdraw_reverts_when_position_not_exists(market, feed, ovl, factory, alice, guardian): input_pos_id = 100 @@ -230,12 +230,12 @@ def test_emergency_withdraw_reverts_when_position_not_exists(market, feed, ov, factory.shutdown(feed, {"from": guardian}) # check can't withdraw collateral when no position exists - with reverts("OVV1:!position"): + with reverts("OVLV1:!position"): market.emergencyWithdraw(input_pos_id, {"from": alice}) def test_multiple_emergency_withdraw( - mock_market, mock_feed, factory, ov, alice, bob, guardian, rando): + mock_market, mock_feed, factory, ovl, alice, bob, guardian, rando): # loop through 10 times n = 10 total_collateral_long = Decimal(10000) @@ -245,8 +245,8 @@ def test_multiple_emergency_withdraw( leverage_cap = Decimal(mock_market.params(idx_cap_leverage) / 1e18) # approve market for spending then build - ov.approve(mock_market, 2**256-1, {"from": alice}) - ov.approve(mock_market, 2**256-1, {"from": bob}) + ovl.approve(mock_market, 2**256-1, {"from": alice}) + ovl.approve(mock_market, 2**256-1, {"from": bob}) # per trade collateral values collateral_alice = total_collateral_long / Decimal(n) @@ -345,7 +345,7 @@ def test_multiple_emergency_withdraw( # check revert happens on withdrawal and continue loop # if trader has already unwound entire position if expect_fraction_remaining == 0: - with reverts("OVV1:!position"): + with reverts("OVLV1:!position"): mock_market.emergencyWithdraw(id, {"from": trader}) # continue the loop after revert goes through @@ -353,8 +353,8 @@ def test_multiple_emergency_withdraw( # for other case when position still has collateral left ... # cache balances prior to withdraw - expect_balance_trader = ov.balanceOf(trader) - expect_balance_market = ov.balanceOf(mock_market) + expect_balance_trader = ovl.balanceOf(trader) + expect_balance_market = ovl.balanceOf(mock_market) # calculate amount of collateral expect to be withdrawn expect_collateral_out = (expect_notional - expect_debt) * \ @@ -377,8 +377,8 @@ def test_multiple_emergency_withdraw( expect_balance_market -= expect_collateral_out # get balances after withdraw - actual_balance_trader = ov.balanceOf(trader) - actual_balance_market = ov.balanceOf(mock_market) + actual_balance_trader = ovl.balanceOf(trader) + actual_balance_market = ovl.balanceOf(mock_market) # check balances for market and trader match expectations assert actual_balance_trader == expect_balance_trader diff --git a/tests/token/test_conftest.py b/tests/token/test_conftest.py index 0bef3e71..ed388875 100644 --- a/tests/token/test_conftest.py +++ b/tests/token/test_conftest.py @@ -33,5 +33,5 @@ def test_roles(token, gov, minter, burner, governor, admin, market, def test_erc20(token): assert token.decimals() == 18 assert token.name() == "Overlay" - assert token.symbol() == "OV" + assert token.symbol() == "OVL" assert token.totalSupply() == 88888888 * 1e18 From 0710d4291ae72c4726cab9efdfc1c1c379e7d20a Mon Sep 17 00:00:00 2001 From: "Arthur G." Date: Mon, 6 Jan 2025 14:27:41 +0100 Subject: [PATCH 4/4] refactor: misc and missed --- README.md | 16 ++++++++-------- contracts/OverlayV1Market.sol | 4 ++-- contracts/interfaces/IOverlayV1Deployer.sol | 2 +- docs/assets/diagram.svg | 2 +- tests/markets/test_conftest.py | 2 +- tests/markets/test_oi_cap.py | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ade57ed4..4a84166a 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ V1 core relies on three modules: - [Modules](#modules) - [Markets Module](#markets-module) - [Feeds Module](#feeds-module) - - [OV Module](#ov-module) + - [OVL Module](#ovl-module) - [Deployment Process](#deployment-process) ### Markets Module @@ -62,9 +62,9 @@ Traders interact directly with the market contract to take positions on a data s - `liquidate()` - `update()` -Traders transfer OV collateral to the market contract to back a position. This collateral is held in the market contract until the trader unwinds their position when exiting the trade. OV is the only collateral supported for V1. +Traders transfer OVL collateral to the market contract to back a position. This collateral is held in the market contract until the trader unwinds their position when exiting the trade. OVL is the only collateral supported for V1. -The market contract tracks the current open interest for all outstanding positions on a market as well as [information about each position](./contracts/libraries/Position.sol), that is needed in order to calculate the current value of the position in OV terms: +The market contract tracks the current open interest for all outstanding positions on a market as well as [information about each position](./contracts/libraries/Position.sol), that is needed in order to calculate the current value of the position in OVL terms: ``` library Position { @@ -110,7 +110,7 @@ library Oracle { uint256 priceOverMicroWindow; // p(now) averaged over micro uint256 priceOverMacroWindow; // p(now) averaged over macro uint256 priceOneMacroWindowAgo; // p(now - macro) avg over macro - uint256 reserveOverMicroWindow; // r(now) in ov averaged over micro + uint256 reserveOverMicroWindow; // r(now) in ovl averaged over micro bool hasReserve; // whether oracle has manipulable reserve pool } } @@ -121,11 +121,11 @@ from the [`Oracle.sol`](./contracts/libraries/Oracle.sol) library. `Oracle.Data` For each oracle provider supported, there should be a specific implementation of a feed contract that inherits from `OverlayV1Feed.sol` (e.g. [`OverlayV1UniswapV3Feed.sol`](./contracts/feeds/uniswapv3/OverlayV1UniswapV3Feed.sol) for Uniswap V3 pools). -### OV Module +### OVL Module -The OV module consists of an ERC20 token with permissioned mint and burn functions. Upon initialization, markets must be given permission to mint and burn OV to compensate traders for their PnL on positions. +The OVL module consists of an ERC20 token with permissioned mint and burn functions. Upon initialization, markets must be given permission to mint and burn OVL to compensate traders for their PnL on positions. -[`OverlayV1Factory.sol`](./contracts/OverlayV1Factory.sol) grants these mint and burn permissions on a call to `deployMarket()`. Because of this, the factory contract must have admin privileges on the OV token prior to deploying markets. +[`OverlayV1Factory.sol`](./contracts/OverlayV1Factory.sol) grants these mint and burn permissions on a call to `deployMarket()`. Because of this, the factory contract must have admin privileges on the OVL token prior to deploying markets. ## Deployment Process @@ -135,4 +135,4 @@ The process to add a new market is as follows: 2. Deploy an [`OverlayV1Market.sol`](./contracts/OverlayV1Market.sol) contract referencing the previously deployed feed from 1 as the `feed` constructor parameter. This is accomplished by governance calling `deployMarket()` on the market factory contract [`OverlayV1Factory.sol`](./contracts/OverlayV1Factory.sol). Traders interact directly with the newly deployed market contract to take positions out. The market contract stores the active positions and open interest for all outstanding trades on the data stream. -3. The market factory contract grants the newly deployed market contract mint and burn privileges on the sole instance of the [`OverlayV1Token.sol`](./contracts/OverlayV1Token.sol) token. Governance should grant the market factory contract admin privileges on the OV token prior to any markets being deployed, otherwise `deployMarket()` will revert. +3. The market factory contract grants the newly deployed market contract mint and burn privileges on the sole instance of the [`OverlayV1Token.sol`](./contracts/OverlayV1Token.sol) token. Governance should grant the market factory contract admin privileges on the OVL token prior to any markets being deployed, otherwise `deployMarket()` will revert. diff --git a/contracts/OverlayV1Market.sol b/contracts/OverlayV1Market.sol index f81e0d2c..4535ea98 100644 --- a/contracts/OverlayV1Market.sol +++ b/contracts/OverlayV1Market.sol @@ -673,14 +673,14 @@ contract OverlayV1Market is IOverlayV1Market, Pausable { } /// @dev bound on notional cap to mitigate front-running attack - /// @dev bound = lmbda * reserveInOv + /// @dev bound = lmbda * reserveInOvl 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 * reserveInOv * 2 * delta + /// @dev bound = macroWindowInBlocks * reserveInOvl * 2 * delta function backRunBound(Oracle.Data memory data) public view returns (uint256) { uint256 averageBlockTime = params.get(Risk.Parameters.AverageBlockTime); uint256 window = (data.macroWindow * ONE * TO_MS) / averageBlockTime; diff --git a/contracts/interfaces/IOverlayV1Deployer.sol b/contracts/interfaces/IOverlayV1Deployer.sol index 3b2b733d..02d9bff3 100644 --- a/contracts/interfaces/IOverlayV1Deployer.sol +++ b/contracts/interfaces/IOverlayV1Deployer.sol @@ -8,5 +8,5 @@ interface IOverlayV1Deployer { function deploy(address feed) external returns (address); - function parameters() external view returns (address ov_, address feed_, address factory_); + function parameters() external view returns (address ovl_, address feed_, address factory_); } diff --git a/docs/assets/diagram.svg b/docs/assets/diagram.svg index 5ec9713f..712c418b 100644 --- a/docs/assets/diagram.svg +++ b/docs/assets/diagram.svg @@ -1,3 +1,3 @@ -
OverlayV1Market

Info[] positions
OverlayV1Market...
OverlayV1UniswapV3Feed

function view latest()
OverlayV1UniswapV3Feed...
_fetch()
_fetch()
latest()
latest()
OV/ETH Market
OV/ETH Market
UniswapV3Pool
OV/WETH
UniswapV3Pool...
Trader
Trader
returns rawData
returns ra...
returns Oracle.Data
returns Oracle.Data
OverlayV1Token
OverlayV1Token
mint() or burn()
mint() or burn()
2. unwind()
2. unwind()
1. build()
1. build()
OverlayV1Market

Info[] positions
OverlayV1Market...
OverlayV1ChainlinkFeed

function view latest()
OverlayV1ChainlinkFeed...
_fetch()
_fetch()
latest()
latest()
ETH/USD Market
ETH/USD Market
Chainlink
ETH/USD
Chainlink...
returns rawData
returns ra...
returns Oracle.Data
returns Oracle.Data
OverlayV1Market

Info[] positions
OverlayV1Market...
OverlayV1BalancerV2Feed

function view latest()
OverlayV1BalancerV2Feed...
_fetch()
_fetch()
latest()
latest()
PUNK/ETH Market
PUNK/ETH Market
BalancerV2Pool
PUNK/WETH
BalancerV2Pool...
returns rawData
returns ra...
returns Oracle.Data
returns Oracle.Data
OverlayV1Factory

mapping isMarket
OverlayV1Factory...
Governor
Gover...
CREATE
CREATE
OverlayV1UniswapV3Factory

mapping isFeed
OverlayV1UniswapV3Factory...
CREATE
CREATE
Rando
Rando
deployMarket()
deployMarket()
deployFeed()
deployFeed()
Text is not SVG - cannot display
\ No newline at end of file +
OverlayV1Market

Info[] positions
OverlayV1Market...
OverlayV1UniswapV3Feed

function view latest()
OverlayV1UniswapV3Feed...
_fetch()
_fetch()
latest()
latest()
OVL/ETH Market
OVL/ETH Market
UniswapV3Pool
OVL/WETH
UniswapV3Pool...
Trader
Trader
returns rawData
returns ra...
returns Oracle.Data
returns Oracle.Data
OverlayV1Token
OverlayV1Token
mint() or burn()
mint() or burn()
2. unwind()
2. unwind()
1. build()
1. build()
OverlayV1Market

Info[] positions
OverlayV1Market...
OverlayV1ChainlinkFeed

function view latest()
OverlayV1ChainlinkFeed...
_fetch()
_fetch()
latest()
latest()
ETH/USD Market
ETH/USD Market
Chainlink
ETH/USD
Chainlink...
returns rawData
returns ra...
returns Oracle.Data
returns Oracle.Data
OverlayV1Market

Info[] positions
OverlayV1Market...
OverlayV1BalancerV2Feed

function view latest()
OverlayV1BalancerV2Feed...
_fetch()
_fetch()
latest()
latest()
PUNK/ETH Market
PUNK/ETH Market
BalancerV2Pool
PUNK/WETH
BalancerV2Pool...
returns rawData
returns ra...
returns Oracle.Data
returns Oracle.Data
OverlayV1Factory

mapping isMarket
OverlayV1Factory...
Governor
Gover...
CREATE
CREATE
OverlayV1UniswapV3Factory

mapping isFeed
OverlayV1UniswapV3Factory...
CREATE
CREATE
Rando
Rando
deployMarket()
deployMarket()
deployFeed()
deployFeed()
Text is not SVG - cannot display
\ No newline at end of file diff --git a/tests/markets/test_conftest.py b/tests/markets/test_conftest.py index 404606a6..6199c8fc 100644 --- a/tests/markets/test_conftest.py +++ b/tests/markets/test_conftest.py @@ -1,7 +1,7 @@ from .utils import RiskParameter -def test_ov_fixture(ovl): +def test_ovl_fixture(ovl): assert ovl.decimals() == 18 assert ovl.name() == "Overlay" assert ovl.symbol() == "OVL" diff --git a/tests/markets/test_oi_cap.py b/tests/markets/test_oi_cap.py index f8577b84..087201dc 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 * reserveInOv * 2 * delta + # check back run bound is macroWindowInBlocks * reserveInOvl * 2 * delta # when has reserve window = Decimal(macro_window) / Decimal(average_block_time) expect = int(Decimal(2) * delta * Decimal(reserve_micro) * window)