diff --git a/Cargo.lock b/Cargo.lock index fdf624718b..3d2af9d7f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -159,6 +159,7 @@ dependencies = [ "orml-oracle", "orml-oracle-runtime-api", "orml-parameters", + "orml-rate-limit", "orml-rewards", "orml-tokens", "orml-tokens-runtime-api", @@ -5363,6 +5364,7 @@ dependencies = [ "orml-oracle", "orml-oracle-runtime-api", "orml-parameters", + "orml-rate-limit", "orml-rewards", "orml-tokens", "orml-tokens-runtime-api", @@ -6276,6 +6278,7 @@ dependencies = [ "orml-oracle-runtime-api", "orml-parameters", "orml-payments", + "orml-rate-limit", "orml-rewards", "orml-tokens", "orml-tokens-runtime-api", @@ -8065,6 +8068,24 @@ dependencies = [ "sp-std", ] +[[package]] +name = "orml-rate-limit" +version = "0.6.7" +dependencies = [ + "frame-support", + "frame-system", + "orml-traits", + "orml-utilities", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "orml-rewards" version = "0.6.7" @@ -11766,6 +11787,7 @@ dependencies = [ "orml-currencies", "orml-nft", "orml-oracle", + "orml-rate-limit", "orml-rewards", "orml-tokens", "orml-traits", diff --git a/Cargo.toml b/Cargo.toml index 0121755a00..e17322c8cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ members = [ "orml/oracle", "orml/parameters", "orml/payments", + "orml/rate-limit", "orml/rewards", "orml/tokens", "orml/tokens/runtime-api", @@ -171,6 +172,7 @@ orml-oracle = { path = "orml/oracle", default-features = false } orml-oracle-runtime-api = { path = "orml/oracle/runtime-api", default-features = false } orml-parameters = { path = "orml/parameters", default-features = false } orml-payments = { path = "orml/payments", default-features = false } +orml-rate-limit = { path = "orml/rate-limit", default-features = false } orml-rewards = { path = "orml/rewards", default-features = false } orml-tokens = { path = "orml/tokens", default-features = false } orml-tokens-runtime-api = { path = "orml/tokens/runtime-api", default-features = false } diff --git a/orml b/orml index 5c96d6bf12..175792bd5e 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit 5c96d6bf12c5fc2aeac359f2297453ba63140927 +Subproject commit 175792bd5e06cf64e17762df037e15a4e6234d49 diff --git a/runtime/acala/Cargo.toml b/runtime/acala/Cargo.toml index e5b2e3fbf1..ddaf4d2d67 100644 --- a/runtime/acala/Cargo.toml +++ b/runtime/acala/Cargo.toml @@ -91,6 +91,7 @@ orml-vesting = { workspace = true } orml-xcm = { workspace = true } orml-xcm-support = { workspace = true } orml-xtokens = { workspace = true } +orml-rate-limit = { workspace = true } # modules module-aggregated-dex = { workspace = true } @@ -228,6 +229,7 @@ std = [ "orml-xcm-support/std", "orml-xcm/std", "orml-xtokens/std", + "orml-rate-limit/std", "module-aggregated-dex/std", "module-asset-registry/std", @@ -302,6 +304,7 @@ runtime-benchmarks = [ "orml-tokens/runtime-benchmarks", "orml-vesting/runtime-benchmarks", "orml-xtokens/runtime-benchmarks", + "orml-rate-limit/runtime-benchmarks", "module-collator-selection/runtime-benchmarks", "module-evm-accounts/runtime-benchmarks", @@ -371,6 +374,7 @@ try-runtime = [ "orml-vesting/try-runtime", "orml-xcm/try-runtime", "orml-xtokens/try-runtime", + "orml-rate-limit/try-runtime", "module-aggregated-dex/try-runtime", "module-asset-registry/try-runtime", diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 11d43d1051..13f25f43ca 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -110,9 +110,9 @@ use runtime_common::{ EnsureRootOrTwoThirdsTechnicalCommittee, ExchangeRate, ExistentialDepositsTimesOneHundred, FinancialCouncilInstance, FinancialCouncilMembershipInstance, GasToWeight, GeneralCouncilInstance, GeneralCouncilMembershipInstance, HomaCouncilInstance, HomaCouncilMembershipInstance, MaxTipsOfPriority, - OperationalFeeMultiplier, OperatorMembershipInstanceAcala, Price, ProxyType, Rate, Ratio, RuntimeBlockLength, - RuntimeBlockWeights, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance, TimeStampedPrice, - TipPerWeightStep, ACA, AUSD, DOT, LCDOT, LDOT, TAP, + OperationalFeeMultiplier, OperatorMembershipInstanceAcala, Price, ProxyType, Rate, RateLimiterId, Ratio, + RuntimeBlockLength, RuntimeBlockWeights, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance, + TimeStampedPrice, TipPerWeightStep, ACA, AUSD, DOT, LCDOT, LDOT, TAP, }; use xcm::v3::prelude::*; @@ -1747,6 +1747,16 @@ impl orml_parameters::Config for Runtime { type WeightInfo = (); } +impl orml_rate_limit::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type GovernanceOrigin = EnsureRootOrOneThirdsTechnicalCommittee; + type RateLimiterId = RateLimiterId; + type MaxWhitelistFilterCount = ConstU32<3>; + type UnixTime = Timestamp; + type BlockNumberProvider = System; + type WeightInfo = (); +} + construct_runtime!( pub enum Runtime { // Core & Utility @@ -1760,6 +1770,7 @@ construct_runtime!( // NOTE: IdleScheduler must be put before ParachainSystem in order to read relaychain blocknumber IdleScheduler: module_idle_scheduler = 7, Preimage: pallet_preimage = 8, + RateLimit: orml_rate_limit = 9, // Tokens & Related Balances: pallet_balances = 10, diff --git a/runtime/acala/src/xcm_config.rs b/runtime/acala/src/xcm_config.rs index e52a77d272..49c91c85f3 100644 --- a/runtime/acala/src/xcm_config.rs +++ b/runtime/acala/src/xcm_config.rs @@ -20,8 +20,8 @@ use super::{ constants::{fee::*, parachains}, AcalaTreasuryAccount, AccountId, AllPalletsWithSystem, AssetIdMapping, AssetIdMaps, Balance, Balances, Convert, Currencies, CurrencyId, EvmAddressMapping, ExistentialDeposits, GetNativeCurrencyId, NativeTokenExistentialDeposit, - ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, UnknownTokens, - XcmInterface, XcmpQueue, ACA, AUSD, TAP, + ParachainInfo, ParachainSystem, PolkadotXcm, RateLimit, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + UnknownTokens, XcmInterface, XcmpQueue, ACA, AUSD, TAP, }; use cumulus_primitives_core::ParaId; use frame_support::{ @@ -40,7 +40,7 @@ use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use primitives::evm::is_system_contract; use runtime_common::{ local_currency_location, native_currency_location, AcalaDropAssets, EnsureRootOrHalfGeneralCouncil, - EnsureRootOrThreeFourthsGeneralCouncil, FixedRateOfAsset, + EnsureRootOrThreeFourthsGeneralCouncil, FixedRateOfAsset, RateLimiterId, }; use xcm::{prelude::*, v3::Weight as XcmWeight}; use xcm_builder::{EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, SignedToAccountId32}; @@ -324,6 +324,7 @@ parameter_types! { parameter_types! { pub const BaseXcmWeight: XcmWeight = XcmWeight::from_parts(100_000_000, 0); pub const MaxAssetsForTransfer: usize = 2; + pub const XtokensRateLimiterId: RateLimiterId = RateLimiterId::XTokens; } parameter_type_with_key! { @@ -351,4 +352,6 @@ impl orml_xtokens::Config for Runtime { type MinXcmFee = ParachainMinFee; type MultiLocationsFilter = Everything; type ReserveProvider = AbsoluteReserveProvider; + type RateLimiter = RateLimit; + type RateLimiterId = XtokensRateLimiterId; } diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 624e9db706..82a3e3215d 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -79,6 +79,7 @@ wasm-bencher = { workspace = true, optional = true } orml-nft = { workspace = true, optional = true } orml-currencies = { workspace = true, optional = true } orml-rewards = { workspace = true, optional = true } +orml-rate-limit = { workspace = true, optional = true } [dev-dependencies] orml-utilities = { workspace = true, features = ["std"] } @@ -124,6 +125,7 @@ std = [ "orml-tokens/std", "orml-traits/std", "orml-xtokens/std", + "orml-rate-limit/std", "module-asset-registry/std", "module-cdp-engine/std", @@ -168,6 +170,7 @@ wasm-bench = [ "orml-currencies", "orml-nft", "orml-rewards", + "orml-rate-limit", "orml-tokens/runtime-benchmarks", "xcm-builder/runtime-benchmarks", diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 52b1eb0c8d..158009bc9b 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -408,6 +408,18 @@ where } } +/// The type used to represent the kinds of rate limiter id. +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)] +pub enum RateLimiterId { + XTokens, +} + +impl Default for RateLimiterId { + fn default() -> Self { + Self::XTokens + } +} + #[cfg(feature = "std")] /// Returns `evm_genesis_accounts` pub fn evm_genesis(evm_accounts: Vec) -> BTreeMap> { diff --git a/runtime/common/src/precompile/mock.rs b/runtime/common/src/precompile/mock.rs index d710ee21c7..d40e1f56d7 100644 --- a/runtime/common/src/precompile/mock.rs +++ b/runtime/common/src/precompile/mock.rs @@ -909,6 +909,8 @@ impl orml_xtokens::Config for Test { type MinXcmFee = ParachainMinFee; type MultiLocationsFilter = Everything; type ReserveProvider = AbsoluteReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } parameter_types!( diff --git a/runtime/karura/Cargo.toml b/runtime/karura/Cargo.toml index 5b97257589..b038666652 100644 --- a/runtime/karura/Cargo.toml +++ b/runtime/karura/Cargo.toml @@ -91,6 +91,7 @@ orml-vesting = { workspace = true } orml-xcm = { workspace = true } orml-xcm-support = { workspace = true } orml-xtokens = { workspace = true } +orml-rate-limit = { workspace = true } # modules module-aggregated-dex = { workspace = true } @@ -229,6 +230,7 @@ std = [ "orml-xcm-support/std", "orml-xcm/std", "orml-xtokens/std", + "orml-rate-limit/std", "module-aggregated-dex/std", "module-asset-registry/std", @@ -304,6 +306,7 @@ runtime-benchmarks = [ "orml-tokens/runtime-benchmarks", "orml-vesting/runtime-benchmarks", "orml-xtokens/runtime-benchmarks", + "orml-rate-limit/runtime-benchmarks", "module-collator-selection/runtime-benchmarks", "module-evm-accounts/runtime-benchmarks", @@ -373,6 +376,7 @@ try-runtime = [ "orml-vesting/try-runtime", "orml-xcm/try-runtime", "orml-xtokens/try-runtime", + "orml-rate-limit/try-runtime", "module-aggregated-dex/try-runtime", "module-asset-registry/try-runtime", diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 87a269fb21..2015c1cfcd 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -111,9 +111,9 @@ use runtime_common::{ EnsureRootOrTwoThirdsTechnicalCommittee, ExchangeRate, ExistentialDepositsTimesOneHundred, FinancialCouncilInstance, FinancialCouncilMembershipInstance, FixedRateOfAsset, GasToWeight, GeneralCouncilInstance, GeneralCouncilMembershipInstance, HomaCouncilInstance, HomaCouncilMembershipInstance, - MaxTipsOfPriority, OperationalFeeMultiplier, OperatorMembershipInstanceAcala, Price, ProxyType, Rate, Ratio, - RuntimeBlockLength, RuntimeBlockWeights, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance, - TimeStampedPrice, TipPerWeightStep, KAR, KSM, KUSD, LKSM, TAI, + MaxTipsOfPriority, OperationalFeeMultiplier, OperatorMembershipInstanceAcala, Price, ProxyType, Rate, + RateLimiterId, Ratio, RuntimeBlockLength, RuntimeBlockWeights, TechnicalCommitteeInstance, + TechnicalCommitteeMembershipInstance, TimeStampedPrice, TipPerWeightStep, KAR, KSM, KUSD, LKSM, TAI, }; use xcm::v3::prelude::*; @@ -1750,6 +1750,16 @@ impl orml_parameters::Config for Runtime { type WeightInfo = (); } +impl orml_rate_limit::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type GovernanceOrigin = EnsureRootOrOneThirdsTechnicalCommittee; + type RateLimiterId = RateLimiterId; + type MaxWhitelistFilterCount = ConstU32<3>; + type UnixTime = Timestamp; + type BlockNumberProvider = System; + type WeightInfo = (); +} + construct_runtime!( pub enum Runtime { // Core & Utility @@ -1763,6 +1773,7 @@ construct_runtime!( // NOTE: IdleScheduler must be put before ParachainSystem in order to read relaychain blocknumber IdleScheduler: module_idle_scheduler = 7, Preimage: pallet_preimage = 8, + RateLimit: orml_rate_limit = 9, // Tokens & Related Balances: pallet_balances = 10, diff --git a/runtime/karura/src/xcm_config.rs b/runtime/karura/src/xcm_config.rs index 3274fea58e..637acd66f6 100644 --- a/runtime/karura/src/xcm_config.rs +++ b/runtime/karura/src/xcm_config.rs @@ -20,8 +20,8 @@ use super::{ constants::{fee::*, parachains}, AccountId, AllPalletsWithSystem, AssetIdMapping, AssetIdMaps, Balance, Balances, Convert, Currencies, CurrencyId, EvmAddressMapping, ExistentialDeposits, FixedRateOfAsset, GetNativeCurrencyId, KaruraTreasuryAccount, - NativeTokenExistentialDeposit, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, - RuntimeOrigin, UnknownTokens, XcmInterface, XcmpQueue, KAR, KUSD, LKSM, TAI, XNFT, + NativeTokenExistentialDeposit, ParachainInfo, ParachainSystem, PolkadotXcm, RateLimit, Runtime, RuntimeCall, + RuntimeEvent, RuntimeOrigin, UnknownTokens, XcmInterface, XcmpQueue, KAR, KUSD, LKSM, TAI, XNFT, }; use cumulus_primitives_core::ParaId; use frame_support::{ @@ -38,7 +38,7 @@ use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use primitives::evm::is_system_contract; use runtime_common::{ local_currency_location, native_currency_location, AcalaDropAssets, EnsureRootOrHalfGeneralCouncil, - EnsureRootOrThreeFourthsGeneralCouncil, + EnsureRootOrThreeFourthsGeneralCouncil, RateLimiterId, }; use xcm::{prelude::*, v3::Weight as XcmWeight}; use xcm_builder::{EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, SignedToAccountId32}; @@ -270,6 +270,7 @@ parameter_types! { parameter_types! { pub const BaseXcmWeight: XcmWeight = XcmWeight::from_parts(100_000_000, 0); pub const MaxAssetsForTransfer: usize = 2; + pub const XtokensRateLimiterId: RateLimiterId = RateLimiterId::XTokens; } parameter_type_with_key! { @@ -297,6 +298,8 @@ impl orml_xtokens::Config for Runtime { type MinXcmFee = ParachainMinFee; type MultiLocationsFilter = Everything; type ReserveProvider = AbsoluteReserveProvider; + type RateLimiter = RateLimit; + type RateLimiterId = XtokensRateLimiterId; } pub type LocalAssetTransactor = ( diff --git a/runtime/mandala/Cargo.toml b/runtime/mandala/Cargo.toml index 403a81211e..9d44b94016 100644 --- a/runtime/mandala/Cargo.toml +++ b/runtime/mandala/Cargo.toml @@ -96,6 +96,7 @@ orml-vesting = { workspace = true } orml-xcm = { workspace = true } orml-xcm-support = { workspace = true } orml-xtokens = { workspace = true } +orml-rate-limit = { workspace = true } # modules module-transaction-pause = { workspace = true } @@ -246,6 +247,7 @@ std = [ "orml-xcm-support/std", "orml-xcm/std", "orml-xtokens/std", + "orml-rate-limit/std", "module-aggregated-dex/std", "module-asset-registry/std", @@ -325,6 +327,7 @@ runtime-benchmarks = [ "orml-tokens/runtime-benchmarks", "orml-vesting/runtime-benchmarks", "orml-xtokens/runtime-benchmarks", + "orml-rate-limit/runtime-benchmarks", "module-collator-selection/runtime-benchmarks", "module-evm-accounts/runtime-benchmarks", @@ -403,6 +406,7 @@ try-runtime = [ "orml-vesting/try-runtime", "orml-xcm/try-runtime", "orml-xtokens/try-runtime", + "orml-rate-limit/try-runtime", "module-aggregated-dex/try-runtime", "module-asset-registry/try-runtime", diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index a5f2a84985..f1fc8eae1a 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -110,9 +110,9 @@ use runtime_common::{ EnsureRootOrTwoThirdsTechnicalCommittee, ExchangeRate, ExistentialDepositsTimesOneHundred, FinancialCouncilInstance, FinancialCouncilMembershipInstance, GasToWeight, GeneralCouncilInstance, GeneralCouncilMembershipInstance, HomaCouncilInstance, HomaCouncilMembershipInstance, MaxTipsOfPriority, - OperationalFeeMultiplier, OperatorMembershipInstanceAcala, Price, ProxyType, Rate, Ratio, RuntimeBlockLength, - RuntimeBlockWeights, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance, TimeStampedPrice, - TipPerWeightStep, ACA, AUSD, DOT, KSM, LCDOT, LDOT, + OperationalFeeMultiplier, OperatorMembershipInstanceAcala, Price, ProxyType, Rate, RateLimiterId, Ratio, + RuntimeBlockLength, RuntimeBlockWeights, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance, + TimeStampedPrice, TipPerWeightStep, ACA, AUSD, DOT, KSM, LCDOT, LDOT, }; use xcm::prelude::*; @@ -1835,6 +1835,16 @@ impl orml_parameters::Config for Runtime { type WeightInfo = (); } +impl orml_rate_limit::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type GovernanceOrigin = EnsureRootOrOneThirdsTechnicalCommittee; + type RateLimiterId = RateLimiterId; + type MaxWhitelistFilterCount = ConstU32<3>; + type UnixTime = Timestamp; + type BlockNumberProvider = System; + type WeightInfo = (); +} + #[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)] pub struct ConvertEthereumTx; @@ -1985,6 +1995,7 @@ construct_runtime!( Scheduler: pallet_scheduler = 2, TransactionPause: module_transaction_pause = 3, Preimage: pallet_preimage = 4, + RateLimit: orml_rate_limit = 9, // Tokens & Related Balances: pallet_balances = 10, diff --git a/runtime/mandala/src/xcm_config.rs b/runtime/mandala/src/xcm_config.rs index 237b7a4454..f4fdced3ae 100644 --- a/runtime/mandala/src/xcm_config.rs +++ b/runtime/mandala/src/xcm_config.rs @@ -19,8 +19,8 @@ use super::{ constants::fee::*, AccountId, AllPalletsWithSystem, AssetIdMapping, AssetIdMaps, Balance, Balances, Convert, Currencies, CurrencyId, EvmAddressMapping, ExistentialDeposits, GetNativeCurrencyId, NativeTokenExistentialDeposit, - ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TreasuryAccount, - UnknownTokens, XcmpQueue, ACA, + ParachainInfo, ParachainSystem, PolkadotXcm, RateLimit, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + TreasuryAccount, UnknownTokens, XcmpQueue, ACA, }; pub use cumulus_primitives_core::ParaId; pub use frame_support::{ @@ -39,7 +39,7 @@ use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use primitives::evm::is_system_contract; use runtime_common::{ local_currency_location, native_currency_location, xcm_impl::AccountKey20Aliases, AcalaDropAssets, - EnsureRootOrHalfGeneralCouncil, EnsureRootOrThreeFourthsGeneralCouncil, FixedRateOfAsset, + EnsureRootOrHalfGeneralCouncil, EnsureRootOrThreeFourthsGeneralCouncil, FixedRateOfAsset, RateLimiterId, }; use xcm::{prelude::*, v3::Weight as XcmWeight}; pub use xcm_builder::{ @@ -373,6 +373,7 @@ impl Convert for AccountIdToMultiLocation { parameter_types! { pub const BaseXcmWeight: XcmWeight = XcmWeight::from_parts(100_000_000, 0); pub const MaxAssetsForTransfer: usize = 2; + pub const XtokensRateLimiterId: RateLimiterId = RateLimiterId::XTokens; } parameter_type_with_key! { @@ -396,4 +397,6 @@ impl orml_xtokens::Config for Runtime { type MinXcmFee = ParachainMinFee; type MultiLocationsFilter = Everything; type ReserveProvider = AbsoluteReserveProvider; + type RateLimiter = RateLimit; + type RateLimiterId = XtokensRateLimiterId; }