From 3a79d4533e2fa6ef1b6bcdbcfaa4026425a275a6 Mon Sep 17 00:00:00 2001 From: ron Date: Fri, 19 Jul 2024 17:28:05 +0800 Subject: [PATCH] Use low level execute directly --- .../primitives/router/src/outbound/mod.rs | 12 ----- .../bridge-hub-rococo/src/tests/snowbridge.rs | 48 ++++++++++++------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/bridges/snowbridge/primitives/router/src/outbound/mod.rs b/bridges/snowbridge/primitives/router/src/outbound/mod.rs index ddc36ce8cb61..3cc1f6e7bfba 100644 --- a/bridges/snowbridge/primitives/router/src/outbound/mod.rs +++ b/bridges/snowbridge/primitives/router/src/outbound/mod.rs @@ -148,11 +148,9 @@ enum XcmConverterError { DepositAssetExpected, NoReserveAssets, FilterDoesNotConsumeAllAssets, - TooManyAssets, ZeroAssetTransfer, BeneficiaryResolutionFailed, AssetResolutionFailed, - InvalidFeeAsset, SetTopicExpected, } @@ -233,18 +231,8 @@ impl<'a, Call> XcmConverter<'a, Call> { return Err(FilterDoesNotConsumeAllAssets) } - // We only support a single asset at a time. - ensure!(reserve_assets.len() == 1, TooManyAssets); let reserve_asset = reserve_assets.get(0).ok_or(AssetResolutionFailed)?; - // If there was a fee specified verify it. - if let Some(fee_asset) = fee_asset { - // The fee asset must be the same as the reserve asset. - if fee_asset.id != reserve_asset.id || fee_asset.fun > reserve_asset.fun { - return Err(InvalidFeeAsset) - } - } - let (token, amount) = match reserve_asset { Asset { id: AssetId(inner_location), fun: Fungible(amount) } => match inner_location.unpack() { diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index 8856fe8eca51..3aece6d1bca1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -395,6 +395,7 @@ fn send_weth_asset_from_asset_hub_to_ethereum() { AssetHubRococo::fund_accounts(vec![(AssetHubRococoReceiver::get(), INITIAL_FUND)]); const WETH_AMOUNT: u128 = 1_000_000_000; + const FEE_AMOUNT: u128 = 1_000; BridgeHubRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; @@ -433,7 +434,8 @@ fn send_weth_asset_from_asset_hub_to_ethereum() { RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { .. }) => {}, ] ); - let assets = vec![Asset { + let fee_asset = Asset { id: AssetId(Location::parent()), fun: Fungible(FEE_AMOUNT) }; + let weth_asset = Asset { id: AssetId(Location::new( 2, [ @@ -442,30 +444,44 @@ fn send_weth_asset_from_asset_hub_to_ethereum() { ], )), fun: Fungible(WETH_AMOUNT), - }]; - let multi_assets = VersionedAssets::V4(Assets::from(assets)); + }; + let assets = vec![fee_asset.clone(), weth_asset.clone()]; - let destination = VersionedLocation::V4(Location::new( - 2, - [GlobalConsensus(Ethereum { chain_id: CHAIN_ID })], - )); + let destination = Location::new(2, [GlobalConsensus(Ethereum { chain_id: CHAIN_ID })]); - let beneficiary = VersionedLocation::V4(Location::new( + let beneficiary = Location::new( 0, [AccountKey20 { network: None, key: ETHEREUM_DESTINATION_ADDRESS.into() }], - )); + ); + + let mut reanchored_fee = fee_asset.clone(); + + let universal_location: InteriorLocation = + Junctions::from([GlobalConsensus(NetworkId::Rococo), Parachain(1000)]); + reanchored_fee = reanchored_fee.reanchored(&destination, &universal_location).unwrap(); + + let xcm_on_bh = Xcm(vec![ + BuyExecution { fees: reanchored_fee.clone(), weight_limit: Unlimited }, + DepositAsset { assets: Wild(AllCounted(2)), beneficiary }, + ]); + + let xcms = VersionedXcm::from(Xcm(vec![ + WithdrawAsset(assets.clone().into()), + SetFeesMode { jit_withdraw: true }, + InitiateReserveWithdraw { + assets: Wild(AllCounted(2)), + reserve: destination, + xcm: xcm_on_bh, + }, + ])); let free_balance_before = ::Balances::free_balance( AssetHubRococoReceiver::get(), ); - // Send the Weth back to Ethereum - ::PolkadotXcm::limited_reserve_transfer_assets( + ::PolkadotXcm::execute( RuntimeOrigin::signed(AssetHubRococoReceiver::get()), - Box::new(destination), - Box::new(beneficiary), - Box::new(multi_assets), - 0, - Unlimited, + bx!(xcms), + Weight::from(8_000_000_000), ) .unwrap(); let free_balance_after = ::Balances::free_balance(