diff --git a/ERCS/erc-6123.md b/ERCS/erc-6123.md index e58ec6f2e1..eeedbc2bb2 100644 --- a/ERCS/erc-6123.md +++ b/ERCS/erc-6123.md @@ -264,9 +264,15 @@ The interface design and reference implementation are based on the following con ![image info](../assets/eip-6123/doc/sdc_trade_states.svg) +The diagram shows the trade states of a single trade SDC as in `SDCSingleTrade.sol`. + ### Sequence diagram of reference implementation 'SDCPledgedBalance.sol' + ![image info](../assets/eip-6123/doc/sequence.svg) +The sequence diagram show the function calls that create the trade and stellement state transitions +and the emitted events. + ## Test Cases Life-cycle unit tests based on the sample implementation and usage of [ERC-20](./eip-20.md) token is provided. See file [test/SDCTests.js](../assets/eip-6123/test/SDCTests.js) diff --git a/assets/erc-6123/doc/sdc_trade_states.svg b/assets/erc-6123/doc/sdc_trade_states.svg index fb99c78fc4..31219ae7c5 100644 --- a/assets/erc-6123/doc/sdc_trade_states.svg +++ b/assets/erc-6123/doc/sdc_trade_states.svg @@ -1,9 +1,9 @@ - + + xmlns:v="http://schemas.microsoft.com/visio/2003/SVGExtensions/" width="11.6929in" height="8.26772in" + viewBox="0 0 841.89 595.276" xml:space="preserve" color-interpolation-filters="sRGB" class="st22"> @@ -19,22 +19,21 @@ .st5 {fill:#316176} .st6 {stroke:#316176;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} .st7 {fill:#ffffff;font-family:Calibri;font-size:1.00001em} - .st8 {fill:#aecedd;stroke:#85b6cc;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5;visibility:hidden} - .st9 {fill:#ffffff;stroke:#85b6cc;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} - .st10 {fill:#aecedd} - .st11 {stroke:#85b6cc;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} - .st12 {marker-end:url(#mrkr4-49);stroke:#9b9b9b;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} - .st13 {fill:#9b9b9b;fill-opacity:1;stroke:#9b9b9b;stroke-opacity:1;stroke-width:0.16556291390728} - .st14 {fill:#ffffff;stroke:none;stroke-linecap:butt;stroke-width:7.2} - .st15 {fill:#595959;font-family:Calibri;font-size:0.666664em} - .st16 {font-size:1em} - .st17 {fill:#316176;stroke:#316176;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} - .st18 {fill:#ffffff;stroke:none;stroke-linecap:butt} - .st19 {fill:none;stroke:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} - .st20 {marker-end:url(#mrkr4-49);stroke:#9b9b9b;stroke-dasharray:3.5,2.5;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} - .st21 {fill:none} - .st22 {stroke:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} - .st23 {fill:none;fill-rule:evenodd;font-size:12px;overflow:visible;stroke-linecap:square;stroke-miterlimit:3} + .st8 {fill:#ffffff;font-family:Calibri;font-size:0.833336em} + .st9 {fill:#aecedd;stroke:#85b6cc;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5;visibility:hidden} + .st10 {fill:#ffffff;stroke:#85b6cc;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} + .st11 {fill:#aecedd} + .st12 {stroke:#85b6cc;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} + .st13 {marker-end:url(#mrkr4-49);stroke:#9b9b9b;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} + .st14 {fill:#9b9b9b;fill-opacity:1;stroke:#9b9b9b;stroke-opacity:1;stroke-width:0.16556291390728} + .st15 {fill:#ffffff;stroke:none;stroke-linecap:butt;stroke-width:7.2} + .st16 {fill:#595959;font-family:Calibri;font-size:0.666664em} + .st17 {font-size:1em} + .st18 {fill:#316176;stroke:#316176;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} + .st19 {fill:#ffffff;stroke:none;stroke-linecap:butt} + .st20 {fill:none;stroke:none;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} + .st21 {marker-end:url(#mrkr4-49);stroke:#9b9b9b;stroke-dasharray:3.5,2.5;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5} + .st22 {fill:none;fill-rule:evenodd;font-size:12px;overflow:visible;stroke-linecap:square;stroke-miterlimit:3} ]]> @@ -42,7 +41,7 @@ - @@ -53,20 +52,20 @@ Zeichenblatt-1 + v:shadowOffsetY="-8.50394"/> - + Anfangszustand - Start + Inactive - + - Start - + Inactive + @@ -100,11 +99,11 @@ + class="st6"/> Incepted - + @@ -138,11 +137,11 @@ + class="st6"/> Confirmed - + @@ -153,34 +152,34 @@ Zusammengesetzter Zustand.408 - + - + Sheet.409 - Terminated - + InTermination + Sheet.410 - + - - + - - Terminated + + InTermination - + @@ -191,7 +190,7 @@ Zusammengesetzter Zustand.419 - + @@ -206,51 +205,51 @@ - + + L35.43 595.28 Z" class="st11"/> + class="st12"/> Cancelled - + Dynamischer Verbinder.304 tx: inceptTrade by Couterparty1 - - - tx: inceptTradeby Couterparty1 - + + + tx: inceptTradeby Couterparty1 + Dynamischer Verbinder.313 tx: confirmTrade by Counterparty2 - - - tx: confirmTradeby Counterparty2 - + + + tx: confirmTradeby Counterparty2 + Dynamischer Verbinder.66 tx: afterTransfer - - - tx: afterTransfer - + + + tx: afterTransfer + Zustand.71 - + Sheet.354 @@ -260,23 +259,23 @@ - + Valuation - + Auswahl.292 - + - + Zustand.336 - + Sheet.360 @@ -286,16 +285,16 @@ - + Settled - + Zustand.380 - + Sheet.381 @@ -305,64 +304,65 @@ - + inTransfer - + Dynamischer Verbinder.398 success - - - success - + + + success + Dynamischer Verbinder.399 tx: initiateSettlement - - - - tx: initiateSettlement - + + + + tx: initiateSettlement + Dynamischer Verbinder.401 Initiate Transfer of Margin Buffers to SDC Balance - - - Initiate Transfer of Margin Buffers to SDC Balance - + + + Initiate Transfer of Margin Buffers to SDC Balance + Dynamischer Verbinder tx: perfomSettlement Initiate Transfer of Settlement Amount - - - tx: perfomSettlementInitiate Transfer ofSettlement Amount - + + + tx: perfomSettlementInitiate Transfer ofSettlement Amount + Dynamischer Verbinder.411 fail - - - - fail - + + + + fail + Dynamischer Verbinder.412 - Transfer Open Settlement Amount from SDC Balance + Final Transfer either from Party‘s or SDC Balance - - - - Transfer Open Settlement Amount from SDC Balance - + + + + Final Transfereither from Party‘sor SDC Balance + Sheet.413 - + - + - + Endzustand - End + Terminated - + - End - + Terminated + Auswahl.415 - + - + Dynamischer Verbinder.417 - + - + Dynamischer Verbinder.418 - Mutuall terminated or Maturity + Mutual Termination - - - - Mutuall terminated or Maturity - + + + + Mutual Termination + Dynamischer Verbinder.422 OPT: cancelInception - - - OPT: cancelInception - - Dynamischer Verbinder.430 - fail - - - - - - fail + + + OPT: cancelInception diff --git a/assets/erc-6123/doc/sequence.puml b/assets/erc-6123/doc/sequence.puml index ea04005b0e..a240a31445 100644 --- a/assets/erc-6123/doc/sequence.puml +++ b/assets/erc-6123/doc/sequence.puml @@ -9,12 +9,9 @@ title SmartDerivativeContract with Settlement-Token and off-chain Valuation Serv participant SettlementToken - participant EventHandler participant ValuationService - - activate EventHandler activate SettlementToken activate ValuationService @@ -31,17 +28,23 @@ CP1 ->SDC: tx 'inceptTrade' SDC-->EventHandler: emit TradeIncepted == TradeState 'Incepted' == -CP2->SDC: tx 'confirmTrade' -SDC->SDC: validate tradedata -SDC-->EventHandler: emit TradeConfirmed + CP2->SDC: tx 'confirmTrade' + SDC->SDC: validate tradedata + + SDC-->EventHandler: emit TradeConfirmed == TradeState 'Confirmed' == -SDC ->SettlementToken: tx 'transferFrom' margin buffers and termination fees\nto SDC address for CP1 and CP2 -SDC->SettlementToken: tx 'transferFrom' optional Upfront Fee from Paying to Receiving Party + SDC -> SettlementToken: tx 'transferFrom' margin buffers and termination fees\nto SDC address for CP1 and CP2 + SDC -> SettlementToken: tx 'transferFrom' optional Upfront Fee from Paying to Receiving Party + == TradeState 'inTransfer' == -SettlementToken->SDC: callback tx 'afterSettlement' + + SettlementToken->SDC: callback tx 'afterTransfer' + + SDC-->EventHandler: emit TradeActivated + ==ProcessState 'Settled' == end @@ -52,25 +55,31 @@ loop Every Settlement CP1->SDC: tx: 'initiateSettlement' == TradeState 'Valuation' == -SDC-->EventHandler:emit ProcessSettlementRequest +SDC-->EventHandler:emit SettlementRequested EventHandler->ValuationService: request valuation data ValuationService->EventHandler: return valuation data EventHandler->SDC: callback: tx 'performSettlement' SDC->SDC:Caps Settlement Amount at Margin Buffer Level + +SDC-->EventHandler: emit SettlementEvaluated + SDC->SettlementToken: tx 'transferFrom' settlement amount from Paying Party to Receiving Party Balance == TradeState 'inTransfer' == -SDC-->EventHandler: emit AwaitingTransfer alt Transfer Check - SettlementToken->SDC: callback tx 'afterSettlement' + SettlementToken->SDC: callback tx 'afterTransfer' else success + SDC-->EventHandler: emit SettlementTransferred == TradeState 'Settled' == else fail + SDC-->EventHandler: emit SettlementFailed + SDC->SettlementToken: tx 'transfer' Settlement Amount from SDC Balance to Receiving Party SDC->SettlementToken: tx 'transfer' Termination Fee from SDC Balance to Receiving Party - SDC->SettlementToken: tx 'transfer' - Release remainigBalances to parties + SDC->SettlementToken: tx 'transfer' - Release remainigBalances to parties + SDC-->EventHandler: emit TradeTerminated == TradeState 'Terminated' == end diff --git a/assets/erc-6123/doc/sequence.svg b/assets/erc-6123/doc/sequence.svg index f7e877a984..99362b5977 100644 --- a/assets/erc-6123/doc/sequence.svg +++ b/assets/erc-6123/doc/sequence.svg @@ -1 +1 @@ -SmartDerivativeContract with Settlement-Token and off-chain Valuation ServiceCP1CP1CP2CP2SDCSDCSettlementTokenSettlementTokenEventHandlerEventHandlerValuationServiceValuationServiceInitialize Tradeallocate balancesallocate balancestx 'deploy' a SDC with token addresstx set 'allowance' for SDC addresstx set 'allowance' for SDC addresstx 'inceptTrade'emit TradeInceptedTradeState 'Incepted'tx 'confirmTrade'validate tradedataemit TradeConfirmedTradeState 'Confirmed'tx 'transferFrom' margin buffers and termination feesto SDC address for CP1 and CP2tx 'transferFrom' optional Upfront Fee from Paying to Receiving PartyTradeState 'inTransfer'callback tx 'afterSettlement'ProcessState 'Settled'loop[Every Settlement]tx: 'initiateSettlement'TradeState 'Valuation'emit ProcessSettlementRequestrequest valuation datareturn valuation datacallback: tx 'performSettlement'Caps Settlement Amount at Margin Buffer Leveltx 'transferFrom' settlement amount from Paying Party to Receiving Party BalanceTradeState 'inTransfer'emit AwaitingTransferalt[Transfer Check]callback tx 'afterSettlement'[success]TradeState 'Settled'[fail]tx 'transfer' Settlement Amount from SDC Balance to Receiving Partytx 'transfer' Termination Fee from SDC Balance to Receiving Partytx 'approve' - Unlock remaing Party BalancesTradeState 'Terminated' \ No newline at end of file +SmartDerivativeContract with Settlement-Token and off-chain Valuation ServiceCP1CP1CP2CP2SDCSDCSettlementTokenSettlementTokenEventHandlerEventHandlerValuationServiceValuationServiceInitialize Tradeallocate balancesallocate balancestx 'deploy' a SDC with token addresstx 'inceptTrade'emit TradeInceptedTradeState 'Incepted'tx 'confirmTrade'validate tradedataemit TradeConfirmedTradeState 'Confirmed'tx 'transferFrom' margin buffers and termination feesto SDC address for CP1 and CP2tx 'transferFrom' optional Upfront Fee from Paying to Receiving PartyTradeState 'inTransfer'callback tx 'afterTransfer'emit TradeActivatedProcessState 'Settled'loop[Every Settlement]tx: 'initiateSettlement'TradeState 'Valuation'emit SettlementRequestedrequest valuation datareturn valuation datacallback: tx 'performSettlement'Caps Settlement Amount at Margin Buffer Levelemit SettlementEvaluatedtx 'transferFrom' settlement amount from Paying Party to Receiving Party BalanceTradeState 'inTransfer'alt[Transfer Check]callback tx 'afterTransfer'[success]emit SettlementTransferredTradeState 'Settled'[fail]emit SettlementFailedtx 'transfer' Settlement Amount from SDC Balance to Receiving Partytx 'transfer' Termination Fee from SDC Balance to Receiving Partytx 'transfer' - Release remainigBalances to partiesemit TradeTerminatedTradeState 'Terminated' \ No newline at end of file