Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameters #2605

Merged
merged 6 commits into from
Sep 5, 2023
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
24 changes: 22 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ members = [
"orml/nft",
"orml/oracle",
"orml/oracle/rpc",
"orml/parameters",
"orml/rewards",
"orml/tokens",
"orml/tokens/rpc",
Expand Down
14 changes: 10 additions & 4 deletions modules/earning/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -41,6 +41,12 @@ pub mod weights;

pub use weights::WeightInfo;

define_parameters! {
pub Parameters = {
InstantUnstakeFee: Permill = 0,
}
}

#[frame_support::pallet]
pub mod module {
use super::*;
Expand All @@ -51,6 +57,8 @@ pub mod module {

type Currency: LockableCurrency<Self::AccountId, Balance = Balance>;

type ParameterStore: ParameterStore<Parameters>;

type OnBonded: Happened<(Self::AccountId, Balance)>;
type OnUnbonded: Happened<(Self::AccountId, Balance)>;
type OnUnstakeFee: OnUnbalanced<NegativeImbalanceOf<Self>>;
Expand All @@ -60,8 +68,6 @@ pub mod module {
#[pallet::constant]
type UnbondingPeriod: Get<BlockNumberFor<Self>>;
#[pallet::constant]
type InstantUnstakeFee: Get<Option<Permill>>;
#[pallet::constant]
type MaxUnbondingChunks: Get<u32>;
#[pallet::constant]
type LockIdentifier: Get<LockIdentifier>;
Expand Down Expand Up @@ -174,7 +180,7 @@ pub mod module {
pub fn unbond_instant(origin: OriginFor<T>, #[pallet::compact] amount: Balance) -> DispatchResult {
let who = ensure_signed(origin)?;

let fee_ratio = T::InstantUnstakeFee::get().ok_or(Error::<T>::NotAllowed)?;
let fee_ratio = T::ParameterStore::get(InstantUnstakeFee).ok_or(Error::<T>::NotAllowed)?;

let change = <Self as BondingController>::unbond_instant(&who, amount)?;

Expand Down
23 changes: 21 additions & 2 deletions modules/earning/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ impl pallet_balances::Config for Runtime {
}

parameter_types! {
pub const InstantUnstakeFee: Option<Permill> = Some(Permill::from_percent(10));
pub const EarningLockIdentifier: LockIdentifier = *b"12345678";
}

Expand All @@ -92,15 +91,35 @@ impl OnUnbalanced<NegativeImbalance<Runtime>> for OnUnstakeFee {
}
}

pub struct ParameterStoreImpl;
impl ParameterStore<Parameters> for ParameterStoreImpl {
fn get<K>(key: K) -> Option<K::Value>
where
K: orml_traits::parameters::Key
+ Into<<Parameters as orml_traits::parameters::AggregratedKeyValue>::AggregratedKey>,
<Parameters as orml_traits::parameters::AggregratedKeyValue>::AggregratedValue: TryInto<K::WrappedValue>,
{
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 = ();
Expand Down
18 changes: 11 additions & 7 deletions runtime/acala/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
22 changes: 19 additions & 3 deletions runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1694,7 +1697,6 @@ impl module_liquid_crowdloan::Config for Runtime {
}

parameter_types! {
pub const InstantUnstakeFee: Option<Permill> = None;
pub MinBond: Balance = 100 * dollar(ACA);
pub const UnbondingPeriod: BlockNumber = 28 * DAYS;
pub const EarningLockIdentifier: LockIdentifier = *b"aca/earn";
Expand All @@ -1703,17 +1705,30 @@ parameter_types! {
impl module_earning::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type ParameterStore = ParameterStoreAdapter<Parameters, module_earning::Parameters>;
type OnBonded = module_incentives::OnEarningBonded<Runtime>;
type OnUnbonded = module_incentives::OnEarningUnbonded<Runtime>;
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
Expand Down Expand Up @@ -1782,6 +1797,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,
Expand Down
20 changes: 12 additions & 8 deletions runtime/karura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading