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

getters.gno

10.76 Kb · 259 lines
  1package staker
  2
  3import (
  4	u256 "gno.land/p/gnoswap/uint256/v1"
  5	rotree "gno.land/p/nt/bptree/rotree/v0"
  6)
  7
  8// GetTotalxGnsSupply returns total xGNS supply, including launchpad-held xGNS.
  9// Returns:
 10//   - int64: total xGNS supply, including xGNS held by launchpad projects.
 11func GetTotalxGnsSupply() int64 {
 12	return getImplementation().GetTotalxGnsSupply()
 13}
 14
 15// GetTotalDelegated returns the total amount of GNS delegated.
 16// Returns:
 17//   - int64: total GNS amount delegated across all delegators.
 18func GetTotalDelegated() int64 {
 19	return getImplementation().GetTotalDelegated()
 20}
 21
 22// GetTotalLockedAmount returns the total amount of GNS locked in undelegation.
 23// Returns:
 24//   - int64: total GNS amount currently locked in undelegation withdrawals.
 25func GetTotalLockedAmount() int64 {
 26	return getImplementation().GetTotalLockedAmount()
 27}
 28
 29// GetUnDelegationLockupPeriod returns the undelegation lockup period in seconds.
 30// Returns:
 31//   - int64: configured undelegation lockup duration in seconds.
 32func GetUnDelegationLockupPeriod() int64 {
 33	return getImplementation().GetUnDelegationLockupPeriod()
 34}
 35
 36// GetDelegations returns a read-only view of every delegation, keyed by the
 37// decimal string form of the delegation ID. Callers paginate it themselves
 38// through IterateByOffset. Reading an entry yields a clone, so the view cannot
 39// mutate realm state.
 40// Returns:
 41//   - *rotree.ReadOnlyTree: read-only delegation view keyed by decimal delegation ID; entry reads return clones.
 42func GetDelegations() *rotree.ReadOnlyTree {
 43	return getImplementation().GetDelegations()
 44}
 45
 46// ExistsDelegation checks if a delegation exists.
 47// Parameters:
 48//   - delegationID: Numeric identifier of the delegation to look up.
 49//
 50// Returns:
 51//   - bool: true when a delegation with delegationID exists, false otherwise.
 52func ExistsDelegation(delegationID int64) bool {
 53	return getImplementation().ExistsDelegation(delegationID)
 54}
 55
 56// GetDelegatorDelegations returns a read-only view of a delegator's delegations,
 57// keyed by delegatee address with that pair's delegation IDs as the value.
 58// Reading an entry yields a copy of the ID slice, so the view cannot mutate
 59// realm state. nil is returned when the delegator has no delegations.
 60// Parameters:
 61//   - delegator: Address whose delegations should be listed.
 62//
 63// Returns:
 64//   - *rotree.ReadOnlyTree: read-only view keyed by delegatee address, or nil when delegator has no delegations.
 65func GetDelegatorDelegations(delegator address) *rotree.ReadOnlyTree {
 66	return getImplementation().GetDelegatorDelegations(delegator)
 67}
 68
 69// GetUserDelegationIDs returns a list of delegation IDs for a specific delegator-delegatee pair.
 70// Parameters:
 71//   - delegator: Address that supplied the delegation.
 72//   - delegatee: Address receiving that delegation.
 73//
 74// Returns:
 75//   - []int64: delegation IDs for the delegator-delegatee pair; the returned slice is independent of realm state.
 76func GetUserDelegationIDs(delegator address, delegatee address) []int64 {
 77	return cloneInt64Slice(getImplementation().GetUserDelegationIDs(delegator, delegatee))
 78}
 79
 80// HasDelegationSnapshotsKey returns true if delegation history exists.
 81// Returns:
 82//   - bool: true when delegation history has been initialized in storage.
 83func HasDelegationSnapshotsKey() bool {
 84	return getImplementation().HasDelegationSnapshotsKey()
 85}
 86
 87// GetTotalDelegationAmountAtSnapshot returns total delegation at a Unix
 88// timestamp, using the latest history entry at or before that timestamp.
 89// The lookup is timestamp-based rather than a block-height snapshot.
 90// Parameters:
 91//   - snapshotTime: Unix timestamp at or before which to select the latest aggregate delegation history entry.
 92//
 93// Returns:
 94//   - int64: aggregate delegated amount recorded at or before snapshotTime.
 95//   - bool: true when a qualifying history entry exists; false when no entry is available.
 96func GetTotalDelegationAmountAtSnapshot(snapshotTime int64) (int64, bool) {
 97	return getImplementation().GetTotalDelegationAmountAtSnapshot(snapshotTime)
 98}
 99
100// GetUserDelegationAmountAtSnapshot returns one user's delegation at a Unix
101// timestamp, using that user's latest history entry at or before the timestamp.
102// The bool is false when no qualifying history entry exists.
103// Parameters:
104//   - userAddr: Delegator address whose historical delegation is queried.
105//   - snapshotTime: Unix timestamp at or before which to select the user's latest history entry.
106//
107// Returns:
108//   - int64: user's delegated amount recorded at or before snapshotTime.
109//   - bool: true when a qualifying user-history entry exists; false otherwise.
110func GetUserDelegationAmountAtSnapshot(userAddr address, snapshotTime int64) (int64, bool) {
111	return getImplementation().GetUserDelegationAmountAtSnapshot(userAddr, snapshotTime)
112}
113
114// GetClaimableRewardByAddress returns claimable rewards for an address.
115//
116// Parameters:
117//   - addr: Address whose emission and protocol-fee rewards are queried.
118//
119// Returns:
120//   - int64: emission reward amount available to addr.
121//   - map[string]int64: protocol-fee reward amounts keyed by token path.
122//   - error: nil on success; non-nil when reward state cannot be resolved for addr.
123func GetClaimableRewardByAddress(addr address) (int64, map[string]int64, error) {
124	emissionReward, protocolFees, err := getImplementation().GetClaimableRewardByAddress(addr)
125	if err != nil {
126		return 0, nil, err
127	}
128	return emissionReward, cloneStringInt64Map(protocolFees), nil
129}
130
131// GetClaimableRewardByLaunchpad returns claimable launchpad rewards for an address.
132//
133// Parameters:
134//   - addr: Address whose launchpad and protocol-fee rewards are queried.
135//
136// Returns:
137//   - int64: emission reward amount available to addr.
138//   - map[string]int64: protocol-fee reward amounts keyed by token path.
139//   - error: nil on success; non-nil when reward state cannot be resolved for addr.
140func GetClaimableRewardByLaunchpad(addr address) (int64, map[string]int64, error) {
141	emissionReward, protocolFees, err := getImplementation().GetClaimableRewardByLaunchpad(addr)
142	if err != nil {
143		return 0, nil, err
144	}
145	return emissionReward, cloneStringInt64Map(protocolFees), nil
146}
147
148// GetClaimableRewardByRewardID returns claimable reward details by reward ID.
149//
150// Parameters:
151//   - rewardID: Reward-state identifier whose claimable rewards are queried.
152//
153// Returns:
154//   - int64: emission reward amount associated with rewardID.
155//   - map[string]int64: protocol-fee reward amounts keyed by token path.
156//   - error: nil on success; non-nil when rewardID cannot be resolved.
157func GetClaimableRewardByRewardID(rewardID string) (int64, map[string]int64, error) {
158	emissionReward, protocolFees, err := getImplementation().GetClaimableRewardByRewardID(rewardID)
159	if err != nil {
160		return 0, nil, err
161	}
162	return emissionReward, cloneStringInt64Map(protocolFees), nil
163}
164
165// GetLaunchpadProjectDeposit returns the deposit amount for a launchpad project.
166// Parameters:
167//   - projectAddr: Launchpad project address whose deposited amount is queried.
168//
169// Returns:
170//   - int64: recorded launchpad project deposit amount.
171//   - bool: true when a deposit record exists for projectAddr; false otherwise.
172func GetLaunchpadProjectDeposit(projectAddr string) (int64, bool) {
173	return getImplementation().GetLaunchpadProjectDeposit(projectAddr)
174}
175
176// GetDelegationWithdrawCount returns the total number of delegation withdraws for a specific delegation.
177// Parameters:
178//   - delegationID: Identifier of the delegation whose withdrawals are counted.
179//
180// Returns:
181//   - int: number of withdrawal records associated with delegationID.
182func GetDelegationWithdrawCount(delegationID int64) int {
183	return getImplementation().GetDelegationWithdrawCount(delegationID)
184}
185
186// GetDelegationWithdraws returns a paginated list of delegation withdraws for a specific delegation.
187// Parameters:
188//   - delegationID: Identifier of the delegation whose withdrawals are requested.
189//   - offset: Number of matching withdrawal records to skip before collecting results.
190//   - count: Maximum number of withdrawal records to return.
191//
192// Returns:
193//   - []DelegationWithdraw: requested page of withdrawal records, copied before returning.
194//   - error: nil on success; non-nil when the requested delegation or page cannot be read.
195func GetDelegationWithdraws(delegationID int64, offset, count int) ([]DelegationWithdraw, error) {
196	withdraws, err := getImplementation().GetDelegationWithdraws(delegationID, offset, count)
197	if err != nil {
198		return nil, err
199	}
200	return cloneDelegationWithdraws(withdraws), nil
201}
202
203// GetCollectableWithdrawAmount returns the collectable withdraw amount for a specific delegation.
204// Parameters:
205//   - delegationID: Identifier of the delegation whose collectable amount is queried.
206//
207// Returns:
208//   - int64: amount currently available to collect from delegationID.
209func GetCollectableWithdrawAmount(delegationID int64) int64 {
210	return getImplementation().GetCollectableWithdrawAmount(delegationID)
211}
212
213// GetProtocolFeeAccumulatedX128PerStake returns the accumulated protocol fee per stake (Q128) for a token path.
214// Parameters:
215//   - tokenPath: Registered token path whose protocol-fee accumulator is queried.
216//
217// Returns:
218//   - *u256.Uint: accumulated protocol-fee amount per unit stake in Q128 fixed-point form.
219func GetProtocolFeeAccumulatedX128PerStake(tokenPath string) *u256.Uint {
220	return getImplementation().GetProtocolFeeAccumulatedX128PerStake(tokenPath).Clone()
221}
222
223// GetProtocolFeeAmount returns the protocol fee amounts for a token path.
224// Parameters:
225//   - tokenPath: Registered token path whose protocol fees are queried.
226//
227// Returns:
228//   - int64: accumulated protocol-fee amount for tokenPath in token base units.
229func GetProtocolFeeAmount(tokenPath string) int64 {
230	return getImplementation().GetProtocolFeeAmount(tokenPath)
231}
232
233// GetProtocolFeeAccumulatedTimestamp returns the accumulated timestamp for protocol fee rewards.
234// Returns:
235//   - int64: Unix timestamp at which protocol-fee accumulation was last updated.
236func GetProtocolFeeAccumulatedTimestamp() int64 {
237	return getImplementation().GetProtocolFeeAccumulatedTimestamp()
238}
239
240// GetEmissionAccumulatedX128PerStake returns the accumulated emission per stake (Q128).
241// Returns:
242//   - *u256.Uint: accumulated emission reward per unit stake in Q128 fixed-point form.
243func GetEmissionAccumulatedX128PerStake() *u256.Uint {
244	return getImplementation().GetEmissionAccumulatedX128PerStake().Clone()
245}
246
247// GetEmissionDistributedAmount returns the total distributed emission amount.
248// Returns:
249//   - int64: total emission amount distributed to stakers.
250func GetEmissionDistributedAmount() int64 {
251	return getImplementation().GetEmissionDistributedAmount()
252}
253
254// GetEmissionAccumulatedTimestamp returns the accumulated timestamp for emission rewards.
255// Returns:
256//   - int64: Unix timestamp at which emission accumulation was last updated.
257func GetEmissionAccumulatedTimestamp() int64 {
258	return getImplementation().GetEmissionAccumulatedTimestamp()
259}