getter.gno
6.65 Kb ยท 190 lines
1package gns
2
3import "time"
4
5// GetMaxEmissionAmount returns the maximum amount of emission allowed.
6func GetMaxEmissionAmount() int64 {
7 return MAX_EMISSION_AMOUNT
8}
9
10// GetMaximumSupply returns the maximum supply of gns tokens.
11func GetMaximumSupply() int64 {
12 return MAXIMUM_SUPPLY
13}
14
15// GetInitialMintAmount returns the initial amount of gns tokens to be minted.
16func GetInitialMintAmount() int64 {
17 return INITIAL_MINT_AMOUNT
18}
19
20// IsEmissionInitialized returns true if emission schedule has been initialized.
21func IsEmissionInitialized() bool {
22 return getEmissionState().isInitialized()
23}
24
25// IsEmissionActive returns true if emission is currently active based on current time.
26func IsEmissionActive() bool {
27 return getEmissionState().isActive(time.Now().Unix())
28}
29
30// IsEmissionEnded returns true if emission schedule has completed.
31func IsEmissionEnded() bool {
32 return getEmissionState().isEnded(time.Now().Unix())
33}
34
35// GetHalvingYear returns the halving year (1-12) for a given timestamp.
36func GetHalvingYear(timestamp int64) int64 {
37 return getEmissionState().getCurrentYear(timestamp)
38}
39
40// GetCurrentYear returns the current halving year (1-12) or 0 if emission is not active.
41func GetCurrentYear() int64 {
42 return getEmissionState().getCurrentYear(time.Now().Unix())
43}
44
45// GetEmissionAmountPerSecondInRange returns halving timestamps and emission rates for the given time range.
46// Returns two slices: timestamps when halving periods start and corresponding emission rates per second.
47func GetEmissionAmountPerSecondInRange(fromTime, toTime int64) ([]int64, []int64) {
48 halvingData := getEmissionState().getHalvingData()
49 halvingTimes := make([]int64, 0, HALVING_END_YEAR)
50 halvingEmissions := make([]int64, 0, HALVING_END_YEAR)
51
52 for year := HALVING_START_YEAR; year <= HALVING_END_YEAR; year++ {
53 startTimestamp := halvingData.getStartTimestamp(year)
54 if startTimestamp < fromTime {
55 continue
56 }
57
58 if toTime < startTimestamp {
59 break
60 }
61
62 halvingTimes = append(halvingTimes, startTimestamp)
63 halvingEmissions = append(halvingEmissions, halvingData.getAmountPerSecond(year))
64 }
65
66 return halvingTimes, halvingEmissions
67}
68
69// GetEmissionAmountPerSecondByTimestamp returns the emission rate per second for a given timestamp.
70// Returns 0 if timestamp is outside emission period.
71func GetEmissionAmountPerSecondByTimestamp(timestamp int64) int64 {
72 state := getEmissionState()
73 year := state.getCurrentYear(timestamp)
74 return state.getHalvingYearAmountPerSecond(year)
75}
76
77// GetEmissionLeftAmountByTimestamp returns the remaining emission amount for the halving year at given timestamp.
78// Returns 0 if timestamp is outside emission period.
79func GetEmissionLeftAmountByTimestamp(timestamp int64) int64 {
80 state := getEmissionState()
81 year := state.getCurrentYear(timestamp)
82 return state.getHalvingYearLeftAmount(year)
83}
84
85// GetEmissionAccumulatedAmountByTimestamp returns the accumulated emission amount for the halving year at given timestamp.
86// Returns 0 if timestamp is outside emission period.
87func GetEmissionAccumulatedAmountByTimestamp(timestamp int64) int64 {
88 state := getEmissionState()
89 year := state.getCurrentYear(timestamp)
90 return state.getHalvingYearAccumulatedAmount(year)
91}
92
93// GetHalvingYearStartTimestamp returns the start timestamp for the specified halving year.
94func GetHalvingYearStartTimestamp(year int64) int64 {
95 halvingData := getEmissionState().getHalvingData()
96 return halvingData.getStartTimestamp(year)
97}
98
99// GetHalvingYearEndTimestamp returns the end timestamp for the specified halving year.
100func GetHalvingYearEndTimestamp(year int64) int64 {
101 halvingData := getEmissionState().getHalvingData()
102 return halvingData.getEndTimestamp(year)
103}
104
105// GetHalvingYearMaxAmount returns the maximum token issuance for the specified halving year.
106func GetHalvingYearMaxAmount(year int64) int64 {
107 halvingData := getEmissionState().getHalvingData()
108 return halvingData.getMaxAmount(year)
109}
110
111// GetHalvingYearMintAmount returns the amount of tokens minted for the specified halving year.
112func GetHalvingYearMintAmount(year int64) int64 {
113 halvingData := getEmissionState().getHalvingData()
114 return halvingData.getMintedAmount(year)
115}
116
117// GetHalvingYearLeftAmount returns the remaining token issuance for the specified halving year.
118func GetHalvingYearLeftAmount(year int64) int64 {
119 halvingData := getEmissionState().getHalvingData()
120 return halvingData.getLeftAmount(year)
121}
122
123// GetHalvingYearAccuAmount returns the accumulated token issuance for the specified halving year.
124func GetHalvingYearAccuAmount(year int64) int64 {
125 halvingData := getEmissionState().getHalvingData()
126 return halvingData.getAccumAmount(year)
127}
128
129// GetAmountPerSecondPerHalvingYear returns the emission rate per second for the specified halving year.
130func GetAmountPerSecondPerHalvingYear(year int64) int64 {
131 halvingData := getEmissionState().getHalvingData()
132 return halvingData.getAmountPerSecond(year)
133}
134
135// GetHalvingAmountsPerYear returns the total emission amount allocated for the specified year.
136// Returns 0 if year is outside the valid range (1-12).
137func GetHalvingAmountsPerYear(year int64) int64 {
138 if validYear(year) != nil {
139 return 0
140 }
141 return halvingAmountsPerYear[year-1]
142}
143
144// GetEmissionCreatedHeight returns the block height when emission schedule was created.
145func GetEmissionCreatedHeight() int64 {
146 return getEmissionState().getCreatedHeight()
147}
148
149// GetEmissionStartTimestamp returns the timestamp when emission schedule begins.
150func GetEmissionStartTimestamp() int64 {
151 return getEmissionState().getStartTimestamp()
152}
153
154// GetEmissionEndTimestamp returns the timestamp when emission schedule ends.
155func GetEmissionEndTimestamp() int64 {
156 return getEmissionState().getEndTimestamp()
157}
158
159// GetHalvingYearInfo returns the halving year, start timestamp, and end timestamp for a given timestamp.
160// Returns (year, startTimestamp, endTimestamp). Year is 0 if outside emission period.
161func GetHalvingYearInfo(timestamp int64) (int64, int64, int64) {
162 state := getEmissionState()
163 year := state.getCurrentYear(timestamp)
164
165 // If outside emission period, return 0 values
166 if year == 0 {
167 return 0, 0, 0
168 }
169
170 // Use cached timestamps from HalvingData
171 halvingData := state.getHalvingData()
172 return year, halvingData.getStartTimestamp(year), halvingData.getEndTimestamp(year)
173}
174
175// GetHalvingInfo returns a clone of the halving data.
176func GetHalvingInfo() *HalvingData {
177 return getEmissionState().getHalvingData().Clone()
178}
179
180// CalculateMintGnsAmount returns the amount of GNS that would be minted for the given timestamp range.
181func CalculateMintGnsAmount(fromTimestamp, toTimestamp int64) int64 {
182 state := getEmissionState().Clone()
183
184 amountToMint, err := calculateAmountToMint(state, fromTimestamp, toTimestamp)
185 if err != nil {
186 return 0
187 }
188
189 return amountToMint
190}