Skip to content

Commit

Permalink
Added SetAssetClaimer instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
x3c41a committed Aug 20, 2024
1 parent 1f031ec commit 9bec263
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 9 additions & 0 deletions polkadot/xcm/src/v5/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,15 @@ pub enum Instruction<Call> {
/// 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
Expand Down
13 changes: 11 additions & 2 deletions polkadot/xcm/xcm-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -84,6 +84,7 @@ pub struct XcmExecutor<Config: config::Config> {
transact_status: MaybeErrorCode,
fees_mode: FeesMode,
_config: PhantomData<Config>,
assetClaimer: Option<Location>,
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -342,7 +343,11 @@ impl<Config: config::Config> XcmExecutor<Config> {
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);
Expand Down Expand Up @@ -1003,6 +1008,10 @@ impl<Config: config::Config> XcmExecutor<Config> {
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())?;
Expand Down

0 comments on commit 9bec263

Please sign in to comment.