Settlement is the process of moving collateral between accounts when a position is closed, the market expires or if there is an interim settlement action defined in the product.
Further to this, the protocol may elect to settle a market at a point in time by carrying out mark to market settlement. This is helpful for maintaining lower margins requirements.
Vega operates as a decentralised "Central Counterparty" (CCP) and facilitates the settlement of markets at various stages of its lifecycle.
Settlement on markets occurs when:
- A position is fully or partially closed - An open position is closed when the owner of the open position enters into a counter trade (including if that trade is created as part of a forced risk management closeout). Settlement occurs for the closed volume / contracts.
- An instrument expires - all open positions in the market are settled. After settlement at expiry, all positions are closed and collateral is released.
- Interim cash flows are generated - not relevant for first instruments launched on Vega. Will be potentially relevant for perpetual futures with periodic settlement.
- Mark to market event - when the protocol runs mark to market settlement.
Settlement calculation logic is defined on the product (for example, see the spec for cash settled direct futures).
Settlement adheres to double entry accounting.
Settlement instructions contain information regarding the accounts from which collateral should be sourced and deducted (in order of preference) and accounts to which the collateral should be deposited.
Vega executes settlement with a two step process:
Vega collects from the margin accounts of those who, according to the settlement formula, are liable to pay collateral. The collection instruction should first collect as much as possible from the trader's margin account for the market, then the trader's general account, then the market's insurance pool. If the full required amount cannot be collected from these accounts then as much as possible is collected.
This will result in ledger entries being formulated ( see collateral ) which adhere to double entry accounting and record the actual transfers that occurred on the ledger. The destination account is the market settlement account for the market. This may be a persistent account or can be created for each settlement process run-through and destroyed after the process completes, but either way, the market settlement account must have a zero balance before the settlement process begins and after it completes.
If all requested amounts are successfully transferred to the market settlement account, then the amount collected will match the amount to be distributed and the settlement function will formulate instructions to distribute to the margin accounts of those whose moves have been positive according to the amount they are owed. These transfers will debit from the market's market settlement account and credited to the margin accounts of traders who have are due to receive a "cash / asset flow" as a result of the settlement.
If some of the collection transfers are not able to supply the full amount to the market settlement account due to some traders having insufficient collateral in their margin account and general account to handle the price / position (mark to market) move, and if the market's insurance pool can't cover the shortfall for some of these, then not enough funds will have been collected to distribute the full amount of the mark to market gains made by traders on the other side. Therefore, settlement needs to decide how to fairly distribute the funds that have been collected. This is called loss socialisation.
In future, a more sophisticated algorithm may be used for this (perhaps taking into account a trader's overall profit on their positions, for example) but initially this will be implemented by reducing the amount to distribute to each trader with an MTM gain pro-rata by relative position size:
distribute_amount[trader] = mtm_gain[trader] * ( actual_collected_amount / target_collect_amount )
When a trader is distressed their position is closed out by the network placing an order to bring their position back to 0. This network order will match against normal orders in the order book and will be part of a mark-to-market settlement action. As the network user is a virtual user it does not have collateral accounts from which to provide or collect wins and loses. The market insurance account is used in place of these. If a network order is settled as a win, the collateral will be transferred from the matched trader directly into the insurance account for the market. If the network order is a loss, the market's insurance pool will be used to pay the matched traders. Loss socialisation is used if the market's insurance pool does not have enough collateral to cover the loss situation.
Some markets on Vega will be trading instruments that "expire" (i.e. they are instruments based on non-perpetual products). Settlement at instrument expiry is the final settlement of such markets.
The expiry of a market happens when an oracle publishes data that meets the filter requirements as defined on the Product (see Market Framework).
The market lifecycle spec provides detail on all the potential paths of a market nearing expiry and should be consulted as the source of truth.
The typical "Happy Path" case (0002-STTL-001,)
- With a market configured to take an oracle termination time and settlement price and put into continuous trading mode. When there are traders with open positions on the market and the termination trigger from oracle is sent so the market is terminated. Send market settlement price and assert that it is no longer possible to trade on this market.
Example 1 - A typical path of a cash settled futures market nearing expiry when market is trading in continuous session (0002-STTL-011)
- Market has a status of ACTIVE and is trading in default trading mode
- The product's trading terminated trigger is hit
- The market's status is set to TRADING TERMINATED and accepts no trading but retains the positions and margin balances that were in place after processing the trading terminated trigger. No margin recalculations or mark-to-market settlement occurs.
- An oracle event occurs that is eligible to settle the market, as defined on the Product (see also cash settled futures spec)
- Final cashflow is calculated according to the valuation formula defined on the product (see cash settled direct futures product)
- Accounts are settled as per collection and distribution methods described above.
- Any remaining balances in parties' margin and LP bond accounts are moved to their general account.
- The margin accounts and LP bond accounts for these markets are no longer required.
- Positions can be left as open, or set to zero (this isn't important for the protocol but should be made clear on the API either way).
- The market's insurance pool balance is transferred into the global insurance pool using the same settlement asset.
- Market status is now set to SETTLED.
- Now the market can be deleted.
- This mechanism does not incur fees to traders that have open positions that are settled at expiry. (0002-STTL-003)
Example 2 - A less typical path of such a futures market nearing expiry when market is suspended (0002-STTL-012)
- Market has a status of SUSPENDED and in a protective auction
- The product's trading terminated trigger is hit
- The market's status is set to TRADING TERMINATED and accepts no trading but retains the positions and margin balances that were in place after processing the trading terminated trigger. No margin recalculations or mark-to-market settlement occurs. No uncrossing of the auction.
- An oracle event occurs that is eligible to settle the market, as defined on the Product (see also cash settled futures spec)
- Final cashflow is calculated according to the valuation formula defined on the product (see cash settled direct futures product)
- Accounts are settled as per collection and distribution methods described above.
- Any remaining balances in parties' margin and LP bond accounts are moved to their general account.
- The margin accounts and LP bond accounts for these markets are no longer required.
- Positions can be left as open, or set to zero (this isn't important for the protocol but should be made clear on the API either way).
- The market's insurance pool balance is transferred into the global insurance pool using the same settlement asset.
- Market status is now set to SETTLED.
- Now the market can be deleted.
- This mechanism does not incur fees to traders that have open positions that are settled at expiry. (0002-STTL-005)
- For settlement at expiry scenarios, transfers for collateral should be attempted by accessing the trader's margin account first and foremost. (0002-STTL-006)
- If margin account of trader is insufficient to cover collateral transfers, then trade's general account is accessed next. (0002-STTL-007)
- If margin and general account of trader are insufficient to cover collateral transfers, then collateral is attempted to be taken from market's insurance pool. (0002-STTL-008)
- If the full required amount for collateral cannot be collected from individual or combination of these accounts, then as much as possible in the above sequence of accounts is collected and loss socialisation occurs. (0002-STTL-009)
Example 3 - Settlement data to cash settled future is submitted before trading is terminated (0002-STTL-013)
- A cash settled futures market has a status of ACTIVE and is trading in default trading mode (continuous trading)
- An oracle event occurs that is eligible to settle the market, as defined on the Product (see also cash settled futures spec). In other words the settlement price is submitted to the market before trading is terminated. This oracle input retained and market is in the default trading mode (continuous trading).
- At least one party places an order that triggers a trade (just to prove that we can).
- An oracle event occurs again that is eligible to settle the market, as defined on the Product (see also cash settled futures spec). In other words the settlement price is submitted to the market before trading is terminated. This oracle input retained and market is in the default trading mode (continuous trading).
- At least one party places an order that triggers a trade (just to prove that we can again).
- The product's trading terminated trigger is hit The market's status is set to TRADING TERMINATED and accepts no trading but retains the positions and margin balances that were in place after processing the trading terminated trigger. No margin recalculations or mark-to-market settlement occurs. Final cashflow is calculated according to the valuation formula defined on the product (see cash settled direct futures product) using the most recent retained settlement price input. All of that happens while processing the trading terminated transaction.
- Accounts are settled as per collection and distribution methods described above.
- Any remaining balances in parties' margin and LP bond accounts are moved to their general account.
- The margin accounts and LP bond accounts for these markets are no longer required.
- Positions can be left as open, or set to zero (this isn't important for the protocol but should be made clear on the API either way).
- The market's insurance pool balance is transferred into the global insurance pool using the same settlement asset.
- Market status is now set to SETTLED.
- Now the market can be deleted.