Skip to content

Commit 69dd03d

Browse files
Self decribing action for ManageNetworkEconomics
1 parent e66596c commit 69dd03d

File tree

3 files changed

+257
-0
lines changed

3 files changed

+257
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
use crate::{
2+
pb::v1::{
3+
NetworkEconomics, NeuronsFundEconomics, NeuronsFundMatchedFundingCurveCoefficients,
4+
SelfDescribingValue, VotingPowerEconomics,
5+
},
6+
proposals::self_describing::{LocallyDescribableProposalAction, ValueBuilder},
7+
};
8+
9+
use ic_nervous_system_proto::pb::v1::{Decimal, Percentage};
10+
11+
impl LocallyDescribableProposalAction for NetworkEconomics {
12+
const TYPE_NAME: &'static str = "Manage Network Economics";
13+
const TYPE_DESCRIPTION: &'static str = "Updates the network economics parameters that control various costs, rewards, and \
14+
thresholds in the Network Nervous System, including proposal costs, neuron staking \
15+
requirements, transaction fees, and voting power economics.";
16+
17+
fn to_self_describing_value(&self) -> SelfDescribingValue {
18+
ValueBuilder::new()
19+
.add_field("reject_cost_e8s", self.reject_cost_e8s)
20+
.add_field("neuron_minimum_stake_e8s", self.neuron_minimum_stake_e8s)
21+
.add_field(
22+
"neuron_management_fee_per_proposal_e8s",
23+
self.neuron_management_fee_per_proposal_e8s,
24+
)
25+
.add_field("minimum_icp_xdr_rate", self.minimum_icp_xdr_rate)
26+
.add_field(
27+
"neuron_spawn_dissolve_delay_seconds",
28+
self.neuron_spawn_dissolve_delay_seconds,
29+
)
30+
.add_field(
31+
"maximum_node_provider_rewards_e8s",
32+
self.maximum_node_provider_rewards_e8s,
33+
)
34+
.add_field("transaction_fee_e8s", self.transaction_fee_e8s)
35+
.add_field(
36+
"max_proposals_to_keep_per_topic",
37+
self.max_proposals_to_keep_per_topic,
38+
)
39+
.add_field(
40+
"neurons_fund_economics",
41+
self.neurons_fund_economics.clone(),
42+
)
43+
.add_field("voting_power_economics", self.voting_power_economics)
44+
.build()
45+
}
46+
}
47+
48+
impl From<NeuronsFundEconomics> for SelfDescribingValue {
49+
fn from(economics: NeuronsFundEconomics) -> Self {
50+
ValueBuilder::new()
51+
.add_field(
52+
"max_theoretical_neurons_fund_participation_amount_xdr",
53+
economics.max_theoretical_neurons_fund_participation_amount_xdr,
54+
)
55+
.add_field(
56+
"neurons_fund_matched_funding_curve_coefficients",
57+
economics.neurons_fund_matched_funding_curve_coefficients,
58+
)
59+
.add_field("minimum_icp_xdr_rate", economics.minimum_icp_xdr_rate)
60+
.add_field("maximum_icp_xdr_rate", economics.maximum_icp_xdr_rate)
61+
.build()
62+
}
63+
}
64+
65+
impl From<Percentage> for SelfDescribingValue {
66+
fn from(percentage: Percentage) -> Self {
67+
ValueBuilder::new()
68+
.add_field("basis_points", percentage.basis_points)
69+
.build()
70+
}
71+
}
72+
73+
impl From<Decimal> for SelfDescribingValue {
74+
fn from(decimal: Decimal) -> Self {
75+
ValueBuilder::new()
76+
.add_field("human_readable", decimal.human_readable)
77+
.build()
78+
}
79+
}
80+
81+
impl From<NeuronsFundMatchedFundingCurveCoefficients> for SelfDescribingValue {
82+
fn from(coefficients: NeuronsFundMatchedFundingCurveCoefficients) -> Self {
83+
ValueBuilder::new()
84+
.add_field(
85+
"contribution_threshold_xdr",
86+
coefficients.contribution_threshold_xdr,
87+
)
88+
.add_field(
89+
"one_third_participation_milestone_xdr",
90+
coefficients.one_third_participation_milestone_xdr,
91+
)
92+
.add_field(
93+
"full_participation_milestone_xdr",
94+
coefficients.full_participation_milestone_xdr,
95+
)
96+
.build()
97+
}
98+
}
99+
100+
impl From<VotingPowerEconomics> for SelfDescribingValue {
101+
fn from(economics: VotingPowerEconomics) -> Self {
102+
ValueBuilder::new()
103+
.add_field(
104+
"start_reducing_voting_power_after_seconds",
105+
economics.start_reducing_voting_power_after_seconds,
106+
)
107+
.add_field(
108+
"clear_following_after_seconds",
109+
economics.clear_following_after_seconds,
110+
)
111+
.add_field(
112+
"neuron_minimum_dissolve_delay_to_vote_seconds",
113+
economics.neuron_minimum_dissolve_delay_to_vote_seconds,
114+
)
115+
.build()
116+
}
117+
}
118+
119+
#[cfg(test)]
120+
#[path = "manage_network_economics_tests.rs"]
121+
mod tests;
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
use super::*;
2+
use crate::proposals::self_describing::LocallyDescribableProposalAction;
3+
use ic_nns_governance_api::SelfDescribingValue;
4+
use maplit::hashmap;
5+
6+
#[test]
7+
fn test_network_economics_all_fields() {
8+
let network_economics = NetworkEconomics::with_default_values();
9+
10+
let self_describing_value =
11+
SelfDescribingValue::from(network_economics.to_self_describing_value());
12+
13+
assert_eq!(
14+
self_describing_value,
15+
SelfDescribingValue::Map(hashmap! {
16+
"reject_cost_e8s".to_string() =>
17+
SelfDescribingValue::Nat(candid::Nat::from(100_000_000u64)),
18+
"neuron_minimum_stake_e8s".to_string() =>
19+
SelfDescribingValue::Nat(candid::Nat::from(100_000_000u64)),
20+
"neuron_management_fee_per_proposal_e8s".to_string() =>
21+
SelfDescribingValue::Nat(candid::Nat::from(1_000_000u64)),
22+
"minimum_icp_xdr_rate".to_string() =>
23+
SelfDescribingValue::Nat(candid::Nat::from(100u64)),
24+
"neuron_spawn_dissolve_delay_seconds".to_string() =>
25+
SelfDescribingValue::Nat(candid::Nat::from(604_800u64)),
26+
"maximum_node_provider_rewards_e8s".to_string() =>
27+
SelfDescribingValue::Nat(candid::Nat::from(100_000_000_000_000u64)),
28+
"transaction_fee_e8s".to_string() =>
29+
SelfDescribingValue::Nat(candid::Nat::from(10_000u64)),
30+
"max_proposals_to_keep_per_topic".to_string() =>
31+
SelfDescribingValue::Nat(candid::Nat::from(100u32)),
32+
"neurons_fund_economics".to_string() =>
33+
SelfDescribingValue::Array(vec![
34+
SelfDescribingValue::Map(hashmap! {
35+
"max_theoretical_neurons_fund_participation_amount_xdr".to_string() =>
36+
SelfDescribingValue::Array(vec![
37+
SelfDescribingValue::Map(hashmap! {
38+
"human_readable".to_string() =>
39+
SelfDescribingValue::Array(vec![SelfDescribingValue::Text("750_000.0".to_string())]),
40+
}),
41+
]),
42+
"neurons_fund_matched_funding_curve_coefficients".to_string() =>
43+
SelfDescribingValue::Array(vec![
44+
SelfDescribingValue::Map(hashmap! {
45+
"contribution_threshold_xdr".to_string() =>
46+
SelfDescribingValue::Array(vec![
47+
SelfDescribingValue::Map(hashmap! {
48+
"human_readable".to_string() =>
49+
SelfDescribingValue::Array(vec![SelfDescribingValue::Text("75_000.0".to_string())]),
50+
}),
51+
]),
52+
"one_third_participation_milestone_xdr".to_string() =>
53+
SelfDescribingValue::Array(vec![
54+
SelfDescribingValue::Map(hashmap! {
55+
"human_readable".to_string() =>
56+
SelfDescribingValue::Array(vec![SelfDescribingValue::Text("225_000.0".to_string())]),
57+
}),
58+
]),
59+
"full_participation_milestone_xdr".to_string() =>
60+
SelfDescribingValue::Array(vec![
61+
SelfDescribingValue::Map(hashmap! {
62+
"human_readable".to_string() =>
63+
SelfDescribingValue::Array(vec![SelfDescribingValue::Text("375_000.0".to_string())]),
64+
}),
65+
]),
66+
}),
67+
]),
68+
"minimum_icp_xdr_rate".to_string() =>
69+
SelfDescribingValue::Array(vec![
70+
SelfDescribingValue::Map(hashmap! {
71+
"basis_points".to_string() =>
72+
SelfDescribingValue::Array(vec![SelfDescribingValue::Nat(candid::Nat::from(10_000u64))]),
73+
}),
74+
]),
75+
"maximum_icp_xdr_rate".to_string() =>
76+
SelfDescribingValue::Array(vec![
77+
SelfDescribingValue::Map(hashmap! {
78+
"basis_points".to_string() =>
79+
SelfDescribingValue::Array(vec![SelfDescribingValue::Nat(candid::Nat::from(1_000_000u64))]),
80+
}),
81+
]),
82+
}),
83+
]),
84+
"voting_power_economics".to_string() =>
85+
SelfDescribingValue::Array(vec![
86+
SelfDescribingValue::Map(hashmap! {
87+
"start_reducing_voting_power_after_seconds".to_string() =>
88+
SelfDescribingValue::Array(vec![SelfDescribingValue::Nat(candid::Nat::from(15_778_800u64))]),
89+
"clear_following_after_seconds".to_string() =>
90+
SelfDescribingValue::Array(vec![SelfDescribingValue::Nat(candid::Nat::from(2_629_800u64))]),
91+
"neuron_minimum_dissolve_delay_to_vote_seconds".to_string() =>
92+
SelfDescribingValue::Array(vec![SelfDescribingValue::Nat(candid::Nat::from(15_778_800u64))]),
93+
}),
94+
]),
95+
})
96+
);
97+
}
98+
99+
#[test]
100+
fn test_network_economics_minimal() {
101+
let network_economics = NetworkEconomics {
102+
neurons_fund_economics: None,
103+
voting_power_economics: None,
104+
..NetworkEconomics::with_default_values()
105+
};
106+
107+
let self_describing_value =
108+
SelfDescribingValue::from(network_economics.to_self_describing_value());
109+
110+
assert_eq!(
111+
self_describing_value,
112+
SelfDescribingValue::Map(hashmap! {
113+
"reject_cost_e8s".to_string() =>
114+
SelfDescribingValue::Nat(candid::Nat::from(100_000_000u64)),
115+
"neuron_minimum_stake_e8s".to_string() =>
116+
SelfDescribingValue::Nat(candid::Nat::from(100_000_000u64)),
117+
"neuron_management_fee_per_proposal_e8s".to_string() =>
118+
SelfDescribingValue::Nat(candid::Nat::from(1_000_000u64)),
119+
"minimum_icp_xdr_rate".to_string() =>
120+
SelfDescribingValue::Nat(candid::Nat::from(100u64)),
121+
"neuron_spawn_dissolve_delay_seconds".to_string() =>
122+
SelfDescribingValue::Nat(candid::Nat::from(604_800u64)),
123+
"maximum_node_provider_rewards_e8s".to_string() =>
124+
SelfDescribingValue::Nat(candid::Nat::from(100_000_000_000_000u64)),
125+
"transaction_fee_e8s".to_string() =>
126+
SelfDescribingValue::Nat(candid::Nat::from(10_000u64)),
127+
"max_proposals_to_keep_per_topic".to_string() =>
128+
SelfDescribingValue::Nat(candid::Nat::from(100u32)),
129+
"neurons_fund_economics".to_string() =>
130+
SelfDescribingValue::Array(vec![]),
131+
"voting_power_economics".to_string() =>
132+
SelfDescribingValue::Array(vec![]),
133+
})
134+
);
135+
}

rs/nns/governance/src/proposals/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub mod deregister_known_neuron;
2727
pub mod execute_nns_function;
2828
pub mod fulfill_subnet_rental_request;
2929
pub mod install_code;
30+
pub mod manage_network_economics;
3031
pub mod manage_neuron;
3132
pub mod register_known_neuron;
3233
pub mod self_describing;

0 commit comments

Comments
 (0)