Skip to content

Commit

Permalink
Merge pull request #495 from confio/491-oc-remuneration
Browse files Browse the repository at this point in the history
OC + AP payments contract
  • Loading branch information
maurolacy authored Jun 1, 2022
2 parents 9db75ad + 0b8913e commit 54fee51
Show file tree
Hide file tree
Showing 14 changed files with 1,567 additions and 5 deletions.
28 changes: 28 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ workflows:
- contract_tgrade_trusted_circle
- contract_tgrade_oc_proposals
- contract_tgrade_ap_voting
- contract_tgrade_tc_payments
build:
jobs:
- lint
Expand Down Expand Up @@ -107,6 +108,33 @@ jobs:
- target
key: cargocache-tgrade-ap-voting-rust:1.58.1-{{ checksum "~/project/Cargo.lock" }}

contract_tgrade_tc_payments:
docker:
- image: rust:1.58.1
working_directory: ~/project/contracts/tgrade-tc-payments
steps:
- checkout:
path: ~/project
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-tgrade-tc-payments-rust:1.58.1-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Unit Tests
environment:
RUST_BACKTRACE: 1
command: cargo unit-test --locked
- run:
name: Build and run schema generator
command: cargo schema --locked
- save_cache:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-tgrade-tc-payments-rust:1.58.1-{{ checksum "~/project/Cargo.lock" }}

lint:
docker:
- image: rust:1.58.1
Expand Down
101 changes: 98 additions & 3 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ incremental = false
[profile.release.package.tgrade-ap-voting]
codegen-units = 1
incremental = false

[profile.release.package.tgrade-tc-payments]
codegen-units = 1
incremental = false
4 changes: 2 additions & 2 deletions contracts/tgrade-ap-voting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ based on [CW3](https://github.com/CosmWasm/cosmwasm-plus/tree/master/packages/cw

## Instantiation

The first step to create an validator-voting-proposals contract is to instantiate
The first step to create a validator-voting-proposals contract is to instantiate
a tg4 contract with the desired member set.

We intend to use this contract with a trusted-circle serving as the backing tg4 group.
Expand All @@ -33,7 +33,7 @@ the proposal expiration date, the status is set to "Passed".
Once a proposal is "Passed", anyone may submit an "Execute" message. This will
trigger the proposal to send all stored messages from the proposal and update
it's state to "Executed", so it cannot run again. (Note if the execution fails
for any reason - out of gas, insufficient funds, etc - the state update will
for any reason - out of gas, insufficient funds, etc. - the state update will
be reverted, and it will remain "Passed", so you can try again).

Once a proposal has expired without passing, anyone can submit a "Close"
Expand Down
5 changes: 5 additions & 0 deletions contracts/tgrade-tc-payments/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --example schema"
41 changes: 41 additions & 0 deletions contracts/tgrade-tc-payments/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "tgrade-tc-payments"
version = "0.9.0"
authors = ["Mauro Lacy <[email protected]>"]
edition = "2021"
description = "Oversight Community / Arbiter Pool payments contract"
repository = "https://github.com/confio/tgrade-contracts"
homepage = "https://tgrade.finance"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

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

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
cw2 = "0.13.2"
cw-controllers = "0.13.2"
cw-storage-plus = "0.13.2"
chrono = "0.4.19"
cosmwasm-schema = "1.0.0-beta8"
cosmwasm-std = "1.0.0-beta8"
schemars = "0.8"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = "1.0.21"
tg-bindings = "0.9.0"
tg4 = "0.9.0"

[dev-dependencies]
cw-multi-test = "0.13.2"
tg4-engagement = "0.9.0"
tg-voting-contract = "0.9.0"
tg-bindings-test = "0.9.0"
tg-utils = "0.9.0"
tgrade-trusted-circle = { version = "0.9.0", path = "../tgrade-trusted-circle" }
tgrade-ap-voting = { version = "0.9.0", path = "../tgrade-ap-voting" }
41 changes: 41 additions & 0 deletions contracts/tgrade-tc-payments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# TGrade Trusted Circle Payments

This contract makes regular payments to the Oversight Community and Arbiter Pool members.

## Init

To create it, you must pass the Trusted Circle and the Arbiter pool contract addresses.
As well as an optional `admin`, if you wish it to be mutable.

```rust
pub struct InstantiateMsg {
/// Admin (if set) can change the payment amount and period
pub admin: Option<String>,
/// Trusted Circle / OC contract address
pub oc_addr: String,
/// Arbiter pool contract address
pub ap_addr: String,
/// The required payment amount, in the payments denom
pub denom: String,
/// The required payment amount, in the TC denom
pub payment_amount: u128,
/// Payment period
pub payment_period: Period,
}

pub enum Period {
Daily,
Monthly,
Yearly
}
```

## Messages

#### Notes
- This contract is to be funded from block rewards, i.e. its address and distribution percentage must be in the `distribution_contracts` tgrade_valset list.
- If there are not enough funds to make a `payment_amount` to all OC + AP members, the existing funds are distributed to the engagement point holders.
- Funds are distributed directly to members through `Bank::Send`. This assumes the total number of members is small (less than thirty).
- If both OC and AP addresses are of the same contract, they are treated as different addresses, i.e. each member will be paid "twice".
- The contract would need an `EndBlocker` privilege, to check the payment time, and execute it if appropriate.
Alternatively, a cron contract could call the payment entry point with a frequency greater or equal than that of `payment_period`.
21 changes: 21 additions & 0 deletions contracts/tgrade-tc-payments/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, export_schema_with_title, remove_schemas, schema_for};

use tgrade_tc_payments::msg::PaymentListResponse;
pub use tgrade_tc_payments::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use tgrade_tc_payments::state::PaymentsConfig;

fn main() {
let mut out_dir = current_dir().unwrap();
out_dir.push("schema");
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

export_schema_with_title(&schema_for!(InstantiateMsg), &out_dir, "InstantiateMsg");
export_schema_with_title(&schema_for!(ExecuteMsg), &out_dir, "ExecuteMsg");
export_schema_with_title(&schema_for!(QueryMsg), &out_dir, "QueryMsg");
export_schema(&schema_for!(PaymentsConfig), &out_dir);
export_schema(&schema_for!(PaymentListResponse), &out_dir);
}
Loading

0 comments on commit 54fee51

Please sign in to comment.