Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Use low level execute directly
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Jul 19, 2024
1 parent f7054e7 commit 3a79d45
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
12 changes: 0 additions & 12 deletions bridges/snowbridge/primitives/router/src/outbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,9 @@ enum XcmConverterError {
DepositAssetExpected,
NoReserveAssets,
FilterDoesNotConsumeAllAssets,
TooManyAssets,
ZeroAssetTransfer,
BeneficiaryResolutionFailed,
AssetResolutionFailed,
InvalidFeeAsset,
SetTopicExpected,
}

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <BridgeHubRococo as Chain>::RuntimeEvent;
Expand Down Expand Up @@ -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,
[
Expand All @@ -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 = <AssetHubRococo as AssetHubRococoPallet>::Balances::free_balance(
AssetHubRococoReceiver::get(),
);
// Send the Weth back to Ethereum
<AssetHubRococo as AssetHubRococoPallet>::PolkadotXcm::limited_reserve_transfer_assets(
<AssetHubRococo as AssetHubRococoPallet>::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 = <AssetHubRococo as AssetHubRococoPallet>::Balances::free_balance(
Expand Down

0 comments on commit 3a79d45

Please sign in to comment.