With penalty
The escrow archetype presented below defines an escrow process with a penalty for the seller if the transaction fails (for example if it does not happen before the deadline).
Factoring is enabled: the seller can sell the “invoice” to a creditor, and the buyer can sell the penalty to a debtor.
A state machine is used to follow the different stages of the escrow transaction.
escrow:penalty.arl
1
archetype escrow_penalty
2
3
variable buyer : role = @tz1Lc2qBKEWCBeDU8npG6zCeCqpmaegRi6Jg
4
5
variable[%transferable%] debitor : role = buyer
6
7
variable seller : role = @tz1bfVgcJC4ukaQSHUe1EbrUd5SekXeP9CWk
8
9
variable[%transferable%] creditor : role = seller
10
11
variable oracle : role = @tz1iawHeddgggn6P5r5jtq2wDRqcJVksGVSa
12
13
variable[%traceable%] price : tez = 10tz
14
15
variable[%traceable%] [%mutable_signed (([{buyer}; {debitor}]), (state = Created))%]
16
penalty : tez = 0.1 * price
17
18
(* action deadline *)
19
variable[%mutable ((buyer or seller), (instate (Created)))%] deadline : date = 2020-06-28T00:00:00
20
21
(* state machine *)
22
states =
23
| Created initial
24
| Aborted
25
| Confirmed
26
| Canceled
27
| Transferred with { i1 : balance = 0tz; }
28
29
transition abort () {
30
called by buyer or seller
31
32
from Created
33
to Aborted
34
}
35
36
transition[%signedbyall ([buyer; seller])%] confirm () {
37
from Created
38
to Confirmed when { balance = price + penalty }
39
}
40
41
transition transfer_ () {
42
called by oracle
43
44
from Confirmed
45
to Transferred when { now < deadline }
46
with effect {
47
transfer price to creditor;
48
transfer penalty to seller
49
}
50
}
51
52
transition cancel () {
53
called by oracle
54
55
from Confirmed
56
to Canceled
57
with effect {
58
transfer penalty to debitor;
59
transfer price to buyer
60
}
61
}
Copied!
Last modified 1mo ago
Export as PDF
Copy link
Edit on GitHub