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

chore: publish nibiru-ownable, resolve linter errors, and add GH automation #151

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .github/issue-labeler-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Adds the "S-triage" label ot any issue that gets opened.
S-triage:
- '/.*/'
38 changes: 38 additions & 0 deletions .github/workflows/gh-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Auto-add GH issues to project"
# Add all issues opened to the issue board for triage and assignment
# GitHub Org and Project Automation
# https://www.notion.so/nibiru/GitHub-Org-and-Project-Automation-c771d671109849ee9fda7c8b741cd66a?pvs=4

on:
issues:
types: ["opened", "labeled"]

permissions:
issues: write
contents: read

jobs:
# https://github.com/actions/add-to-project
add-to-project:
name: "Add GH ticket to project"
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
project-url: https://github.com/orgs/NibiruChain/projects/8
github-token: ${{ secrets.NIBIRU_PM }}

label-triage:
name: "Add GH ticket to project"
runs-on: ubuntu-latest
# The action comes from the "Activty types" for the "issues" webhook event
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#issues
if: "github.event.action == 'opened'"
steps:
- uses: github/[email protected]
if: join(github.event.issue.labels) == ''
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
configuration-path: ".github/issue-labeler-config.yml"
enable-versioned-regex: 0
not-before: "2024-05-01T00:00:00Z"
48 changes: 30 additions & 18 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ prost-types = "0.12.3"
bash-rs = { path = "packages/bash-rs" }
# Macros for controlling ownership of CosmWasm smart contracts
nibiru-ownable = { path = "packages/nibiru-ownable" }
ownable-derive = { path = "packages/nibiru-ownable/derive" }
nibiru-ownable-derive = { version = "0.1.0" }
# nibiru-ownable-derive = { path = "packages/nibiru-ownable-derive" }
cw-address-like = { path = "packages/cw-address-like" }
easy-addr = { path = "packages/easy-addr" }

Expand All @@ -39,7 +40,7 @@ cw-utils = { version = "2.0.0" }
# deps: cw-plus
cw2 = { version = "2.0.0" }
cw3 = { version = "2.0.0" }
cw3-fixed-multisig = { version = "2.0.0", features = ["library"] }
cw3-fixed-multisig = { path = "contracts/core-cw3-fixed-msig", version = "2.0.0", features = ["library"] }
cw4 = { version = "2.0.0" }
cw20 = { version = "2.0.0" }
cw4-group = { version = "2.0" }
Expand Down
2 changes: 1 addition & 1 deletion contracts/broker-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn claim_rewards(

// query current delegations
let delegations =
deps.querier.query_all_delegations(&env.contract.address)?;
deps.querier.query_all_delegations(env.contract.address)?;

let mut messages: Vec<CosmosMsg> = vec![];
for delegation in delegations.iter() {
Expand Down
4 changes: 2 additions & 2 deletions contracts/broker-staking/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::contract::{execute, query};
use crate::msg::{ExecuteMsg, StakeMsg, UnstakeMsg};
use cosmwasm_std::{self as cw_std};
use cw_std::{
coin, from_json, testing, BankMsg, Coin, CosmosMsg, DistributionMsg,
Response, StakingMsg, Uint128,
coin, from_json, testing, BankMsg, Coin, CosmosMsg, Response, StakingMsg,
Uint128,
};
use nibiru_std::errors::TestResult;
use serde::Serialize;
Expand Down
6 changes: 6 additions & 0 deletions contracts/core-cw3-fixed-msig/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[alias]
wasm = "build --release --lib --target wasm32-unknown-unknown"
wasm-debug = "build --lib --target wasm32-unknown-unknown"
unit-test = "test --lib"
integration-test = "test --test integration"
schema = "run --bin schema"
34 changes: 34 additions & 0 deletions contracts/core-cw3-fixed-msig/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "cw3-fixed-multisig"
version = "2.0.1" # Should match contracts/core-cw3-flex-msig
authors = ["Ethan Frey <[email protected]>"]
edition = "2021"
description = "Implementing cw3 with an fixed group multisig"
license = "Apache-2.0"
repository = "https://github.com/NibiruChain/cw-nibiru"
homepage = "https://cosmwasm.com"
documentation = "https://docs.cosmwasm.com"

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

[features]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
cosmwasm-schema = { workspace = true }
cw-utils = { workspace = true }
cw2 = { workspace = true }
cw3 = { workspace = true }
cw-storage-plus = { workspace = true }
cosmwasm-std = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
cw20 = { workspace = true }
cw20-base = { workspace = true }
cw-multi-test = { workspace = true }
easy-addr = { workspace = true }
65 changes: 65 additions & 0 deletions contracts/core-cw3-fixed-msig/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# CW3 Fixed Multisig

This is a simple implementation of the [cw3 spec](../../packages/cw3/README.md).
It is a multisig with a fixed set of addresses created upon instatiation.
Each address may have the same weight (K of N), or some may have extra voting
power. This works much like the native Cosmos SDK multisig, except that rather
than aggregating the signatures off chain and submitting the final result,
we aggregate the approvals on-chain.

This is usable as is, and probably the most secure implementation of cw3
(as it is the simplest), but we will be adding more complex cases, such
as updating the multisig set, different voting rules for the same group
with different permissions, and even allow token-weighted voting. All through
the same client interface.

## Instantiation

To create the multisig, you must pass in a set of `HumanAddr` with a weight
for each one, as well as a required weight to pass a proposal. To create
a 2 of 3 multisig, pass 3 voters with weight 1 and a `required_weight` of 2.

Note that 0 *is an allowed weight*. This doesn't give any voting rights, but
it does allow that key to submit proposals that can later be approved by the
voters. Any address not in the voter set cannot submit a proposal.

## Execution Process

First, a registered voter must submit a proposal. This also includes the
first "Yes" vote on the proposal by the proposer. The proposer can set
an expiration time for the voting process, or it defaults to the limit
provided when creating the contract (so proposals can be closed after several
days).

Before the proposal has expired, any voter with non-zero weight can add their
vote. Only "Yes" votes are tallied. If enough "Yes" votes were submitted before
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
be reverted, and it will remain "Passed", so you can try again).

Once a proposal has expired without passing, anyone can submit a "Close"
message to mark it closed. This has no effect beyond cleaning up the UI/database.

## Running this contract

You will need Rust 1.44.1+ with `wasm32-unknown-unknown` target installed.

You can run unit tests on this via:

`cargo test`

Once you are happy with the content, you can compile it to wasm via:

```
RUSTFLAGS='-C link-arg=-s' cargo wasm
cp ../../target/wasm32-unknown-unknown/release/cw3_fixed_multisig.wasm .
ls -l cw3_fixed_multisig.wasm
sha256sum cw3_fixed_multisig.wasm
```

Or for a production-ready (optimized) build, run a build command in the
repository root: https://github.com/CosmWasm/cw-plus#compiling.
11 changes: 11 additions & 0 deletions contracts/core-cw3-fixed-msig/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use cosmwasm_schema::write_api;

use cw3_fixed_multisig::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};

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

Check warning on line 11 in contracts/core-cw3-fixed-msig/src/bin/schema.rs

View check run for this annotation

Codecov / codecov/patch

contracts/core-cw3-fixed-msig/src/bin/schema.rs#L5-L11

Added lines #L5 - L11 were not covered by tests
Loading
Loading