Skip to content

Commit

Permalink
Merge pull request #105 from confio/tg4-group
Browse files Browse the repository at this point in the history
Add `tg4-group` contract
  • Loading branch information
maurolacy committed Feb 16, 2022
2 parents e2258fb + 397af92 commit 98e96c0
Show file tree
Hide file tree
Showing 14 changed files with 925 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ workflows:
test:
jobs:
- contract_tg4_engagement
- contract_tg4_group
- contract_tg4_mixer
- contract_tg4_stake
- contract_tgrade_community_pool
Expand Down Expand Up @@ -65,6 +66,33 @@ jobs:
- target
key: cargocache-tg4-engagement-rust:1.58.1-{{ checksum "~/project/Cargo.lock" }}

contract_tg4_group:
docker:
- image: rust:1.58.1
working_directory: ~/project/contracts/tg4-group
steps:
- checkout:
path: ~/project
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-tg4-group-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-tg4-group-rust:1.58.1-{{ checksum "~/project/Cargo.lock" }}

contract_tg4_mixer:
docker:
- image: rust:1.58.1
Expand Down
18 changes: 18 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions contracts/tg4-group/.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"
42 changes: 42 additions & 0 deletions contracts/tg4-group/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "tg4-group"
version = "0.6.0"
authors = ["Mauro Lacy <mauro@confio.gmbh>"]
edition = "2018"
description = "Simple tg4 implementation of group membership controlled by admin"
license = "Apache-2.0"
repository = "https://github.com/confio/poe-contracts"
homepage = "https://cosmwasm.com"
documentation = "https://docs.cosmwasm.com"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"artifacts/*",
]

# 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]
cw-utils = "0.11.1"
cw2 = "0.11.1"
tg-bindings = { version = "0.6.0", path = "../../packages/bindings" }
tg-utils = { version = "0.6.0", path = "../../packages/utils" }
tg4 = { version = "0.6.0", path = "../../packages/tg4" }
cw-controllers = "0.11.1"
cw-storage-plus = "0.11.1"
cosmwasm-std = { version = "1.0.0-beta5" }
schemars = "0.8.1"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.23" }

[dev-dependencies]
cosmwasm-schema = { version = "1.0.0-beta5" }
14 changes: 14 additions & 0 deletions contracts/tg4-group/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Tg4_group
Copyright (C) 2022 Confio Gmbh

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
51 changes: 51 additions & 0 deletions contracts/tg4-group/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# TG4 Group

This is a basic implementation of the [tg4 spec](../../packages/tg4/README.md).
It fulfills all elements of the spec, including the raw query lookups,
and it designed to be used as a backing storage for
[cw3 compliant contracts](../../packages/cw3/README.md).

It stores a set of members along with an admin, and allows the admin to
update the state. Raw queries (intended for cross-contract queries)
can check a given member address and the total points. Smart queries (designed
for client API) can do the same, and also query the admin address as well as
paginate over all members.

## Init

To create it, you must pass in a list of members, as well as an optional
`admin`, if you wish it to be mutable.

```rust
pub struct InitMsg {
pub admin: Option<HumanAddr>,
pub members: Vec<Member>,
}

pub struct Member {
pub addr: HumanAddr,
pub points: u64,
}
```

Members are defined by an address and a number of points. This is transformed
and stored under their `CanonicalAddr`, in a format defined in
[tg4 raw queries](../../packages/tg4/README.md#raw).

Note that 0 *is an allowed number of points*. This doesn't give any voting rights, but
it does define this address is part of the group. This could be used in
e.g. a KYC whitelist to say they are allowed, but cannot participate in
decision-making.

## Messages

Basic update messages, queries, and hooks are defined by the
[tg4 spec](../../packages/tg4/README.md). Please refer to it for more info.

`tg4-group` adds one message to control the group membership:

`UpdateMembers{add, remove}` - takes a membership diff and adds/updates the
members, as well as removing any provided addresses. If an address is on both
lists, it will be removed. If it appears multiple times in `add`, only the
last occurrence will be used.

22 changes: 22 additions & 0 deletions contracts/tg4-group/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::env::current_dir;
use std::fs::create_dir_all;

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

pub use tg4::{AdminResponse, MemberListResponse, MemberResponse, TotalPointsResponse};
pub use tg4_group::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};

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!(AdminResponse), &out_dir);
export_schema(&schema_for!(MemberListResponse), &out_dir);
export_schema(&schema_for!(MemberResponse), &out_dir);
export_schema(&schema_for!(TotalPointsResponse), &out_dir);
}
Loading

0 comments on commit 98e96c0

Please sign in to comment.