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

Support different assets for delivery fees #4375

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
eea690b
feat(xcm-executor): add AssetConverter config item to support multipl…
franciscoaguirre May 8, 2024
5d74482
fix: implement AssetConverter in all runtimes
franciscoaguirre May 8, 2024
8e9df56
feat: add AssetConverters copying the traders
franciscoaguirre May 8, 2024
3ed0430
test(asset-hub-westend): add tests for paying delivery fees with diff…
franciscoaguirre May 8, 2024
da83c68
fix: update lock
franciscoaguirre May 8, 2024
efab825
fix(pallet-xcm): remove jit withdrawal to allow paying delivery fees …
franciscoaguirre May 11, 2024
da7b054
doc: add TODOs I'm considering
franciscoaguirre May 11, 2024
bdfbeaf
feat: start with SwapAssetConverter
franciscoaguirre May 11, 2024
a81ba18
Merge branch 'master' into different-assets-delivery-fees
franciscoaguirre May 15, 2024
c69095f
feat: SwapAssetConverter. Some tests failing
franciscoaguirre May 22, 2024
0193e60
fix(asset-hub-rococo-integration-tests): delivery fee taken from holding
franciscoaguirre May 22, 2024
0b0437c
fix(integration-tests): stick to jit withdrawal for now
franciscoaguirre May 22, 2024
03c01ff
Merge branch 'master' into different-assets-delivery-fees
franciscoaguirre Jul 1, 2024
502ebf6
chore: update Cargo.lock
franciscoaguirre Jul 1, 2024
550d92a
fix: fmt
franciscoaguirre Jul 1, 2024
ba024d1
feat(xcm-executor): remove all logic regarding local execution
franciscoaguirre Jul 1, 2024
69d1043
feat: complete tests
franciscoaguirre Jul 2, 2024
820160e
fix: fmt
franciscoaguirre Jul 2, 2024
677129d
Merge branch 'master' into different-assets-delivery-fees
franciscoaguirre Jul 2, 2024
99c9749
feat: remove support for sufficient asset converters
franciscoaguirre Jul 2, 2024
05b620d
feat(asset-hub-rococo): add a PoolAssetsConverter
franciscoaguirre Jul 2, 2024
522e7c7
feat(emulated-tests): add USDT to genesis and create WND<>USDT pool i…
franciscoaguirre Jul 3, 2024
629dcce
doc: prdoc
franciscoaguirre Jul 3, 2024
b6f3b6e
doc(asset-hub-westend-integration-tests): change the docs for a test
franciscoaguirre Jul 3, 2024
7ffd02a
chore(xcm-executor): change order of associated types in config
franciscoaguirre Jul 3, 2024
69c22ce
fix: fmt
franciscoaguirre Jul 3, 2024
b485475
Merge branch 'master' into different-assets-delivery-fees
franciscoaguirre Jul 3, 2024
df196fe
feat: remove AssetConverter and use AssetExchanger instead
franciscoaguirre Jul 4, 2024
1639489
doc: prdoc
franciscoaguirre Jul 4, 2024
9875ee2
doc: prdoc
franciscoaguirre Jul 4, 2024
c3d1554
fix: clippy and feedback
franciscoaguirre Jul 4, 2024
ab890aa
Merge branch 'master' into different-assets-delivery-fees
franciscoaguirre Jul 4, 2024
e2107f8
fix: zepter and taplo
franciscoaguirre Jul 4, 2024
84d0f14
Merge branch 'master' into different-assets-delivery-fees
franciscoaguirre Jul 5, 2024
77b0cc8
feat(xcm-executor): not error in case there are no delivery fees
franciscoaguirre Jul 5, 2024
2888826
chore(xcm-executor): deduplicate swapping logic in take_fees
franciscoaguirre Jul 5, 2024
90807aa
fix(assets-common): remove duplicated feature flags
franciscoaguirre Jul 5, 2024
10dd60f
chore(xcm-executor): remove default implementation for AssetExchange
franciscoaguirre Jul 5, 2024
49d76b9
doc: update prdoc crate bumps
franciscoaguirre Jul 5, 2024
a2d3b68
Apply suggestions from code review
acatangiu Jul 9, 2024
d4d6055
fix executor
acatangiu Jul 9, 2024
8f266c4
clean up tests
acatangiu Jul 9, 2024
11a03ee
Merge branch 'master' into different-assets-delivery-fees
franciscoaguirre Jul 17, 2024
b0e1c60
chore: address some docs and naming feedback
franciscoaguirre Jul 17, 2024
18e8b7c
fix(staging-xcm-executor): move log to tracing
franciscoaguirre Jul 18, 2024
d1baffc
chore: address more feedback
franciscoaguirre Jul 18, 2024
28553fb
Merge branch 'master' into different-assets-delivery-fees
franciscoaguirre Jul 18, 2024
d576a76
fix: fmt
franciscoaguirre Jul 18, 2024
1605b8a
Merge branch 'master' into different-assets-delivery-fees
franciscoaguirre Jul 22, 2024
5e1c999
fix: fmt
franciscoaguirre Jul 22, 2024
1fe6c08
feat(xcm-builder): rename FungiblesPoolAdapter to SingleAssetExchange…
franciscoaguirre Jul 22, 2024
184b2eb
feat(xcm-builder): tests for SingleAssetExchangeAdapter
franciscoaguirre Jul 24, 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,155 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
assert_eq!(receiver_rocs_after, receiver_rocs_before + foreign_amount_to_send);
}

// =================================================================================
// ======= Reserve Transfers - Sufficient Foreign Asset - AssetHub<>Parachain ======
// =================================================================================
/// Reserve Transfers of a sufficient foreign asset from System Parachain to Parachain should
/// work without using any other token.
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
#[test]
fn reserve_transfer_sufficient_foreign_assets_from_system_para_to_para() {
use penpal_runtime::xcm_config::ASSET_HUB_ID;

let destination = AssetHubWestend::sibling_location_of(PenpalA::para_id());
let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of(destination.clone());
let sender = AssetHubWestendSender::get();
let fee_amount_to_send = ASSET_HUB_WESTEND_ED * 100;
let asset_amount_to_send = ASSET_HUB_WESTEND_ED * 100;
let asset_owner = AssetHubWestendAssetOwner::get();
let asset_owner_signer = <AssetHubWestend as Chain>::RuntimeOrigin::signed(asset_owner.clone());
let receiver = PenpalAReceiver::get();

let roc_at_westend_parachains = Location::new(2, GlobalConsensus(NetworkId::Rococo));
// Configure destination chain to trust AH as reserve of ROC
PenpalA::execute_with(|| {
assert_ok!(<PenpalA as Chain>::System::set_storage(
<PenpalA as Chain>::RuntimeOrigin::root(),
vec![(
penpal_runtime::xcm_config::CustomizableAssetFromSystemAssetHub::key().to_vec(),
roc_at_westend_parachains.encode(),
)],
));
});
// Create sufficient asset.
PenpalA::force_create_foreign_asset(
roc_at_westend_parachains.clone(),
PenpalAssetOwner::get(),
true, // Mark it as sufficient.
10_000_000_000,
vec![],
);
AssetHubWestend::force_create_foreign_asset(
roc_at_westend_parachains.clone().try_into().unwrap(),
asset_owner,
true, // Mark it as sufficient.
10_000_000_000,
vec![(sender.clone(), ASSET_HUB_WESTEND_ED * 10000)],
);

let assets: Assets = vec![
(
(Parent, Parent, GlobalConsensus(NetworkId::Rococo)),
asset_amount_to_send + fee_amount_to_send,
).into(),
].into();
// Just to be very clear we don't need to send any native asset.
assert_eq!(assets.len(), 1);
let fee_asset_index = 0;

// Create SA-of-Penpal-on-AHR with ED.
// This ED isn't reflected in any derivative in a PenpalA account.
AssetHubWestend::fund_accounts(vec![(sov_penpal_on_ahr.into(), ASSET_HUB_WESTEND_ED)]);

// We want to make sure the sender doesn't have ANY native asset other than ED, so we can make
// sure we are paying delivery fees with the sufficient asset.
AssetHubWestend::execute_with(|| {
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::Balances::force_set_balance(
<AssetHubWestend as Chain>::RuntimeOrigin::root(),
sender.clone().into(),
ASSET_HUB_WESTEND_ED,
));
});

let para_test_args = TestContext {
sender: sender.clone(),
receiver: receiver.clone(),
args: TestArgs::new_para(
destination,
receiver.clone(),
asset_amount_to_send,
assets,
None,
fee_asset_index,
),
};
let mut test = SystemParaToParaTest::new(para_test_args);

// Query initial balances.
let sender_balance_before = test.sender.balance;
let sender_foreign_assets_before = AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(roc_at_westend_parachains.clone().try_into().unwrap(), &sender)
});
let receiver_foreign_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(
roc_at_westend_parachains.clone(),
&receiver,
)
});

// Set assertions and dispatchables
test.set_assertion::<AssetHubWestend>(system_para_to_para_sender_sufficient_foreign_asset_assertions);
test.set_assertion::<PenpalA>(system_para_to_para_receiver_assertions);
test.set_dispatchable::<AssetHubWestend>(ah_to_para_transfer_assets);
test.assert();

// Query initial balances.
let sender_balance_after = test.sender.balance;
let sender_foreign_assets_after = AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(roc_at_westend_parachains.clone().try_into().unwrap(), &sender)
});
let receiver_foreign_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(
roc_at_westend_parachains.clone(),
&receiver,
)
});

// The native asset balance is the same. They weren't send or used for fees.
assert_eq!(sender_balance_before, sender_balance_after);
// The assets have been sent and used for fees.
assert!(sender_foreign_assets_after < sender_foreign_assets_before - asset_amount_to_send);
assert!(receiver_foreign_assets_after > receiver_foreign_assets_before);
}

pub fn system_para_to_para_sender_sufficient_foreign_asset_assertions(t: SystemParaToParaTest) {
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
AssetHubWestend::assert_xcm_pallet_attempted_complete(None);

let sov_account_of_dest = AssetHubWestend::sovereign_account_id_of(t.args.dest.clone());
for (index, asset) in t.args.assets.into_inner().into_iter().enumerate() {
let expected_id = asset.id.0.clone().try_into().unwrap();
let asset_amount = if let Fungible(a) = asset.fun { Some(a) } else { None }.unwrap();
assert_expected_events!(
AssetHubWestend,
vec![
// Amount of foreign asset is transferred to Parachain's sovereign account.
RuntimeEvent::ForeignAssets(
pallet_assets::Event::Transferred { asset_id, from, to, amount },
) => {
asset_id: *asset_id == expected_id,
from: *from == t.sender.account_id, // Sender is test sender.
to: *to == sov_account_of_dest, // Receiver is parachain's sovereign account.
amount: *amount == asset_amount, // Asset amount is the one specified in the test.
},
]
);
}
}

/// Reserve Transfers of native asset from Parachain to System Parachain should work
// ===========================================================================
// ======= Transfer - Native + Bridged Assets - Parachain->AssetHub ==========
Expand Down Expand Up @@ -613,13 +762,16 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
<ForeignAssets as Inspect<_>>::balance(roc_at_westend_parachains, &receiver)
});

// Sender's balance is reduced by amount sent plus delivery fees
assert!(sender_wnds_after < sender_wnds_before - wnd_to_send);
// Sender's balance is reduced by amount sent.
assert_eq!(sender_wnds_after, sender_wnds_before - wnd_to_send);
assert_eq!(sender_rocs_after, sender_rocs_before - roc_to_send);
// Sovereign accounts on reserve are changed accordingly
let delivery_fees_amount = 31_340_000_000; // TODO: Estimate this.
// Delivery fees stay in the sender chain, so the balance of the sender's
// sovereign account reflects this.
assert_eq!(
wnds_in_sender_reserve_on_ah_after,
wnds_in_sender_reserve_on_ah_before - wnd_to_send
wnds_in_sender_reserve_on_ah_before - wnd_to_send + delivery_fees_amount
);
assert_eq!(
rocs_in_sender_reserve_on_ah_after,
Expand All @@ -630,8 +782,9 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
rocs_in_receiver_reserve_on_ah_after,
rocs_in_receiver_reserve_on_ah_before + roc_to_send
);
// Receiver's balance is increased
// Receiver's balance is increased by amount sent minus delivery fees.
assert!(receiver_wnds_after > receiver_wnds_before);
assert!(receiver_wnds_after < receiver_wnds_before + wnd_to_send);
assert_eq!(receiver_rocs_after, receiver_rocs_before + roc_to_send);
}

Expand Down
Loading
Loading