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

Treasury spends various asset kinds #1333

Merged
merged 29 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e54e06a
pallet-treasury spends various asset kinds
muharem Aug 30, 2023
13be2fe
integrate into polkadot runtimes
muharem Aug 30, 2023
19756c8
allow unpaid execution for treasury pallet
muharem Aug 30, 2023
27e2a3e
features settings
muharem Aug 31, 2023
297308a
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
muharem Aug 31, 2023
4cd17ff
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
muharem Sep 13, 2023
3798a36
forward runtime-benchmarks feature for parachains-common and cumulus-…
muharem Sep 13, 2023
d8dc1da
box asset kind and beneficiary paramaters of treasury spend dispatchable
muharem Sep 13, 2023
d2dfcca
box asset kind paramater for asset-rate pallet dispatchables
muharem Sep 13, 2023
3225f75
format cargo tomls
muharem Sep 13, 2023
82b2887
remove unused import
muharem Sep 13, 2023
de634d3
TryConvert for asset and beneficiary in PayOverXcm
muharem Sep 14, 2023
21e385c
versioned asset kind and beneficiary
muharem Sep 14, 2023
122f1e8
fix pay over xcm tests
muharem Sep 14, 2023
249ae0e
emulated tests
muharem Sep 14, 2023
55563ec
Merge branch 'master' into muharem-multi-asset-treasury
muharem Sep 14, 2023
cbb629c
propagate features
muharem Sep 14, 2023
dea4e42
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
muharem Sep 15, 2023
7a3aefc
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
muharem Sep 18, 2023
0c4acb2
add beneficiary lookup
muharem Sep 18, 2023
b8b0135
review fixes
muharem Oct 4, 2023
d42dcfa
Apply suggestions from code review
muharem Oct 4, 2023
2a6821f
Update cumulus/parachains/integration-tests/emulated/assets/asset-hub…
muharem Oct 4, 2023
e6ae266
Merge remote-tracking branch 'origin/master' into muharem-multi-asset…
muharem Oct 4, 2023
e3185f0
setup multi asset spends for westend treasury
muharem Oct 4, 2023
682fc0e
westend test
muharem Oct 4, 2023
26c2d46
remove files related to kusama/polkadot runtimes
muharem Oct 4, 2023
26d85ed
".git/.scripts/commands/fmt/fmt.sh"
Oct 7, 2023
994aa95
Merge branch 'master' into muharem-multi-asset-treasury
joepetrowski Oct 7, 2023
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
12 changes: 12 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,24 @@ frame-system = { path = "../../../../../../substrate/frame/system", default-feat
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-treasury = { path = "../../../../../../substrate/frame/treasury", default-features = false}
pallet-asset-rate = { path = "../../../../../../substrate/frame/asset-rate", default-features = false}

# Polkadot
polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false}
polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain", default-features = false}
polkadot-runtime-common = { path = "../../../../../../polkadot/runtime/common" }
polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" }
xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false}
xcm-builder = { package = "staging-xcm-builder", path = "../../../../../../polkadot/xcm/xcm-builder", default-features = false}
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false}
pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false}

# Cumulus
parachains-common = { path = "../../../../common" }
asset-hub-westend-runtime = { path = "../../../../runtimes/assets/asset-hub-westend" }
cumulus-pallet-dmp-queue = { default-features = false, path = "../../../../../pallets/dmp-queue" }
cumulus-pallet-parachain-system = { default-features = false, path = "../../../../../pallets/parachain-system" }

# Local
xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false}
Expand All @@ -37,15 +44,21 @@ integration-tests-common = { path = "../../common", default-features = false}
[features]
runtime-benchmarks = [
"asset-hub-westend-runtime/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"integration-tests-common/runtime-benchmarks",
"pallet-asset-conversion/runtime-benchmarks",
"pallet-asset-rate/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
"polkadot-runtime-common/runtime-benchmarks",
"polkadot-runtime-parachains/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
]
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ mod send;
mod set_xcm_versions;
mod swap;
mod teleport;
mod treasury;
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// 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::*;
use frame_support::traits::fungibles::{Create, Inspect, Mutate};
use integration_tests_common::constants::accounts::{ALICE, BOB};
use polkadot_runtime_common::impls::VersionedLocatableAsset;
use xcm_executor::traits::ConvertLocation;

#[test]
fn create_and_claim_treasury_spend() {
const ASSET_ID: u32 = 1984;
const SPEND_AMOUNT: u128 = 1_000_000;
// treasury location from a sibling parachain.
let treasury_location: MultiLocation = MultiLocation::new(1, PalletInstance(37));
// treasury account on a sibling parachain.
let treasury_account =
asset_hub_westend_runtime::xcm_config::LocationToAccountId::convert_location(
&treasury_location,
)
.unwrap();
let asset_hub_location = MultiLocation::new(0, Parachain(AssetHubWestend::para_id().into()));
let root = <Westend as Chain>::RuntimeOrigin::root();
// asset kind to be spend from the treasury.
let asset_kind = VersionedLocatableAsset::V3 {
location: asset_hub_location,
asset_id: AssetId::Concrete((PalletInstance(50), GeneralIndex(ASSET_ID.into())).into()),
};
// treasury spend beneficiary.
let alice: AccountId = Westend::account_id_of(ALICE);
let bob: AccountId = Westend::account_id_of(BOB);
let bob_signed = <Westend as Chain>::RuntimeOrigin::signed(bob.clone());

AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::Assets;

// create an asset class and mint some assets to the treasury account.
assert_ok!(<Assets as Create<_>>::create(
ASSET_ID,
treasury_account.clone(),
true,
SPEND_AMOUNT / 2
));
assert_ok!(<Assets as Mutate<_>>::mint_into(ASSET_ID, &treasury_account, SPEND_AMOUNT * 4));
// beneficiary has zero balance.
assert_eq!(<Assets as Inspect<_>>::balance(ASSET_ID, &alice,), 0u128,);
});

Westend::execute_with(|| {
type RuntimeEvent = <Westend as Chain>::RuntimeEvent;
type Treasury = <Westend as WestendPallet>::Treasury;
type AssetRate = <Westend as WestendPallet>::AssetRate;

// create a conversion rate from `asset_kind` to the native currency.
assert_ok!(AssetRate::create(root.clone(), Box::new(asset_kind.clone()), 2.into()));

// create and approve a treasury spend.
assert_ok!(Treasury::spend(
root,
Box::new(asset_kind),
SPEND_AMOUNT,
Box::new(MultiLocation::new(0, Into::<[u8; 32]>::into(alice.clone())).into()),
None,
));
// claim the spend.
assert_ok!(Treasury::payout(bob_signed.clone(), 0));

assert_expected_events!(
Westend,
vec![
RuntimeEvent::Treasury(pallet_treasury::Event::Paid { .. }) => {},
]
);
});

AssetHubWestend::execute_with(|| {
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
type Assets = <AssetHubWestend as AssetHubWestendPallet>::Assets;

// assert events triggered by xcm pay program
// 1. treasury asset transferred to spend beneficiary
// 2. response to Relay Chain treasury pallet instance sent back
// 3. XCM program completed
assert_expected_events!(
AssetHubWestend,
vec![
RuntimeEvent::Assets(pallet_assets::Event::Transferred { asset_id: id, from, to, amount }) => {
id: id == &ASSET_ID,
from: from == &treasury_account,
to: to == &alice,
amount: amount == &SPEND_AMOUNT,
},
RuntimeEvent::ParachainSystem(cumulus_pallet_parachain_system::Event::UpwardMessageSent { .. }) => {},
RuntimeEvent::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward { outcome: Outcome::Complete(..) ,.. }) => {},
]
);
// beneficiary received the assets from the treasury.
assert_eq!(<Assets as Inspect<_>>::balance(ASSET_ID, &alice,), SPEND_AMOUNT,);
});

Westend::execute_with(|| {
type RuntimeEvent = <Westend as Chain>::RuntimeEvent;
type Treasury = <Westend as WestendPallet>::Treasury;

// check the payment status to ensure the response from the AssetHub was received.
assert_ok!(Treasury::check_status(bob_signed, 0));
assert_expected_events!(
Westend,
vec![
RuntimeEvent::Treasury(pallet_treasury::Event::SpendProcessed { .. }) => {},
]
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ decl_test_relay_chains! {
XcmPallet: westend_runtime::XcmPallet,
Sudo: westend_runtime::Sudo,
Balances: westend_runtime::Balances,
Treasury: westend_runtime::Treasury,
AssetRate: westend_runtime::AssetRate,
}
},
#[api_version(7)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, CurrencyAdapter,
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FungiblesAdapter, IsConcrete,
LocalMint, NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
DenyReserveTransferToRelayChain, DenyThenTry, DescribeFamily, DescribePalletTerminal,
EnsureXcmOrigin, FungiblesAdapter, HashedDescription, IsConcrete, LocalMint, NativeAsset,
NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand Down Expand Up @@ -75,6 +76,9 @@ pub type LocationToAccountId = (
SiblingParachainConvertsVia<Sibling, AccountId>,
// Straight up local `AccountId32` origins just alias directly to `AccountId`.
AccountId32Aliases<RelayNetwork, AccountId>,
// Foreign chain account alias into local accounts according to a hash of their standard
// description.
HashedDescription<AccountId, DescribeFamily<DescribePalletTerminal>>,
);

/// Means for transacting the native currency on this chain.
Expand Down Expand Up @@ -222,6 +226,9 @@ match_types! {
MultiLocation { parents: 1, interior: Here } |
MultiLocation { parents: 1, interior: X1(Plurality { .. }) }
};
pub type TreasuryPallet: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: X1(PalletInstance(37)) }
};
}

/// A call filter for the XCM Transact instruction. This is a temporary measure until we properly
Expand Down Expand Up @@ -449,8 +456,9 @@ pub type Barrier = TrailingSetTopicAsId<
// If the message is one that immediately attemps to pay for execution, then
// allow it.
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its pluralities (i.e. governance bodies) get free execution.
AllowExplicitUnpaidExecutionFrom<ParentOrParentsPlurality>,
// Parent, its pluralities (i.e. governance bodies) and treasury pallet get
// free execution.
AllowExplicitUnpaidExecutionFrom<(ParentOrParentsPlurality, TreasuryPallet)>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<Everything>,
),
Expand Down
7 changes: 7 additions & 0 deletions polkadot/runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pallet-timestamp = { path = "../../../substrate/frame/timestamp", default-featur
pallet-vesting = { path = "../../../substrate/frame/vesting", default-features = false }
pallet-transaction-payment = { path = "../../../substrate/frame/transaction-payment", default-features = false }
pallet-treasury = { path = "../../../substrate/frame/treasury", default-features = false }
pallet-asset-rate = { path = "../../../substrate/frame/asset-rate", default-features = false }
pallet-election-provider-multi-phase = { path = "../../../substrate/frame/election-provider-multi-phase", default-features = false }
frame-election-provider-support = { path = "../../../substrate/frame/election-provider-support", default-features = false }

Expand All @@ -50,6 +51,7 @@ runtime-parachains = { package = "polkadot-runtime-parachains", path = "../parac

slot-range-helper = { path = "slot_range_helper", default-features = false }
xcm = { package = "staging-xcm", path = "../../xcm", default-features = false }
xcm-builder = { package = "staging-xcm-builder", path = "../../xcm/xcm-builder", default-features = false }

[dev-dependencies]
hex-literal = "0.4.1"
Expand All @@ -74,6 +76,7 @@ std = [
"inherents/std",
"libsecp256k1/std",
"log/std",
"pallet-asset-rate/std",
"pallet-authorship/std",
"pallet-balances/std",
"pallet-election-provider-multi-phase/std",
Expand All @@ -100,6 +103,7 @@ std = [
"sp-session/std",
"sp-staking/std",
"sp-std/std",
"xcm-builder/std",
"xcm/std",
]
runtime-benchmarks = [
Expand All @@ -109,6 +113,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"libsecp256k1/hmac",
"libsecp256k1/static-context",
"pallet-asset-rate/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
Expand All @@ -121,12 +126,14 @@ runtime-benchmarks = [
"runtime-parachains/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
]
try-runtime = [
"frame-election-provider-support/try-runtime",
"frame-support-test/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-asset-rate/try-runtime",
"pallet-authorship/try-runtime",
"pallet-babe?/try-runtime",
"pallet-balances/try-runtime",
Expand Down
Loading