introduced the concept of allowed profit margin ranges

This commit is contained in:
Jędrzej Stuczyński
2024-07-17 15:06:44 +01:00
committed by fmtabbara
parent 70db1ad062
commit 03ffb25bf9
6 changed files with 41 additions and 2 deletions
@@ -57,6 +57,25 @@ pub struct InstantiateMsg {
pub epochs_in_interval: u32,
pub epoch_duration: Duration,
pub initial_rewarding_params: InitialRewardingParams,
#[serde(default)]
pub profit_margin: ProfitMarginRange,
}
#[cw_serde]
#[derive(Copy)]
pub struct ProfitMarginRange {
pub minimum: Percent,
pub maximum: Percent,
}
impl Default for ProfitMarginRange {
fn default() -> Self {
ProfitMarginRange {
minimum: Percent::zero(),
maximum: Percent::hundred(),
}
}
}
#[cw_serde]
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
use crate::error::MixnetContractError;
use crate::Layer;
use crate::{Layer, ProfitMarginRange};
use cosmwasm_schema::cw_serde;
use cosmwasm_std::Addr;
use cosmwasm_std::Coin;
@@ -154,4 +154,9 @@ pub struct ContractStateParams {
/// Minimum amount a gateway must pledge to get into the system.
pub minimum_gateway_pledge: Coin,
/// Defines the allowed profit margin range of operators.
/// default: 0% - 100%
#[serde(default)]
pub profit_margin: ProfitMarginRange,
}
+13 -1
View File
@@ -11,7 +11,8 @@ use cosmwasm_std::{
};
use mixnet_contract_common::error::MixnetContractError;
use mixnet_contract_common::{
ContractState, ContractStateParams, ExecuteMsg, InstantiateMsg, Interval, MigrateMsg, QueryMsg,
ContractState, ContractStateParams, ExecuteMsg, InstantiateMsg, Interval, MigrateMsg,
ProfitMarginRange, QueryMsg,
};
use nym_contracts_common::set_build_information;
@@ -24,6 +25,7 @@ fn default_initial_state(
rewarding_validator_address: Addr,
rewarding_denom: String,
vesting_contract_address: Addr,
profit_margin: ProfitMarginRange,
) -> ContractState {
ContractState {
owner,
@@ -40,6 +42,7 @@ fn default_initial_state(
denom: rewarding_denom,
amount: INITIAL_GATEWAY_PLEDGE_AMOUNT,
},
profit_margin,
},
}
}
@@ -71,6 +74,7 @@ pub fn instantiate(
rewarding_validator_address.clone(),
msg.rewarding_denom,
vesting_contract_address,
msg.profit_margin,
);
let starting_interval =
Interval::init_interval(msg.epochs_in_interval, msg.epoch_duration, &env);
@@ -573,6 +577,10 @@ mod tests {
rewarded_set_size: 543,
active_set_size: 123,
},
profit_margin: ProfitMarginRange {
minimum: "0.05".parse().unwrap(),
maximum: "0.95".parse().unwrap(),
},
};
let sender = mock_info("sender", &[]);
@@ -594,6 +602,10 @@ mod tests {
denom: "uatom".into(),
amount: INITIAL_GATEWAY_PLEDGE_AMOUNT,
},
profit_margin: ProfitMarginRange {
minimum: Percent::from_percentage_value(5).unwrap(),
maximum: Percent::from_percentage_value(95).unwrap(),
},
},
};
@@ -45,6 +45,7 @@ pub(crate) mod tests {
minimum_mixnode_delegation: None,
minimum_mixnode_pledge: coin(123u128, "unym"),
minimum_gateway_pledge: coin(456u128, "unym"),
profit_margin: Default::default(),
},
};
@@ -121,6 +121,7 @@ pub mod tests {
denom,
amount: INITIAL_GATEWAY_PLEDGE_AMOUNT + Uint128::new(1234),
},
profit_margin: Default::default(),
};
let initial_params = storage::CONTRACT_STATE
@@ -996,6 +996,7 @@ pub mod test_helpers {
epochs_in_interval: 720,
epoch_duration: Duration::from_secs(60 * 60),
initial_rewarding_params: initial_rewarding_params(),
profit_margin: Default::default(),
};
let env = mock_env();
let info = mock_info("creator", &[]);