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

3.06 Kb · 104 lines
  1package emission
  2
  3import (
  4	gnsmath "gno.land/p/gnoswap/gnsmath/v1"
  5)
  6
  7// GetLeftGNSAmount returns the amount of undistributed GNS tokens from previous distributions.
  8//
  9// Returns:
 10//   - amount: undistributed GNS amount
 11func GetLeftGNSAmount() int64 {
 12	return leftGNSAmount
 13}
 14
 15// GetDistributionStartTimestamp returns the configured emission start timestamp.
 16// The value may be in the future; it is 0 when no start timestamp is configured.
 17//
 18// Returns:
 19//   - timestamp: configured distribution start timestamp, or 0 if unconfigured
 20func GetDistributionStartTimestamp() int64 {
 21	return distributionStartTimestamp
 22}
 23
 24// GetLastExecutedTimestamp returns the timestamp of the last emission distribution execution.
 25//
 26// Returns:
 27//   - timestamp: last execution timestamp
 28func GetLastExecutedTimestamp() int64 {
 29	return lastExecutedTimestamp
 30}
 31
 32// GetAllDistributionBpsPct returns all distribution percentages in basis points.
 33//
 34// Returns:
 35//   - percentages: map of target to percentage in basis points
 36func GetAllDistributionBpsPct() map[int]int64 {
 37	result := make(map[int]int64, len(distributionBpsPct))
 38	if distributionBpsPct == nil {
 39		return result
 40	}
 41
 42	for target, pct := range distributionBpsPct {
 43		result[target] = pct
 44	}
 45
 46	return result
 47}
 48
 49// GetTotalAccuDistributed returns the total accumulated distributed GNS amount.
 50//
 51// Returns:
 52//   - amount: total accumulated distributed GNS
 53func GetTotalAccuDistributed() int64 {
 54	return gnsmath.SafeAddInt64(
 55		gnsmath.SafeAddInt64(accuDistributedToStaker, accuDistributedToDevOps),
 56		gnsmath.SafeAddInt64(accuDistributedToCommunityPool, accuDistributedToGovStaker),
 57	)
 58}
 59
 60// GetTotalDistributed returns the total pending distributed GNS amount.
 61//
 62// Returns:
 63//   - amount: total pending distributed GNS
 64func GetTotalDistributed() int64 {
 65	return gnsmath.SafeAddInt64(
 66		gnsmath.SafeAddInt64(distributedToStaker, distributedToDevOps),
 67		gnsmath.SafeAddInt64(distributedToCommunityPool, distributedToGovStaker),
 68	)
 69}
 70
 71// GetDistributionEndTimestamp returns the timestamp when emission distribution ends.
 72//
 73// Returns:
 74//   - timestamp: distribution end timestamp, or 0 if not started
 75func GetDistributionEndTimestamp() int64 {
 76	if distributionStartTimestamp == 0 {
 77		return 0
 78	}
 79
 80	return gnsmath.SafeAddInt64(distributionStartTimestamp, totalDistributionDuration-1)
 81}
 82
 83// GetDistributableAmount returns distribution amounts by target and the remainder.
 84// If timestamp is outside the distribution window, it returns an empty map and the full amount as left.
 85//
 86// Parameters:
 87//   - amount: total amount to distribute
 88//   - timestamp: timestamp to check distribution window
 89//
 90// Returns:
 91//   - distributions: map of target to distribution amount
 92//   - remainder: undistributed amount
 93func GetDistributableAmount(amount, timestamp int64) (map[int]int64, int64) {
 94	if distributionStartTimestamp == 0 || timestamp < distributionStartTimestamp {
 95		return make(map[int]int64), amount
 96	}
 97
 98	endTimestamp := GetDistributionEndTimestamp()
 99	if endTimestamp != 0 && timestamp > endTimestamp {
100		return make(map[int]int64), amount
101	}
102
103	return calculateDistributableAmounts(amount)
104}