/p/nt/commondao/v0/exts/definition
CommonDAO Package Definition Extension
Definition package is an extension of gno.land/p/nt/commondao/v0 that provides
an alternative approach to define custom proposal types.
Definition
The Definition type is an implementation that allows creating custom proposal
definitions using callback functions and definition options.
CommonDAO package supports different proposal types through the
ProposalDefinition interface, so new proposal types require the definition
of a custom type that implements the interface. The Definition type is a
callback based alternative to the type based approach.
By default, new definitions have a voting period of 7 days, allowing YES, NO and ABSTAIN votes, tallying those votes using an absolute majority of more than 50% of member votes, considering that a proposal passes when the majority of the votes are YES.
New definition can be created using any of the following functions:
1// New creates a new custom proposal definition or returns an error
2func New(title, body string, options ...Option) (Definition, error)
3
4// MustNew creates a new custom proposal definition or panics on error
5func MustNew(title, body string, options ...Option) Definition
Default definition behavior can be configured by setting custom options that configures the following proposal options:
- Custom vote choices
- Voting period
- Tally behavior
- Pre-execution and render validation
- Execution behavior
Example usage:
1import (
2 "chain/runtime"
3 "errors"
4 "time"
5
6 "gno.land/p/nt/commondao/v0"
7 "gno.land/p/nt/commondao/v0/exts/definition"
8)
9
10var dao = commondao.New()
11
12// CreateMemberProposal creates a new example proposal to add a DAO member.
13func CreateMemberProposal(member address) uint64 {
14 if !member.IsValid() {
15 panic("invalid member address")
16 }
17
18 // Define a function to validate that member doesn't exist within the DAO
19 validate := func() error {
20 if dao.Members().Has(member) {
21 return errors.New("member already exists within the DAO")
22 }
23 return nil
24 }
25
26 // Define a custom tally function that approves proposals without votes
27 tally := func(commondao.VotingContext) (bool, error) {
28 return true, nil
29 }
30
31 // Define an executor to add the new member to the DAO
32 executor := func(realm) error {
33 dao.Members().Add(member)
34 return nil
35 }
36
37 // Create a custom proposal definition for an example proposal type
38 def := definition.MustNew(
39 "Example Proposal",
40 "This is a simple proposal example",
41 definition.WithVotingPeriod(time.Hour * 24 * 2), // 2 days
42 definition.WithTally(tally),
43 definition.WithValidation(validate),
44 definition.WithExecutor(executor),
45 )
46
47 // Create a new proposal
48 p := dao.MustPropose(runtime.PreviousRealm().Address(), def)
49 return p.ID()
50}