Search Apps Documentation Source Content File Folder Download Copy Actions Download

simple_dao.gno

2.78 Kb · 91 lines
 1package custom_resource
 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	myblog     Blog
14)
15
16func init(cur realm) {
17	initialRoles := []basedao.RoleInfo{
18		{Name: "Role", Description: "Has a role", Color: "#329175"},
19	}
20	initialMembers := []basedao.Member{
21		{Address: "g1demo1234567890abcdefghijklmnopqrstuvw1", Roles: []string{}},
22		{Address: "g1demo1234567890abcdefghijklmnopqrstuvw2", Roles: []string{}},
23		{Address: "g1demo1234567890abcdefghijklmnopqrstuvw3", Roles: []string{}},
24		{Address: "g1demo1234567890abcdefghijklmnopqrstuvw4", Roles: []string{}},
25	}
26	memberStore := basedao.NewMembersStore(initialRoles, initialMembers)
27	membersMajority := daocond.MembersThreshold(0.1, memberStore.IsMember, memberStore.MembersCount)
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: membersMajority,
34		GetProfileString: profile.GetStringField,
35		SetProfileString: profile.SetStringField,
36		PrivateVarName:   "daoPrivate",
37		RenderFn: func(path string, dao *basedao.DAOPrivate) string {
38			s := ""
39			if path == "" {
40				s += renderDemo()
41			}
42			s += " \n\n--- \n\n "
43			s += dao.RenderRouter.Render(path)
44			s += "# My blog\n"
45			s += myblog.Render()
46			return s
47		},
48		SetImplemFn: setImplem,
49	}, cur)
50
51	// Create a new custom resource
52	resource := daokit.Resource{
53		Handler:     NewPostHandler(&myblog),
54		Condition:   membersMajority,
55		DisplayName: "Create Blog Post",
56		Description: "Allows DAO members to create and publish new blog posts",
57	}
58	// Add it to our DAO
59	daoPrivate.Core.Resources.Set(&resource)
60
61	// Add some demo blog post proposals to showcase custom resource
62	initBlogProposals()
63}
64
65// Propose creates a new proposal
66// To execute this function, you must use a MsgRun (maketx run)
67// See why it is necessary in Gno Documentation: https://docs.gno.land/users/interact-with-gnokey#run
68func Propose(cur realm, req daokit.ProposalRequest) {
69	localDAO.Propose(req)
70}
71
72// Vote allows DAO members to cast their vote on a specific proposal
73func Vote(cur realm, proposalID uint64, vote daocond.Vote) {
74	localDAO.Vote(proposalID, vote)
75}
76
77// Execute triggers the implementation of a proposal's actions
78func Execute(cur realm, proposalID uint64) {
79	localDAO.Execute(proposalID, cur)
80}
81
82// Render generates a UI representation of the DAO's state
83func Render(path string) string {
84	return localDAO.Render(path)
85}
86
87// Updates the DAO implementation when governance proposals change it.
88// This allows the DAO to upgrade itself through proposals that modify its core logic.
89func setImplem(newLocalDAO daokit.DAO) {
90	localDAO = newLocalDAO
91}