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

staker source realm

Readme View source

Staker

Liquidity mining and reward distribution for LP positions.

Overview

Staker manages distribution of internal (GNS emission) and external (user-provided) rewards to staked LP positions, with time-weighted rewards and warmup periods.

Configuration

  • Deposit GNS Amount: 1,000 GNS for external incentives (default)
  • Minimum Reward Amount: 1,000 tokens (default)
  • Unstaking Fee: 1% (default)
  • Pool Tiers: 1, 2, or 3 (assigned per pool)
  • Warmup Schedule: 30/50/70/100% over 30/60/90 days
  • External Token Whitelist: Approved reward tokens

Core Features

Internal Rewards (GNS Emission)

  • Allocated to tiered pools (tiers 1, 2, 3)
  • Split across tiers by TierRatio
  • Distributed proportionally to in-range liquidity
  • Unclaimed rewards go to community pool

External Rewards (User Incentives)

  • Created for specific pools
  • Constant reward per block
  • Proportional to staked liquidity
  • Unclaimed rewards returned to creator

Warmup Periods

Every staked position progresses through warmup periods:

  • 0-30 days: 30% rewards (70% to community/creator)
  • 30-60 days: 50% rewards (50% to community/creator)
  • 60-90 days: 70% rewards (30% to community/creator)
  • 90+ days: 100% rewards

Key Functions

StakeToken

Stakes LP position NFT to earn rewards.

UnStakeToken

Unstakes position and collects all rewards.

CollectReward

Collects accumulated rewards without unstaking.

CreateExternalIncentive

Creates external reward program for specific pool.

EndExternalIncentive

Ends incentive program and returns unused rewards.

Reward Calculation Logic

Tier Ratio Distribution

Emission split across tiers based on active pools:

If only tier 1 has pools:    [100%, 0%, 0%]
If tiers 1 & 3 have pools:   [80%, 0%, 20%]
If tiers 1 & 2 have pools:   [70%, 30%, 0%]
If all tiers have pools:     [50%, 30%, 20%]

Mathematical representation:

TierRatio(t) =
  [1, 0, 0]        if Count(2) = 0 ∧ Count(3) = 0
  [0.8, 0, 0.2]    if Count(2) = 0
  [0.7, 0.3, 0]    if Count(3) = 0
  [0.5, 0.3, 0.2]  otherwise

Pool Reward Formula

poolReward(pool) = (emission × TierRatio[tier(pool)]) / Count(tier(pool))

Where emission is calculated as:

emission = GNSEmissionPerSecond × (avgMsPerBlock/1000) × StakerEmissionRatio

Position Reward Calculation

The reward for each position is calculated through:

  1. Cache pool rewards up to current block
  2. Retrieve position state from deposit records
  3. Calculate internal rewards if pool is tiered
  4. Calculate external rewards for active incentives
  5. Apply warmup penalties based on stake duration

Mathematical formula for total reward ratio:

TotalRewardRatio(s,e) = Σ[i=0 to m-1] ΔRaw(αᵢ, βᵢ) × rᵢ

where:
  αᵢ = max(s, Hᵢ₋₁)
  βᵢ = min(e, Hᵢ)

ΔRaw(a, b) = CalcRaw(b) - CalcRaw(a)

CalcRaw(h) =
  L(h) - U(h)           if tick(h) < ℓ
  U(h) - L(h)           if tick(h) ≥ u
  G(h) - (L(h) + U(h))  otherwise

where:
  L(h) = tickLower.OutsideAccumulation(h)
  U(h) = tickUpper.OutsideAccumulation(h)
  G(h) = globalRewardRatioAccumulation(h)
  ℓ = tickLower.id
  u = tickUpper.id

Final position reward:

finalReward = TotalRewardRatio × poolReward × positionLiquidity
            = ∫[s to e] (poolReward × positionLiquidity) / TotalStakedLiquidity(h) dh

Tick Cross Hook

When price crosses an initialized tick with staked positions:

  1. Updates staked liquidity - Adjusts total staked liquidity
  2. Updates reward accumulation - Recalculates globalRewardRatioAccumulation
  3. Manages unclaimable periods - Starts/ends periods with no in-range liquidity
  4. Updates tick accumulation - Adjusts CurrentOutsideAccumulation

The globalRewardRatioAccumulation tracks the integral:

globalRewardRatioAccumulation = ∫ 1/TotalStakedLiquidity(h) dh

This integral is only computed when TotalStakedLiquidity(h) ≠ 0, enabling precise reward calculation even as liquidity changes.

Reward State Tracking

The system maintains:

  • Global accumulation: Tracks reward ratio across all positions
  • Tick accumulation: Tracks rewards "outside" each tick
  • Position state: Individual reward calculation parameters

Usage

 1// Stake existing position
 2StakeToken(123, "g1referrer...")
 3
 4// Create external incentive
 5CreateExternalIncentive(
 6    "gno.land/r/demo/bar:gno.land/r/demo/baz:3000",
 7    "gno.land/r/demo/reward",
 8    "1000000000",  // 1000 tokens
 9    startTime,
10    endTime,
11)
12
13// Collect rewards without unstaking
14CollectReward(123)
15
16// Unstake and collect all rewards
17UnStakeToken(123)

Security

  • Positions locked during staking
  • External incentives require GNS deposit
  • Warmup periods prevent gaming
  • Unclaimed rewards properly redirected
  • Hook integration ensures accurate tracking

Constants 3

const StoreKeyUnDelegationLockupPeriod, StoreKeyTotalDelegatedAmount, StoreKeyTotalLockedAmount, StoreKeyDelegationNextID, StoreKeyDelegations, StoreKeyTotalDelegationHistory, StoreKeyUserDelegationHistory, StoreKeyEmissionRewardManager, StoreKeyProtocolFeeRewardManager, StoreKeyDelegationManager, StoreKeyLaunchpadProjectDeposits

 1const (
 2	// Basic configuration
 3	StoreKeyUnDelegationLockupPeriod = "unDelegationLockupPeriod"
 4	StoreKeyTotalDelegatedAmount     = "totalDelegatedAmount"
 5	StoreKeyTotalLockedAmount        = "totalLockedAmount"
 6
 7	// Counters
 8	StoreKeyDelegationNextID = "delegationNextID"
 9
10	// Complex data structures
11	StoreKeyDelegations            = "delegations"            // BPTree of delegations
12	StoreKeyTotalDelegationHistory = "totalDelegationHistory" // UintTree: timestamp -> int64 (cumulative total)
13	StoreKeyUserDelegationHistory  = "userDelegationHistory"  // BPTree: address -> *UintTree[timestamp -> int64]
14
15	// Manager states
16	StoreKeyEmissionRewardManager    = "emissionRewardManager"
17	StoreKeyProtocolFeeRewardManager = "protocolFeeRewardManager"
18	StoreKeyDelegationManager        = "delegationManager"
19	StoreKeyLaunchpadProjectDeposits = "launchpadProjectDeposits"
20)
source

Storage key constants

const ErrSpoofedRealm

1const ErrSpoofedRealm = "rlm does not match the current crossing frame"
source

ErrSpoofedRealm is returned by store Set* methods when the supplied realm token does not match the current crossing frame (rlm.IsCurrent() is false), rejecting spoofed or stale realm tokens before any write is performed.

Functions 61

func CleanStakerDelegationSnapshotByAdmin

crossing Action
1func CleanStakerDelegationSnapshotByAdmin(cur realm, threshold int64, target address)
source

CleanStakerDelegationSnapshotByAdmin removes old delegation snapshots for the total history and the user history of a single target address. Only callable by admin.

Parameters:

  • threshold: timestamp threshold for cleanup
  • target: user address whose delegation history to clean

func CollectEmissionRewardFromLaunchPad

crossing Action
1func CollectEmissionRewardFromLaunchPad(cur realm, to address)
source

CollectEmissionRewardFromLaunchPad claims accumulated launchpad emission rewards.

Parameters:

  • to: address to collect rewards for

func CollectProtocolFeeReward

crossing Action
1func CollectProtocolFeeReward(cur realm, tokenPath string)
source

CollectProtocolFeeReward claims accumulated protocol fee rewards for the provided token path.

func CollectProtocolFeeRewardFromLaunchPad

crossing Action
1func CollectProtocolFeeRewardFromLaunchPad(cur realm, to address, tokenPath string)
source

CollectProtocolFeeRewardFromLaunchPad claims accumulated launchpad protocol fee rewards for the provided token path.

Parameters:

  • to: address to collect rewards for
  • tokenPath: token path to collect

func CollectRewardFromLaunchPad

crossing Action
1func CollectRewardFromLaunchPad(cur realm, to address)
source

CollectRewardFromLaunchPad claims rewards from launchpad projects.

Parameters:

  • to: address to collect rewards for

func CollectUndelegatedGns

crossing Action
1func CollectUndelegatedGns(cur realm) int64
source

CollectUndelegatedGns collects GNS tokens after the undelegation lockup period.

Returns:

  • int64: amount of GNS collected

func DecodeUint

Action
1func DecodeUint(s string) uint64
source

DecodeUint converts a zero-padded string back into a uint64 number.

Parameters: - s (string): The zero-padded string.

Returns: - uint64: The decoded number.

Panics: - If the string cannot be parsed into a uint64.

Example: Input: "00000000000000012345" Output: 12345

func Delegate

crossing Action
1func Delegate(cur realm, to address, amount int64, referrer string) int64
source

Delegate stakes GNS tokens to a delegatee address.

Parameters:

  • to: address to delegate to
  • amount: amount of GNS to delegate
  • referrer: referrer address for reward tracking

Returns:

  • int64: delegation ID

func EncodeUint

Action
1func EncodeUint(num uint64) string
source

EncodeUint converts a uint64 number into a zero-padded 20-character string.

Parameters: - num (uint64): The number to encode.

Returns: - string: A zero-padded string representation of the number.

Example: Input: 12345 Output: "00000000000000012345"

func GetClaimableRewardByAddress

Action
1func GetClaimableRewardByAddress(addr address) (int64, map[string]int64, error)
source

GetClaimableRewardByAddress returns claimable rewards for an address.

Returns:

  • int64: emission reward amount
  • map[string]int64: protocol fee rewards by token path

func GetClaimableRewardByLaunchpad

Action
1func GetClaimableRewardByLaunchpad(addr address) (int64, map[string]int64, error)
source

GetClaimableRewardByLaunchpad returns claimable launchpad rewards for an address.

Returns:

  • int64: emission reward amount
  • map[string]int64: protocol fee rewards by token path

func GetClaimableRewardByRewardID

Action
1func GetClaimableRewardByRewardID(rewardID string) (int64, map[string]int64, error)
source

GetClaimableRewardByRewardID returns claimable reward details by reward ID.

Returns:

  • int64: emission reward amount
  • map[string]int64: protocol fee rewards by token path

func GetDelegationWithdrawCount

Action
1func GetDelegationWithdrawCount(delegationID int64) int
source

GetDelegationWithdrawCount returns the total number of delegation withdraws for a specific delegation.

func GetUserDelegationAmountAtSnapshot

Action
1func GetUserDelegationAmountAtSnapshot(userAddr address, snapshotTime int64) (int64, bool)
source

GetUserDelegationAmountAtSnapshot returns the user delegation amount at a specific snapshot time.

func GetUserDelegationCount

Action
1func GetUserDelegationCount(delegator address, delegatee address) int
source

GetUserDelegationCount returns the number of delegations for a specific delegator-delegatee pair.

func GetUserDelegationIDs

Action
1func GetUserDelegationIDs(delegator address, delegatee address) []int64
source

GetUserDelegationIDs returns a list of delegation IDs for a specific delegator-delegatee pair.

func Redelegate

crossing Action
1func Redelegate(cur realm, delegatee, newDelegatee address, amount int64) int64
source

Redelegate moves delegation from one delegatee to another.

Parameters:

  • delegatee: current delegatee address
  • newDelegatee: new delegatee address
  • amount: amount to redelegate

Returns:

  • int64: redelegation result code

func RegisterInitializer

crossing Action
1func RegisterInitializer(cur realm, initializer func(_ int, rlm realm, govStakerStore IGovStakerStore) IGovStaker)
source

RegisterInitializer registers an implementation. This function is called by each implementation version during init.

The initializer function creates a new instance of the implementation using the provided IGovStakerStore. It receives a realm value that resolves to the gov/staker proxy realm — the only address with write permission on the shared KV store — so any per-version store bootstrapping performed inside the initializer passes the proxy's authorization check.

func SetAmountByProjectWallet

crossing Action
1func SetAmountByProjectWallet(cur realm, addr address, amount int64, add bool)
source

SetAmountByProjectWallet sets reward amount for a project wallet. Only callable by launchpad contract.

Parameters:

  • addr: project wallet address
  • amount: reward amount
  • add: true to add, false to subtract

func SetUnDelegationLockupPeriodByAdmin

crossing Action
1func SetUnDelegationLockupPeriodByAdmin(cur realm, period int64)
source

SetUnDelegationLockupPeriodByAdmin sets the undelegation lockup period. Only callable by admin.

Parameters:

  • period: lockup period in seconds

func Undelegate

crossing Action
1func Undelegate(cur realm, from address, amount int64) int64
source

Undelegate initiates the undelegation process for staked GNS.

Parameters:

  • from: delegatee address to undelegate from
  • amount: amount of GNS to undelegate

Returns:

  • int64: undelegation result code

func UpgradeImpl

crossing Action
1func UpgradeImpl(cur realm, packagePath string)
source

UpgradeImpl upgrades the implementation to a new version Only admin or governance can call this function

func GetDelegation

Action
1func GetDelegation(delegationID int64) (*Delegation, error)
source

GetDelegation returns the delegation for the given ID.

func NewDelegation

Action
1func NewDelegation(
2	id int64,
3	delegateFrom, delegateTo address,
4	delegateAmount, createdHeight, createdAt int64,
5) *Delegation
source

NewDelegation creates a new delegation

func NewDelegationManager

Action
1func NewDelegationManager() *DelegationManager
source

NewDelegationManager creates a new instance of DelegationManager. This factory function initializes the BPTree structure for tracking user delegations.

func GetDelegationWithdraws

Action
1func GetDelegationWithdraws(delegationID int64, offset, count int) ([]DelegationWithdraw, error)
source

GetDelegationWithdraws returns a paginated list of delegation withdraws for a specific delegation.

func NewDelegationWithdraw

Action
1func NewDelegationWithdraw(
2	delegationID,
3	unDelegateAmount,
4	createdHeight,
5	createdAt,
6	unDelegationLockupPeriod int64,
7) DelegationWithdraw
source

NewDelegationWithdraw creates a new delegation withdrawal with lockup period. The withdrawal will be collectable after the lockup period expires.

Parameters:

  • delegationID: unique identifier of the associated delegation
  • unDelegateAmount: amount being withdrawn
  • createdAt: timestamp when the withdrawal was created
  • unDelegationLockupPeriod: duration of the lockup period in seconds

Returns:

  • *DelegationWithdraw: new withdrawal instance with lockup

func NewDelegationWithdrawWithoutLockup

Action
1func NewDelegationWithdrawWithoutLockup(
2	delegationID,
3	unDelegateAmount,
4	createdHeight,
5	createdAt int64,
6) DelegationWithdraw
source

NewDelegationWithdrawWithoutLockup creates a new delegation withdrawal that is immediately collectable. This is used for special cases like redelegation where no lockup period is required.

Parameters:

  • delegationID: unique identifier of the associated delegation
  • unDelegateAmount: amount being withdrawn
  • createdAt: timestamp when the withdrawal was created

Returns:

  • *DelegationWithdraw: new withdrawal instance that is immediately collected

func NewEmissionRewardManager

Action
1func NewEmissionRewardManager() *EmissionRewardManager
source

NewEmissionRewardManager creates a new instance of EmissionRewardManager. This factory function initializes all tracking structures for emission reward management. NewEmissionRewardManager creates new emission reward manager instance.

func NewEmissionRewardState

Action
1func NewEmissionRewardState(accumulatedRewardX128PerStake *u256.Uint) *EmissionRewardState
source

NewEmissionRewardState creates a new emission reward state for a staker. This factory function initializes the state with the current system reward debt.

Parameters:

  • accumulatedRewardX128PerStake: current system-wide accumulated reward per stake

Returns:

  • *EmissionRewardState: new emission reward state instance

func NewGovStakerStore

Action
1func NewGovStakerStore(kvStore store.KVStore) IGovStakerStore
source

NewGovStakerStore creates a new governance staker store instance

func NewProtocolFeeRewardManager

Action
1func NewProtocolFeeRewardManager() *ProtocolFeeRewardManager
source

NewProtocolFeeRewardManager creates a new instance of ProtocolFeeRewardManager. This factory function initializes all tracking structures for multi-token protocol fee reward management.

Returns:

  • *ProtocolFeeRewardManager: new protocol fee reward manager instance

func NewProtocolFeeRewardState

Action
1func NewProtocolFeeRewardState(accumulatedProtocolFeeX128PerStake map[string]*u256.Uint) *ProtocolFeeRewardState
source

NewProtocolFeeRewardState creates a new protocol fee reward state for a staker. This factory function initializes the state with the current system reward debt for all tokens.

Types 17

type Counter

struct
1type Counter struct {
2	id int64
3}
source

Methods on Counter

func Get

method on Counter
1func (c *Counter) Get() int64
source

func Next

method on Counter
1func (c *Counter) Next() int64
source

type Delegation

struct
 1type Delegation struct {
 2	id               int64
 3	delegateAmount   int64
 4	unDelegateAmount int64
 5	collectedAmount  int64
 6	delegateFrom     address
 7	delegateTo       address
 8	createdHeight    int64
 9	createdAt        int64
10	withdraws        []DelegationWithdraw
11}
source

Delegation represents a delegation between two addresses

Methods on Delegation

func AddWithdraw

method on Delegation
1func (d *Delegation) AddWithdraw(withdraw DelegationWithdraw)
source

func Clone

method on Delegation
1func (d *Delegation) Clone() *Delegation
source

Clone creates a deep copy of the delegation.

func CreatedAt

method on Delegation
1func (d *Delegation) CreatedAt() int64
source

func DelegateFrom

method on Delegation
1func (d *Delegation) DelegateFrom() address
source

func DelegateTo

method on Delegation
1func (d *Delegation) DelegateTo() address
source

func ID

method on Delegation
1func (d *Delegation) ID() int64
source

Basic getters

func SetWithdraw

method on Delegation
1func (d *Delegation) SetWithdraw(index int, withdraw DelegationWithdraw)
source

func SetWithdraws

method on Delegation
1func (d *Delegation) SetWithdraws(withdraws []DelegationWithdraw)
source

func Withdraws

method on Delegation
1func (d *Delegation) Withdraws() []DelegationWithdraw
source

Withdraws getters

type DelegationManager

struct
1type DelegationManager struct {
2	// userDelegations maps delegator address -> *bptree.BPTree (delegatee address -> list of delegation IDs)
3	// Using BPTree instead of map to handle unbounded growth of delegators efficiently
4	userDelegations *bptree.BPTree
5}
source

DelegationManager manages the mapping between users and their delegation IDs. It provides efficient lookup and management of user delegations organized by delegator and delegatee addresses.

Methods on DelegationManager

func AddDelegationID

method on DelegationManager
1func (dm *DelegationManager) AddDelegationID(delegator, delegatee string, delegationID int64)
source

AddDelegationID appends a delegation ID to the delegator-delegatee pair, skipping duplicates. The whole get-modify-set runs inside this domain method so the nested BPTree mutation never escapes the owning realm. Performing the lookup in one realm and the write in another (e.g. re-fetching the inner tree across a realm boundary and mutating it) would hit the cross-realm write guard for the persisted leaf slot.

func GetDelegationIDs

method on DelegationManager
1func (dm *DelegationManager) GetDelegationIDs(delegator, delegatee string) ([]int64, bool)
source

GetDelegationIDs returns all delegation IDs for a specific delegator-delegatee pair.

func GetDelegatorDelegations

method on DelegationManager
1func (dm *DelegationManager) GetDelegatorDelegations(delegator string) (*bptree.BPTree, bool)
source

GetDelegatorDelegations returns all delegations for a specific delegator.

func GetUserDelegations

method on DelegationManager
1func (dm *DelegationManager) GetUserDelegations() *bptree.BPTree
source

GetUserDelegations returns the entire user delegations tree.

func RemoveDelegationID

method on DelegationManager
1func (dm *DelegationManager) RemoveDelegationID(delegator, delegatee string, delegationID int64)
source

RemoveDelegationID removes a delegation ID from the delegator-delegatee pair. Like AddDelegationID, the read-modify-write is kept inside this domain method.

func SetDelegationIDs

method on DelegationManager
1func (dm *DelegationManager) SetDelegationIDs(delegator, delegatee string, ids []int64)
source

SetDelegationIDs sets delegation IDs for a specific delegator-delegatee pair.

func SetUserDelegations

method on DelegationManager
1func (dm *DelegationManager) SetUserDelegations(userDelegations *bptree.BPTree)
source

SetUserDelegations sets the entire user delegations tree.

type DelegationType

ident
1type DelegationType string
source

DelegationType represents the type of delegation operation

Methods on DelegationType

func IsDelegate

method on DelegationType
1func (d DelegationType) IsDelegate() bool
source

func IsUnDelegate

method on DelegationType
1func (d DelegationType) IsUnDelegate() bool
source

func String

method on DelegationType
1func (d DelegationType) String() string
source

type DelegationWithdraw

struct
 1type DelegationWithdraw struct {
 2	// delegationID is the unique identifier of the associated delegation
 3	delegationID int64
 4	// unDelegateAmount is the total amount that was undelegated
 5	unDelegateAmount int64
 6	// unDelegatedHeight is the height when the undelegation occurred
 7	unDelegatedHeight int64
 8	// unDelegatedAt is the timestamp when the undelegation occurred
 9	unDelegatedAt int64
10	// collectedAmount is the amount that has already been collected
11	collectedAmount int64
12	// collectableTime is the timestamp when collection becomes available
13	collectableTime int64
14	// collectedAt is the timestamp when collection occurred
15	collectedAt int64
16	// collected indicates whether the withdrawal has been fully collected
17	collected bool
18}
source

DelegationWithdraw represents a pending withdrawal from a delegation. This struct tracks undelegated amounts that are subject to lockup periods and manages the collection process once the lockup period expires.

Methods on DelegationWithdraw

func Clone

method on DelegationWithdraw
1func (d *DelegationWithdraw) Clone() DelegationWithdraw
source

Clone creates a deep copy of the delegation withdraw.

func CollectableTime

method on DelegationWithdraw
1func (d *DelegationWithdraw) CollectableTime() int64
source

CollectableTime returns the timestamp when collection becomes available.

Returns:

  • int64: collectable time

func CollectedAmount

method on DelegationWithdraw
1func (d *DelegationWithdraw) CollectedAmount() int64
source

CollectedAmount returns the amount that has already been collected.

Returns:

  • int64: collected amount

func CollectedAt

method on DelegationWithdraw
1func (d *DelegationWithdraw) CollectedAt() int64
source

CollectedAt returns the timestamp when collection occurred.

Returns:

  • int64: collection timestamp

func DelegationID

method on DelegationWithdraw
1func (d *DelegationWithdraw) DelegationID() int64
source

DelegationID returns the unique identifier of the associated delegation.

Returns:

  • int64: delegation ID

func IsCollected

method on DelegationWithdraw
1func (d *DelegationWithdraw) IsCollected() bool
source

IsCollected returns whether the withdrawal has been fully collected.

Returns:

  • bool: true if fully collected, false otherwise

func SetCollected

method on DelegationWithdraw
1func (d *DelegationWithdraw) SetCollected(collected bool)
source

SetCollected sets the collected status.

Parameters:

  • collected: new collected status

func SetCollectedAmount

method on DelegationWithdraw
1func (d *DelegationWithdraw) SetCollectedAmount(amount int64)
source

SetCollectedAmount sets the collected amount.

Parameters:

  • amount: collected amount

func SetCollectedAt

method on DelegationWithdraw
1func (d *DelegationWithdraw) SetCollectedAt(collectedAt int64)
source

SetCollectedAt sets the collection timestamp.

Parameters:

  • collectedAt: collection timestamp

func UnDelegateAmount

method on DelegationWithdraw
1func (d *DelegationWithdraw) UnDelegateAmount() int64
source

UnDelegateAmount returns the total amount that was undelegated.

Returns:

  • int64: undelegated amount

func UnDelegatedAt

method on DelegationWithdraw
1func (d *DelegationWithdraw) UnDelegatedAt() int64
source

UnDelegatedAt returns the timestamp when the undelegation occurred.

Returns:

  • int64: undelegation timestamp

func UnDelegatedHeight

method on DelegationWithdraw
1func (d *DelegationWithdraw) UnDelegatedHeight() int64
source

UnDelegatedHeight returns the height when the undelegation occurred.

Returns:

  • int64: undelegation height

type EmissionRewardManager

struct
 1type EmissionRewardManager struct {
 2	// rewardStates maps address to EmissionRewardState for tracking individual staker rewards
 3	rewardStates *bptree.BPTree // address -> EmissionRewardState
 4
 5	// accumulatedRewardX128PerStake tracks the cumulative reward per unit of stake with 128-bit precision
 6	accumulatedRewardX128PerStake *u256.Uint
 7	// distributedAmount tracks the total amount of rewards distributed
 8	distributedAmount int64
 9	// accumulatedTimestamp tracks the last timestamp when rewards were accumulated
10	accumulatedTimestamp int64
11	// totalStakedAmount tracks the total amount of tokens staked in the system
12	totalStakedAmount int64
13}
source

EmissionRewardManager manages the distribution of emission rewards to stakers.

Methods on EmissionRewardManager

func GetAccumulatedRewardX128PerStake

method on EmissionRewardManager
1func (e *EmissionRewardManager) GetAccumulatedRewardX128PerStake() *u256.Uint
source

GetAccumulatedRewardX128PerStake returns the accumulated reward per stake with 128-bit precision.

func GetAccumulatedTimestamp

method on EmissionRewardManager
1func (e *EmissionRewardManager) GetAccumulatedTimestamp() int64
source

GetAccumulatedTimestamp returns the last timestamp when rewards were accumulated.

func GetDistributedAmount

method on EmissionRewardManager
1func (e *EmissionRewardManager) GetDistributedAmount() int64
source

GetDistributedAmount returns the total amount of rewards distributed.

func GetRewardState

method on EmissionRewardManager
1func (e *EmissionRewardManager) GetRewardState(addr string) (*EmissionRewardState, bool, error)
source

func GetTotalStakedAmount

method on EmissionRewardManager
1func (e *EmissionRewardManager) GetTotalStakedAmount() int64
source

GetTotalStakedAmount returns the total amount of tokens staked in the system.

func SetAccumulatedTimestamp

method on EmissionRewardManager
1func (e *EmissionRewardManager) SetAccumulatedTimestamp(accumulatedTimestamp int64)
source

func SetDistributedAmount

method on EmissionRewardManager
1func (e *EmissionRewardManager) SetDistributedAmount(distributedAmount int64)
source

func SetRewardState

method on EmissionRewardManager
1func (e *EmissionRewardManager) SetRewardState(address string, rewardState *EmissionRewardState)
source

SetRewardState sets the reward state for a specific address

func SetRewardStates

method on EmissionRewardManager
1func (e *EmissionRewardManager) SetRewardStates(rewardStates *bptree.BPTree)
source

func SetTotalStakedAmount

method on EmissionRewardManager
1func (e *EmissionRewardManager) SetTotalStakedAmount(totalStakedAmount int64)
source

type EmissionRewardState

struct
 1type EmissionRewardState struct {
 2	// rewardDebtX128 represents the reward debt with 128-bit precision scaling
 3	// Used to calculate rewards earned since the last update
 4	rewardDebtX128 *u256.Uint
 5	// accumulatedRewardAmount is the total rewards accumulated but not yet claimed
 6	accumulatedRewardAmount int64
 7	// accumulatedTimestamp is the last timestamp when rewards were accumulated
 8	accumulatedTimestamp int64
 9	// claimedRewardAmount is the total amount of rewards that have been claimed
10	claimedRewardAmount int64
11	// claimedTimestamp is the last timestamp when rewards were claimed
12	claimedTimestamp int64
13	// stakedAmount is the current amount of tokens staked by this address
14	stakedAmount int64
15}
source

EmissionRewardState tracks emission reward information for an individual staker. This struct maintains reward debt, accumulated rewards, and claiming history to ensure accurate reward calculations and prevent double-claiming.

Methods on EmissionRewardState

func GetRewardDebtX128

method on EmissionRewardState
1func (e *EmissionRewardState) GetRewardDebtX128() *u256.Uint
source

func GetStakedAmount

method on EmissionRewardState
1func (e *EmissionRewardState) GetStakedAmount() int64
source

func SetAccumulatedTimestamp

method on EmissionRewardState
1func (e *EmissionRewardState) SetAccumulatedTimestamp(accumulatedTimestamp int64)
source

func SetClaimedRewardAmount

method on EmissionRewardState
1func (e *EmissionRewardState) SetClaimedRewardAmount(claimedRewardAmount int64)
source

func SetClaimedTimestamp

method on EmissionRewardState
1func (e *EmissionRewardState) SetClaimedTimestamp(claimedTimestamp int64)
source

func SetRewardDebtX128

method on EmissionRewardState
1func (e *EmissionRewardState) SetRewardDebtX128(rewardDebtX128 *u256.Uint)
source

Setters

func SetStakedAmount

method on EmissionRewardState
1func (e *EmissionRewardState) SetStakedAmount(stakedAmount int64)
source

type IGovStaker

interface
1type IGovStaker interface {
2	IGovStakerDelegation
3	IGovStakerReward
4	IGovStakerGetter
5	IGovStakerAdmin
6}
source

Main interface that combines all sub-interfaces

type IGovStakerAdmin

interface
1type IGovStakerAdmin interface {
2	CleanStakerDelegationSnapshotByAdmin(_ int, rlm realm, snapshotTime int64, target address)
3	SetUnDelegationLockupPeriodByAdmin(_ int, rlm realm, period int64)
4}
source

Admin interface for administrative functions

type IGovStakerDelegation

interface
1type IGovStakerDelegation interface {
2	// Main delegation operations
3	Delegate(_ int, rlm realm, to address, amount int64, referrer string) int64
4	Undelegate(_ int, rlm realm, from address, amount int64) int64
5	Redelegate(_ int, rlm realm, delegatee, newDelegatee address, amount int64) int64
6	CollectUndelegatedGns(_ int, rlm realm) int64
7}
source

Delegation operations interface

Mutating methods take `_ int, rlm realm` so the realm token is threaded from the proxy entry points down to the cross-realm token transfers and store writes performed inside each implementation. The `_ int` sentinel surfaces at every call site as a literal `0`, making the realm threading visible to readers.

type IGovStakerGetter

interface
 1type IGovStakerGetter interface {
 2	// Store data getters
 3	GetUnDelegationLockupPeriod() int64
 4
 5	// Delegation getters
 6	GetTotalxGnsSupply() int64
 7	GetTotalDelegated() int64
 8	GetTotalLockedAmount() int64
 9	GetDelegationCount() int
10	GetDelegationIDs(offset, count int) []int64
11	ExistsDelegation(delegationID int64) bool
12	GetDelegation(delegationID int64) (*Delegation, error)
13	GetDelegatorDelegateeCount(delegator address) int
14	GetDelegatorDelegateeAddresses(delegator address, offset, count int) []address
15	GetUserDelegationCount(delegator address, delegatee address) int
16	GetUserDelegationIDs(delegator address, delegatee address) []int64
17	HasDelegationSnapshotsKey() bool
18	GetTotalDelegationAmountAtSnapshot(snapshotTime int64) (int64, bool)
19	GetUserDelegationAmountAtSnapshot(userAddr address, snapshotTime int64) (int64, bool)
20
21	// Reward getters
22	GetClaimableRewardByAddress(addr address) (int64, map[string]int64, error)
23	GetClaimableRewardByLaunchpad(addr address) (int64, map[string]int64, error)
24	GetClaimableRewardByRewardID(rewardID string) (int64, map[string]int64, error)
25
26	// Launchpad getters
27	GetLaunchpadProjectDeposit(projectAddr string) (int64, bool)
28
29	// Withdraw getters
30	GetDelegationWithdrawCount(delegationID int64) int
31	GetDelegationWithdraws(delegationID int64, offset, count int) ([]DelegationWithdraw, error)
32	GetCollectableWithdrawAmount(delegationID int64) int64
33
34	// Protocol fee reward getters
35	GetProtocolFeeAccumulatedX128PerStake(tokenPath string) *uint256.Uint
36	GetProtocolFeeAmount(tokenPath string) int64
37	GetProtocolFeeAccumulatedTimestamp() int64
38
39	// Emission reward getters
40	GetEmissionAccumulatedX128PerStake() *uint256.Uint
41	GetEmissionDistributedAmount() int64
42	GetEmissionAccumulatedTimestamp() int64
43}
source

Getter interface for read operations

type IGovStakerReward

interface
 1type IGovStakerReward interface {
 2	// Reward collection
 3	CollectReward(_ int, rlm realm)
 4	CollectEmissionReward(_ int, rlm realm)
 5	CollectProtocolFeeReward(_ int, rlm realm, tokenPath string)
 6	CollectRewardFromLaunchPad(_ int, rlm realm, to address)
 7	CollectEmissionRewardFromLaunchPad(_ int, rlm realm, to address)
 8	CollectProtocolFeeRewardFromLaunchPad(_ int, rlm realm, to address, tokenPath string)
 9	SetAmountByProjectWallet(_ int, rlm realm, addr address, amount int64, add bool)
10}
source

Reward management interface

type IGovStakerStore

interface
 1type IGovStakerStore interface {
 2	// Basic configuration
 3	HasUnDelegationLockupPeriodStoreKey() bool
 4	GetUnDelegationLockupPeriod() int64
 5	SetUnDelegationLockupPeriod(_ int, rlm realm, period int64) error
 6
 7	HasTotalDelegatedAmountStoreKey() bool
 8	GetTotalDelegatedAmount() int64
 9	SetTotalDelegatedAmount(_ int, rlm realm, amount int64) error
10
11	HasTotalLockedAmountStoreKey() bool
12	GetTotalLockedAmount() int64
13	SetTotalLockedAmount(_ int, rlm realm, amount int64) error
14
15	// Delegation management
16	HasDelegation(id int64) bool
17	GetDelegation(id int64) (*Delegation, bool)
18	SetDelegation(_ int, rlm realm, id int64, delegation *Delegation) error
19	RemoveDelegation(_ int, rlm realm, id int64) error
20
21	HasDelegationsStoreKey() bool
22	SetDelegations(_ int, rlm realm, delegations *bptree.BPTree) error
23	GetAllDelegations() *bptree.BPTree
24
25	HasDelegationCounterStoreKey() bool
26	GetDelegationCounter() *Counter
27	SetDelegationCounter(_ int, rlm realm, counter *Counter) error
28
29	// Total delegation history (timestamp -> int64)
30	HasTotalDelegationHistoryStoreKey() bool
31	GetTotalDelegationHistory() *UintTree
32	SetTotalDelegationHistory(_ int, rlm realm, history *UintTree) error
33
34	// User delegation history (address -> *UintTree[timestamp -> int64])
35	HasUserDelegationHistoryStoreKey() bool
36	GetUserDelegationHistory() *bptree.BPTree
37	SetUserDelegationHistory(_ int, rlm realm, history *bptree.BPTree) error
38
39	// Manager states
40	HasEmissionRewardManagerStoreKey() bool
41	GetEmissionRewardManager() *EmissionRewardManager
42	SetEmissionRewardManager(_ int, rlm realm, manager *EmissionRewardManager) error
43
44	HasProtocolFeeRewardManagerStoreKey() bool
45	GetProtocolFeeRewardManager() *ProtocolFeeRewardManager
46	SetProtocolFeeRewardManager(_ int, rlm realm, manager *ProtocolFeeRewardManager) error
47
48	HasDelegationManagerStoreKey() bool
49	GetDelegationManager() *DelegationManager
50	SetDelegationManager(_ int, rlm realm, manager *DelegationManager) error
51
52	HasLaunchpadProjectDepositsStoreKey() bool
53	GetLaunchpadProjectDeposits() *LaunchpadProjectDeposits
54	SetLaunchpadProjectDeposits(_ int, rlm realm, deposits *LaunchpadProjectDeposits) error
55}
source

IGovStakerStore mirrors the mutating-method realm-threading convention used by the public IGovStaker* interfaces above. Setters take `_ int, rlm realm` so KV-store writes execute under the proxy realm — the only address with write access to the shared store.

type LaunchpadProjectDeposits

struct
1type LaunchpadProjectDeposits struct {
2	// deposits maps owner address to deposit amount
3	deposits *bptree.BPTree // string -> int64
4}
source

LaunchpadProjectDeposits manages deposit amounts for launchpad projects. It tracks the total staked amount for each project identified by owner address.

Methods on LaunchpadProjectDeposits

func GetDeposit

method on LaunchpadProjectDeposits
1func (lpd *LaunchpadProjectDeposits) GetDeposit(ownerAddress string) (int64, bool)
source

func GetDeposits

method on LaunchpadProjectDeposits
1func (lpd *LaunchpadProjectDeposits) GetDeposits() *bptree.BPTree
source

GetDeposits returns the entire deposits tree.

func RemoveDeposit

method on LaunchpadProjectDeposits
1func (lpd *LaunchpadProjectDeposits) RemoveDeposit(ownerAddress string) bool
source

func SetDeposit

method on LaunchpadProjectDeposits
1func (lpd *LaunchpadProjectDeposits) SetDeposit(ownerAddress string, amount int64)
source

func SetDeposits

method on LaunchpadProjectDeposits
1func (lpd *LaunchpadProjectDeposits) SetDeposits(deposits *bptree.BPTree)
source

SetDeposits sets the entire deposits tree.

type ProtocolFeeRewardManager

struct
 1type ProtocolFeeRewardManager struct {
 2	// rewardStates maps address to ProtocolFeeRewardState for tracking individual staker rewards
 3	rewardStates *bptree.BPTree // address -> ProtocolFeeRewardState
 4
 5	// accumulatedProtocolFeeX128PerStake maps token path to accumulated fee per stake with 128-bit precision
 6	accumulatedProtocolFeeX128PerStake map[string]*u256.Uint
 7	// protocolFeeAmounts maps token path to total distributed protocol fee amounts
 8	protocolFeeAmounts map[string]int64
 9	// accumulatedTimestamp tracks the last timestamp when fees were accumulated
10	accumulatedTimestamp int64
11	// totalStakedAmount tracks the total amount of tokens staked in the system
12	totalStakedAmount int64
13}
source

ProtocolFeeRewardManager manages the distribution of protocol fee rewards to stakers. Unlike emission rewards, protocol fees can come from multiple tokens, requiring separate tracking and distribution mechanisms for each token type.

Methods on ProtocolFeeRewardManager

func GetAccumulatedProtocolFeeX128PerStake

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) GetAccumulatedProtocolFeeX128PerStake(token string) *u256.Uint
source

GetAccumulatedProtocolFeeX128PerStake returns the accumulated protocol fee per stake for a specific token.

Parameters:

  • token: token path to get accumulated fee for

Returns:

  • *u256.Uint: accumulated protocol fee per stake for the token (scaled by 2^128)

func GetAccumulatedTimestamp

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) GetAccumulatedTimestamp() int64
source

GetAccumulatedTimestamp returns the last timestamp when protocol fees were accumulated.

Returns:

  • int64: last accumulated timestamp

func GetAllAccumulatedProtocolFeeX128PerStake

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) GetAllAccumulatedProtocolFeeX128PerStake() map[string]*u256.Uint
source

GetAllAccumulatedProtocolFeeX128PerStake returns all accumulated protocol fees per stake

func GetProtocolFeeAmount

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) GetProtocolFeeAmount(token string) int64
source

GetProtocolFeeAmount returns the protocol fee amount for a specific token

func GetProtocolFeeAmounts

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) GetProtocolFeeAmounts() map[string]int64
source

func GetRewardState

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) GetRewardState(addr string) (*ProtocolFeeRewardState, bool, error)
source

func GetTotalStakedAmount

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) GetTotalStakedAmount() int64
source

func SetAccumulatedProtocolFeeX128PerStake

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) SetAccumulatedProtocolFeeX128PerStake(accumulatedProtocolFeeX128PerStake map[string]*u256.Uint)
source

func SetAccumulatedTimestamp

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) SetAccumulatedTimestamp(accumulatedTimestamp int64)
source

func SetProtocolFeeAmountForToken

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) SetProtocolFeeAmountForToken(token string, amount int64)
source

func SetProtocolFeeAmounts

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) SetProtocolFeeAmounts(protocolFeeAmounts map[string]int64)
source

func SetRewardState

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) SetRewardState(address string, rewardState *ProtocolFeeRewardState)
source

SetRewardState sets the reward state for a specific address

func SetRewardStates

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) SetRewardStates(rewardStates *bptree.BPTree)
source

func SetTotalStakedAmount

method on ProtocolFeeRewardManager
1func (p *ProtocolFeeRewardManager) SetTotalStakedAmount(totalStakedAmount int64)
source

type ProtocolFeeRewardState

struct
 1type ProtocolFeeRewardState struct {
 2	// rewardDebtX128 maps token path to reward debt with 128-bit precision scaling
 3	// Used to calculate rewards earned since the last update for each token
 4	rewardDebtX128 map[string]*u256.Uint
 5	// accumulatedRewards maps token path to total rewards accumulated but not yet claimed
 6	accumulatedRewards map[string]int64
 7	// claimedRewards maps token path to total amount of rewards that have been claimed
 8	claimedRewards map[string]int64
 9	// accumulatedTimestamp is the last timestamp when rewards were accumulated
10	accumulatedTimestamp int64
11	// claimedTimestamp is the last timestamp when rewards were claimed
12	claimedTimestamp int64
13	// stakedAmount is the current amount of tokens staked by this address
14	stakedAmount int64
15}
source

ProtocolFeeRewardState tracks protocol fee reward information for an individual staker across multiple tokens. Unlike emission rewards which are single-token, protocol fees can come from various trading pairs, requiring separate tracking and calculation for each token type.

Methods on ProtocolFeeRewardState

func GetAccumulatedRewards

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) GetAccumulatedRewards() map[string]int64
source

func GetClaimedRewardForToken

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) GetClaimedRewardForToken(token string) int64
source

func GetClaimedRewards

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) GetClaimedRewards() map[string]int64
source

func GetClaimedTimestamp

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) GetClaimedTimestamp() int64
source

func GetRewardDebtX128

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) GetRewardDebtX128() map[string]*u256.Uint
source

func GetRewardDebtX128ForToken

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) GetRewardDebtX128ForToken(token string) *u256.Uint
source

func GetStakedAmount

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) GetStakedAmount() int64
source

func SetAccumulatedRewards

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) SetAccumulatedRewards(accumulatedRewards map[string]int64)
source

func SetAccumulatedTimestamp

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) SetAccumulatedTimestamp(accumulatedTimestamp int64)
source

func SetClaimedRewardForToken

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) SetClaimedRewardForToken(token string, value int64)
source

func SetClaimedRewards

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) SetClaimedRewards(claimedRewards map[string]int64)
source

func SetClaimedTimestamp

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) SetClaimedTimestamp(claimedTimestamp int64)
source

func SetRewardDebtX128

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) SetRewardDebtX128(rewardDebtX128 map[string]*u256.Uint)
source

SetRewardDebtX128 stores a copy of the given map. Copying into a map allocated by this domain method keeps the stored map owned by /r/gnoswap/gov/staker, so later per-token writes (SetRewardDebtX128ForToken) from any realm clear the cross-realm write guard. Storing the caller's map directly would leave the map stamped with the caller's realm.

func SetRewardDebtX128ForToken

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) SetRewardDebtX128ForToken(token string, value *u256.Uint)
source

func SetStakedAmount

method on ProtocolFeeRewardState
1func (p *ProtocolFeeRewardState) SetStakedAmount(stakedAmount int64)
source

type UintTree

struct
1type UintTree struct {
2	tree *bptree.BPTree // blockTimestamp -> any
3}
source

UintTree is a wrapper around a BPTree for storing block timestamps as strings. Since block timestamps are defined as int64, we take int64 and convert it to uint64 for the tree.

Methods: - Get: Retrieves a value associated with a uint64 key. - set: Stores a value with a uint64 key. - Has: Checks if a uint64 key exists in the tree. - remove: Removes a uint64 key and its associated value. - Iterate: Iterates over keys and values in a range. - ReverseIterate: Iterates in reverse order over keys and values in a range.

Methods on UintTree

func Get

method on UintTree
1func (self *UintTree) Get(key int64) (any, bool)
source

func Has

method on UintTree
1func (self *UintTree) Has(key int64) bool
source

func Iterate

method on UintTree
1func (self *UintTree) Iterate(start, end int64, fn func(key int64, value any) bool)
source

func Remove

method on UintTree
1func (self *UintTree) Remove(key int64)
source

func ReverseIterate

method on UintTree
1func (self *UintTree) ReverseIterate(start, end int64, fn func(key int64, value any) bool)
source

func Set

method on UintTree
1func (self *UintTree) Set(key int64, value any)
source

func Size

method on UintTree
1func (self *UintTree) Size() int
source

Size returns the number of entries in the tree.

Imports 12

Source Files 22