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

Package governor is a simplified on-chain governance realm inspired by OpenZeppelin's Governor. Anyone may open a pro...

Readme View source

Governor

⚠️ Experimental — generated with no human supervision by the daily MCP pipeline (Solidity→Gno port). Not audited. See r/moul/x/daily.


A simplified on-chain governance realm inspired by OpenZeppelin's Governor. It ports the core proposal → vote → execute lifecycle to Gno: Propose records a proposal's snapshot height and a deadline of ChainHeight() + votingPeriod, CastVote gives every address a single equally-weighted vote (1 address = 1 vote, tracked in an avl voter set), and State computes Active / Succeeded / Defeated from the deadline versus the current chain height plus whether the for tally beats against. Execute finalizes a Succeeded proposal.

Unlike the ERC20Votes-weighted original, voting power here is flat (one address, one vote) and there is no timelock — the emphasis is on a clean, deterministic state machine driven by block height.

Example calls

# open a proposal (returns its id)
Propose("Fund the docs working group for Q3")

# vote: 0=against, 1=for, 2=abstain (one vote per address)
CastVote(1, 1)

# read the current state: Active | Succeeded | Defeated | Executed
State(1)

# once past the deadline with for > against, finalize it
Execute(1)

Render("") lists every proposal with its tally bars (▓░) and state.

What changed in v1

State moved from a hand-rolled avl.Tree + nextID + zero-padding helper to p/moul/kit/store, which keys entries by seqid instead of a fixed-width decimal string.

v0 padded ids to width 12. Past that width the padding stops and the tree orders "1000000000000" before "999999999999", so every list this realm renders would be wrong from that entry on. store keys are 8 big-endian bytes whose order is numeric for every uint64, so there is no width left to outgrow.

Proposal loses its ID field, which the store now owns, and the local mustGet becomes one line: the store's labelled MustGet panics governor: proposal #7 not found, the same information v0 assembled by hand. The totalCount counter is gone too: with no deletion, the highest id ever assigned is the count, so LastID() answers it. Each proposal keeps its own address-keyed votes tree, which the store does not cover. Proposal ids already started at 1, so nothing shifts.

This is a storage change, which under this repo's versioning rule is a compatibility change, hence a new version rather than an edit in place. v0 stays live and untouched.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

Dependency graph:

gno.land/r/moul/x/daily/governor/v1 dependency graph

🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.

Overview

Package governor is a simplified on-chain governance realm inspired by OpenZeppelin's Governor. Anyone may open a proposal; every address gets a single equally-weighted vote (1 address = 1 vote); a proposal succeeds when its voting deadline has passed and the "for" tally strictly beats "against".

Constants 2

Functions 5

func CastVote

crossing Action
1func CastVote(cur realm, id int64, support int)
source

CastVote records one vote for the caller on proposal id. support is 0=against, 1=for, 2=abstain. One address may vote at most once per proposal, and voting is only allowed while the proposal is Active.

func Execute

crossing Action
1func Execute(cur realm, id int64)
source

Execute marks a Succeeded proposal as executed. It panics unless the proposal has reached the Succeeded state.

func Propose

crossing Action
1func Propose(cur realm, description string) int64
source

Propose opens a new proposal and returns its id. The snapshot height and deadline are recorded from the current chain height.

func Render

1func Render(path string) string
source

Render lists all proposals with their tallies and states as Markdown.

func State

Action
1func State(id int64) string
source

State returns the current lifecycle state of proposal id.

Types 1

type Proposal

struct
 1type Proposal struct {
 2	Proposer       address
 3	Description    string
 4	SnapshotHeight int64
 5	Deadline       int64
 6	For            int64
 7	Against        int64
 8	Abstain        int64
 9	Executed       bool
10	votes          *avl.Tree // voter address (string) -> support (int)
11}
source

Proposal is a single governance proposal. It carries no ID field: the id belongs to the store, which hands it back on lookup and iteration.

Imports 7

Source Files 5