Skip to content

Commit efd8792

Browse files
committed
[pallet_xcm] adapt paritytech/polkadot-sdk#2388 (new transfer_assets)
1 parent 54e279f commit efd8792

File tree

14 files changed

+352
-0
lines changed

14 files changed

+352
-0
lines changed

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

12061255
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)