Class SmartContractStateMachine
java.lang.Object
net.finmath.smartcontract.statemachine.SmartContractStateMachine
State Machine Modeling of the Smart Derivative Contract.
This state machine models a smart derivative contract using a loop of the following core states:
- a pre-funding test (Guard),
- an active state (State) (representing the time until the settlement has to occurs),
- a settlement state (State),
- a settlement test (Guard),
- a maturity test (Guard),
SmartContractStateMachine.States
and SmartContractStateMachine.Events
.
Most of the time, a smart derivative contract is in the ACTIVE state. If a SETTLE event occurs the contract moves to the SETTLEMENT state.
A settlement can be partial or successful. A partial settlement will lead to termination.
After settlement, the machine checks the success of the settlement, checks for maturity, checks for pre-funding for the next period, then returns to the active state.
Hence, there are three different termination states.
- Author:
- Christian Fries
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The events of a smart derivative contract.class
static enum
The states of a smart derivative contract. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.statemachine.StateMachine
<SmartContractStateMachine.States, SmartContractStateMachine.Events> Building a smart derivative contract state machine.boolean
Check the state if the contract is matured.boolean
Check the state if the account is prefunded.boolean
Check the state if the settlement has been successful.static void
Example for using theSmartContractStateMachine
.org.springframework.statemachine.guard.Guard
<SmartContractStateMachine.States, SmartContractStateMachine.Events> Test to be executed to check for maturity.org.springframework.statemachine.action.Action
<SmartContractStateMachine.States, SmartContractStateMachine.Events> Action performend if the settlement state is entered.org.springframework.statemachine.guard.Guard
<SmartContractStateMachine.States, SmartContractStateMachine.Events> Test to be executed to check for existing pre-funding.setMatured
(boolean isMatured) Set the state if the contract is matured.setPrefunded
(boolean isPrefunded) Set the state if the account is prefunded.setSettlementSuccessful
(boolean isSettlementSuccessful) Set the state if the settlement has been successful.org.springframework.statemachine.guard.Guard
<SmartContractStateMachine.States, SmartContractStateMachine.Events> Test to be executed to check for successful settlement.
-
Constructor Details
-
SmartContractStateMachine
public SmartContractStateMachine()
-
-
Method Details
-
main
-
buildMachine
public org.springframework.statemachine.StateMachine<SmartContractStateMachine.States,SmartContractStateMachine.Events> buildMachine() throws ExceptionBuilding a smart derivative contract state machine.- Returns:
- The state machine in terms of States and Events.
- Throws:
Exception
- Thrown when build of state machine fails. This is a severe internal error. It should not happen.
-
isPrefunded
public boolean isPrefunded()Check the state if the account is prefunded.- Returns:
- True, if the account has been verified to be pre-funded.
-
setPrefunded
Set the state if the account is prefunded.- Parameters:
isPrefunded
- True, if the account has been verified to be pre-funded.- Returns:
- Self reference.
-
isMatured
public boolean isMatured()Check the state if the contract is matured.- Returns:
- True, if the contract is matured.
-
setMatured
Set the state if the contract is matured.- Parameters:
isMatured
- True, if the contract is matured.- Returns:
- Self reference.
-
isSettlementSuccessful
public boolean isSettlementSuccessful()Check the state if the settlement has been successful.- Returns:
- True, if the settlement was successful.
-
setSettlementSuccessful
Set the state if the settlement has been successful.- Parameters:
isSettlementSuccessful
- True, if the settlement has been successful.- Returns:
- Self reference.
-
settlementCheck
public org.springframework.statemachine.guard.Guard<SmartContractStateMachine.States,SmartContractStateMachine.Events> settlementCheck()Test to be executed to check for successful settlement.- Returns:
- The test to be executed to check for successful settlement.
-
prefundingCheck
public org.springframework.statemachine.guard.Guard<SmartContractStateMachine.States,SmartContractStateMachine.Events> prefundingCheck()Test to be executed to check for existing pre-funding.- Returns:
- The test to be executed to check for existing pre-funding.
-
notMaturedCheck
public org.springframework.statemachine.guard.Guard<SmartContractStateMachine.States,SmartContractStateMachine.Events> notMaturedCheck()Test to be executed to check for maturity.- Returns:
- The test to be executed to check for maturity.
-
performSettlement
public org.springframework.statemachine.action.Action<SmartContractStateMachine.States,SmartContractStateMachine.Events> performSettlement()Action performend if the settlement state is entered.- Returns:
- The action executed if settlement state is entered
-