From a1dab988184b271dd242fa397efac76dd4de2c6b Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 21 Sep 2024 17:05:40 +0200 Subject: [PATCH 1/4] feat: add moul/ownable opinionated framework Signed-off-by: moul <94029+moul@users.noreply.github.com> --- examples/gno.land/r/moul/ownable/ownable.gno | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 examples/gno.land/r/moul/ownable/ownable.gno diff --git a/examples/gno.land/r/moul/ownable/ownable.gno b/examples/gno.land/r/moul/ownable/ownable.gno new file mode 100644 index 00000000000..45ceab37eab --- /dev/null +++ b/examples/gno.land/r/moul/ownable/ownable.gno @@ -0,0 +1,7 @@ +package ownable + +// – Ownavoe, members, dao implements the CannDoEr +// Recursive usage of it so a member list is owned by a single admin( but the admin can give ownership to member list +// Gnosis safe style using this with threshold +// : affMember + update threshold at the same time +// Composition!!!! OrCanDo(à,b) admin + dao From f4f74d14a7fda5fdde6b9de5091d55e429982eff Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Tue, 24 Sep 2024 19:43:21 +0200 Subject: [PATCH 2/4] chore: bootstrap entity Signed-off-by: moul <94029+moul@users.noreply.github.com> --- examples/gno.land/p/moul/entity/entity.gno | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/gno.land/p/moul/entity/entity.gno diff --git a/examples/gno.land/p/moul/entity/entity.gno b/examples/gno.land/p/moul/entity/entity.gno new file mode 100644 index 00000000000..707433cea12 --- /dev/null +++ b/examples/gno.land/p/moul/entity/entity.gno @@ -0,0 +1,21 @@ +// 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" + +type Entity interface { + Addr() std.Address + Path() string + Kind + isEntity() +} + +type UserEntity interface { + Entity + isUserEntity() +} + +type RealmEntity interface { + Entity + isRealmEntity() +} From 17b64bd05ca564e518f6eb563f3cbce08499b82f Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Tue, 24 Sep 2024 20:26:14 +0200 Subject: [PATCH 3/4] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- examples/gno.land/p/moul/entity/entity.gno | 19 +++++- examples/gno.land/p/moul/ownable/ownable.gno | 30 +++++++++ examples/gno.land/p/moul/safe/safe.gno | 66 ++++++++++++++++++++ examples/gno.land/r/moul/ownable/ownable.gno | 7 --- 4 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 examples/gno.land/p/moul/ownable/ownable.gno create mode 100644 examples/gno.land/p/moul/safe/safe.gno delete mode 100644 examples/gno.land/r/moul/ownable/ownable.gno diff --git a/examples/gno.land/p/moul/entity/entity.gno b/examples/gno.land/p/moul/entity/entity.gno index 707433cea12..34846cc10b4 100644 --- a/examples/gno.land/p/moul/entity/entity.gno +++ b/examples/gno.land/p/moul/entity/entity.gno @@ -1,7 +1,17 @@ -// 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 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" +import ( + "std" + + "gno.land/p/demo/users" +) type Entity interface { Addr() std.Address @@ -19,3 +29,8 @@ 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") } diff --git a/examples/gno.land/p/moul/ownable/ownable.gno b/examples/gno.land/p/moul/ownable/ownable.gno new file mode 100644 index 00000000000..b728e83a66a --- /dev/null +++ b/examples/gno.land/p/moul/ownable/ownable.gno @@ -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") } diff --git a/examples/gno.land/p/moul/safe/safe.gno b/examples/gno.land/p/moul/safe/safe.gno new file mode 100644 index 00000000000..1867a9dac1f --- /dev/null +++ b/examples/gno.land/p/moul/safe/safe.gno @@ -0,0 +1,66 @@ +// 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? +} + +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) 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 { +} diff --git a/examples/gno.land/r/moul/ownable/ownable.gno b/examples/gno.land/r/moul/ownable/ownable.gno deleted file mode 100644 index 45ceab37eab..00000000000 --- a/examples/gno.land/r/moul/ownable/ownable.gno +++ /dev/null @@ -1,7 +0,0 @@ -package ownable - -// – Ownavoe, members, dao implements the CannDoEr -// Recursive usage of it so a member list is owned by a single admin( but the admin can give ownership to member list -// Gnosis safe style using this with threshold -// : affMember + update threshold at the same time -// Composition!!!! OrCanDo(à,b) admin + dao From 6fd58d6c7cc71dbd61539389e92893344ff656d2 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Tue, 24 Sep 2024 20:27:51 +0200 Subject: [PATCH 4/4] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- examples/gno.land/p/moul/safe/safe.gno | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/gno.land/p/moul/safe/safe.gno b/examples/gno.land/p/moul/safe/safe.gno index 1867a9dac1f..1e19e77177c 100644 --- a/examples/gno.land/p/moul/safe/safe.gno +++ b/examples/gno.land/p/moul/safe/safe.gno @@ -32,6 +32,8 @@ type Safe interface { ApproveProposal(p Proposal) error ExecuteProposal(p Proposal) error CancelProposal(p Proposal) error // XXX: should be ProposeToCancel? + + Render(path string) string } type Proposal interface { @@ -59,8 +61,14 @@ type safe struct { 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") }