Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
89ccc72
WIP
gui1117 Apr 15, 2024
e286945
rename
gui1117 Apr 16, 2024
a716e0f
Merge remote-tracking branch 'origin/master' into gui-assets-revoke-t…
gui1117 Apr 16, 2024
9430c24
version and prdoc
gui1117 Apr 16, 2024
f185216
doc
gui1117 Apr 16, 2024
ef36ecf
formatting refactoring
gui1117 Apr 16, 2024
4f61356
prdoc
gui1117 Apr 16, 2024
31ebf61
Merge remote-tracking branch 'origin/master' into gui-assets-revoke-t…
gui1117 Apr 23, 2024
1c8185d
address comments improves prdoc
gui1117 Apr 23, 2024
fb0a90c
safer internal API
gui1117 Apr 23, 2024
602eeab
doc
gui1117 Apr 23, 2024
18358ad
reorg and fix destroying assert
gui1117 Apr 23, 2024
f7021bb
fmt and typo
gui1117 Apr 23, 2024
a2a3a26
make runtimes burn when privilege is revoked
gui1117 Apr 23, 2024
e2315c6
fmt
gui1117 Apr 23, 2024
27cf5a8
weights
gui1117 Apr 23, 2024
b5884a2
fake weight before benchmarking with bot
gui1117 Apr 23, 2024
a9f51b5
fix
gui1117 Apr 23, 2024
250b321
prdoc
gui1117 Apr 23, 2024
4dc68c4
weights
gui1117 Apr 23, 2024
0dd982a
spelling and fix compilation
gui1117 Apr 23, 2024
51ae60c
log
gui1117 Apr 23, 2024
e2a3782
fix migration for pallet with instance
gui1117 Apr 23, 2024
d3c2801
fix benchmarking by using force_create
gui1117 Apr 23, 2024
bc31d85
Merge branch 'master' into gui-assets-revoke-through-status
joepetrowski Apr 23, 2024
9176cd9
".git/.scripts/commands/fmt/fmt.sh"
Apr 23, 2024
1aec7d5
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 23, 2024
0ac4845
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 23, 2024
bb1a490
Fix migration idempotency
gui1117 Apr 24, 2024
43b61d8
prdoc suggestions
gui1117 Apr 24, 2024
c4f98f6
Fix spelling and use saturating_add
gui1117 Apr 24, 2024
3cda448
Use versioned migration
gui1117 Apr 24, 2024
615f5ae
Fix compilation
gui1117 Apr 24, 2024
c1d67aa
Fix migration
gui1117 Apr 24, 2024
266cbb8
fix compilation
gui1117 Apr 24, 2024
f146170
fix unused
gui1117 Apr 24, 2024
a76350b
Merge branch 'master' into gui-assets-revoke-through-status
gui1117 Apr 27, 2024
e1853a6
Merge remote-tracking branch 'origin/master' into gui-assets-revoke-t…
gui1117 Jun 27, 2024
7dd5394
fix mock
gui1117 Jun 27, 2024
f76b23f
Apply suggestions from code review
gui1117 Jul 1, 2024
3036e0c
doc
gui1117 Jul 1, 2024
3794a11
Burn at relay
gui1117 Jul 1, 2024
d6d83e2
Merge branch 'master' into gui-assets-revoke-through-status
gui1117 Jul 1, 2024
6976d91
add integration test for assets and burn at relay
gui1117 Jul 3, 2024
247c84a
hello clippy
gui1117 Jul 3, 2024
a0c0f1f
Merge branch 'master' into gui-assets-revoke-through-status
gui1117 Jul 3, 2024
85e4fcc
minor improvement
gui1117 Jul 3, 2024
47d4bfd
Apply suggestions from code review
joepetrowski Jul 3, 2024
69ee8b4
Merge branch 'master' into gui-assets-revoke-through-status
gui1117 Jul 4, 2024
5962bb5
add migration for penpal and rococo and do prdoc
gui1117 Jul 4, 2024
36a3d7d
fmt
gui1117 Jul 4, 2024
a49b673
Merge remote-tracking branch 'origin/master' into gui-assets-revoke-t…
gui1117 Aug 7, 2024
905f658
Merge remote-tracking branch 'origin/master' into gui-assets-revoke-t…
gui1117 Aug 7, 2024
35fb7e2
Merge branch 'master' into gui-assets-revoke-through-status
gui1117 Aug 7, 2024
c0929cb
fix nostd
gui1117 Aug 7, 2024
5be3576
Merge remote-tracking branch 'origin/master' into gui-assets-revoke-t…
gui1117 Aug 27, 2024
ec8f2d0
fix tests
gui1117 Aug 27, 2024
50634c9
prdoc
gui1117 Aug 27, 2024
6594d94
address review: refactor + error returned on internal error, instead …
gui1117 Sep 6, 2024
04bd5ae
Merge remote-tracking branch 'origin/master' into gui-assets-revoke-t…
gui1117 Sep 6, 2024
24ab012
fixup
gui1117 Sep 6, 2024
d0a8ab2
better doc about reset team
gui1117 Sep 9, 2024
d029b29
fix test
gui1117 Sep 9, 2024
0fbdeb3
slightly better wording
gui1117 Sep 9, 2024
5d30a4e
use some random account for team with no privileges
gui1117 Sep 9, 2024
6b99f08
prdoc
gui1117 Sep 9, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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 emulated_integration_tests_common::accounts;

/// Create asset and then remove privileges; this results in the burning of the deposit, which must
/// burn at the Relay Chain.
#[test]
fn create_asset_remove_privileges_burn_deposit_at_relay() {
let owner = AssetHubRococo::account_id_of(accounts::CHARLIE);
let asset_id = 3939;

// We need first to teleport some balance so that it can be withdrawn later on the Relay
// Chain. Otherwise the asset is not withdrawable due to how genesis is set up.
Rococo::execute_with(|| {
type XcmPallet = <Rococo as RococoPallet>::XcmPallet;

assert_ok!(XcmPallet::limited_teleport_assets(
<Rococo as Chain>::RuntimeOrigin::signed(Rococo::account_id_of(accounts::CHARLIE)),
bx!(Parachain(AssetHubRococo::para_id().into()).into()),
bx!((*AsRef::<[u8; 32]>::as_ref(&owner)).into()),
bx!(Assets::from((Here, 1_000_000_000_000u128)).into()),
0,
WeightLimit::Unlimited,
));
});

let original_total_issuance =
Rococo::execute_with(|| <Rococo as RococoPallet>::Balances::total_issuance());

let deposit = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::Assets;
type Balances = <AssetHubRococo as AssetHubRococoPallet>::Balances;

let original_reserved_balance = Balances::reserved_balance(owner.clone());

assert_ok!(Assets::create(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(owner.clone()),
asset_id.into(),
owner.clone().into(),
1,
));
assert_ok!(Assets::set_metadata(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(owner.clone()),
asset_id.into(),
vec![],
vec![],
0,
));

let new_reserved_balance = Balances::reserved_balance(owner.clone());
let original_total_issuance = Balances::total_issuance();

let deposit = new_reserved_balance - original_reserved_balance;
assert!(deposit != 0); // This ensures we are testing something.

assert_ok!(Assets::revoke_all_privileges(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(owner.clone()),
asset_id.into(),
));

assert_eq!(deposit, original_total_issuance - Balances::total_issuance());

deposit
});

let new_total_issuance =
Rococo::execute_with(|| <Rococo as RococoPallet>::Balances::total_issuance());

assert_eq!(deposit, original_total_issuance - new_total_issuance);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

mod burn_at_relay;
mod claim_assets;
mod hybrid_transfers;
mod reserve_transfer;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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 emulated_integration_tests_common::accounts;

/// Create asset and then remove privileges; this results in the burning of the deposit, which must
/// burn at the Relay Chain.
#[test]
fn create_asset_remove_privileges_burn_deposit_at_relay() {
let owner = AssetHubWestend::account_id_of(accounts::CHARLIE);
let asset_id = 3939;

// We need first to teleport some balance so that it can be withdrawn later on the Relay
// Chain. Otherwise the asset is not withdrawable due to how genesis is set up.
Westend::execute_with(|| {
type XcmPallet = <Westend as WestendPallet>::XcmPallet;

assert_ok!(XcmPallet::limited_teleport_assets(
<Westend as Chain>::RuntimeOrigin::signed(Westend::account_id_of(accounts::CHARLIE)),
bx!(Parachain(AssetHubWestend::para_id().into()).into()),
bx!((*AsRef::<[u8; 32]>::as_ref(&owner)).into()),
bx!(Assets::from((Here, 1_000_000_000_000u128)).into()),
0,
WeightLimit::Unlimited,
));
});

let original_total_issuance =
Westend::execute_with(|| <Westend as WestendPallet>::Balances::total_issuance());

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

let original_reserved_balance = Balances::reserved_balance(owner.clone());

assert_ok!(Assets::create(
<AssetHubWestend as Chain>::RuntimeOrigin::signed(owner.clone()),
asset_id.into(),
owner.clone().into(),
1,
));
assert_ok!(Assets::set_metadata(
<AssetHubWestend as Chain>::RuntimeOrigin::signed(owner.clone()),
asset_id.into(),
vec![],
vec![],
0,
));

let new_reserved_balance = Balances::reserved_balance(owner.clone());
let original_total_issuance = Balances::total_issuance();

let deposit = new_reserved_balance - original_reserved_balance;
assert!(deposit != 0); // This ensures we are testing something.

assert_ok!(Assets::revoke_all_privileges(
<AssetHubWestend as Chain>::RuntimeOrigin::signed(owner.clone()),
asset_id.into(),
));

assert_eq!(deposit, original_total_issuance - Balances::total_issuance());

deposit
});

let new_total_issuance =
Westend::execute_with(|| <Westend as WestendPallet>::Balances::total_issuance());

assert_eq!(deposit, original_total_issuance - new_total_issuance);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

mod burn_at_relay;
mod claim_assets;
mod fellowship_treasury;
mod hybrid_transfers;
Expand Down
64 changes: 60 additions & 4 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ use frame_support::{
ord_parameter_types, parameter_types,
traits::{
fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool,
ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, InstanceFilter, TransformOrigin,
ConstU128, ConstU32, ConstU64, ConstU8, DefensiveResult, EitherOfDiverse, Imbalance,
InstanceFilter, OnUnbalanced, TransformOrigin,
},
weights::{ConstantMultiplier, Weight, WeightToFee as _},
BoundedVec, PalletId,
Expand Down Expand Up @@ -99,13 +100,17 @@ use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
#[cfg(feature = "runtime-benchmarks")]
use xcm::latest::prelude::{
Asset, Assets as XcmAssets, Fungible, Here, InteriorLocation, Junction, Junction::*, Location,
NetworkId, NonFungible, Parent, ParentThen, Response, XCM_VERSION,
InteriorLocation, Junction, Junction::*, NetworkId, NonFungible, Parent, ParentThen, Response,
XCM_VERSION,
};
use xcm::{
latest::prelude::{AssetId, BodyId},
latest::prelude::{
Asset, AssetId, Assets as XcmAssets, BodyId, BurnAsset, Fungible, Here, Instruction,
Location, Reanchorable, ReceiveTeleportedAsset, WeightLimit, Xcm, XcmContext, XcmError,
},
VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
};
use xcm_executor::traits::TransactAsset;
use xcm_runtime_apis::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
fees::Error as XcmPaymentApiError,
Expand Down Expand Up @@ -245,6 +250,50 @@ parameter_types! {
/// We allow root to execute privileged asset operations.
pub type AssetsForceOrigin = EnsureRoot<AccountId>;

type AssetTransactor = <xcm_config::XcmConfig as xcm_executor::Config>::AssetTransactor;

fn try_burn_at_relay(value: Balance) -> Result<(), XcmError> {
let asset = Asset { id: AssetId(Location::parent()), fun: Fungible(value) };
let dest = Location::parent();
let parent_assets = Into::<XcmAssets>::into(asset.clone())
.reanchored(&dest, &Here.into())
.defensive_map_err(|_| XcmError::ReanchorFailed)?;

let dummy_xcm_context = XcmContext { origin: None, message_id: [0; 32], topic: None };

AssetTransactor::can_check_out(&dest, &asset, &dummy_xcm_context)?;

PolkadotXcm::send_xcm(
Here,
Location::parent(),
Xcm(vec![
Instruction::UnpaidExecution {
weight_limit: WeightLimit::Unlimited,
check_origin: None,
},
ReceiveTeleportedAsset(parent_assets.clone()),
BurnAsset(parent_assets),
]),
)?;

AssetTransactor::check_out(&dest, &asset, &dummy_xcm_context);

Ok(())
}

// Burn negative imbalance at the relay chain.
pub struct BurnAtRelay;

impl OnUnbalanced<pallet_balances::NegativeImbalance<Runtime>> for BurnAtRelay {
fn on_nonzero_unbalanced(amount: pallet_balances::NegativeImbalance<Runtime>) {
let amount = amount.peek();
if let Err(e) = try_burn_at_relay(amount) {
log::error!(target: "runtime::assets", "failed to burn balance at relay: amount: \
{amount}: {e:?}");
}
}
}

// Called "Trust Backed" assets because these are generally registered by some account, and users of
// the asset assume it has some claimed backing. The pallet is called `Assets` in
// `construct_runtime` to avoid breaking changes on storage reads.
Expand All @@ -269,6 +318,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type CallbackHandle = ();
type AssetAccountDeposit = AssetAccountDeposit;
type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
type DepositDestinationOnRevocation = BurnAtRelay;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}
Expand Down Expand Up @@ -312,6 +362,7 @@ impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type Extra = ();
type WeightInfo = weights::pallet_assets_pool::WeightInfo<Runtime>;
type CallbackHandle = ();
type DepositDestinationOnRevocation = BurnAtRelay;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}
Expand Down Expand Up @@ -437,6 +488,7 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type CallbackHandle = ();
type AssetAccountDeposit = ForeignAssetsAssetAccountDeposit;
type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
type DepositDestinationOnRevocation = BurnAtRelay;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = xcm_config::XcmBenchmarkHelper;
}
Expand Down Expand Up @@ -1016,9 +1068,13 @@ pub type Migrations = (
InitStorageVersions,
// unreleased
cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4<Runtime>,
// unreleased
cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5<Runtime>,
pallet_collator_selection::migration::v2::MigrationToV2<Runtime>,
frame_support::migrations::RemovePallet<StateTrieMigrationName, RocksDbWeight>,
pallet_assets::migration::v2::MigrateV1ToV2<Runtime, TrustBackedAssetsInstance>,
pallet_assets::migration::v2::MigrateV1ToV2<Runtime, PoolAssetsInstance>,
pallet_assets::migration::v2::MigrateV1ToV2<Runtime, ForeignAssetsInstance>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
);
Expand Down
Loading