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: github oracle #16

Draft
wants to merge 72 commits into
base: teritori-unified
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
ec523e7
feat: DA0-DA0 port
n0izn0iz Sep 18, 2023
fd76513
feat: social feed and moderation dao by @hthieu1110
n0izn0iz Sep 18, 2023
ec5f5b7
chore: remove duplicates and unversion packages
n0izn0iz Sep 18, 2023
1eea98f
chore: reset gnovm changes
n0izn0iz Sep 18, 2023
aca197f
fix: make social feed and moderation work with latest dao packages
n0izn0iz Sep 18, 2023
b56f2f8
chore: move daodao contracts under teritori dir
n0izn0iz Sep 19, 2023
649a10f
chore: move ujson under teritori dir
n0izn0iz Sep 19, 2023
98f0f52
chore: reset Makefile changes
n0izn0iz Sep 19, 2023
5df85b3
chore: move binutils under teritori dir
n0izn0iz Sep 19, 2023
a5bd681
chore: move flags_index under teritori dir
n0izn0iz Sep 19, 2023
0a53afe
chore: move havl under teritori dir
n0izn0iz Sep 19, 2023
da9c395
chore: move markdown_utils under teritori dir
n0izn0iz Sep 19, 2023
84a1832
chore: move utf16 under teritori dir
n0izn0iz Sep 19, 2023
fe9835a
chore: update modboards golden test
n0izn0iz Sep 19, 2023
3e68c65
chore: move dao_realm under teritori dir
n0izn0iz Sep 19, 2023
63dd591
chore: move dao_registry under teritori dir
n0izn0iz Sep 19, 2023
172731e
chore: fork groups into teritori dir
n0izn0iz Sep 19, 2023
8aab4d0
chore: move modboards under teritori dir
n0izn0iz Sep 19, 2023
1a61229
chore: move social_feeds under teritori dir
n0izn0iz Sep 19, 2023
8a7680e
chore: move social_feeds_dao under teritori dir
n0izn0iz Sep 19, 2023
014baa4
chore: move tori under teritori dir
n0izn0iz Sep 19, 2023
58bb506
chore: update modboards golden test
n0izn0iz Sep 19, 2023
9fd8b9b
chore: reset gnovm changes
n0izn0iz Sep 19, 2023
c67f6f7
chore: reset .gitignore changes
n0izn0iz Sep 19, 2023
6303188
feat: escrow contract by @go7066
n0izn0iz Sep 19, 2023
46c6d1e
chore: move escrow under teritori dir
n0izn0iz Sep 19, 2023
ca5525c
feat: cosmos-style voting DAO by @go7066
n0izn0iz Sep 19, 2023
c991f43
chore: move gnodaos under teritori dir
n0izn0iz Sep 19, 2023
c400d35
chore: add disclaimer in gnodaos
n0izn0iz Sep 19, 2023
8c915f3
feat: justicedao and vrf by @go7066
n0izn0iz Sep 19, 2023
77d846a
chore: move justicedao and vrf under teritori dir
n0izn0iz Sep 19, 2023
fba6d55
chore: disable test targeting test3 avl
n0izn0iz Sep 19, 2023
e8c163e
chore: move daodao contracts at teritori root
n0izn0iz Sep 19, 2023
3b03013
chore: add teritori contracts overview
n0izn0iz Sep 19, 2023
3a8cc72
feat: abstract modules config query
n0izn0iz Sep 19, 2023
a3f8d69
fix: add missing imports in gno.mods
n0izn0iz Sep 19, 2023
d088ec6
feat: add tutorial to create a DAO
n0izn0iz Sep 20, 2023
308adc8
chore: clean dao core
n0izn0iz Sep 21, 2023
5ec3d6b
Merge branch 'master' into teritori-unified
moul Sep 22, 2023
d81d436
chore: add moderation DAO documentation
n0izn0iz Sep 26, 2023
6b64cfa
Merge remote-tracking branch 'origin/master' into teritori-unified
n0izn0iz Sep 26, 2023
4f75d8a
feat(ujson): add union support
n0izn0iz Sep 26, 2023
4bacc73
chore: use ujson union
n0izn0iz Sep 26, 2023
126edcd
feat: add voting durations
n0izn0iz Sep 26, 2023
a787dea
chore: clearer error messages
n0izn0iz Sep 26, 2023
139bd50
fix: pass examples CI tests
n0izn0iz Sep 27, 2023
82de5be
feat: check expiration in vote procedure
n0izn0iz Sep 27, 2023
7d9aa49
chore: typo in doc
n0izn0iz Sep 27, 2023
bebea69
chore: fmt
n0izn0iz Sep 28, 2023
26fcec5
chore: Merge remote-tracking branch 'teritori/master' into teritori-u…
n0izn0iz Feb 15, 2024
bf3e518
feat: add social follow system (#15)
omarsy Feb 18, 2024
08334cd
chore: tidy utf16
n0izn0iz Mar 11, 2024
e5d0b07
chore: clean ujson
n0izn0iz Mar 11, 2024
24ec7a1
chore: clean flags_index
n0izn0iz Mar 11, 2024
d5c4b36
chore: clean dao_interfaces
n0izn0iz Mar 11, 2024
ef7d604
Merge remote-tracking branch 'teritori/master' into teritori-unified
n0izn0iz Mar 11, 2024
ef8e55f
chore: clean social_feeds
n0izn0iz Mar 11, 2024
283d54e
chore: clean havl
n0izn0iz Mar 11, 2024
d4b2ee9
chore: clean havl groups
n0izn0iz Mar 11, 2024
21ab531
chore: clean markdown_utils
n0izn0iz Mar 11, 2024
47f7d0d
chore: clean dao_core
n0izn0iz Mar 11, 2024
7e88a5a
chore: clean dao_utils
n0izn0iz Mar 11, 2024
10e5afe
chore: clean dao_proposal_single
n0izn0iz Mar 11, 2024
68aab05
chore: clean dao_voting_group
n0izn0iz Mar 11, 2024
c92c3d9
chore: clean dao_registry
n0izn0iz Mar 11, 2024
e2b13dc
fix: disable broken registry in dao
n0izn0iz Mar 11, 2024
1fedd57
chore: clean modboard
n0izn0iz Mar 13, 2024
96970ae
chore: clean tori
n0izn0iz Mar 13, 2024
9e26151
chore: clean dao_realm
n0izn0iz Mar 13, 2024
7a7a949
chore: clean escrow package
n0izn0iz Mar 13, 2024
4470e0e
chore: rename escrow -> projects_manager
n0izn0iz Mar 13, 2024
17a2b45
feat: github oracle
omarsy Apr 20, 2024
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
34 changes: 34 additions & 0 deletions examples/gno.land/p/demo/teritori/binutils/binutils.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package binutils

import (
"encoding/binary"
"errors"
)

var ErrInvalidLengthPrefixedString = errors.New("invalid length-prefixed string")

func EncodeLengthPrefixedStringUint16BE(s string) []byte {
b := make([]byte, 2+len(s))
binary.BigEndian.PutUint16(b, uint16(len(s)))
copy(b[2:], s)
return b
}

func DecodeLengthPrefixedStringUint16BE(b []byte) (string, []byte, error) {
if len(b) < 2 {
return "", nil, ErrInvalidLengthPrefixedString
}
l := binary.BigEndian.Uint16(b)
if len(b) < 2+int(l) {
return "", nil, ErrInvalidLengthPrefixedString
}
return string(b[2 : 2+l]), b[l+2:], nil
}

func MustDecodeLengthPrefixedStringUint16BE(b []byte) (string, []byte) {
s, r, err := DecodeLengthPrefixedStringUint16BE(b)
if err != nil {
panic(err)
}
return s, r
}
1 change: 1 addition & 0 deletions examples/gno.land/p/demo/teritori/binutils/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/demo/teritori/binutils
183 changes: 183 additions & 0 deletions examples/gno.land/p/demo/teritori/dao_core/dao_core.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package core

import (
"std"

dao_interfaces "gno.land/p/demo/teritori/dao_interfaces"
"gno.land/p/demo/teritori/markdown_utils"
)

// TODO: add wrapper message handler to handle multiple proposal modules messages

type daoCore struct {
dao_interfaces.IDAOCore

votingModule dao_interfaces.IVotingModule
proposalModules []dao_interfaces.ActivableProposalModule
activeProposalModuleCount int
realm std.Realm
registry *dao_interfaces.MessagesRegistry
}

func NewDAOCore(
votingModuleFactory dao_interfaces.VotingModuleFactory,
proposalModulesFactories []dao_interfaces.ProposalModuleFactory,
messageHandlersFactories []dao_interfaces.MessageHandlerFactory,
) dao_interfaces.IDAOCore {
if votingModuleFactory == nil {
panic("Missing voting module factory")
}

if len(proposalModulesFactories) == 0 {
panic("No proposal modules factories")
}

core := &daoCore{
realm: std.CurrentRealm(),
activeProposalModuleCount: len(proposalModulesFactories),
registry: dao_interfaces.NewMessagesRegistry(),
proposalModules: make([]dao_interfaces.ActivableProposalModule, len(proposalModulesFactories)),
}

core.votingModule = votingModuleFactory(core)
if core.votingModule == nil {
panic("voting module factory returned nil")
}

for i, modFactory := range proposalModulesFactories {
mod := modFactory(core)
if mod == nil {
panic("proposal module factory returned nil")
}
core.proposalModules[i] = dao_interfaces.ActivableProposalModule{
Enabled: true,
Module: mod,
}
}

// this registry is specific to gno since we can't do dynamic calls
core.registry.Register(NewUpdateVotingModuleMessageHandler(core))
core.registry.Register(NewUpdateProposalModulesMessageHandler(core))
for _, handlerFactory := range messageHandlersFactories {
handler := handlerFactory(core)
if handler == nil {
panic("message handler factory returned nil")
}
core.registry.Register(handler)
}

return core
}

// mutations

func (d *daoCore) UpdateVotingModule(newVotingModule dao_interfaces.IVotingModule) {
if std.CurrentRealm().Addr() != d.realm.Addr() { // not sure this check necessary since the ownership system should protect against mutation from other realms
panic(ErrUnauthorized)
}

// FIXME: check da0-da0 implem
d.votingModule = newVotingModule
}

func (d *daoCore) UpdateProposalModules(toAdd []dao_interfaces.IProposalModule, toDisable []int) {
if std.CurrentRealm().Addr() != d.realm.Addr() { // not sure this check necessary since the ownership system should protect against mutation from other realms
panic(ErrUnauthorized)
}

for _, module := range toAdd {
d.addProposalModule(module)
}

for _, moduleIndex := range toDisable {
module := GetProposalModule(d, moduleIndex)

if !module.Enabled {
panic(ErrModuleAlreadyDisabled)
}
module.Enabled = false

d.activeProposalModuleCount--
if d.activeProposalModuleCount == 0 {
panic("no active proposal modules") // this -> `panic(ErrNoActiveProposalModules)` triggers `panic: reflect: reflect.Value.SetString using value obtained using unexported field`
}
}
}

// queries

func (d *daoCore) ProposalModules() []dao_interfaces.ActivableProposalModule {
return d.proposalModules
}

func (d *daoCore) VotingModule() dao_interfaces.IVotingModule {
return d.votingModule
}

func (d *daoCore) VotingPowerAtHeight(address std.Address, height int64) uint64 {
return d.VotingModule().VotingPowerAtHeight(address, height)
}

func (d *daoCore) ActiveProposalModuleCount() int {
return d.activeProposalModuleCount
}

func (d *daoCore) Render(path string) string {
s := "# DAO Core\n"
s += "This is an attempt at porting [DA0-DA0 contracts](https://github.com/DA0-DA0/dao-contracts)\n"
s += markdown_utils.Indent(d.votingModule.Render(path)) + "\n"
for _, propMod := range d.proposalModules {
if !propMod.Enabled {
continue
}
s += markdown_utils.Indent(propMod.Module.Render(path)) + "\n"
}
return s
}

func (d *daoCore) Registry() *dao_interfaces.MessagesRegistry {
return d.registry
}

// TODO: move this helper in dao interfaces

func GetProposalModule(core dao_interfaces.IDAOCore, moduleIndex int) *dao_interfaces.ActivableProposalModule {
if moduleIndex < 0 {
panic("module index must be >= 0")
}
mods := core.ProposalModules()
if moduleIndex >= len(mods) {
panic("invalid module index")
}
return &mods[moduleIndex]
}

// internal

func (d *daoCore) executeMsgs(msgs []dao_interfaces.ExecutableMessage) {
for _, msg := range msgs {
d.registry.Execute(msg)
}
}

func (d *daoCore) addProposalModule(proposalMod dao_interfaces.IProposalModule) {
for _, mod := range d.proposalModules {
if mod.Module != proposalMod {
continue
}

if mod.Enabled {
panic(ErrModuleAlreadyAdded)
}
mod.Enabled = true
d.activeProposalModuleCount++
return
}

d.proposalModules = append(d.proposalModules, dao_interfaces.ActivableProposalModule{
Enabled: true,
Module: proposalMod,
})

d.activeProposalModuleCount++
}
Loading