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

v1 source realm

Readme View source

Governance

Decentralized protocol governance via GNS staking and voting.

Overview

Governance system enables GNS holders to stake for xGNS voting power, create proposals, and vote on protocol changes. For more details, check out docs.

Configuration

The governance.Config type defines the core governance parameters. All values can be modified through governance proposals. This type can be found in the config.gno file.

Field Description Default
VotingStartDelay Delay before voting starts after proposal creation 1 day
VotingPeriod Duration for collecting votes 7 days
VotingWeightSmoothingDuration Period for averaging voting weight (prevents flash loans) 1 day
Quorum Percentage of active xGNS required for proposal passage 50%
ProposalCreationThreshold Minimum xGNS amount required to create a proposal 1,000 xGNS
ExecutionDelay Waiting period after voting ends before execution 1 day
ExecutionWindow Time window during which an approved proposal can be executed 30 days

Core Mechanics

Staking Flow

1GNS → Stake → xGNS (voting power) → Delegate → Vote
  1. Stake GNS to receive equal xGNS
  2. Delegate voting power (can be self)
  3. Vote on proposals with delegated power
  4. 7-day lockup for undelegation

Proposal Types

  • Text: Signal proposals without execution
  • CommunityPoolSpend: Treasury disbursements
  • ParameterChange: Protocol parameter updates

Proposal Lifecycle

Creation

  • Requires 1,000 xGNS balance
  • One active proposal per address
  • Valid type and parameters required

Voting

  • 1 day delay before voting starts
  • 7 days voting period
  • Weight = 24hr average delegation (prevents flash loans)

Execution

A proposal is considered valid and executable when:

  • The voting period has ended
  • Total votes meet the quorum threshold (50% of xGNS total supply)
  • YES votes strictly exceed NO votes (ties do not pass)
  • The execution delay period (configured via ExecutionDelay default: 24 hours) has passed after voting ends
  • Within the execution window period (configured via ExecutionWindow default: 30 days)
    • ExecutionDelay and ExecutionWindow are configured through the governance.Config type.
  • Anyone can trigger execution once conditions are met

Technical Details

Vote Weight Calculation

1// 24-hour average prevents manipulation
2snapshot1 = getDelegationAt(proposalTime - 24hr)
3snapshot2 = getDelegationAt(proposalTime)
4voteWeight = (snapshot1 + snapshot2) / 2

Quorum Calculation

1activeXGNS = totalXGNS - launchpadXGNS
2quorumAmount = activeXGNS * quorumPercent / 100  // quorumPercent defaults to 50

The quorum threshold is calculated based on the Quorum percentage (default: 50%) of the active xGNS supply at the time of proposal creation. A proposal passes only when total votes reach quorum and the accumulated YES votes strictly exceed the accumulated NO votes.

Rewards Distribution

xGNS holders earn protocol fees:

1userShare = (userXGNS / totalXGNS) * protocolFees

Usage

 1// Stake GNS for xGNS
 2Delegate(amount, delegateTo)
 3
 4// Create proposal
 5ProposeText(title, description, body)
 6ProposeCommunityPoolSpend(recipient, amount)
 7ProposeParameterChange(title, description, numToExecute, executions)
 8
 9// Vote on proposal
10Vote(proposalId, true)  // YES
11Vote(proposalId, false) // NO
12
13// Execute after timelock
14Execute(proposalId)
15
16// Undelegate (7-day lockup)
17Undelegate()

Security

  • Flash loan protection via vote smoothing
  • Sybil resistance through stake weighting
  • Timelock prevents rushed execution
  • Single proposal limit per address
  • Dynamic quorum excludes inactive xGNS

Constants 1

const GNS_TOKEN_KEY, HALT_PATH, RBAC_PATH, ACCESS_PATH, EMISSION_PATH, COMMON_PATH, POOL_PATH, POSITION_PATH, ROUTER_PATH, STAKER_PATH, LAUNCHPAD_PATH, PROTOCOL_FEE_PATH, COMMUNITY_POOL_PATH, GOV_GOVERNANCE_PATH, GOV_STAKER_PATH

 1const (
 2	GNS_TOKEN_KEY       = "gno.land/r/gnoswap/gns.GNS"
 3	HALT_PATH           = "gno.land/r/gnoswap/halt"
 4	RBAC_PATH           = "gno.land/r/gnoswap/rbac"
 5	ACCESS_PATH         = "gno.land/r/gnoswap/access"
 6	EMISSION_PATH       = "gno.land/r/gnoswap/emission"
 7	COMMON_PATH         = "gno.land/r/gnoswap/common"
 8	POOL_PATH           = "gno.land/r/gnoswap/pool"
 9	POSITION_PATH       = "gno.land/r/gnoswap/position"
10	ROUTER_PATH         = "gno.land/r/gnoswap/router"
11	STAKER_PATH         = "gno.land/r/gnoswap/staker"
12	LAUNCHPAD_PATH      = "gno.land/r/gnoswap/launchpad"
13	PROTOCOL_FEE_PATH   = "gno.land/r/gnoswap/protocol_fee"
14	COMMUNITY_POOL_PATH = "gno.land/r/gnoswap/community_pool"
15	GOV_GOVERNANCE_PATH = "gno.land/r/gnoswap/gov/governance"
16	GOV_STAKER_PATH     = "gno.land/r/gnoswap/gov/staker"
17)
source

Package paths

Functions 17

func NewGovernanceV1

Action
1func NewGovernanceV1(
2	governanceStore governance.IGovernanceStore,
3	stakerAccessor governance.GovStakerAccessor,
4) governance.IGovernance
source

func NewProposalCommunityPoolSpendData

Action
1func NewProposalCommunityPoolSpendData(
2	tokenPath string,
3	to address,
4	amount int64,
5	communityPoolPackagePath string,
6) *governance.ProposalData
source

NewProposalCommunityPoolSpendData creates proposal data for a community pool spend proposal. Automatically generates the execution message for the token transfer.

Parameters:

  • tokenPath: path of the token to transfer
  • to: recipient address for the transfer
  • amount: amount of tokens to transfer
  • communityPoolPackagePath: package path of the community pool contract

Returns:

  • *ProposalData: proposal data configured for community pool spending

func NewProposalExecutionData

Action
1func NewProposalExecutionData(numToExecute int64, executions string) *governance.ProposalData
source

NewProposalExecutionData creates proposal data for a parameter change proposal. Each message in executions should be formatted as <pkgPath>*EXE*<function>*EXE*<params>, separated by *GOV* when there are multiple messages.

Parameters:

  • numToExecute: number of parameter changes to execute
  • executions: raw encoded execution string with parameter changes

Returns:

  • *ProposalData: proposal data configured for parameter changes

func NewProposalScheduleStatus

Action
1func NewProposalScheduleStatus(
2	votingStartDelay,
3	votingPeriod,
4	executionDelay,
5	executionWindow,
6	createdAt int64,
7) *governance.ProposalScheduleStatus
source

NewProposalScheduleStatus creates a new schedule status with calculated timestamps. This constructor takes the governance timing parameters and calculates all important timestamps for the proposal's lifecycle.

Parameters:

  • votingStartDelay: delay before voting starts (seconds)
  • votingPeriod: duration of voting period (seconds)
  • executionDelay: delay before execution can start (seconds)
  • executionWindow: window during which execution is allowed (seconds)
  • createdAt: timestamp when proposal was created

Returns:

  • *ProposalScheduleStatus: new schedule status with calculated times

func NewProposalStatus

Action
1func NewProposalStatus(
2	config governance.Config,
3	maxVotingWeight int64,
4	executable bool,
5	createdAt int64,
6	quorumWeight int64,
7) *governance.ProposalStatus
source

NewProposalStatus creates a new proposal status with the specified configuration. This initializes all status components with the governance configuration and timing.

Parameters:

  • config: governance configuration to use
  • maxVotingWeight: maximum voting weight for this proposal
  • executable: whether this proposal type can be executed
  • createdAt: timestamp when proposal was created

Returns:

  • *ProposalStatus: new proposal status instance

func NewProposalTextData

Action
1func NewProposalTextData() *governance.ProposalData
source

NewProposalTextData creates proposal data for a text proposal. Text proposals have no additional data requirements.

Returns:

  • *ProposalData: proposal data configured for text proposal

func NewParameterHandlerOptions

Action
1func NewParameterHandlerOptions(
2	pkgPath,
3	function string,
4	paramCount int,
5	handlerFunc func(_ int, rlm realm, _ []string) error,
6	paramValidators ...paramValidator,
7) ParameterHandler
source

NewParameterHandlerOptions creates a new parameter handler with the specified configuration.

Parameters:

  • pkgPath: package path of the target contract
  • function: function name to be called
  • paramCount: expected number of parameters
  • handlerFunc: function that executes the parameter change
  • paramValidators: optional validators for each parameter (must match paramCount if provided)

Returns:

  • ParameterHandler: configured parameter handler interface

func CreateParameterHandlers

Action
1func CreateParameterHandlers() *ParameterRegistry
source

createParameterHandlers initializes and configures all supported parameter handlers. This function defines all the parameter changes that can be executed through governance proposals. It covers configuration changes for various system components including pools, staking, fees, etc.

Returns:

  • *ParameterRegistry: fully configured registry with all supported handlers

func NewParameterRegistry

Action
1func NewParameterRegistry() *ParameterRegistry
source

NewParameterRegistry creates a new empty parameter registry.

Returns:

  • *ParameterRegistry: new registry instance

Types 11

type ParameterHandler

interface
1type ParameterHandler interface {
2	// Execute processes the parameters and applies the changes to the system.
3	// The `_ int, cur realm` discriminator pair forwards the governance proxy's
4	// realm value into the handler so any cross-realm calls inside the closure
5	// run under the proxy's identity (the only address with caller-allowlist
6	// permission against the targeted /r/ realms).
7	Execute(_ int, rlm realm, params []string) error
8}
source

ParameterHandler interface defines the contract for parameter execution handlers. Each handler is responsible for executing specific parameter changes in the system.

type ParameterHandlerOptions

struct
1type ParameterHandlerOptions struct {
2	pkgPath         string                                   // Package path of the target contract
3	function        string                                   // Function name to be called
4	paramCount      int                                      // Expected number of parameters
5	handlerFunc     func(_ int, rlm realm, _ []string) error // Function that executes the parameter change
6	paramValidators []paramValidator                         // Optional per-parameter validators for proposal-time checks
7}
source

ParameterHandlerOptions contains the configuration and execution logic for a parameter handler. This struct encapsulates all information needed to identify and execute a parameter change.

NOTE: handlerFunc uses `rlm realm` (rather than `cur realm`) as the realm parameter name. The v2 preprocessor reserves the `cur` name for the first realm-type parameter of top-level crossing function declarations and `t.Run` closures only; using it as the realm-parameter name on a multi-parameter struct-field function value trips a parser check ("only the first realm type argument of a crossing function may have name `cur`"). Naming it `rlm` keeps the lowering identical without the syntax constraint.

Methods on ParameterHandlerOptions

func Execute

method on ParameterHandlerOptions
1func (h *ParameterHandlerOptions) Execute(_ int, rlm realm, params []string) error
source

Execute validates parameter count and executes the handler function. This method ensures the correct number of parameters are provided before execution.

Parameters:

  • cur: governance proxy realm threaded in by the caller; forwarded to the wrapped closure so its cross-realm calls run under the proxy.
  • params: slice of string parameters to pass to the handler

Returns:

  • error: execution error if parameter count mismatch or handler execution fails

func HandlerKey

method on ParameterHandlerOptions
1func (h *ParameterHandlerOptions) HandlerKey() string
source

HandlerKey generates a unique key for this handler based on package path and function name.

Returns:

  • string: unique identifier for the handler

func ValidateParams

method on ParameterHandlerOptions
1func (h *ParameterHandlerOptions) ValidateParams(params []string) error
source

ValidateParams runs parameter count and per-parameter validation without executing the handler.

type ParameterRegistry

struct
1type ParameterRegistry struct {
2	handlers map[string]ParameterHandlerOptions // Map storing handler configurations keyed by package:function
3}
source

ParameterRegistry manages the collection of parameter handlers for governance execution. This registry allows proposals to execute parameter changes across different system contracts.

Methods on ParameterRegistry

func Handler

method on ParameterRegistry
1func (r *ParameterRegistry) Handler(key string) (ParameterHandler, error)
source

handler retrieves a parameter handler by package path and function name. This method is used during proposal execution to find the appropriate handler.

Parameters:

  • pkgPath: package path of the target contract
  • function: function name to be called

Returns:

  • ParameterHandler: the matching parameter handler
  • error: error if handler not found or casting fails

func Register

method on ParameterRegistry
1func (r *ParameterRegistry) Register(handler ParameterHandlerOptions)
source

register adds a new parameter handler to the registry. Each handler is identified by a unique combination of package path and function name.

Parameters:

  • handler: parameter handler configuration to register

type ProposalActionStatusResolver

struct
1type ProposalActionStatusResolver struct {
2	*governance.ProposalActionStatus
3}
source

Methods on ProposalActionStatusResolver

func Execute

method on ProposalActionStatusResolver
1func (p *ProposalActionStatusResolver) Execute(
2	executedAt, executedHeight int64,
3	executedBy address,
4) error
source

execute marks the proposal as executed and records execution details. This method validates that the proposal is eligible for execution.

Parameters:

  • executedAt: timestamp when execution occurred
  • executedHeight: block height when execution occurred
  • executedBy: address performing the execution

Returns:

  • error: already canceled error if proposal action status is already canceled

type ProposalDataResolver

struct
1type ProposalDataResolver struct {
2	*governance.ProposalData
3}
source

ProposalDataResolver handles business logic for proposal data.

Methods on ProposalDataResolver

func ParameterChangesInfos

method on ProposalDataResolver
1func (r *ProposalDataResolver) ParameterChangesInfos() ([]governance.ParameterChangeInfo, error)
source

ParameterChangesInfos parses the execution messages and returns structured parameter change information. Each message is expected to be in format: pkgPath*EXE*function*EXE*params

Returns:

  • []ParameterChangeInfo: slice of parsed parameter change information
  • error: validation error if any execution message is malformed

func Validate

method on ProposalDataResolver
1func (r *ProposalDataResolver) Validate() error
source

Validate performs type-specific validation of the proposal data. Different proposal types have different validation requirements.

Returns:

  • error: validation error if data is invalid

type ProposalMetadataResolver

struct
1type ProposalMetadataResolver struct {
2	*governance.ProposalMetadata
3}
source

Methods on ProposalMetadataResolver

func Validate

method on ProposalMetadataResolver
1func (r *ProposalMetadataResolver) Validate() error
source

Validate performs comprehensive validation of the proposal metadata. Checks title and description length and content requirements.

Returns:

  • error: validation error if metadata is invalid

type ProposalResolver

struct
1type ProposalResolver struct {
2	*governance.Proposal
3	statusResolver   *ProposalStatusResolver
4	dataResolver     *ProposalDataResolver
5	metadataResolver *ProposalMetadataResolver
6}
source

Methods on ProposalResolver

func CommunityPoolSpendTokenPath

method on ProposalResolver
1func (r *ProposalResolver) CommunityPoolSpendTokenPath() string
source

CommunityPoolSpendTokenPath returns the token path for community pool spend proposals. Returns empty string for other proposal types.

func IsActive

method on ProposalResolver
1func (r *ProposalResolver) IsActive(current int64) bool
source

IsActive determines if the proposal is currently active (can be voted on or executed). A proposal is considered active if it's not rejected, expired, executed, or canceled.

func IsExecutable

method on ProposalResolver
1func (r *ProposalResolver) IsExecutable(current int64) bool
source

IsExecutable determines if the proposal can be executed at the given time. Only executable proposal types that have passed voting can be executed.

func IsVotingPeriod

method on ProposalResolver
1func (r *ProposalResolver) IsVotingPeriod(votedAt int64) bool
source

IsVotingPeriod checks if the proposal is currently in its voting period.

func Status

method on ProposalResolver
1func (r *ProposalResolver) Status(current int64) string
source

Status returns the current status string of the proposal at the given time.

func StatusType

method on ProposalResolver
1func (r *ProposalResolver) StatusType(current int64) governance.ProposalStatusType
source

StatusType returns the current status type of the proposal at the given time.

func Validate

method on ProposalResolver
1func (r *ProposalResolver) Validate() error
source

Validate performs comprehensive validation of the proposal data and metadata. This ensures all proposal components meet requirements before storage.

func Vote

method on ProposalResolver
1func (r *ProposalResolver) Vote(votedYes bool, weight int64) error
source

vote records a vote for this proposal and updates vote tallies. This is an internal method called during voting process.

func VotingTotalWeight

method on ProposalResolver
1func (r *ProposalResolver) VotingTotalWeight() int64
source

VotingTotalWeight returns total weight of all votes cast.

type ProposalScheduleStatusResolver

struct
1type ProposalScheduleStatusResolver struct {
2	*governance.ProposalScheduleStatus
3}
source

Methods on ProposalScheduleStatusResolver

func IsPassedActiveAt

method on ProposalScheduleStatusResolver
1func (p *ProposalScheduleStatusResolver) IsPassedActiveAt(current int64) bool
source

IsPassedActiveAt checks if the current time has passed the voting start time. When true, the proposal enters its active voting period.

Parameters:

  • current: timestamp to check against

Returns:

  • bool: true if voting period has started

func IsPassedCreatedAt

method on ProposalScheduleStatusResolver
1func (p *ProposalScheduleStatusResolver) IsPassedCreatedAt(current int64) bool
source

IsPassedCreatedAt checks if the current time has passed the proposal creation time. This is always true once a proposal exists.

Parameters:

  • current: timestamp to check against

Returns:

  • bool: true if current time is at or after creation time

func IsPassedExecutableAt

method on ProposalScheduleStatusResolver
1func (p *ProposalScheduleStatusResolver) IsPassedExecutableAt(current int64) bool
source

IsPassedExecutableAt checks if the current time has passed the execution start time. When true, approved proposals can be executed (after execution delay).

Parameters:

  • current: timestamp to check against

Returns:

  • bool: true if execution window has started

func IsPassedExpiredAt

method on ProposalScheduleStatusResolver
1func (p *ProposalScheduleStatusResolver) IsPassedExpiredAt(current int64) bool
source

IsPassedExpiredAt checks if the current time has passed the execution expiration time. When true, the proposal can no longer be executed and has expired.

Parameters:

  • current: timestamp to check against

Returns:

  • bool: true if execution window has expired

func IsPassedVotingEndedAt

method on ProposalScheduleStatusResolver
1func (p *ProposalScheduleStatusResolver) IsPassedVotingEndedAt(current int64) bool
source

IsPassedVotingEndedAt checks if the current time has passed the voting end time. When true, no more votes can be cast on the proposal.

Parameters:

  • current: timestamp to check against

Returns:

  • bool: true if voting period has ended

type ProposalStatusResolver

struct
1type ProposalStatusResolver struct {
2	*governance.ProposalStatus
3	scheduleResolver     *ProposalScheduleStatusResolver
4	actionStatusResolver *ProposalActionStatusResolver
5	voteStatusResolver   *ProposalVoteStatusResolver
6}
source

Methods on ProposalStatusResolver

func IsActive

method on ProposalStatusResolver
1func (p *ProposalStatusResolver) IsActive(current int64) bool
source

IsActive checks if the proposal is in active voting status.

Parameters:

  • current: timestamp to check status at

Returns:

  • bool: true if proposal is active (voting period)

func IsCanceled

method on ProposalStatusResolver
1func (p *ProposalStatusResolver) IsCanceled(current int64) bool
source

IsCanceled checks if the proposal has been canceled.

Parameters:

  • current: timestamp to check status at

Returns:

  • bool: true if proposal has been canceled

func IsExecutable

method on ProposalStatusResolver
1func (p *ProposalStatusResolver) IsExecutable(current int64) bool
source

IsExecutable checks if the proposal is in executable status.

Parameters:

  • current: timestamp to check status at

Returns:

  • bool: true if proposal can be executed

func IsExecuted

method on ProposalStatusResolver
1func (p *ProposalStatusResolver) IsExecuted(current int64) bool
source

IsExecuted checks if the proposal has been executed.

Parameters:

  • current: timestamp to check status at

Returns:

  • bool: true if proposal has been executed

func IsExpired

method on ProposalStatusResolver
1func (p *ProposalStatusResolver) IsExpired(current int64) bool
source

IsExpired checks if the proposal execution window has expired.

Parameters:

  • current: timestamp to check status at

Returns:

  • bool: true if proposal has expired

func IsPassed

method on ProposalStatusResolver
1func (p *ProposalStatusResolver) IsPassed(current int64) bool
source

IsPassed checks if the proposal has passed voting.

Parameters:

  • current: timestamp to check status at

Returns:

  • bool: true if proposal has passed

func IsRejected

method on ProposalStatusResolver
1func (p *ProposalStatusResolver) IsRejected(current int64) bool
source

IsRejected checks if the proposal has been rejected by voting.

Parameters:

  • current: timestamp to check status at

Returns:

  • bool: true if proposal was rejected

func IsUpcoming

method on ProposalStatusResolver
1func (p *ProposalStatusResolver) IsUpcoming(current int64) bool
source

IsUpcoming checks if the proposal is in upcoming status.

Parameters:

  • current: timestamp to check status at

Returns:

  • bool: true if proposal is upcoming

func StatusType

method on ProposalStatusResolver
1func (p *ProposalStatusResolver) StatusType(current int64) governance.ProposalStatusType
source

StatusType determines the current status of the proposal based on timing, voting, and actions. This is the main status calculation method that considers all factors.

Parameters:

  • current: current timestamp to evaluate status at

Returns:

  • ProposalStatusType: current status of the proposal

func TotalVoteWeight

method on ProposalStatusResolver
1func (p *ProposalStatusResolver) TotalVoteWeight() int64
source

TotalVoteWeight returns the total weight of all votes cast.

Returns:

  • int64: total vote weight

type ProposalVoteStatusResolver

struct
1type ProposalVoteStatusResolver struct {
2	*governance.ProposalVoteStatus
3}
source

Methods on ProposalVoteStatusResolver

func AddNoVoteWeight

method on ProposalVoteStatusResolver
1func (p *ProposalVoteStatusResolver) AddNoVoteWeight(nay int64) error
source

addNoVoteWeight adds the specified weight to the "no" vote tally. This is called when a user votes "no" on the proposal.

Parameters:

  • nay: vote weight to add to "no" votes

Returns:

  • error: always nil (reserved for future validation)

func AddYesVoteWeight

method on ProposalVoteStatusResolver
1func (p *ProposalVoteStatusResolver) AddYesVoteWeight(yea int64) error
source

addYesVoteWeight adds the specified weight to the "yes" vote tally. This is called when a user votes "yes" on the proposal.

Parameters:

  • yea: vote weight to add to "yes" votes

Returns:

  • error: always nil (reserved for future validation)

func IsPassed

method on ProposalVoteStatusResolver
1func (p *ProposalVoteStatusResolver) IsPassed() bool
source

IsPassed determines if the proposal has passed the voting requirements. A proposal passes when quorum is reached and "yes" votes strictly exceed "no" votes.

func TotalVoteWeight

method on ProposalVoteStatusResolver
1func (p *ProposalVoteStatusResolver) TotalVoteWeight() int64
source

TotalVoteWeight returns the total weight of all votes cast (yes + no).

Returns:

  • int64: combined weight of all votes

Imports 26

Source Files 22