udao.gno
2.42 Kb · 77 lines
1// Package udao defines minimal interfaces for Decentralized Autonomous Organizations (DAOs).
2// It intentionally does not expose members and votes, as these details are implementation-specific.
3// Instead, it focuses on providing an external view of proposals and their statuses,
4// which is what non-members and non-voters typically care about.
5//
6// The package is designed to allow for composable DAO patterns, enabling flexible
7// and modular implementations of various DAO structures and behaviors.
8package udao
9
10// DAO defines a minimal interface for a Decentralized Autonomous Organization
11// from an external point of view, hiding the internal details of members and voting.
12type DAO interface {
13 // Propose submits a new proposal to the DAO
14 Propose(prop Proposal) (id uint64, err error)
15
16 // GetProposalStatus retrieves the current status and metrics of a specific proposal
17 GetProposalStatus(id uint64) (ProposalStatus, error)
18
19 // Execute attempts to execute a proposal if it has passed
20 Execute(id uint64) error
21
22 // GetProposal retrieves the details of a specific proposal
23 GetProposal(id uint64) (Proposal, error)
24
25 // XXX: find a smart way to list proposals
26 // // ListProposalss retrieves a list of Proposals with pagination and optional filters
27 // ListDAOs(offset, limit int, filters ...ProposalFilter) ([]DAO, error)
28}
29
30// Proposal defines the interface for a DAO proposal
31type Proposal interface {
32 Title() string
33 Body() string
34 Constraints() []Constraint
35}
36
37// ProposalStatus represents the current status and metrics of a proposal
38type ProposalStatus struct {
39 // status
40 State ProposalState
41
42 // metrics
43 YeaPercentage float64
44 NayPercentage float64
45 NonVoterPercentage float64
46 // XXX: other metrics?
47}
48
49// ProposalState represents the current state of a proposal
50type ProposalState int
51
52const (
53 Pending ProposalState = iota
54 Active
55 Passed
56 Rejected
57 Executed
58 Expired // XXX: better name for when it's expired but not because of time?
59)
60
61// Constraint defines an interface for proposal constraints
62type Constraint interface {
63 Validate() (bool, string)
64 Description() string
65}
66
67// ValidateConstraints checks if all constraints of a proposal are met
68func ValidateConstraints(p Proposal) (bool, []string) {
69 var unmetReasons []string
70 for _, constraint := range p.Constraints() {
71 valid, reason := constraint.Validate()
72 if !valid {
73 unmetReasons = append(unmetReasons, reason)
74 }
75 }
76 return len(unmetReasons) == 0, unmetReasons
77}