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.
1
archetype competition
2
3
variable organizer : role = @tz1Lc2qBKEWCBeDU8npG6zCeCqpmaegRi6Jg
4
5
(* start date *)
6
variable startdate : date = 2019-11-12T00:00:00
7
8
(* deadline *)
9
variable deadline : date = 2020-11-12T00:00:00
10
11
variable 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
entry submit (ckey : pkey<submission>, pscore : 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
var submissions = submission.sort(desc(score), timestamp);
53
if submissions.count() >= 3
54
then (
55
var first = submissions.nth(0);
56
var second = submissions.nth(1);
57
var third = submissions.nth(2);
58
var q1 = 0.5 * prize;
59
var q2 = 0.3 * prize;
60
var q3 = 0.2 * prize;
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
var first = submissions.nth(0);
68
var second = submissions.nth(1);
69
var q1 = 0.6 * prize;
70
var q2 = 0.4 * prize;
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
var first = submissions.nth(0);
77
transfer prize to first)
78
else transfer prize to organizer
79
}
80
}
81
Copied!
Last modified 1yr ago
Export as PDF
Copy link