Skip to content

Commit

Permalink
add to other runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
TarekkMA committed Oct 3, 2024
1 parent 932463f commit aab0e01
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions runtime/common/src/runtime_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#[macro_export]
macro_rules! gen_runtime_params {
(
UNIT: $UNIT:ident,
RuntimeConfig_TreasuryProportion: $RuntimeConfig_TreasuryProportion:expr,
PalletRandomness_Deposit: $PalletRandomness_Deposit:expr,
) => {
Expand All @@ -43,8 +44,8 @@ macro_rules! gen_runtime_params {
pub mod pallet_randomness {
#[codec(index = 0)]
pub static Deposit: BoundedU128<
{ 1 * currency::UNIT * currency::SUPPLY_FACTOR },
{ 1_000 * currency::UNIT * currency::SUPPLY_FACTOR },
{ 1 * currency::$UNIT * currency::SUPPLY_FACTOR },
{ 1_000 * currency::$UNIT * currency::SUPPLY_FACTOR },
> = $PalletRandomness_Deposit;
}
}
Expand Down
3 changes: 2 additions & 1 deletion runtime/moonbase/src/runtime_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

//! Dynamic runtime parametes.
//! Dynamic runtime parameters for moonbase.

use moonbeam_runtime_common::gen_runtime_params;

gen_runtime_params!(
UNIT: UNIT,
RuntimeConfig_TreasuryProportion: Perbill::from_percent(20),
PalletRandomness_Deposit:
BoundedU128::const_new::<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>(),
Expand Down
4 changes: 4 additions & 0 deletions runtime/moonbeam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pallet-conviction-voting = { workspace = true }
pallet-identity = { workspace = true }
pallet-multisig = { workspace = true }
pallet-preimage = { workspace = true }
pallet-parameters = { workspace = true }
pallet-proxy = { workspace = true }
pallet-referenda = { workspace = true }
pallet-root-testing = { workspace = true }
Expand Down Expand Up @@ -272,6 +273,7 @@ std = [
"pallet-parachain-staking/std",
"pallet-precompile-benchmarks/std",
"pallet-preimage/std",
"pallet-parameters/std",
"pallet-proxy-genesis-companion/std",
"pallet-proxy/std",
"pallet-randomness/std",
Expand Down Expand Up @@ -362,6 +364,7 @@ runtime-benchmarks = [
"pallet-parachain-staking/runtime-benchmarks",
"pallet-precompile-benchmarks/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-parameters/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-randomness/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
Expand Down Expand Up @@ -404,6 +407,7 @@ try-runtime = [
"pallet-parachain-staking/try-runtime",
"pallet-precompile-benchmarks/try-runtime",
"pallet-preimage/try-runtime",
"pallet-parameters/try-runtime",
"pallet-referenda/try-runtime",
"pallet-relay-storage-roots/try-runtime",
"pallet-root-testing/try-runtime",
Expand Down
21 changes: 18 additions & 3 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ use sp_std::{convert::TryFrom, prelude::*};
use xcm::{VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm};
use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;

use runtime_params::*;

#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
Expand All @@ -120,6 +122,7 @@ pub type Precompiles = MoonbeamPrecompiles<Runtime>;

pub mod asset_config;
pub mod governance;
pub mod runtime_params;
pub mod xcm_config;
use governance::councils::*;

Expand Down Expand Up @@ -345,8 +348,11 @@ where
mut fees_then_tips: impl Iterator<Item = Credit<R::AccountId, pallet_balances::Pallet<R>>>,
) {
if let Some(fees) = fees_then_tips.next() {
// for fees, 80% are burned, 20% to the treasury
let (_, to_treasury) = fees.ration(80, 20);
let treasury_perbill =
runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get();
let treasury_part = treasury_perbill.deconstruct();
let burn_part = Perbill::one().deconstruct() - treasury_part;
let (_, to_treasury) = fees.ration(burn_part, treasury_part);
// Balances pallet automatically burns dropped Credits by decreasing
// total_supply accordingly
ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(
Expand Down Expand Up @@ -1345,7 +1351,7 @@ impl pallet_randomness::Config for Runtime {
type Currency = Balances;
type BabeDataGetter = BabeDataGetter<Runtime>;
type VrfKeyLookup = AuthorMapping;
type Deposit = ConstU128<{ 1 * currency::GLMR * currency::SUPPLY_FACTOR }>;
type Deposit = runtime_params::PalletRandomnessDepositU128;
type MaxRandomWords = ConstU8<100>;
type MinBlockDelay = ConstU32<2>;
type MaxBlockDelay = ConstU32<2_000>;
Expand Down Expand Up @@ -1386,6 +1392,13 @@ impl pallet_precompile_benchmarks::Config for Runtime {
type WeightInfo = moonbeam_weights::pallet_precompile_benchmarks::WeightInfo<Runtime>;
}

impl pallet_parameters::Config for Runtime {
type AdminOrigin = EnsureRoot<AccountId>;
type RuntimeEvent = RuntimeEvent;
type RuntimeParameters = RuntimeParameters;
type WeightInfo = moonbeam_weights::pallet_parameters::WeightInfo<Runtime>;
}

construct_runtime! {
pub enum Runtime
{
Expand Down Expand Up @@ -1475,6 +1488,8 @@ construct_runtime! {

// Randomness
Randomness: pallet_randomness::{Pallet, Call, Storage, Event<T>, Inherent} = 120,

Parameters: pallet_parameters = 121,
}
}

Expand Down
26 changes: 26 additions & 0 deletions runtime/moonbeam/src/runtime_params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 Moonbeam Foundation.
// This file is part of Moonbeam.

// Moonbeam is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Moonbeam is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

//! Dynamic runtime parameters for moonbeam.

use moonbeam_runtime_common::gen_runtime_params;

gen_runtime_params!(
UNIT: GLMR,
RuntimeConfig_TreasuryProportion: Perbill::from_percent(20),
PalletRandomness_Deposit:
BoundedU128::const_new::<{ 1 * currency::GLMR * currency::SUPPLY_FACTOR }>(),
);
4 changes: 4 additions & 0 deletions runtime/moonriver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pallet-conviction-voting = { workspace = true }
pallet-identity = { workspace = true }
pallet-multisig = { workspace = true }
pallet-preimage = { workspace = true }
pallet-parameters = { workspace = true }
pallet-proxy = { workspace = true }
pallet-referenda = { workspace = true }
pallet-root-testing = { workspace = true }
Expand Down Expand Up @@ -272,6 +273,7 @@ std = [
"pallet-parachain-staking/std",
"pallet-precompile-benchmarks/std",
"pallet-preimage/std",
"pallet-parameters/std",
"pallet-proxy-genesis-companion/std",
"pallet-proxy/std",
"pallet-randomness/std",
Expand Down Expand Up @@ -367,6 +369,7 @@ runtime-benchmarks = [
"pallet-parachain-staking/runtime-benchmarks",
"pallet-precompile-benchmarks/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-parameters/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-randomness/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
Expand Down Expand Up @@ -407,6 +410,7 @@ try-runtime = [
"pallet-parachain-staking/try-runtime",
"pallet-precompile-benchmarks/try-runtime",
"pallet-preimage/try-runtime",
"pallet-parameters/try-runtime",
"pallet-referenda/try-runtime",
"pallet-relay-storage-roots/try-runtime",
"pallet-root-testing/try-runtime",
Expand Down
21 changes: 18 additions & 3 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ use sp_std::{convert::TryFrom, prelude::*};
use xcm::{VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm};
use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;

use runtime_params::*;

use smallvec::smallvec;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
Expand All @@ -119,6 +121,7 @@ pub type Precompiles = MoonriverPrecompiles<Runtime>;

pub mod asset_config;
pub mod governance;
pub mod runtime_params;
pub mod xcm_config;

mod migrations;
Expand Down Expand Up @@ -347,8 +350,11 @@ where
mut fees_then_tips: impl Iterator<Item = Credit<R::AccountId, pallet_balances::Pallet<R>>>,
) {
if let Some(fees) = fees_then_tips.next() {
// for fees, 80% are burned, 20% to the treasury
let (_, to_treasury) = fees.ration(80, 20);
let treasury_perbill =
runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get();
let treasury_part = treasury_perbill.deconstruct();
let burn_part = Perbill::one().deconstruct() - treasury_part;
let (_, to_treasury) = fees.ration(burn_part, treasury_part);
// Balances pallet automatically burns dropped Credits by decreasing
// total_supply accordingly
ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(
Expand Down Expand Up @@ -1349,7 +1355,7 @@ impl pallet_randomness::Config for Runtime {
type Currency = Balances;
type BabeDataGetter = BabeDataGetter<Runtime>;
type VrfKeyLookup = AuthorMapping;
type Deposit = ConstU128<{ 1 * currency::MOVR * currency::SUPPLY_FACTOR }>;
type Deposit = runtime_params::PalletRandomnessDepositU128;
type MaxRandomWords = ConstU8<100>;
type MinBlockDelay = ConstU32<2>;
type MaxBlockDelay = ConstU32<2_000>;
Expand Down Expand Up @@ -1390,6 +1396,13 @@ impl pallet_precompile_benchmarks::Config for Runtime {
type WeightInfo = moonriver_weights::pallet_precompile_benchmarks::WeightInfo<Runtime>;
}

impl pallet_parameters::Config for Runtime {
type AdminOrigin = EnsureRoot<AccountId>;
type RuntimeEvent = RuntimeEvent;
type RuntimeParameters = RuntimeParameters;
type WeightInfo = moonriver_weights::pallet_parameters::WeightInfo<Runtime>;
}

construct_runtime! {
pub enum Runtime
{
Expand Down Expand Up @@ -1476,6 +1489,8 @@ construct_runtime! {

// Randomness
Randomness: pallet_randomness::{Pallet, Call, Storage, Event<T>, Inherent} = 120,

Parameters: pallet_parameters = 121,
}
}

Expand Down
26 changes: 26 additions & 0 deletions runtime/moonriver/src/runtime_params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 Moonbeam Foundation.
// This file is part of Moonbeam.

// Moonbeam is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Moonbeam is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

//! Dynamic runtime parameters for moonriver.

use moonbeam_runtime_common::gen_runtime_params;

gen_runtime_params!(
UNIT: MOVR,
RuntimeConfig_TreasuryProportion: Perbill::from_percent(20),
PalletRandomness_Deposit:
BoundedU128::const_new::<{ 1 * currency::MOVR * currency::SUPPLY_FACTOR }>(),
);

0 comments on commit aab0e01

Please sign in to comment.