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
function inceptTrade(address withParty, string memory tradeData, int256 position, int256 paymentAmount, string memory initialSettlementData) external returns (string memory);: Initiates a trade by presenting the counterparty's address, trade data, position, payment amount, and initial settlement data. Returns the generated unique tradeId.function confirmTrade(address withParty, string memory tradeData, int256 position, int256 paymentAmount, string memory initialSettlementData) external;: The counterparty confirms the trade by submitting its own trade specification data. It is checked against the data stored by inceptTrade.function cancelTrade(address withParty, string memory tradeData, int256 position, int256 paymentAmount, string memory initialSettlementData) external;: The party that called inceptTrade cancels the trade. Used, for example, when the trade is not confirmed in time.function requestTradeTermination(string memory tradeId, int256 terminationPayment, string memory terminationTerms) external;: Requests mutual termination of the trade for the given tradeId, presenting the termination payment to be made and the termination terms.function confirmTradeTermination(string memory tradeId, int256 terminationPayment, string memory terminationTerms) external;: Confirms a previously requested mutual trade termination, including the termination payment amount and termination terms.function cancelTradeTermination(string memory tradeId, int256 terminationPayment, string memory terminationTerms) external;: The party that requested termination withdraws the request. Used, for example, when it is not confirmed in time.function initiateSettlement() external;: An eligible participant, such as a party or a delegated agent, initiates the settlement phase.function performSettlement(int256 settlementAmount, string memory settlementData) external;: A callback through which an external oracle delivers the settlement amount and settlement data. It is checked against the contract terms and proceeds to either a regular settlement or trade termination.function afterSettlement() external;: Validates and prepares for the next settlement and moves to that phase. It can perform optional checks such as pre-funding verification.function afterTransfer(bool success, uint256 transactionID, string memory transactionData) external;: A callback through which the settlement token or an eligible address reports the result of the settlement amount transfer, completing the settlement transfer.event TradeIncepted(address initiator, string tradeId, string tradeData);: Emitted when a trade is initiated via inceptTrade.event TradeConfirmed(address confirmer, string tradeId);: Emitted when a trade is confirmed via confirmTrade.event TradeCanceled(address initiator, string tradeId);: Emitted when a trade is canceled via cancelTrade.event TradeActivated(string tradeId);: Emitted when a trade becomes active.event TradeTerminationRequest(address initiator, string tradeId, int256 terminationPayment, string terminationTerms);: Emitted when one party initiates a termination request.event TradeTerminationConfirmed(address confirmer, string tradeId, int256 terminationPayment, string terminationTerms);: Emitted when the counterparty confirms the termination request.event TradeTerminationCanceled(address initiator, string tradeId, string terminationTerms);: Emitted when the requesting party withdraws the termination request.event TradeTerminated(string cause);: Emitted, along with the cause, when the trade is terminated.event SettlementRequested(address initiator, string tradeData, string lastSettlementData);: Emitted when settlement is requested via initiateSettlement. It passes the data delivered in the previous settlement as lastSettlementData.event SettlementDetermined(address initiator, int256 settlementAmount, string settlementData);: Emitted when the settlement phase begins via performSettlement.event SettlementTransferred(string transactionData);: Emitted when settlement succeeds.event SettlementFailed(string transactionData);: Emitted when settlement fails.
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.