Search Apps Documentation Source Content File Folder Download Copy Actions Download

simple_dao.gno

3.14 Kb · 93 lines
 1package simple_dao
 2
 3// This is the most basic example of a DAO using DAOKIT.
 4// It is a simple DAO that has a single admin role, a public-relationships role and a finance-officer.
 5// It is used to demonstrate the basic functionality of DAOKIT.
 6
 7import (
 8	"gno.land/p/samcrew/basedao"
 9	"gno.land/p/samcrew/daocond"
10	"gno.land/p/samcrew/daokit"
11	"gno.land/r/demo/profile"
12)
13
14var (
15	localDAO   daokit.DAO          // Local interface for maketx call
16	daoPrivate *basedao.DAOPrivate // Full access to internal DAO state
17)
18
19// Initializes the DAO with predefined roles, members, and governance rules.
20func init(cur realm) {
21	// Define initial roles in the DAO
22	initialRoles := []basedao.RoleInfo{
23		{Name: "public-relationships", Description: "Responsible of communication with the public", Color: "#21577A"},
24		{Name: "finance-officer", Description: "Responsible of funds management", Color: "#F3D3BC"},
25	}
26
27	// Define initial members and their roles
28	initialMembers := []basedao.Member{
29		{Address: "g1demo1234567890abcdefghijklmnopqrstuvwxyz", Roles: []string{"finance-officer"}},
30	}
31
32	// Create the member store now to be able to use it in the condition
33	memberStore := basedao.NewMembersStore(initialRoles, initialMembers)
34
35	// Define governance conditions using daocond
36	membersMajority := daocond.MembersThreshold(0.4, memberStore.IsMember, memberStore.MembersCount)
37	financeOfficer := daocond.RoleCount(1, "finance-officer", memberStore.HasRole)
38
39	// `and` and `or` use va_args so you can pass as many conditions as needed
40	adminCond := daocond.And(membersMajority, financeOfficer)
41
42	// Initialize DAO with configuration
43	localDAO, daoPrivate = basedao.New(&basedao.Config{
44		Name:             "Demo DAOKIT DAO",
45		Description:      "This is a demo DAO built with DAOKIT",
46		Members:          memberStore,
47		InitialCondition: adminCond,
48		GetProfileString: profile.GetStringField,
49		SetProfileString: profile.SetStringField,
50		PrivateVarName:   "daoPrivate",
51		SetImplemFn:      setImplem,
52		RenderFn: func(path string, dao *basedao.DAOPrivate) string {
53			s := ""
54			// Demo path to showcase the possibility of this realm
55			if path == "" {
56				s += renderDemo()
57			}
58			s += " \n\n--- \n\n "
59			s += dao.RenderRouter.Render(path)
60			return s
61		},
62	}, cur)
63
64	initProposals(cur, 25)
65}
66
67// Creates a new proposal
68// To execute this function, you must use a MsgRun `gnokey maketx run“
69// See why it is necessary in Gno Documentation: https://docs.gno.land/users/interact-with-gnokey#run
70func Propose(cur realm, req daokit.ProposalRequest) {
71	localDAO.Propose(req)
72}
73
74// Allows DAO members to cast their vote on a specific proposal
75func Vote(cur realm, proposalID uint64, vote daocond.Vote) {
76	localDAO.Vote(proposalID, vote)
77}
78
79// Triggers the implementation of a proposal's actions
80func Execute(cur realm, proposalID uint64) {
81	localDAO.Execute(proposalID, cur)
82}
83
84// Generates a UI representation of the DAO's state
85func Render(path string) string {
86	return localDAO.Render(path)
87}
88
89// Updates the DAO implementation when governance proposals change it.
90// This allows the DAO to upgrade itself through proposals that modify its core logic.
91func setImplem(newLocalDAO daokit.DAO) {
92	localDAO = newLocalDAO
93}