Add stake reward rates and bump version of client (#738)

* Tiny PR to add stake reward rates and bump version

This is needed so that we can publish the 0.17 version.

* Add the changes to contracts as well

On second thought, update the contract together with the client, and
leave the wallet changes for another PR.

* Rename _stake_ to _delegation_
This commit is contained in:
Bogdan-Ștefan Neacşu
2021-08-16 11:43:24 +03:00
committed by GitHub
parent 28e55c6de6
commit bed09bf8a4
7 changed files with 48 additions and 4 deletions
+1 -1
View File
@@ -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",
+2
View File
@@ -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,
}
+14 -2
View File
@@ -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,
}
@@ -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: {} ]",
+6
View File
@@ -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,
@@ -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(
+6
View File
@@ -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,
+2
View File
@@ -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(),
+17 -1
View File
@@ -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 =
@@ -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::{
@@ -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
};