Competition
Best submission decision process
The competition archetype defines a process that enables a competitor to submit a score. The score is signed by an oracle. The signature of the score is generated by the signedby extension.
The decision process specified in the decide transaction allocates the prize to the top 3 scores. Allocation policy manages the situations where less than 3 competitors have submitted a score.
competition.arl
1
archetype competition
2
3
variable[%transferable%] organizer : role = @tz1Lc2qBKEWCBeDU8npG6zCeCqpmaegRi6Jg
4
5
(* start date *)
6
variable[%mutable (organiser, (instate (Created)))%] startdate : date = 2019-11-12T00:00:00
7
8
(* deadline *)
9
variable[%mutable (organiser, (instate (Created)))%] deadline : date = 2020-11-12T00:00:00
10
11
variable[%traceable%] prize : tez = 3500tz
12
13
variable oracle : role = @tz1bfVgcJC4ukaQSHUe1EbrUd5SekXeP9CWk
14
15
asset submission {
16
competitor : role;
17
score : int;
18
timestamp : date;
19
}
20
21
(* state machine *)
22
states =
23
| Created initial
24
| InProgress
25
| Done with { s1 : balance = 0tz; }
26
| Closed
27
28
transition confirm () {
29
from Created
30
to InProgress when { now > startdate }
31
}
32
33
action submit (ckey : pkey of submission, pscore[%signedby (oracle)%] : int) {
34
require {
35
c1 : state = InProgress;
36
}
37
38
effect {
39
submission.add ({ competitor = ckey;
40
score = pscore;
41
timestamp = now })
42
}
43
}
44
45
transition decide () {
46
require {
47
c2 : now > deadline;
48
}
49
from InProgress
50
to Done
51
with effect {
52
let submissions = submission.sort(desc(score), timestamp) in
53
if submissions.count() >= 3
54
then (
55
let first = submissions.nth(0).competitor in
56
let second = submissions.nth(1).competitor in
57
let third = submissions.nth(2).competitor in
58
let q1 = 0.5 * prize in
59
let q2 = 0.3 * prize in
60
let q3 = 0.2 * prize in
61
transfer q1 to first;
62
transfer q2 to second;
63
transfer q3 to third;
64
transfer (prize - q1 - q2 - q3) to organizer)
65
else if (submissions.count() >= 2)
66
then (
67
let first = submissions.nth(0).competitor in
68
let second = submissions.nth(1).competitor in
69
let q1 = 0.6 * prize in
70
let q2 = 0.4 * prize in
71
transfer q1 to first;
72
transfer q2 to second;
73
transfer (prize - q1 - q2) to organizer)
74
else if (submissions.count() >= 1)
75
then (
76
let first = submissions.nth(0).competitor in
77
transfer prize to first)
78
else transfer prize to organizer
79
}
80
}
Copied!
Last modified 1mo ago
Export as PDF
Copy link
Edit on GitHub