Skip to content
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
21 changes: 20 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ members = [
"rs/nns/common/protobuf_generator",
"rs/nns/cmc",
"rs/nns/governance",
"rs/nns/governance/api",
"rs/nns/governance/init",
"rs/nns/governance/protobuf_generator",
"rs/nns/handlers/lifeline/impl",
"rs/nns/handlers/lifeline/interface",
Expand Down
2 changes: 2 additions & 0 deletions rs/nns/governance/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ DEPENDENCIES = BASE_DEPENDENCIES + [
"//rs/nns/governance/api",
"//rs/nns/sns-wasm",
"//rs/sns/init",
"//rs/nns/governance/init",
"//rs/sns/swap",
]

Expand All @@ -88,6 +89,7 @@ DEPENDENCIES_WITH_TEST_FEATURES = BASE_DEPENDENCIES + [
"//rs/nns/sns-wasm:sns-wasm--test_feature",
"//rs/sns/init:init--test_feature",
"//rs/sns/swap:swap--test_feature",
"//rs/nns/governance/init:init--test_feature",
]

MACRO_DEPENDENCIES = [
Expand Down
1 change: 1 addition & 0 deletions rs/nns/governance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ic-nns-common = { path = "../common" }
ic-nns-constants = { path = "../constants" }
ic-nns-gtc-accounts = { path = "../gtc_accounts" }
ic-nns-governance-api = { path = "./api" }
ic-nns-governance-init = { path = "./init" }
ic-protobuf = { path = "../../protobuf" }
ic-sns-init = { path = "../../sns/init" } # This is just for a couple of PB definitions.
ic-sns-root = { path = "../../sns/root" } # This is just for a couple of PB definitions.
Expand Down
78 changes: 77 additions & 1 deletion rs/nns/governance/api/src/pb.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
use crate::pb::v1::{governance_error::ErrorType, GovernanceError};
use crate::pb::v1::{
governance_error::ErrorType, GovernanceError, NetworkEconomics, NeuronsFundEconomics,
NeuronsFundMatchedFundingCurveCoefficients, XdrConversionRate,
};
use ic_nervous_system_proto::pb::v1::{Decimal, Percentage};
use icp_ledger::{DEFAULT_TRANSFER_FEE, TOKEN_SUBDIVIDABLE_BY};

#[allow(clippy::all)]
#[path = "./ic_nns_governance.pb.v1.rs"]
pub mod v1;

/// The number of e8s per ICP;
const E8S_PER_ICP: u64 = TOKEN_SUBDIVIDABLE_BY;
// TODO get this from nervous_system/common/consts after we migrate consts out of nervous_system/common
pub const ONE_DAY_SECONDS: u64 = 24 * 60 * 60;

impl GovernanceError {
pub fn new(error_type: ErrorType) -> Self {
Self {
Expand All @@ -19,3 +29,69 @@ impl GovernanceError {
}
}
}

impl NeuronsFundEconomics {
Comment thread
max-dfinity marked this conversation as resolved.
/// The default values for network economics (until we initialize it).
/// Can't implement Default since it conflicts with Prost's.
/// The values here are computed under the assumption that 1 XDR = 0.75 USD. See also:
/// https://dashboard.internetcomputer.org/proposal/124822
pub fn with_default_values() -> Self {
Self {
max_theoretical_neurons_fund_participation_amount_xdr: Some(Decimal {
human_readable: Some("750_000.0".to_string()),
}),
neurons_fund_matched_funding_curve_coefficients: Some(
NeuronsFundMatchedFundingCurveCoefficients {
contribution_threshold_xdr: Some(Decimal {
human_readable: Some("75_000.0".to_string()),
}),
one_third_participation_milestone_xdr: Some(Decimal {
human_readable: Some("225_000.0".to_string()),
}),
full_participation_milestone_xdr: Some(Decimal {
human_readable: Some("375_000.0".to_string()),
}),
},
),
minimum_icp_xdr_rate: Some(Percentage {
basis_points: Some(10_000), // 1:1
}),
maximum_icp_xdr_rate: Some(Percentage {
basis_points: Some(1_000_000), // 1:100
}),
}
}
}

impl NetworkEconomics {
/// The multiplier applied to minimum_icp_xdr_rate to convert the XDR unit to basis_points
pub const ICP_XDR_RATE_TO_BASIS_POINT_MULTIPLIER: u64 = 100;

// The default values for network economics (until we initialize it).
// Can't implement Default since it conflicts with Prost's.
pub fn with_default_values() -> Self {
Self {
reject_cost_e8s: E8S_PER_ICP, // 1 ICP
neuron_management_fee_per_proposal_e8s: 1_000_000, // 0.01 ICP
neuron_minimum_stake_e8s: E8S_PER_ICP, // 1 ICP
neuron_spawn_dissolve_delay_seconds: ONE_DAY_SECONDS * 7, // 7 days
maximum_node_provider_rewards_e8s: 1_000_000 * 100_000_000, // 1M ICP
minimum_icp_xdr_rate: 100, // 1 XDR
transaction_fee_e8s: DEFAULT_TRANSFER_FEE.get_e8s(),
max_proposals_to_keep_per_topic: 100,
neurons_fund_economics: Some(NeuronsFundEconomics::with_default_values()),
}
}
}

impl XdrConversionRate {
/// This constructor should be used only at canister creation, and not, e.g., after upgrades.
/// The reason this function exists is because `Default::default` is already defined by prost.
/// However, the Governance canister relies on the fields of this structure being `Some`.
pub fn with_default_values() -> Self {
Self {
timestamp_seconds: Some(0),
xdr_permyriad_per_icp: Some(10_000),
}
}
}
58 changes: 58 additions & 0 deletions rs/nns/governance/init/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
load("@rules_rust//rust:defs.bzl", "rust_library")

package(default_visibility = ["//visibility:public"])

# See rs/nervous_system/feature_test.md
BASE_DEPENDENCIES = [
# Keep sorted.
"//rs/nervous_system/common",
"//rs/nervous_system/common/test_keys",
"//rs/nns/common",
"//rs/rosetta-api/icp_ledger",
"//rs/types/base_types",
"@crate_index//:csv",
"@crate_index//:rand",
"@crate_index//:rand_chacha",
]

# Each target declared in this file may choose either these (release-ready)
# dependencies (`DEPENDENCIES`), or `DEPENDENCIES_WITH_TEST_FEATURES` feature previews.
DEPENDENCIES = BASE_DEPENDENCIES + [
"//rs/nns/governance/api",
]

DEPENDENCIES_WITH_TEST_FEATURES = BASE_DEPENDENCIES + [
"//rs/nns/governance/api:api--test_feature",
]
Comment thread
max-dfinity marked this conversation as resolved.

MACRO_DEPENDENCIES = [
# Keep sorted.
]

ALIASES = {}

rust_library(
name = "init",
srcs = glob(
["src/**/*.rs"],
exclude = ["**/*tests.rs"],
),
aliases = ALIASES,
crate_name = "ic_nns_governance_init",
proc_macro_deps = MACRO_DEPENDENCIES,
version = "0.9.0",
deps = DEPENDENCIES,
)

rust_library(
name = "init--test_feature",
srcs = glob(
["src/**/*.rs"],
exclude = ["**/*tests.rs"],
),
aliases = ALIASES,
crate_name = "ic_nns_governance_init",
proc_macro_deps = MACRO_DEPENDENCIES,
version = "0.9.0",
deps = DEPENDENCIES_WITH_TEST_FEATURES,
)
25 changes: 25 additions & 0 deletions rs/nns/governance/init/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "ic-nns-governance-init"
version.workspace = true
authors.workspace = true
edition.workspace = true
description.workspace = true
documentation.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
path = "src/lib.rs"

[dependencies]
ic-base-types = { path = "../../../types/base_types" }
ic-nervous-system-common = { path = "../../../nervous_system/common" }
ic-nervous-system-common-test-keys = { path = "../../../nervous_system/common/test_keys" }
ic-nervous-system-common-build-metadata = { path = "../../../nervous_system/common/build_metadata" }
ic-nns-common = { path = "../../common" }
ic-nns-governance-api = { path = "../api" }
icp-ledger = { path = "../../../rosetta-api/icp_ledger" }
rand = { workspace = true }
rand_chacha = { workspace = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
csv = "1.1"
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#[cfg(not(target_arch = "wasm32"))]
use crate::pb::v1::{neuron::DissolveState, neuron::Followees, Topic};
#[cfg(not(target_arch = "wasm32"))]
use ic_nervous_system_common::ledger;
#[cfg(not(target_arch = "wasm32"))]
use icp_ledger::Subaccount;
#[cfg(not(target_arch = "wasm32"))]
use rand::{RngCore, SeedableRng};
Expand All @@ -11,11 +7,11 @@ use rand_chacha::ChaCha20Rng;
#[cfg(not(target_arch = "wasm32"))]
use std::path::Path;

use crate::pb::v1::{
Governance, NetworkEconomics, Neuron, XdrConversionRate as XdrConversionRatePb,
};
use ic_base_types::PrincipalId;
use ic_nns_common::types::NeuronId;
use ic_nns_governance_api::pb::v1::{
Governance, NetworkEconomics, Neuron, XdrConversionRate as XdrConversionRatePb,
};

// To update or add more, add print statements to `with_test_neurons` to print
// the generated neuron IDs and copy the printed IDs here.
Expand Down Expand Up @@ -97,6 +93,7 @@ impl GovernanceCanisterInitPayloadBuilder {
TEST_NEURON_1_ID, TEST_NEURON_1_OWNER_PRINCIPAL, TEST_NEURON_2_ID,
TEST_NEURON_2_OWNER_PRINCIPAL, TEST_NEURON_3_ID, TEST_NEURON_3_OWNER_PRINCIPAL,
};
use ic_nns_governance_api::pb::v1::{neuron::DissolveState, Neuron};

let mut neuron1 = {
let neuron_id = NeuronIdProto::from(self.new_neuron_id());
Expand Down Expand Up @@ -210,6 +207,13 @@ impl GovernanceCanisterInitPayloadBuilder {
use ic_nns_common::pb::v1::NeuronId as NeuronIdProto;

use csv::ReaderBuilder;
use ic_base_types::PrincipalId;
use ic_nervous_system_common::ledger;
use ic_nns_common::types::NeuronId;
use ic_nns_governance_api::pb::v1::{
neuron::{DissolveState, Followees},
Neuron, Topic,
};
use std::str::FromStr;

let mut reader = ReaderBuilder::new()
Expand Down
29 changes: 16 additions & 13 deletions rs/nns/governance/src/governance/tests/neurons_fund.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use super::*;
use crate::init::GovernanceCanisterInitPayloadBuilder;
use crate::pb::v1::create_service_nervous_system::SwapParameters;
use crate::test_utils::{MockEnvironment, StubCMC, StubIcpLedger};
use crate::{
pb::v1::create_service_nervous_system::SwapParameters,
test_utils::{MockEnvironment, StubCMC, StubIcpLedger},
};
use assert_matches::assert_matches;
use ic_nervous_system_common::E8;
use ic_nervous_system_proto::pb::v1 as pb;
use ic_nns_governance_api::pb::v1 as pb_api;
use ic_nns_governance_init::GovernanceCanisterInitPayloadBuilder;
use maplit::btreemap;
use test_data::CREATE_SERVICE_NERVOUS_SYSTEM_WITH_MATCHED_FUNDING;

Expand All @@ -16,13 +19,13 @@ fn proposal_passes_if_not_too_many_nf_neurons_can_occur() {
.with_test_neurons_fund_neurons(500_000 * E8)
.build();
governance_proto.proposals = btreemap! {
123 => ProposalData {
123_u64 => ProposalData {
id: Some(proposal_id),
..ProposalData::default()
}
}.into()
};
let mut governance = Governance::new(
governance_proto,
governance_proto.into(),
Box::<MockEnvironment>::default(),
Box::new(StubIcpLedger {}),
Box::new(StubCMC {}),
Expand Down Expand Up @@ -72,7 +75,7 @@ fn proposal_fails_if_too_many_nf_neurons_can_occur() {
})
.unwrap();
let neurons = (0..num_neurons_fund_neurons)
.map(|id| NeuronProto {
.map(|id| pb_api::Neuron {
id: Some(NeuronId { id }),
..proto_neuron.clone()
})
Expand All @@ -82,13 +85,13 @@ fn proposal_fails_if_too_many_nf_neurons_can_occur() {
.build()
};
governance_proto.proposals = btreemap! {
123 => ProposalData {
123_u64 => ProposalData {
id: Some(proposal_id),
..ProposalData::default()
}
}.into()
};
let mut governance = Governance::new(
governance_proto,
governance_proto.into(),
Box::<MockEnvironment>::default(),
Box::new(StubIcpLedger {}),
Box::new(StubCMC {}),
Expand Down Expand Up @@ -123,13 +126,13 @@ fn proposal_fails_if_no_nf_neurons_exist() {
let create_service_nervous_system = CREATE_SERVICE_NERVOUS_SYSTEM_WITH_MATCHED_FUNDING.clone();
let mut governance_proto = GovernanceCanisterInitPayloadBuilder::new().build();
governance_proto.proposals = btreemap! {
123 => ProposalData {
123_u64 => ProposalData {
id: Some(proposal_id),
..ProposalData::default()
}
}.into()
};
let mut governance = Governance::new(
governance_proto,
governance_proto.into(),
Box::<MockEnvironment>::default(),
Box::new(StubIcpLedger {}),
Box::new(StubCMC {}),
Expand Down
1 change: 0 additions & 1 deletion rs/nns/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ mod garbage_collection;
pub mod governance;
pub mod governance_proto_builder;
mod heap_governance_data;
pub mod init;
mod known_neuron_index;
mod migrations;
mod neuron;
Expand Down
Loading