Skip to content

Commit 3449ef8

Browse files
committed
[pallet_xcm] adapt paritytech/polkadot-sdk#2388 (new transfer_assets)
1 parent a78ffe8 commit 3449ef8

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
@@ -2364,6 +2364,20 @@ sp_api::impl_runtime_apis! {
23642364
crate::Junction::Parachain(43211234).into(),
23652365
))
23662366
}
2367+
2368+
fn set_up_complex_asset_transfer(
2369+
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
2370+
// Relay supports only native token, either reserve transfer it to non-system parachains,
2371+
// or teleport it to system parachain. Use the teleport case for benchmarking as it's
2372+
// slightly heavier.
2373+
// Relay/native token can be teleported to/from AH.
2374+
let native_location = Here.into();
2375+
let dest = crate::xcm_config::AssetHubLocation::get();
2376+
pallet_xcm::benchmarking::helpers::native_teleport_as_asset_transfer::<Runtime>(
2377+
native_location,
2378+
dest
2379+
)
2380+
}
23672381
}
23682382

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

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

12021251
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
@@ -795,6 +795,18 @@ impl_runtime_apis! {
795795
// Reserve transfers are disabled on BH.
796796
None
797797
}
798+
799+
fn set_up_complex_asset_transfer(
800+
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
801+
// BH only supports teleports to system parachain.
802+
// Relay/native token can be teleported between BH and Relay.
803+
let native_location = Parent.into();
804+
let dest = Parent.into();
805+
pallet_xcm::benchmarking::helpers::native_teleport_as_asset_transfer::<Runtime>(
806+
native_location,
807+
dest
808+
)
809+
}
798810
}
799811

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