Skip to content

Commit 6bf4f98

Browse files
committed
[pallet_xcm] adapt paritytech/polkadot-sdk#2388 (new transfer_assets)
1 parent a51632e commit 6bf4f98

14 files changed

Lines changed: 352 additions & 0 deletions

File tree

relay/kusama/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,6 +2358,20 @@ sp_api::impl_runtime_apis! {
23582358
crate::Junction::Parachain(43211234).into(),
23592359
))
23602360
}
2361+
2362+
fn set_up_complex_asset_transfer(
2363+
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
2364+
// Relay supports only native token, either reserve transfer it to non-system parachains,
2365+
// or teleport it to system parachain. Use the teleport case for benchmarking as it's
2366+
// slightly heavier.
2367+
// Relay/native token can be teleported to/from AH.
2368+
let native_location = Here.into();
2369+
let dest = crate::xcm_config::AssetHubLocation::get();
2370+
pallet_xcm::benchmarking::helpers::native_teleport_as_asset_transfer::<Runtime>(
2371+
native_location,
2372+
dest
2373+
)
2374+
}
23612375
}
23622376

23632377
parameter_types! {

relay/kusama/src/weights/pallet_xcm.rs

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

relay/polkadot/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,20 @@ sp_api::impl_runtime_apis! {
23542354
crate::Junction::Parachain(43211234).into(),
23552355
))
23562356
}
2357+
2358+
fn set_up_complex_asset_transfer(
2359+
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
2360+
// Relay supports only native token, either reserve transfer it to non-system parachains,
2361+
// or teleport it to system parachain. Use the teleport case for benchmarking as it's
2362+
// slightly heavier.
2363+
// Relay/native token can be teleported to/from AH.
2364+
let native_location = Here.into();
2365+
let dest = crate::xcm_config::AssetHubLocation::get();
2366+
pallet_xcm::benchmarking::helpers::native_teleport_as_asset_transfer::<Runtime>(
2367+
native_location,
2368+
dest
2369+
)
2370+
}
23572371
}
23582372

23592373
parameter_types! {

relay/polkadot/src/weights/pallet_xcm.rs

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,55 @@ impl_runtime_apis! {
13101310
ParentThen(Parachain(random_para_id).into()).into(),
13111311
))
13121312
}
1313+
1314+
fn set_up_complex_asset_transfer(
1315+
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
1316+
// Transfer to Relay some local AH asset (local-reserve-transfer) while paying
1317+
// fees using teleported native token.
1318+
// (We don't care that Relay doesn't accept incoming unknown AH local asset)
1319+
let dest = Parent.into();
1320+
1321+
let fee_amount = EXISTENTIAL_DEPOSIT;
1322+
let fee_asset: MultiAsset = (MultiLocation::parent(), fee_amount).into();
1323+
1324+
let who = frame_benchmarking::whitelisted_caller();
1325+
// Give some multiple of the existential deposit
1326+
let balance = fee_amount + EXISTENTIAL_DEPOSIT * 1000;
1327+
let _ = <Balances as frame_support::traits::Currency<_>>::make_free_balance_be(
1328+
&who, balance,
1329+
);
1330+
// verify initial balance
1331+
assert_eq!(Balances::free_balance(&who), balance);
1332+
1333+
// set up local asset
1334+
let asset_amount = 10u128;
1335+
let initial_asset_amount = asset_amount * 10;
1336+
let (asset_id, _, _) = pallet_assets::benchmarking::create_default_minted_asset::<
1337+
Runtime,
1338+
pallet_assets::Instance1
1339+
>(true, initial_asset_amount);
1340+
let asset_location = MultiLocation::new(
1341+
0,
1342+
X2(PalletInstance(50), GeneralIndex(u32::from(asset_id).into()))
1343+
);
1344+
let transfer_asset: MultiAsset = (asset_location, asset_amount).into();
1345+
1346+
let assets: MultiAssets = vec![fee_asset.clone(), transfer_asset].into();
1347+
let fee_index = if assets.get(0).unwrap().eq(&fee_asset) { 0 } else { 1 };
1348+
1349+
// verify transferred successfully
1350+
let verify = Box::new(move || {
1351+
// verify native balance after transfer, decreased by transferred fee amount
1352+
// (plus transport fees)
1353+
assert!(Balances::free_balance(&who) <= balance - fee_amount);
1354+
// verify asset balance decreased by exactly transferred amount
1355+
assert_eq!(
1356+
Assets::balance(asset_id.into(), &who),
1357+
initial_asset_amount - asset_amount,
1358+
);
1359+
});
1360+
Some((assets, fee_index as u32, dest, verify))
1361+
}
13131362
}
13141363

13151364
parameter_types! {

system-parachains/asset-hubs/asset-hub-kusama/src/weights/pallet_xcm.rs

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,55 @@ impl_runtime_apis! {
12001200
ParentThen(Parachain(random_para_id).into()).into(),
12011201
))
12021202
}
1203+
1204+
fn set_up_complex_asset_transfer(
1205+
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
1206+
// Transfer to Relay some local AH asset (local-reserve-transfer) while paying
1207+
// fees using teleported native token.
1208+
// (We don't care that Relay doesn't accept incoming unknown AH local asset)
1209+
let dest = Parent.into();
1210+
1211+
let fee_amount = EXISTENTIAL_DEPOSIT;
1212+
let fee_asset: MultiAsset = (MultiLocation::parent(), fee_amount).into();
1213+
1214+
let who = frame_benchmarking::whitelisted_caller();
1215+
// Give some multiple of the existential deposit
1216+
let balance = fee_amount + EXISTENTIAL_DEPOSIT * 1000;
1217+
let _ = <Balances as frame_support::traits::Currency<_>>::make_free_balance_be(
1218+
&who, balance,
1219+
);
1220+
// verify initial balance
1221+
assert_eq!(Balances::free_balance(&who), balance);
1222+
1223+
// set up local asset
1224+
let asset_amount = 10u128;
1225+
let initial_asset_amount = asset_amount * 10;
1226+
let (asset_id, _, _) = pallet_assets::benchmarking::create_default_minted_asset::<
1227+
Runtime,
1228+
pallet_assets::Instance1
1229+
>(true, initial_asset_amount);
1230+
let asset_location = MultiLocation::new(
1231+
0,
1232+
X2(PalletInstance(50), GeneralIndex(u32::from(asset_id).into()))
1233+
);
1234+
let transfer_asset: MultiAsset = (asset_location, asset_amount).into();
1235+
1236+
let assets: MultiAssets = vec![fee_asset.clone(), transfer_asset].into();
1237+
let fee_index = if assets.get(0).unwrap().eq(&fee_asset) { 0 } else { 1 };
1238+
1239+
// verify transferred successfully
1240+
let verify = Box::new(move || {
1241+
// verify native balance after transfer, decreased by transferred fee amount
1242+
// (plus transport fees)
1243+
assert!(Balances::free_balance(&who) <= balance - fee_amount);
1244+
// verify asset balance decreased by exactly transferred amount
1245+
assert_eq!(
1246+
Assets::balance(asset_id.into(), &who),
1247+
initial_asset_amount - asset_amount,
1248+
);
1249+
});
1250+
Some((assets, fee_index as u32, dest, verify))
1251+
}
12031252
}
12041253

12051254
parameter_types! {

system-parachains/asset-hubs/asset-hub-polkadot/src/weights/pallet_xcm.rs

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,18 @@ impl_runtime_apis! {
799799
// Reserve transfers are disabled on BH.
800800
None
801801
}
802+
803+
fn set_up_complex_asset_transfer(
804+
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
805+
// BH only supports teleports to system parachain.
806+
// Relay/native token can be teleported between BH and Relay.
807+
let native_location = Parent.into();
808+
let dest = Parent.into();
809+
pallet_xcm::benchmarking::helpers::native_teleport_as_asset_transfer::<Runtime>(
810+
native_location,
811+
dest
812+
)
813+
}
802814
}
803815

804816
parameter_types! {

system-parachains/bridge-hubs/bridge-hub-kusama/src/weights/pallet_xcm.rs

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)