deposit.gno
8.65 Kb · 284 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 duration of the deposit (30, 90, or 180 days).
13// - depositAmount (int64): The amount of the deposit.
14// - withdrawnHeight (int64): The height at which the deposit was withdrawn.
15// - withdrawnTime (int64): The Unix timestamp when the deposit was withdrawn.
16// - createdHeight (int64): The block height at which the deposit was created.
17// - createdAt (int64): The Unix timestamp when the deposit was created.
18// - endTime (int64): The Unix timestamp when the deposit ends.
19type Deposit struct {
20 depositor address
21
22 id string
23 projectID string
24 tier int64 // 30, 90, 180 // instead of tierId
25 depositAmount int64
26 withdrawnHeight int64
27 withdrawnTime int64
28 createdHeight int64
29 createdAt int64
30 endTime int64
31}
32
33// ID returns the unique identifier stored for the deposit.
34//
35// Returns:
36// - id: deposit identifier used to retrieve this deposit from launchpad state.
37func (d Deposit) ID() string {
38 return d.id
39}
40
41// SetID updates the unique identifier stored for the deposit.
42//
43// Parameters:
44// - id: new identifier to associate with the deposit.
45func (d *Deposit) SetID(id string) {
46 d.id = id
47}
48
49// ProjectID returns the identifier of the launchpad project associated with the deposit.
50//
51// Returns:
52// - projectID: associated launchpad project identifier.
53func (d Deposit) ProjectID() string {
54 return d.projectID
55}
56
57// SetProjectID updates the launchpad project identifier associated with the deposit.
58//
59// Parameters:
60// - projectID: identifier of the launchpad project to associate with the deposit.
61func (d *Deposit) SetProjectID(projectID string) {
62 d.projectID = projectID
63}
64
65// Tier returns the deposit's tier duration.
66//
67// Returns:
68// - tier: tier duration in days; launchpad tiers use 30, 90, or 180.
69func (d Deposit) Tier() int64 {
70 return d.tier
71}
72
73// SetTier updates the tier duration recorded for the deposit.
74//
75// Parameters:
76// - tier: tier duration in days; valid launchpad tiers are 30, 90, or 180.
77func (d *Deposit) SetTier(tier int64) {
78 d.tier = tier
79}
80
81// Depositor returns the address that made the deposit.
82//
83// Returns:
84// - depositor: account address recorded as the deposit owner.
85func (d Deposit) Depositor() address {
86 return d.depositor
87}
88
89// SetDepositor updates the account address recorded as the deposit owner.
90//
91// Parameters:
92// - depositor: account address to record as the deposit owner.
93func (d *Deposit) SetDepositor(depositor address) {
94 d.depositor = depositor
95}
96
97// DepositAmount returns the amount recorded for the deposit.
98//
99// Returns:
100// - depositAmount: amount of GNS deposited for the associated project.
101func (d Deposit) DepositAmount() int64 {
102 return d.depositAmount
103}
104
105// SetDepositAmount updates the amount recorded for the deposit.
106//
107// Parameters:
108// - depositAmount: amount of GNS to record as deposited for the associated project.
109func (d *Deposit) SetDepositAmount(depositAmount int64) {
110 d.depositAmount = depositAmount
111}
112
113// CreatedHeight returns the block height at which the deposit was created.
114//
115// Returns:
116// - createdHeight: creation block height stored on the deposit.
117func (d Deposit) CreatedHeight() int64 {
118 return d.createdHeight
119}
120
121// SetCreatedHeight updates the block height recorded for deposit creation.
122//
123// Parameters:
124// - createdHeight: block height at which the deposit was created.
125func (d *Deposit) SetCreatedHeight(createdHeight int64) {
126 d.createdHeight = createdHeight
127}
128
129// CreatedAt returns the Unix timestamp at which the deposit was created.
130//
131// Returns:
132// - createdAt: creation timestamp in Unix seconds.
133func (d Deposit) CreatedAt() int64 {
134 return d.createdAt
135}
136
137// SetCreatedAt updates the Unix timestamp recorded for deposit creation.
138//
139// Parameters:
140// - createdAt: creation timestamp in Unix seconds.
141func (d *Deposit) SetCreatedAt(createdAt int64) {
142 d.createdAt = createdAt
143}
144
145// WithdrawnTime returns the Unix timestamp recorded for withdrawal.
146//
147// Returns:
148// - withdrawnTime: withdrawal timestamp in Unix seconds; zero before withdrawal is recorded.
149func (d Deposit) WithdrawnTime() int64 {
150 return d.withdrawnTime
151}
152
153// SetWithdrawnTime updates the Unix timestamp recorded for withdrawal.
154//
155// Parameters:
156// - withdrawnTime: withdrawal timestamp in Unix seconds.
157func (d *Deposit) SetWithdrawnTime(withdrawnTime int64) {
158 d.withdrawnTime = withdrawnTime
159}
160
161// WithdrawnHeight returns the block height recorded for withdrawal.
162//
163// Returns:
164// - withdrawnHeight: withdrawal block height; zero before withdrawal is recorded.
165func (d Deposit) WithdrawnHeight() int64 {
166 return d.withdrawnHeight
167}
168
169// SetWithdrawnHeight updates the block height recorded for withdrawal.
170//
171// Parameters:
172// - withdrawnHeight: block height at which the deposit was withdrawn.
173func (d *Deposit) SetWithdrawnHeight(withdrawnHeight int64) {
174 d.withdrawnHeight = withdrawnHeight
175}
176
177// EndTime returns the Unix timestamp at which the deposit's tier ends.
178//
179// Returns:
180// - endTime: tier end timestamp in Unix seconds.
181func (d Deposit) EndTime() int64 {
182 return d.endTime
183}
184
185// SetEndTime updates the Unix timestamp at which the deposit's tier ends.
186//
187// Parameters:
188// - endTime: tier end timestamp in Unix seconds.
189func (d *Deposit) SetEndTime(endTime int64) {
190 d.endTime = endTime
191}
192
193// ProjectTierID returns the composite identifier for the deposit's project tier.
194//
195// Returns:
196// - projectTierID: identifier formed from the project ID and tier duration.
197func (d Deposit) ProjectTierID() string {
198 return MakeProjectTierID(d.projectID, d.tier)
199}
200
201// IsDepositor reports whether an address matches the deposit owner.
202//
203// Parameters:
204// - address: account address to compare with the recorded depositor.
205//
206// Returns:
207// - matches: true when the supplied address has the same string representation as the depositor; false otherwise.
208func (d Deposit) IsDepositor(address address) bool {
209 return d.depositor.String() == address.String()
210}
211
212// IsEnded reports whether the deposit's tier end time is before the supplied time.
213//
214// Parameters:
215// - currentTime: current Unix timestamp in seconds used for the end-time comparison.
216//
217// Returns:
218// - ended: true when endTime is strictly less than currentTime; false at or before the end time.
219func (d Deposit) IsEnded(currentTime int64) bool {
220 return d.endTime < currentTime
221}
222
223// IsWithdrawn reports whether both withdrawal markers have been recorded.
224//
225// Returns:
226// - withdrawn: true when both withdrawnHeight and withdrawnTime are greater than zero; false when either marker is zero.
227func (d Deposit) IsWithdrawn() bool {
228 return d.withdrawnTime > 0 && d.withdrawnHeight > 0
229}
230
231// SetWithdrawn records the block height and Unix timestamp of withdrawal.
232//
233// Parameters:
234// - withdrawnHeight: block height at which the deposit was withdrawn.
235// - withdrawnTime: withdrawal timestamp in Unix seconds.
236func (d *Deposit) SetWithdrawn(withdrawnHeight int64, withdrawnTime int64) {
237 d.withdrawnHeight = withdrawnHeight
238 d.withdrawnTime = withdrawnTime
239}
240
241// MakeDeposit returns a new Deposit value with the given values.
242//
243// Parameters:
244// - depositID: unique identifier to assign to the new deposit.
245// - projectID: launchpad project identifier associated with the deposit.
246// - tier: tier duration in days; launchpad tiers use 30, 90, or 180.
247// - depositor: account address making the deposit.
248// - depositAmount: amount of GNS deposited for the project.
249// - createdHeight: block height at which the deposit was created.
250// - createdTime: creation timestamp in Unix seconds.
251// - endTime: tier end timestamp in Unix seconds.
252//
253// Returns:
254// - deposit: new Deposit populated with the supplied fields and zero withdrawal markers.
255func MakeDeposit(
256 depositID string,
257 projectID string,
258 tier int64,
259 depositor address,
260 depositAmount int64,
261 createdHeight int64,
262 createdTime int64,
263 endTime int64,
264) Deposit {
265 return Deposit{
266 id: depositID,
267 projectID: projectID,
268 tier: tier,
269 depositor: depositor,
270 depositAmount: depositAmount,
271 withdrawnHeight: 0,
272 createdHeight: createdHeight,
273 createdAt: createdTime,
274 endTime: endTime,
275 }
276}
277
278// DefaultDeposit returns the zero Deposit value.
279//
280// Returns:
281// - deposit: zero-valued Deposit with no identifier, amounts, timestamps, or withdrawal markers.
282func DefaultDeposit() Deposit {
283 return Deposit{}
284}