Skip to content

Commit

Permalink
Cosmos native staking (#783)
Browse files Browse the repository at this point in the history
* Wooooooo

Co-authored-by: Reece Williams <[email protected]>
Co-authored-by: Jake Hartnell <[email protected]>

* Start Delegation Changes & Happy Path

---------

Co-authored-by: Reece Williams <[email protected]>
Co-authored-by: Jake Hartnell <[email protected]>
  • Loading branch information
3 people authored Dec 14, 2023
1 parent a843c37 commit 6bd2785
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 3,366 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions contracts/voting/dao-voting-cosmos-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,4 @@ dao-proposal-single = { workspace = true }
dao-proposal-hook-counter = { workspace = true }
dao-test-custom-factory = { workspace = true }
dao-testing = { workspace = true, features = ["test-tube"] }
osmosis-std = { workspace = true }
osmosis-test-tube = { workspace = true }
serde = { workspace = true }
70 changes: 70 additions & 0 deletions contracts/voting/dao-voting-cosmos-staking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,73 @@
A DAO DAO voting contract that uses Cosmos SDK staking for calculating voting power.

For example, if I stake 100 Juno, I have 100 Juno worth of voting power in the DAO.

## Naive Approach: Mirror with historical data

Just query for info...

Problem: no historical info.

```ignore
QueryMsg::VotingPowerAtHeight { address, height } => {
// Check if is historical data
let staking_history = HISTORICAL_STAKING_SNAPSHOT.may_load(address, height)
// If no historical data, query stargate delegation info (just ignore height as long as it's less than unbonding period)
match staking_history {
// IF historical data, we use that
Some(hist) => Ok(hist),
// else do a stargate query, user's staking balance hasn't changed since snapshotting began
None => {
// Stargate Query!
}
}
}
QueryMsg::TotalPowerAtHeight { height } => {
// TODO query total power (store as snapshot map)
}
// cw-hooks
SudoMsg::AfterDelegationModified {validator: String, delegator: String, shares: String} => {
// if delegator is in a pending proposals vote list, update theri vote
HISTORICAL_STAKING_SNAPSHOT.save(info)
}
```


# on change
- user votes, query current VP delegated
- cw-hooks update the previous VP change amount


When a prop is created, we could have a hook that stores current total voting power at proposal start time.
Use clock to fire membership changed events.

## Solution with Clock

- Every end of block, the `SudoMsg::ClockEndBlock` will be called by the chain (when registered).
- execute the proposal then
- only direct votes (no validator overrides)
- always have quaroum? (DAO config to allow for % of total, OR instant quaroum based off of the voted accounts)
- execute it if end


- 2bn gas limit, assume this for the contract.
- SudoMsg::ClockEndBlock
- iter all proposals currently in voting period
- if proposal is expired, execute it
- on exec, query stake from stargate for everyone who voted
- sum this up, then perform based off the config (quaroum, % of total who did vote, etc)



# flow
- put up a proposal, text
- people vote on it, we ONLY save their juno address to a list / map (we do not care about VP)
- execute closes voting period, expire (pre tally)
- ClockEndBlock sees this, then queries ALL balances from the list, tallies it up, and executes if




Loading

0 comments on commit 6bd2785

Please sign in to comment.