Skip to content

Commit

Permalink
Split KMA and MA currency (#225)
Browse files Browse the repository at this point in the history
* Split KMA and MA currency

* Add CHANGELOG line
  • Loading branch information
tommyjk21 committed Oct 21, 2021
1 parent 0e4524b commit 13b60c9
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 69 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

### Features
- [Support XCM V2](https://github.com/paritytech/polkadot/pull/3629)
- Split KMA and MA currencies into 18 decimal precision and 12 decimal precision

### Improvements
- [Follow Rework Transaction Priority calculation](https://github.com/paritytech/substrate/pull/9834)
Expand Down
4 changes: 2 additions & 2 deletions node/src/chain_specs/calamari_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn calamari_dev_genesis(
.map(|k| {
(
k.clone(),
100 * ENDOWMENT / ((endowed_accounts.len() / 2) as Balance),
100 * CALAMARI_ENDOWMENT / ((endowed_accounts.len() / 2) as Balance),
)
})
.collect(),
Expand All @@ -156,7 +156,7 @@ fn calamari_dev_genesis(
parachain_info: calamari_runtime::ParachainInfoConfig { parachain_id: id },
collator_selection: calamari_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: MA * 1000, // How many tokens will be reserved as collator
candidacy_bond: KMA * 1000, // How many tokens will be reserved as collator
..Default::default()
},
session: calamari_runtime::SessionConfig {
Expand Down
4 changes: 2 additions & 2 deletions node/src/chain_specs/manta_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn manta_pc_dev_genesis(
.map(|k| {
(
k.clone(),
10 * ENDOWMENT / ((endowed_accounts.len() / 2) as Balance),
10 * MANTA_ENDOWMENT / ((endowed_accounts.len() / 2) as Balance),
)
})
.collect(),
Expand Down Expand Up @@ -234,7 +234,7 @@ fn manta_pc_testnet_genesis(
let mut initial_balances: Vec<(AccountId, Balance)> = initial_authorities
.iter()
.cloned()
.map(|x| (x.0, ENDOWMENT))
.map(|x| (x.0, MANTA_ENDOWMENT))
.collect();
initial_balances.push((root_key.clone(), 500_000_000 * MA));

Expand Down
13 changes: 11 additions & 2 deletions node/src/chain_specs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(dead_code)]
use cumulus_primitives_core::ParaId;
use hex_literal::hex;
use manta_primitives::{constants, currency::MA, AccountId, AuraId, Balance, Signature};
use manta_primitives::{constants, AccountId, AuraId, Balance, Signature};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::{ChainType, Properties};
use serde::{Deserialize, Serialize};
Expand All @@ -12,13 +12,22 @@ use sp_runtime::traits::{IdentifyAccount, Verify};
#[cfg(feature = "calamari")]
pub mod calamari_pc;
#[cfg(feature = "calamari")]
pub use calamari_runtime::currency::KMA;
#[cfg(feature = "calamari")]
pub use self::calamari_pc::*;
#[cfg(feature = "manta-pc")]
pub mod manta_pc;
#[cfg(feature = "manta-pc")]
pub use manta_pc_runtime::currency::MA;
#[cfg(feature = "manta-pc")]
pub use self::manta_pc::*;

const ENDOWMENT: Balance = 1_000_000_000 * MA; // 10 endowment so that total supply is 10B
#[cfg(feature = "calamari")]
const CALAMARI_ENDOWMENT: Balance = 1_000_000_000 * KMA; // 10 endowment so that total supply is 10B

#[cfg(feature = "manta-pc")]
const MANTA_ENDOWMENT: Balance = 1_000_000_000 * MA; // 10 endowment so that total supply is 10B

const STAGING_TELEMETRY_URL: &str = "wss://api.telemetry.manta.systems/submit/";

/// Helper function to generate a crypto pair from seed
Expand Down
10 changes: 10 additions & 0 deletions runtime/calamari/src/currency.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use manta_primitives::Balance;

pub const KMA: Balance = 1_000_000_000_000; // 12 decimal
pub const cKMA: Balance = KMA / 100; // 10 decimal, cent-MA
pub const mKMA: Balance = KMA / 1_000; // 9 decimal, milli-MA
pub const uKMA: Balance = KMA / 1_000_000; // 6 decimal, micro-MA

pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 15 * mKMA + (bytes as Balance) * 6 * mKMA // TODO: revisit the storage cost here
}
39 changes: 39 additions & 0 deletions runtime/calamari/src/fee.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::currency;
use frame_support::weights::{
constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients,
WeightToFeePolynomial,
};
use manta_primitives::Balance;
use smallvec::smallvec;
pub use sp_runtime::Perbill;

/// The block saturation level. Fees will be updates based on this value.
pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);

/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
/// node's balance type.
///
/// This should typically create a mapping between the following ranges:
/// - [0, MAXIMUM_BLOCK_WEIGHT]
/// - [Balance::min, Balance::max]
///
/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
/// - Setting it to `0` will essentially disable the weight fee.
/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
// in Manta Parachain, we map to 1/10 of that, or 1/100 CENT
// TODO, revisit here to figure out why use this polynomial
let p = currency::cKMA;
let q = 100 * Balance::from(ExtrinsicBaseWeight::get());
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q,
}]
}
}
13 changes: 9 additions & 4 deletions runtime/calamari/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ use frame_system::{
EnsureOneOf, EnsureRoot,
};
use manta_primitives::{
currency::*, fee::WeightToFee, time::*, AccountId, AuraId, Balance, BlockNumber, Hash, Header,
Index, Signature,
time::*, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature,
};
use sp_runtime::Perbill;

Expand All @@ -57,6 +56,12 @@ use xcm_builder::{
};
use xcm_executor::{Config, XcmExecutor};

pub mod currency;
pub mod fee;

use currency::*;
use fee::WeightToFee;

/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
Expand Down Expand Up @@ -205,7 +210,7 @@ impl pallet_authorship::Config for Runtime {
}

parameter_types! {
pub const NativeTokenExistentialDeposit: u128 = 10 * cMA; // 0.1 KMA
pub const NativeTokenExistentialDeposit: u128 = 10 * cKMA; // 0.1 KMA
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = 50;
}
Expand All @@ -224,7 +229,7 @@ impl pallet_balances::Config for Runtime {

parameter_types! {
/// Relay Chain `TransactionByteFee` / 10
pub const TransactionByteFee: Balance = mMA / 100;
pub const TransactionByteFee: Balance = mKMA / 100;
pub const OperationalFeeMultiplier: u8 = 5;
}

Expand Down
10 changes: 10 additions & 0 deletions runtime/manta-pc/src/currency.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use manta_primitives::Balance;

pub const MA: Balance = 1_000_000_000_000_000_000; // 18 decimal
pub const cMA: Balance = MA / 100; // 16 decimal, cent-MA
pub const mMA: Balance = MA / 1_000; // 15 decimal, milli-MA
pub const uMA: Balance = MA / 1_000_000; // 12 decimal, micro-MA

pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 15 * mMA + (bytes as Balance) * 6 * mMA // TODO: revisit the storage cost here
}
39 changes: 39 additions & 0 deletions runtime/manta-pc/src/fee.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::currency;
use frame_support::weights::{
constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients,
WeightToFeePolynomial,
};
use manta_primitives::Balance;
use smallvec::smallvec;
pub use sp_runtime::Perbill;

/// The block saturation level. Fees will be updates based on this value.
pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);

/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
/// node's balance type.
///
/// This should typically create a mapping between the following ranges:
/// - [0, MAXIMUM_BLOCK_WEIGHT]
/// - [Balance::min, Balance::max]
///
/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
/// - Setting it to `0` will essentially disable the weight fee.
/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
// in Manta Parachain, we map to 1/10 of that, or 1/100 CENT
// TODO, revisit here to figure out why use this polynomial
let p = currency::cMA;
let q = 100 * Balance::from(ExtrinsicBaseWeight::get());
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q,
}]
}
}
9 changes: 7 additions & 2 deletions runtime/manta-pc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ use frame_system::{
EnsureOneOf, EnsureRoot,
};
use manta_primitives::{
currency::*, fee::WeightToFee, time::*, AccountId, AuraId, Balance, BlockNumber, Hash, Header,
Index, Signature,
time::*, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature,
};
use sp_runtime::Perbill;

Expand All @@ -58,6 +57,12 @@ use xcm_builder::{
};
use xcm_executor::{Config, XcmExecutor};

pub mod currency;
pub mod fee;

use currency::*;
use fee::WeightToFee;

/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
Expand Down
56 changes: 0 additions & 56 deletions runtime/primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@ pub const MANTA_DECIMAL: u8 = 12;
pub const CALAMARI_TOKEN_SYMBOL: &str = "KMA";
pub const MANTA_TOKEN_SYMBOL: &str = "MA";

// Money matters.
pub mod currency {
use crate::Balance;

pub const MA: Balance = 1_000_000_000_000; // 12 decimal
pub const cMA: Balance = MA / 100; // 10 decimal, cent-MA
pub const mMA: Balance = MA / 1_000; // 9 decimal, milli-MA
pub const uMA: Balance = MA / 1_000_000; // 6 decimal, micro-MA

pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 15 * mMA + (bytes as Balance) * 6 * mMA // TODO: revisit the storage cost here
}
}

/// Manta parachain time-related
pub mod time {
use crate::{BlockNumber, Moment};
Expand All @@ -35,45 +21,3 @@ pub mod time {
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;
}

/// Fee-related.
pub mod fee {
use crate::Balance;
use frame_support::weights::{
constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients,
WeightToFeePolynomial,
};
use smallvec::smallvec;
pub use sp_runtime::Perbill;

/// The block saturation level. Fees will be updates based on this value.
pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);

/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
/// node's balance type.
///
/// This should typically create a mapping between the following ranges:
/// - [0, MAXIMUM_BLOCK_WEIGHT]
/// - [Balance::min, Balance::max]
///
/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
/// - Setting it to `0` will essentially disable the weight fee.
/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
// in Manta Parachain, we map to 1/10 of that, or 1/100 CENT
// TODO, revisit here to figure out why use this polynomial
let p = super::currency::cMA;
let q = 100 * Balance::from(ExtrinsicBaseWeight::get());
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q,
}]
}
}
}
2 changes: 1 addition & 1 deletion runtime/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod constants;
pub use constants::{currency, fee, time};
pub use constants::time;

use sp_runtime::traits::{BlakeTwo256, IdentifyAccount, Verify};

Expand Down

0 comments on commit 13b60c9

Please sign in to comment.