daodemo.gno
2.24 Kb · 64 lines
1package daodemo
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 and a single public-relationships role.
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 DAO daokit.DAO
16 daoPrivate *basedao.DAOPrivate
17)
18
19// TODO: add a little bit more complexity to show daocond initialization
20func init() {
21 initialRoles := []basedao.RoleInfo{
22 {Name: "admin", Description: "Admin is the superuser"},
23 {Name: "public-relationships", Description: "Responsible of communication with the public"},
24 {Name: "finance-officer", Description: "Responsible of funds management"},
25 }
26
27 initialMembers := []basedao.Member{
28 {Address: "g126gx6p6d3da4ymef35ury6874j6kys044r7zlg", Roles: []string{"admin", "public-relationships"}},
29 {Address: "g1ld6uaykyugld4rnm63rcy7vju4zx23lufml3jv", Roles: []string{"public-relationships"}},
30 {Address: "g1r69l0vhp7tqle3a0rk8m8fulr8sjvj4h7n0tth", Roles: []string{"finance-officer"}},
31 {Address: "g16jv3rpz7mkt0gqulxas56se2js7v5vmc6n6e0r", Roles: []string{}},
32 }
33
34 // create the member store now to be able to use it in the condition
35 memberStore := basedao.NewMembersStore(initialRoles, initialMembers)
36
37 membersMajority := daocond.MembersThreshold(0.6, memberStore.IsMember, memberStore.MembersCount)
38 publicRelationships := daocond.RoleCount(1, "public-relationships", memberStore.HasRole)
39 financeOfficer := daocond.RoleCount(1, "finance-officer", memberStore.HasRole)
40
41 // and & or use va_args so you can pass as many conditions as you want
42 adminCond := daocond.And(membersMajority, publicRelationships, financeOfficer)
43
44 DAO, daoPrivate = basedao.New(&basedao.Config{
45 Name: "Demo DAOKIT DAO",
46 Description: "This is a demo DAO built with [DAOKIT](/p/samcrew/daokit)",
47 Members: memberStore,
48 InitialCondition: adminCond,
49 GetProfileString: profile.GetStringField,
50 SetProfileString: profile.SetStringField,
51 })
52}
53
54func Vote(proposalID uint64, vote daocond.Vote) {
55 DAO.Vote(proposalID, vote)
56}
57
58func Execute(proposalID uint64) {
59 DAO.Execute(proposalID)
60}
61
62func Render(path string) string {
63 return daoPrivate.Render(path)
64}