Conversation
* SIP-202 Target Staking Ratio
…etix into futures-implementation
837ca7a to
82e22cd
Compare
82e22cd to
7caa059
Compare
ae33449 to
527ef56
Compare
f6275e9 to
c7157b1
Compare
jacko125
approved these changes
Mar 9, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the futures contracts.
There are several major new smart contracts to consider:
FuturesMarket.sol: the actual futures market itself. One of these will exist per asset, and each operates behind a proxy so that they are upgradeable.FuturesMarketSettings.sol: an interface to the sameFlexibleStoragecontract asSystemSettings. This provides setters and getters for all the specific settings for each market, such as fee rates and capital controls, along with for cross-market settings such as the liquidation fee and minimum initial margin. This is accompanied byMixinFuturesMarketSettings.sol, which allows futures markets themselves to access the flexible storage.FuturesMarketManager.sol: This is responsible for managing which markets exist, as well as issuing and burning sUSD on behalf of the markets (including paying fees to the pool). It is also responsible for aggregating the debt of all futures markets, and reporting this aggregate to the debt cache.FuturesMarketData.sol: A data contract which accumulates all relevant data from individual markets or futures positions, so that they can be reported to the front-end in a single transaction.The futures markets make extensive use of signed arithmetic, which represent long and short positions with positive and negative values respectively. To facilitate this, the
SafeMathandSafeDecimalMathlibraries have been extended to support signed values, in the form ofSignedSafeMath.solandSignedSafeDecimalMath.sol. Although OpenZeppelin provides a signed safe math library, it does so only in versions later than that which Synthetix actually imports.A user wishing to interact with a futures market follows these steps:
transferMargin. This function is used for both deposits and withdrawals, depending on the sign of the argument.modifyPosition, providing the desired change in their position size. The sign of the argument determines whether they are going more long or more short. Positive inputs buy long or sell short, while negative inputs buy short or sell long. To close an existing position, a user must bring their position size to zero by providing-position.sizeas the argument, or using theclosePositionfunction.Orders are immediately confirmed at the spot price. A position is subject to profit and funding as per the calculations in SIP-80. Liquidation are performed by keepers, though they could potentially be handled by any user. If an account
ahas exhausted its margin, the position can be liquidated, and the predicatecanLiquidate(a)returns true. When a keeper detects this, it executesliquidatePosition(a).