project_tier.gno
2.11 Kb ยท 68 lines
1package v1
2
3import (
4 "gno.land/r/gnoswap/launchpad"
5
6 u256 "gno.land/p/gnoswap/uint256"
7)
8
9func getTierCurrentDepositCount(t *launchpad.ProjectTier) int64 {
10 return safeSubInt64(t.TotalDepositCount(), t.TotalWithdrawCount())
11}
12
13func getTierCurrentDepositAmount(t *launchpad.ProjectTier) int64 {
14 return safeSubInt64(t.TotalDepositAmount(), t.TotalWithdrawAmount())
15}
16
17func getCalculatedLeftReward(t *launchpad.ProjectTier) int64 {
18 return safeSubInt64(t.TotalDistributeAmount(), t.TotalCollectedAmount())
19}
20
21func depositToTier(t *launchpad.ProjectTier, deposit *launchpad.Deposit) {
22 totalDepositAmount := safeAddInt64(t.TotalDepositAmount(), deposit.DepositAmount())
23 totalDepositCount := safeAddInt64(t.TotalDepositCount(), 1)
24
25 t.SetTotalDepositAmount(totalDepositAmount)
26 t.SetTotalDepositCount(totalDepositCount)
27}
28
29func withdrawToTier(t *launchpad.ProjectTier, deposit *launchpad.Deposit) {
30 totalWithdrawAmount := safeAddInt64(t.TotalWithdrawAmount(), deposit.DepositAmount())
31 totalWithdrawCount := safeAddInt64(t.TotalWithdrawCount(), 1)
32
33 t.SetTotalWithdrawAmount(totalWithdrawAmount)
34 t.SetTotalWithdrawCount(totalWithdrawCount)
35}
36
37func updateTierDistributeAmountPerSecond(t *launchpad.ProjectTier) {
38 // Use time duration instead of block count
39 distributeTimeDuration := t.EndTime() - t.StartTime()
40 if distributeTimeDuration <= 0 {
41 return
42 }
43
44 totalDistributeAmountX128, overflow := u256.Zero().MulOverflow(u256.NewUintFromInt64(t.TotalDistributeAmount()), q128.Clone())
45 if overflow {
46 panic(errOverflow)
47 }
48
49 // Divide by time duration in seconds
50 distributeAmountPerSecondX128 := u256.Zero().Div(totalDistributeAmountX128, u256.NewUintFromInt64(distributeTimeDuration))
51
52 t.SetDistributeAmountPerSecondX128(distributeAmountPerSecondX128)
53}
54
55// newProjectTier returns a pointer to a new ProjectTier with the given values.
56func newProjectTier(
57 projectID string,
58 tierDuration int64,
59 totalDistributeAmount int64,
60 startTime int64,
61 endTime int64,
62) *launchpad.ProjectTier {
63 tier := launchpad.NewProjectTier(projectID, tierDuration, totalDistributeAmount, startTime, endTime)
64
65 updateTierDistributeAmountPerSecond(tier)
66
67 return tier
68}