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

Added feature flags #197

Merged
merged 8 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[workspace]
members = [
# Packages
"packages/network_integration",
"packages/shade_protocol",
"packages/secretcli",

Expand All @@ -27,6 +26,9 @@ members = [
# Tools
"tools/doc2book"
]
exclude = [
"packages/network_integration",
]

[profile.release]
opt-level = 3
Expand Down
2 changes: 1 addition & 1 deletion contracts/airdrop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol", features = ["airdrop", "math"] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
Expand Down
2 changes: 1 addition & 1 deletion contracts/governance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol", features = ["governance"] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
Expand Down
2 changes: 1 addition & 1 deletion contracts/initializer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol", features = ["initializer"] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
2 changes: 1 addition & 1 deletion contracts/mint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol", features = ["mint"] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
Expand Down
2 changes: 1 addition & 1 deletion contracts/mint_router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol", features = ["mint_router"] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
Expand Down
2 changes: 1 addition & 1 deletion contracts/mock_band/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol", features = ["band"] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
Expand Down
2 changes: 1 addition & 1 deletion contracts/mock_secretswap_pair/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol", features = ["dex", "secretswap"] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
2 changes: 1 addition & 1 deletion contracts/mock_sienna_pair/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol", features = ["dex", "sienna"] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
2 changes: 1 addition & 1 deletion contracts/oracle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol", features = ["oracle", "dex"] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
Expand Down
2 changes: 1 addition & 1 deletion contracts/scrt_staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std", features = [
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol", features = ["scrt_staking"] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
2 changes: 1 addition & 1 deletion contracts/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol", features = ["staking"] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
Expand Down
2 changes: 1 addition & 1 deletion contracts/treasury/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol", features = ["treasury", "snip20"] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
Expand Down
2 changes: 1 addition & 1 deletion packages/network_integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ default = []
[dependencies]
colored = "2.0.0"
chrono = "0.4.19"
shade-protocol = { version = "0.1.0", path = "../shade_protocol" }
shade-protocol = { version = "0.1.0", path = "../shade_protocol", features = ["dex", "airdrop", "initializer", "governance", "mint", "mint_router", "oracle", "scrt_staking", "staking", "treasury"] }
secretcli = { version = "0.1.0", path = "../secretcli" }
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.67"}
Expand Down
27 changes: 26 additions & 1 deletion packages/shade_protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,32 @@ edition = "2018"
crate-type = ["cdylib", "rlib"]

[features]
default = []
default = ["utils"]
# Templates
dex = ["utils", "math", "snip20", "mint", "secretswap", "sienna", "band"]
band = []
secretswap = ["utils"]
sienna = ["utils", "math"]
snip20 = ["utils"]

# Utils
utils = []
errors = []
flexible_msg = []
math = []
storage = []

# Protocol contracts
airdrop = ["utils", "errors"]
initializer = ["snip20", "utils"]
governance = ["utils"]
mint = ["utils", "snip20"]
mint_router = ["utils", "snip20"]
oracle = ["snip20"]
scrt_staking= ["utils"]
staking = ["governance", "utils"]
treasury = ["utils"]

# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
Expand Down
26 changes: 26 additions & 0 deletions packages/shade_protocol/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
#[cfg(feature = "band")]
pub mod band;

#[cfg(feature = "secretswap")]
pub mod secretswap;

#[cfg(feature = "sienna")]
pub mod sienna;

#[cfg(feature = "dex")]
pub mod dex;

#[cfg(feature = "snip20")]
pub mod snip20;

pub mod utils;

// Protocol init libraries
#[cfg(feature = "airdrop")]
pub mod airdrop;

#[cfg(feature = "initializer")]
pub mod initializer;

// Protocol libraries
#[cfg(feature = "governance")]
pub mod governance;

#[cfg(feature = "mint")]
pub mod mint;

#[cfg(feature = "mint_router")]
pub mod mint_router;

#[cfg(feature = "oracle")]
pub mod oracle;

#[cfg(feature = "scrt_staking")]
pub mod scrt_staking;

#[cfg(feature = "staking")]
pub mod staking;

#[cfg(feature = "treasury")]
pub mod treasury;
14 changes: 14 additions & 0 deletions packages/shade_protocol/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
// Helper libraries

#[cfg(feature = "utils")]
pub mod asset;

#[cfg(feature = "errors")]
pub mod errors;

#[cfg(feature = "flexible_msg")]
pub mod flexible_msg;

#[cfg(feature = "utils")]
pub mod generic_response;

#[cfg(feature = "math")]
pub mod math;

#[cfg(feature = "storage")]
pub mod storage;

#[cfg(feature = "math")]
pub mod price;
6 changes: 4 additions & 2 deletions packages/shade_protocol/src/utils/price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ pub fn normalize_price(amount: Uint128, decimals: u8) -> Uint128 {

#[cfg(test)]
mod tests {
use cosmwasm_std::Uint128;
use crate::utils::price::{translate_price, normalize_price};
FloppyDisck marked this conversation as resolved.
Show resolved Hide resolved
macro_rules! normalize_price_tests {
($($name:ident: $value:expr,)*) => {
$(
#[test]
fn $name() {
let (amount, decimals, expected) = $value;
assert_eq!(oracle::normalize_price(amount, decimals), expected)
assert_eq!(normalize_price(amount, decimals), expected)
}
)*
}
Expand Down Expand Up @@ -63,7 +65,7 @@ mod tests {
#[test]
fn $name() {
let (scrt_price, trade_price, expected) = $value;
assert_eq!(query::translate_price(scrt_price, trade_price), expected)
assert_eq!(translate_price(scrt_price, trade_price), expected)
}
)*
}
Expand Down