1package govdao
2
3import (
4 "std"
5 "strconv"
6
7 "gno.land/p/demo/dao"
8 "gno.land/p/demo/membstore"
9 "gno.land/p/demo/simpledao"
10 "gno.land/p/demo/ufmt"
11)
12
13var (
14 d *simpledao.SimpleDAO // the current active DAO implementation
15 members membstore.MemberStore // the member store
16)
17
18func init() {
19 set := []membstore.Member{
20 {
21 Address: std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"), // Jae
22 VotingPower: 20,
23 },
24 {
25 Address: std.Address("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq"), // Manfred
26 VotingPower: 20,
27 },
28 {
29 Address: std.Address("g1e6gxg5tvc55mwsn7t7dymmlasratv7mkv0rap2"), // Milos
30 VotingPower: 20,
31 },
32 {
33 Address: std.Address("g1jazghxvvgz3egnr2fc8uf72z4g0l03596y9ls7"), // Nemanja
34 VotingPower: 20,
35 },
36 {
37 Address: std.Address("g17p2kkyy9lp2z3ecw4psssk357vxp20afnyl00d"), // Petar
38 VotingPower: 20,
39 },
40 {
41 Address: std.Address("g18amm3fc00t43dcxsys6udug0czyvqt9e7p23rd"), // Marc
42 VotingPower: 20,
43 },
44 {
45 Address: std.Address("g1dfr24yhk5ztwtqn2a36m8f6ud8cx5hww4dkjfl"), // Antonio
46 VotingPower: 20,
47 },
48 {
49 Address: std.Address("g19p3yzr3cuhzqa02j0ce6kzvyjqfzwemw3vam0x"), // Guilhem
50 VotingPower: 20,
51 },
52 {
53 Address: std.Address("g1mx4pum9976th863jgry4sdjzfwu03qan5w2v9j"), // Ray
54 VotingPower: 20,
55 },
56 {
57 Address: std.Address("g127l4gkhk0emwsx5tmxe96sp86c05h8vg5tufzq"), // Maxwell
58 VotingPower: 20,
59 },
60 {
61 Address: std.Address("g1cpx59z5r8vzeww2fm4ezpz7yvjs7kptywkm864"), // Morgan
62 VotingPower: 20,
63 },
64 {
65 Address: std.Address("g1ker4vvggvsyatexxn3hkthp2hu80pkhrwmuczr"), // Sergio
66 VotingPower: 20,
67 },
68 {
69 Address: std.Address("g18x425qmujg99cfz3q97y4uep5pxjq3z8lmpt25"), // Antoine
70 VotingPower: 20,
71 },
72 // GNO DEVX
73 {
74 Address: std.Address("g16tfrrul20g4jzt3z303raqw8vs8s2pqqh5clwu"), // Ilker
75 VotingPower: 10,
76 },
77 {
78 Address: std.Address("g1hy6zry03hg5d8le9s2w4fxme6236hkgd928dun"), // Jerónimo
79 VotingPower: 10,
80 },
81 {
82 Address: std.Address("g15ruzptpql4dpuyzej0wkt5rq6r26kw4nxu9fwd"), // Denis
83 VotingPower: 10,
84 },
85 {
86 Address: std.Address("g1dnllrdzwfhxv3evyk09y48mgn5phfjvtyrlzm7"), // Danny
87 VotingPower: 10,
88 },
89 {
90 Address: std.Address("g1778y2yphxs2wpuaflsy5y9qwcd4gttn4g5yjx5"), // Michelle
91 VotingPower: 10,
92 },
93 {
94 Address: std.Address("g1mq7g0jszdmn4qdpc9tq94w0gyex37su892n80m"), // Alan
95 VotingPower: 10,
96 },
97 {
98 Address: std.Address("g197q5e9v00vuz256ly7fq7v3ekaun5cr7wmjgfh"), // Salvo
99 VotingPower: 10,
100 },
101 {
102 Address: std.Address("g1mpkp5lm8lwpm0pym4388836d009zfe4maxlqsq"), // Alexis
103 VotingPower: 10,
104 },
105 {
106 Address: std.Address("g125em6arxsnj49vx35f0n0z34putv5ty3376fg5"), // Leon
107 VotingPower: 10,
108 },
109 {
110 Address: std.Address("g1whzkakk4hzjkvy60d5pwfk484xu67ar2cl62h2"), // Kirk
111 VotingPower: 10,
112 },
113 // ONBLOC
114 {
115 Address: std.Address("g12vx7dn3dqq89mz550zwunvg4qw6epq73d9csay"), // Dongwon
116 VotingPower: 5,
117 },
118 {
119 Address: std.Address("g1r04aw56fgvzy859fachr8hzzhqkulkaemltr76"), // Blake
120 VotingPower: 5,
121 },
122 {
123 Address: std.Address("g17n4y745s08awwq4e0a38lagsgtntna0749tnxe"), // Jinwoo
124 VotingPower: 5,
125 },
126 {
127 Address: std.Address("g1ckae7tc5sez8ul3ssne75sk4muwgttp6ks2ky9"), // ByeongJun
128 VotingPower: 5,
129 },
130 // TERITORI
131 {
132 Address: std.Address("g14u5eaheavy0ux4dmpykg2gvxpvqvexm9cyg58a"), // Norman
133 VotingPower: 5,
134 },
135 // BERTY
136 {
137 Address: std.Address("g1qynsu9dwj9lq0m5fkje7jh6qy3md80ztqnshhm"), // Rémi
138 VotingPower: 5,
139 },
140 // FLIPPANDO / ZENTASKTIC
141 {
142 Address: std.Address("g17ernafy6ctpcz6uepfsq2js8x2vz0wladh5yc3"), // Dragos
143 VotingPower: 5,
144 },
145 }
146
147 // Set the member store
148 members = membstore.NewMembStore(membstore.WithInitialMembers(set))
149
150 // Set the DAO implementation
151 d = simpledao.New(members)
152}
153
154// Propose is designed to be called by another contract or with
155// `maketx run`, not by a `maketx call`.
156func Propose(request dao.ProposalRequest) uint64 {
157 idx, err := d.Propose(request)
158 if err != nil {
159 panic(err)
160 }
161
162 return idx
163}
164
165// VoteOnProposal casts a vote for the given proposal
166func VoteOnProposal(id uint64, option dao.VoteOption) {
167 if err := d.VoteOnProposal(id, option); err != nil {
168 panic(err)
169 }
170}
171
172// ExecuteProposal executes the proposal
173func ExecuteProposal(id uint64) {
174 if err := d.ExecuteProposal(id); err != nil {
175 panic(err)
176 }
177}
178
179// GetPropStore returns the active proposal store
180func GetPropStore() dao.PropStore {
181 return d
182}
183
184// GetMembStore returns the active member store
185func GetMembStore() membstore.MemberStore {
186 return members
187}
188
189func Render(path string) string {
190 if path == "" {
191 numProposals := d.Size()
192
193 if numProposals == 0 {
194 return "No proposals found :(" // corner case
195 }
196
197 output := ""
198
199 offset := uint64(0)
200 if numProposals >= 10 {
201 offset = uint64(numProposals) - 10
202 }
203
204 // Fetch the last 10 proposals
205 for idx, prop := range d.Proposals(offset, uint64(10)) {
206 output += ufmt.Sprintf(
207 "- [Proposal #%d](%s:%d) - (**%s**)(by %s)\n",
208 idx,
209 "/r/gov/dao/v2",
210 idx,
211 prop.Status().String(),
212 prop.Author().String(),
213 )
214 }
215
216 return output
217 }
218
219 // Display the detailed proposal
220 idx, err := strconv.Atoi(path)
221 if err != nil {
222 return "404: Invalid proposal ID"
223 }
224
225 // Fetch the proposal
226 prop, err := d.ProposalByID(uint64(idx))
227 if err != nil {
228 return ufmt.Sprintf("unable to fetch proposal, %s", err.Error())
229 }
230
231 // Render the proposal
232 output := ""
233 output += ufmt.Sprintf("# Prop #%d", idx)
234 output += "\n\n"
235 output += prop.Render()
236 output += "\n\n"
237
238 return output
239}
dao.gno
5.55 Kb · 239 lines