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(examples/moul): ownable, entity, safe #2844

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 36 additions & 0 deletions examples/gno.land/p/moul/entity/entity.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Package entity provides an interface that abstracts a notion of entity which
// can under the hood be an EOA (std.Address), a package realm (PkgPath,
// std.Address). It also tries to give a notion of type where for instance, a
// user can be either a simple user or a team, and a contract can be either an
// arbitrary contract, or one that implements a famous pattern/interface, such
// as a DAO. It also provides some composition utilities so that an entity can
// be a flow that matches multiple other entities.
package entity

import (
"std"

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

type Entity interface {
Addr() std.Address
Path() string
Kind
isEntity()
}

type UserEntity interface {
Entity
isUserEntity()
}

type RealmEntity interface {
Entity
isRealmEntity()
}

func NewUserByAddr(addr std.Address) UserEntity { panic("not implemented") }
func NewUserByAddrOrName(aon users.AddressOrName) UserEntity { panic("not implemented") }
func NewUserByName(name string) UserEntity { panic("not implemented") }
func NewRealm(rlm std.Realm) RealmEntity { panic("not implemented") }
30 changes: 30 additions & 0 deletions examples/gno.land/p/moul/ownable/ownable.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Package ownable propose an abstraction around the ownership which provides
// various kind of owners and some composition options.
package ownable

import "std"

type Owner interface {
Addr() std.Address
Kind() Kind
owner()
}

type UserOwner struct {
addr std.Address
}

type RealmOwner struct {
realm std.Realm
}

type MembstoreOwner struct {
// membstore.Membstore
}

type DAOOwner struct {
// dao.DAO
}

func And(a, b ...Owner) Owner { panic("not implemented") }
func Or(a, b ...Owner) Owner { panic("not implemented") }
74 changes: 74 additions & 0 deletions examples/gno.land/p/moul/safe/safe.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Package safe is inspired by Gnosis Safe
package safe

import (
"std"

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

// Gnosis safe style using this with threshold
// : affMember + update threshold at the same time

type Safe interface {
Name() string
Members() []std.Address
Threshold() uint
Size() uint
NextProposal() Proposal
UpcomingProposals(page uint) (props []Proposal, total uint)
PreviousProposals(page uint) (props []Proposal, total uint)
// balances (native, grc20, grc721)

ProposeAddingMember(addr std.Address, newThreshold uint) (prop Proposal, err error)
ProposeRemovingMember(addr std.Address, newThreshold uint) (prop Proposal, err error)
ProposeUpdatingThreshold(newThreshold uint) (prop Proposal, err error)
// ProposeClosure(cl func()) (prop Proposal, err error)
// ProposeBankXXX()
// ProposeGRC20XXX()
// ProposeGRC721XXX()

GetProposal(id uint) Proposal
ApproveProposal(p Proposal) error
ExecuteProposal(p Proposal) error
CancelProposal(p Proposal) error // XXX: should be ProposeToCancel?

Render(path string) string
}

type Proposal interface {
ID() uint
Active() bool
Executed() bool
Voters() []std.Address
}

func NewSafe() Safe {
caller := std.PrevRealm().Addr()
return safe{
members: []std.Address{caller},
threshold: 1,
prevProps: []Proposal{},
nextProps: []Proposal{},
}
}

type safe struct {
name string
members avl.Tree // id -> std.Address
threshold uint
prevProps avl.tree // pid -> Proposal
nextProps avl.Tree // pid -> Proposal
}

func (s safe) String() string { panic("not implemented") }

func (s safe) Members() []std.Address { return s.members }
func (s safe) Threshold() uint { return s.threshold }
func (s safe) Size() uint { return len(s.members) }
func (s *safe) AddMember(addr std.Address, newThreshold uint) error {
}

type proposal struct{}

func (p proposal) String() string { panic("not implemented") }
Loading