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

add rate limit for xtokens transfer #2652

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
22 changes: 22 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ members = [
"orml/oracle",
"orml/parameters",
"orml/payments",
"orml/rate-limit",
"orml/rewards",
"orml/tokens",
"orml/tokens/runtime-api",
Expand Down Expand Up @@ -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 }
Expand Down
4 changes: 4 additions & 0 deletions runtime/acala/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
17 changes: 14 additions & 3 deletions runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions runtime/acala/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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};
Expand Down Expand Up @@ -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! {
Expand Down Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -168,6 +170,7 @@ wasm-bench = [
"orml-currencies",
"orml-nft",
"orml-rewards",
"orml-rate-limit",
"orml-tokens/runtime-benchmarks",

"xcm-builder/runtime-benchmarks",
Expand Down
12 changes: 12 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<H160>) -> BTreeMap<H160, GenesisAccount<Balance, primitives::Nonce>> {
Expand Down
2 changes: 2 additions & 0 deletions runtime/common/src/precompile/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
4 changes: 4 additions & 0 deletions runtime/karura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
17 changes: 14 additions & 3 deletions runtime/karura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions runtime/karura/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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};
Expand Down Expand Up @@ -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! {
Expand Down Expand Up @@ -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 = (
Expand Down
4 changes: 4 additions & 0 deletions runtime/mandala/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading