Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pallet-xcm: add new extrinsic for asset transfers using explicit XCM transfer types #3695

Merged
merged 37 commits into from
Apr 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dda9308
pallet-xcm: deprecate unlimited_* weight extrinsics
acatangiu Mar 13, 2024
1db1cae
pallet-xcm: remove extrinsics guessed weight and rely on runtime benc…
acatangiu Mar 13, 2024
f5e1dfb
pallet-xcm: add new extrinsic for asset transfers using explicit reserve
acatangiu Mar 13, 2024
547eeee
add more trace logging to XCM transport
acatangiu Mar 13, 2024
c7ee1af
minor style fix
acatangiu Mar 13, 2024
ed77fde
integration-tests: add scenario for parachain sending asset over brid…
acatangiu Mar 13, 2024
a7a44c9
make penpal UniversalLocation configurable
acatangiu Mar 14, 2024
ffa6250
penpal: charge XCM delivery fees for accurate real-world testing
acatangiu Mar 22, 2024
4afba95
integration-tests: fix tests for penpal charging delivery fees
acatangiu Mar 22, 2024
210cdd2
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Mar 23, 2024
c918bea
fix test
acatangiu Mar 23, 2024
3db344b
add prdoc
acatangiu Mar 25, 2024
10d2c40
fix clippy
acatangiu Mar 25, 2024
5b48155
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Mar 27, 2024
dbe453d
add test for westend->rococo direction
acatangiu Mar 27, 2024
42e4041
nit
acatangiu Mar 27, 2024
e794df3
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Apr 1, 2024
81dc911
pallet-xcm: specify explicit transfer type
acatangiu Apr 3, 2024
e1dbf7a
add more tests
acatangiu Apr 3, 2024
ef83eab
fix prdoc
acatangiu Apr 4, 2024
a2b8708
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Apr 4, 2024
4250692
refactor tests
acatangiu Apr 4, 2024
888d403
even more tests
acatangiu Apr 4, 2024
1c86e6e
another test
acatangiu Apr 4, 2024
b82d0b9
add teleport test as well
acatangiu Apr 4, 2024
f4e88da
rename xt and update docs
acatangiu Apr 4, 2024
4f2381c
fix weights
acatangiu Apr 4, 2024
36af01f
add tests to westend
acatangiu Apr 4, 2024
bd9233a
Merge branch 'master' of github.com:paritytech/polkadot-sdk into tran…
acatangiu Apr 4, 2024
9c7bd39
remove leftover comment
acatangiu Apr 4, 2024
adf5128
Apply suggestions from code review
acatangiu Apr 11, 2024
1347f0b
fix logs
acatangiu Apr 11, 2024
e3acff2
fix api
acatangiu Apr 11, 2024
4a44194
Merge branch 'master' into transfer-using-explicit-reserve
acatangiu Apr 11, 2024
0d407eb
Update polkadot/xcm/pallet-xcm/src/lib.rs
acatangiu Apr 12, 2024
22093d0
".git/.scripts/commands/fmt/fmt.sh"
Apr 12, 2024
a673792
Merge branch 'master' into transfer-using-explicit-reserve
acatangiu Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test for westend->rococo direction
acatangiu committed Mar 27, 2024
commit dbe453d9709b2c8597f15f08355bf861299d2339
Original file line number Diff line number Diff line change
@@ -16,16 +16,18 @@
mod genesis;
pub use genesis::{genesis, PenpalAssetOwner, PenpalSudoAccount, ED, PARA_ID_A, PARA_ID_B};
pub use penpal_runtime::xcm_config::{
CustomizableAssetFromSystemAssetHub, LocalTeleportableToAssetHub, XcmConfig,
CustomizableAssetFromSystemAssetHub, RelayNetworkId as PenpalRelayNetworkId,
};

// Substrate
use frame_support::traits::OnInitialize;
use sp_core::Encode;

// Cumulus
use emulated_integration_tests_common::{
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
impl_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain, impls::Parachain,
impl_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain,
impls::{NetworkId, Parachain},
xcm_emulator::decl_test_parachains,
};

@@ -35,6 +37,10 @@ decl_test_parachains! {
genesis = genesis(PARA_ID_A),
on_init = {
penpal_runtime::AuraExt::on_initialize(1);
frame_support::assert_ok!(penpal_runtime::System::set_storage(
penpal_runtime::RuntimeOrigin::root(),
vec![(PenpalRelayNetworkId::key().to_vec(), NetworkId::Rococo.encode())],
));
Comment on lines +40 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
runtime = penpal_runtime,
core = {
@@ -54,6 +60,10 @@ decl_test_parachains! {
genesis = genesis(PARA_ID_B),
on_init = {
penpal_runtime::AuraExt::on_initialize(1);
frame_support::assert_ok!(penpal_runtime::System::set_storage(
penpal_runtime::RuntimeOrigin::root(),
vec![(PenpalRelayNetworkId::key().to_vec(), NetworkId::Westend.encode())],
));
},
runtime = penpal_runtime,
core = {
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ use asset_hub_rococo_emulated_chain::AssetHubRococo;
use asset_hub_westend_emulated_chain::AssetHubWestend;
use bridge_hub_rococo_emulated_chain::BridgeHubRococo;
use bridge_hub_westend_emulated_chain::BridgeHubWestend;
use penpal_emulated_chain::PenpalA;
use penpal_emulated_chain::{PenpalA, PenpalB};
use rococo_emulated_chain::Rococo;
use westend_emulated_chain::Westend;

@@ -48,13 +48,13 @@ decl_test_networks! {
PenpalA,
],
bridge = RococoWestendMockBridge

},
pub struct WestendMockNet {
relay_chain = Westend,
parachains = vec![
AssetHubWestend,
BridgeHubWestend,
PenpalB,
],
bridge = WestendRococoMockBridge
},
@@ -96,5 +96,6 @@ decl_test_sender_receiver_accounts_parameter_types! {
WestendRelay { sender: ALICE, receiver: BOB },
AssetHubWestendPara { sender: ALICE, receiver: BOB },
BridgeHubWestendPara { sender: ALICE, receiver: BOB },
PenpalAPara { sender: ALICE, receiver: BOB }
PenpalAPara { sender: ALICE, receiver: BOB },
PenpalBPara { sender: ALICE, receiver: BOB }
}
Original file line number Diff line number Diff line change
@@ -48,13 +48,15 @@ mod imports {
genesis::ED as BRIDGE_HUB_WESTEND_ED,
BridgeHubWestendParaPallet as BridgeHubWestendPallet,
},
penpal_emulated_chain::{PenpalAssetOwner, PenpalBParaPallet as PenpalBPallet},
westend_emulated_chain::WestendRelayPallet as WestendPallet,
AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver,
AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWestendPara as AssetHubWestend,
AssetHubWestendParaReceiver as AssetHubWestendReceiver,
AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubRococoPara as BridgeHubRococo,
BridgeHubWestendPara as BridgeHubWestend,
BridgeHubWestendParaSender as BridgeHubWestendSender, WestendRelay as Westend,
BridgeHubWestendParaSender as BridgeHubWestendSender, PenpalBPara as PenpalB,
PenpalBParaSender as PenpalBSender, WestendRelay as Westend,
};

pub const ASSET_MIN_BALANCE: u128 = 1000;
Original file line number Diff line number Diff line change
@@ -30,6 +30,72 @@ fn send_asset_from_asset_hub_westend_to_asset_hub_rococo(id: Location, amount: u
assert_bridge_hub_rococo_message_received();
}

fn send_asset_from_penpal_westend_through_local_asset_hub_to_rococo_asset_hub(
id: Location,
transfer_amount: u128,
) {
let destination = asset_hub_rococo_location();
let local_asset_hub: Location = PenpalB::sibling_location_of(AssetHubWestend::para_id());
let sov_penpal_on_ahw = AssetHubWestend::sovereign_account_id_of(
AssetHubWestend::sibling_location_of(PenpalB::para_id()),
);
let sov_ahr_on_ahw = AssetHubWestend::sovereign_account_of_parachain_on_other_global_consensus(
Rococo,
AssetHubRococo::para_id(),
);

// fund the AHW's SA on BHW for paying bridge transport fees
BridgeHubWestend::fund_para_sovereign(AssetHubWestend::para_id(), 10_000_000_000_000u128);

// set XCM versions
PenpalB::force_xcm_version(local_asset_hub.clone(), XCM_VERSION);
AssetHubWestend::force_xcm_version(destination.clone(), XCM_VERSION);
BridgeHubWestend::force_xcm_version(bridge_hub_rococo_location(), XCM_VERSION);

// send message over bridge
assert_ok!(PenpalB::execute_with(|| {
let signed_origin = <PenpalB as Chain>::RuntimeOrigin::signed(PenpalBSender::get());
let beneficiary: Location =
AccountId32Junction { network: None, id: AssetHubRococoReceiver::get().into() }.into();
let fees: Asset = (id, transfer_amount).into();
let assets: Assets = fees.clone().into();

<PenpalB as PenpalBPallet>::PolkadotXcm::transfer_assets_using_reserve(
signed_origin,
bx!(destination.into()),
bx!(beneficiary.into()),
bx!(assets.into()),
bx!(fees.into()),
bx!(local_asset_hub.into()),
WeightLimit::Unlimited,
)
}));
AssetHubWestend::execute_with(|| {
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
assert_expected_events!(
AssetHubWestend,
vec![
// Amount to reserve transfer is withdrawn from Penpal's sovereign account
RuntimeEvent::Balances(
pallet_balances::Event::Burned { who, amount }
) => {
who: *who == sov_penpal_on_ahw.clone().into(),
amount: *amount == transfer_amount,
},
// Amount deposited in AHR's sovereign account
RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => {
who: *who == sov_ahr_on_ahw.clone().into(),
},
RuntimeEvent::XcmpQueue(
cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }
) => {},
]
);
});
assert_bridge_hub_westend_message_accepted(true);
assert_bridge_hub_rococo_message_received();
}

#[test]
fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() {
let wnd_at_asset_hub_westend: Location = Parent.into();
@@ -215,3 +281,137 @@ fn send_rocs_from_asset_hub_westend_to_asset_hub_rococo() {
// Reserve balance is reduced by sent amount
assert_eq!(rocs_in_reserve_on_ahr_after, rocs_in_reserve_on_ahr_before - amount_to_send);
}

#[test]
fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo() {
let wnd_at_westend_parachains: v3::Location = v3::Parent.into();
let wnd_at_asset_hub_rococo =
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Westend)]);
let wnd_at_westend_parachains_latest: Location = wnd_at_westend_parachains.try_into().unwrap();
let owner: AccountId = AssetHubRococo::account_id_of(ALICE);
AssetHubRococo::force_create_foreign_asset(
wnd_at_asset_hub_rococo,
owner,
true,
ASSET_MIN_BALANCE,
vec![],
);
let sov_ahr_on_ahw = AssetHubWestend::sovereign_account_of_parachain_on_other_global_consensus(
NetworkId::Rococo,
AssetHubRococo::para_id(),
);

AssetHubRococo::execute_with(|| {
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;

// setup a pool to pay xcm fees with `wnd_at_asset_hub_rococo` tokens
assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::ForeignAssets::mint(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
wnd_at_asset_hub_rococo.into(),
AssetHubRococoSender::get().into(),
3_000_000_000_000,
));

assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::create_pool(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
Box::new(xcm::v3::Parent.into()),
Box::new(wnd_at_asset_hub_rococo),
));

assert_expected_events!(
AssetHubRococo,
vec![
RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::PoolCreated { .. }) => {},
]
);

assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::add_liquidity(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
Box::new(xcm::v3::Parent.into()),
Box::new(wnd_at_asset_hub_rococo),
1_000_000_000_000,
2_000_000_000_000,
1,
1,
AssetHubRococoSender::get().into()
));

assert_expected_events!(
AssetHubRococo,
vec![
RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::LiquidityAdded {..}) => {},
]
);
});

let amount = ASSET_HUB_WESTEND_ED * 10_000_000;
let penpal_location = AssetHubWestend::sibling_location_of(PenpalB::para_id());
let sov_penpal_on_ahw = AssetHubWestend::sovereign_account_id_of(penpal_location);
// fund Penpal's sovereign account on AssetHub
AssetHubWestend::fund_accounts(vec![(sov_penpal_on_ahw.into(), amount * 2)]);
// fund Penpal's sender account
PenpalB::mint_foreign_asset(
<PenpalB as Chain>::RuntimeOrigin::signed(PenpalAssetOwner::get()),
wnd_at_westend_parachains,
PenpalBSender::get(),
amount * 2,
);

let wnds_in_reserve_on_ahw_before =
<AssetHubWestend as Chain>::account_data_of(sov_ahr_on_ahw.clone()).free;
let sender_wnds_before = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(
wnd_at_westend_parachains.into(),
&PenpalBSender::get(),
)
});
let receiver_wnds_before = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get())
});
send_asset_from_penpal_westend_through_local_asset_hub_to_rococo_asset_hub(
wnd_at_westend_parachains_latest,
amount,
);

AssetHubRococo::execute_with(|| {
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;
assert_expected_events!(
AssetHubRococo,
vec![
// issue WNDs on AHR
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => {
asset_id: *asset_id == wnd_at_westend_parachains,
owner: *owner == AssetHubRococoReceiver::get(),
},
// message processed successfully
RuntimeEvent::MessageQueue(
pallet_message_queue::Event::Processed { success: true, .. }
) => {},
]
);
});

let sender_wnds_after = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(
wnd_at_westend_parachains.into(),
&PenpalBSender::get(),
)
});
let receiver_wnds_after = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get())
});
let wnds_in_reserve_on_ahw_after =
<AssetHubWestend as Chain>::account_data_of(sov_ahr_on_ahw.clone()).free;

// Sender's balance is reduced
assert!(sender_wnds_after < sender_wnds_before);
// Receiver's balance is increased
assert!(receiver_wnds_after > receiver_wnds_before);
// Reserve balance is increased by sent amount (less fess)
assert!(wnds_in_reserve_on_ahw_after > wnds_in_reserve_on_ahw_before);
assert!(wnds_in_reserve_on_ahw_after <= wnds_in_reserve_on_ahw_before + amount);
}
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ parameter_types! {
// The Penpal runtime is utilized for testing with various environment setups.
// This storage item allows us to customize the `NetworkId` where Penpal is deployed.
// By default, it is set to `NetworkId::Rococo` and can be changed using `System::set_storage`.
pub storage RelayNetworkId: NetworkId = NetworkId::Rococo;
pub storage RelayNetworkId: NetworkId = NetworkId::Westend;
bkontur marked this conversation as resolved.
Show resolved Hide resolved
pub RelayNetwork: Option<NetworkId> = Some(RelayNetworkId::get());
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub UniversalLocation: InteriorLocation = [
Loading