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
- 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.
Burn
Burns tokens from supply.
Usage
1// Transfer tokens
2Transfer(to, amount)
3
4// Approve and transfer
5Approve(spender, amount)
6TransferFrom(from, to, amount)
7
8// Mint per emission schedule (called by emission contract)
9MintGns(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)
- Burn: Burns tokens from circulation (admin 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
44
func Allowance
ActionAllowance returns the amount of GNS that a spender is allowed to transfer from an owner.
func Approve
crossing ActionApprove allows spender to transfer GNS tokens from caller's account.
Parameters:
- spender: address authorized to spend
- amount: maximum amount spender can transfer
func BalanceOf
ActionBalanceOf returns the GNS balance of a specific address.
func CalculateMintGnsAmount
ActionCalculateMintGnsAmount returns the amount of GNS that would be minted for the given timestamp range.
func Decimals
ActionDecimals returns the number of decimal places for GNS token.
func GetAmountPerSecondPerHalvingYear
ActionGetAmountPerSecondPerHalvingYear returns the emission rate per second for the specified halving year.
func GetCurrentYear
ActionGetCurrentYear returns the current halving year (1-12) or 0 if emission is not active.
func GetEmissionAccumulatedAmountByTimestamp
ActionGetEmissionAccumulatedAmountByTimestamp returns the accumulated emission amount for the halving year at given timestamp. Returns 0 if timestamp is outside emission period.
func GetEmissionAmountPerSecondByTimestamp
ActionGetEmissionAmountPerSecondByTimestamp returns the emission rate per second for a given timestamp. Returns 0 if timestamp is outside emission period.
func GetEmissionAmountPerSecondInRange
ActionGetEmissionAmountPerSecondInRange returns halving timestamps and emission rates for the given time range. Returns two slices: timestamps when halving periods start and corresponding emission rates per second.
func GetEmissionCreatedHeight
ActionGetEmissionCreatedHeight returns the block height when emission schedule was created.
func GetEmissionEndTimestamp
ActionGetEmissionEndTimestamp returns the timestamp when emission schedule ends.
func GetEmissionLeftAmountByTimestamp
ActionGetEmissionLeftAmountByTimestamp returns the remaining emission amount for the halving year at given timestamp. Returns 0 if timestamp is outside emission period.
func GetEmissionStartTimestamp
ActionGetEmissionStartTimestamp returns the timestamp when emission schedule begins.
func GetHalvingAmountsPerYear
ActionGetHalvingAmountsPerYear returns the total emission amount allocated for the specified year. Returns 0 if year is outside the valid range (1-12).
func GetHalvingYear
ActionGetHalvingYear returns the halving year (1-12) for a given timestamp.
func GetHalvingYearAccuAmount
ActionGetHalvingYearAccuAmount returns the accumulated token issuance for the specified halving year.
func GetHalvingYearEndTimestamp
ActionGetHalvingYearEndTimestamp returns the end timestamp for the specified halving year.
func GetHalvingYearInfo
ActionGetHalvingYearInfo returns the halving year, start timestamp, and end timestamp for a given timestamp. Returns (year, startTimestamp, endTimestamp). Year is 0 if outside emission period.
func GetHalvingYearLeftAmount
ActionGetHalvingYearLeftAmount returns the remaining token issuance for the specified halving year.
func GetHalvingYearMaxAmount
ActionGetHalvingYearMaxAmount returns the maximum token issuance for the specified halving year.
func GetHalvingYearMintAmount
ActionGetHalvingYearMintAmount returns the amount of tokens minted for the specified halving year.
func GetHalvingYearStartTimestamp
ActionGetHalvingYearStartTimestamp returns the start timestamp for the specified halving year.
func GetInitialMintAmount
ActionGetInitialMintAmount returns the initial amount of gns tokens to be minted.
func GetMaxEmissionAmount
ActionGetMaxEmissionAmount returns the maximum amount of emission allowed.
func GetMaximumSupply
ActionGetMaximumSupply returns the maximum supply of gns tokens.
func InitEmissionState
crossing ActionInitEmissionState initializes emission schedule with start timestamp. Only callable by emission contract. Sets up 12-year emission schedule with halving every 2 years. Panics if caller is not emission contract.
func IsEmissionActive
ActionIsEmissionActive returns true if emission is currently active based on current time.
func IsEmissionEnded
ActionIsEmissionEnded returns true if emission schedule has completed.
func IsEmissionInitialized
ActionIsEmissionInitialized returns true if emission schedule has been initialized.
func KnownAccounts
ActionKnownAccounts returns the number of addresses that have held GNS.
func LastMintedTimestamp
ActionLastMintedTimestamp returns the timestamp of the last GNS emission mint.
func LeftEmissionAmount
ActionLeftEmissionAmount returns the remaining GNS tokens available for emission.
func MintGns
crossing ActionMintGns mints new GNS tokens according to the emission schedule.
Parameters:
- address: recipient address for minted tokens
Returns amount minted. 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.
func Name
ActionName returns the name of the GNS token.
func Render
Render returns token information for web interface.
func Symbol
ActionSymbol returns the symbol of the GNS token.
func TotalSupply
ActionTotalSupply returns the total supply of GNS tokens in circulation.
func Transfer
crossing ActionTransfer transfers GNS tokens from caller to recipient.
Parameters:
- to: recipient address
- amount: amount to transfer
func TransferFrom
crossing ActionTransferFrom transfers GNS tokens on behalf of owner.
Parameters:
- from: token owner address
- to: recipient address
- amount: amount to transfer
func NewEmissionState
ActionNewEmissionState creates a new EmissionState with specified start height and timestamp. Calculates emission end time based on 12-year schedule and initializes halving data.
func GetHalvingInfo
ActionGetHalvingInfo returns a clone of the halving data.
func NewHalvingData
ActionNewHalvingData creates a new HalvingData instance with emission schedule. Initializes 12 years of halving periods with timestamps, amounts, and rates based on startTimestamp.
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.
12
- chain stdlib
- chain/runtime stdlib
- gno.land/p/demo/tokens/grc20 package
- gno.land/p/gnoswap/gnsmath package
- gno.land/p/gnoswap/rbac package
- gno.land/p/gnoswap/utils package
- gno.land/p/nt/ufmt/v0 package
- gno.land/r/demo/defi/grc20reg realm
- gno.land/r/gnoswap/access realm
- gno.land/r/gnoswap/rbac realm
- strings stdlib
- time stdlib