From 35048df6418f2ad9e0b8171e083c4e3839b2a691 Mon Sep 17 00:00:00 2001 From: Muharem Date: Wed, 6 Mar 2024 13:55:21 +0100 Subject: [PATCH] Treasury Pallet Account as destination for XCM fees on System Parachains (#191) Designates the Treasury Pallet Account as the destination for XCM fees on System Parachains. This ensures that assets accumulated in the pallet's account can be spent by Treasury Origins from Relay Chains. --------- Co-authored-by: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> --- CHANGELOG.md | 1 + .../asset-hub-kusama/src/xcm_config.rs | 12 +++++++++-- .../asset-hub-kusama/tests/tests.rs | 14 ++++++++++--- .../asset-hub-polkadot/src/xcm_config.rs | 12 +++++++++-- .../asset-hub-polkadot/tests/tests.rs | 14 ++++++++++--- .../bridge-hub-kusama/src/xcm_config.rs | 20 +++++++++++++++++-- .../bridge-hub-kusama/tests/tests.rs | 14 ++++++++++++- .../bridge-hub-polkadot/src/xcm_config.rs | 12 +++++++++-- .../bridge-hub-polkadot/tests/tests.rs | 14 ++++++++++++- .../collectives-polkadot/src/xcm_config.rs | 20 +++++++++++++++++-- 10 files changed, 115 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa688224a6..b2a0f9c18f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Deprecate the `xcm::body::TREASURER_INDEX` constant and use the standard `Treasury` variant from the `xcm::BodyId` type instead ([polkadot-fellows/runtimes#149](https://github.com/polkadot-fellows/runtimes/pull/149)) - Bump parachains runtime API to v9 in Kusama to enable the `node_features` function [polkadot-fellows/runtimes#194](https://github.com/polkadot-fellows/runtimes/pull/194) - Bump parachains runtime API to v10 in Kusama to enable the `approval-voting-params` function [polkadot-fellows/runtimes#204](https://github.com/polkadot-fellows/runtimes/pull/204) +- Use Relay Chain's Treasury Pallet account as a destination for XCM fees on System Parachain ([polkadot-fellows/runtimes#191](https://github.com/polkadot-fellows/runtimes/pull/191)) ### Removed diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs index 96ac90bc43..cb4a71067f 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs @@ -49,7 +49,10 @@ use xcm_builder::{ TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, XcmFeeToAccount, }; -use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; +use xcm_executor::{ + traits::{ConvertLocation, WithOriginFilter}, + XcmExecutor, +}; parameter_types! { pub const KsmLocation: Location = Location::parent(); @@ -73,6 +76,11 @@ parameter_types! { pub const FellowshipLocation: Location = Location::parent(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(kusama_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); + // Test [`crate::tests::treasury_pallet_account_not_none`] ensures that the result of location + // conversion is not `None`. + pub RelayTreasuryPalletAccount: AccountId = + LocationToAccountId::convert_location(&RelayTreasuryLocation::get()) + .unwrap_or(TreasuryAccount::get()); } /// Type for specifying how a `Location` can be converted into an `AccountId`. This is used @@ -562,7 +570,7 @@ impl xcm_executor::Config for XcmConfig { type AssetExchanger = (); type FeeManager = XcmFeeManagerFromComponents< WaivedLocations, - XcmFeeToAccount, + XcmFeeToAccount, >; type MessageExporter = (); type UniversalAliases = bridging::to_polkadot::UniversalAliases; diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index 602b8e23be..3c8c204a0a 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -21,8 +21,8 @@ use asset_hub_kusama_runtime::{ xcm_config::{ bridging::{self, XcmBridgeHubRouterFeeAssetId}, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, - ForeignCreatorsSovereignAccountOf, KsmLocation, LocationToAccountId, TreasuryAccount, - TrustBackedAssetsPalletLocation, XcmConfig, + ForeignCreatorsSovereignAccountOf, KsmLocation, LocationToAccountId, RelayTreasuryLocation, + RelayTreasuryPalletAccount, TrustBackedAssetsPalletLocation, XcmConfig, }, AllPalletsWithoutSystem, AssetDeposit, Assets, Balances, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, @@ -717,7 +717,7 @@ fn limited_reserve_transfer_assets_for_native_asset_to_asset_hub_polkadot_works( bridging_to_asset_hub_polkadot, WeightLimit::Unlimited, Some(XcmBridgeHubRouterFeeAssetId::get()), - Some(TreasuryAccount::get()), + Some(RelayTreasuryPalletAccount::get()), ) } @@ -923,3 +923,11 @@ fn change_xcm_bridge_hub_router_byte_fee_by_governance_works() { }, ) } + +#[test] +fn treasury_pallet_account_not_none() { + assert_eq!( + RelayTreasuryPalletAccount::get(), + LocationToAccountId::convert_location(&RelayTreasuryLocation::get()).unwrap() + ) +} diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index b662f16d6e..fe276f1d2f 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -50,7 +50,10 @@ use xcm_builder::{ TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, XcmFeeToAccount, }; -use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; +use xcm_executor::{ + traits::{ConvertLocation, WithOriginFilter}, + XcmExecutor, +}; parameter_types! { pub const DotLocation: Location = Location::parent(); @@ -66,6 +69,11 @@ parameter_types! { pub const GovernanceLocation: Location = Location::parent(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); + // Test [`crate::tests::treasury_pallet_account_not_none`] ensures that the result of location + // conversion is not `None`. + pub RelayTreasuryPalletAccount: AccountId = + LocationToAccountId::convert_location(&RelayTreasuryLocation::get()) + .unwrap_or(TreasuryAccount::get()); } /// Type for specifying how a `Location` can be converted into an `AccountId`. This is used @@ -512,7 +520,7 @@ impl xcm_executor::Config for XcmConfig { type AssetExchanger = (); type FeeManager = XcmFeeManagerFromComponents< WaivedLocations, - XcmFeeToAccount, + XcmFeeToAccount, >; type MessageExporter = (); type UniversalAliases = bridging::to_kusama::UniversalAliases; diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index 5ffc407a30..08949a1157 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -21,8 +21,8 @@ use asset_hub_polkadot_runtime::{ xcm_config::{ bridging::{self, XcmBridgeHubRouterFeeAssetId}, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount, DotLocation, - ForeignCreatorsSovereignAccountOf, LocationToAccountId, TreasuryAccount, - TrustBackedAssetsPalletLocation, XcmConfig, + ForeignCreatorsSovereignAccountOf, LocationToAccountId, RelayTreasuryLocation, + RelayTreasuryPalletAccount, TrustBackedAssetsPalletLocation, XcmConfig, }, AllPalletsWithoutSystem, AssetDeposit, Assets, Balances, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, @@ -731,7 +731,7 @@ fn limited_reserve_transfer_assets_for_native_asset_to_asset_hub_kusama_works() bridging_to_asset_hub_kusama, WeightLimit::Unlimited, Some(XcmBridgeHubRouterFeeAssetId::get()), - Some(TreasuryAccount::get()), + Some(RelayTreasuryPalletAccount::get()), ) } @@ -935,3 +935,11 @@ fn change_xcm_bridge_hub_router_byte_fee_by_governance_works() { }, ) } + +#[test] +fn treasury_pallet_account_not_none() { + assert_eq!( + RelayTreasuryPalletAccount::get(), + LocationToAccountId::convert_location(&RelayTreasuryLocation::get()).unwrap() + ) +} diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index 8e0d5a9562..828904565b 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -49,7 +49,10 @@ use xcm_builder::{ TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, XcmFeeToAccount, }; -use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; +use xcm_executor::{ + traits::{ConvertLocation, WithOriginFilter}, + XcmExecutor, +}; parameter_types! { pub const KsmRelayLocation: Location = Location::parent(); @@ -63,6 +66,11 @@ parameter_types! { pub const FellowshipLocation: Location = Location::parent(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(kusama_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); + // Test [`crate::tests::treasury_pallet_account_not_none`] ensures that the result of location + // conversion is not `None`. + pub RelayTreasuryPalletAccount: AccountId = + LocationToAccountId::convert_location(&RelayTreasuryLocation::get()) + .unwrap_or(TreasuryAccount::get()); } /// Type for specifying how a `Location` can be converted into an `AccountId`. This is used @@ -266,7 +274,7 @@ impl xcm_executor::Config for XcmConfig { type AssetExchanger = (); type FeeManager = XcmFeeManagerFromComponents< WaivedLocations, - XcmFeeToAccount, + XcmFeeToAccount, >; type MessageExporter = ToBridgeHubPolkadotHaulBlobExporter; type UniversalAliases = Nothing; @@ -326,3 +334,11 @@ impl cumulus_pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; } + +#[test] +fn treasury_pallet_account_not_none() { + assert_eq!( + RelayTreasuryPalletAccount::get(), + LocationToAccountId::convert_location(&RelayTreasuryLocation::get()).unwrap() + ) +} diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs index b0856de882..74e0f4c4a2 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs @@ -23,7 +23,10 @@ use bridge_hub_kusama_runtime::{ RequiredStakeForStakeAndSlash, WithBridgeHubPolkadotMessageBridge, WithBridgeHubPolkadotMessagesInstance, XCM_LANE_FOR_ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT, }, - xcm_config::{KsmRelayLocation, RelayNetwork, XcmConfig}, + xcm_config::{ + KsmRelayLocation, LocationToAccountId, RelayNetwork, RelayTreasuryLocation, + RelayTreasuryPalletAccount, XcmConfig, + }, AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages, Executive, ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys, SignedExtra, TransactionPayment, UncheckedExtrinsic, SLOT_DURATION, @@ -42,6 +45,7 @@ use system_parachains_constants::kusama::{ consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, fee::WeightToFee, }; use xcm::latest::prelude::*; +use xcm_executor::traits::ConvertLocation; // Para id of sibling chain used in tests. pub const SIBLING_PARACHAIN_ID: u32 = 1000; @@ -360,6 +364,14 @@ pub fn can_calculate_fee_for_complex_message_confirmation_transaction() { ) } +#[test] +fn treasury_pallet_account_not_none() { + assert_eq!( + RelayTreasuryPalletAccount::get(), + LocationToAccountId::convert_location(&RelayTreasuryLocation::get()).unwrap() + ) +} + use sp_runtime::Perbill; // TODO:(PR#159): remove when `polkadot-sdk@1.8.0` bump (https://github.com/polkadot-fellows/runtimes/issues/186) diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 2051bca78e..c28e8b89ab 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -50,7 +50,10 @@ use xcm_builder::{ TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, XcmFeeToAccount, }; -use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; +use xcm_executor::{ + traits::{ConvertLocation, WithOriginFilter}, + XcmExecutor, +}; parameter_types! { pub const DotRelayLocation: Location = Location::parent(); @@ -64,6 +67,11 @@ parameter_types! { pub const GovernanceLocation: Location = Location::parent(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); + // Test [`crate::tests::treasury_pallet_account_not_none`] ensures that the result of location + // conversion is not `None`. + pub RelayTreasuryPalletAccount: AccountId = + LocationToAccountId::convert_location(&RelayTreasuryLocation::get()) + .unwrap_or(TreasuryAccount::get()); } /// Type for specifying how a `Location` can be converted into an `AccountId`. This is used @@ -285,7 +293,7 @@ impl xcm_executor::Config for XcmConfig { type AssetExchanger = (); type FeeManager = XcmFeeManagerFromComponents< WaivedLocations, - XcmFeeToAccount, + XcmFeeToAccount, >; type MessageExporter = ToBridgeHubKusamaHaulBlobExporter; type UniversalAliases = Nothing; diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs index e1081d3eee..0f03bd3415 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs @@ -24,7 +24,10 @@ use bridge_hub_polkadot_runtime::{ WithBridgeHubKusamaMessageBridge, WithBridgeHubKusamaMessagesInstance, XCM_LANE_FOR_ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA, }, - xcm_config::{DotRelayLocation, RelayNetwork, XcmConfig}, + xcm_config::{ + DotRelayLocation, LocationToAccountId, RelayNetwork, RelayTreasuryLocation, + RelayTreasuryPalletAccount, XcmConfig, + }, AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages, Executive, ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys, SignedExtra, TransactionPayment, UncheckedExtrinsic, SLOT_DURATION, @@ -43,6 +46,7 @@ use system_parachains_constants::polkadot::{ consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, fee::WeightToFee, }; use xcm::latest::prelude::*; +use xcm_executor::traits::ConvertLocation; // Para id of sibling chain used in tests. pub const SIBLING_PARACHAIN_ID: u32 = 1000; @@ -361,6 +365,14 @@ pub fn can_calculate_fee_for_complex_message_confirmation_transaction() { ) } +#[test] +fn treasury_pallet_account_not_none() { + assert_eq!( + RelayTreasuryPalletAccount::get(), + LocationToAccountId::convert_location(&RelayTreasuryLocation::get()).unwrap() + ) +} + // TODO:(PR#159): remove when `polkadot-sdk@1.8.0` bump (https://github.com/polkadot-fellows/runtimes/issues/186) /// A helper function for comparing the actual value of a fee constant with its estimated value. The /// estimated value can be overestimated (`overestimate_in_percent`), and if the difference to the diff --git a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs index e6ebbd8687..d81523c75a 100644 --- a/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs +++ b/system-parachains/collectives/collectives-polkadot/src/xcm_config.rs @@ -47,7 +47,10 @@ use xcm_builder::{ UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, XcmFeeToAccount, }; -use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; +use xcm_executor::{ + traits::{ConvertLocation, WithOriginFilter}, + XcmExecutor, +}; parameter_types! { pub const RootLocation: Location = Location::here(); @@ -61,6 +64,11 @@ parameter_types! { pub RelayTreasuryLocation: Location = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); pub const TreasurerBodyId: BodyId = BodyId::Treasury; + // Test [`treasury_pallet_account_not_none`] ensures that the result of location conversion is + // not `None`. + pub RelayTreasuryPalletAccount: AccountId = + LocationToAccountId::convert_location(&RelayTreasuryLocation::get()) + .unwrap_or(TreasuryAccount::get()); } /// Type for specifying how a `Location` can be converted into an `AccountId`. This is used @@ -294,7 +302,7 @@ impl xcm_executor::Config for XcmConfig { type AssetExchanger = (); type FeeManager = XcmFeeManagerFromComponents< WaivedLocations, - XcmFeeToAccount, + XcmFeeToAccount, >; type MessageExporter = (); type UniversalAliases = Nothing; @@ -353,3 +361,11 @@ impl cumulus_pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; } + +#[test] +fn treasury_pallet_account_not_none() { + assert_eq!( + RelayTreasuryPalletAccount::get(), + LocationToAccountId::convert_location(&RelayTreasuryLocation::get()).unwrap() + ) +}