-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PoC,gov): initial sys/validators and gov/dao contracts (#1945)
This PR showcases a model that combines multiple contracts with defined goals and constraints. The aim is to make everything in `sys/*` usable by the chain (tm2 powered) efficiently, with minimal need for updates while maintaining flexibility in usage. The `sys/` contracts focus on defining data types and helpers to ensure that received callbacks meet minimal constraints, like GovDAO approval. They do not handle DAO logic or state due to complexity and upgradability requirements for DAOs. I won't include complete DAO examples in this PR. Imagine having these sections once everything is done: - `{p,r}/sys: minimal interface with the chain` - `{p,r}/gov: simple DAO frameworks` - `{p,r}/*`: where users will develop permissionless logic and propose it to `gov` for approval using `sys` to trigger the chain. Personal note -> try to introduce and document the notion of "pausable threads". Related with #1974. --- TODO: - [x] pseudo-code for proof of conribution's valset management. - [x] proposal example. - [ ] pseudo-code for gnosdk v0 to catch the event and apply the change from tm2. cc @gfanton - [ ] add unit-tests, to illustrate the expected usage. depends on std.Emit (#575). depends on #1948 (need rebase). --------- Signed-off-by: moul <94029+moul@users.noreply.github.com> Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com> Co-authored-by: Milos Zivkovic <milos.zivkovic@tendermint.com> Co-authored-by: gfanton <8671905+gfanton@users.noreply.github.com>
- Loading branch information
1 parent
e3f33a2
commit 145f612
Showing
17 changed files
with
346 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module proposal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Package proposal provides a structure for executing proposals. | ||
package proposal | ||
|
||
// NewExecutor creates a new executor with the provided callback function. | ||
func NewExecutor(callback func() error) Executor { | ||
return &executorImpl{ | ||
callback: callback, | ||
done: false, | ||
} | ||
} | ||
|
||
// executorImpl is an implementation of the Executor interface. | ||
type executorImpl struct { | ||
callback func() error | ||
done bool | ||
success bool | ||
} | ||
|
||
// execute runs the executor's callback function. | ||
func (exec *executorImpl) Execute() error { | ||
if exec.done { | ||
return ErrAlreadyDone | ||
} | ||
// XXX: assertCalledByGovdao | ||
err := exec.callback() | ||
exec.done = true | ||
exec.success = err == nil | ||
return err | ||
} | ||
|
||
// Done returns whether the executor has been executed. | ||
func (exec *executorImpl) Done() bool { | ||
return exec.done | ||
} | ||
|
||
// Success returns whether the execution was successful. | ||
func (exec *executorImpl) Success() bool { | ||
return exec.success | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Package proposal defines types for proposal execution. | ||
package proposal | ||
|
||
import "errors" | ||
|
||
// Executor represents a minimal closure-oriented proposal design. | ||
// It is intended to be used by a govdao governance proposal (v1, v2, etc). | ||
type Executor interface { | ||
Execute() error | ||
Done() bool | ||
Success() bool // Done() && !err | ||
} | ||
|
||
// ErrAlreadyDone is the error returned when trying to execute an already | ||
// executed proposal. | ||
var ErrAlreadyDone = errors.New("already executed") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module valopers | ||
|
||
require ( | ||
gno.land/p/demo/ownable v0.0.0-latest | ||
gno.land/r/gov/dao v0.0.0-latest | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Package valopers is designed around the permissionless lifecycle of valoper profiles. | ||
// It also includes parts designed for govdao to propose valset changes based on registered valopers. | ||
package valopers | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/p/demo/ownable" | ||
govdao "gno.land/r/gov/dao" | ||
) | ||
|
||
// Valoper represents a validator operator profile. | ||
type Valoper struct { | ||
ownable.Ownable // Embedding the Ownable type for ownership management. | ||
|
||
DisplayName string // The display name of the valoper. | ||
ValidatorAddr std.Address // The address of the validator. | ||
// TODO: Add other valoper metadata as needed. | ||
} | ||
|
||
// Register registers a new valoper. | ||
// TODO: Define the parameters and implement the function. | ||
func Register( /* TBD */ ) { | ||
panic("not implemented") | ||
} | ||
|
||
// Update updates an existing valoper. | ||
// TODO: Define the parameters and implement the function. | ||
func Update( /* TBD */ ) { | ||
panic("not implemented") | ||
} | ||
|
||
// GovXXX is a placeholder for a function to interact with the governance DAO. | ||
// TODO: Define a good API and implement it. | ||
func GovXXX() { | ||
// Assert that the caller is a member of the governance DAO. | ||
govdao.AssertIsMember(std.PrevRealm().Addr()) | ||
panic("not implemented") | ||
} |
Oops, something went wrong.