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

OC + AP payments contract #495

Merged
merged 58 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
87b31fc
Add new tc-payments contract structure
May 9, 2022
1361bbb
tc-payments instantiation
May 9, 2022
b88fa40
Update lock file
May 9, 2022
f840eeb
Add tc-payments to CI
May 9, 2022
3d5d65c
Add payments module
May 9, 2022
4a7bf2b
Add main payments logic as a sudo end block hook
May 9, 2022
cad983f
Add cargo config
May 9, 2022
2c25851
Update lock file
May 9, 2022
2af7956
Update comments
May 9, 2022
2e0fabd
Add schema generator
May 9, 2022
7362fe0
Remove unused messages / comments
May 9, 2022
7c55094
Complete main payments logic
May 10, 2022
4a4c252
Send remaining rewards after payment to engagement contract
May 11, 2022
082f2c9
Only pay oc + ap members if there are enough funds
May 11, 2022
1b6ae82
Fix typo in tc-payments contract CI config
May 12, 2022
e51f388
Add basic initialization multi test
May 13, 2022
ce813ef
Update README
May 13, 2022
8e4bbff
Update lock file
May 13, 2022
e7503cc
Write payments test skeleton
May 17, 2022
6b41232
Don't try to pay without funds
May 17, 2022
0b69d1c
Add happy path payments test
May 17, 2022
7bd6f40
Add extra payments workings tests
May 18, 2022
8373cf5
Simplify / clarify tests
May 18, 2022
7f7707e
Make Payment deserializable
May 18, 2022
10d1bfa
Add already paid check (avoid paying twice) in the same period
May 18, 2022
a444f19
Add after payment time check / test
May 18, 2022
2dd92be
Register empty payments to avoid extra processing in case of failure
May 18, 2022
8a29f80
Improve performance / sequence
May 18, 2022
5ba84e1
Better test checks / encapsulation
May 18, 2022
b692958
Get rid of unnecessary IndexedMap for payments
May 18, 2022
49f7a3a
Use update instead of save for safety
May 18, 2022
3afff57
Fix: ap address copy paste error
May 19, 2022
2c316f1
Generalized oc and ap members for tests
May 19, 2022
acd4541
Fix: avoid division by zero
May 19, 2022
5155060
Add empty oc / ap members tests
May 19, 2022
67f578a
cargo clippy
May 19, 2022
320be06
Add config query
May 19, 2022
d295259
Reorganize payments / fix link
May 19, 2022
f09472d
Add list payments query
May 19, 2022
5a50d05
Fix doc comments
May 31, 2022
4806e38
Generate schemas for execute / query msgs
May 31, 2022
ea36f95
Error on unimplemented ExecuteMsg
May 31, 2022
83eabaa
Add query response schemas
May 31, 2022
c754a04
cargo fmt --all
May 31, 2022
5db2c02
Improve / remove commented code
May 31, 2022
3da0f58
Fix: Yearly period number of seconds
May 31, 2022
1b847cf
Fix: Monthly period (so that we pay in February)
May 31, 2022
51524ba
Remove unneeded cast
May 31, 2022
3553bde
Avoid hitting storage except when needed
May 31, 2022
792d058
Avoid payment time's secular drift
May 31, 2022
0a048a6
Switch to object for Period deserialization
Jun 1, 2022
d9aa15e
Use `if let` instead of `unwrap`
Jun 1, 2022
9dfb5fd
Tentatively increase pagination limit, for performance
Jun 1, 2022
d1eda8e
Use `map` instead of `for` loop
Jun 1, 2022
92c47c1
Improve happy path test assertions
Jun 1, 2022
145523f
Improve payment works test assertions
Jun 1, 2022
91cd098
Improve remaining tests assertions
Jun 1, 2022
0b8913e
Implement sorted comparison for assertions
Jun 1, 2022
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
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,
maurolacy marked this conversation as resolved.
Show resolved Hide resolved
}

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).
maurolacy marked this conversation as resolved.
Show resolved Hide resolved
- 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".
maurolacy marked this conversation as resolved.
Show resolved Hide resolved
- 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