Skip to content

Commit

Permalink
staking rewards distribution followup (#835)
Browse files Browse the repository at this point in the history
Co-authored-by: Noah Saso <[email protected]>
Co-authored-by: Jake Hartnell <[email protected]>
  • Loading branch information
3 people authored Jun 17, 2024
1 parent bb8224e commit 8be18d1
Show file tree
Hide file tree
Showing 33 changed files with 4,782 additions and 17 deletions.
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

0 comments on commit 8be18d1

Please sign in to comment.