From ce4dec5b8c9919377438a8d48b8171e81a7f11d8 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Thu, 17 Aug 2023 18:30:35 +1200 Subject: [PATCH 1/5] it should work --- Cargo.lock | 20 ++++++++++++++++++++ Cargo.toml | 1 + modules/earning/src/lib.rs | 14 ++++++++++---- orml | 2 +- runtime/acala/Cargo.toml | 18 +++++++++++------- runtime/karura/Cargo.toml | 20 ++++++++++++-------- runtime/mandala/Cargo.toml | 20 ++++++++++++-------- runtime/mandala/src/lib.rs | 23 +++++++++++++++++------ 8 files changed, 84 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b7e307074b..6d4244ca55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -172,6 +172,7 @@ dependencies = [ "orml-nft", "orml-oracle", "orml-oracle-rpc-runtime-api", + "orml-parameters", "orml-rewards", "orml-tokens", "orml-tokens-rpc-runtime-api", @@ -4955,6 +4956,7 @@ dependencies = [ "orml-nft", "orml-oracle", "orml-oracle-rpc-runtime-api", + "orml-parameters", "orml-rewards", "orml-tokens", "orml-tokens-rpc-runtime-api", @@ -5961,6 +5963,7 @@ dependencies = [ "orml-nft", "orml-oracle", "orml-oracle-rpc-runtime-api", + "orml-parameters", "orml-payments", "orml-rewards", "orml-tokens", @@ -7667,6 +7670,22 @@ dependencies = [ "sp-std", ] +[[package]] +name = "orml-parameters" +version = "0.4.1-dev" +dependencies = [ + "frame-support", + "frame-system", + "orml-traits", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "orml-payments" version = "0.4.1-dev" @@ -7758,6 +7777,7 @@ dependencies = [ "num-traits", "orml-utilities", "parity-scale-codec", + "paste", "scale-info", "serde", "sp-core", diff --git a/Cargo.toml b/Cargo.toml index f76d3ecfa4..12ef312601 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ members = [ "orml/nft", "orml/oracle", "orml/oracle/rpc", + "orml/parameters", "orml/rewards", "orml/tokens", "orml/tokens/rpc", diff --git a/modules/earning/src/lib.rs b/modules/earning/src/lib.rs index 062699988f..819f4c0d45 100644 --- a/modules/earning/src/lib.rs +++ b/modules/earning/src/lib.rs @@ -26,7 +26,7 @@ use frame_support::{ traits::{Currency, ExistenceRequirement, LockIdentifier, LockableCurrency, OnUnbalanced, WithdrawReasons}, }; use frame_system::pallet_prelude::*; -use orml_traits::Happened; +use orml_traits::{define_parameters, parameters::ParameterStore, Happened}; use primitives::{ bonding::{self, BondingController}, Balance, @@ -41,6 +41,12 @@ pub mod weights; pub use weights::WeightInfo; +define_parameters! { + pub Parameters = { + InstantUnstakeFee: Permill = 1, + } +} + #[frame_support::pallet] pub mod module { use super::*; @@ -51,6 +57,8 @@ pub mod module { type Currency: LockableCurrency; + type ParameterStore: ParameterStore; + type OnBonded: Happened<(Self::AccountId, Balance)>; type OnUnbonded: Happened<(Self::AccountId, Balance)>; type OnUnstakeFee: OnUnbalanced>; @@ -60,8 +68,6 @@ pub mod module { #[pallet::constant] type UnbondingPeriod: Get>; #[pallet::constant] - type InstantUnstakeFee: Get>; - #[pallet::constant] type MaxUnbondingChunks: Get; #[pallet::constant] type LockIdentifier: Get; @@ -174,7 +180,7 @@ pub mod module { pub fn unbond_instant(origin: OriginFor, #[pallet::compact] amount: Balance) -> DispatchResult { let who = ensure_signed(origin)?; - let fee_ratio = T::InstantUnstakeFee::get().ok_or(Error::::NotAllowed)?; + let fee_ratio = T::ParameterStore::get(InstantUnstakeFee).ok_or(Error::::NotAllowed)?; let change = ::unbond_instant(&who, amount)?; diff --git a/orml b/orml index 22ae492498..f3d4a54bca 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit 22ae49249854b058043665f6642ac4ecad5b78da +Subproject commit f3d4a54bca265437fe606fcc0d3d1dbc80346591 diff --git a/runtime/acala/Cargo.toml b/runtime/acala/Cargo.toml index ef95ab91c9..6187c079c0 100644 --- a/runtime/acala/Cargo.toml +++ b/runtime/acala/Cargo.toml @@ -75,19 +75,20 @@ pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release orml-auction = { path = "../../orml/auction", default-features = false } orml-authority = { path = "../../orml/authority", default-features = false } orml-benchmarking = { path = "../../orml/benchmarking", default-features = false, optional = true } +orml-nft= { path = "../../orml/nft", default-features = false } orml-oracle = { path = "../../orml/oracle", default-features = false } orml-oracle-rpc-runtime-api = { path = "../../orml/oracle/rpc/runtime-api", default-features = false } +orml-parameters = { path = "../../orml/parameters", default-features = false } +orml-rewards = { path = "../../orml/rewards", default-features = false } orml-tokens = { path = "../../orml/tokens", default-features = false } orml-tokens-rpc-runtime-api = { path = "../../orml/tokens/rpc/runtime-api", default-features = false } orml-traits = { path = "../../orml/traits", default-features = false } -orml-vesting = { path = "../../orml/vesting", default-features = false } -orml-rewards = { path = "../../orml/rewards", default-features = false } -orml-nft= { path = "../../orml/nft", default-features = false } -orml-xtokens = { path = "../../orml/xtokens", default-features = false } -orml-xcm-support = { path = "../../orml/xcm-support", default-features = false } orml-unknown-tokens = { path = "../../orml/unknown-tokens", default-features = false } -orml-xcm = { path = "../../orml/xcm", default-features = false } orml-utilities = { path = "../../orml/utilities", default-features = false } +orml-vesting = { path = "../../orml/vesting", default-features = false } +orml-xcm = { path = "../../orml/xcm", default-features = false } +orml-xcm-support = { path = "../../orml/xcm-support", default-features = false } +orml-xtokens = { path = "../../orml/xtokens", default-features = false } # modules module-aggregated-dex = { path = "../../modules/aggregated-dex", default-features = false } @@ -212,16 +213,17 @@ std = [ "orml-nft/std", "orml-oracle-rpc-runtime-api/std", "orml-oracle/std", + "orml-parameters/std", "orml-rewards/std", "orml-tokens-rpc-runtime-api/std", "orml-tokens/std", "orml-traits/std", "orml-unknown-tokens/std", + "orml-utilities/std", "orml-vesting/std", "orml-xcm-support/std", "orml-xcm/std", "orml-xtokens/std", - "orml-utilities/std", "module-aggregated-dex/std", "module-asset-registry/std", @@ -292,6 +294,7 @@ runtime-benchmarks = [ "polkadot-runtime/runtime-benchmarks", "orml-authority/runtime-benchmarks", + "orml-parameters/runtime-benchmarks", "orml-tokens/runtime-benchmarks", "orml-vesting/runtime-benchmarks", "orml-xtokens/runtime-benchmarks", @@ -356,6 +359,7 @@ try-runtime = [ "orml-authority/try-runtime", "orml-nft/try-runtime", "orml-oracle/try-runtime", + "orml-parameters/try-runtime", "orml-rewards/try-runtime", "orml-tokens/try-runtime", "orml-unknown-tokens/try-runtime", diff --git a/runtime/karura/Cargo.toml b/runtime/karura/Cargo.toml index e693ba6160..18845b9230 100644 --- a/runtime/karura/Cargo.toml +++ b/runtime/karura/Cargo.toml @@ -75,19 +75,20 @@ pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release orml-auction = { path = "../../orml/auction", default-features = false } orml-authority = { path = "../../orml/authority", default-features = false } orml-benchmarking = { path = "../../orml/benchmarking", default-features = false, optional = true } +orml-nft= { path = "../../orml/nft", default-features = false } orml-oracle = { path = "../../orml/oracle", default-features = false } orml-oracle-rpc-runtime-api = { path = "../../orml/oracle/rpc/runtime-api", default-features = false } +orml-parameters = { path = "../../orml/parameters", default-features = false } +orml-rewards = { path = "../../orml/rewards", default-features = false } orml-tokens = { path = "../../orml/tokens", default-features = false } orml-tokens-rpc-runtime-api = { path = "../../orml/tokens/rpc/runtime-api", default-features = false } orml-traits = { path = "../../orml/traits", default-features = false } -orml-vesting = { path = "../../orml/vesting", default-features = false } -orml-rewards = { path = "../../orml/rewards", default-features = false } -orml-nft= { path = "../../orml/nft", default-features = false } -orml-xtokens = { path = "../../orml/xtokens", default-features = false } -orml-xcm-support = { path = "../../orml/xcm-support", default-features = false } orml-unknown-tokens = { path = "../../orml/unknown-tokens", default-features = false } -orml-xcm = { path = "../../orml/xcm", default-features = false } orml-utilities = { path = "../../orml/utilities", default-features = false } +orml-vesting = { path = "../../orml/vesting", default-features = false } +orml-xcm = { path = "../../orml/xcm", default-features = false } +orml-xcm-support = { path = "../../orml/xcm-support", default-features = false } +orml-xtokens = { path = "../../orml/xtokens", default-features = false } # modules module-aggregated-dex = { path = "../../modules/aggregated-dex", default-features = false } @@ -213,16 +214,17 @@ std = [ "orml-nft/std", "orml-oracle-rpc-runtime-api/std", "orml-oracle/std", + "orml-parameters/std", "orml-rewards/std", "orml-tokens-rpc-runtime-api/std", "orml-tokens/std", "orml-traits/std", "orml-unknown-tokens/std", + "orml-utilities/std", "orml-vesting/std", "orml-xcm-support/std", "orml-xcm/std", "orml-xtokens/std", - "orml-utilities/std", "module-aggregated-dex/std", "module-asset-registry/std", @@ -288,11 +290,12 @@ runtime-benchmarks = [ "cumulus-pallet-xcmp-queue/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "polkadot-parachain/runtime-benchmarks", + "polkadot-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", - "polkadot-runtime/runtime-benchmarks", "orml-authority/runtime-benchmarks", + "orml-parameters/runtime-benchmarks", "orml-tokens/runtime-benchmarks", "orml-vesting/runtime-benchmarks", "orml-xtokens/runtime-benchmarks", @@ -357,6 +360,7 @@ try-runtime = [ "orml-authority/try-runtime", "orml-nft/try-runtime", "orml-oracle/try-runtime", + "orml-parameters/try-runtime", "orml-rewards/try-runtime", "orml-tokens/try-runtime", "orml-unknown-tokens/try-runtime", diff --git a/runtime/mandala/Cargo.toml b/runtime/mandala/Cargo.toml index eff089f914..35c0ec0f40 100644 --- a/runtime/mandala/Cargo.toml +++ b/runtime/mandala/Cargo.toml @@ -79,20 +79,21 @@ pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release orml-auction = { path = "../../orml/auction", default-features = false } orml-authority = { path = "../../orml/authority", default-features = false } orml-benchmarking = { path = "../../orml/benchmarking", default-features = false, optional = true } +orml-nft= { path = "../../orml/nft", default-features = false } orml-oracle = { path = "../../orml/oracle", default-features = false } orml-oracle-rpc-runtime-api = { path = "../../orml/oracle/rpc/runtime-api", default-features = false } +orml-parameters = { path = "../../orml/parameters", default-features = false } +orml-payments = { path = "../../orml/payments", default-features = false } +orml-rewards = { path = "../../orml/rewards", default-features = false } orml-tokens = { path = "../../orml/tokens", default-features = false } orml-tokens-rpc-runtime-api = { path = "../../orml/tokens/rpc/runtime-api", default-features = false } orml-traits = { path = "../../orml/traits", default-features = false } -orml-vesting = { path = "../../orml/vesting", default-features = false } -orml-rewards = { path = "../../orml/rewards", default-features = false } -orml-nft= { path = "../../orml/nft", default-features = false } -orml-xtokens = { path = "../../orml/xtokens", default-features = false } -orml-xcm-support = { path = "../../orml/xcm-support", default-features = false } orml-unknown-tokens = { path = "../../orml/unknown-tokens", default-features = false } -orml-xcm = { path = "../../orml/xcm", default-features = false } -orml-payments = { path = "../../orml/payments", default-features = false } orml-utilities = { path = "../../orml/utilities", default-features = false } +orml-vesting = { path = "../../orml/vesting", default-features = false } +orml-xcm = { path = "../../orml/xcm", default-features = false } +orml-xcm-support = { path = "../../orml/xcm-support", default-features = false } +orml-xtokens = { path = "../../orml/xtokens", default-features = false } # modules module-transaction-pause = { path = "../../modules/transaction-pause", default-features = false } @@ -227,17 +228,18 @@ std = [ "orml-nft/std", "orml-oracle-rpc-runtime-api/std", "orml-oracle/std", + "orml-parameters/std", "orml-payments/std", "orml-rewards/std", "orml-tokens-rpc-runtime-api/std", "orml-tokens/std", "orml-traits/std", "orml-unknown-tokens/std", + "orml-utilities/std", "orml-vesting/std", "orml-xcm-support/std", "orml-xcm/std", "orml-xtokens/std", - "orml-utilities/std", "module-aggregated-dex/std", "module-asset-registry/std", @@ -311,6 +313,7 @@ runtime-benchmarks = [ "acala-service/runtime-benchmarks", "orml-authority/runtime-benchmarks", + "orml-parameters/runtime-benchmarks", "orml-tokens/runtime-benchmarks", "orml-vesting/runtime-benchmarks", "orml-xtokens/runtime-benchmarks", @@ -383,6 +386,7 @@ try-runtime = [ "orml-authority/try-runtime", "orml-nft/try-runtime", "orml-oracle/try-runtime", + "orml-parameters/try-runtime", "orml-payments/try-runtime", "orml-rewards/try-runtime", "orml-tokens/try-runtime", diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 97f269d39d..d7a8d8f4fb 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -62,7 +62,8 @@ use scale_info::TypeInfo; use orml_tokens::CurrencyAdapter; use orml_traits::{ - create_median_value_data_provider, parameter_type_with_key, DataFeeder, DataProviderExtended, GetByKey, + create_median_value_data_provider, define_aggregrated_parameters, parameter_type_with_key, + parameters::ParameterStoreAdapter, DataFeeder, DataProviderExtended, GetByKey, }; use orml_utilities::simulate_execution; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; @@ -1301,10 +1302,6 @@ impl module_transaction_payment::Config for Runtime { type DefaultFeeTokens = DefaultFeeTokens; } -parameter_types! { - pub const InstantUnstakeFee: Permill = Permill::from_percent(10); -} - impl module_earning::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; @@ -1313,7 +1310,7 @@ impl module_earning::Config for Runtime { type OnUnstakeFee = Treasury; // fee goes to treasury type MinBond = ConstU128<100>; type UnbondingPeriod = ConstU32<3>; - type InstantUnstakeFee = InstantUnstakeFee; + type ParameterStore = ParameterStoreAdapter; type MaxUnbondingChunks = ConstU32<3>; type LockIdentifier = EarningLockIdentifier; type WeightInfo = weights::module_earning::WeightInfo; @@ -1810,6 +1807,19 @@ impl module_liquid_crowdloan::Config for Runtime { type WeightInfo = weights::module_liquid_crowdloan::WeightInfo; } +define_aggregrated_parameters! { + pub RuntimeParameters = { + Earning: module_earning::Parameters = 0, + } +} + +impl orml_parameters::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AggregratedKeyValue = RuntimeParameters; + type AdminOrigin = EnsureRootOrThreeFourthsGeneralCouncil; + type WeightInfo = (); +} + #[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)] pub struct ConvertEthereumTx; @@ -2058,6 +2068,7 @@ construct_runtime!( Dex: module_dex = 111, DexOracle: module_dex_oracle = 112, AggregatedDex: module_aggregated_dex = 113, + Parameters: orml_parameters = 114, // Honzon AuctionManager: module_auction_manager = 120, From 2bb6eb79fc92ce47a40f3da7610c1313e1109a3b Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Tue, 5 Sep 2023 11:51:32 +1200 Subject: [PATCH 2/5] wip --- Cargo.lock | 4 ++-- modules/earning/src/lib.rs | 2 +- modules/earning/src/mock.rs | 23 +++++++++++++++++++++-- orml | 2 +- runtime/acala/src/lib.rs | 27 +++++++++++++++++++++++++-- 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e95f0829bd..9f5b1db076 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7549,7 +7549,7 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "hex-literal 0.3.4", + "hex-literal 0.4.1", "log", "parity-scale-codec", "paste", @@ -7783,7 +7783,7 @@ version = "0.4.1-dev" dependencies = [ "frame-support", "frame-system", - "hex-literal 0.3.4", + "hex-literal 0.4.1", "orml-xcm-support", "parity-scale-codec", "scale-info", diff --git a/modules/earning/src/lib.rs b/modules/earning/src/lib.rs index 819f4c0d45..0d172d569c 100644 --- a/modules/earning/src/lib.rs +++ b/modules/earning/src/lib.rs @@ -43,7 +43,7 @@ pub use weights::WeightInfo; define_parameters! { pub Parameters = { - InstantUnstakeFee: Permill = 1, + InstantUnstakeFee: Permill = 0, } } diff --git a/modules/earning/src/mock.rs b/modules/earning/src/mock.rs index 7983f5b6cb..b4ac33f3f4 100644 --- a/modules/earning/src/mock.rs +++ b/modules/earning/src/mock.rs @@ -76,7 +76,6 @@ impl pallet_balances::Config for Runtime { } parameter_types! { - pub const InstantUnstakeFee: Option = Some(Permill::from_percent(10)); pub const EarningLockIdentifier: LockIdentifier = *b"12345678"; } @@ -92,15 +91,35 @@ impl OnUnbalanced> for OnUnstakeFee { } } +pub struct ParameterStoreImpl; +impl ParameterStore for ParameterStoreImpl { + fn get(key: K) -> Option + where + K: orml_traits::parameters::Key + + Into<::AggregratedKey>, + ::AggregratedValue: TryInto, + { + let key = key.into(); + match key { + ParametersKey::InstantUnstakeFee(_) => Some( + ParametersValue::InstantUnstakeFee(Permill::from_percent(10)) + .try_into() + .ok()? + .into(), + ), + } + } +} + impl Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; + type ParameterStore = ParameterStoreImpl; type OnBonded = OnBonded; type OnUnbonded = OnUnbonded; type OnUnstakeFee = OnUnstakeFee; type MinBond = ConstU128<100>; type UnbondingPeriod = ConstU64<3>; - type InstantUnstakeFee = InstantUnstakeFee; type MaxUnbondingChunks = ConstU32<3>; type LockIdentifier = EarningLockIdentifier; type WeightInfo = (); diff --git a/orml b/orml index f3d4a54bca..3461e570b3 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit f3d4a54bca265437fe606fcc0d3d1dbc80346591 +Subproject commit 3461e570b3d045d1dcd603f2d549a5fc1db64937 diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 1521911709..01c4bdf94a 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -1694,7 +1694,6 @@ impl module_liquid_crowdloan::Config for Runtime { } parameter_types! { - pub const InstantUnstakeFee: Option = None; pub MinBond: Balance = 100 * dollar(ACA); pub const UnbondingPeriod: BlockNumber = 28 * DAYS; pub const EarningLockIdentifier: LockIdentifier = *b"aca/earn"; @@ -1703,17 +1702,40 @@ parameter_types! { impl module_earning::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; + type ParameterStore = ParameterStoreAdapter; type OnBonded = module_incentives::OnEarningBonded; type OnUnbonded = module_incentives::OnEarningUnbonded; type OnUnstakeFee = Treasury; // fee goes to treasury type MinBond = MinBond; type UnbondingPeriod = UnbondingPeriod; - type InstantUnstakeFee = InstantUnstakeFee; type MaxUnbondingChunks = ConstU32<10>; type LockIdentifier = EarningLockIdentifier; type WeightInfo = (); } +pub struct EnsureOriginImpl; + +impl EnsureOriginWithArg for EnsureOriginImpl { + type Success = (); + + fn try_origin(origin: RuntimeOrigin, key: &RuntimeParametersKey) -> Result { + EnsureRoot::try_origin(origin.clone()).map_err(|_| origin)?; + return Ok(()); + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin(_key: &RuntimeParametersKey) -> Result { + RuntimeOrigin::Root.into() + } +} + +impl orml_parameters::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AggregratedKeyValue = RuntimeParameters; + type AdminOrigin = EnsureOriginImpl; + type WeightInfo = (); +} + construct_runtime!( pub enum Runtime { // Core & Utility @@ -1782,6 +1804,7 @@ construct_runtime!( Auction: orml_auction = 80, Rewards: orml_rewards = 81, OrmlNFT: orml_nft exclude_parts { Call } = 82, + Parameters: orml_parameters = 83, // Acala Core Prices: module_prices = 90, From 3ab3008f3746cbba20472b09f81a42903fe756d6 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Tue, 5 Sep 2023 13:32:46 +1200 Subject: [PATCH 3/5] fix --- orml | 2 +- runtime/acala/src/lib.rs | 25 +++++++++---------------- runtime/karura/src/lib.rs | 20 +++++++++++++++++--- runtime/mandala/src/lib.rs | 4 ++-- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/orml b/orml index 3461e570b3..ad3ee01356 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit 3461e570b3d045d1dcd603f2d549a5fc1db64937 +Subproject commit ad3ee01356c7541dc019651b0200a71f936f0b41 diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 01c4bdf94a..2625c191ec 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -60,7 +60,10 @@ use module_support::{AssetIdMapping, DispatchableTask, PoolId}; use module_transaction_payment::TargetedFeeAdjustment; use cumulus_pallet_parachain_system::RelaychainDataProvider; -use orml_traits::{create_median_value_data_provider, parameter_type_with_key, DataFeeder, DataProviderExtended}; +use orml_traits::{ + create_median_value_data_provider, define_aggregrated_parameters, parameter_type_with_key, + parameters::ParameterStoreAdapter, DataFeeder, DataProviderExtended, +}; use orml_utilities::simulate_execution; use pallet_transaction_payment::RuntimeDispatchInfo; @@ -1702,7 +1705,7 @@ parameter_types! { impl module_earning::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; - type ParameterStore = ParameterStoreAdapter; + type ParameterStore = ParameterStoreAdapter; type OnBonded = module_incentives::OnEarningBonded; type OnUnbonded = module_incentives::OnEarningUnbonded; type OnUnstakeFee = Treasury; // fee goes to treasury @@ -1713,26 +1716,16 @@ impl module_earning::Config for Runtime { type WeightInfo = (); } -pub struct EnsureOriginImpl; - -impl EnsureOriginWithArg for EnsureOriginImpl { - type Success = (); - - fn try_origin(origin: RuntimeOrigin, key: &RuntimeParametersKey) -> Result { - EnsureRoot::try_origin(origin.clone()).map_err(|_| origin)?; - return Ok(()); - } - - #[cfg(feature = "runtime-benchmarks")] - fn try_successful_origin(_key: &RuntimeParametersKey) -> Result { - RuntimeOrigin::Root.into() +define_aggregrated_parameters! { + pub RuntimeParameters = { + Earning: module_earning::Parameters = 0, } } impl orml_parameters::Config for Runtime { type RuntimeEvent = RuntimeEvent; type AggregratedKeyValue = RuntimeParameters; - type AdminOrigin = EnsureOriginImpl; + type AdminOrigin = EnsureRootOrThreeFourthsGeneralCouncil; type WeightInfo = (); } diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index ef2c223696..b2f162e10f 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -61,7 +61,8 @@ use module_transaction_payment::TargetedFeeAdjustment; use cumulus_pallet_parachain_system::RelaychainDataProvider; use orml_traits::{ - create_median_value_data_provider, parameter_type_with_key, DataFeeder, DataProviderExtended, GetByKey, + create_median_value_data_provider, define_aggregrated_parameters, parameter_type_with_key, + parameters::ParameterStoreAdapter, DataFeeder, DataProviderExtended, GetByKey, }; use orml_utilities::simulate_execution; use pallet_transaction_payment::RuntimeDispatchInfo; @@ -1688,7 +1689,6 @@ impl nutsfinance_stable_asset::Config for Runtime { } parameter_types! { - pub const InstantUnstakeFee: Option = None; pub MinBond: Balance = 10 * dollar(KAR); pub const UnbondingPeriod: BlockNumber = 8 * DAYS; pub const EarningLockIdentifier: LockIdentifier = *b"aca/earn"; @@ -1697,17 +1697,30 @@ parameter_types! { impl module_earning::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; + type ParameterStore = ParameterStoreAdapter; type OnBonded = module_incentives::OnEarningBonded; type OnUnbonded = module_incentives::OnEarningUnbonded; type OnUnstakeFee = Treasury; // fee goes to treasury type MinBond = MinBond; type UnbondingPeriod = UnbondingPeriod; - type InstantUnstakeFee = InstantUnstakeFee; type MaxUnbondingChunks = ConstU32<10>; type LockIdentifier = EarningLockIdentifier; type WeightInfo = (); } +define_aggregrated_parameters! { + pub RuntimeParameters = { + Earning: module_earning::Parameters = 0, + } +} + +impl orml_parameters::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AggregratedKeyValue = RuntimeParameters; + type AdminOrigin = EnsureRootOrThreeFourthsGeneralCouncil; + type WeightInfo = (); +} + construct_runtime!( pub enum Runtime { // Core & Utility @@ -1776,6 +1789,7 @@ construct_runtime!( Auction: orml_auction = 80, Rewards: orml_rewards = 81, OrmlNFT: orml_nft exclude_parts { Call } = 82, + Parameters: orml_parameters = 83, // Karura Core Prices: module_prices = 90, diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 08f67225f2..80eaa39545 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -1305,12 +1305,12 @@ impl module_transaction_payment::Config for Runtime { impl module_earning::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; + type ParameterStore = ParameterStoreAdapter; type OnBonded = module_incentives::OnEarningBonded; type OnUnbonded = module_incentives::OnEarningUnbonded; type OnUnstakeFee = Treasury; // fee goes to treasury type MinBond = ConstU128<100>; type UnbondingPeriod = ConstU32<3>; - type ParameterStore = ParameterStoreAdapter; type MaxUnbondingChunks = ConstU32<3>; type LockIdentifier = EarningLockIdentifier; type WeightInfo = weights::module_earning::WeightInfo; @@ -2030,13 +2030,13 @@ construct_runtime!( Auction: orml_auction = 100, Rewards: orml_rewards = 101, OrmlNFT: orml_nft exclude_parts { Call } = 102, + Parameters: orml_parameters = 103, // Acala Core Prices: module_prices = 110, Dex: module_dex = 111, DexOracle: module_dex_oracle = 112, AggregatedDex: module_aggregated_dex = 113, - Parameters: orml_parameters = 114, // Honzon AuctionManager: module_auction_manager = 120, From 7b0370526e8eb6cdfa774eead7d1b4e0126e1729 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Tue, 5 Sep 2023 16:06:25 +1200 Subject: [PATCH 4/5] fix benchmarkings --- orml | 2 +- runtime/mandala/src/benchmarking/earning.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/orml b/orml index ad3ee01356..f9654d45de 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit ad3ee01356c7541dc019651b0200a71f936f0b41 +Subproject commit f9654d45de0c39c9001ecad276cca75f7c4418d1 diff --git a/runtime/mandala/src/benchmarking/earning.rs b/runtime/mandala/src/benchmarking/earning.rs index 03f769945f..88c09234dd 100644 --- a/runtime/mandala/src/benchmarking/earning.rs +++ b/runtime/mandala/src/benchmarking/earning.rs @@ -17,10 +17,14 @@ // along with this program. If not, see . use super::utils::{dollar, set_balance, NATIVE}; -use crate::{AccountId, DispatchResult, Earning, Get, NativeTokenExistentialDeposit, Runtime, RuntimeOrigin, System}; +use crate::{ + AccountId, DispatchResult, Earning, Get, NativeTokenExistentialDeposit, Parameters, Runtime, RuntimeOrigin, + RuntimeParameters, System, +}; use frame_benchmarking::whitelisted_caller; use frame_system::RawOrigin; use orml_benchmarking::runtime_benchmarks; +use sp_runtime::Permill; fn make_max_unbonding_chunk(who: AccountId) -> DispatchResult { System::set_block_number(0); @@ -46,6 +50,10 @@ runtime_benchmarks! { unbond_instant { let caller: AccountId = whitelisted_caller(); set_balance(NATIVE, &caller, dollar(NATIVE)); + Parameters::set_parameter( + RawOrigin::Root.into(), + RuntimeParameters::Earning(module_earning::Parameters::InstantUnstakeFee(module_earning::InstantUnstakeFee, Some(Permill::from_percent(10)))) + )?; Earning::bond(RuntimeOrigin::signed(caller.clone()), 2 * NativeTokenExistentialDeposit::get())?; }: _(RawOrigin::Signed(caller), NativeTokenExistentialDeposit::get()) From 767c7db6328df08752497dacb24e1ba71b997ae3 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 6 Sep 2023 10:25:48 +1200 Subject: [PATCH 5/5] update orml --- orml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orml b/orml index f9654d45de..5680303914 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit f9654d45de0c39c9001ecad276cca75f7c4418d1 +Subproject commit 56803039140d968f41a10431d5d6a66133dd200a