Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: index daokit daos #1511

Merged
merged 28 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f49dea6
feat: index daokit daos
n0izn0iz Feb 18, 2025
f448101
feat: adapt members query
n0izn0iz Feb 18, 2025
82d725c
chore: use pinata gateway to access zenao content
n0izn0iz Feb 18, 2025
137816d
Merge branch 'main' into daokit-indexer
n0izn0iz Feb 18, 2025
6e2861d
fix: pinata gateway url
n0izn0iz Feb 18, 2025
57bbc5b
chore: Merge branch 'daokit-indexer' of github.com:TERITORI/teritori-…
n0izn0iz Feb 18, 2025
a4bc527
fix: add crossorigin tag to images
n0izn0iz Feb 18, 2025
cb05620
tmp: crossorigin on opti img
n0izn0iz Feb 18, 2025
2253a4d
fix: correctly use uri
n0izn0iz Feb 18, 2025
2853a46
fix: revert to expo image
n0izn0iz Feb 18, 2025
c7f22dd
tmp: remove fallback system to inspect img tag
n0izn0iz Feb 18, 2025
cb8e1d0
tmp: add transform
n0izn0iz Feb 18, 2025
6808694
chore: remove error handler
n0izn0iz Feb 18, 2025
9f6ea4e
tmp: try using img tag
n0izn0iz Feb 18, 2025
d199271
fix: use contain
n0izn0iz Feb 18, 2025
a966de1
fix: adjustments
n0izn0iz Feb 18, 2025
d554b12
fix: make banner cover
n0izn0iz Feb 18, 2025
23c76a2
chore: style adjustments
n0izn0iz Feb 18, 2025
970e205
feat(upp): better explorer link + gnoweb link
n0izn0iz Feb 18, 2025
7e99ffa
fix: correct test5 gnoweb url
n0izn0iz Feb 18, 2025
5c99a2a
chore: normalize width
n0izn0iz Feb 18, 2025
9cc6392
feat: index basedao members
n0izn0iz Feb 18, 2025
681628b
feat: list daokit proposals
n0izn0iz Feb 19, 2025
91ae87b
feat: zenao support
n0izn0iz Feb 19, 2025
076c58e
chore: revert app change
n0izn0iz Feb 19, 2025
dc10df2
chore: remove unused asset
n0izn0iz Feb 19, 2025
04db17b
fix: image
n0izn0iz Feb 19, 2025
c7ebb77
fix: restrict gnotribe netwotks
n0izn0iz Feb 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
INDEXER_NETWORK_ID=teritori-testnet
GNO_NETWORK_ID=gno-test4
GNO_NETWORK_ID=gno-dev
TERITORI_MINTER_CODE_IDS=10
TENDERMINT_WEBSOCKET_ENDPOINT=wss://rpc.testnet.teritori.com/websocket
TERITORI_COLLECTION_WHITELIST=testeth-0x43cc70bf324d716782628bed38af97e4afe92f69,mumbai-0x916ad9d549907ccbbaf9ba65526826bfc3a9c0c4,testori-tori1r8raaqul4j05qtn0t05603mgquxfl8e9p7kcf7smwzcv2hc5rrlq0vket0,testori-tori1436kxs0w2es6xlqpp9rd35e3d0cjnw4sv8j3a7483sgks29jqwgsjscd88
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ publish.multisig-backend:

.PHONY: publish.gno-indexer
publish.gno-indexer:
docker build -f go/cmd/gno_social_feed_indexer/Dockerfile . --platform linux/amd64 -t $(GNO_INDEXER_DOCKER_IMAGE)
docker build -f go/cmd/gno-indexer/Dockerfile . --platform linux/amd64 -t $(GNO_INDEXER_DOCKER_IMAGE)
docker push $(GNO_INDEXER_DOCKER_IMAGE)

.PHONY: validate-networks
Expand Down
2 changes: 1 addition & 1 deletion apps/gnotribe/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import AppRoot from "@/dapp-root/App";
const config: AppConfig = {
disableBuyTokensButton: true,
disableDAppStore: true,
forceNetworkList: ["gno-test5", "gno-portal"],
forceNetworkList: ["gno-test5", "gno-zenao"],
forceDAppsList: ["feed", "organizations"],
defaultNetworkId: "gno-test5",
homeScreen: "Feed",
Expand Down
4 changes: 4 additions & 0 deletions assets/icons/networks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import teritori from "./teritori.svg";
import polygon from "./polygon.svg";
import starknet from "./starknet.svg";
import starknetCircle from "./starknet-circle.svg";
import zenao from "./zenao.svg";
import zenaoCircle from "./zenao-circle.svg"

export const networks = {
teritori,
Expand All @@ -34,4 +36,6 @@ export const networks = {
polygon,
starknet,
starknetCircle,
zenao,
zenaoCircle,
};
470 changes: 470 additions & 0 deletions assets/icons/networks/zenao-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
470 changes: 470 additions & 0 deletions assets/icons/networks/zenao.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion gno/p/basedao/basedao.gno
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ type Config struct {
type ProfileStringSetter func(field string, value string) bool
type ProfileStringGetter func(addr std.Address, field string, def string) string

const EventBaseDAOCreated = "BaseDAOCreated"

func emitBaseDAOCreated() {
std.Emit(EventBaseDAOCreated)
}

func New(conf *Config) *DAO {
// XXX: emit events from memberstore

Expand Down Expand Up @@ -63,7 +69,6 @@ func New(conf *Config) *DAO {

if !conf.NoDefaultHandlers {
if conf.InitialCondition == nil {
// XXX: this won't work because members threshold uses events
conf.InitialCondition = daocond.MembersThreshold(0.6, members.IsMember, members.MembersCount)
}

Expand All @@ -85,6 +90,8 @@ func New(conf *Config) *DAO {
}
}

emitBaseDAOCreated()

return dao
}

Expand Down
36 changes: 36 additions & 0 deletions gno/p/basedao/members.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"std"

"gno.land/p/demo/avl"
"gno.land/p/demo/json"
"gno.land/p/teritori/role_manager"
)

Expand All @@ -17,6 +18,9 @@ type Member struct {
Roles []string
}

const EventAddMember = "BaseDAOAddMember"
const EventRemoveMember = "BaseDAORemoveMember"

func NewMembersStore(initialRoles []role_manager.RoleInfo, initialMembers []Member) *MembersStore {
res := &MembersStore{
RoleManager: role_manager.New(),
Expand Down Expand Up @@ -76,6 +80,11 @@ func (m *MembersStore) setRoles(roles []role_manager.RoleInfo) {

func (m *MembersStore) setMembers(members []Member) {
for _, member := range members {
if ok := m.Members.Has(member.Address); !ok {
std.Emit(EventAddMember,
"address", member.Address,
)
}
m.Members.Set(member.Address, struct{}{})
for _, role := range member.Roles {
m.RoleManager.AddRoleToUser(std.Address(member.Address), role)
Expand All @@ -87,6 +96,9 @@ func (m *MembersStore) AddMember(member string, roles []string) {
if m.IsMember(member) {
panic("member already exists")
}
std.Emit(EventAddMember,
"address", member,
)
m.Members.Set(member, struct{}{})
for _, role := range roles {
m.RoleManager.AddRoleToUser(std.Address(member), role)
Expand All @@ -97,6 +109,9 @@ func (m *MembersStore) RemoveMember(member string) {
if !m.IsMember(member) {
panic("member does not exist")
}
std.Emit(EventRemoveMember,
"address", member,
)
m.Members.Remove(member)
m.RoleManager.RemoveAllRolesFromUser(std.Address(member))
}
Expand Down Expand Up @@ -126,3 +141,24 @@ func (m *MembersStore) RemoveRoleFromMember(member string, role string) {
}
m.RoleManager.RemoveRoleFromUser(std.Address(member), role)
}

func (m *MembersStore) GetMembersJSON() string {
// XXX: replace with protoc-gen-gno
members := []*json.Node{}
for _, memberID := range m.GetMembers() {
roles := []*json.Node{}
for _, role := range m.GetMemberRoles(memberID) {
roles = append(roles, json.StringNode("", role))
}
members = append(members, json.ObjectNode("", map[string]*json.Node{
"address": json.StringNode("", memberID),
"roles": json.ArrayNode("", roles),
}))
}
node := json.ArrayNode("", members)
bz, err := json.Marshal(node)
if err != nil {
panic(err)
}
return string(bz)
}
19 changes: 16 additions & 3 deletions gno/p/basedao/messages.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"std"

"gno.land/p/demo/ufmt"
"gno.land/p/moul/md"
"gno.land/p/teritori/daokit"
)

Expand Down Expand Up @@ -111,17 +112,29 @@ func NewUnassignRoleMsg(payload *MsgUnassignRole) daokit.ExecutableMessage {

const MsgEditProfileKind = "gno.land/p/teritori/basedao.EditProfile"

type msgEditProfile struct {
kv [][2]string
}

func (m *msgEditProfile) String() string {
elems := []string{}
for _, v := range m.kv {
elems = append(elems, v[0]+": "+v[1])
}
return md.BulletList(elems)
}

func NewEditProfileMsg(kv ...[2]string) daokit.ExecutableMessage {
return daokit.NewMessage(MsgEditProfileKind, kv)
return daokit.NewMessage(MsgEditProfileKind, &msgEditProfile{kv: kv})
}

func NewEditProfileHandler(setter ProfileStringSetter, allowedFields []string) daokit.MessageHandler {
return daokit.NewMessageHandler(MsgEditProfileKind, func(imsg interface{}) {
msg, ok := imsg.([][2]string)
msg, ok := imsg.(*msgEditProfile)
if !ok {
panic(errors.New("invalid message type"))
}
for _, elem := range msg {
for _, elem := range msg.kv {
k, v := elem[0], elem[1]
if len(allowedFields) > 0 && !stringSliceContains(allowedFields, k) {
panic(ufmt.Errorf("unauthorized field %q", k))
Expand Down
8 changes: 5 additions & 3 deletions gno/p/basedao/render.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package basedao

import (
"std"
"strconv"
"strings"

"gno.land/p/demo/mux"
Expand Down Expand Up @@ -69,7 +70,7 @@ func (d *DAO) renderHomePage(res *mux.ResponseWriter, req *mux.Request) {
if err != nil {
panic(err)
}
res.Write(ufmt.Sprintf("- **Proposal %d: [%s](%s:%s/%s)**\n\n", uint64(id), proposal.Title, linkPath, "proposal", key))
res.Write(ufmt.Sprintf("- **Proposal %d: [%s](%s:%s/%d)**\n\n", uint64(id), proposal.Title, linkPath, "proposal", uint64(id)))
i += 1
return false
})
Expand Down Expand Up @@ -120,7 +121,7 @@ func (d *DAO) renderProposalHistoryPage(res *mux.ResponseWriter, req *mux.Reques
if err != nil {
panic(err)
}
res.Write(ufmt.Sprintf("- **Proposal %d: [%s](%s:%s/%s) - %s**\n\n", uint64(id), proposal.Title, linkPath, "proposal", key, proposal.Status))
res.Write(ufmt.Sprintf("- **Proposal %d: [%s](%s:%s/%d) - %s**\n\n", uint64(id), proposal.Title, linkPath, "proposal", uint64(id), proposal.Status))
i += 1
return false
})
Expand Down Expand Up @@ -156,10 +157,11 @@ func (d *DAO) renderProposalDetailPage(res *mux.ResponseWriter, req *mux.Request
pkgPath := d.Realm.PkgPath()
linkPath := getLinkPath(pkgPath)

id, err := seqid.FromString(req.GetVar("id"))
idu, err := strconv.ParseUint(req.GetVar("id"), 10, 64)
if err != nil {
panic(err)
}
id := seqid.ID(idu)
res.Write(ufmt.Sprintf("# %s - Proposal #%d\n\n", name, uint64(id)))
proposal := d.Core.ProposalModule.GetProposal(uint64(id))
res.Write(ufmt.Sprintf("## Title - %s 📜\n\n", proposal.Title))
Expand Down
7 changes: 7 additions & 0 deletions gno/p/daocond/cond_and.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package daocond

import (
"math"

"gno.land/p/demo/json"
)

Expand Down Expand Up @@ -43,6 +45,11 @@ type andState struct {
right State
}

// Signal implements State.
func (a *andState) Signal(votes map[string]Vote) float64 {
return math.Min(a.left.Signal(votes), a.right.Signal(votes))
}

// RenderJSON implements State.
func (a *andState) RenderJSON(votes map[string]Vote) *json.Node {
return json.ObjectNode("", map[string]*json.Node{
Expand Down
7 changes: 7 additions & 0 deletions gno/p/daocond/cond_govdao.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package daocond

import (
"errors"
"math"
"strconv"
"strings"

Expand Down Expand Up @@ -67,12 +68,18 @@ type govDaoCondThresholdState struct {
cond *govDaoCondThreshold
}

func (m *govDaoCondThresholdState) Signal(votes map[string]Vote) float64 {
return math.Min(m.yesRatio(votes)/m.cond.threshold, 1)
}

func (m *govDaoCondThresholdState) Eval(votes map[string]Vote) bool {
return m.yesRatio(votes) >= m.cond.threshold
}

func (m *govDaoCondThresholdState) HandleEvent(_ Event, _ map[string]Vote) {
panic(errors.New("not implemented"))
}

func (m *govDaoCondThresholdState) RenderJSON(votes map[string]Vote) *json.Node {
vPowers, totalPower := m.computeVotingPowers()
rolePowers := []string{}
Expand Down
12 changes: 11 additions & 1 deletion gno/p/daocond/cond_members_threshold.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package daocond

import (
"errors"
"math"

"gno.land/p/demo/json"
"gno.land/p/demo/ufmt"
Expand Down Expand Up @@ -57,9 +58,18 @@ type membersThresholdState struct {
totalYes uint64
}

// Signal implements State.
func (m *membersThresholdState) Signal(votes map[string]Vote) float64 {
return math.Min(m.yesRatio()/m.cond.threshold, 1)
}

func (m *membersThresholdState) yesRatio() float64 {
return float64(m.totalYes) / float64(m.cond.membersCountFn())
}

// Eval implements State.
func (m *membersThresholdState) Eval(_ map[string]Vote) bool {
return float64(m.totalYes)/float64(m.cond.membersCountFn()) >= m.cond.threshold
return m.yesRatio() >= m.cond.threshold
}

// HandleEvent implements State.
Expand Down
12 changes: 11 additions & 1 deletion gno/p/daocond/cond_members_threshold_few_votes.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package daocond

import (
"errors"
"math"

"gno.land/p/demo/json"
"gno.land/p/demo/ufmt"
Expand Down Expand Up @@ -56,6 +57,11 @@ type membersThresholdFewVotesState struct {
cond *membersThresholdFewVotesCond
}

// Signal implements State.
func (m *membersThresholdFewVotesState) Signal(votes map[string]Vote) float64 {
return math.Min(m.yesRatio(votes)/m.cond.threshold, 1)
}

func (m *membersThresholdFewVotesState) totalYes(votes map[string]Vote) uint64 {
totalYes := uint64(0)
for userId, vote := range votes {
Expand All @@ -70,9 +76,13 @@ func (m *membersThresholdFewVotesState) totalYes(votes map[string]Vote) uint64 {
return totalYes
}

func (m *membersThresholdFewVotesState) yesRatio(votes map[string]Vote) float64 {
return float64(m.totalYes(votes)) / float64(m.cond.membersCountFn())
}

// Eval implements State.
func (m *membersThresholdFewVotesState) Eval(votes map[string]Vote) bool {
return float64(m.totalYes(votes))/float64(m.cond.membersCountFn()) >= m.cond.threshold
return m.yesRatio(votes) >= m.cond.threshold
}

// HandleEvent implements State.
Expand Down
7 changes: 7 additions & 0 deletions gno/p/daocond/cond_or.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package daocond

import (
"math"

"gno.land/p/demo/json"
)

Expand Down Expand Up @@ -43,6 +45,11 @@ type orState struct {
right State
}

// Signal implements State.
func (a *orState) Signal(votes map[string]Vote) float64 {
return math.Max(a.left.Signal(votes), a.right.Signal(votes))
}

// Eval implements State.
func (a *orState) Eval(votes map[string]Vote) bool {
return a.left.Eval(votes) || a.right.Eval(votes)
Expand Down
6 changes: 6 additions & 0 deletions gno/p/daocond/cond_role_count.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package daocond

import (
"errors"
"math"

"gno.land/p/demo/json"
"gno.land/p/demo/ufmt"
Expand Down Expand Up @@ -58,6 +59,11 @@ type roleCountState struct {
totalYes uint64
}

// Signal implements State.
func (m *roleCountState) Signal(votes map[string]Vote) float64 {
return math.Min(float64(m.totalYes)/float64(m.cond.count), 1)
}

// Eval implements State.
func (m *roleCountState) Eval(_ map[string]Vote) bool {
return m.totalYes >= m.cond.count
Expand Down
6 changes: 6 additions & 0 deletions gno/p/daocond/cond_role_count_few_votes.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package daocond

import (
"errors"
"math"

"gno.land/p/demo/json"
"gno.land/p/demo/ufmt"
Expand Down Expand Up @@ -57,6 +58,11 @@ type roleCountFewVotesState struct {
cond *roleCountFewVotesCond
}

// Signal implements State.
func (m *roleCountFewVotesState) Signal(votes map[string]Vote) float64 {
return math.Min(float64(m.totalYes(votes))/float64(m.cond.count), 1)
}

func (m *roleCountFewVotesState) totalYes(votes map[string]Vote) uint64 {
totalYes := uint64(0)
for userId, vote := range votes {
Expand Down
Loading
Loading