gns source realm
Package gns implements the GNS governance and utility token for GnoSwap.
View source
GNS
GnoSwap governance and utility token.
Overview
GNS is the native governance token of GnoSwap, featuring a deflationary emission schedule with halvings every 2 years over 12 years total.
Token Economics
- Symbol: GNS
- Decimals: 6
- Max Supply: 1,000,000,000 GNS
- Initial Mint: 100,000,000 GNS, pre-minted to the configured
ADMINrole address during GNS realm initialization - Total Emission: 900,000,000 GNS over 12 years
Emission Schedule
| Years | Annual Emission | Rate |
|---|---|---|
| 1-2 | 225,000,000 | 100% |
| 3-4 | 112,500,000 | 50% |
| 5-6 | 56,250,000 | 25% |
| 7-8 | 28,125,000 | 12.5% |
| 9-12 | 14,062,500 | 6.25% |
Core Functions
Transfer
Transfers tokens between addresses.
TransferFrom
Transfers with allowance.
Approve
Approves spending allowance.
InitEmissionState
Initializes the emission schedule with start height and timestamp. Sets up the 12-year emission schedule with halving periods. Only callable by emission contract.
MintGns
Mints new tokens per emission schedule. Only callable by emission contract. Calculates tokens to mint based on elapsed time and updates halving year state.
Usage
These snippets call the GNS realm from a realm function with a current cur
token. Import the package and qualify its function names in integrating code.
1// Transfer tokens
2Transfer(cross(cur), to, amount)
3
4// Approve and transfer
5Approve(cross(cur), spender, amount)
6TransferFrom(cross(cur), from, to, amount)
7
8// Mint per emission schedule (called by emission contract)
9MintGns(cross(cur), recipientAddress)
Distribution
See emission contract for distribution details.
Package gns implements the GNS governance and utility token for GnoSwap.
GNS is a GRC20-compliant token with a deflationary emission schedule. The emission follows a 12-year schedule with halving every 2 years:
- Years 1-2: 225,000,000 GNS per year (100%)
- Years 3-4: 112,500,000 GNS per year (50%)
- Years 5-6: 56,250,000 GNS per year (25%)
- Years 7-8: 28,125,000 GNS per year (12.5%)
- Years 9-12: 14,062,500 GNS per year (6.25%)
Token Economics:
- Maximum Supply: 1,000,000,000 GNS
- Initial Mint: 100,000,000 GNS
- Total Emission: 900,000,000 GNS
Key Functions:
- InitEmissionState: Initializes emission schedule (emission contract only)
- MintGns: Mints tokens per emission schedule (emission contract only)
- Transfer/TransferFrom/Approve: Standard GRC20 operations
The emission state tracks accumulated and remaining amounts per halving year, ensuring precise token distribution according to the schedule.
2
43
func Allowance
ActionAllowance returns the amount of GNS that a spender is allowed to transfer from an owner.
Parameters:
- owner: token owner address
- spender: spender address
Returns:
- allowance: approved amount
func Approve
crossing ActionApprove allows spender to transfer GNS tokens from caller's account.
Parameters:
- cur: Current realm context; callers use cross(cur) when crossing into this realm.
- spender: address authorized to spend
- amount: maximum number of GNS base units spender can transfer
func BalanceOf
ActionBalanceOf returns the GNS balance of a specific address.
Parameters:
- owner: address to check balance for
Returns:
- balance: token balance
func CalculateMintGnsAmount
ActionCalculateMintGnsAmount calculates the GNS base units allocated over an inclusive timestamp range without mutating the live emission state.
Parameters:
- fromTimestamp: inclusive Unix timestamp at which allocation begins
- toTimestamp: inclusive Unix timestamp at which allocation ends
Returns:
- amount: GNS base units allocated in the overlapping schedule interval, or 0 for an invalid or non-overlapping range
func Decimals
ActionDecimals returns the number of decimal places for GNS token.
Returns:
- decimals: number of decimal places
func GetAmountPerSecondPerHalvingYear
ActionGetAmountPerSecondPerHalvingYear returns the configured GNS emission rate for a halving year.
Parameters:
- year: halving year number in [1, 12]
Returns:
- amountPerSecond: GNS base units emitted per second in year, or 0 when year is invalid
func GetCurrentYear
ActionGetCurrentYear returns the halving year containing the current Unix time.
Returns:
- year: current halving year in [1, 12], or 0 when the current time is outside the schedule
func GetEmissionAccumulatedAmountByTimestamp
ActionGetEmissionAccumulatedAmountByTimestamp returns the stored minted allocation for the halving year containing timestamp.
Parameters:
- timestamp: Unix timestamp used to select a halving year
Returns:
- amount: minted GNS base units recorded for that halving year, or 0 outside the schedule
func GetEmissionAmountPerSecondByTimestamp
ActionGetEmissionAmountPerSecondByTimestamp returns the configured GNS emission rate for the halving year containing timestamp.
Parameters:
- timestamp: Unix timestamp whose schedule rate is queried
Returns:
- amount: GNS base units emitted per second for timestamp's halving year, or 0 outside the schedule
func GetEmissionAmountPerSecondInRange
ActionGetEmissionAmountPerSecondInRange returns paired emission-rate change points whose timestamps fall within the requested range.
Parameters:
- fromTime: inclusive Unix timestamp lower bound
- toTime: inclusive Unix timestamp upper bound; a lower value yields nil slices
Returns:
- timestamps: schedule timestamps in the range where the rate changes, including the post-end zero-rate point when applicable
- amounts: GNS base units emitted per second at each corresponding timestamp; same length and order as timestamps
func GetEmissionCreatedHeight
ActionGetEmissionCreatedHeight returns the blockchain height recorded when the emission schedule was created.
Returns:
- height: schedule creation height, or the uninitialized state's stored value
func GetEmissionEndTimestamp
ActionGetEmissionEndTimestamp returns the inclusive Unix timestamp at which the configured emission schedule ends.
Returns:
- timestamp: schedule end timestamp
func GetEmissionLeftAmountByTimestamp
ActionGetEmissionLeftAmountByTimestamp returns the stored unminted allocation for the halving year containing timestamp.
Parameters:
- timestamp: Unix timestamp used to select a halving year
Returns:
- amount: remaining GNS base units recorded for that halving year, or 0 outside the schedule
func GetEmissionStartTimestamp
ActionGetEmissionStartTimestamp returns the inclusive Unix timestamp at which the configured emission schedule begins.
Returns:
- timestamp: schedule start timestamp
func GetHalvingAmountsPerYear
ActionGetHalvingAmountsPerYear returns the total GNS allocation configured for a halving year.
Parameters:
- year: halving year number in [1, 12]
Returns:
- amount: total GNS base units allocated to year, or 0 when year is invalid
func GetHalvingYear
ActionGetHalvingYear returns the halving year containing timestamp.
Parameters:
- timestamp: Unix timestamp to classify against the inclusive 12-year emission schedule
Returns:
- year: halving year in [1, 12], or 0 when timestamp is before the start or after the end
func GetHalvingYearEndTimestamp
ActionGetHalvingYearEndTimestamp returns the inclusive end Unix timestamp for a configured halving year.
Parameters:
- year: halving year number in [1, 12]
Returns:
- timestamp: inclusive end timestamp for year, or 0 when year is invalid
func GetHalvingYearInfo
ActionGetHalvingYearInfo returns the configured halving interval containing timestamp.
Parameters:
- timestamp: Unix timestamp to classify against the inclusive emission schedule
Returns:
- year: halving year in [1, 12], or 0 outside the schedule
- startTimestamp: inclusive start timestamp of year, or 0 when timestamp is outside the schedule
- endTimestamp: inclusive end timestamp of year, or 0 when timestamp is outside the schedule
func GetHalvingYearLeftAmount
ActionGetHalvingYearLeftAmount returns the remaining GNS allocation recorded for a halving year.
Parameters:
- year: halving year number in [1, 12]
Returns:
- amount: unminted GNS base units for year, or 0 when year is invalid
func GetHalvingYearMaxAmount
ActionGetHalvingYearMaxAmount returns the maximum GNS allocation for a halving year.
Parameters:
- year: halving year number in [1, 12]
Returns:
- amount: maximum GNS base units allocated to year, or 0 when year is invalid
func GetHalvingYearMintedAmount
ActionGetHalvingYearMintedAmount returns the minted GNS allocation recorded for a halving year.
Parameters:
- year: halving year number in [1, 12]
Returns:
- amount: minted GNS base units for year, or 0 when year is invalid
func GetHalvingYearStartTimestamp
ActionGetHalvingYearStartTimestamp returns the inclusive start Unix timestamp for a configured halving year.
Parameters:
- year: halving year number in [1, 12]
Returns:
- timestamp: inclusive start timestamp for year, or 0 when year is invalid
func GetInitialMintAmount
ActionGetInitialMintAmount returns the initial GNS allocation minted before emissions.
Returns:
- initialAmount: number of GNS base units in the initial mint
func GetMaxEmissionAmount
ActionGetMaxEmissionAmount returns the configured lifetime GNS emission cap in base units.
Returns:
- maxAmount: maximum number of GNS base units available for emission
func GetMaximumSupply
ActionGetMaximumSupply returns the maximum possible GNS token supply in base units.
Returns:
- maximumSupply: configured total supply cap, including the initial mint and emissions
func InitEmissionState
crossing ActionInitEmissionState initializes the emission schedule. It creates the 12-year schedule with two-year halving periods.
Parameters:
- cur: Current realm context; callers use cross(cur) when crossing into this realm.
- createdHeight: block height when the schedule is initialized
- startTimestamp: Unix timestamp when emission begins
Only callable by the emission contract.
func IsEmissionActive
ActionIsEmissionActive reports whether emission is initialized and the current Unix time lies within the inclusive emission schedule.
Returns:
- active: true during the configured schedule, including its endpoints; false otherwise
func IsEmissionEnded
ActionIsEmissionEnded reports whether the current Unix time is after the emission end timestamp.
Returns:
- ended: true after the configured schedule's end; false at or before that timestamp
func IsEmissionInitialized
ActionIsEmissionInitialized reports whether the emission state has non-zero creation height and start timestamp.
Returns:
- initialized: true when both initialization fields are set; false otherwise
func KnownAccounts
ActionKnownAccounts returns the number of addresses that have held GNS.
Returns:
- count: number of known accounts
func LastMintedTimestamp
ActionLastMintedTimestamp returns the timestamp of the last GNS emission mint.
Returns:
- timestamp: last minted timestamp
func LeftEmissionAmount
ActionLeftEmissionAmount returns the remaining GNS tokens available for emission.
Returns:
- amount: remaining emission amount
func MintGns
crossing ActionMintGns mints new GNS tokens according to the emission schedule.
Parameters:
- cur: Current realm context; callers use cross(cur) when crossing into this realm.
- address: recipient address for minted tokens
Returns:
- amount: GNS minted for the current timestamp; zero when emission is already processed for that timestamp or the schedule has ended
Only callable by emission contract.
Note: Halt check is performed by the caller (emission.MintAndDistributeGns) to allow graceful handling. This function assumes caller has already verified halt status before invoking.
func MintedEmissionAmount
ActionMintedEmissionAmount returns the total GNS tokens minted through emission, excluding the initial mint amount.
Returns:
- amount: total minted emission amount
func Name
ActionName returns the name of the GNS token.
Returns:
- name: token name
func Render
Render returns token information for web interface.
Parameters:
- path: render path for specific views
Returns:
- output: formatted token information
func Symbol
ActionSymbol returns the symbol of the GNS token.
Returns:
- symbol: token symbol
func TotalSupply
ActionTotalSupply returns the total supply of GNS tokens in circulation.
Returns:
- supply: total token supply
func Transfer
crossing ActionTransfer transfers GNS tokens from caller to recipient.
Parameters:
- cur: Current realm context; callers use cross(cur) when crossing into this realm.
- to: recipient address
- amount: number of GNS base units to transfer
func TransferFrom
crossing ActionTransferFrom transfers GNS tokens on behalf of owner.
Parameters:
- cur: Current realm context; callers use cross(cur) when crossing into this realm.
- from: token owner address
- to: recipient address
- amount: number of GNS base units to transfer
func NewEmissionState
ActionNewEmissionState creates an emission state and its 12-year halving schedule.
Parameters:
- createdHeight: blockchain height recorded as the schedule's creation height.
- startTimestamp: Unix timestamp at which the first halving year begins.
Returns:
- state: newly allocated emission state with an end timestamp and initialized halving data.
func GetHalvingInfo
ActionGetHalvingInfo returns an independent copy of the configured 12-year halving schedule.
Returns:
- halvingData: deep copy of schedule timestamps, allocations, minted amounts, remaining amounts, and rates
func NewHalvingData
ActionNewHalvingData creates a 12-year HalvingData emission schedule starting at startTimestamp. Each year receives configured timestamps, allocation, zero minted amount, remaining allocation, and an integer-truncated per-second rate.
Parameters:
- startTimestamp: Unix timestamp at which halving year 1 begins
Returns:
- halvingData: initialized schedule with years [1, 12] and their derived values
2
type EmissionState
structEmissionState manages emission state and halving data. Tracks emission timing, status, and halving year information for 12-year schedule.
type HalvingData
structHalvingData stores emission data for each halving period. Contains timestamps, amounts, and rates for the 12-year emission schedule.
11
- chain stdlib
- chain/runtime stdlib
- gno.land/p/gnoswap/gnsmath/v1 package
- gno.land/p/gnoswap/utils/v1 package
- gno.land/p/nt/grc20/v0 package
- gno.land/p/nt/ufmt/v0 package
- gno.land/r/gnoswap/access/v1 realm
- gno.land/r/gnoswap/rbac/v1 realm
- gno.land/r/nt/grc20reg/v0 realm
- strings stdlib
- time stdlib