-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathlfest.tla
More file actions
43 lines (33 loc) · 1.82 KB
/
lfest.tla
File metadata and controls
43 lines (33 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
------------------------------- MODULE lfest -------------------------------
EXTENDS Integers, TLC
VARIABLES balances
(* Define the state as a record with three balances *)
(*state == [available: INT, positionMargin: INT, orderMargin: INT]*)
(* Initial state: no position active, so only available balance *)
Init == balances = [available |-> 1000, positionMargin |-> 0, orderMargin |-> 0]
(* Place an order: requires sufficient available balance *)
PlaceOrder(amount) ==
/\ amount > 0
/\ balances.available >= amount
/\ balances' = [balances EXCEPT !.available = balances.available - amount, !.orderMargin = balances.orderMargin + amount]
(* Fill an order: move margin from orderMargin to positionMargin *)
FillOrder(amount) ==
/\ amount > 0
/\ balances.orderMargin >= amount
/\ balances' = [balances EXCEPT !.orderMargin = balances.orderMargin - amount, !.positionMargin = balances.positionMargin + amount]
(* Close a position: move margin from positionMargin to available balance *)
ClosePosition(amount) ==
/\ amount > 0
/\ balances.positionMargin >= amount
/\ balances' = [balances EXCEPT !.positionMargin = balances.positionMargin - amount, !.available = balances.available + amount]
(* Define the next-state relation *)
Next ==
\A amount \in (1..1000): PlaceOrder(amount) \/ FillOrder(amount) \/ ClosePosition(amount)
(* Safety: Ensure all balances are non-negat ive *)
Safety == balances.available >= 0 /\ balances.positionMargin >= 0 /\ balances.orderMargin >= 0
(* The specification is the combination of the initial state and transitions *)
Spec == Init /\ [][Next]_balances /\ Safety
=============================================================================
\* Modification History
\* Last modified Fri May 30 11:24:59 CEST 2025 by magewe
\* Created Tue May 27 13:42:49 CEST 2025 by magewe