diff --git a/contracts/OverlayV1State.sol b/contracts/OverlayV1State.sol index 5d3f894..9708247 100644 --- a/contracts/OverlayV1State.sol +++ b/contracts/OverlayV1State.sol @@ -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"; @@ -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, diff --git a/contracts/interfaces/IOverlayV1State.sol b/contracts/interfaces/IOverlayV1State.sol new file mode 100644 index 0000000..403a0e4 --- /dev/null +++ b/contracts/interfaces/IOverlayV1State.sol @@ -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 +{} diff --git a/contracts/interfaces/state/IOverlayV1BaseState.sol b/contracts/interfaces/state/IOverlayV1BaseState.sol new file mode 100644 index 0000000..4150d62 --- /dev/null +++ b/contracts/interfaces/state/IOverlayV1BaseState.sol @@ -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_); +} diff --git a/contracts/interfaces/state/IOverlayV1OIState.sol b/contracts/interfaces/state/IOverlayV1OIState.sol new file mode 100644 index 0000000..6f1b2ef --- /dev/null +++ b/contracts/interfaces/state/IOverlayV1OIState.sol @@ -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_); +} diff --git a/contracts/interfaces/state/IOverlayV1PositionState.sol b/contracts/interfaces/state/IOverlayV1PositionState.sol new file mode 100644 index 0000000..cd3a825 --- /dev/null +++ b/contracts/interfaces/state/IOverlayV1PositionState.sol @@ -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_); +} diff --git a/contracts/interfaces/state/IOverlayV1PriceState.sol b/contracts/interfaces/state/IOverlayV1PriceState.sol new file mode 100644 index 0000000..80c6584 --- /dev/null +++ b/contracts/interfaces/state/IOverlayV1PriceState.sol @@ -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_); +} diff --git a/contracts/state/OverlayV1BaseState.sol b/contracts/state/OverlayV1BaseState.sol index 99e2b88..50d3b29 100644 --- a/contracts/state/OverlayV1BaseState.sol +++ b/contracts/state/OverlayV1BaseState.sol @@ -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; diff --git a/contracts/state/OverlayV1OIState.sol b/contracts/state/OverlayV1OIState.sol index fd69cd1..6b4cbd7 100644 --- a/contracts/state/OverlayV1OIState.sol +++ b/contracts/state/OverlayV1OIState.sol @@ -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; diff --git a/contracts/state/OverlayV1PositionState.sol b/contracts/state/OverlayV1PositionState.sol index d170eac..bc8eedd 100644 --- a/contracts/state/OverlayV1PositionState.sol +++ b/contracts/state/OverlayV1PositionState.sol @@ -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 diff --git a/contracts/state/OverlayV1PriceState.sol b/contracts/state/OverlayV1PriceState.sol index 540cd1c..792d618 100644 --- a/contracts/state/OverlayV1PriceState.sol +++ b/contracts/state/OverlayV1PriceState.sol @@ -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(