Skip to content

Commit

Permalink
Merge branch 'main' into feat-rakki-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
WaDadidou authored Dec 20, 2024
2 parents 70ff903 + a475671 commit a6f190e
Show file tree
Hide file tree
Showing 90 changed files with 1,657 additions and 689 deletions.
2 changes: 1 addition & 1 deletion .gnoversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9786fa366f922f04e1251ec6f1df6423b4fd2bf4
c8cd8f4b6ccbe9f4ee5622032228553496186d51
6 changes: 4 additions & 2 deletions cypress/e2e/gno/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ export const resetChain = () => {

export const connectWallet = () => {
// NOTE: Wait a little bit to ensure that Connect wallet exist and clickable
cy.wait(500);
cy.wait(2000);

cy.contains("Connect wallet").click({ force: true });

cy.get("div[data-testid=connect-gnotest-wallet]", {
timeout: 5_000,
}).click({ force: true });
})
.should("exist")
.click({ force: true });
cy.contains("Connect wallet").should("not.exist");
};
13 changes: 7 additions & 6 deletions gno/p/dao_core/dao_core.gno
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ func NewDAOCore(
proposalModules: make([]dao_interfaces.ActivableProposalModule, len(proposalModulesFactories)),
}

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

// important to keep this order since voting module might depend on roles module
core.rolesModule = rolesModuleFactory(core)
if core.rolesModule == nil {
panic("roles module factory returned nil")
}

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 {
Expand Down Expand Up @@ -157,7 +158,7 @@ func (d *daoCore) GetMembersJSON(start, end string, limit uint64, height int64)
}

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

func (d *daoCore) ActiveProposalModuleCount() int {
Expand Down
8 changes: 6 additions & 2 deletions gno/p/dao_core/dao_core_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (vm *votingModule) Render(path string) string {
return "# Test Voting Module"
}

func (vm *votingModule) VotingPowerAtHeight(address std.Address, height int64) uint64 {
func (vm *votingModule) VotingPowerAtHeight(address std.Address, height int64, resources []string) uint64 {
return 0
}

Expand Down Expand Up @@ -73,7 +73,7 @@ func (rm *rolesModule) HasRole(address std.Address, role string) bool {
return false
}

func (rm *rolesModule) NewRole(roleName string) {
func (rm *rolesModule) NewRoleJSON(roleName, resourcesJSON string) {
panic("not implemented")
}

Expand All @@ -93,6 +93,10 @@ func (rm *rolesModule) GetMemberRoles(address std.Address) []string {
return []string{}
}

func (rm *rolesModule) GetMemberResourceVPower(address std.Address, resource string) uint64 {
return 0
}

type proposalModule struct {
core dao_interfaces.IDAOCore
}
Expand Down
6 changes: 0 additions & 6 deletions gno/p/dao_core/gno.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
module gno.land/p/teritori/dao_core

require (
gno.land/p/demo/json v0.0.0-latest
gno.land/p/teritori/dao_interfaces v0.0.0-latest
gno.land/p/teritori/jsonutil v0.0.0-latest
)
5 changes: 0 additions & 5 deletions gno/p/dao_interfaces/gno.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
module gno.land/p/teritori/dao_interfaces

require (
gno.land/p/demo/avl v0.0.0-latest
gno.land/p/demo/json v0.0.0-latest
)
5 changes: 3 additions & 2 deletions gno/p/dao_interfaces/modules.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type IVotingModule interface {
ConfigJSON() string
GetMembersJSON(start, end string, limit uint64, height int64) string
Render(path string) string
VotingPowerAtHeight(address std.Address, height int64) (power uint64)
VotingPowerAtHeight(address std.Address, height int64, resources []string) (power uint64)
TotalPowerAtHeight(height int64) uint64
}

Expand All @@ -43,8 +43,9 @@ type IRolesModule interface {
ConfigJSON() string
Render(path string) string
GetMemberRoles(address std.Address) []string
GetMemberResourceVPower(address std.Address, resource string) uint64
HasRole(address std.Address, role string) bool
NewRole(roleName string)
NewRoleJSON(roleName, resourcesJSON string)
DeleteRole(roleName string)
GrantRole(address std.Address, role string)
RevokeRole(address std.Address, role string)
Expand Down
7 changes: 6 additions & 1 deletion gno/p/dao_proposal_single/dao_proposal_single.gno
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,12 @@ func (d *DAOProposalSingle) VoteJSON(proposalID int, voteJSON string) {
panic("proposal is expired")
}

votePower := d.core.VotingModule().VotingPowerAtHeight(voter, proposal.StartHeight)
resources := make([]string, len(proposal.Messages))
for i, m := range proposal.Messages {
resources[i] = m.Type()
}

votePower := d.core.VotingModule().VotingPowerAtHeight(voter, proposal.StartHeight, resources)
if votePower == 0 {
panic("not registered")
}
Expand Down
8 changes: 0 additions & 8 deletions gno/p/dao_proposal_single/gno.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
module gno.land/p/teritori/dao_proposal_single

require (
gno.land/p/demo/avl v0.0.0-latest
gno.land/p/demo/json v0.0.0-latest
gno.land/p/teritori/dao_interfaces v0.0.0-latest
gno.land/p/teritori/dao_utils v0.0.0-latest
gno.land/p/teritori/jsonutil v0.0.0-latest
)
7 changes: 0 additions & 7 deletions gno/p/dao_roles_group/gno.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
module gno.land/p/teritori/dao_roles_group

require (
gno.land/p/demo/json v0.0.0-latest
gno.land/p/teritori/dao_interfaces v0.0.0-latest
gno.land/p/teritori/jsonutil v0.0.0-latest
gno.land/p/teritori/role_manager v0.0.0-latest
)
49 changes: 46 additions & 3 deletions gno/p/dao_roles_group/roles_group.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dao_roles_group
import (
"std"

"gno.land/p/demo/avl"
"gno.land/p/demo/json"
dao_interfaces "gno.land/p/teritori/dao_interfaces"
"gno.land/p/teritori/jsonutil"
Expand All @@ -12,12 +13,19 @@ import (
type RolesGroup struct {
dao_interfaces.IRolesModule

rm *role_manager.RoleManager
rm *role_manager.RoleManager
resourcesVPower *avl.Tree // roles -> ResourceVPower[]
}

type ResourceVPower struct {
Resource string
Power uint64
}

func NewRolesGroup() *RolesGroup {
return &RolesGroup{
rm: role_manager.NewWithAddress(std.PrevRealm().Addr()),
rm: role_manager.NewWithAddress(std.PrevRealm().Addr()),
resourcesVPower: avl.NewTree(),
}
}

Expand All @@ -42,8 +50,25 @@ func (r *RolesGroup) HasRole(address std.Address, role string) bool {
return r.rm.HasRole(address, role)
}

func (r *RolesGroup) NewRole(roleName string) {
func (r *RolesGroup) NewRoleJSON(roleName, resourcesJSON string) {
node := json.Must(json.Unmarshal([]byte(resourcesJSON)))
arr := node.MustArray()
resources := make([]ResourceVPower, len(arr))
for i, n := range arr {
node := n.MustObject()
resources[i] = ResourceVPower{
Resource: node["resource"].MustString(),
Power: jsonutil.MustUint64(node["power"]),
}
}
r.NewRole(roleName, resources)
}

func (r *RolesGroup) NewRole(roleName string, resources []ResourceVPower) {
r.rm.CreateNewRole(roleName, []string{})
if len(resources) > 0 {
r.resourcesVPower.Set(roleName, resources)
}
}

func (r *RolesGroup) DeleteRole(roleName string) {
Expand All @@ -61,3 +86,21 @@ func (r *RolesGroup) RevokeRole(address std.Address, role string) {
func (r *RolesGroup) GetMemberRoles(address std.Address) []string {
return r.rm.GetUserRoles(address)
}

func (r *RolesGroup) GetMemberResourceVPower(address std.Address, resource string) uint64 {
roles := r.rm.GetUserRoles(address)
power := uint64(0)
for _, role := range roles {
resourcesRaw, exists := r.resourcesVPower.Get(role)
if !exists {
continue
}
resources := resourcesRaw.([]ResourceVPower)
for _, r := range resources {
if r.Resource == resource && r.Power > power {
power = r.Power
}
}
}
return power
}
1 change: 1 addition & 0 deletions gno/p/dao_roles_voting_group/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/teritori/dao_roles_voting_group
62 changes: 62 additions & 0 deletions gno/p/dao_roles_voting_group/messages.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package dao_roles_voting_group

import (
"gno.land/p/demo/json"
"gno.land/p/teritori/dao_interfaces"
)

const updateMembersType = "gno.land/p/teritori/dao_voting_group.UpdateMembers"

type UpdateMembersExecutableMessage []Member

var _ dao_interfaces.ExecutableMessage = (*UpdateMembersExecutableMessage)(nil)

func (m *UpdateMembersExecutableMessage) FromJSON(ast *json.Node) {
changes := ast.MustArray()
*m = make([]Member, len(changes))
for i, change := range changes {
(*m)[i].FromJSON(change)
}
}

func (m *UpdateMembersExecutableMessage) ToJSON() *json.Node {
changes := make([]*json.Node, len(*m))
for i, change := range *m {
changes[i] = change.ToJSON()
}

return json.ArrayNode("", changes)
}

func (m *UpdateMembersExecutableMessage) String() string {
return m.ToJSON().String()
}

func (m *UpdateMembersExecutableMessage) Type() string {
return updateMembersType
}

type updateMembersHandler struct {
vg *RolesVotingGroup
}

var _ dao_interfaces.MessageHandler = (*updateMembersHandler)(nil)

func (h *updateMembersHandler) Type() string {
return updateMembersType
}

func (h *updateMembersHandler) Execute(msg dao_interfaces.ExecutableMessage) {
m, ok := msg.(*UpdateMembersExecutableMessage)
if !ok {
panic("unexpected message type")
}

for _, change := range *m {
h.vg.SetMemberPower(change.Address, change.Power)
}
}

func (h *updateMembersHandler) Instantiate() dao_interfaces.ExecutableMessage {
return &UpdateMembersExecutableMessage{}
}
Loading

0 comments on commit a6f190e

Please sign in to comment.