Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

getter.gno

2.39 Kb · 76 lines
 1package emission
 2
 3import (
 4	gnsmath "gno.land/p/gnoswap/gnsmath"
 5)
 6
 7// GetLeftGNSAmount returns the amount of undistributed GNS tokens from previous distributions.
 8func GetLeftGNSAmount() int64 {
 9	return leftGNSAmount
10}
11
12// GetDistributionStartTimestamp returns the timestamp when emission distribution started.
13// Returns 0 if distribution has not been started yet.
14func GetDistributionStartTimestamp() int64 {
15	return distributionStartTimestamp
16}
17
18// GetLastExecutedTimestamp returns the timestamp of the last emission distribution execution.
19func GetLastExecutedTimestamp() int64 {
20	return lastExecutedTimestamp
21}
22
23// GetAllDistributionBpsPct returns all distribution percentages in basis points.
24func GetAllDistributionBpsPct() map[int]int64 {
25	result := make(map[int]int64, len(distributionBpsPct))
26	if distributionBpsPct == nil {
27		return result
28	}
29
30	for target, pct := range distributionBpsPct {
31		result[target] = pct
32	}
33
34	return result
35}
36
37// GetTotalAccuDistributed returns the total accumulated distributed GNS amount.
38func GetTotalAccuDistributed() int64 {
39	return gnsmath.SafeAddInt64(
40		gnsmath.SafeAddInt64(accuDistributedToStaker, accuDistributedToDevOps),
41		gnsmath.SafeAddInt64(accuDistributedToCommunityPool, accuDistributedToGovStaker),
42	)
43}
44
45// GetTotalDistributed returns the total pending distributed GNS amount.
46func GetTotalDistributed() int64 {
47	return gnsmath.SafeAddInt64(
48		gnsmath.SafeAddInt64(distributedToStaker, distributedToDevOps),
49		gnsmath.SafeAddInt64(distributedToCommunityPool, distributedToGovStaker),
50	)
51}
52
53// GetDistributionEndTimestamp returns the timestamp when emission distribution ends.
54// Returns 0 if distribution has not been started yet.
55func GetDistributionEndTimestamp() int64 {
56	if distributionStartTimestamp == 0 {
57		return 0
58	}
59
60	return gnsmath.SafeAddInt64(distributionStartTimestamp, totalDistributionDuration-1)
61}
62
63// GetDistributableAmount returns distribution amounts by target and the remainder.
64// If timestamp is outside the distribution window, it returns an empty map and the full amount as left.
65func GetDistributableAmount(amount, timestamp int64) (map[int]int64, int64) {
66	if distributionStartTimestamp == 0 || timestamp < distributionStartTimestamp {
67		return make(map[int]int64), amount
68	}
69
70	endTimestamp := GetDistributionEndTimestamp()
71	if endTimestamp != 0 && timestamp > endTimestamp {
72		return make(map[int]int64), amount
73	}
74
75	return calculateDistributableAmounts(amount)
76}