Skip to content

Commit

Permalink
fix(broker-staking): compilation issues and run tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine committed Mar 22, 2024
1 parent 4b87403 commit fca8548
Show file tree
Hide file tree
Showing 29 changed files with 112 additions and 305 deletions.
38 changes: 19 additions & 19 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cosmwasm-std = { version = "1.5.0", features = ["stargate", "staking"] }
cosmwasm-schema = "1.5.0"
cw-storage-plus = { version = "1.2.0" }
cw-multi-test = { version = "0.20.0" }
cw-utils = { version = "1.0.2" }
cw-utils = { version = "1.0.3" }
# Macros for controlling ownership of CosmWasm smart contracts
cw-ownable = { version = "0.5.1"}

Expand All @@ -42,6 +42,7 @@ shifter = { path = "contracts/core-shifter" }
controller = { path = "contracts/core-controller" }
lockup = { path = "contracts/lockup", features = ["library"] }
incentives = { path = "contracts/incentives", features = ["library"] }
broker-bank = { path = "contracts/broker-bank", features = ["library"] }

# deps: else
anyhow = "1"
Expand Down
Binary file added artifacts/broker_bank.wasm
Binary file not shown.
Binary file added artifacts/broker_staking.wasm
Binary file not shown.
6 changes: 4 additions & 2 deletions artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
3878c8fec84001d1260da6d8b7ea91af5bc3d3433d8cab293ae24de94a9fdda0 broker_bank.wasm
dfd48116b2181f477d42b7d0d697057e16814c0b703ef592a8757ca681c6e5ad broker_staking.wasm
382c05baf544f2886de849933ecf59e8bc3bcdcdd552d5a63537bd6d63f2ecf1 controller.wasm
05948cad982935aa30a9c2011649ab40a38172ab50df5781a3e24f72b76dcc56 core_compounder.wasm
6cf70cdf7ca010cbeff5fff2ca992ccb6d48fa669baf2b9ee26c8289a926413c core_token_vesting_v2.wasm
ed4a89ae4669b22863fcabd18e3bd7e40d039899f863a07eb0449eed059a898e core_token_vesting_v2.wasm
b56a880d4c67d9f353f549b502256f73159f89b50aa6dae683948e117efa4792 cw3_flex_multisig.wasm
1ecff403bbf3b5fcedccb5de76a0ef5f1fdbcc5f60890e3388f5425584899f0b incentives.wasm
dc89ed88f1c69bf63fc284492b7bf6935e3a85da2945067d70f71f08c01df60d lockup.wasm
222eac4e17c7ddffbecde0b196bc06ed1e458b8578ab25ed200a6fd7db4e5eda nibi_stargate.wasm
ef5b4de76526713e3531c3b9bbc4620b5d61599c4a0e8605365ebb0f1d7ee2ac nibi_stargate_perp.wasm
0074489ff40c8ecbd766f7140b32d288dcaf7302ba630d452f79e7d292ea57ef nusd_valuator.wasm
955592d08017aa41f3c9ba3883153d6de024e8c7a3a79aa3b664a241ec1e7a19 pricefeed.wasm
354fdeff1386394d7aa829358323f89bde548d4aa782bae4a16dddfe33dad739 shifter.wasm
89e3236c932a73575bf39da532bcb93f8e4a5f4a3a7f3836e43f8970993eb809 shifter.wasm
8d982ca2d679ea8d44f825fe91a3d4e0cb92150b12e4684497eee9e76991d247 token_vesting.wasm
Binary file removed artifacts/core_compounder.wasm
Binary file not shown.
Binary file modified artifacts/core_token_vesting_v2.wasm
Binary file not shown.
Binary file modified artifacts/shifter.wasm
Binary file not shown.
18 changes: 16 additions & 2 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
## Core Contracts

- [**core-token-vesting**](./core-token-vesting/README.md)
- [**core-token-vesting-v2**](./core-token-vesting-v2/README.md)
- [**core-shifter**](./core-shifter/README.md): Simple contract to execute peg shift
and depth shift admin calls in x/perp module. This contract is meant to be used
to run a bot.
Expand All @@ -17,6 +18,21 @@
- [**core-compounder**](./core-compounder): Simple contract to allow third parties
to stake funds without being able to withdraw/unstake them.

## Broker Contracts

Account abstraction smart contracts where the smart contract acts as or enables a
broker to act on the contract owner's behalf with some gated functionality.

- [**broker-bank**](./broker-bank/README.md): Account abstration to enable funds
to be held and sent to a whitelisted set of accounts (`TO_ADDRS`). Bank
transfers can only be called by "operators", and the funds can only be
withdrawn by the contract owner.
- [**broker-staking**](./broker-staking/README.md): Account abstraction to enable
certain staking transaction messages to be called by a subset of "operators".
Although operators can stake the funds, only the contract owner can withdraw or
unstake them.


## Example Contracts

- [**nibi-stargate**](./nibi-stargate/README.md): Example smart contract that showcases how to use the Nibiru standard (nibiru-std) library to execute `CosmosMsg::Stargate` transactions for the token factory module.
Expand All @@ -29,5 +45,3 @@

- [**pricefeed**](./pricefeed): Legacy implementation of the Nibiru Oracle Module in pure
CosmWasm rather than the Cosmos-SDK.

- [**core-token-vesting-v2**](./core-token-vesting-v2/README.md)
6 changes: 4 additions & 2 deletions contracts/broker-bank/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ crate-type = ["cdylib", "rlib"]

[features]
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
# library = []
# features.library: Use the library feature to disable all
# instantiate/execute/query exports. This is necessary use this as a dependency
# for another smart contract crate.
library = []

[dependencies]
cosmwasm-std = { workspace = true }
Expand Down
5 changes: 5 additions & 0 deletions contracts/broker-bank/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# contracts/broker-bank

Account abstration to enable funds to be held and sent to a whitelisted set of
accounts (`TO_ADDRS`). Bank transfers can only be called by "operators", and the
funds can only be withdrawn by the contract owner.
2 changes: 1 addition & 1 deletion contracts/broker-bank/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,4 +798,4 @@ pub mod tests {

Ok(())
}
}
}
2 changes: 1 addition & 1 deletion contracts/broker-bank/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod msgs;
pub mod oper_perms;
pub mod tutil;

#[cfg(not(feature = "library"))]
// #[cfg(not(feature = "library"))]
// When imported with the "library" feature, contract.rs will not be compiled.
// This prevents errors related to entry the smart contract's entrypoints,
// enabling its use as a library.
Expand Down
14 changes: 7 additions & 7 deletions contracts/broker-bank/src/tutil.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! testing.rs: Test helpers for the contract
#![cfg(not(target_arch = "wasm32"))]

use cosmwasm_std::{
testing::{
mock_dependencies, mock_env, mock_info, MockApi, MockQuerier,
MockStorage,
},
Env, MessageInfo, OwnedDeps,
use cosmwasm_std::{Env, MessageInfo, OwnedDeps};

#[cfg(not(target_arch = "wasm32"))]
use cosmwasm_std::testing::{
mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage,
};

use crate::{contract::instantiate, msgs::InstantiateMsg};
Expand Down Expand Up @@ -59,4 +59,4 @@ pub fn mock_env_height(height: u64) -> Env {
let mut env = mock_env();
env.block.height = height;
env
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "core-compounder"
name = "broker-staking"
version = "0.2.0"
edition = "2021"
description = "Compounder contract to stake"
description = "Broker smart contract to stake on another account's behalf"

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.
Expand All @@ -21,18 +21,18 @@ crate-type = ["cdylib", "rlib"]
backtraces = ["cosmwasm-std/backtraces"]

[dependencies]
cosmwasm-schema = "1.4.0"
cosmwasm-schema = { workspace = true }
cw-ownable = { workspace = true }
nibiru-std = { workspace = true }
cosmwasm-std = { version = "1.5.0", features = ["staking"] }
cw20 = "1.1.1"
cw-utils = { version = "1.0.2" }
thiserror = { version = "1.0.49" }
cw-storage-plus = "1.1.0"
schemars = "0.8.15"
serde = { version = "1.0.188", default-features = false, features = ["derive"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
broker-bank = { version = "0.1.0", path = "../broker-bank" }
cosmwasm-std = { workspace = true }
cw20.workspace = true
cw-utils = { workspace = true }
thiserror = { workspace = true }
cw-storage-plus = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
broker-bank = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
anyhow = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
## Compounder
## contracts/broker-staking

This contract handles permissions so we can compound safely the funds of the
multisig.
This smart contract handles account abstraction to enable certain staking transaction messages
to be called by a subset of "operators", while the funds can only be withdrawn by the contract owner.

This is useful if you want a mutlisig to manage a large allocation of funds while
permitting certain bots to safely make calls to stake or unstake, as is the case
for Nibiru's Foundation Delegation Program.

Table of Contents:
- [Overview](#overview)
- [Master Operations](#master-operations)
- [Instantiate](#instantiate)
- [Execute](#execute)
- [Admin functions](#admin-functions)
- [Manager functions](#manager-functions)
- [Query](#query)
- [Deployed Contract Info](#deployed-contract-info)
- [Testing Against a Live Chain](#testing-against-a-live-chain)

## Overview

The contract has 2 modes, defined by the autocompounder_on flag. When it is
true, managers can call the contract to stake the balance of the contract.
Expand Down Expand Up @@ -137,4 +154,4 @@ TODO for mainnet/testnet
| rpc_url | ... |
| chain_id | ... |

### Testing Against a Live Chain
### Testing Against a Live Chain
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env::current_dir;
use std::fs::create_dir_all;

use broker_bank::msgs::{InstantiateMsg, QueryMsg};
use core_compounder::msg::ExecuteMsg;
use broker_staking::msg::ExecuteMsg;
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};

fn main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn build_stake_message(
validator: String,
) -> StdResult<CosmosMsg> {
Ok(CosmosMsg::Staking(StakingMsg::Delegate {
validator: validator,
validator,
amount: Coin {
denom: "unibi".to_string(),
amount,
Expand All @@ -149,7 +149,7 @@ fn build_unstakes_messages(
validator: String,
) -> StdResult<CosmosMsg> {
Ok(CosmosMsg::Staking(StakingMsg::Undelegate {
validator: validator,
validator,
amount: Coin {
denom: "unibi".to_string(),
amount,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,7 @@ fn exec_stake() -> TestResult {
resp_msgs: vec![CosmosMsg::Staking(StakingMsg::Delegate {
validator: String::from("mm_bybit"),
amount: coin(50, "unibi"),
})
.into()],
})],
},
// Success : valid operation to multiple stakers
TestCaseExec {
Expand Down Expand Up @@ -506,8 +505,7 @@ fn exec_stake() -> TestResult {
CosmosMsg::Staking(StakingMsg::Delegate {
validator: String::from("mm_kucoin"),
amount: coin(25, "unibi"),
})
.into(),
}),
],
},
// Success : valid operation to multiple stakers - different shares
Expand Down Expand Up @@ -538,8 +536,7 @@ fn exec_stake() -> TestResult {
CosmosMsg::Staking(StakingMsg::Delegate {
validator: String::from("mm_kucoin"),
amount: coin(30, "unibi"),
})
.into(),
}),
],
},
// Fail - invalid sender
Expand All @@ -561,8 +558,7 @@ fn exec_stake() -> TestResult {
resp_msgs: vec![CosmosMsg::Staking(StakingMsg::Delegate {
validator: String::from("mm_bybit"),
amount: coin(50, "unibi"),
})
.into()],
})],
},
// Fail - empty stake messages
TestCaseExec {
Expand All @@ -578,8 +574,7 @@ fn exec_stake() -> TestResult {
resp_msgs: vec![CosmosMsg::Staking(StakingMsg::Delegate {
validator: String::from("mm_bybit"),
amount: coin(50, "unibi"),
})
.into()],
})],
},
];
for tc in &test_cases {
Expand Down Expand Up @@ -644,8 +639,7 @@ fn exec_unstake() -> TestResult {
resp_msgs: vec![CosmosMsg::Staking(StakingMsg::Undelegate {
validator: String::from("mm_bybit"),
amount: coin(100, "unibi"),
})
.into()],
})],
},
// Success - multiple
TestCaseExec {
Expand Down Expand Up @@ -674,13 +668,11 @@ fn exec_unstake() -> TestResult {
CosmosMsg::Staking(StakingMsg::Undelegate {
validator: String::from("mm_bybit"),
amount: coin(100, "unibi"),
})
.into(),
}),
CosmosMsg::Staking(StakingMsg::Undelegate {
validator: String::from("mm_kucoin"),
amount: coin(20, "unibi"),
})
.into(),
}),
],
},
// Fail - oper can't do that
Expand All @@ -699,8 +691,7 @@ fn exec_unstake() -> TestResult {
resp_msgs: vec![CosmosMsg::Staking(StakingMsg::Undelegate {
validator: String::from("mm_bybit"),
amount: coin(100, "unibi"),
})
.into()],
})],
},
// Fail - non oper also can't
TestCaseExec {
Expand All @@ -718,8 +709,7 @@ fn exec_unstake() -> TestResult {
resp_msgs: vec![CosmosMsg::Staking(StakingMsg::Undelegate {
validator: String::from("mm_bybit"),
amount: coin(100, "unibi"),
})
.into()],
})],
},
];
for tc in &test_cases {
Expand Down
Loading

0 comments on commit fca8548

Please sign in to comment.