Skip to content

Commit

Permalink
Add interfaces (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeyrf authored Apr 20, 2022
1 parent 7daa53d commit 3b1d419
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 7 deletions.
3 changes: 3 additions & 0 deletions contracts/OverlayV1State.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;

import "./interfaces/IOverlayV1State.sol";

import "./state/OverlayV1BaseState.sol";
import "./state/OverlayV1OIState.sol";
import "./state/OverlayV1PositionState.sol";
Expand All @@ -9,6 +11,7 @@ import "./state/OverlayV1PriceState.sol";
/// @title A market state contract to view the current state of
/// @title an Overlay market
contract OverlayV1State is
IOverlayV1State,
OverlayV1BaseState,
OverlayV1PriceState,
OverlayV1OIState,
Expand Down
14 changes: 14 additions & 0 deletions contracts/interfaces/IOverlayV1State.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;

import "./state/IOverlayV1BaseState.sol";
import "./state/IOverlayV1PriceState.sol";
import "./state/IOverlayV1OIState.sol";
import "./state/IOverlayV1PositionState.sol";

interface IOverlayV1State is
IOverlayV1BaseState,
IOverlayV1PriceState,
IOverlayV1OIState,
IOverlayV1PositionState
{}
17 changes: 17 additions & 0 deletions contracts/interfaces/state/IOverlayV1BaseState.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;

import "@overlay/v1-core/contracts/interfaces/IOverlayV1Factory.sol";
import "@overlay/v1-core/contracts/interfaces/IOverlayV1Market.sol";
import "@overlay/v1-core/contracts/libraries/Oracle.sol";

interface IOverlayV1BaseState {
// immutables
function factory() external view returns (IOverlayV1Factory);

// market associated with given feed
function market(address feed) external view returns (IOverlayV1Market market_);

// latest oracle data associated with given feed
function data(address feed) external view returns (Oracle.Data memory data_);
}
31 changes: 31 additions & 0 deletions contracts/interfaces/state/IOverlayV1OIState.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;

import "./IOverlayV1BaseState.sol";
import "./IOverlayV1PriceState.sol";

interface IOverlayV1OIState is IOverlayV1BaseState, IOverlayV1PriceState {
// aggregate open interest values on market associated with feed
function ois(address feed) external view returns (uint256 oiLong_, uint256 oiShort_);

// cap on aggregate open interest on market associated with feed
function capOi(address feed) external view returns (uint256 capOi_);

// fraction of cap on aggregate open interest given oi amount
function fractionOfCapOi(address feed, uint256 oi)
external
view
returns (uint256 fractionOfCapOi_);

// funding rate on market associated with feed
function fundingRate(address feed) external view returns (int256 fundingRate_);

// circuit breaker level on market associated with feed
function circuitBreakerLevel(address feed)
external
view
returns (uint256 circuitBreakerLevel_);

// rolling minted amount on market associated with feed
function minted(address feed) external view returns (int256 minted_);
}
103 changes: 103 additions & 0 deletions contracts/interfaces/state/IOverlayV1PositionState.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;

import "@overlay/v1-core/contracts/libraries/Position.sol";

import "./IOverlayV1BaseState.sol";
import "./IOverlayV1OIState.sol";
import "./IOverlayV1PriceState.sol";

interface IOverlayV1PositionState is IOverlayV1BaseState, IOverlayV1PriceState, IOverlayV1OIState {
// position on the market associated with feed
function position(
address feed,
address owner,
uint256 id
) external view returns (Position.Info memory position_);

// debt of position on the market associated with feed
function debt(
address feed,
address owner,
uint256 id
) external view returns (uint256 debt_);

// cost basis of position on the market associated with feed
function cost(
address feed,
address owner,
uint256 id
) external view returns (uint256 cost_);

// open interest of position on the market associated with feed
function oi(
address feed,
address owner,
uint256 id
) external view returns (uint256 oi_);

// collateral backing position on the market associated with feed
function collateral(
address feed,
address owner,
uint256 id
) external view returns (uint256 collateral_);

// value of position on the market associated with feed
function value(
address feed,
address owner,
uint256 id
) external view returns (uint256 value_);

// notional of position on the market associated with feed
function notional(
address feed,
address owner,
uint256 id
) external view returns (uint256 notional_);

// trading fee charged to unwind position on the market associated with feed
function tradingFee(
address feed,
address owner,
uint256 id
) external view returns (uint256 tradingFee_);

// whether position is liquidatable on the market associated with feed
function liquidatable(
address feed,
address owner,
uint256 id
) external view returns (bool liquidatable_);

// liquidation fee rewarded to liquidator for position on market associated
// with feed
function liquidationFee(
address feed,
address owner,
uint256 id
) external view returns (uint256 liquidationFee_);

// maintenance margin requirement for position on market associated with feed
function maintenanceMargin(
address feed,
address owner,
uint256 id
) external view returns (uint256 maintenanceMargin_);

// remaining margin before liquidation for position on market associated
// with feed
function marginExcessBeforeLiquidation(
address feed,
address owner,
uint256 id
) external view returns (int256 excess_);

// liquidation price for position on market associated with feed
function liquidationPrice(
address feed,
address owner,
uint256 id
) external view returns (uint256 liquidationPrice_);
}
42 changes: 42 additions & 0 deletions contracts/interfaces/state/IOverlayV1PriceState.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;

import "./IOverlayV1BaseState.sol";

interface IOverlayV1PriceState is IOverlayV1BaseState {
// bid on the market associated with the feed given new volume from fractionOfCapOi
function bid(address feed, uint256 fractionOfCapOi) external view returns (uint256 bid_);

// ask on the market associated with the feed given new volume from fractionOfCapOi
function ask(address feed, uint256 fractionOfCapOi) external view returns (uint256 ask_);

// mid on the market associated with the feed
function mid(address feed) external view returns (uint256 mid_);

// volume on the bid of the market associated with the feed given
// new volume from fractionOfCapOi
function volumeBid(address feed, uint256 fractionOfCapOi)
external
view
returns (uint256 volumeBid_);

// volume on the ask of the market associated with the feed given
// new volume from fractionOfCapOi
function volumeAsk(address feed, uint256 fractionOfCapOi)
external
view
returns (uint256 volumeAsk_);

// bid, ask, mid prices of the market associated with the feed
function prices(address feed)
external
view
returns (
uint256 bid_,
uint256 ask_,
uint256 mid_
);

// bid, ask volumes of the market associated with the feed
function volumes(address feed) external view returns (uint256 volumeBid_, uint256 volumeAsk_);
}
6 changes: 3 additions & 3 deletions contracts/state/OverlayV1BaseState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import "@overlay/v1-core/contracts/interfaces/IOverlayV1Factory.sol";
import "@overlay/v1-core/contracts/interfaces/IOverlayV1Market.sol";
import "@overlay/v1-core/contracts/interfaces/feeds/IOverlayV1Feed.sol";

import "@overlay/v1-core/contracts/libraries/FixedPoint.sol";
import "@overlay/v1-core/contracts/libraries/Oracle.sol";
import "@overlay/v1-core/contracts/libraries/Position.sol";

abstract contract OverlayV1BaseState {
import "../interfaces/state/IOverlayV1BaseState.sol";

abstract contract OverlayV1BaseState is IOverlayV1BaseState {
// immutables
IOverlayV1Factory public immutable factory;

Expand Down
4 changes: 3 additions & 1 deletion contracts/state/OverlayV1OIState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import "@overlay/v1-core/contracts/libraries/FixedPoint.sol";
import "@overlay/v1-core/contracts/libraries/Oracle.sol";
import "@overlay/v1-core/contracts/libraries/Roller.sol";

import "../interfaces/state/IOverlayV1OIState.sol";

import "./OverlayV1BaseState.sol";
import "./OverlayV1PriceState.sol";

abstract contract OverlayV1OIState is OverlayV1BaseState, OverlayV1PriceState {
abstract contract OverlayV1OIState is IOverlayV1OIState, OverlayV1BaseState, OverlayV1PriceState {
using FixedPoint for uint256;
using Roller for Roller.Snapshot;

Expand Down
5 changes: 4 additions & 1 deletion contracts/state/OverlayV1PositionState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ pragma solidity 0.8.10;
import "@overlay/v1-core/contracts/interfaces/IOverlayV1Market.sol";
import "@overlay/v1-core/contracts/libraries/FixedPoint.sol";
import "@overlay/v1-core/contracts/libraries/Oracle.sol";
import "@overlay/v1-core/contracts/libraries/Roller.sol";
import "@overlay/v1-core/contracts/libraries/Position.sol";

import "../interfaces/state/IOverlayV1PositionState.sol";

import "./OverlayV1BaseState.sol";
import "./OverlayV1OIState.sol";
import "./OverlayV1PriceState.sol";

abstract contract OverlayV1PositionState is
IOverlayV1PositionState,
OverlayV1BaseState,
OverlayV1PriceState,
OverlayV1OIState
Expand Down
6 changes: 4 additions & 2 deletions contracts/state/OverlayV1PriceState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ pragma solidity 0.8.10;
import "@openzeppelin/contracts/utils/math/Math.sol";

import "@overlay/v1-core/contracts/interfaces/IOverlayV1Market.sol";
import "@overlay/v1-core/contracts/libraries/FixedPoint.sol";
import "@overlay/v1-core/contracts/libraries/Oracle.sol";
import "@overlay/v1-core/contracts/libraries/Roller.sol";

import "../interfaces/state/IOverlayV1PriceState.sol";

import "./OverlayV1BaseState.sol";

abstract contract OverlayV1PriceState is OverlayV1BaseState {
abstract contract OverlayV1PriceState is IOverlayV1PriceState, OverlayV1BaseState {
using Roller for Roller.Snapshot;

function _bid(
Expand Down

0 comments on commit 3b1d419

Please sign in to comment.