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
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
@@ -29,6 +29,7 @@ members = [
"orml/nft",
"orml/oracle",
"orml/oracle/rpc",
"orml/parameters",
"orml/rewards",
"orml/tokens",
"orml/tokens/rpc",
14 changes: 10 additions & 4 deletions modules/earning/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 = 0,
}
}

#[frame_support::pallet]
pub mod module {
use super::*;
@@ -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>>;
@@ -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>;
@@ -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)?;

23 changes: 21 additions & 2 deletions modules/earning/src/mock.rs
Original file line number Diff line number Diff line change
@@ -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";
}

@@ -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 = ();
18 changes: 11 additions & 7 deletions runtime/acala/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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",
22 changes: 19 additions & 3 deletions runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

@@ -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";
@@ -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
@@ -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,
20 changes: 12 additions & 8 deletions runtime/karura/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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",
20 changes: 17 additions & 3 deletions runtime/karura/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<Permill> = 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<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
@@ -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,
20 changes: 12 additions & 8 deletions runtime/mandala/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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",
10 changes: 9 additions & 1 deletion runtime/mandala/src/benchmarking/earning.rs
Original file line number Diff line number Diff line change
@@ -17,10 +17,14 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

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())

23 changes: 17 additions & 6 deletions runtime/mandala/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,19 +1302,15 @@ 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;
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 = ConstU128<100>;
type UnbondingPeriod = ConstU32<3>;
type InstantUnstakeFee = InstantUnstakeFee;
type MaxUnbondingChunks = ConstU32<3>;
type LockIdentifier = EarningLockIdentifier;
type WeightInfo = weights::module_earning::WeightInfo<Runtime>;
@@ -1810,6 +1807,19 @@ impl module_liquid_crowdloan::Config for Runtime {
type WeightInfo = weights::module_liquid_crowdloan::WeightInfo<Runtime>;
}

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;

@@ -2020,6 +2030,7 @@ 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,