From d53dde2c7fff5747a821bda3af7579109369b64f Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Fri, 26 Jan 2024 12:22:22 +0100 Subject: [PATCH] More instructions --- polkadot/xcm/xcm-executor/src/lib.rs | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index d509c87532a8..d4842d030a24 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -510,6 +510,21 @@ impl XcmExecutor { }, TransferReserveAsset { mut assets, dest, xcm } => { let origin = self.origin_ref().ok_or(XcmError::BadOrigin)?; + + // we need to do this take/put cycle to solve wildcards and get exact assets to be + // weighed + let to_weigh = self.holding.saturating_take(assets.clone()); + self.holding.subsume_assets(to_weigh.clone()); + + let mut message_to_weigh = + vec![ReserveAssetDeposited(to_weigh.into()), ClearOrigin]; + message_to_weigh.extend(xcm.0.clone().into_iter()); + let (_, fee) = validate_send::(dest, Xcm(message_to_weigh))?; + // set aside fee to be charged by XcmSender + let parked_fee = self.holding.saturating_take(fee.into()); + + // now take assets to deposit (excluding parked_fee) + let assets = self.holding.saturating_take(assets); // Take `assets` from the origin account (on-chain) and place into dest account. for asset in assets.inner() { Config::AssetTransactor::transfer_asset(asset, origin, &dest, &self.context)?; @@ -653,6 +668,19 @@ impl XcmExecutor { Ok(()) }, InitiateReserveWithdraw { assets, reserve, xcm } => { + // we need to do this take/put cycle to solve wildcards and get exact assets to be + // weighed + let to_weigh = self.holding.saturating_take(assets.clone()); + self.holding.subsume_assets(to_weigh.clone()); + + let mut message_to_weigh = + vec![WithdrawAsset(to_weigh.clone()), ClearOrigin]; + message_to_weigh.extend(xcm.0.clone().into_iter()); + let (_, fee) = validate_send::(dest, Xcm(message_to_weigh))?; + // set aside fee to be charged by XcmSender + let parked_fee = self.holding.saturating_take(fee.into()); + + // now take assets to deposit (excluding parked_fee) // Note that here we are able to place any assets which could not be reanchored // back into Holding. let assets = Self::reanchored( @@ -662,11 +690,25 @@ impl XcmExecutor { ); let mut message = vec![WithdrawAsset(assets), ClearOrigin]; message.extend(xcm.0.into_iter()); + + // put back parked_fee in holding register to be charged by XcmSender + self.holding.subsume_assets(parked_fee); self.send(reserve, Xcm(message), FeeReason::InitiateReserveWithdraw)?; Ok(()) }, InitiateTeleport { assets, dest, xcm } => { // We must do this first in order to resolve wildcards. + let to_weigh = self.holding.saturating_take(assets); + self.holding.subsume_assets(to_weigh.clone()); + + let mut message_to_weigh = + vec![ReceiveTeleportedAsset(to_weigh.clone()), ClearOrigin]; + message_to_weigh.extend(xcm.0.clone().into_iter()); + let (_, fee) = validate_send::(dest, Xcm(message_to_weigh))?; + // set aside fee to be charged by XcmSender + let parked_fee = self.holding.saturating_take(fee.into()); + + // now take assets to deposit (excluding parked_fee) let assets = self.holding.saturating_take(assets); for asset in assets.assets_iter() { // We should check that the asset can actually be teleported out (for this to @@ -683,6 +725,9 @@ impl XcmExecutor { let assets = Self::reanchored(assets, &dest, None); let mut message = vec![ReceiveTeleportedAsset(assets), ClearOrigin]; message.extend(xcm.0.into_iter()); + + // put back parked_fee in holding register to be charged by XcmSender + self.holding.subsume_assets(parked_fee); self.send(dest, Xcm(message), FeeReason::InitiateTeleport)?; Ok(()) },