pool.gno
Types
ExternalIncentive
Methods
AccumulatedPenaltyAmount
AccumulatedPenaltyAmount returns the accumulated warmup penalty amount
Return Values
amount
int64
Warm-up penalty accumulated from reward collections for this incentive.
Clone
Clone returns an independent ExternalIncentive value with scalar fields copied and its fixed-point rate duplicated.
Return Values
incentive
*ExternalIncentive
Copied external incentive record; its fixed-point rate is cloned when present and otherwise initialized to zero.
CreatedHeight
CreatedHeight returns the created height
Return Values
height
int64
Block height at which the incentive record was created.
CreatedTimestamp
CreatedTimestamp returns the created timestamp
Return Values
timestamp
int64
Unix timestamp in seconds at which the incentive record was created.
Creator
Creator returns the creator address
Return Values
creator
address
Address that created and funded the incentive.
DepositGnsAmount
DepositGnsAmount returns the deposit GNS amount
Return Values
amount
int64
GNS amount deposited to back this external incentive.
DistributedRewardAmount
DistributedRewardAmount returns the distributed reward amount
Return Values
amount
int64
Reward amount already delivered to positions or refunded at incentive end.
EndTimestamp
EndTimestamp returns the end timestamp
Return Values
timestamp
int64
Unix timestamp in seconds at which the incentive window ends.
IncentiveId
IncentiveId returns the incentive ID
Return Values
id
string
Identifier assigned to this external incentive.
Refunded
Refunded returns the refunded status
Return Values
refunded
bool
True when incentive finalization has marked its refundable balances as returned.
RewardAmount
RewardAmount returns the reward amount
Return Values
amount
int64
Mutable reward amount remaining after distributions and refunds.
RewardPerSecondX128
RewardPerSecondX128 returns the Q128-scaled reward per second. The underlying value is (rewardAmount << 128) / duration.
Return Values
rate
*u256.Uint
Reward emitted per second, scaled by 2^128 for fixed-point accounting.
RewardToken
RewardToken returns the reward token
Return Values
token
string
Reward-token path distributed by this incentive.
SetAccumulatedPenaltyAmount
SetAccumulatedPenaltyAmount sets the accumulated warmup penalty amount
Parameters
accumulatedPenaltyAmount
int64
Warm-up penalty amount to store in the incentive's accumulated accounting.
SetCreatedHeight
SetCreatedHeight sets the created height
Parameters
createdHeight
int64
Block height to record as the incentive's creation height.
SetCreatedTimestamp
SetCreatedTimestamp sets the created timestamp
Parameters
createdTimestamp
int64
Unix timestamp in seconds to record as the incentive creation time.
SetCreator
SetCreator sets the creator address
Parameters
creator
address
Address to record as the incentive creator and refund recipient.
SetDepositGnsAmount
SetDepositGnsAmount sets the deposit GNS amount
Parameters
depositGnsAmount
int64
GNS amount deposited to back this external incentive.
SetDistributedRewardAmount
SetDistributedRewardAmount sets the distributed reward amount
Parameters
distributedRewardAmount
int64
Reward amount delivered to positions or refunded at incentive end.
SetEndTimestamp
SetEndTimestamp sets the end timestamp
Parameters
endTimestamp
int64
Unix timestamp in seconds at which the incentive window ends.
SetIncentiveId
SetIncentiveId sets the incentive ID
Parameters
incentiveId
string
Identifier to store on the incentive record.
SetRefunded
SetRefunded sets the refunded status
Parameters
refunded
bool
Finalization status to store for the incentive.
SetRewardAmount
SetRewardAmount sets the reward amount
Parameters
rewardAmount
int64
Remaining reward amount to store after accounting adjustments.
SetRewardPerSecondX128
SetRewardPerSecondX128 sets the Q128-scaled reward per second.
Parameters
rewardPerSecondX128
*u256.Uint
Q128-scaled per-second reward rate; the value is copied before storage.
SetRewardToken
SetRewardToken sets the reward token
Parameters
rewardToken
string
Token path of the reward asset distributed by this incentive.
SetTargetPoolPath
SetTargetPoolPath sets the target pool path
Parameters
targetPoolPath
string
Pool path to target with this external incentive.
SetTotalRewardAmount
SetTotalRewardAmount sets the total reward amount
Parameters
totalRewardAmount
int64
Total reward amount to record for the incentive.
SetUnclaimableSeconds
SetUnclaimableSeconds sets the accumulated unclaimable seconds.
Parameters
unclaimableSeconds
int64
Overlapping unclaimable duration in seconds to store.
StartTimestamp
StartTimestamp returns the start timestamp.
It keys the byStartTime discovery index and must stay immutable after the incentive is registered, so no setter is exposed.
Return Values
timestamp
int64
Unix timestamp in seconds at which reward distribution starts.
TargetPoolPath
TargetPoolPath returns the target pool path
Return Values
path
string
Pool path targeted by this external incentive.
TotalRewardAmount
TotalRewardAmount returns the total reward amount
Return Values
amount
int64
Total reward amount configured when the incentive was created.
UnclaimableSeconds
UnclaimableSeconds returns the accumulated seconds of unclaimable periods that overlap the incentive window. It is updated whenever an unclaimable period closes and is backfilled once from the historical unclaimable periods tree after an upgrade.
Return Values
seconds
int64
Accumulated seconds of unclaimable periods overlapping the incentive window.
Constructors
func GetExternalIncentiveByPoolPath(poolPath string) ([]ExternalIncentive, error)(source)func NewExternalIncentive(incentiveId string, targetPoolPath string, rewardToken string, rewardAmount int64, startTimestamp int64, endTimestamp int64, creator address, depositGnsAmount int64, createdHeight int64, currentTime int64) *ExternalIncentive(source)
Incentives
Incentives represents a collection of external incentives for a specific pool.
Fields:
incentives: BPTree storing ExternalIncentive objects indexed by incentiveId The incentiveId serves as the key to efficiently lookup incentive details
targetPoolPath: String identifier for the pool this incentive collection belongs to Used to associate incentives with their corresponding liquidity pool
unclaimablePeriods: Tree storing periods when rewards cannot be claimed Maps start timestamp (key) to end timestamp (value) An end timestamp of 0 indicates an ongoing unclaimable period Used to track intervals when staking rewards are not claimable
byStartTime: Per-pool start-time index mapping an incentive's start timestamp (key) to the incentive IDs that start at that timestamp (value). This mirrors the lazy-discovery lookup previously served by a global creation-time index, but scoped to this pool's own incentives, so discovery cost is bounded by this pool's incentives instead of growing with the total number of incentives system-wide.
Methods
AddIncentiveByStartTime
AddIncentiveByStartTime registers an incentive ID under its start timestamp in the per-pool start-time index. Multiple incentives starting at the same timestamp are accumulated as a list.
Parameters
startTimestamp
int64
Nonnegative Unix timestamp in seconds used as the start-time index key.
incentiveId
string
Incentive identifier to append to that timestamp's bucket.
Incentive
Incentive returns an incentive by ID
Parameters
incentiveId
string
Identifier used to look up the external incentive record.
Return Values
incentive
*ExternalIncentive
Matching ExternalIncentive pointer, or nil when no value is stored for incentiveId.
found
bool
True only when the stored value has ExternalIncentive type; false for a missing or mismatched value.
IncentiveTrees
Incentives returns the incentives tree
Return Values
tree
*bptree.BPTree
Mutable B+ tree mapping incentive IDs to ExternalIncentive records.
IterateIncentiveIdsByTime
IterateIncentiveIdsByTime iterates over the incentive IDs that start within the inclusive [startTime, endTime] range, visiting only the buckets that fall in the range. ReverseIterate is used because it is inclusive on both ends, matching the discovery semantics previously implemented as (startTimestamp >= startTime && startTimestamp <= endTime).
Parameters
startTime
int64
Inclusive lower Unix timestamp bound for incentive starts.
endTime
int64
Inclusive upper Unix timestamp bound for incentive starts.
fn
func(string) bool
Callback receiving each matching incentive ID; returning true requests that iteration stop.
IterateIncentives
IterateIncentives iterates over all incentives
Parameters
fn
func(string, *ExternalIncentive) bool
Callback receiving each incentive ID and record; returning true requests that iteration stop.
RemoveIncentive
RemoveIncentive deletes an incentive by ID.
Only an incentive that never started may be removed: once rewards begin accruing, deposits and the refund accounting reference the record, so an ended incentive is marked refunded instead of removed.
Parameters
incentiveId
string
Identifier of the external incentive record to remove.
RemoveIncentiveByStartTime
RemoveIncentiveByStartTime unregisters an incentive ID from the per-pool start-time index. The bucket itself is dropped once its last ID is removed, so the index never keeps an empty entry that discovery would still visit.
Parameters
startTimestamp
int64
Nonnegative Unix timestamp in seconds identifying the start-time bucket.
incentiveId
string
Incentive identifier to remove from that bucket; all matching entries are omitted.
RemoveUnclaimablePeriod
RemoveUnclaimablePeriod removes the interval keyed by its start timestamp.
Parameters
startTimestamp
int64
Nonnegative Unix timestamp in seconds identifying the interval to remove.
SetIncentive
SetIncentive sets an incentive by ID
Parameters
incentiveId
string
Identifier under which to store the incentive.
incentive
*ExternalIncentive
ExternalIncentive record to store for incentiveId.
SetIncentives
SetIncentives sets the incentives tree
Parameters
incentives
*bptree.BPTree
B+ tree to use for incentive ID lookups and storage.
SetTargetPoolPath
SetTargetPoolPath sets the target pool path
Parameters
targetPoolPath
string
Pool path to associate with this incentive collection.
SetUnclaimablePeriod
SetUnclaimablePeriod records an interval during which staking rewards cannot be claimed.
Parameters
startTimestamp
int64
Nonnegative Unix timestamp in seconds at which the interval begins.
endTimestamp
int64
Unix timestamp in seconds at which the interval ends; 0 records an ongoing interval.
SetUnclaimablePeriods
SetUnclaimablePeriods sets the unclaimable periods tree
Parameters
unclaimablePeriods
*UintTree
Tree of reward-unclaimable intervals keyed by their start timestamps.
TargetPoolPath
TargetPoolPath returns the target pool path
Return Values
path
string
Pool path to which this incentive collection belongs.
UnclaimablePeriods
UnclaimablePeriods returns the unclaimable periods tree
Return Values
periods
*UintTree
Tree mapping unclaimable-period start timestamps to end timestamps; end 0 denotes an open period.
Constructors
func NewIncentives(targetPoolPath string) *Incentives(source)
Pool
Pool is a struct for storing an incentivized pool information Each pool stores Incentives and Ticks associated with it.
Fields:
poolPath: The path of the pool.
stakedLiquidity: The current total staked liquidity of the in-range positions for the pool. Updated when tick cross happens or stake/unstake happens. Used to calculate the global reward ratio accumulation or decide whether to enter/exit unclaimable period.
lastUnclaimableTime: The time at which the unclaimable period started. Set to 0 when the pool is not in an unclaimable period.
unclaimableAcc: The accumulated undistributed unclaimable reward. Reset to 0 when processUnclaimableReward is called and sent to community pool.
rewardCache: The cached per-second reward emitted for this pool. Stores new entry only when the reward is changed. PoolTier.cacheReward() updates this.
incentives: The external incentives associated with the pool.
ticks: The Ticks associated with the pool.
globalRewardRatioAccumulation: Global ratio of Time / TotalStake accumulation(since the pool creation) Stores new entry only when tick cross or stake/unstake happens. It is used to calculate the reward for a staked position at certain time.
historicalTick: The historical tick for the pool at a given time. It does not reflect the exact tick at the timestamp, but it provides correct ordering for the staked position's ticks. Therefore, you should not compare it for equality, only for ordering. Set when tick cross happens or a new position is created.
Methods
Clone
Clone returns a pool copy of the scalar state with a fresh tick container.
Return Values
pool
*Pool
Pool copy carrying scalar state and a fresh tick container; backing trees and incentives are nil, and nil receiver yields nil.
GlobalRewardRatioAccumulation
GlobalRewardRatioAccumulation returns the global reward ratio accumulation tree
Return Values
tree
*UintTree
Historical global time-per-total-stake accumulation keyed by Unix timestamp.
HistoricalTick
HistoricalTick returns the historical tick tree
Return Values
tree
*UintTree
Historical tick-ID ordering snapshots keyed by Unix timestamp.
Incentives
Incentives returns the incentives
Return Values
incentives
*Incentives
External-incentive collection associated with this pool.
LastUnclaimableTime
LastUnclaimableTime returns the last unclaimable time
Return Values
timestamp
int64
Unix timestamp in seconds at which the pool entered its current unclaimable period, or 0 when tracking has not started.
PoolPath
PoolPath returns the pool path
Return Values
path
string
Pool identifier used to associate this state with a liquidity pool.
RewardCache
RewardCache returns the reward cache tree
Return Values
tree
*UintTree
Historical per-second GNS reward cache keyed by Unix timestamp.
SetGlobalRewardRatioAccumulation
SetGlobalRewardRatioAccumulation sets the global reward ratio accumulation tree
Parameters
globalRewardRatioAccumulation
*UintTree
Tree of serialized Q128-scaled reward-ratio accumulation snapshots.
SetGlobalRewardRatioAccumulationAt
SetGlobalRewardRatioAccumulationAt records a serialized global reward-ratio accumulation snapshot.
Parameters
currentTime
int64
Nonnegative Unix timestamp in seconds used as the snapshot key.
acc
string
Serialized Q128-scaled global reward-ratio accumulation value.
SetHistoricalTick
SetHistoricalTick sets the historical tick tree
Parameters
historicalTick
*UintTree
Tree of tick IDs representing the ordering history of staked positions.
SetHistoricalTickAt
SetHistoricalTickAt records the tick ordering snapshot for a timestamp.
Parameters
currentTime
int64
Nonnegative Unix timestamp in seconds used as the snapshot key.
tick
int32
Tick ID representing the pool's historical ordering at currentTime.
SetIncentives
SetIncentives sets the incentives
Parameters
incentives
*Incentives
External-incentive collection to associate with the pool.
SetLastUnclaimableTime
SetLastUnclaimableTime sets the last unclaimable time
Parameters
lastUnclaimableTime
int64
Unix timestamp in seconds marking the start of the current unclaimable period; use 0 when no period is active.
SetPoolPath
SetPoolPath sets the pool path
Parameters
poolPath
string
Pool identifier to store.
SetRewardCache
SetRewardCache sets the reward cache tree
Parameters
rewardCache
*UintTree
Tree containing the pool's per-second GNS reward snapshots.
SetRewardCacheAt
SetRewardCacheAt records the per-second reward rate for a timestamp.
Parameters
currentTime
int64
Nonnegative Unix timestamp in seconds used as the cache key.
reward
int64
GNS reward emitted per second from currentTime until the next cached change.
SetStakedLiquidity
SetStakedLiquidity sets the staked liquidity tree
Parameters
stakedLiquidity
*UintTree
Tree of historical total staked liquidity snapshots.
SetStakedLiquidityAt
SetStakedLiquidityAt records the current total staked liquidity at a timestamp.
Parameters
currentTime
int64
Nonnegative Unix timestamp in seconds used as the snapshot key.
delta
*u256.Uint
Total staked liquidity at currentTime, stored as a copied Q128-scaled uint value.
SetTicks
SetTicks sets the ticks
Parameters
ticks
Ticks
Tick mapping value to store in the pool.
SetUnclaimableAcc
SetUnclaimableAcc sets the unclaimable accumulation
Parameters
unclaimableAcc
int64
Accumulated undistributed unclaimable reward amount in the pool's int64 reward units.
StakedLiquidity
StakedLiquidity returns the staked liquidity tree
Return Values
tree
*UintTree
Historical staked-liquidity tree keyed by Unix timestamp, with Q128-scaled liquidity values.
Ticks
Ticks returns the ticks
Return Values
ticks
*Ticks
Addressable tick mapping for this pool's staked positions.
UnclaimableAcc
UnclaimableAcc returns the unclaimable accumulation
Return Values
amount
int64
Accumulated undistributed unclaimable reward amount in the pool's int64 reward units.
Constructors
func GetPool(poolPath string) (*Pool, error)(source)func NewPool(poolPath string, currentTime int64) *Pool(source)
SwapBatchProcessor
SwapBatchProcessor processes tick crosses in batch for a swap This processor accumulates all tick crosses that occur during a single swap and processes them together at the end, reducing redundant calculations and state updates that would occur with individual tick processing
Methods
AddCross
AddCross appends a tick-cross record to the batch sequence.
Parameters
tickCross
*SwapTickCross
Tick-cross record to append.
Crosses
Crosses returns the tick crosses accumulated by this batch.
Return Values
crosses
[]*SwapTickCross
Slice of tick-cross records in the order they were added.
IsActive
IsActive reports the processor's stored active flag.
Return Values
active
bool
True when the batch is marked active for the swap lifecycle.
LastCross
LastCross returns the most recently appended tick cross.
Return Values
cross
*SwapTickCross
Last tick-cross record, or nil when no crosses have been added.
Pool
Pool returns the pool referenced by this swap batch.
Return Values
pool
*Pool
Pool state used to process the accumulated tick crosses.
PoolPath
PoolPath returns the pool path associated with this swap batch.
Return Values
path
string
Pool identifier for the swap being processed.
SetCrosses
SetCrosses replaces the batch's accumulated tick-cross sequence.
Parameters
crosses
[]*SwapTickCross
Tick-cross records to store as the batch's accumulated sequence.
SetIsActive
SetIsActive stores the processor's active lifecycle flag.
Parameters
isActive
bool
Active flag to store for the swap lifecycle.
SetPool
SetPool replaces the pool reference used by this swap batch.
Parameters
pool
*Pool
Pool state to reference while processing tick crosses.
SetPoolPath
SetPoolPath stores the pool identifier associated with this swap batch.
Parameters
poolPath
string
Pool identifier to associate with the swap batch.
SetTimestamp
SetTimestamp stores the swap-start timestamp for this batch.
Parameters
timestamp
int64
Unix timestamp in seconds to record for the swap batch.
Timestamp
Timestamp returns the Unix timestamp in seconds recorded when the swap started.
Return Values
timestamp
int64
Swap-start timestamp in Unix seconds.
Constructors
func NewSwapBatchProcessor(poolPath string, pool *Pool, timestamp int64) *SwapBatchProcessor(source)
SwapTickCross
SwapTickCross stores information about a tick cross during a swap This struct is used to accumulate tick cross events during a single swap transaction for batch processing to optimize gas usage and computational efficiency
Methods
Delta
Delta returns the precomputed net staked-liquidity change for the crossed tick.
Return Values
delta
*i256.Int
Signed liquidity delta to apply at the crossed tick.
TickID
TickID returns the index of the crossed tick.
Return Values
tickID
int32
Tick index represented by this cross.
ZeroForOne
ZeroForOne reports the swap direction represented by this cross.
Return Values
zeroForOne
bool
True for token0-to-token1 swaps; false for token1-to-token0 swaps.
Constructors
func NewSwapTickCross(tickID int32, zeroForOne bool, delta *i256.Int) *SwapTickCross(source)
Tick
Tick represents the state of a specific tick in a pool.
Fields:
id (int32): The ID of the tick.
stakedLiquidityGross (*u256.Uint): Total gross staked liquidity at this tick.
stakedLiquidityDelta (*i256.Int): Net change in staked liquidity at this tick.
outsideAccumulation (*UintTree): RewardRatioAccumulation outside the tick.
Methods
Clone
Clone returns a deep copy of the tick.
Return Values
tick
*Tick
Deep copy of the tick and its outside-accumulation tree, or nil when the receiver is nil.
Id
Id returns the tick ID
Return Values
id
int32
Tick index represented by this record.
OutsideAccumulation
OutsideAccumulation returns the outside accumulation tree
Return Values
tree
*UintTree
Historical reward-ratio accumulation observed outside this tick.
SetId
SetId sets the tick ID
Parameters
id
int32
Tick index to store in the record.
SetOutsideAccumulation
SetOutsideAccumulation sets the outside accumulation tree
Parameters
outsideAccumulation
*UintTree
UintTree of outside-accumulation snapshots keyed by Unix timestamp.
SetOutsideAccumulationAt
SetOutsideAccumulationAt sets the outside accumulation at the timestamp. SetOutsideAccumulationAt records the Q128-scaled outside accumulation at a timestamp.
Parameters
timestamp
int64
Nonnegative Unix timestamp in seconds used as the snapshot key.
acc
*u256.Uint
Q128-scaled accumulation value encoded into the tree.
SetStakedLiquidityDelta
SetStakedLiquidityDelta sets the staked liquidity delta
Parameters
stakedLiquidityDelta
*i256.Int
New net staked liquidity delta; the value is copied before storage.
SetStakedLiquidityGross
SetStakedLiquidityGross sets the staked liquidity gross
Parameters
stakedLiquidityGross
*u256.Uint
New total gross staked liquidity; the value is copied before storage.
StakedLiquidityDelta
StakedLiquidityDelta returns the staked liquidity delta
Return Values
delta
*i256.Int
Net staked liquidity change associated with this tick.
StakedLiquidityGross
StakedLiquidityGross returns the staked liquidity gross
Return Values
liquidity
*u256.Uint
Total gross staked liquidity currently associated with this tick.
Constructors
func NewTick(tickId int32) *Tick(source)
Ticks
Tick mapping for each pool
Methods
Clone
Clone returns a deep copy of ticks.
Return Values
ticks
Ticks
New Ticks value with cloned Tick records in a fresh fanout-16 tree.
Get
Get returns the tick for the given tickId, or nil if it does not exist.
Parameters
tickId
int32
Tick index to look up.
Return Values
tick
*Tick
Matching Tick record, or nil when the encoded ID is absent; panics if a stored value has the wrong type.
Has
Has reports whether a tick ID is present in the underlying tree.
Parameters
tickId
int32
Tick index whose encoded key is tested.
Return Values
present
bool
True when the encoded tick ID exists in the underlying tree.
IterateTicks
IterateTicks iterates over all ticks
Parameters
fn
func(int32, *Tick) bool
Callback receiving each stored Tick and decoded tick ID; returning true requests that iteration stop.
SetTick
SetTick sets a tick by ID
Parameters
tickId
int32
Tick index under which to store the record.
tick
*Tick
Non-nil Tick record to store; a zero gross staked liquidity removes the tick instead, while nil input panics during the gross-liquidity check.
SetTree
SetTree sets the ticks tree
Parameters
tree
*bptree.BPTree
B+ tree to use for tick storage.
Tree
Tree returns the ticks tree
Return Values
tree
*bptree.BPTree
Mutable B+ tree mapping encoded int32 tick IDs to Tick records.
Constructors
func NewTicks() Ticks(source)
TierRatio
100%, 0%, 0% if no tier2 and tier3 80%, 0%, 20% if no tier2 70%, 30%, 0% if no tier3 50%, 30%, 20% if has tier2 and tier3
Fields
Methods
Get
Get returns the ratio(scaled up by 100) for the given tier.
Parameters
tier
uint64
Tier number to query; only tiers 1, 2, and 3 are supported.
Return Values
ratio
uint64
Requested tier share scaled by 100.
err
error
Non-nil when tier is not 1, 2, or 3; nil for a supported tier.
Constructors
func NewTierRatio(tier1 uint64, tier2 uint64, tier3 uint64) TierRatio(source)
Last updated