ERC-6123 Smart derivatives contract (Smart Derivative Contract)

Draft · Vaults & DeFi · created 2022-12-13

A standard that automates the entire process of executing, settling, and terminating financial contracts such as OTC derivatives or bonds through smart contracts. Settling according to predetermined rules effectively eliminates counterparty risk.

Why it is needed

An over-the-counter (OTC) financial contract is a bilateral agreement between two parties to exchange cash flows over a long period. As market conditions change, the value of the contract also changes, which creates counterparty credit risk: if one party defaults, the other party does not receive the payments it is owed. In addition, post-trade processing such as confirmation, valuation, settlement, and termination after execution is complex and has required reliance on central intermediaries. The way settlement amounts are calculated also differs between parties, leaving room for disputes. This standard predefines all processing states and removes ambiguity in settlement amounts through an agreed valuation oracle and valuation model, allowing two parties to process a financial contract in a fully decentralized way without a third-party intermediary.

What to implement

In depth

A structure split into four interfaces

The specification divides functionality into four interfaces. ISDCTrade contains the functions and events related to trade inception, confirmation, and termination; ISDCSettlement contains the functions and events related to the settlement lifecycle; IAsyncTransferCallback contains the afterTransfer callback for settlements that use an external payment system; and IAsyncTransfer contains the functions and events related to asynchronous transfers (e.g., an external payment system). The ISDC interface combines ISDCTrade, ISDCSettlement, and IAsyncTransferCallback.

The three stages of trade inception and the sign convention

inceptTrade can only be called by a registered party, and the position (negative for sell, positive for buy) and payment amount (negative or positive) are interpreted from the initiator's perspective. The function returns the generated unique tradeId and also emits it as an event. In confirmTrade, the position and payment amount submitted by the counterparty are interpreted from the confirmer's perspective, so they must have the opposite sign from inceptTrade, and the submitted data is checked against the data stored by inceptTrade. If the trade is not confirmed in time, the initiator can cancel it via cancelTrade.

The settlement lifecycle and the oracle callback pattern

initiateSettlement is the function by which a party or a delegated agent opens the settlement phase. Valuation can be performed on-chain or by an external oracle using market data, and the result is delivered via the performSettlement callback and stored. The delivered settlementData is sent back out as lastSettlementData in the next SettlementRequested event, so information needed for the next settlement decision, such as an updated margin buffer value, can be passed to a stateless external oracle. afterSettlement is the function that validates and prepares the next settlement; it is called automatically at the end of performSettlement or can be called externally, for example by a time oracle, and it can perform checks such as pre-funding verification and can trigger termination if the settlement fails.

Asynchronous transfers and afterTransfer

performSettlement can transfer the settlement amount synchronously, or it can transfer it to an external payment system using IAsyncTransfer and complete it with the afterTransfer callback. In afterTransfer, the settlement token or an eligible address delivers the transfer's success status, a transaction ID, and transaction data; depending on the outcome, either a SettlementTransferred or SettlementFailed event is emitted, leading to trade termination or the start of the next settlement phase.

Mutual termination procedure

Via requestTradeTermination, an eligible party requests mutual termination by presenting the tradeId, the termination payment it intends to make (terminationPayment), and the termination terms (terminationTerms, e.g., XML). The counterparty confirms this with the same values via confirmTradeTermination. If not confirmed in time, the requester can withdraw it via cancelTradeTermination. At each stage, a TradeTerminationRequest, TradeTerminationConfirmed, or TradeTerminationCanceled event is emitted, and when the trade is actually terminated, a TradeTerminated event is emitted along with the cause.

Four forms of use

A settle-to-market OTC derivative settles net present value periodically, for example daily, resetting the contract's value to zero. Settlement is guaranteed within the margin buffer locked at the start of the cycle, and if a rule is violated, the violator pays a termination fee and the contract is automatically terminated. The collateralized variant manages collateral tokens and cash tokens separately, eliminating the risk of insufficient collateral, so no separate initial margin is needed. The default-capable variant settles cash flows according to the contract specification without a collateral procedure, and if settlement fails it can end in a 'Failure to Pay' state. Smart bonds use the same set of functions for the issuer's allocation, redemption, and coupon payments as well as secondary trading between holders.

Reference implementation and state machine

An abstract contract for a single trade, SDCSingleTrade.sol, and a full reference implementation for OTC derivatives, SDCPledgedBalance.sol, are provided based on ERC-20 tokens. The reference implementation uses a state machine pattern, in which the state also acts as a guard, via modifiers, restricting which functions can be called at each point in time. The interface also allows extensions that bundle multiple trades into netted settlement. Proofs of concept were carried out in 2021 and 2022 with two legally binding digital interest rate swaps.

A proposal in Draft status

This standard is still in Draft status. Since the specification may change in the future, check the latest original text when implementing it.

Original ERC · ← ERCs