diff --git a/Cargo.lock b/Cargo.lock index db87de219ef97fafac7cdc5155800ca344a25d57..32dee11171fdc57382fbd8c0d64e40a006064c13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -947,6 +947,7 @@ dependencies = [ "emulated-integration-tests-common", "frame-support", "pallet-asset-conversion", + "pallet-asset-rewards", "pallet-assets", "pallet-balances", "pallet-message-queue", diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index 87cb8cba13b8606b3c738279965dd9bfefc5a065..1bde52f2e75a97180901fe0abc243337df599303 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -58,6 +58,7 @@ pub const TELEPORTABLE_ASSET_ID: u32 = 2; pub const PENPAL_ID: u32 = 2000; pub const ASSET_HUB_ROCOCO_ID: u32 = 1000; +pub const ASSET_HUB_WESTEND_ID: u32 = 1000; pub const ASSETS_PALLET_ID: u8 = 50; parameter_types! { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/treasury_asset_reward_pool.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/treasury_asset_reward_pool.rs index 309f69428e5682bb87e0c87a384761ac0ef2513c..4dd23dbca78ea6a462c6a96fbd1b996191407df7 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/treasury_asset_reward_pool.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/treasury_asset_reward_pool.rs @@ -14,6 +14,7 @@ // limitations under the License. use crate::imports::*; +use asset_hub_rococo_runtime::xcm_config::TokenLocationV3; use codec::Encode; use emulated_integration_tests_common::ASSET_HUB_ROCOCO_ID; use frame_support::{assert_ok, sp_runtime::traits::Dispatchable}; @@ -28,8 +29,9 @@ fn treasury_creates_asset_reward_pool() { type RococoRuntimeEvent = <Rococo as Chain>::RuntimeEvent; type RococoRuntimeOrigin = <Rococo as Chain>::RuntimeOrigin; - let staked_asset_id = bx!(xcm::v3::Junction::PalletInstance(1).into()); - let reward_asset_id = bx!(xcm::v3::Junction::PalletInstance(2).into()); + let staked_asset_id = bx!(TokenLocationV3::get()); + let reward_asset_id = bx!(TokenLocationV3::get()); + let reward_rate_per_block = 1_000_000_000; let expiry_block = 1_000_000_000; let admin = None; @@ -61,9 +63,7 @@ fn treasury_creates_asset_reward_pool() { let treasury_origin: RococoRuntimeOrigin = rococo_runtime::governance::pallet_custom_origins::Origin::Treasurer.into(); - // TODO: Figure out how to enable treasury origin - // assert_ok!(create_pool_call.dispatch(treasury_origin)); - assert_ok!(create_pool_call.dispatch(RococoRuntimeOrigin::root())); + assert_ok!(create_pool_call.dispatch(treasury_origin)); assert_expected_events!( Rococo, @@ -74,6 +74,18 @@ fn treasury_creates_asset_reward_pool() { }); AssetHubRococo::execute_with(|| { - // TODO: Check that the pool was created + type AssetHubRococoRuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent; + assert_expected_events!( + AssetHubRococo, + vec![ + AssetHubRococoRuntimeEvent::AssetRewards( + pallet_asset_rewards::Event::PoolCreated { + .. + } + ) => { + }, + + ] + ); }); } diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/Cargo.toml index 00f4308324a96734afac879cafd1e51300407a26..4c089a472641c0f020846cadb18e45d2a3d07232 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/Cargo.toml @@ -20,6 +20,7 @@ frame-support = { path = "../../../../../../../substrate/frame/support", default pallet-balances = { path = "../../../../../../../substrate/frame/balances", default-features = false } pallet-assets = { path = "../../../../../../../substrate/frame/assets", default-features = false } pallet-asset-conversion = { path = "../../../../../../../substrate/frame/asset-conversion", default-features = false } +pallet-asset-rewards = { path = "../../../../../../../substrate/frame/asset-rewards", default-features = false } pallet-treasury = { path = "../../../../../../../substrate/frame/treasury", default-features = false } pallet-message-queue = { path = "../../../../../../../substrate/frame/message-queue", default-features = false } diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/mod.rs index e463e21e9e5295a7c33efc30006299ee2a801902..9c427d64e795f9c7bb421472ce8dc77e0850cdf9 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/mod.rs @@ -21,3 +21,4 @@ mod set_xcm_versions; mod swap; mod teleport; mod treasury; +mod treasury_asset_reward_pool; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/treasury_asset_reward_pool.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/treasury_asset_reward_pool.rs new file mode 100644 index 0000000000000000000000000000000000000000..9e9166da18728ac29292c86d8294af7a46c38ccd --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/treasury_asset_reward_pool.rs @@ -0,0 +1,91 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::imports::*; +use asset_hub_westend_runtime::xcm_config::WestendLocationV3; +use codec::Encode; +use emulated_integration_tests_common::ASSET_HUB_WESTEND_ID; +use frame_support::{assert_ok, sp_runtime::traits::Dispatchable}; + +#[test] +fn treasury_creates_asset_reward_pool() { + Westend::execute_with(|| { + type AssetHubWestendRuntimeCall = <AssetHubWestend as Chain>::RuntimeCall; + type AssetHubWestendRuntime = <AssetHubWestend as Chain>::Runtime; + type WestendRuntimeCall = <Westend as Chain>::RuntimeCall; + type WestendRuntime = <Westend as Chain>::Runtime; + type WestendRuntimeEvent = <Westend as Chain>::RuntimeEvent; + type WestendRuntimeOrigin = <Westend as Chain>::RuntimeOrigin; + + let staked_asset_id = bx!(WestendLocationV3::get()); + let reward_asset_id = bx!(WestendLocationV3::get()); + + let reward_rate_per_block = 1_000_000_000; + let expiry_block = 1_000_000_000; + let admin = None; + + let create_pool_call = + WestendRuntimeCall::XcmPallet(pallet_xcm::Call::<WestendRuntime>::send { + dest: bx!(VersionedLocation::V4( + xcm::v4::Junction::Parachain(ASSET_HUB_WESTEND_ID).into() + )), + message: bx!(VersionedXcm::V4(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind: OriginKind::Xcm, + require_weight_at_most: Weight::from_parts(5_000_000_000, 500_000), + call: AssetHubWestendRuntimeCall::AssetRewards( + pallet_asset_rewards::Call::<AssetHubWestendRuntime>::create_pool { + staked_asset_id, + reward_asset_id, + reward_rate_per_block, + expiry_block, + admin + } + ) + .encode() + .into(), + } + ]))), + }); + + let treasury_origin: WestendRuntimeOrigin = + westend_runtime::governance::pallet_custom_origins::Origin::Treasurer.into(); + assert_ok!(create_pool_call.dispatch(treasury_origin)); + + assert_expected_events!( + Westend, + vec![ + WestendRuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + AssetHubWestend::execute_with(|| { + type AssetHubWestendRuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent; + assert_expected_events!( + AssetHubWestend, + vec![ + AssetHubWestendRuntimeEvent::AssetRewards( + pallet_asset_rewards::Event::PoolCreated { + .. + } + ) => { + }, + + ] + ); + }); +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index 4e525261931a4286601ed79c6961df5aa573fab5..0442ee2db883781b7ebed6ce469c7fc8393ca318 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -296,10 +296,11 @@ impl Contains<RuntimeCall> for SafeCallFilter { matches!( call, - RuntimeCall::PolkadotXcm( - pallet_xcm::Call::force_xcm_version { .. } | - pallet_xcm::Call::force_default_xcm_version { .. } - ) | RuntimeCall::System( + RuntimeCall::AssetRewards(pallet_asset_rewards::Call::create_pool { .. }) | + RuntimeCall::PolkadotXcm( + pallet_xcm::Call::force_xcm_version { .. } | + pallet_xcm::Call::force_default_xcm_version { .. } + ) | RuntimeCall::System( frame_system::Call::set_heap_pages { .. } | frame_system::Call::set_code { .. } | frame_system::Call::set_code_without_checks { .. } | diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 7105925fc9f7e0bb02b1287d1ed1c4c539981818..d9d66cc2bf950389a9edbb12f6c880de5f637869 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -308,10 +308,11 @@ impl Contains<RuntimeCall> for SafeCallFilter { matches!( call, - RuntimeCall::PolkadotXcm( - pallet_xcm::Call::force_xcm_version { .. } | - pallet_xcm::Call::force_default_xcm_version { .. } - ) | RuntimeCall::System( + RuntimeCall::AssetRewards(pallet_asset_rewards::Call::create_pool { .. }) | + RuntimeCall::PolkadotXcm( + pallet_xcm::Call::force_xcm_version { .. } | + pallet_xcm::Call::force_default_xcm_version { .. } + ) | RuntimeCall::System( frame_system::Call::set_heap_pages { .. } | frame_system::Call::set_code { .. } | frame_system::Call::set_code_without_checks { .. } | diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs index c7063bd7ad616c2e5cb7b2e3f8c397087e522c33..dd8660d77509d873aa46324cee7744b447351d34 100644 --- a/polkadot/runtime/rococo/src/xcm_config.rs +++ b/polkadot/runtime/rococo/src/xcm_config.rs @@ -18,7 +18,8 @@ use super::{ parachains_origin, AccountId, AllPalletsWithSystem, Balances, Dmp, Fellows, ParaId, Runtime, - RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, Treasury, WeightToFee, XcmPallet, + RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, Treasurer, Treasury, WeightToFee, + XcmPallet, }; use crate::governance::StakingAdmin; @@ -227,11 +228,14 @@ impl xcm_executor::Config for XcmConfig { } parameter_types! { + /// Collective pluralistic body. pub const CollectiveBodyId: BodyId = BodyId::Unit; - // StakingAdmin pluralistic body. + /// StakingAdmin pluralistic body. pub const StakingAdminBodyId: BodyId = BodyId::Defense; - // Fellows pluralistic body. + /// Fellows pluralistic body. pub const FellowsBodyId: BodyId = BodyId::Technical; + /// Treasury pluralistic body. + pub const TreasuryBodyId: BodyId = BodyId::Treasury; } /// Type to convert an `Origin` type value into a `Location` value which represents an interior @@ -248,6 +252,9 @@ pub type StakingAdminToPlurality = /// Type to convert the Fellows origin to a Plurality `Location` value. pub type FellowsToPlurality = OriginToPluralityVoice<RuntimeOrigin, Fellows, FellowsBodyId>; +/// Type to convert the Treasury origin to a Plurality `Location` value. +pub type TreasurerToPlurality = OriginToPluralityVoice<RuntimeOrigin, Treasurer, TreasuryBodyId>; + /// Type to convert a pallet `Origin` type value into a `Location` value which represents an /// interior location of this chain for a destination chain. pub type LocalPalletOriginToLocation = ( @@ -255,13 +262,15 @@ pub type LocalPalletOriginToLocation = ( StakingAdminToPlurality, // Fellows origin to be used in XCM as a corresponding Plurality `Location` value. FellowsToPlurality, + // Treasurer origin to be used in XCM as a corresponding Plurality `Location` value. + TreasurerToPlurality, ); impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; // Note that this configuration of `SendXcmOrigin` is different from the one present in // production. - type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalPalletOriginToLocation>; type XcmRouter = XcmRouter; // Anyone can execute XCM messages locally. type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>; diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs index f661c4b0e4f437a2f2d597d8bdef26e0b76930c3..a06df2a19683253b6741f44fa5ff3d970898fd46 100644 --- a/polkadot/runtime/westend/src/xcm_config.rs +++ b/polkadot/runtime/westend/src/xcm_config.rs @@ -274,7 +274,7 @@ impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; // Note that this configuration of `SendXcmOrigin` is different from the one present in // production. - type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalPalletOriginToLocation>; type XcmRouter = XcmRouter; // Anyone can execute XCM messages locally. type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;