Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

staking rewards distribution followup #835

Merged
merged 53 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
fb8e9cd
re-added schema cargo cmd
NoahSaso Jun 6, 2024
a3eda5c
Move cw-fund-distributor to new distribution folder
JakeHartnell Jan 3, 2024
b6db195
Make more generic version of cw20-stake-external-rewards
JakeHartnell Jan 3, 2024
ead0e3c
Make rewards distribution working with all DAO types
JakeHartnell Jan 3, 2024
bead1c3
Break out tests into separate file
JakeHartnell Jan 3, 2024
a246028
Tests for other DAO types
JakeHartnell Jan 4, 2024
d53d2cb
Clean up
JakeHartnell Jan 4, 2024
96de247
Add distribution contracts to schema generation
JakeHartnell Jan 4, 2024
600beab
More code comments
JakeHartnell Jan 4, 2024
5a8b464
Fix bug, clean up response types
JakeHartnell Jan 4, 2024
fe41980
reward_token -> reward_denom
JakeHartnell Jan 4, 2024
2e1ee99
Update README
JakeHartnell Jan 4, 2024
787ddc0
Remove unused dependency
JakeHartnell Jan 8, 2024
9159132
Fix latest clippy errors
JakeHartnell Jan 8, 2024
4613a51
set cw-fund-distributor package version to workspace
bekauz Apr 7, 2024
efa00d8
Set distribution contract versions
Apr 9, 2024
413d4cf
state update for using duration and expiration instead of block heigh…
bekauz Apr 14, 2024
72692b2
storing expiration to denote last distribution update block in consis…
bekauz Apr 21, 2024
aa7ab88
happy case timestamp based rewards distribution test
bekauz Apr 21, 2024
c793996
multiple denom rewards
bekauz Apr 28, 2024
5733167
dao rewards distributor shutdown
bekauz May 12, 2024
c127951
wip: reworking state multiple denom support
bekauz May 19, 2024
30ed098
claiming per token
bekauz May 22, 2024
f5e3495
switch cumulative rewards storage from hashmap to cosmwasm map
bekauz May 22, 2024
2faac3e
moving denom funded amount into reward config
bekauz May 22, 2024
503209d
removing top level vp contract & hook caller no longer optional
bekauz May 22, 2024
dae89fc
wip: rework dneom distribution logic
bekauz May 25, 2024
21bf3d8
wip: init suitebuilder
bekauz May 25, 2024
c8004d9
suite cntd; cleanup contract
bekauz May 25, 2024
34b2e24
moving hook related logic to new file; update reward emission config
bekauz May 26, 2024
dc4cc80
shutdown testing; storing & updating distribution period start date
bekauz May 26, 2024
53c2d03
allow native token funding iff one denom is sent
bekauz May 26, 2024
b48cb57
reward emission config update test
bekauz May 26, 2024
79f7e60
fix cw721 suite setup
bekauz May 27, 2024
e8ef80d
schema regen
bekauz Jun 1, 2024
a07577b
unit tests; clippyfmt; commenting out old test file
bekauz Jun 2, 2024
5d7143a
renamed and commented a bunch of stuff
NoahSaso Jun 6, 2024
0a66ca5
fixed funding date extension typo
NoahSaso Jun 6, 2024
c803acc
make funding permissionless
NoahSaso Jun 6, 2024
f1fe493
allow to specify optional denom rewards withdrawal destination addr
bekauz Jun 15, 2024
c2afb8a
update_rewards and get_accrued_rewards_since_last_user_action handle …
bekauz Jun 15, 2024
38006cc
more tests; extend suite builder
bekauz Jun 15, 2024
c1cb0be
cw4 rewards tests
bekauz Jun 15, 2024
0e28d29
adding withdraw destination, cw20 rewards and more time-based distrib…
bekauz Jun 16, 2024
c662230
little cleanup
bekauz Jun 16, 2024
5f11eda
clippyfmt
bekauz Jun 16, 2024
fd8cc4e
added comment
NoahSaso Jun 16, 2024
b395a04
use previous total power for updating rewards distributed
NoahSaso Jun 16, 2024
5b9ee5d
remove old test file
bekauz Jun 16, 2024
acc5fed
remove emission update; add remaining cw20 time based funding tests
bekauz Jun 16, 2024
42a7977
clippy
bekauz Jun 16, 2024
8ff1834
that specific clippy
bekauz Jun 16, 2024
3f7eb1c
schema
bekauz Jun 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ all-test = "test --workspace"
unit-test = "test --lib"
integration-test = "test --package integration-tests -- --ignored --test-threads 1 -Z unstable-options --report-time"
test-tube = "test --features test-tube"
schema = "run --example schema"

[env]
RUSTFLAGS = "-C link-arg=-s"
32 changes: 31 additions & 1 deletion Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
exclude = ["ci/configs/", "wasmvm/libwasmvm"]
members = [
"contracts/dao-dao-core",
"contracts/distribution/*",
"contracts/external/*",
"contracts/proposal/*",
"contracts/pre-propose/*",
Expand Down Expand Up @@ -82,6 +83,7 @@ cw-ownable = "0.5"

cw-admin-factory = { path = "./contracts/external/cw-admin-factory", version = "2.4.2" }
cw-denom = { path = "./packages/cw-denom", version = "2.4.2" }
cw-fund-distributor = { path = "./contracts/distribution/cw-fund-distributor", version = "2.4.2" }
cw-hooks = { path = "./packages/cw-hooks", version = "2.4.2" }
cw-paginate-storage = { path = "./packages/cw-paginate-storage", version = "2.4.2" }
cw-payroll-factory = { path = "./contracts/external/cw-payroll-factory", version = "2.4.2" }
Expand All @@ -108,6 +110,7 @@ dao-proposal-hook-counter = { path = "./contracts/test/dao-proposal-hook-counter
dao-proposal-multiple = { path = "./contracts/proposal/dao-proposal-multiple", version = "2.4.2" }
dao-proposal-single = { path = "./contracts/proposal/dao-proposal-single", version = "2.4.2" }
dao-proposal-sudo = { path = "./contracts/test/dao-proposal-sudo", version = "2.4.2" }
dao-rewards-distributor = { path = "./contracts/distribution/dao-rewards-distributor", version = "2.4.2" }
dao-test-custom-factory = { path = "./contracts/test/dao-test-custom-factory", version = "2.4.2" }
dao-testing = { path = "./packages/dao-testing", version = "2.4.2" }
dao-voting = { path = "./packages/dao-voting", version = "2.4.2" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "A CosmWasm contract for distributing funds to DAO members based o
edition = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
version = "0.1.0"
version = { workspace = true }

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "cw-fund-distributor",
"contract_version": "0.1.0",
"contract_version": "2.4.2",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
44 changes: 44 additions & 0 deletions contracts/distribution/dao-rewards-distributor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "dao-rewards-distributor"
authors = ["Ben2x4 <[email protected]>", "ekez <[email protected]>", "Jake Hartnell <[email protected]>", "bekauz <[email protected]>"]
description = "Distributes rewards based on DAO membership."
edition = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
version = { workspace = true }

[lib]
crate-type = ["cdylib", "rlib"]

[features]
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
cosmwasm-std = { workspace = true }
cosmwasm-schema = { workspace = true }
cw2 = { workspace = true }
cw4 = { workspace = true }
cw20 = { workspace = true }
cw20-base = { workspace = true, features = ["library"] }
cw-controllers = { workspace = true }
cw-ownable = { workspace = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
dao-hooks = { workspace = true }
dao-interface = { workspace = true }
dao-voting = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
cw-multi-test = { workspace = true }
anyhow = { workspace = true }
cw20-stake = { workspace = true, features = ["library"] }
cw4-group = { workspace = true, features = ["library"] }
cw721-base = { workspace = true, features = ["library"] }
dao-voting-cw20-staked = { workspace = true, features = ["library"] }
dao-voting-cw4 = { workspace = true, features = ["library"] }
dao-voting-token-staked = { workspace = true, features = ["library"] }
dao-voting-cw721-staked = { workspace = true, features = ["library"] }
dao-testing = { workspace = true }
31 changes: 31 additions & 0 deletions contracts/distribution/dao-rewards-distributor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# DAO Rewards Distributor

[![dao-rewards-distributor on crates.io](https://img.shields.io/crates/v/dao-rewards-distributor.svg?logo=rust)](https://crates.io/crates/dao-rewards-distributor)
[![docs.rs](https://img.shields.io/docsrs/dao-rewards-distributor?logo=docsdotrs)](https://docs.rs/dao-rewards-distributor/latest/cw20_stake_external_rewards/)

The `dao-rewards-distributor` works in conjuction with DAO voting modules to provide rewards over time for DAO members. The contract supports both cw20 and native Cosmos SDK tokens. The following voting power modules are supported:
- `dao-voting-cw4`: for membership or group based DAOs
- `dao-voting-cw20-staked`: for cw20 token based DAOs.
- `dao-voting-cw721-staked`: for NFT based DAOs.
- `dao-voting-token-staked`: for native and Token Factory token based DAOs.

NOTE: this contract is NOT AUDITED and is _experimental_. USE AT YOUR OWN RISK.

## Instantiation and Setup

The contract is instantiated with a number of parameters:
- `owner`: The owner of the contract. Is able to fund the contract and update the reward duration.
- `vp_contract`: A DAO DAO voting power module contract address, used to determine membership in the DAO over time.
- `hook_caller`: An optional contract that is allowed to call voting power change hooks. Often, as in `dao-voting-token-staked` and `dao-voting-cw721-staked` the vp_contract calls hooks for power change events, but sometimes they are separate. For example, the `cw4-group` contract is separate from the `dao-voting-cw4` contract and since the `cw4-group` contract fires the membership change events, it's address would be used as the `hook_caller`.
- `reward_denom`: the denomination of the reward token, can be either a cw20 or native token.
- `reward_duration`: the time period over which rewards are to be paid out in blocks.

After instantiating the contract it is VITAL to setup the required hooks for it to work. This is because to pay out rewards accurately, this contract needs to know about staking or voting power changes in the DAO.

This can be achieved using the `add_hook` method on contracts that support voting power changes, which are:
- `cw4-group`
- `dao-voting-cw721-staked`
- `dao-voting-token-staked`
- `cw20-stake`

Finally, the contract needs to be funded with a token matching the denom specified in the `reward_denom` field during instantiation. This can be achieved by calling the `fund` method on the `dao-rewards-distributor` smart contract, and sending along the appropriate funds.
11 changes: 11 additions & 0 deletions contracts/distribution/dao-rewards-distributor/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use cosmwasm_schema::write_api;
use dao_rewards_distributor::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
query: QueryMsg,
execute: ExecuteMsg,
migrate: MigrateMsg,
}
}
Loading
Loading