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
6 changes: 4 additions & 2 deletions node/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ use sp_runtime::{
};

mod bridge;
mod currency;
pub mod currency;
mod salp;
mod tests;
pub mod traits;
mod xcm;
pub use salp::*;

#[cfg(test)]
mod tests;

pub use crate::{
bridge::*,
currency::{CurrencyId, TokenSymbol},
Expand Down
11 changes: 6 additions & 5 deletions node/service/src/chain_spec/asgard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use asgard_runtime::{
constants::{currency::DOLLARS, time::DAYS},
AccountId, AuraId, Balance, BalancesConfig, BancorConfig, BlockNumber, CollatorSelectionConfig,
CouncilConfig, DemocracyConfig, GenesisConfig, IndicesConfig, MinterRewardConfig,
ParachainInfoConfig, PolkadotXcmConfig, SessionConfig, SudoConfig, SystemConfig,
TechnicalCommitteeConfig, TokensConfig, VestingConfig, VtokenMintConfig, WASM_BINARY,
constants::currency::DOLLARS, AccountId, AuraId, Balance, BalancesConfig, BancorConfig,
BlockNumber, CollatorSelectionConfig, CouncilConfig, DemocracyConfig, GenesisConfig,
IndicesConfig, MinterRewardConfig, ParachainInfoConfig, PolkadotXcmConfig, SessionConfig,
SudoConfig, SystemConfig, TechnicalCommitteeConfig, TokensConfig, VestingConfig,
VtokenMintConfig, WASM_BINARY,
};
use bifrost_runtime_common::constants::time::*;
use cumulus_primitives_core::ParaId;
use frame_benchmarking::{account, whitelisted_caller};
use hex_literal::hex;
Expand Down
51 changes: 29 additions & 22 deletions node/service/src/chain_spec/bifrost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ use std::{
};

use bifrost_runtime::{
constants::currency::DOLLARS, AccountId, AuraId, Balance, BalancesConfig, BlockNumber,
CollatorSelectionConfig, CouncilConfig, CouncilMembershipConfig, DemocracyConfig,
GenesisConfig, IndicesConfig, ParachainInfoConfig, PolkadotXcmConfig, SessionConfig,
SystemConfig, TechnicalCommitteeConfig, TechnicalMembershipConfig, TokensConfig, VestingConfig,
WASM_BINARY,
AccountId, AuraId, Balance, BalancesConfig, BlockNumber, CollatorSelectionConfig,
CouncilConfig, CouncilMembershipConfig, DemocracyConfig, GenesisConfig, IndicesConfig,
ParachainInfoConfig, PolkadotXcmConfig, SessionConfig, SystemConfig, TechnicalCommitteeConfig,
TechnicalMembershipConfig, TokensConfig, VestingConfig, WASM_BINARY,
};
use bifrost_runtime_common::dollar;
use cumulus_primitives_core::ParaId;
use frame_benchmarking::{account, whitelisted_caller};
use hex_literal::hex;
Expand All @@ -47,7 +47,10 @@ const DEFAULT_PROTOCOL_ID: &str = "bifrost";
/// Specialized `ChainSpec` for the bifrost runtime.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig, RelayExtensions>;

const ENDOWMENT: u128 = 1_000_000 * DOLLARS;
#[allow(non_snake_case)]
pub fn ENDOWMENT() -> u128 {
1_000_000 * dollar(CurrencyId::Token(TokenSymbol::BNC))
}

pub fn bifrost_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
Expand Down Expand Up @@ -114,21 +117,21 @@ fn development_config_genesis(id: ParaId) -> GenesisConfig {
get_account_id_from_seed::<sr25519::Public>("Alice"),
whitelisted_caller(), // Benchmarking whitelist_account
];
let balances = endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect();
let balances = endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT())).collect();
let vestings = endowed_accounts
.iter()
.cloned()
.map(|x| (x.clone(), 0u32, 100u32, ENDOWMENT / 4))
.map(|x| (x.clone(), 0u32, 100u32, ENDOWMENT() / 4))
.collect();
let tokens = endowed_accounts
.iter()
.flat_map(|x| {
vec![
(x.clone(), CurrencyId::Stable(TokenSymbol::KUSD), ENDOWMENT * 10_000),
(x.clone(), CurrencyId::Token(TokenSymbol::KAR), ENDOWMENT * 10_000),
(x.clone(), CurrencyId::Token(TokenSymbol::KSM), ENDOWMENT),
(x.clone(), CurrencyId::Token(TokenSymbol::DOT), ENDOWMENT),
(x.clone(), CurrencyId::VSToken(TokenSymbol::DOT), ENDOWMENT),
(x.clone(), CurrencyId::Stable(TokenSymbol::KUSD), ENDOWMENT() * 10_000),
(x.clone(), CurrencyId::Token(TokenSymbol::KAR), ENDOWMENT() * 10_000),
(x.clone(), CurrencyId::Token(TokenSymbol::KSM), ENDOWMENT()),
(x.clone(), CurrencyId::Token(TokenSymbol::DOT), ENDOWMENT()),
(x.clone(), CurrencyId::VSToken(TokenSymbol::DOT), ENDOWMENT()),
]
})
.collect();
Expand Down Expand Up @@ -182,29 +185,29 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig {
account("bechmarking_account_1", 0, 0), /* Benchmarking account_1, used for interacting
* with whitelistted_caller */
];
let balances = endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect();
let balances = endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT())).collect();
let vestings = endowed_accounts
.iter()
.cloned()
.map(|x| (x.clone(), 0u32, 100u32, ENDOWMENT / 4))
.map(|x| (x.clone(), 0u32, 100u32, ENDOWMENT() / 4))
.collect();
let tokens = endowed_accounts
.iter()
.flat_map(|x| {
vec![
(x.clone(), CurrencyId::Stable(TokenSymbol::KUSD), ENDOWMENT * 10_000),
(x.clone(), CurrencyId::Token(TokenSymbol::KAR), ENDOWMENT * 10_000),
(x.clone(), CurrencyId::Token(TokenSymbol::KSM), ENDOWMENT * 4_000_000),
(x.clone(), CurrencyId::VSToken(TokenSymbol::KSM), ENDOWMENT * 4_000_000),
(x.clone(), CurrencyId::Stable(TokenSymbol::KUSD), ENDOWMENT() * 10_000),
(x.clone(), CurrencyId::Token(TokenSymbol::KAR), ENDOWMENT() * 10_000),
(x.clone(), CurrencyId::Token(TokenSymbol::KSM), ENDOWMENT() * 4_000_000),
(x.clone(), CurrencyId::VSToken(TokenSymbol::KSM), ENDOWMENT() * 4_000_000),
(
x.clone(),
CurrencyId::VSBond(TokenSymbol::KSM, 3000, 13, 20),
ENDOWMENT * 4_000_000,
ENDOWMENT() * 4_000_000,
),
(
x.clone(),
CurrencyId::VSBond(TokenSymbol::BNC, 2001, 13, 20),
ENDOWMENT * 4_000_000,
ENDOWMENT() * 4_000_000,
),
]
})
Expand Down Expand Up @@ -321,7 +324,11 @@ fn bifrost_config_genesis(id: ParaId) -> GenesisConfig {
.into_iter()
.collect();

assert_eq!(total_issuance, 32_000_000 * DOLLARS, "total issuance must be equal to 320 million");
assert_eq!(
total_issuance,
32_000_000 * dollar(CurrencyId::Token(TokenSymbol::BNC)),
"total issuance must be equal to 320 million"
);

let vesting_configs: Vec<VestingConfig> =
config_from_json_files(exe_dir.join("res/genesis_config/vesting")).unwrap();
Expand Down
51 changes: 3 additions & 48 deletions runtime/asgard/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub mod currency {
use smallvec::smallvec;
pub use sp_runtime::Perbill;

pub const BNCS: Balance = 1_000_000_000_000;
pub const DOLLARS: Balance = BNCS;
pub const ASGS: Balance = 1_000_000_000_000;
pub const DOLLARS: Balance = ASGS;
pub const CENTS: Balance = DOLLARS / 100; // assume this is worth about a cent.
pub const RELAY_CENTS: Balance = DOLLARS / 30_000;
pub const MILLICENTS: Balance = CENTS / 1_000;
Expand Down Expand Up @@ -69,49 +69,4 @@ pub mod currency {
}

/// Time.
pub mod time {
use node_primitives::{BlockNumber, Moment};

/// Since BABE is probabilistic this is the average expected block time that
/// we are targetting. Blocks will be produced at a minimum duration defined
/// by `SLOT_DURATION`, but some slots will not be allocated to any
/// authority and hence no block will be produced. We expect to have this
/// block time on average following the defined slot duration and the value
/// of `c` configured for BABE (where `1 - c` represents the probability of
/// a slot being empty).
/// This value is only used indirectly to define the unit constants below
/// that are expressed in blocks. The rest of the code should use
/// `SLOT_DURATION` instead (like the Timestamp pallet for calculating the
/// minimum period).
///
/// If using BABE with secondary slots (default) then all of the slots will
/// always be assigned, in which case `MILLISECS_PER_BLOCK` and
/// `SLOT_DURATION` should have the same value.
///
/// <https://research.web3.foundation/en/latest/polkadot/block-production/Babe.html#-6.-practical-results>
pub const MILLISECS_PER_BLOCK: Moment = 12000;
pub const SECS_PER_BLOCK: Moment = MILLISECS_PER_BLOCK / 1000;

pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;

// 1 in 4 blocks (on average, not counting collisions) will be primary BABE blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);

pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 10 * MINUTES;
pub const EPOCH_DURATION_IN_SLOTS: u64 = {
const SLOT_FILL_RATE: f64 = MILLISECS_PER_BLOCK as f64 / SLOT_DURATION as f64;

(EPOCH_DURATION_IN_BLOCKS as f64 * SLOT_FILL_RATE) as u64
};

// These time units are defined in number of blocks.
pub const MINUTES: BlockNumber = 60 / (SECS_PER_BLOCK as BlockNumber);
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;
pub const WEEKS: BlockNumber = DAYS * 7;

// The `LeasePeriod` defination from `polkadot`.
pub const KUSAMA_LEASE_PERIOD: BlockNumber = 6 * WEEKS;
pub const ROCOCO_LEASE_PERIOD: BlockNumber = 1 * DAYS;
pub const WESTEND_LEASE_PERIOD: BlockNumber = 28 * DAYS;
}
pub mod time {}
35 changes: 18 additions & 17 deletions runtime/asgard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,18 @@ use bifrost_flexible_fee::{
misc_fees::{ExtraFeeMatcher, MiscFeeHandler, NameGetter},
};
use bifrost_runtime_common::{
constants::parachains,
xcm_impl::{
cent,
constants::{parachains, time::*},
dollar, micro, milli, millicent,
r#impl::{
BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert,
BifrostFilteredAssets,
},
CouncilCollective, EnsureRootOrAllTechnicalCommittee, MoreThanHalfCouncil,
SlowAdjustingFeeUpdate, TechnicalCollective,
};
use codec::{Decode, Encode, MaxEncodedLen};
use constants::{currency::*, time::*};
use constants::currency::*;
use cumulus_primitives_core::ParaId as CumulusParaId;
use frame_support::{
sp_runtime::traits::Convert,
Expand Down Expand Up @@ -1112,19 +1114,18 @@ impl orml_currencies::Config for Runtime {
orml_traits::parameter_type_with_key! {
pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
match currency_id {
&CurrencyId::Native(TokenSymbol::ASG) => 10 * MILLIBNC, // 0.01 BNC
&CurrencyId::Stable(TokenSymbol::KUSD) => 10 * MILLICENTS,
&CurrencyId::Token(TokenSymbol::KSM) => 10 * MILLICENTS, // 0.0001 KSM
&CurrencyId::Token(TokenSymbol::KAR) => 10 * MILLICENTS,
&CurrencyId::Token(TokenSymbol::DOT) => 100_000_000, // DOT has a decimals of 10e10, 0.01 DOT
&CurrencyId::Token(TokenSymbol::ZLK) => 1_000_000_000_000, // ZLK has a decimals of 10e18
&CurrencyId::VSToken(TokenSymbol::KSM) => 10 * MILLICENTS,
&CurrencyId::VSToken(TokenSymbol::DOT) => 100_000_000,
&CurrencyId::VSBond(TokenSymbol::ASG, ..) => 10 * MILLICENTS,
&CurrencyId::VSBond(TokenSymbol::KSM, ..) => 10 * MILLICENTS,
&CurrencyId::VSBond(TokenSymbol::BNC, ..) => 10 * MILLICENTS,
&CurrencyId::VSBond(TokenSymbol::DOT, ..) => 100_000_000,
&CurrencyId::LPToken(..) => 10 * MILLICENTS,
&CurrencyId::Native(TokenSymbol::BNC) => 10 * milli(NativeCurrencyId::get()), // 0.01 BNC
&CurrencyId::Stable(TokenSymbol::KUSD) => 10 * millicent(StableCurrencyId::get()),
&CurrencyId::Token(TokenSymbol::KSM) => 10 * millicent(RelayCurrencyId::get()), // 0.0001 KSM
&CurrencyId::Token(TokenSymbol::KAR) => 10 * millicent(CurrencyId::Token(TokenSymbol::KAR)),
&CurrencyId::Token(TokenSymbol::DOT) => 1 * cent(PolkadotCurrencyId::get()), // DOT has a decimals of 10e10, 0.01 DOT
&CurrencyId::Token(TokenSymbol::ZLK) => 1 * micro(CurrencyId::Token(TokenSymbol::ZLK)), // ZLK has a decimals of 10e18
&CurrencyId::VSToken(TokenSymbol::KSM) => 10 * millicent(RelayCurrencyId::get()),
&CurrencyId::VSToken(TokenSymbol::DOT) => 1 * cent(PolkadotCurrencyId::get()),
&CurrencyId::VSBond(TokenSymbol::BNC, ..) => 10 * millicent(NativeCurrencyId::get()),
&CurrencyId::VSBond(TokenSymbol::KSM, ..) => 10 * millicent(RelayCurrencyId::get()),
&CurrencyId::VSBond(TokenSymbol::DOT, ..) => 1 * cent(PolkadotCurrencyId::get()),
&CurrencyId::LPToken(..) => 10 * millicent(NativeCurrencyId::get()),
_ => Balance::max_value() // unsupported
}
};
Expand Down Expand Up @@ -1412,7 +1413,7 @@ impl bifrost_vsbond_auction::Config for Runtime {
parameter_types! {
pub const RelayChainTokenSymbol: TokenSymbol = TokenSymbol::KSM;
pub const RelayChainTokenSymbolDOT: TokenSymbol = TokenSymbol::DOT;
pub const MaximumDepositInPool: Balance = 1_000_000_000 * DOLLARS;
pub MaximumDepositInPool: Balance = 1_000_000_000 * dollar(NativeCurrencyId::get());
pub const MinimumDepositOfUser: Balance = 1_000_000;
pub const MinimumRewardPerBlock: Balance = 1_000;
pub const MinimumDuration: BlockNumber = HOURS;
Expand Down
89 changes: 28 additions & 61 deletions runtime/bifrost/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,42 @@

/// Money matters.
pub mod currency {
use bifrost_runtime_common::{cent, dollar};
use frame_support::weights::{
constants::{ExtrinsicBaseWeight, WEIGHT_PER_SECOND},
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
};
use node_primitives::Balance;
use node_primitives::{Balance, CurrencyId, TokenSymbol};
use smallvec::smallvec;
pub use sp_runtime::Perbill;

pub const BNCS: Balance = 1_000_000_000_000;
pub const DOLLARS: Balance = BNCS;
pub const CENTS: Balance = DOLLARS / 100; // assume this is worth about a cent.
pub const RELAY_CENTS: Balance = DOLLARS / 10_000;
pub const MILLICENTS: Balance = CENTS / 1_000;
pub const MILLIBNC: Balance = 1_000_000_000;
pub const MICROBNC: Balance = 1_000_000;
pub const XCM_WEIGHT: u64 = 1_000_000_000;
pub fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 15 * cent(CurrencyId::Token(TokenSymbol::BNC)) +
(bytes as Balance) * 6 * cent(CurrencyId::Token(TokenSymbol::BNC))
}

pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS
pub struct KsmWeightToFee;
impl WeightToFeePolynomial for KsmWeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
let p = ksm_base_tx_fee();
let q = 10 * Balance::from(ExtrinsicBaseWeight::get());
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q,
}]
}
}

pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
let p = super::currency::RELAY_CENTS;
let q = 10 * Balance::from(ExtrinsicBaseWeight::get());
// extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
let p = base_tx_fee();
let q = Balance::from(ExtrinsicBaseWeight::get());
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
Expand All @@ -56,8 +65,12 @@ pub mod currency {
}
}

fn ksm_base_tx_fee() -> Balance {
dollar(CurrencyId::Token(TokenSymbol::KSM)) / 10_000
}

fn base_tx_fee() -> Balance {
CENTS / 10
cent(CurrencyId::Token(TokenSymbol::BNC)) / 5
}

pub fn ksm_per_second() -> u128 {
Expand All @@ -69,50 +82,4 @@ pub mod currency {
}

/// Time.
pub mod time {
use node_primitives::{BlockNumber, Moment};

/// Since BABE is probabilistic this is the average expected block time that
/// we are targetting. Blocks will be produced at a minimum duration defined
/// by `SLOT_DURATION`, but some slots will not be allocated to any
/// authority and hence no block will be produced. We expect to have this
/// block time on average following the defined slot duration and the value
/// of `c` configured for BABE (where `1 - c` represents the probability of
/// a slot being empty).
/// This value is only used indirectly to define the unit constants below
/// that are expressed in blocks. The rest of the code should use
/// `SLOT_DURATION` instead (like the Timestamp pallet for calculating the
/// minimum period).
///
/// If using BABE with secondary slots (default) then all of the slots will
/// always be assigned, in which case `MILLISECS_PER_BLOCK` and
/// `SLOT_DURATION` should have the same value.
///
/// <https://research.web3.foundation/en/latest/polkadot/block-production/Babe.html#-6.-practical-results>
pub const MILLISECS_PER_BLOCK: Moment = 12000;
pub const SECS_PER_BLOCK: Moment = MILLISECS_PER_BLOCK / 1000;

pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;

// 1 in 4 blocks (on average, not counting collisions) will be primary BABE blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);

pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 6 * HOURS;
pub const EPOCH_DURATION_IN_SLOTS: u64 = {
const SLOT_FILL_RATE: f64 = MILLISECS_PER_BLOCK as f64 / SLOT_DURATION as f64;

(EPOCH_DURATION_IN_BLOCKS as f64 * SLOT_FILL_RATE) as u64
};

// These time units are defined in number of blocks.
pub const MINUTES: BlockNumber = 60 / (SECS_PER_BLOCK as BlockNumber);
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;
pub const WEEKS: BlockNumber = DAYS * 7;

// The `LeasePeriod` defination from `polkadot`.
pub const POLKA_LEASE_PERIOD: BlockNumber = 12 * WEEKS;
pub const KUSAMA_LEASE_PERIOD: BlockNumber = 6 * WEEKS;
pub const ROCOCO_LEASE_PERIOD: BlockNumber = 1 * DAYS;
pub const WESTEND_LEASE_PERIOD: BlockNumber = 28 * DAYS;
}
pub mod time {}
Loading