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

Add stake reward rates and bump version of client #738

Merged
merged 3 commits into from
Aug 16, 2021
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
2 changes: 1 addition & 1 deletion clients/validator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nymproject/nym-validator-client",
"version": "0.16.0",
"version": "0.17.0",
"description": "A TypeScript client for interacting with smart contracts in Nym validators",
"repository": "https://github.com/nymtech/nym",
"main": "./dist/index.js",
Expand Down
2 changes: 2 additions & 0 deletions clients/validator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,8 @@ export type StateParams = {
minimum_gateway_bond: string,
mixnode_bond_reward_rate: string,
gateway_bond_reward_rate: string,
mixnode_delegation_reward_rate: string,
gateway_delegation_reward_rate: string,
mixnode_active_set_size: number,
}

Expand Down
16 changes: 14 additions & 2 deletions common/mixnet-contract/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct StateParams {
pub minimum_gateway_bond: Uint128, // minimum amount a gateway must bond to get into the system
pub mixnode_bond_reward_rate: Decimal, // annual reward rate, expressed as a decimal like 1.25
pub gateway_bond_reward_rate: Decimal, // annual reward rate, expressed as a decimal like 1.25
pub mixnode_delegation_reward_rate: Decimal, // annual reward rate, expressed as a decimal like 1.25
pub gateway_delegation_reward_rate: Decimal, // annual reward rate, expressed as a decimal like 1.25
pub mixnode_active_set_size: u32,
}

Expand All @@ -45,14 +47,24 @@ impl Display for StateParams {
write!(f, "minimum gateway bond: {}; ", self.minimum_gateway_bond)?;
write!(
f,
"mixnode reward rate: {}; ",
"mixnode bond reward rate: {}; ",
self.mixnode_bond_reward_rate
)?;
write!(
f,
"gateway reward rate: {}; ",
"gateway bond reward rate: {}; ",
self.gateway_bond_reward_rate
)?;
write!(
f,
"mixnode delegation reward rate: {}; ",
self.mixnode_delegation_reward_rate
)?;
write!(
f,
"gateway delegation reward rate: {}; ",
self.gateway_delegation_reward_rate
)?;
write!(
f,
"mixnode active set size: {} ]",
Expand Down
6 changes: 6 additions & 0 deletions contracts/mixnet/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ pub const INITIAL_MIXNODE_BOND: Uint128 = Uint128(100_000000);
// percentage annual increase. Given starting value of x, we expect to have 1.1x at the end of the year
pub const INITIAL_MIXNODE_BOND_REWARD_RATE: u64 = 110;
pub const INITIAL_GATEWAY_BOND_REWARD_RATE: u64 = 110;
pub const INITIAL_MIXNODE_DELEGATION_REWARD_RATE: u64 = 110;
pub const INITIAL_GATEWAY_DELEGATION_REWARD_RATE: u64 = 110;

pub const INITIAL_MIXNODE_ACTIVE_SET_SIZE: u32 = 100;

fn default_initial_state(owner: Addr) -> State {
let mixnode_bond_reward_rate = Decimal::percent(INITIAL_MIXNODE_BOND_REWARD_RATE);
let gateway_bond_reward_rate = Decimal::percent(INITIAL_GATEWAY_BOND_REWARD_RATE);
let mixnode_delegation_reward_rate = Decimal::percent(INITIAL_MIXNODE_DELEGATION_REWARD_RATE);
let gateway_delegation_reward_rate = Decimal::percent(INITIAL_GATEWAY_DELEGATION_REWARD_RATE);

State {
owner,
Expand All @@ -39,6 +43,8 @@ fn default_initial_state(owner: Addr) -> State {
minimum_gateway_bond: INITIAL_GATEWAY_BOND,
mixnode_bond_reward_rate,
gateway_bond_reward_rate,
mixnode_delegation_reward_rate,
gateway_delegation_reward_rate,
mixnode_active_set_size: INITIAL_MIXNODE_ACTIVE_SET_SIZE,
},
mixnode_epoch_bond_reward: calculate_epoch_reward_rate(
Expand Down
6 changes: 6 additions & 0 deletions contracts/mixnet/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ pub enum ContractError {
#[error("The bond reward rate for gateway was set to be lower than 1")]
DecreasingGatewayBondReward,

#[error("The delegation reward rate for mixnode was set to be lower than 1")]
DecreasingMixnodeDelegationReward,

#[error("The delegation reward rate for gateway was set to be lower than 1")]
DecreasingGatewayDelegationReward,

#[error("The node had uptime larger than 100%")]
UnexpectedUptime,

Expand Down
2 changes: 2 additions & 0 deletions contracts/mixnet/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ mod tests {
minimum_gateway_bond: 456u128.into(),
mixnode_bond_reward_rate: "1.23".parse().unwrap(),
gateway_bond_reward_rate: "4.56".parse().unwrap(),
mixnode_delegation_reward_rate: "7.89".parse().unwrap(),
gateway_delegation_reward_rate: "0.12".parse().unwrap(),
mixnode_active_set_size: 1000,
},
mixnode_epoch_bond_reward: "1.23".parse().unwrap(),
Expand Down
18 changes: 17 additions & 1 deletion contracts/mixnet/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ pub(crate) fn try_update_state_params(
return Err(ContractError::DecreasingGatewayBondReward);
}

if params.mixnode_delegation_reward_rate < Decimal::one() {
return Err(ContractError::DecreasingMixnodeDelegationReward);
}

if params.gateway_delegation_reward_rate < Decimal::one() {
return Err(ContractError::DecreasingGatewayDelegationReward);
}

// if we're updating epoch length, recalculate rewards for both mixnodes and gateways
if state.params.epoch_length != params.epoch_length {
state.mixnode_epoch_bond_reward =
Expand Down Expand Up @@ -682,7 +690,9 @@ pub mod tests {
use super::*;
use crate::contract::{
execute, query, INITIAL_DEFAULT_EPOCH_LENGTH, INITIAL_GATEWAY_BOND,
INITIAL_GATEWAY_BOND_REWARD_RATE, INITIAL_MIXNODE_BOND, INITIAL_MIXNODE_BOND_REWARD_RATE,
INITIAL_GATEWAY_BOND_REWARD_RATE, INITIAL_GATEWAY_DELEGATION_REWARD_RATE,
INITIAL_MIXNODE_BOND, INITIAL_MIXNODE_BOND_REWARD_RATE,
INITIAL_MIXNODE_DELEGATION_REWARD_RATE,
};
use crate::helpers::calculate_epoch_reward_rate;
use crate::storage::{
Expand Down Expand Up @@ -1543,6 +1553,12 @@ pub mod tests {
minimum_gateway_bond: INITIAL_GATEWAY_BOND,
mixnode_bond_reward_rate: Decimal::percent(INITIAL_MIXNODE_BOND_REWARD_RATE),
gateway_bond_reward_rate: Decimal::percent(INITIAL_GATEWAY_BOND_REWARD_RATE),
mixnode_delegation_reward_rate: Decimal::percent(
INITIAL_MIXNODE_DELEGATION_REWARD_RATE,
),
gateway_delegation_reward_rate: Decimal::percent(
INITIAL_GATEWAY_DELEGATION_REWARD_RATE,
),
mixnode_active_set_size: 42, // change something
};

Expand Down