Skip to content

Commit

Permalink
Connect Justice DAO solution to escrow realm to determine the final a…
Browse files Browse the repository at this point in the history
…mount by DAO
  • Loading branch information
go7066 committed Sep 19, 2023
1 parent 55efafe commit 103cbef
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 36 deletions.
49 changes: 28 additions & 21 deletions examples/gno.land/r/demo/justicedao/justicedao.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package justicedao
import (
"gno.land/p/demo/avl"
fmt "gno.land/p/demo/ufmt"
escrow "gno.land/r/demo/escrow_05"
vrf "gno.land/r/demo/vrf_08"
"std"
"strconv"
Expand Down Expand Up @@ -91,16 +92,18 @@ type Proposal struct {
}

type JusticeProposal struct {
id uint64 // unique id assigned for each proposal
title string // proposal title
summary string // proposal summary
vrfId uint64 // the vrf request id being used to determine governers
governers []string // the governers of the proposal
solution string // proposed result of justice DAO proposal
submitTime uint64 // solution submission time
voteEndTime uint64 // vote end time for the proposal
status ProposalStatus // StatusNil | StatusVotingPeriod | StatusPassed | StatusRejected | StatusFailed
votes []Vote
id uint64 // unique id assigned for each proposal
title string // proposal title
summary string // proposal summary
vrfId uint64 // the vrf request id being used to determine governers
governers []string // the governers of the proposal
contractId uint64 // the escrow contract id to resolve
sellerAmount uint64 // the seller amount determined by Justice DAO
solution string // proposed result of justice DAO proposal
submitTime uint64 // solution submission time
voteEndTime uint64 // vote end time for the proposal
status ProposalStatus // StatusNil | StatusVotingPeriod | StatusPassed | StatusRejected | StatusFailed
votes []Vote
}

// GNODAO STATE
Expand Down Expand Up @@ -543,19 +546,21 @@ func Render(path string) string {
}

func CreateJusticeProposal(
title, summary string,
title, summary string, contractId uint64,
) {
reqId := vrf.RequestRandomWords(1)
justiceProposals = append(justiceProposals, JusticeProposal{
id: uint64(len(justiceProposals)),
title: title,
summary: summary,
vrfId: reqId,
governers: []string{},
solution: "",
voteEndTime: 0,
status: NIL,
votes: []Vote{},
id: uint64(len(justiceProposals)),
title: title,
summary: summary,
vrfId: reqId,
governers: []string{},
solution: "",
voteEndTime: 0,
status: NIL,
votes: []Vote{},
contractId: contractId,
sellerAmount: 0,
})
}

Expand Down Expand Up @@ -590,11 +595,12 @@ func DetermineJusticeDAOMembers(id uint64) {
}
}

func ProposeJusticeDAOSolution(id uint64, solution string) {
func ProposeJusticeDAOSolution(id uint64, sellerAmount uint64, solution string) {
if int(id) >= len(justiceProposals) {
panic("invalid justice DAO proposal id")
}

justiceProposals[id].sellerAmount = sellerAmount
justiceProposals[id].solution = solution
justiceProposals[id].submitTime = uint64(time.Now().Unix())
justiceProposals[id].voteEndTime = uint64(time.Now().Unix()) + dao.votingPeriod
Expand Down Expand Up @@ -672,6 +678,7 @@ func TallyAndExecuteJusticeSolution(proposalId uint64) {
// If more than 2/3 votes Yes, let it pass
if numYesVotes > 0 && numYesVotes*3 >= uint64(len(proposal.governers))*2 {
justiceProposals[proposalId].status = PASSED
escrow.CompleteContractByDAO(proposal.contractId, proposal.sellerAmount)
} else {
justiceProposals[proposalId].status = REJECTED
}
Expand Down
32 changes: 17 additions & 15 deletions examples/gno.land/r/demo/justicedao/justicedao_teritori_testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ gnokey maketx addpkg \
-broadcast="true" \
-remote="51.15.236.215:26657" \
-chainid="teritori-1" \
-pkgdir="./r/justicedao" \
-pkgpath="gno.land/r/demo/justicedao_05" \
-pkgdir="./r/demo/justicedao" \
-pkgpath="gno.land/r/demo/justicedao_10" \
teritori

# Create DAO
Expand All @@ -30,7 +30,7 @@ gnokey maketx call \
-broadcast="true" \
-remote="51.15.236.215:26657" \
-chainid="teritori-1" \
-pkgpath="gno.land/r/demo/justicedao_05" \
-pkgpath="gno.land/r/demo/justicedao_10" \
-func="CreateDAO" \
-args="https://gnodao1.org" \
-args="https://metadata.gnodao1.org" \
Expand All @@ -50,10 +50,11 @@ gnokey maketx call \
-broadcast="true" \
-remote="51.15.236.215:26657" \
-chainid="teritori-1" \
-pkgpath="gno.land/r/demo/justicedao_05" \
-pkgpath="gno.land/r/demo/justicedao_10" \
-func="CreateJusticeProposal" \
-args="First Justice DAO proposal" \
-args="First Justice DAO proposal summary" \
-args="1" \
teritori

# Fulfill Random Words on VRF
Expand All @@ -65,7 +66,7 @@ gnokey maketx call \
-chainid="teritori-1" \
-pkgpath="gno.land/r/demo/vrf_08" \
-func="FulfillRandomWords" \
-args="4" \
-args="7" \
-args="f440c4980357d8b56db87ddd50f06bd551f1319b" \
teritori

Expand All @@ -76,7 +77,7 @@ gnokey maketx call \
-broadcast="true" \
-remote="51.15.236.215:26657" \
-chainid="teritori-1" \
-pkgpath="gno.land/r/demo/justicedao_05" \
-pkgpath="gno.land/r/demo/justicedao_10" \
-func="DetermineJusticeDAOMembers" \
-args="0" \
teritori
Expand All @@ -88,9 +89,10 @@ gnokey maketx call \
-broadcast="true" \
-remote="51.15.236.215:26657" \
-chainid="teritori-1" \
-pkgpath="gno.land/r/demo/justicedao_05" \
-pkgpath="gno.land/r/demo/justicedao_10" \
-func="ProposeJusticeDAOSolution" \
-args="0" \
-args="50" \
-args="Split 50:50" \
teritori

Expand All @@ -101,7 +103,7 @@ gnokey maketx call \
-broadcast="true" \
-remote="51.15.236.215:26657" \
-chainid="teritori-1" \
-pkgpath="gno.land/r/demo/justicedao_05" \
-pkgpath="gno.land/r/demo/justicedao_10" \
-func="VoteJusticeSolutionProposal" \
-args="0" \
-args="0" \
Expand All @@ -114,7 +116,7 @@ gnokey maketx call \
-broadcast="true" \
-remote="51.15.236.215:26657" \
-chainid="teritori-1" \
-pkgpath="gno.land/r/demo/justicedao_05" \
-pkgpath="gno.land/r/demo/justicedao_10" \
-func="TallyAndExecuteJusticeSolution" \
-args="0" \
teritori
Expand All @@ -126,7 +128,7 @@ gnokey maketx call \
-broadcast="true" \
-remote="51.15.236.215:26657" \
-chainid="teritori-1" \
-pkgpath="gno.land/r/demo/justicedao_05" \
-pkgpath="gno.land/r/demo/justicedao_10" \
-func="CreateProposal" \
-args="First proposal" \
-args="First proposal summary" \
Expand All @@ -139,19 +141,19 @@ gnokey maketx call \
teritori

# Query proposal
gnokey query "vm/qeval" -data="gno.land/r/demo/justicedao_05
gnokey query "vm/qeval" -data="gno.land/r/demo/justicedao_10
RenderProposal(0)" -remote="51.15.236.215:26657"

# Render Juste DAO Proposal
gnokey query "vm/qeval" -data="gno.land/r/demo/justicedao_05
gnokey query "vm/qeval" -data="gno.land/r/demo/justicedao_10
RenderJusticeDAOProposal(0)" -remote="51.15.236.215:26657"

# Render Justice DAO Proposals
gnokey query "vm/qeval" -data="gno.land/r/demo/justicedao_05
gnokey query "vm/qeval" -data="gno.land/r/demo/justicedao_10
RenderJusticeDAOProposals(0, 1)" -remote="51.15.236.215:26657"

gnokey query "vm/qeval" -data="gno.land/r/demo/justicedao_05
gnokey query "vm/qeval" -data="gno.land/r/demo/justicedao_10
GetDAOMembers()" -remote="51.15.236.215:26657"

gnokey query "vm/qeval" -data="gno.land/r/demo/justicedao_05
gnokey query "vm/qeval" -data="gno.land/r/demo/justicedao_10
RenderDAOMembers(\"\",\"\")" -remote="51.15.236.215:26657"
96 changes: 96 additions & 0 deletions examples/gno.land/r/demo/justicedao/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,99 @@ Those random members selected all have same voting power and those members do on
We consider the conflict proposal as a specific proposal called `Justice DAO Proposal`, while normal proposal is for internal DAO management.

Justice DAO uses `VRF` realm to determine random members.

## Data structure

Justice DAO has 3 main sections.

- `DAO` to manage overall members and DAO itself

```go
type DAO struct {
uri string // DAO homepage link
metadata string // DAO metadata reference link
funds uint64 // DAO managing funds
depositHistory []string // deposit history - reserved for later use
spendHistory []string // spend history - reserved for later use
permissions []string // permissions managed on DAO - reserved for later use
permMap *avl.Tree // permission map - reserved for later use
votingPowers *avl.Tree
totalVotingPower uint64
votingPeriod uint64
voteQuorum uint64
threshold uint64
vetoThreshold uint64
numJusticeDAO uint64 // number of justice DAO members on justice proposal
}
```

- `Proposal` to manage interal DAO related proposals

```go

type Vote struct {
address std.Address // address of the voter
timestamp uint64 // block timestamp of the vote
option VoteOption // vote option
}


type VotingPower struct {
address string
power uint64
}

type Proposal struct {
id uint64 // unique id assigned for each proposal
title string // proposal title
summary string // proposal summary
spendAmount uint64 // amount of tokens to spend as part the proposal
spender std.Address // address to receive spending tokens
vpUpdates []VotingPower // updates on voting power - optional
newMetadata string // new metadata for the DAO - optional
newURI string // new URI for the DAO - optional
submitTime uint64 // proposal submission time
voteEndTime uint64 // vote end time for the proposal
status ProposalStatus // StatusNil | StatusVotingPeriod | StatusPassed | StatusRejected | StatusFailed
votes *avl.Tree // votes on the proposal
votingPowers []uint64 // voting power sum per voting option
}

```

- `JusticeProposal` for external requests to resolve.

```go
type JusticeProposal struct {
id uint64 // unique id assigned for each proposal
title string // proposal title
summary string // proposal summary
vrfId uint64 // the vrf request id being used to determine governers
governers []string // the governers of the proposal
contractId uint64 // the escrow contract id to resolve
sellerAmount uint64 // the seller amount determined by Justice DAO
solution string // proposed result of justice DAO proposal
submitTime uint64 // solution submission time
voteEndTime uint64 // vote end time for the proposal
status ProposalStatus // StatusNil | StatusVotingPeriod | StatusPassed | StatusRejected | StatusFailed
votes []Vote
}
```

## Realm configuration process

Create DAO by usin `CreateDAO` endpoint

## DAO internal proposals flow

- `CreateProposal` to create an internal proposal
- `VoteProposal` to vote an internal proposal
- `TallyAndExecute` to execute the finally voted proposal

## DAO justice proposals flow

- `CreateJusticeProposal` to create a justice DAO proposal, this requests random number to `VRF` and it will be needed to wait until the required number of random word feeders to feed the words
- `DetermineJusticeDAOMembers` to determine random members from Justice DAO
- `ProposeJusticeDAOSolution` to propose Justice DAO solution by one of elected Justice DAO member
- `VoteJusticeSolutionProposal` to vote on Justice DAO solution
- `TallyAndExecuteJusticeSolution` to execute the finally voted justice DAO solution

0 comments on commit 103cbef

Please sign in to comment.