From 9bec2631361ed89deb11158b6c029d238c0f7cc2 Mon Sep 17 00:00:00 2001 From: ndk Date: Tue, 20 Aug 2024 15:00:20 +0300 Subject: [PATCH] Added SetAssetClaimer instruction --- polkadot/xcm/src/v5/mod.rs | 9 +++++++++ polkadot/xcm/xcm-executor/src/lib.rs | 13 +++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/polkadot/xcm/src/v5/mod.rs b/polkadot/xcm/src/v5/mod.rs index 4a23507709f59..fc808ba1a2bde 100644 --- a/polkadot/xcm/src/v5/mod.rs +++ b/polkadot/xcm/src/v5/mod.rs @@ -737,6 +737,15 @@ pub enum Instruction { /// Errors: None. ClearError, + /// Set asset claimer for all the trapped assets during the execution. + /// + /// - `location`: The claimer of the assets; it might be an arbitrary location, not necessarily the caller or origin. + /// + /// Kind: *Command* + /// + /// Errors: None. + SetAssetClaimer {location: Location}, + /// Create some assets which are being held on behalf of the origin. /// /// - `assets`: The assets which are to be claimed. This must match exactly with the assets diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index 74561e931e7e1..84732def3b562 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -29,7 +29,7 @@ use frame_support::{ use sp_core::defer; use sp_io::hashing::blake2_128; use sp_weights::Weight; -use xcm::latest::prelude::*; +use xcm::{latest::prelude::*, v3::MultiLocation}; pub mod traits; use traits::{ @@ -84,6 +84,7 @@ pub struct XcmExecutor { transact_status: MaybeErrorCode, fees_mode: FeesMode, _config: PhantomData, + assetClaimer: Option, } #[cfg(feature = "runtime-benchmarks")] @@ -342,7 +343,11 @@ impl XcmExecutor { original_origin = ?self.original_origin, "Trapping assets in holding register", ); - let effective_origin = self.context.origin.as_ref().unwrap_or(&self.original_origin); + let effective_orgin = if let Some(assetClaimer) = self.assetClaimer { + assetClaimer.as_ref().unwrap_or(&self.original_origin) + } else { + self.context.origin.as_ref().unwrap_or(&self.original_origin) + }; let trap_weight = Config::AssetTrap::drop_assets(effective_origin, self.holding, &self.context); weight_used.saturating_accrue(trap_weight); @@ -1003,6 +1008,10 @@ impl XcmExecutor { self.error = None; Ok(()) }, + SetAssetClaimer { location } => { + self.assetClaimer = Some(location); + Ok(()) + } ClaimAsset { assets, ticket } => { let origin = self.origin_ref().ok_or(XcmError::BadOrigin)?; self.ensure_can_subsume_assets(assets.len())?;