From 371d5b07bf332972ec2b32e7f55d5c5d28ab36a0 Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Fri, 26 Jan 2024 11:34:06 +0200 Subject: [PATCH] quick fix for delivery fees --- polkadot/xcm/xcm-executor/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index 665b051c13060..a453ab1c93778 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -772,6 +772,19 @@ impl XcmExecutor { Ok(()) }, DepositReserveAsset { assets, dest, 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![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 deposited = self.holding.saturating_take(assets); for asset in deposited.assets_iter() { Config::AssetTransactor::deposit_asset(&asset, &dest, Some(&self.context))?; @@ -781,6 +794,9 @@ impl XcmExecutor { let assets = Self::reanchored(deposited, &dest, None); let mut message = vec![ReserveAssetDeposited(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::DepositReserveAsset)?; Ok(()) },