deposit.gno
3.85 Kb ยท 170 lines
1package launchpad
2
3// Deposit represents a deposit made by a user in a launchpad project.
4//
5// This struct contains the necessary data and methods to manage and distribute
6// rewards for a specific deposit.
7//
8// Fields:
9// - depositor (std.Address): The address of the depositor.
10// - id (string): The unique identifier for the deposit.
11// - projectID (string): The ID of the project associated with the deposit.
12// - tier (int64): The tier of the deposit.
13// - depositAmount (int64): The amount of the deposit.
14// - withdrawnHeight (int64): The height at which the deposit was withdrawn.
15// - withdrawnTime (int64): The time when the deposit was withdrawn.
16// - createdTime (int64): The time when the deposit was created.
17// - endTime (int64): The time when the deposit ends.
18type Deposit struct {
19 depositor address
20
21 id string
22 projectID string
23 tier int64 // 30, 60, 180 // instead of tierId
24 depositAmount int64
25 withdrawnHeight int64
26 withdrawnTime int64
27 createdHeight int64
28 createdAt int64
29 endTime int64
30}
31
32func (d *Deposit) ID() string {
33 return d.id
34}
35
36func (d *Deposit) SetID(id string) {
37 d.id = id
38}
39
40func (d *Deposit) ProjectID() string {
41 return d.projectID
42}
43
44func (d *Deposit) SetProjectID(projectID string) {
45 d.projectID = projectID
46}
47
48func (d *Deposit) Tier() int64 {
49 return d.tier
50}
51
52func (d *Deposit) SetTier(tier int64) {
53 d.tier = tier
54}
55
56func (d *Deposit) Depositor() address {
57 return d.depositor
58}
59
60func (d *Deposit) SetDepositor(depositor address) {
61 d.depositor = depositor
62}
63
64func (d *Deposit) DepositAmount() int64 {
65 return d.depositAmount
66}
67
68func (d *Deposit) SetDepositAmount(depositAmount int64) {
69 d.depositAmount = depositAmount
70}
71
72func (d *Deposit) CreatedHeight() int64 {
73 return d.createdHeight
74}
75
76func (d *Deposit) SetCreatedHeight(createdHeight int64) {
77 d.createdHeight = createdHeight
78}
79
80func (d *Deposit) CreatedAt() int64 {
81 return d.createdAt
82}
83
84func (d *Deposit) SetCreatedAt(createdAt int64) {
85 d.createdAt = createdAt
86}
87
88func (d *Deposit) WithdrawnTime() int64 {
89 return d.withdrawnTime
90}
91
92func (d *Deposit) SetWithdrawnTime(withdrawnTime int64) {
93 d.withdrawnTime = withdrawnTime
94}
95
96func (d *Deposit) WithdrawnHeight() int64 {
97 return d.withdrawnHeight
98}
99
100func (d *Deposit) SetWithdrawnHeight(withdrawnHeight int64) {
101 d.withdrawnHeight = withdrawnHeight
102}
103
104func (d *Deposit) EndTime() int64 {
105 return d.endTime
106}
107
108func (d *Deposit) SetEndTime(endTime int64) {
109 d.endTime = endTime
110}
111
112func (d *Deposit) ProjectTierID() string {
113 return MakeProjectTierID(d.projectID, d.tier)
114}
115
116func (d *Deposit) IsDepositor(address address) bool {
117 return d.depositor.String() == address.String()
118}
119
120func (d *Deposit) IsEnded(currentTime int64) bool {
121 return d.endTime < currentTime
122}
123
124func (d *Deposit) IsWithdrawn() bool {
125 return d.withdrawnTime > 0 && d.withdrawnHeight > 0
126}
127
128func (d *Deposit) SetWithdrawn(withdrawnHeight int64, withdrawnTime int64) {
129 d.withdrawnHeight = withdrawnHeight
130 d.withdrawnTime = withdrawnTime
131}
132
133func (d Deposit) Clone() *Deposit {
134 return &Deposit{
135 id: d.id,
136 projectID: d.projectID,
137 tier: d.tier,
138 depositor: d.depositor,
139 depositAmount: d.depositAmount,
140 withdrawnHeight: d.withdrawnHeight,
141 withdrawnTime: d.withdrawnTime,
142 createdHeight: d.createdHeight,
143 createdAt: d.createdAt,
144 endTime: d.endTime,
145 }
146}
147
148// NewDeposit returns a pointer to a new Deposit with the given values.
149func NewDeposit(
150 depositID string,
151 projectID string,
152 tier int64,
153 depositor address,
154 depositAmount int64,
155 createdHeight int64,
156 createdTime int64,
157 endTime int64,
158) *Deposit {
159 return &Deposit{
160 id: depositID,
161 projectID: projectID,
162 tier: tier,
163 depositor: depositor,
164 depositAmount: depositAmount,
165 withdrawnHeight: 0,
166 createdHeight: createdHeight,
167 createdAt: createdTime,
168 endTime: endTime,
169 }
170}