Skip to content

Commit

Permalink
Replace any calculations in fiat with base economic unit
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx committed Sep 15, 2023
1 parent f469f62 commit 2b35c88
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 72 deletions.
6 changes: 3 additions & 3 deletions node/service/src/chain_spec/vara.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_core::{crypto::UncheckedInto, sr25519};
use sp_runtime::{Perbill, Perquintill};
use vara_runtime::{
constants::currency::{DOLLARS, EXISTENTIAL_DEPOSIT, UNITS as TOKEN},
constants::currency::{ECONOMIC_UNIT, EXISTENTIAL_DEPOSIT, UNITS as TOKEN},
AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, GenesisConfig, GrandpaConfig,
ImOnlineConfig, NominationPoolsConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig,
StakingRewardsConfig, SudoConfig, SystemConfig, VestingConfig, WASM_BINARY,
Expand Down Expand Up @@ -617,8 +617,8 @@ fn testnet_genesis(
transaction_payment: Default::default(),
treasury: Default::default(),
nomination_pools: NominationPoolsConfig {
min_create_bond: 10 * DOLLARS,
min_join_bond: DOLLARS,
min_create_bond: 10 * ECONOMIC_UNIT,
min_join_bond: ECONOMIC_UNIT,
..Default::default()
},
vesting: VestingConfig { vesting: vec![] },
Expand Down
44 changes: 27 additions & 17 deletions node/testing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ pub fn genesis_config(code: Option<&[u8]>) -> GenesisConfig {
#[cfg(feature = "vara-native")]
pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> GenesisConfig {
let mut endowed = vec![
(alice(), 111 * DOLLARS),
(bob(), 100 * DOLLARS),
(charlie(), 100_000_000 * DOLLARS),
(dave(), 111 * DOLLARS),
(eve(), 101 * DOLLARS),
(ferdie(), 100 * DOLLARS),
(alice(), 111 * ECONOMIC_UNIT),
(bob(), 100 * ECONOMIC_UNIT),
(charlie(), 100_000_000 * ECONOMIC_UNIT),
(dave(), 111 * ECONOMIC_UNIT),
(eve(), 101 * ECONOMIC_UNIT),
(ferdie(), 100 * ECONOMIC_UNIT),
];

endowed.extend(
extra_endowed
.into_iter()
.map(|endowed| (endowed, 100 * DOLLARS)),
.map(|endowed| (endowed, 100 * ECONOMIC_UNIT)),
);

GenesisConfig {
Expand Down Expand Up @@ -98,9 +98,19 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Gen
},
staking: StakingConfig {
stakers: vec![
(dave(), alice(), 111 * DOLLARS, StakerStatus::Validator),
(eve(), bob(), 100 * DOLLARS, StakerStatus::Validator),
(ferdie(), charlie(), 100 * DOLLARS, StakerStatus::Validator),
(
dave(),
alice(),
111 * ECONOMIC_UNIT,
StakerStatus::Validator,
),
(eve(), bob(), 100 * ECONOMIC_UNIT, StakerStatus::Validator),
(
ferdie(),
charlie(),
100 * ECONOMIC_UNIT,
StakerStatus::Validator,
),
],
validator_count: 3,
minimum_validator_count: 3,
Expand Down Expand Up @@ -128,18 +138,18 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Gen
#[cfg(all(not(feature = "vara-native"), feature = "gear-native"))]
pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> GenesisConfig {
let mut endowed = vec![
(alice(), 111 * DOLLARS),
(bob(), 100 * DOLLARS),
(charlie(), 100_000_000 * DOLLARS),
(dave(), 111 * DOLLARS),
(eve(), 101 * DOLLARS),
(ferdie(), 100 * DOLLARS),
(alice(), 111 * ECONOMIC_UNIT),
(bob(), 100 * ECONOMIC_UNIT),
(charlie(), 100_000_000 * ECONOMIC_UNIT),
(dave(), 111 * ECONOMIC_UNIT),
(eve(), 101 * ECONOMIC_UNIT),
(ferdie(), 100 * ECONOMIC_UNIT),
];

endowed.extend(
extra_endowed
.into_iter()
.map(|endowed| (endowed, 100 * DOLLARS)),
.map(|endowed| (endowed, 100 * ECONOMIC_UNIT)),
);

GenesisConfig {
Expand Down
7 changes: 2 additions & 5 deletions pallets/staking-rewards/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@ pub(crate) const NOM_1_CONTROLLER: AccountId = 41;
pub(crate) const ROOT: AccountId = 101;

pub(crate) const INITIAL_TOTAL_TOKEN_SUPPLY: u128 = 1_000_000 * UNITS;
pub(crate) const EXISTENTIAL_DEPOSIT: u128 = 10 * MILLICENTS; // 10
pub(crate) const EXISTENTIAL_DEPOSIT: u128 = 10 * UNITS / 100_000; // 10
pub(crate) const VALIDATOR_STAKE: u128 = 100 * UNITS; // 10
pub(crate) const ENDOWMENT: u128 = 100 * UNITS;

pub(crate) const UNITS: u128 = 100_000; // 10^(-5) precision
pub(crate) const DOLLARS: u128 = UNITS; // 1 to 1
pub(crate) const CENTS: u128 = DOLLARS / 100; // 1_000
pub(crate) const MILLICENTS: u128 = CENTS / 1_000; // 1
pub(crate) const MILLISECONDS_PER_YEAR: u64 = 1_000 * 3_600 * 24 * 36_525 / 100;
pub(crate) const MILLISECS_PER_BLOCK: u64 = 2_400;
pub(crate) const SESSION_DURATION: u64 = 1000;
Expand Down Expand Up @@ -394,7 +391,7 @@ impl pallet_bags_list::Config<pallet_bags_list::Instance1> for Test {

parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: u128 = DOLLARS;
pub const ProposalBondMinimum: u128 = UNITS;
pub const SpendPeriod: u32 = 100;
pub const Burn: Permill = Permill::from_percent(50);
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
Expand Down
1 change: 0 additions & 1 deletion runtime/gear/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub mod currency {
use runtime_primitives::Balance;

pub const UNITS: Balance = 1_000_000_000_000; // 10^(-12) precision
pub const DOLLARS: Balance = UNITS * 50; // Theoretical cost ~$0.02

/// The existential deposit.
pub const EXISTENTIAL_DEPOSIT: Balance = 500;
Expand Down
9 changes: 5 additions & 4 deletions runtime/vara/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ pub mod currency {
use runtime_primitives::Balance;

pub const UNITS: Balance = 1_000_000_000_000; // 10^(-12) precision
pub const DOLLARS: Balance = UNITS * 50; // Theoretical cost ~$0.02
pub const CENTS: Balance = DOLLARS / 100; // 500_000_000_000
pub const MILLICENTS: Balance = CENTS / 1_000; // 500_000_000

/// Base economic unit, 50 Vara.
pub const ECONOMIC_UNIT: Balance = UNITS * 50;
pub const ECONOMIC_CENTIUNIT: Balance = ECONOMIC_UNIT / 100;

/// The existential deposit.
pub const EXISTENTIAL_DEPOSIT: Balance = 10 * UNITS; // 10 Vara
Expand All @@ -34,7 +35,7 @@ pub mod currency {
/// Helper function to calculate various deposits for using pallets' storage
pub const fn deposit(items: u32, bytes: u32) -> Balance {
// TODO: review numbers (#2650)
items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS
items as Balance * 15 * ECONOMIC_CENTIUNIT + (bytes as Balance) * 6 * ECONOMIC_CENTIUNIT
}
}

Expand Down
22 changes: 11 additions & 11 deletions runtime/vara/src/governance/fellowship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use sp_runtime::{
};

use super::*;
use crate::{DAYS, DOLLARS};
use crate::{DAYS, ECONOMIC_UNIT};

parameter_types! {
pub const AlarmInterval: BlockNumber = 1;
Expand All @@ -49,7 +49,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
pallet_referenda::TrackInfo {
name: "candidates",
max_deciding: 10,
decision_deposit: 100 * DOLLARS,
decision_deposit: 100 * ECONOMIC_UNIT,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
Expand All @@ -71,7 +71,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
pallet_referenda::TrackInfo {
name: "members",
max_deciding: 10,
decision_deposit: 10 * DOLLARS,
decision_deposit: 10 * ECONOMIC_UNIT,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
Expand All @@ -93,7 +93,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
pallet_referenda::TrackInfo {
name: "proficients",
max_deciding: 10,
decision_deposit: 10 * DOLLARS,
decision_deposit: 10 * ECONOMIC_UNIT,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
Expand All @@ -115,7 +115,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
pallet_referenda::TrackInfo {
name: "fellows",
max_deciding: 10,
decision_deposit: 10 * DOLLARS,
decision_deposit: 10 * ECONOMIC_UNIT,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
Expand All @@ -137,7 +137,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
pallet_referenda::TrackInfo {
name: "senior fellows",
max_deciding: 10,
decision_deposit: 10 * DOLLARS,
decision_deposit: 10 * ECONOMIC_UNIT,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
Expand All @@ -159,7 +159,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
pallet_referenda::TrackInfo {
name: "experts",
max_deciding: 10,
decision_deposit: 1 * DOLLARS,
decision_deposit: 1 * ECONOMIC_UNIT,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
Expand All @@ -181,7 +181,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
pallet_referenda::TrackInfo {
name: "senior experts",
max_deciding: 10,
decision_deposit: 1 * DOLLARS,
decision_deposit: 1 * ECONOMIC_UNIT,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
Expand All @@ -203,7 +203,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
pallet_referenda::TrackInfo {
name: "masters",
max_deciding: 10,
decision_deposit: 1 * DOLLARS,
decision_deposit: 1 * ECONOMIC_UNIT,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
Expand All @@ -225,7 +225,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
pallet_referenda::TrackInfo {
name: "senior masters",
max_deciding: 10,
decision_deposit: 1 * DOLLARS,
decision_deposit: 1 * ECONOMIC_UNIT,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
Expand All @@ -247,7 +247,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
pallet_referenda::TrackInfo {
name: "grand masters",
max_deciding: 10,
decision_deposit: 1 * DOLLARS,
decision_deposit: 1 * ECONOMIC_UNIT,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
Expand Down
2 changes: 1 addition & 1 deletion runtime/vara/src/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl pallet_conviction_voting::Config for Runtime {

parameter_types! {
pub const AlarmInterval: BlockNumber = 1;
pub const SubmissionDeposit: Balance = 10 * DOLLARS;
pub const SubmissionDeposit: Balance = 10 * ECONOMIC_UNIT;
pub const UndecidingTimeout: BlockNumber = 14 * DAYS;
}

Expand Down
26 changes: 13 additions & 13 deletions runtime/vara/src/governance/tracks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 13
pallet_referenda::TrackInfo {
name: "root",
max_deciding: 1,
decision_deposit: 100_000 * DOLLARS,
decision_deposit: 100_000 * ECONOMIC_UNIT,
prepare_period: 2 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 24 * HOURS,
Expand All @@ -81,7 +81,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 13
pallet_referenda::TrackInfo {
name: "whitelisted_caller",
max_deciding: 100,
decision_deposit: 10_000 * DOLLARS,
decision_deposit: 10_000 * ECONOMIC_UNIT,
prepare_period: 30 * MINUTES,
decision_period: 14 * DAYS,
confirm_period: 10 * MINUTES,
Expand All @@ -95,7 +95,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 13
pallet_referenda::TrackInfo {
name: "staking_admin",
max_deciding: 10,
decision_deposit: 5_000 * DOLLARS,
decision_deposit: 5_000 * ECONOMIC_UNIT,
prepare_period: 2 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 3 * HOURS,
Expand All @@ -109,7 +109,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 13
pallet_referenda::TrackInfo {
name: "treasurer",
max_deciding: 10,
decision_deposit: 1_000 * DOLLARS,
decision_deposit: 1_000 * ECONOMIC_UNIT,
prepare_period: 2 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 3 * HOURS,
Expand All @@ -123,7 +123,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 13
pallet_referenda::TrackInfo {
name: "fellowship_admin",
max_deciding: 10,
decision_deposit: 5_000 * DOLLARS,
decision_deposit: 5_000 * ECONOMIC_UNIT,
prepare_period: 2 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 3 * HOURS,
Expand All @@ -137,7 +137,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 13
pallet_referenda::TrackInfo {
name: "general_admin",
max_deciding: 10,
decision_deposit: 5_000 * DOLLARS,
decision_deposit: 5_000 * ECONOMIC_UNIT,
prepare_period: 2 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 3 * HOURS,
Expand All @@ -151,7 +151,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 13
pallet_referenda::TrackInfo {
name: "referendum_canceller",
max_deciding: 1_000,
decision_deposit: 10_000 * DOLLARS,
decision_deposit: 10_000 * ECONOMIC_UNIT,
prepare_period: 2 * HOURS,
decision_period: 7 * DAYS,
confirm_period: 3 * HOURS,
Expand All @@ -165,7 +165,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 13
pallet_referenda::TrackInfo {
name: "referendum_killer",
max_deciding: 1_000,
decision_deposit: 50_000 * DOLLARS,
decision_deposit: 50_000 * ECONOMIC_UNIT,
prepare_period: 2 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 3 * HOURS,
Expand All @@ -179,7 +179,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 13
pallet_referenda::TrackInfo {
name: "small_tipper",
max_deciding: 200,
decision_deposit: DOLLARS,
decision_deposit: ECONOMIC_UNIT,
prepare_period: MINUTES,
decision_period: 7 * DAYS,
confirm_period: 10 * MINUTES,
Expand All @@ -193,7 +193,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 13
pallet_referenda::TrackInfo {
name: "big_tipper",
max_deciding: 100,
decision_deposit: 10 * DOLLARS,
decision_deposit: 10 * ECONOMIC_UNIT,
prepare_period: 10 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: HOURS,
Expand All @@ -207,7 +207,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 13
pallet_referenda::TrackInfo {
name: "small_spender",
max_deciding: 50,
decision_deposit: 100 * DOLLARS,
decision_deposit: 100 * ECONOMIC_UNIT,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 12 * HOURS,
Expand All @@ -221,7 +221,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 13
pallet_referenda::TrackInfo {
name: "medium_spender",
max_deciding: 50,
decision_deposit: 200 * DOLLARS,
decision_deposit: 200 * ECONOMIC_UNIT,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 24 * HOURS,
Expand All @@ -235,7 +235,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 13
pallet_referenda::TrackInfo {
name: "big_spender",
max_deciding: 50,
decision_deposit: 400 * DOLLARS,
decision_deposit: 400 * ECONOMIC_UNIT,
prepare_period: 4 * HOURS,
decision_period: 14 * DAYS,
confirm_period: 48 * HOURS,
Expand Down
Loading

0 comments on commit 2b35c88

Please sign in to comment.