Skip to content

Commit

Permalink
Treasury Pallet Account as destination for XCM fees on System Paracha…
Browse files Browse the repository at this point in the history
…ins (#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 <[email protected]>
  • Loading branch information
muharem and Szegoo authored Mar 6, 2024
1 parent 71ddd5f commit 35048df
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -562,7 +570,7 @@ impl xcm_executor::Config for XcmConfig {
type AssetExchanger = ();
type FeeManager = XcmFeeManagerFromComponents<
WaivedLocations,
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
XcmFeeToAccount<Self::AssetTransactor, AccountId, RelayTreasuryPalletAccount>,
>;
type MessageExporter = ();
type UniversalAliases = bridging::to_polkadot::UniversalAliases;
Expand Down
14 changes: 11 additions & 3 deletions system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()),
)
}

Expand Down Expand Up @@ -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()
)
}
12 changes: 10 additions & 2 deletions system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -512,7 +520,7 @@ impl xcm_executor::Config for XcmConfig {
type AssetExchanger = ();
type FeeManager = XcmFeeManagerFromComponents<
WaivedLocations,
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
XcmFeeToAccount<Self::AssetTransactor, AccountId, RelayTreasuryPalletAccount>,
>;
type MessageExporter = ();
type UniversalAliases = bridging::to_kusama::UniversalAliases;
Expand Down
14 changes: 11 additions & 3 deletions system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()),
)
}

Expand Down Expand Up @@ -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()
)
}
20 changes: 18 additions & 2 deletions system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -266,7 +274,7 @@ impl xcm_executor::Config for XcmConfig {
type AssetExchanger = ();
type FeeManager = XcmFeeManagerFromComponents<
WaivedLocations,
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
XcmFeeToAccount<Self::AssetTransactor, AccountId, RelayTreasuryPalletAccount>,
>;
type MessageExporter = ToBridgeHubPolkadotHaulBlobExporter;
type UniversalAliases = Nothing;
Expand Down Expand Up @@ -326,3 +334,11 @@ impl cumulus_pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type XcmExecutor = XcmExecutor<XcmConfig>;
}

#[test]
fn treasury_pallet_account_not_none() {
assert_eq!(
RelayTreasuryPalletAccount::get(),
LocationToAccountId::convert_location(&RelayTreasuryLocation::get()).unwrap()
)
}
14 changes: 13 additions & 1 deletion system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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 `[email protected]` bump (https://github.com/polkadot-fellows/runtimes/issues/186)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -285,7 +293,7 @@ impl xcm_executor::Config for XcmConfig {
type AssetExchanger = ();
type FeeManager = XcmFeeManagerFromComponents<
WaivedLocations,
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
XcmFeeToAccount<Self::AssetTransactor, AccountId, RelayTreasuryPalletAccount>,
>;
type MessageExporter = ToBridgeHubKusamaHaulBlobExporter;
type UniversalAliases = Nothing;
Expand Down
14 changes: 13 additions & 1 deletion system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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 `[email protected]` 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -294,7 +302,7 @@ impl xcm_executor::Config for XcmConfig {
type AssetExchanger = ();
type FeeManager = XcmFeeManagerFromComponents<
WaivedLocations,
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
XcmFeeToAccount<Self::AssetTransactor, AccountId, RelayTreasuryPalletAccount>,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
Expand Down Expand Up @@ -353,3 +361,11 @@ impl cumulus_pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type XcmExecutor = XcmExecutor<XcmConfig>;
}

#[test]
fn treasury_pallet_account_not_none() {
assert_eq!(
RelayTreasuryPalletAccount::get(),
LocationToAccountId::convert_location(&RelayTreasuryLocation::get()).unwrap()
)
}

0 comments on commit 35048df

Please sign in to comment.