From 9b00f0d8ccec0474f28591d89697b2ce38a10169 Mon Sep 17 00:00:00 2001 From: Jakub Bogucki Date: Tue, 21 Mar 2023 14:10:51 +0100 Subject: [PATCH] Set version v1.2.0 --- Cargo.lock | 75 +++++++++------ Cargo.toml | 4 +- contracts/gauge-adapter/Cargo.toml | 2 + contracts/gauge-adapter/src/contract.rs | 94 ++++++++++++++++++- contracts/gauge-adapter/src/error.rs | 3 + contracts/gauge-adapter/src/msg.rs | 4 + .../gauge-adapter/src/multitest/options.rs | 38 +++++++- .../gauge-adapter/src/multitest/sample.rs | 54 +++++------ .../gauge-adapter/src/multitest/suite.rs | 56 ++++++----- contracts/gauge-adapter/src/state.rs | 4 +- contracts/lsd-hub/src/contract.rs | 16 ++-- contracts/lsd-hub/src/msg.rs | 2 +- contracts/lsd-hub/src/multitest/suite.rs | 2 +- .../deploy_and_instantiate_contracts.ts | 4 +- node_ci_test/spec/main.spec.ts | 4 +- node_ci_test/src/constants.ts | 2 +- 16 files changed, 258 insertions(+), 106 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a162d2f..8c7ca63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,9 +15,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.69" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" +checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" [[package]] name = "base16ct" @@ -48,9 +48,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ "generic-array", ] @@ -98,7 +98,7 @@ version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1895f6d7a191bb044e3c555190d1da555c2571a3af41f849f60c855580e392f" dependencies = [ - "syn", + "syn 1.0.109", ] [[package]] @@ -122,7 +122,7 @@ checksum = "a92ceea61033cb69c336abf673da017ddf251fc4e26e0cdd387eaf8bedb14e49" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -329,7 +329,7 @@ checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -347,7 +347,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ - "block-buffer 0.10.3", + "block-buffer 0.10.4", "crypto-common", "subtle", ] @@ -429,7 +429,7 @@ checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" [[package]] name = "gauge-adapter" -version = "1.1.0" +version = "1.2.0" dependencies = [ "anyhow", "cosmwasm-schema", @@ -437,9 +437,11 @@ dependencies = [ "cw-multi-test", "cw-placeholder", "cw-storage-plus", + "cw-utils", "cw2", "cw20", "cw20-base", + "semver", "thiserror", "wynd-lsd-hub", ] @@ -529,9 +531,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.139" +version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] name = "once_cell" @@ -557,9 +559,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" dependencies = [ "unicode-ident", ] @@ -584,14 +586,14 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -649,7 +651,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn", + "syn 1.0.109", ] [[package]] @@ -668,15 +670,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" [[package]] name = "serde" -version = "1.0.153" +version = "1.0.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a382c72b4ba118526e187430bb4963cd6d55051ebf13d9b25574d379cc98d20" +checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9" dependencies = [ "serde_derive", ] @@ -692,13 +694,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.153" +version = "1.0.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ef476a5790f0f6decbc66726b6e5d63680ed518283e64c7df415989d880954f" +checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.4", ] [[package]] @@ -709,7 +711,7 @@ checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -790,24 +792,35 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c622ae390c9302e214c31013517c2061ecb2699935882c60a9b37f82f8625ae" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "thiserror" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.4", ] [[package]] @@ -852,7 +865,7 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wynd-lsd-hub" -version = "1.1.0" +version = "1.2.0" dependencies = [ "anyhow", "cosmwasm-schema", diff --git a/Cargo.toml b/Cargo.toml index add8be9..aeab5ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ members = ["packages/*", "contracts/*"] [workspace.package] -version = "1.1.0" +version = "1.2.0" edition = "2021" license = "GPL 3.0" repository = "https://github.com/cosmorama/wynd-lsd" @@ -22,7 +22,7 @@ cw-utils = "1.0" semver = "1" serde = { version = "1", default-features = false, features = ["derive"] } thiserror = "1" -wynd-lsd-hub = { path = "./contracts/lsd-hub", version = "1.0.0", features = ["library"] } +wynd-lsd-hub = { path = "./contracts/lsd-hub", version = "1.2.0", features = ["library"] } cw-placeholder = { version = "1.0", git = "https://github.com/cosmorama/wynddex.git", tag = "v1.0.0", features = [ "library", ] } diff --git a/contracts/gauge-adapter/Cargo.toml b/contracts/gauge-adapter/Cargo.toml index 7e0d3da..783878b 100644 --- a/contracts/gauge-adapter/Cargo.toml +++ b/contracts/gauge-adapter/Cargo.toml @@ -23,6 +23,8 @@ cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } cw2 = { workspace = true } cw20 = { workspace = true } +cw-utils = { workspace = true } +semver = { workspace = true } thiserror = { workspace = true } wynd-lsd-hub = { workspace = true } cw-placeholder = { workspace = true } diff --git a/contracts/gauge-adapter/src/contract.rs b/contracts/gauge-adapter/src/contract.rs index 8ebbc7d..bdf2399 100644 --- a/contracts/gauge-adapter/src/contract.rs +++ b/contracts/gauge-adapter/src/contract.rs @@ -1,13 +1,17 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult, WasmMsg, + ensure, to_binary, Addr, Binary, Decimal, Deps, DepsMut, Empty, Env, MessageInfo, Response, + StdResult, WasmMsg, }; use cw2::set_contract_version; +use cw_utils::ensure_from_older_version; use cw_placeholder::contract::CONTRACT_NAME as PLACEHOLDER_CONTRACT_NAME; use wynd_lsd_hub::msg::ExecuteMsg as HubExecuteMsg; +use semver::Version; + use crate::error::ContractError; use crate::msg::{AdapterQueryMsg, InstantiateMsg, MigrateMsg}; use crate::state::{Config, CONFIG}; @@ -25,8 +29,14 @@ pub fn instantiate( ) -> Result { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + ensure!( + msg.max_commission > Decimal::zero() && msg.max_commission <= Decimal::one(), + ContractError::InvalidMaxCommission {} + ); + let config = Config { hub: deps.api.addr_validate(&msg.hub)?, + max_commission: msg.max_commission, }; CONFIG.save(deps.storage, &config)?; @@ -66,11 +76,14 @@ mod query { use super::*; pub fn all_options(deps: Deps) -> StdResult { + let max_commission = CONFIG.load(deps.storage)?.max_commission; + Ok(AllOptionsResponse { options: deps .querier .query_all_validators()? .into_iter() + .filter(|v| v.commission <= max_commission) .map(|v| v.address) .collect(), }) @@ -86,7 +99,10 @@ mod query { deps: Deps, new_validators: Vec<(String, Decimal)>, ) -> StdResult { - let Config { hub } = CONFIG.load(deps.storage)?; + let Config { + hub, + max_commission: _, + } = CONFIG.load(deps.storage)?; Ok(SampleGaugeMsgsResponse { execute: vec![WasmMsg::Execute { contract_addr: hub.to_string(), @@ -98,6 +114,15 @@ mod query { } } +pub mod migration { + use cosmwasm_schema::cw_serde; + + #[cw_serde] + pub struct OldConfig { + pub hub: String, + } +} + /// Manages the contract migration. #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Result { @@ -126,6 +151,20 @@ pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Result { + let version = ensure_from_older_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + if version < "1.2.0".parse::().unwrap() { + use cw_storage_plus::Item; + let old_storage: Item = Item::new("config"); + let old_config = old_storage.load(deps.storage)?; + + let new_config = Config { + hub: Addr::unchecked(old_config.hub), + max_commission, + }; + CONFIG.save(deps.storage, &new_config)?; + } + } }; Ok(Response::new()) @@ -145,12 +184,62 @@ mod tests { let mut deps = mock_dependencies(); let msg = InstantiateMsg { hub: "hub".to_string(), + max_commission: Decimal::percent(30), }; instantiate(deps.as_mut(), mock_env(), mock_info("user", &[]), msg).unwrap(); // check if the config is stored let config = CONFIG.load(deps.as_ref().storage).unwrap(); assert_eq!(config.hub, "hub"); + assert_eq!(config.max_commission, Decimal::percent(30)); + } + + #[test] + fn invalid_max_commission() { + let mut deps = mock_dependencies(); + let msg = InstantiateMsg { + hub: "hub".to_string(), + max_commission: Decimal::zero(), + }; + + let err = instantiate( + deps.as_mut(), + mock_env(), + mock_info("user", &[]), + msg.clone(), + ) + .unwrap_err(); + assert_eq!(err, ContractError::InvalidMaxCommission {}); + + let msg = InstantiateMsg { + max_commission: Decimal::percent(101), + ..msg + }; + let err = instantiate( + deps.as_mut(), + mock_env(), + mock_info("user", &[]), + msg.clone(), + ) + .unwrap_err(); + assert_eq!(err, ContractError::InvalidMaxCommission {}); + + let msg = InstantiateMsg { + max_commission: Decimal::one(), + ..msg + }; + instantiate( + deps.as_mut(), + mock_env(), + mock_info("user", &[]), + msg.clone(), + ) + .unwrap(); + let msg = InstantiateMsg { + max_commission: Decimal::percent(1), + ..msg + }; + instantiate(deps.as_mut(), mock_env(), mock_info("user", &[]), msg).unwrap(); } #[test] @@ -163,6 +252,7 @@ mod tests { mock_info("user", &[]), InstantiateMsg { hub: "hub".to_string(), + max_commission: Decimal::percent(30), }, ) .unwrap(); diff --git a/contracts/gauge-adapter/src/error.rs b/contracts/gauge-adapter/src/error.rs index 6acab69..8d86a38 100644 --- a/contracts/gauge-adapter/src/error.rs +++ b/contracts/gauge-adapter/src/error.rs @@ -8,4 +8,7 @@ pub enum ContractError { #[error("Can only init upgrade from cw-placeholder")] NotPlaceholder, + + #[error("Invalid max_commission; must be higher then 0.0 and smaller or equal then 1.0")] + InvalidMaxCommission {}, } diff --git a/contracts/gauge-adapter/src/msg.rs b/contracts/gauge-adapter/src/msg.rs index cd3034d..b8cf37d 100644 --- a/contracts/gauge-adapter/src/msg.rs +++ b/contracts/gauge-adapter/src/msg.rs @@ -5,12 +5,16 @@ use cosmwasm_std::{CosmosMsg, Decimal}; pub struct InstantiateMsg { /// Address of the hub contract pub hub: String, + /// Maximum allowed commision by validator to be included in voting set + pub max_commission: Decimal, } #[cw_serde] pub enum MigrateMsg { /// Used to instantiate from cw-placeholder Init(InstantiateMsg), + /// Migrates from version <= v1.2.0 + Update { max_commission: Decimal }, } // Queries copied from gauge-orchestrator for now (we could use a common crate for this) diff --git a/contracts/gauge-adapter/src/multitest/options.rs b/contracts/gauge-adapter/src/multitest/options.rs index fdfbe93..386dbcf 100644 --- a/contracts/gauge-adapter/src/multitest/options.rs +++ b/contracts/gauge-adapter/src/multitest/options.rs @@ -5,9 +5,9 @@ use crate::multitest::suite::SuiteBuilder; #[test] fn option_queries() { let validators = vec![ - "junovaloper1t8ehvswxjfn3ejzkjtntcyrqwvmvuknzmvtaaa", - "junovaloper196ax4vc0lwpxndu9dyhvca7jhxp70rmcqcnylw", - "junovaloper1y0us8xvsvfvqkk9c6nt5cfyu5au5tww2wsdcwk", + ("junovaloper1t8ehvswxjfn3ejzkjtntcyrqwvmvuknzmvtaaa", "1.0"), + ("junovaloper196ax4vc0lwpxndu9dyhvca7jhxp70rmcqcnylw", "1.0"), + ("junovaloper1y0us8xvsvfvqkk9c6nt5cfyu5au5tww2wsdcwk", "1.0"), ]; let suite = SuiteBuilder::new() .with_chain_validators(validators.clone()) @@ -17,14 +17,42 @@ fn option_queries() { let options = suite.query_all_options().unwrap(); assert_eq!( options, - validators.iter().map(|v| v.to_string()).collect::>() + validators + .iter() + .map(|v| v.0.to_string()) + .collect::>() ); // check option validity for v in validators { - assert!(suite.query_check_option(v.to_string()).unwrap()); + assert!(suite.query_check_option(v.0.to_string()).unwrap()); } assert!(!suite .query_check_option(Addr::unchecked("invalid").to_string()) .unwrap()); } + +#[test] +fn query_validators_with_commission_cap() { + let validators = vec![ + ("junovaloper1t8ehvswxjfn3ejzkjtntcyrqwvmvuknzmvtaaa", "1.0"), + ("junovaloper196ax4vc0lwpxndu9dyhvca7jhxp70rmcqcnylw", "0.2"), + ("junovaloper196ax4vc0lwpxndu9dyhvca7jhxpsdawytdfsgf", "0.3"), + ("junovaloper196ax4vc0lwpxndu9dyhvca7jhxp70rdadsadsa", "0.8"), + ("junovaloper1y0us8xvsvfvqkk9c6nt5cfyu5au5tww2wsdcwk", "1.0"), + ]; + let suite = SuiteBuilder::new() + .with_chain_validators(validators.clone()) + .with_max_allowed_commission("0.3") + .build(); + + // get all options + let options = suite.query_all_options().unwrap(); + assert_eq!( + options, + vec![ + "junovaloper196ax4vc0lwpxndu9dyhvca7jhxp70rmcqcnylw", + "junovaloper196ax4vc0lwpxndu9dyhvca7jhxpsdawytdfsgf" + ] + ); +} diff --git a/contracts/gauge-adapter/src/multitest/sample.rs b/contracts/gauge-adapter/src/multitest/sample.rs index 482abb3..246e938 100644 --- a/contracts/gauge-adapter/src/multitest/sample.rs +++ b/contracts/gauge-adapter/src/multitest/sample.rs @@ -1,33 +1,31 @@ -// TODO: uncomment when validator set update is implemented +use cosmwasm_std::Decimal; -// use cosmwasm_std::Decimal; +use super::suite::SuiteBuilder; -// use super::suite::SuiteBuilder; +#[test] +fn updating_validators_works() { + let mut suite = SuiteBuilder::new().build(); -// #[test] -// fn updating_validators_works() { -// let mut suite = SuiteBuilder::new().build(); + let selected = vec![ + ( + "junovaloper196ax4vc0lwpxndu9dyhvca7jhxp70rmcqcnylw".to_string(), + Decimal::percent(50), + ), + ( + "junovaloper1y0us8xvsvfvqkk9c6nt5cfyu5au5tww2wsdcwk".to_string(), + Decimal::percent(20), + ), + ]; + // sample messages + let messages = suite.sample_gauge_msgs(selected.clone()); -// let selected = vec![ -// ( -// "junovaloper196ax4vc0lwpxndu9dyhvca7jhxp70rmcqcnylw".to_string(), -// Decimal::percent(50), -// ), -// ( -// "junovaloper1y0us8xvsvfvqkk9c6nt5cfyu5au5tww2wsdcwk".to_string(), -// Decimal::percent(20), -// ), -// ]; -// // sample messages -// let messages = suite.sample_gauge_msgs(selected.clone()); + // should be able to update validators + suite + .app + .execute_multi(suite.owner.clone(), messages) + .unwrap(); -// // should be able to update validators -// suite -// .app -// .execute_multi(suite.owner.clone(), messages) -// .unwrap(); - -// // check if the validators are updated -// let validators = suite.query_validator_set().unwrap(); -// assert_eq!(validators, selected); -// } + // check if the validators are updated + let validators = suite.query_validator_set().unwrap(); + assert_eq!(validators, selected); +} diff --git a/contracts/gauge-adapter/src/multitest/suite.rs b/contracts/gauge-adapter/src/multitest/suite.rs index aa24c05..1be2e79 100644 --- a/contracts/gauge-adapter/src/multitest/suite.rs +++ b/contracts/gauge-adapter/src/multitest/suite.rs @@ -1,3 +1,5 @@ +use std::str::FromStr; + use anyhow::Result as AnyResult; use cosmwasm_std::{testing::mock_env, Addr, CosmosMsg, Decimal, Validator}; @@ -62,10 +64,11 @@ fn store_placeholder_code(app: &mut App) -> u64 { #[derive(Debug)] pub struct SuiteBuilder { - chain_validators: Vec, - validator_commission: Decimal, + max_allowed_commission: Decimal, + // validator / commission + chain_validators: Vec<(String, Decimal)>, - comission: Decimal, + commission: Decimal, validators: Vec<(String, Decimal)>, epoch_period: u64, unbond_period: u64, @@ -76,13 +79,22 @@ pub struct SuiteBuilder { impl SuiteBuilder { pub fn new() -> Self { Self { + max_allowed_commission: Decimal::one(), chain_validators: vec![ - "junovaloper1t8ehvswxjfn3ejzkjtntcyrqwvmvuknzmvtaaa".to_string(), - "junovaloper196ax4vc0lwpxndu9dyhvca7jhxp70rmcqcnylw".to_string(), - "junovaloper1y0us8xvsvfvqkk9c6nt5cfyu5au5tww2wsdcwk".to_string(), + ( + "junovaloper1t8ehvswxjfn3ejzkjtntcyrqwvmvuknzmvtaaa".to_string(), + Decimal::one(), + ), + ( + "junovaloper196ax4vc0lwpxndu9dyhvca7jhxp70rmcqcnylw".to_string(), + Decimal::one(), + ), + ( + "junovaloper1y0us8xvsvfvqkk9c6nt5cfyu5au5tww2wsdcwk".to_string(), + Decimal::one(), + ), ], - validator_commission: Decimal::percent(1), - comission: Decimal::percent(10), + commission: Decimal::percent(10), validators: vec![( "junovaloper196ax4vc0lwpxndu9dyhvca7jhxp70rmcqcnylw".to_string(), Decimal::one(), @@ -94,17 +106,16 @@ impl SuiteBuilder { } } - pub fn with_chain_validators(mut self, chain_validators: Vec<&str>) -> Self { - self.chain_validators = chain_validators - .into_iter() - .map(|v| v.to_string()) - .collect(); + pub fn with_max_allowed_commission(mut self, commission: &str) -> Self { + self.max_allowed_commission = Decimal::from_str(commission).unwrap(); self } - #[allow(unused)] - pub fn with_validator_commission(mut self, validator_commission: Decimal) -> Self { - self.validator_commission = validator_commission; + pub fn with_chain_validators(mut self, chain_validators: Vec<(&str, &str)>) -> Self { + self.chain_validators = chain_validators + .into_iter() + .map(|(v, c)| (v.to_string(), Decimal::from_str(c).unwrap())) + .collect(); self } @@ -115,8 +126,8 @@ impl SuiteBuilder { } #[allow(unused)] - pub fn with_comission(mut self, comission: Decimal) -> Self { - self.comission = comission; + pub fn with_commission(mut self, commission: Decimal) -> Self { + self.commission = commission; self } @@ -166,7 +177,7 @@ impl SuiteBuilder { &HubInstantiateMsg { treasury: "treasury".to_string(), owner: owner.to_string(), - comission: self.comission, + commission: self.commission, validators: self.validators, cw20_init: TokenInitInfo { cw20_code_id, @@ -190,6 +201,7 @@ impl SuiteBuilder { let adapter_init_msg = crate::msg::InstantiateMsg { hub: hub.to_string(), + max_commission: self.max_allowed_commission, }; let adapter_label = "Gauge Adapter"; @@ -227,14 +239,14 @@ impl SuiteBuilder { }; app.init_modules(|router, api, storage| -> AnyResult<()> { - for val in self.chain_validators { + for (address, commission) in self.chain_validators { router.staking.add_validator( api, storage, &mock_env().block, Validator { - address: val, - commission: self.validator_commission, + address, + commission, max_commission: Decimal::one(), max_change_rate: Decimal::one(), }, diff --git a/contracts/gauge-adapter/src/state.rs b/contracts/gauge-adapter/src/state.rs index aa76696..8a4e43c 100644 --- a/contracts/gauge-adapter/src/state.rs +++ b/contracts/gauge-adapter/src/state.rs @@ -1,11 +1,13 @@ use cosmwasm_schema::cw_serde; -use cosmwasm_std::Addr; +use cosmwasm_std::{Addr, Decimal}; use cw_storage_plus::Item; #[cw_serde] pub struct Config { /// Address of the hub contract pub hub: Addr, + /// Maximum allowed commision by validator to be included in voting set + pub max_commission: Decimal, } pub const CONFIG: Item = Item::new("config"); diff --git a/contracts/lsd-hub/src/contract.rs b/contracts/lsd-hub/src/contract.rs index 0dfa35d..78518e2 100644 --- a/contracts/lsd-hub/src/contract.rs +++ b/contracts/lsd-hub/src/contract.rs @@ -45,7 +45,7 @@ pub fn instantiate( SUPPLY.save(deps.storage, &supply)?; // Verify commission is greater than 0.0 and no higher than 0.50 - if msg.comission < Decimal::zero() || msg.comission > Decimal::percent(50) { + if msg.commission < Decimal::zero() || msg.commission > Decimal::percent(50) { return Err(ContractError::InvalidCommission {}); } @@ -94,7 +94,7 @@ pub fn instantiate( let config = Config { token_contract: Addr::unchecked(""), treasury: deps.api.addr_validate(&msg.treasury)?, - commission: msg.comission, + commission: msg.commission, epoch_period: msg.epoch_period, unbond_period: msg.unbond_period, owner: deps.api.addr_validate(&msg.owner)?, @@ -771,7 +771,7 @@ mod tests { fn init(deps: DepsMut, owner: &str) -> Response { let msg = InstantiateMsg { treasury: "treasury".to_string(), - comission: Decimal::percent(10), + commission: Decimal::percent(10), validators: vec![("val1".to_string(), Decimal::percent(100))], owner: owner.to_string(), @@ -802,7 +802,7 @@ mod tests { let msg = InstantiateMsg { treasury: "treasury".to_string(), - comission: Decimal::percent(10), + commission: Decimal::percent(10), validators: vec![("val1".to_string(), Decimal::percent(100))], owner: "owner".to_string(), @@ -894,7 +894,7 @@ mod tests { // Instantiate message with invalid commission let msg = InstantiateMsg { treasury: "treasury".to_string(), - comission: Decimal::percent(100), + commission: Decimal::percent(100), validators: vec![("val1".to_string(), Decimal::percent(100))], owner: "owner".to_string(), @@ -925,7 +925,7 @@ mod tests { // Instantiate message with invalid validator weights let msg = InstantiateMsg { treasury: "treasury".to_string(), - comission: Decimal::percent(10), + commission: Decimal::percent(10), validators: vec![("val1".to_string(), Decimal::percent(50))], owner: "owner".to_string(), @@ -953,7 +953,7 @@ mod tests { // Instantiate message with a badd Liquidity Discount value let msg = InstantiateMsg { treasury: "treasury".to_string(), - comission: Decimal::percent(10), + commission: Decimal::percent(10), validators: vec![("val1".to_string(), Decimal::percent(100))], owner: "owner".to_string(), @@ -1074,7 +1074,7 @@ mod tests { let msg = InstantiateMsg { treasury: "treasury".to_string(), - comission: Decimal::percent(10), + commission: Decimal::percent(10), validators: vec![("val1".to_string(), Decimal::percent(100))], owner: "owner".to_string(), diff --git a/contracts/lsd-hub/src/msg.rs b/contracts/lsd-hub/src/msg.rs index 61d374c..144fe5c 100644 --- a/contracts/lsd-hub/src/msg.rs +++ b/contracts/lsd-hub/src/msg.rs @@ -23,7 +23,7 @@ pub struct InstantiateMsg { // This address collects a commission from the rewards pub treasury: String, /// This is the percentage of the collected rewards sent to the treasury - pub comission: Decimal, + pub commission: Decimal, /// The owner/admin of the created CW20 pub owner: String, diff --git a/contracts/lsd-hub/src/multitest/suite.rs b/contracts/lsd-hub/src/multitest/suite.rs index ac4a2ef..c9526ab 100644 --- a/contracts/lsd-hub/src/multitest/suite.rs +++ b/contracts/lsd-hub/src/multitest/suite.rs @@ -177,7 +177,7 @@ impl SuiteBuilder { admin.clone(), &InstantiateMsg { treasury: "treasury".to_string(), - comission: self.treasury_commission, + commission: self.treasury_commission, validators: self.validators, owner: "owner".to_string(), diff --git a/node_ci_test/deploy_and_instantiate_contracts.ts b/node_ci_test/deploy_and_instantiate_contracts.ts index 9391977..fccc579 100755 --- a/node_ci_test/deploy_and_instantiate_contracts.ts +++ b/node_ci_test/deploy_and_instantiate_contracts.ts @@ -12,7 +12,7 @@ import {readFileSync} from 'fs'; declare var process; declare var __dirname; import { getCosmWasmClient} from './src/index'; -import { alice, DEFAULT_COMISSION, DEFAULT_EPOCH_PEROID, DEFAULT_UNBOND_PEROID, ENDPOINT, GAS_INSTANTIATE_COST, GAS_UPLOAD_COST } from './src/constants'; +import { alice, DEFAULT_COMMISSION, DEFAULT_EPOCH_PEROID, DEFAULT_UNBOND_PEROID, ENDPOINT, GAS_INSTANTIATE_COST, GAS_UPLOAD_COST } from './src/constants'; async function main() { const { gasPrice, client } = await getCosmWasmClient(); @@ -46,7 +46,7 @@ async function main() { { // TODO: change this to a better address treasury: admin, - comission: DEFAULT_COMISSION, + commission: DEFAULT_COMMISSION, owner: admin, validators: [["wasmvaloper1tjgue6r5kqj5dets24pwaa9u7wuzucpwfsgndk", "1.0"]], cw20_init: { diff --git a/node_ci_test/spec/main.spec.ts b/node_ci_test/spec/main.spec.ts index 968ad06..8c9fd2a 100644 --- a/node_ci_test/spec/main.spec.ts +++ b/node_ci_test/spec/main.spec.ts @@ -3,7 +3,7 @@ import "jasmine"; import { encodeBase64, getCosmWasmClient } from "../src/index"; import { coin } from '@cosmjs/proto-signing'; import { calculateFee } from '@cosmjs/stargate'; -import { CONFIG_QUERY, BOND_EXECUTE_MSG, CLAIM_EXECUTE_MSG, alice, bob, DEFAULT_COMISSION, DEFAULT_UNBOND_PEROID, DEFAULT_EPOCH_PEROID, DELAY_EPOCH, GAS_INSTANTIATE_COST, GAS_EXECUTE_COST } from "../src/constants"; +import { CONFIG_QUERY, BOND_EXECUTE_MSG, CLAIM_EXECUTE_MSG, alice, bob, DEFAULT_COMMISSION, DEFAULT_UNBOND_PEROID, DEFAULT_EPOCH_PEROID, DELAY_EPOCH, GAS_INSTANTIATE_COST, GAS_EXECUTE_COST } from "../src/constants"; import { SpecReporter, StacktraceOption } from 'jasmine-spec-reporter'; // Make Jasmine output prettier and more verbose @@ -23,7 +23,7 @@ describe("The LSD Hub", function () { const result = await client.queryContractSmart(WYND_LSD_HUB, CONFIG_QUERY); expect(result.owner).toBe(alice.address0); - expect(result.commission).toBe(DEFAULT_COMISSION); + expect(result.commission).toBe(DEFAULT_COMMISSION); expect(result.unbond_period).toBe(DEFAULT_UNBOND_PEROID); expect(result.epoch_period).toBe(DEFAULT_EPOCH_PEROID); }); diff --git a/node_ci_test/src/constants.ts b/node_ci_test/src/constants.ts index 9ca0011..421eb2c 100644 --- a/node_ci_test/src/constants.ts +++ b/node_ci_test/src/constants.ts @@ -11,7 +11,7 @@ export const bob = { mnemonic: "remain fragile remove stamp quiz bus country dress critic mammal office need", address0: "wasm1lvrwcvrqlc5ktzp2c4t22xgkx29q3y83426at5", } -export const DEFAULT_COMISSION = "0.01"; +export const DEFAULT_COMMISSION = "0.01"; export const DEFAULT_EPOCH_PEROID = 5; export const DEFAULT_UNBOND_PEROID = 5; export const DELAY_EPOCH = 5000;