Search Apps Documentation Source Content File Folder Download Copy Actions Download

simple_dao.gno

2.25 Kb · 77 lines
 1package custom_condition
 2
 3import (
 4	"gno.land/p/samcrew/basedao"
 5	"gno.land/p/samcrew/daocond"
 6	"gno.land/p/samcrew/daokit"
 7	"gno.land/r/demo/profile"
 8)
 9
10var (
11	localDAO   daokit.DAO
12	daoPrivate *basedao.DAOPrivate
13)
14
15func init(cur realm) {
16	initialRoles := []basedao.RoleInfo{
17		{Name: "Role", Description: "Has a role", Color: "#329175"},
18	}
19	initialMembers := []basedao.Member{
20		{Address: "g1demo1234567890abcdefghijklmnopqrstuvwxy1", Roles: []string{"Role"}},
21		{Address: "g1demo1234567890abcdefghijklmnopqrstuvwxy2", Roles: []string{}},
22		{Address: "g1demo1234567890abcdefghijklmnopqrstuvwxy3", Roles: []string{}},
23	}
24	memberStore := basedao.NewMembersStore(initialRoles, initialMembers)
25
26	// Define the "NoRole" condition
27	noRole := NoRole(memberStore, 1)
28
29	localDAO, daoPrivate = basedao.New(&basedao.Config{
30		Name:             "Demo DAOKIT DAO",
31		Description:      "This is a demo DAO built with DAOKIT",
32		Members:          memberStore,
33		InitialCondition: noRole,
34		GetProfileString: profile.GetStringField,
35		SetProfileString: profile.SetStringField,
36		PrivateVarName:   "daoPrivate",
37		SetImplemFn:      setImplem,
38		RenderFn: func(path string, dao *basedao.DAOPrivate) string {
39			s := ""
40			if path == "" {
41				s += renderDemo()
42			}
43			s += " \n\n--- \n\n "
44			s += dao.RenderRouter.Render(path)
45			return s
46		},
47	}, cur)
48	initDemoProposals()
49}
50
51// Propose creates a new proposal
52// To execute this function, you must use a MsgRun (maketx run)
53// See why it is necessary in Gno Documentation: https://docs.gno.land/users/interact-with-gnokey#run
54func Propose(cur realm, req daokit.ProposalRequest) {
55	localDAO.Propose(req)
56}
57
58// Vote allows DAO members to cast their vote on a specific proposal
59func Vote(cur realm, proposalID uint64, vote daocond.Vote) {
60	localDAO.Vote(proposalID, vote)
61}
62
63// Execute triggers the implementation of a proposal's actions
64func Execute(cur realm, proposalID uint64) {
65	localDAO.Execute(proposalID, cur)
66}
67
68// Render generates a UI representation of the DAO's state
69func Render(path string) string {
70	return localDAO.Render(path)
71}
72
73// Updates the DAO implementation when governance proposals change it.
74// This allows the DAO to upgrade itself through proposals that modify its core logic.
75func setImplem(newLocalDAO daokit.DAO) {
76	localDAO = newLocalDAO
77}