diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml index c2090d102a56fafd650d1f74802d252224533a7b..035ca061af1f44cf20d11167fda368111223d63b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml @@ -144,6 +144,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", + "pallet-asset-rewards/runtime-benchmarks" ] try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", @@ -177,6 +178,7 @@ try-runtime = [ "parachain-info/try-runtime", "polkadot-runtime-common/try-runtime", "sp-runtime/try-runtime", + "pallet-asset-rewards/try-runtime" ] std = [ "assets-common/std", @@ -252,6 +254,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "pallet-asset-rewards/std" ] # A feature that should be enabled when the runtime should be built for on-chain diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 22687addb57cba808a05789957dbf5ba316acba8..9d75f8854f57dab3a0f8a0a03df77586a7df0564 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -68,7 +68,7 @@ use frame_support::{ }; use frame_system::{ limits::{BlockLength, BlockWeights}, - EnsureRoot, EnsureSigned, EnsureSignedBy, + EnsureRoot, EnsureSigned, EnsureSignedBy, EnsureWithSuccess, }; use pallet_asset_conversion_tx_payment::AssetConversionAdapter; use pallet_nfts::PalletFeatures; @@ -77,6 +77,7 @@ use parachains_common::{ message_queue::{NarrowOriginToSibling, ParaIdToSibling}, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, CollectionId, Hash, Header, ItemId, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO, NORMAL_DISPATCH_RATIO, + TREASURY_PALLET_ID, }; use sp_runtime::{Perbill, RuntimeDebug}; use testnet_parachains_constants::rococo::{consensus::*, currency::*, fee::WeightToFee, time::*}; @@ -336,7 +337,7 @@ pub type NativeAndNonPoolAssets = fungible::UnionOf< /// Union fungibles implementation for [`PoolAssets`] and [`NativeAndAssets`]. /// -/// Should be kept updated to include ALL balances and assets in the runtime. +/// NOTE: Should be kept updated to include ALL balances and assets in the runtime. pub type NativeAndAllAssets = fungibles::UnionOf< PoolAssets, NativeAndNonPoolAssets, @@ -903,9 +904,40 @@ impl pallet_xcm_bridge_hub_router::Config<ToWestendXcmRouterInstance> for Runtim type FeeAsset = xcm_config::bridging::XcmBridgeHubRouterFeeAssetId; } +#[cfg(feature = "runtime-benchmarks")] +use crate::fungible::NativeOrWithId; + +#[cfg(feature = "runtime-benchmarks")] +use frame_support::traits::PalletInfoAccess; + +#[cfg(feature = "runtime-benchmarks")] +pub struct PalletAssetRewardsBenchmarkHelper; + +#[cfg(feature = "runtime-benchmarks")] +impl pallet_asset_rewards::benchmarking::BenchmarkHelper<xcm::v3::Location, AccountId> + for PalletAssetRewardsBenchmarkHelper +{ + fn to_asset_id(seed: NativeOrWithId<u32>) -> xcm::v3::Location { + match seed { + NativeOrWithId::Native => xcm::v3::Location::here().into(), + NativeOrWithId::WithId(id) => xcm::v3::Location::ancestor(id.try_into().unwrap()), + } + } + fn to_account_id(seed: u32) -> AccountId { + let mut bytes = [0u8; 32]; + bytes[0..4].copy_from_slice(&seed.to_be_bytes()); + bytes.into() + } + fn sufficient_asset() -> xcm::v3::Location { + xcm::v3::Junction::PalletInstance(<Balances as PalletInfoAccess>::index() as u8).into() + } +} + parameter_types! { - pub const AssetRewardsPalletId: PalletId = PalletId(*b"py/asrwd"); + pub const AssetRewardsPalletId: PalletId = PalletId(*b"py/astrd"); pub const TreasurerBodyId: BodyId = BodyId::Treasury; + pub TreasurerBodyAccount: AccountId = + AccountIdConversion::<AccountId>::into_account_truncating(&TREASURY_PALLET_ID); } impl pallet_asset_rewards::Config for Runtime { @@ -914,12 +946,13 @@ impl pallet_asset_rewards::Config for Runtime { type Balance = Balance; type Assets = NativeAndAllAssets; type AssetId = xcm::v3::Location; - type PermissionedPoolCreator = EitherOfDiverse< - EnsureRoot<AccountId>, + type PermissionedOrigin = EnsureWithSuccess< EnsureXcm<IsVoiceOfBody<GovernanceLocation, TreasurerBodyId>>, + AccountId, + TreasurerBodyAccount, >; #[cfg(feature = "runtime-benchmarks")] - type BenchmarkHelper = (); + type BenchmarkHelper = PalletAssetRewardsBenchmarkHelper; } // Create the runtime by composing the FRAME pallets that were previously configured.