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

[xcm-v5] implement RFC#100: add new InitiateTransfer instruction #5876

Merged
merged 89 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 84 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
3d7e24a
feat(xcm): add PayFees instruction
franciscoaguirre Aug 20, 2024
0a88320
chore(xcm-executor): clean up executor unit test and move everything …
franciscoaguirre Aug 21, 2024
0b16ca5
Merge branch 'xcm-v5' into xcm-pay-fees
franciscoaguirre Aug 21, 2024
2393087
feat(xcm-executor): tests for delivery fees and old BuyExecution
franciscoaguirre Aug 21, 2024
b9ca9e0
feat(xcm-executor): interaction between PayFees and RefundSurplus
franciscoaguirre Aug 21, 2024
22efce5
fix(xcm): add builder(pays_fees) to old xcm versions
franciscoaguirre Aug 21, 2024
49f63a4
chore(xcm-executor): unhappy tests for PayFees
franciscoaguirre Aug 21, 2024
50b06d6
chore(xcm-executor): test that leftover fees are also trapped
franciscoaguirre Aug 23, 2024
738a8c1
chore: add made-up benchmarks to all runtimes
franciscoaguirre Aug 26, 2024
995cc09
feat(xcm-builder): allow PayFees in AllowTopLevelPaidExecutionFrom ba…
franciscoaguirre Aug 26, 2024
679c3c7
feat(xcm-executor): use fees register in DepositReserveAsset
franciscoaguirre Aug 26, 2024
d934c64
feat(xcm-emulator): add set_call method for dispatching calls
franciscoaguirre Aug 26, 2024
52f3ba1
test(asset-hub-westend-integration-tests): add xcm estimation test wi…
franciscoaguirre Aug 26, 2024
900bb46
fix: fmt
franciscoaguirre Aug 26, 2024
56bcd4d
fix(xcm-executor): remove unnecessary clones
franciscoaguirre Aug 27, 2024
c062c0c
chore(asset-hub-westend-integration-tests): refactor test to decl macro
franciscoaguirre Aug 27, 2024
94f831f
feat(asset-hub-rococo-integration-tests): add PayFees test
franciscoaguirre Aug 27, 2024
3198950
fix: fmt
franciscoaguirre Aug 27, 2024
6bf562b
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=ro…
Aug 27, 2024
15a5333
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=we…
Aug 27, 2024
fb79e69
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=co…
Aug 27, 2024
4c9dddc
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=as…
Aug 27, 2024
a8d5d1d
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=as…
Aug 27, 2024
c1c95dc
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=co…
Aug 27, 2024
0c5afe3
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Aug 27, 2024
338d8de
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Aug 27, 2024
12164f8
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=pe…
Aug 27, 2024
c3b6bd0
chore: add missing benchmark and made up benchmarks for all runtimes
franciscoaguirre Aug 27, 2024
e2c620e
fix: remove duplicated weight
franciscoaguirre Aug 27, 2024
86b151c
fix: remove unused imports
franciscoaguirre Aug 27, 2024
2937662
Merge branch 'xcm-v5' into xcm-pay-fees
franciscoaguirre Aug 27, 2024
0eaa9fb
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=we…
Aug 27, 2024
39cf7b1
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=ro…
Aug 27, 2024
abe36c3
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=co…
Aug 27, 2024
a60172c
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=as…
Aug 27, 2024
8470fca
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=as…
Aug 27, 2024
6a59c1d
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Aug 27, 2024
bdae9ec
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=co…
Aug 27, 2024
6b339a0
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Aug 27, 2024
02b0fbb
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=pe…
Aug 27, 2024
ec92154
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=pe…
Aug 27, 2024
1091ac7
doc: add prdoc
franciscoaguirre Aug 30, 2024
f0f1aac
fix: prdoc
franciscoaguirre Aug 30, 2024
d32a028
Merge branch 'xcm-v5' into xcm-pay-fees
franciscoaguirre Sep 4, 2024
62e71ca
Merge branch 'xcm-v5' into xcm-pay-fees
acatangiu Oct 1, 2024
25a2b4d
xcm-v5: add new InitiateTransfer instruction
acatangiu Sep 27, 2024
91794c7
add benchmark and weights for InitiateTransfer
acatangiu Sep 27, 2024
adb4ac2
add integration tests
acatangiu Sep 30, 2024
4e568d1
have tests use PayFees
acatangiu Oct 2, 2024
60345e5
adjust implementation and documentation to work with PayFees
acatangiu Oct 3, 2024
5378ec7
clean up test
acatangiu Oct 3, 2024
3ef8cf1
fix import
acatangiu Oct 3, 2024
1737476
fix checks for teleports and reserve-withdrawals
acatangiu Oct 3, 2024
919107e
chore: address feedback
franciscoaguirre Oct 7, 2024
f10feb0
".git/.scripts/commands/fmt/fmt.sh"
Oct 7, 2024
a9334fa
fix: if no delivery fees are defined, xcm should still work
franciscoaguirre Oct 7, 2024
adbec21
".git/.scripts/commands/fmt/fmt.sh"
Oct 7, 2024
328891c
Merge branch 'xcm-pay-fees' of github.com:paritytech/polkadot-sdk int…
acatangiu Oct 7, 2024
31d283a
fix auto-swap delivery fee when using PayFees
acatangiu Oct 7, 2024
f9af07d
Merge branch 'xcm-v5' of github.com:paritytech/polkadot-sdk into impl…
acatangiu Oct 17, 2024
b0ffd1a
fix merge dmg
acatangiu Oct 17, 2024
ec07efc
Merge branch 'xcm-v5' of github.com:paritytech/polkadot-sdk into impl…
acatangiu Oct 17, 2024
6e3c5ec
fix merge dmg
acatangiu Oct 17, 2024
31cf0a8
Merge branch 'xcm-v5' into impl-rfc-100
acatangiu Oct 21, 2024
c09dd14
consolidate v5->v4 conversion
acatangiu Oct 21, 2024
6165999
test permissions
franciscoaguirre Oct 21, 2024
3cf1f10
revert: test permissions
franciscoaguirre Oct 21, 2024
5db5842
chore: change VersionedXcm::V5 to VersionedXcm::from
franciscoaguirre Oct 21, 2024
2abea08
fix: add new instruction benchmark to missing runtimes
franciscoaguirre Oct 21, 2024
e27689b
bench(xcm): initiate_transfer
franciscoaguirre Oct 21, 2024
c8352fd
".git/.scripts/commands/fmt/fmt.sh"
Oct 21, 2024
a181c4d
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=as…
Oct 21, 2024
f184a9c
doc: add prdoc
franciscoaguirre Oct 21, 2024
dec6af9
fix: prdoc bad character
franciscoaguirre Oct 21, 2024
1cc0c56
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=we…
Oct 21, 2024
668b548
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=ro…
Oct 21, 2024
5100b2c
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Oct 21, 2024
b421fad
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=co…
Oct 21, 2024
5da29b9
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=as…
Oct 21, 2024
127b844
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=co…
Oct 21, 2024
6623f50
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Oct 21, 2024
f92bb6b
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=pe…
Oct 21, 2024
2649e67
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=pe…
Oct 21, 2024
bef1b0a
fix: remove unnecessary clone
franciscoaguirre Oct 22, 2024
fb35fd9
chore: link issue to TODO
franciscoaguirre Oct 23, 2024
fb75a73
chore: create new Error type in XCMv5
franciscoaguirre Oct 23, 2024
89e0ce0
chore(xcm): link issue to TODO
franciscoaguirre Oct 23, 2024
58db84d
chore: remove commented code
franciscoaguirre Oct 23, 2024
b7db28f
fix: updated error
franciscoaguirre Oct 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use sp_keyring::Sr25519Keyring as Keyring;

// Cumulus
use emulated_integration_tests_common::{
accounts, build_genesis_storage, collators, PenpalSiblingSovereignAccount,
PenpalTeleportableAssetLocation, RESERVABLE_ASSET_ID, SAFE_XCM_VERSION, USDT_ID,
accounts, build_genesis_storage, collators, PenpalASiblingSovereignAccount,
PenpalATeleportableAssetLocation, PenpalBSiblingSovereignAccount,
PenpalBTeleportableAssetLocation, RESERVABLE_ASSET_ID, SAFE_XCM_VERSION, USDT_ID,
};
use parachains_common::{AccountId, Balance};

Expand Down Expand Up @@ -77,10 +78,17 @@ pub fn genesis() -> Storage {
},
foreign_assets: asset_hub_rococo_runtime::ForeignAssetsConfig {
assets: vec![
// Penpal's teleportable asset representation
// PenpalA's teleportable asset representation
(
PenpalTeleportableAssetLocation::get(),
PenpalSiblingSovereignAccount::get(),
PenpalATeleportableAssetLocation::get(),
PenpalASiblingSovereignAccount::get(),
false,
ED,
),
// PenpalB's teleportable asset representation
(
PenpalBTeleportableAssetLocation::get(),
PenpalBSiblingSovereignAccount::get(),
false,
ED,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use sp_keyring::Sr25519Keyring as Keyring;

// Cumulus
use emulated_integration_tests_common::{
accounts, build_genesis_storage, collators, PenpalBSiblingSovereignAccount,
PenpalBTeleportableAssetLocation, PenpalSiblingSovereignAccount,
PenpalTeleportableAssetLocation, RESERVABLE_ASSET_ID, SAFE_XCM_VERSION, USDT_ID,
accounts, build_genesis_storage, collators, PenpalASiblingSovereignAccount,
PenpalATeleportableAssetLocation, PenpalBSiblingSovereignAccount,
PenpalBTeleportableAssetLocation, RESERVABLE_ASSET_ID, SAFE_XCM_VERSION, USDT_ID,
};
use parachains_common::{AccountId, Balance};

Expand Down Expand Up @@ -75,10 +75,10 @@ pub fn genesis() -> Storage {
},
foreign_assets: asset_hub_westend_runtime::ForeignAssetsConfig {
assets: vec![
// Penpal's teleportable asset representation
// PenpalA's teleportable asset representation
(
PenpalTeleportableAssetLocation::get(),
PenpalSiblingSovereignAccount::get(),
PenpalATeleportableAssetLocation::get(),
PenpalASiblingSovereignAccount::get(),
false,
ED,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,26 @@ pub const TELEPORTABLE_ASSET_ID: u32 = 2;
// USDT registered on AH as (trust-backed) Asset and reserve-transferred between Parachain and AH
pub const USDT_ID: u32 = 1984;

pub const PENPAL_ID: u32 = 2000;
pub const PENPAL_A_ID: u32 = 2000;
pub const PENPAL_B_ID: u32 = 2001;
pub const ASSETS_PALLET_ID: u8 = 50;

parameter_types! {
pub PenpalTeleportableAssetLocation: xcm::v5::Location
pub PenpalATeleportableAssetLocation: xcm::v5::Location
= xcm::v5::Location::new(1, [
xcm::v5::Junction::Parachain(PENPAL_ID),
xcm::v5::Junction::Parachain(PENPAL_A_ID),
xcm::v5::Junction::PalletInstance(ASSETS_PALLET_ID),
xcm::v5::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into()),
]
);
pub PenpalSiblingSovereignAccount: AccountId = Sibling::from(PENPAL_ID).into_account_truncating();
pub PenpalBTeleportableAssetLocation: xcm::v5::Location
= xcm::v5::Location::new(1, [
xcm::v5::Junction::Parachain(PENPAL_B_ID),
xcm::v5::Junction::PalletInstance(ASSETS_PALLET_ID),
xcm::v5::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into()),
]
);
pub PenpalASiblingSovereignAccount: AccountId = Sibling::from(PENPAL_A_ID).into_account_truncating();
pub PenpalBSiblingSovereignAccount: AccountId = Sibling::from(PENPAL_B_ID).into_account_truncating();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
imports::*,
tests::teleport::do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using_xt,
};
use xcm::latest::AssetTransferFilter;

fn para_to_para_assethub_hop_assertions(t: ParaToParaThroughAHTest) {
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
Expand Down Expand Up @@ -819,3 +820,85 @@ fn transfer_native_asset_from_relay_to_para_through_asset_hub() {
// should be non-zero
assert!(receiver_assets_after < receiver_assets_before + amount_to_send);
}

// ==============================================================================================
// ==== Bidirectional Transfer - Native + Teleportable Foreign Assets - Parachain<->AssetHub ====
// ==============================================================================================
/// Transfers of native asset plus teleportable foreign asset from Parachain to AssetHub and back
/// with fees paid using native asset.
#[test]
fn bidirectional_transfer_multiple_assets_between_penpal_and_asset_hub() {
fn execute_xcm_penpal_to_asset_hub(t: ParaToSystemParaTest) -> DispatchResult {
// let transport_fees: Asset = (Parent, 40_000_000_000u128).into();
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
let all_assets = t.args.assets.clone().into_inner();
let mut assets = all_assets.clone();
let mut fees = assets.remove(t.args.fee_asset_item as usize);
// TODO: dry-run to get exact fees, for now just use half the fees locally, half on dest
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
if let Fungible(fees_amount) = fees.fun {
fees.fun = Fungible(fees_amount / 2);
}
// xcm to be executed at dest
let xcm_on_dest = Xcm(vec![
// since this is the last hop, we don't need to further use any assets previously
// reserved for fees (there are no further hops to cover transport fees for); we
// RefundSurplus to get back any unspent fees
RefundSurplus,
DepositAsset { assets: Wild(All), beneficiary: t.args.beneficiary },
]);
let xcm = Xcm::<()>(vec![
WithdrawAsset(all_assets.into()),
PayFees { asset: fees.clone() },
InitiateTransfer {
destination: t.args.dest,
remote_fees: Some(AssetTransferFilter::ReserveWithdraw(fees.into())),
assets: vec![AssetTransferFilter::Teleport(assets.into())],
remote_xcm: xcm_on_dest,
},
]);
<PenpalA as PenpalAPallet>::PolkadotXcm::execute(
t.signed_origin,
bx!(xcm::VersionedXcm::from(xcm.into())),
Weight::MAX,
)
.unwrap();
Ok(())
}
fn execute_xcm_asset_hub_to_penpal(t: SystemParaToParaTest) -> DispatchResult {
let all_assets = t.args.assets.clone().into_inner();
let mut assets = all_assets.clone();
let mut fees = assets.remove(t.args.fee_asset_item as usize);
// TODO: dry-run to get exact fees, for now just use half the fees locally, half on dest
if let Fungible(fees_amount) = fees.fun {
fees.fun = Fungible(fees_amount / 2);
}
// xcm to be executed at dest
let xcm_on_dest = Xcm(vec![
// since this is the last hop, we don't need to further use any assets previously
// reserved for fees (there are no further hops to cover transport fees for); we
// RefundSurplus to get back any unspent fees
RefundSurplus,
DepositAsset { assets: Wild(All), beneficiary: t.args.beneficiary },
]);
let xcm = Xcm::<()>(vec![
WithdrawAsset(all_assets.into()),
PayFees { asset: fees.clone() },
InitiateTransfer {
destination: t.args.dest,
remote_fees: Some(AssetTransferFilter::ReserveDeposit(fees.into())),
assets: vec![AssetTransferFilter::Teleport(assets.into())],
remote_xcm: xcm_on_dest,
},
]);
<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::execute(
t.signed_origin,
bx!(xcm::VersionedXcm::from(xcm.into())),
Weight::MAX,
)
.unwrap();
Ok(())
}
do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using_xt(
execute_xcm_penpal_to_asset_hub,
execute_xcm_asset_hub_to_penpal,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,6 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) {
assert_expected_events!(
AssetHubWestend,
vec![
// native asset used for fees is transferred to Parachain's Sovereign account as reserve
RuntimeEvent::Balances(
pallet_balances::Event::Transfer { from, to, amount }
) => {
from: *from == t.sender.account_id,
to: *to == AssetHubWestend::sovereign_account_id_of(
t.args.dest.clone()
),
amount: *amount == t.args.amount,
},
// foreign asset is burned locally as part of teleportation
RuntimeEvent::ForeignAssets(pallet_assets::Event::Burned { asset_id, owner, balance }) => {
asset_id: *asset_id == expected_foreign_asset_id,
Expand Down Expand Up @@ -283,13 +273,13 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
ah_to_para_dispatchable: fn(SystemParaToParaTest) -> DispatchResult,
) {
// Init values for Parachain
let fee_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 100;
let fee_amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000;
let asset_location_on_penpal = PenpalLocalTeleportableToAssetHub::get();
let asset_id_on_penpal = match asset_location_on_penpal.last() {
Some(Junction::GeneralIndex(id)) => *id as u32,
_ => unreachable!(),
};
let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100;
let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 1000;
let asset_owner = PenpalAssetOwner::get();
let system_para_native_asset_location = RelayLocation::get();
let sender = PenpalASender::get();
Expand Down Expand Up @@ -318,7 +308,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
<PenpalA as Chain>::RuntimeOrigin::signed(asset_owner.clone()),
asset_id_on_penpal,
sender.clone(),
asset_amount_to_send,
asset_amount_to_send * 2,
);
// fund Parachain's check account to be able to teleport
PenpalA::fund_accounts(vec![(
Expand Down Expand Up @@ -433,6 +423,10 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using
));
});

// Only send back half the amount.
let asset_amount_to_send = asset_amount_to_send / 2;
let fee_amount_to_send = fee_amount_to_send / 2;

let ah_to_penpal_beneficiary_id = PenpalAReceiver::get();
let penpal_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalA::para_id());
let ah_assets: Assets = vec![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ mod imports {
penpal_emulated_chain::{
penpal_runtime::xcm_config::{
CustomizableAssetFromSystemAssetHub as PenpalCustomizableAssetFromSystemAssetHub,
LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub,
UniversalLocation as PenpalUniversalLocation,
},
PenpalAssetOwner, PenpalBParaPallet as PenpalBPallet,
Expand Down
Loading
Loading