This repository has been archived by the owner on Apr 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProposal.java
75 lines (56 loc) · 1.8 KB
/
Proposal.java
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.util.*;
public class Proposal {
// Amount of Kairo staked for/against a Proposal
public double kairoSupport;
public double kairoAgainst;
// Current amount of balance put in the Proposal
public double balance;
// The current price the Proposal is at, set to 1 for now to normalize rates
public double price = 1.0;
// The percentages that the Proposals grow/fall
public double growthRate;
public double fallRate;
// Probability that either grow/fall occurs
// A double from 0 to 1
public double growthThreshold;
// Proposal ID
public int index;
// Pointer to the GroupFund
public GroupFund g;
// Need an enum for if it's a Winner, Loser, or Neutral we're in
public enum Status {WINNER, LOSER, NEUTRAL}
public Status statusVar;
// Constructor
public Proposal() {
}
// Appends proposal to the GroupFund list
public void addProposal() {
g.proposalList.add(this);
}
// Constructor + adder function
public static Proposal addProposal(double growthRate, double fallRate,
double growthThreshold, GroupFund g) {
Proposal proposalVar = new Proposal();
proposalVar.statusVar = Status.NEUTRAL;
proposalVar.growthRate = growthRate;
proposalVar.fallRate = fallRate;
proposalVar.growthThreshold = growthThreshold;
proposalVar.g = g;
proposalVar.index = g.proposalList.size();
// Adds it to the Proposal
proposalVar.addProposal();
return proposalVar;
}
// Updates the Proposal's prices
public void update() {
double prob = Math.random();
if (prob < growthThreshold) {
price = (price * growthRate);
this.statusVar = Status.WINNER;
}
else {
price = (price * fallRate);
this.statusVar = Status.LOSER;
}
}
}