Skip to content

Commit

Permalink
update: currency primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Nov 23, 2019
1 parent a652a20 commit 9f80a33
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 214 deletions.
27 changes: 12 additions & 15 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Substrate chain configurations.
pub use node_runtime::GenesisConfig;

use babe_primitives::AuthorityId as BabeId;
use chain_spec::ChainSpecExtension;
use grandpa_primitives::AuthorityId as GrandpaId;
use hex_literal::hex;
use im_online::sr25519::AuthorityId as ImOnlineId;
use node_primitives::{AccountId, Balance};
use node_runtime::constants::currency::*;
use node_runtime::Block;
pub use node_runtime::GenesisConfig;
use node_runtime::{
constants::currency::MILLICENTS, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig,
constants::currency::*, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, Block, ContractsConfig,
GrandpaConfig, ImOnlineConfig, IndicesConfig, KtonConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig,
SudoConfig, SystemConfig, WASM_BINARY,
};
use primitives::{crypto::UncheckedInto, Pair, Public};
use serde::{Deserialize, Serialize};
use serde_json::de::ParserNumber;
use serde_json::Number;
use serde_json::{de::ParserNumber, Number};
use sr_primitives::Perbill;
use substrate_service;
use substrate_service::Properties;
use substrate_telemetry::TelemetryEndpoints;

Expand Down Expand Up @@ -195,8 +192,8 @@ pub fn testnet_genesis(
]
});

const ENDOWMENT: Balance = 10_000_000 * DOLLARS;
const STASH: Balance = 100 * DOLLARS;
const ENDOWMENT: Balance = 10_000_000 * COIN;
const STASH: Balance = 100 * COIN;

GenesisConfig {
system: Some(SystemConfig {
Expand Down Expand Up @@ -230,7 +227,7 @@ pub fn testnet_genesis(
enable_println, // this should only be enabled on development chains
..Default::default()
},
gas_price: 1 * MILLICENTS,
gas_price: 1 * MICRO,
}),
sudo: Some(SudoConfig { key: root_key }),
babe: Some(BabeConfig { authorities: vec![] }),
Expand All @@ -249,7 +246,7 @@ pub fn testnet_genesis(
}),
staking: Some(StakingConfig {
current_era: 0,
// current_era_total_reward: 80_000_000 * MILLICENTS / 63720,
// current_era_total_reward: 80_000_000 * COIN / 63720,
// offline_slash: Perbill::from_parts(1_000_000),
session_reward: Perbill::from_percent(90),
validator_count: 7,
Expand Down Expand Up @@ -350,8 +347,8 @@ pub fn darwinia_genesis_verbose(
]
});

const ENDOWMENT: Balance = 100_000_000 * MILLICENTS;
const STASH: Balance = 100 * MILLICENTS;
const ENDOWMENT: Balance = 100_000_000 * COIN;
const STASH: Balance = 100 * COIN;

GenesisConfig {
system: Some(SystemConfig {
Expand Down Expand Up @@ -385,7 +382,7 @@ pub fn darwinia_genesis_verbose(
enable_println, // this should only be enabled on development chains
..Default::default()
},
gas_price: 1 * MILLICENTS,
gas_price: 1 * MICRO,
}),
sudo: Some(SudoConfig { key: root_key }),
babe: Some(BabeConfig { authorities: vec![] }),
Expand All @@ -404,7 +401,7 @@ pub fn darwinia_genesis_verbose(
}),
staking: Some(StakingConfig {
current_era: 0,
// current_era_total_reward: 80_000_000 * MILLICENTS / 63720,
// current_era_total_reward: 80_000_000 * COIN / 63720,
// offline_slash: Perbill::from_parts(1_000_000),
session_reward: Perbill::from_percent(90),
validator_count: 7,
Expand Down
4 changes: 1 addition & 3 deletions node/runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ pub mod currency {
pub const NANO: Balance = 1;
pub const MICRO: Balance = 1_000 * NANO;
pub const MILLI: Balance = 1_000 * MICRO;
pub const MILLICENTS: Balance = 1_000 * MILLI;
pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
pub const DOLLARS: Balance = 100 * CENTS;
pub const COIN: Balance = 1_000 * MILLI;
}

/// Time.
Expand Down
41 changes: 20 additions & 21 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![recursion_limit = "256"]

/// Constant values used within the runtime.
pub mod constants;
/// Implementations of some helper traits passed into runtime modules as associated types.
pub mod impls;

pub use contracts::Gas;
pub use timestamp::Call as TimestampCall;

Expand Down Expand Up @@ -55,16 +60,10 @@ use version::RuntimeVersion;
//use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
//use im_online::sr25519::AuthorityId as ImOnlineId;

use darwinia_support::TimeStamp;
use staking::EraIndex;

/// Constant values used within the runtime.
pub mod constants;
/// Implementations of some helper traits passed into runtime modules as associated types.
pub mod impls;

use constants::{currency::*, time::*};
use darwinia_support::TimeStamp;
use impls::{Author, CurrencyToVoteHandler, LinearWeightToFee, TargetedFeeAdjustment};
use staking::EraIndex;

// Make the WASM binary available.
#[cfg(feature = "std")]
Expand Down Expand Up @@ -151,9 +150,9 @@ impl indices::Trait for Runtime {
}

parameter_types! {
pub const ExistentialDeposit: Balance = 1 * MILLICENTS;
pub const TransferFee: Balance = 1 * MILLI;
pub const CreationFee: Balance = 1 * MILLI;
pub const ExistentialDeposit: Balance = 1 * COIN;
pub const TransferFee: Balance = 1 * MICRO;
pub const CreationFee: Balance = 1 * MICRO;
}
impl balances::Trait for Runtime {
type Balance = Balance;
Expand All @@ -168,7 +167,7 @@ impl balances::Trait for Runtime {
}

parameter_types! {
pub const TransactionBaseFee: Balance = 1 * MILLI;
pub const TransactionBaseFee: Balance = 1 * MICRO;
pub const TransactionByteFee: Balance = 10 * MICRO;
// setting this to zero will disable the weight fee.
pub const WeightFeeCoefficient: Balance = 1_000;
Expand Down Expand Up @@ -290,15 +289,15 @@ impl finality_tracker::Trait for Runtime {
}

parameter_types! {
pub const ContractTransferFee: Balance = 1 * MILLI;
pub const ContractCreationFee: Balance = 1 * MILLI;
pub const ContractTransactionBaseFee: Balance = 1 * MILLI;
pub const ContractTransferFee: Balance = 1 * MICRO;
pub const ContractCreationFee: Balance = 1 * MICRO;
pub const ContractTransactionBaseFee: Balance = 1 * MICRO;
pub const ContractTransactionByteFee: Balance = 10 * MICRO;
pub const ContractFee: Balance = 1 * MILLI;
pub const TombstoneDeposit: Balance = 1 * MILLICENTS;
pub const RentByteFee: Balance = 1 * MILLICENTS;
pub const RentDepositOffset: Balance = 1000 * MILLICENTS;
pub const SurchargeReward: Balance = 150 * MILLICENTS;
pub const ContractFee: Balance = 1 * MICRO;
pub const TombstoneDeposit: Balance = 1 * COIN;
pub const RentByteFee: Balance = 1 * COIN;
pub const RentDepositOffset: Balance = 1000 * COIN;
pub const SurchargeReward: Balance = 150 * COIN;
}
impl contracts::Trait for Runtime {
type Currency = Balances;
Expand Down Expand Up @@ -375,7 +374,7 @@ parameter_types! {
// 365 days * 24 hours * 60 minutes / 5 minutes
pub const ErasPerEpoch: EraIndex = 105120;
// decimal 9
pub const HardCap: Balance = 10_000_000_000 * MILLICENTS;
pub const HardCap: Balance = 10_000_000_000 * COIN;
pub const GenesisTime: Moment = 1_574_156_000_000;
}
impl staking::Trait for Runtime {
Expand Down
6 changes: 3 additions & 3 deletions srml/kton/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use node_runtime::constants::currency::MILLICENTS;
pub use node_runtime::constants::currency::COIN;

use std::{cell::RefCell, collections::HashSet};

Expand Down Expand Up @@ -100,9 +100,9 @@ impl ExtBuilder {
self.set_associated_consts();
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
let balance_factor = if self.existential_deposit > 0 {
1_000 * MILLICENTS
1_000 * COIN
} else {
1 * MILLICENTS
1 * COIN
};

let _ = GenesisConfig::<Test> {
Expand Down
14 changes: 7 additions & 7 deletions srml/staking/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use node_runtime::constants::currency::MILLICENTS;
pub use node_runtime::constants::currency::COIN;

use std::{cell::RefCell, collections::HashSet};

Expand Down Expand Up @@ -187,7 +187,7 @@ parameter_types! {
}
parameter_types! {
// decimal 9
pub const CAP: Balance = 10_000_000_000 * MILLICENTS;
pub const CAP: Balance = 10_000_000_000 * COIN;
}
impl Trait for Test {
type Ring = Ring;
Expand Down Expand Up @@ -270,9 +270,9 @@ impl ExtBuilder {
self.set_associated_consts();
let mut storage = system::GenesisConfig::default().build_storage::<Test>().unwrap();
let balance_factor = if self.existential_deposit > 0 {
1_000 * MILLICENTS
1_000 * COIN
} else {
1 * MILLICENTS
1 * COIN
};
let validators = if self.validator_pool {
vec![10, 20, 30, 40]
Expand Down Expand Up @@ -322,10 +322,10 @@ impl ExtBuilder {
let nominated = if self.nominate { vec![11, 21] } else { vec![] };
let _ = GenesisConfig::<Test> {
current_era: self.current_era,
// current_era_total_reward: 80_000_000 * MILLICENTS / ErasPerEpoch::get() as u64,
// current_era_total_reward: 80_000_000 * COIN / ErasPerEpoch::get() as u64,
stakers: vec![
// (2, 1, 1 * MILLICENTS, StakerStatus::<AccountId>::Validator),
(11, 10, 100 * MILLICENTS, StakerStatus::<AccountId>::Validator),
// (2, 1, 1 * COIN, StakerStatus::<AccountId>::Validator),
(11, 10, 100 * COIN, StakerStatus::<AccountId>::Validator),
(21, 20, stake_21, StakerStatus::<AccountId>::Validator),
(31, 30, stake_31, StakerStatus::<AccountId>::Validator),
(41, 40, balance_factor * 1000, status_41),
Expand Down
Loading

0 comments on commit 9f80a33

Please sign in to comment.