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 WeightTrader: Swap Fee Asset for Native Asset #1845

Merged
merged 109 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
39935e9
move swap trait and impl into separate module
muharem Sep 15, 2023
d8ab7c1
restructure imports
muharem Sep 15, 2023
6d6cc18
transfer swap
muharem Sep 20, 2023
a355241
swap credit
muharem Sep 22, 2023
a78ac71
with transaction
muharem Sep 22, 2023
888c9fa
preservation
muharem Sep 22, 2023
793b612
add amounts to the event
muharem Sep 22, 2023
cdaf500
not expendable constraint
muharem Sep 25, 2023
2a19a41
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Sep 25, 2023
e237dfc
vec import
muharem Sep 25, 2023
0c13c85
fix tests, preserve account
muharem Sep 25, 2023
24654b8
tests
muharem Sep 26, 2023
e0bd8b7
max lenght of the swap path in swap trait
muharem Sep 26, 2023
80dbcab
fix clippy
muharem Sep 26, 2023
847207b
debug impls for imbalances
muharem Sep 26, 2023
53c699f
eq and partial_eq impls for imbalance
muharem Sep 28, 2023
827ce1b
eq, partial_eq, runtime debug for credit
muharem Sep 28, 2023
d533acf
tests
muharem Sep 28, 2023
69b17f8
Apply suggestions from code review
muharem Sep 28, 2023
28edff5
correct docs
muharem Sep 28, 2023
697afa6
dev comments
muharem Sep 28, 2023
1c50220
use eq/partial_eq/runtime_debug derives with no bound version
muharem Sep 29, 2023
fe9e4f8
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Oct 5, 2023
e7ffbb4
swap trait update
muharem Oct 5, 2023
ee49f27
box multi asset id
muharem Oct 7, 2023
ee9d2eb
use vec instead bounded vec
muharem Oct 7, 2023
ced5e99
update to new api
muharem Oct 7, 2023
7fee81e
drop clone
muharem Oct 7, 2023
b63cd73
box arguments and drop bounded vec from benches
muharem Oct 8, 2023
01bd4da
no box for benchmarks impls
muharem Oct 8, 2023
e2b99f9
single balance type for Currency and Assets
muharem Oct 8, 2023
37b2e34
Balance trait bound on Balance generic type
muharem Oct 8, 2023
d9bc836
try into for credit
muharem Oct 8, 2023
0193864
drop clone
muharem Oct 8, 2023
ae19bb8
fix
muharem Oct 8, 2023
2372277
clippy fixes
muharem Oct 9, 2023
d1f37c7
review fixes
muharem Oct 9, 2023
3a4935e
remove unused trait
muharem Oct 9, 2023
75a7b8a
note in docs for swap traits
muharem Oct 10, 2023
03cee5b
extract for imbalance
muharem Oct 11, 2023
6b0c847
swap weight trader
muharem Oct 11, 2023
1847090
swap weight trader for westend xcm executor
muharem Oct 11, 2023
1c11bc3
clippi fix: remove clone
muharem Oct 11, 2023
991b734
fmt
muharem Oct 11, 2023
ec25bca
ignore tests
muharem Oct 11, 2023
b3d3caf
resolve credit to account impl
muharem Oct 11, 2023
e16f2f7
resolve fees to treasury account
muharem Oct 11, 2023
20b85a5
ignore test
muharem Oct 11, 2023
ec2cf1d
impl on_nonzero_unbalanced instead on_unbalanced
muharem Oct 18, 2023
a8fadda
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Oct 23, 2023
168141d
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Oct 23, 2023
2b13f27
adjustments for rococo setup
muharem Oct 24, 2023
bbca52d
adjustments for rococo tests
muharem Oct 24, 2023
251d3f8
Merge branch 'master' into muharem-asset-conversion-credit-swap
muharem Oct 24, 2023
66a6611
rococo benchmarks
muharem Oct 24, 2023
01eab06
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Oct 25, 2023
b21d0aa
fungible/s union_of
muharem Oct 25, 2023
50cdf82
tests for fungible/s sets
muharem Oct 25, 2023
5fbdc2a
asset conversion
muharem Oct 25, 2023
f490744
asset conversion tx payment
muharem Oct 25, 2023
45d450d
substrate test runtime
muharem Oct 25, 2023
baac8e5
asset hub common impls
muharem Oct 25, 2023
c4eb514
asset hub runtimes
muharem Oct 25, 2023
d28ffea
asset hub emulated tests
muharem Oct 25, 2023
d255301
clippy fixes
muharem Oct 25, 2023
4ec7496
clippy fixes
muharem Oct 25, 2023
2ce5071
Apply suggestions from code review
muharem Oct 26, 2023
c60fa97
fixes
muharem Oct 26, 2023
3b187eb
derive Eq
muharem Oct 26, 2023
03bec01
update bounds
muharem Oct 26, 2023
51c6dfc
benchmarks
muharem Oct 30, 2023
1a9c5f3
weights
muharem Oct 30, 2023
e0f1d0a
remove inc_providers on pool creation
muharem Oct 30, 2023
78332d7
remove unused var
muharem Oct 30, 2023
3f59637
account touch
muharem Oct 31, 2023
9ea208d
remove conrain pair from union_of
muharem Oct 31, 2023
d87a80e
should touch
muharem Oct 31, 2023
55917dd
touch doc
muharem Oct 31, 2023
497c92e
Merge branch 'muharem-asset-conversion-without-fungible' into muharem…
muharem Oct 31, 2023
62850a7
trader with target asset
muharem Oct 31, 2023
964afa0
revert changes in impls
muharem Oct 31, 2023
04091d8
logs
muharem Nov 1, 2023
bf3ce63
docs
muharem Nov 1, 2023
33a7730
remove comment
muharem Nov 2, 2023
6c17db2
tests
muharem Nov 14, 2023
f9c3397
more tests
muharem Nov 15, 2023
47512ea
move mock mod to the bottom
muharem Nov 15, 2023
a7bdc81
more tests
muharem Nov 15, 2023
b49dce0
more tests
muharem Nov 16, 2023
34dfcce
resolve to staking pot
muharem Nov 16, 2023
bc12fc1
remove outdated tests
muharem Nov 16, 2023
8025a40
remove ignore
muharem Nov 16, 2023
cdffd5a
remove unused type alias
muharem Nov 17, 2023
0a89934
return error
muharem Nov 20, 2023
5f93423
Merge remote-tracking branch 'origin/master' into muharem-swap-weight…
muharem Dec 20, 2023
673ed3e
remove dublicate tests
muharem Dec 20, 2023
dbc6a8d
prdoc
muharem Dec 20, 2023
cb30d43
clippy fix
muharem Dec 20, 2023
8b85a3d
ignore test
muharem Dec 20, 2023
4088a5c
toml format
muharem Dec 20, 2023
472f6e7
Merge remote-tracking branch 'origin/master' into muharem-swap-weight…
muharem Jan 8, 2024
2ff205e
swap trader for rococo
muharem Jan 8, 2024
cc182e2
revert back hex-literal dep import prev changes
muharem Jan 8, 2024
b016d9b
integration tests
muharem Jan 8, 2024
6a5f665
remove TakeFirstAssetTrader trader and update affected tests
muharem Jan 9, 2024
b22702f
fix tests
muharem Jan 9, 2024
4401b7a
toml format
muharem Jan 10, 2024
da33ead
Merge remote-tracking branch 'origin/master' into muharem-swap-weight…
muharem Jan 10, 2024
9b8c158
Merge branch 'master' into muharem-swap-weight-trader
muharem Jan 16, 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
4 changes: 4 additions & 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 @@ -27,78 +27,3 @@ fn send_transact_as_superuser_from_relay_to_system_para_works() {
Some(Weight::from_parts(1_019_445_000, 200_000)),
)
}

/// Parachain should be able to send XCM paying its fee with sufficient asset
/// in the System Parachain
#[test]
fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() {
let para_sovereign_account = AssetHubRococo::sovereign_account_id_of(
AssetHubRococo::sibling_location_of(PenpalA::para_id()),
);

// Force create and mint assets for Parachain's sovereign account
AssetHubRococo::force_create_and_mint_asset(
ASSET_ID,
ASSET_MIN_BALANCE,
true,
para_sovereign_account.clone(),
Some(Weight::from_parts(1_019_445_000, 200_000)),
ASSET_MIN_BALANCE * 1000000000,
);

// We just need a call that can pass the `SafeCallFilter`
// Call values are not relevant
let call = AssetHubRococo::force_create_asset_call(
ASSET_ID,
para_sovereign_account.clone(),
true,
ASSET_MIN_BALANCE,
);

let origin_kind = OriginKind::SovereignAccount;
let fee_amount = ASSET_MIN_BALANCE * 1000000;
let native_asset =
(X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())), fee_amount).into();

let root_origin = <PenpalA as Chain>::RuntimeOrigin::root();
let system_para_destination = PenpalA::sibling_location_of(AssetHubRococo::para_id()).into();
let xcm = xcm_transact_paid_execution(
call,
origin_kind,
native_asset,
para_sovereign_account.clone(),
);

PenpalA::execute_with(|| {
assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send(
root_origin,
bx!(system_para_destination),
bx!(xcm),
));

PenpalA::assert_xcm_pallet_sent();
});

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

AssetHubRococo::assert_xcmp_queue_success(Some(Weight::from_parts(
15_594_564_000,
562_893,
)));

assert_expected_events!(
AssetHubRococo,
vec![
RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => {
asset_id: *asset_id == ASSET_ID,
owner: *owner == para_sovereign_account,
balance: *balance == fee_amount,
},
RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, .. }) => {
asset_id: *asset_id == ASSET_ID,
},
]
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,130 @@ fn cannot_create_pool_from_pool_assets() {
);
});
}

#[test]
fn pay_xcm_fee_with_some_asset_swapped_for_native() {
let asset_native = asset_hub_rococo_runtime::xcm_config::TokenLocation::get();
let asset_one = MultiLocation {
parents: 0,
interior: X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())),
};
let penpal = AssetHubRococo::sovereign_account_id_of(AssetHubRococo::sibling_location_of(
PenpalA::para_id(),
));

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

// set up pool with ASSET_ID <> NATIVE pair
assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::Assets::create(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
ASSET_ID.into(),
AssetHubRococoSender::get().into(),
ASSET_MIN_BALANCE,
));
assert!(<AssetHubRococo as AssetHubRococoPallet>::Assets::asset_exists(ASSET_ID));

assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::Assets::mint(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
ASSET_ID.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(asset_native),
Box::new(asset_one),
));

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(asset_native),
Box::new(asset_one),
1_000_000_000_000,
2_000_000_000_000,
0,
0,
AssetHubRococoSender::get().into()
));

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

// ensure `penpal` sovereign account has no native tokens and mint some `ASSET_ID`
assert_eq!(
<AssetHubRococo as AssetHubRococoPallet>::Balances::free_balance(penpal.clone()),
0
);

assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::Assets::touch_other(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
ASSET_ID.into(),
penpal.clone().into(),
));

assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::Assets::mint(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
ASSET_ID.into(),
penpal.clone().into(),
10_000_000_000_000,
));
});

PenpalA::execute_with(|| {
// send xcm transact from `penpal` account which as only `ASSET_ID` tokens on
// `AssetHubRococo`
let call = AssetHubRococo::force_create_asset_call(
ASSET_ID + 1000,
penpal.clone(),
true,
ASSET_MIN_BALANCE,
);

let penpal_root = <PenpalA as Chain>::RuntimeOrigin::root();
let fee_amount = 4_000_000_000_000u128;
let asset_one =
(X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())), fee_amount)
.into();
let asset_hub_location = PenpalA::sibling_location_of(AssetHubRococo::para_id()).into();
let xcm = xcm_transact_paid_execution(
call,
OriginKind::SovereignAccount,
asset_one,
penpal.clone(),
);

assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send(
penpal_root,
bx!(asset_hub_location),
bx!(xcm),
));

PenpalA::assert_xcm_pallet_sent();
});

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

AssetHubRococo::assert_xcmp_queue_success(None);
assert_expected_events!(
AssetHubRococo,
vec![
RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::SwapCreditExecuted { .. },) => {},
RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true,.. }) => {},
]
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,78 +27,3 @@ fn send_transact_as_superuser_from_relay_to_system_para_works() {
Some(Weight::from_parts(1_019_445_000, 200_000)),
)
}

/// Parachain should be able to send XCM paying its fee with sufficient asset
/// in the System Parachain
#[test]
fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() {
let para_sovereign_account = AssetHubWestend::sovereign_account_id_of(
AssetHubWestend::sibling_location_of(PenpalB::para_id()),
);

// Force create and mint assets for Parachain's sovereign account
AssetHubWestend::force_create_and_mint_asset(
ASSET_ID,
ASSET_MIN_BALANCE,
true,
para_sovereign_account.clone(),
Some(Weight::from_parts(1_019_445_000, 200_000)),
ASSET_MIN_BALANCE * 1000000000,
);

// We just need a call that can pass the `SafeCallFilter`
// Call values are not relevant
let call = AssetHubWestend::force_create_asset_call(
ASSET_ID,
para_sovereign_account.clone(),
true,
ASSET_MIN_BALANCE,
);

let origin_kind = OriginKind::SovereignAccount;
let fee_amount = ASSET_MIN_BALANCE * 1000000;
let native_asset =
(X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())), fee_amount).into();

let root_origin = <PenpalB as Chain>::RuntimeOrigin::root();
let system_para_destination = PenpalB::sibling_location_of(AssetHubWestend::para_id()).into();
let xcm = xcm_transact_paid_execution(
call,
origin_kind,
native_asset,
para_sovereign_account.clone(),
);

PenpalB::execute_with(|| {
assert_ok!(<PenpalB as PenpalBPallet>::PolkadotXcm::send(
root_origin,
bx!(system_para_destination),
bx!(xcm),
));

PenpalB::assert_xcm_pallet_sent();
});

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

AssetHubWestend::assert_xcmp_queue_success(Some(Weight::from_parts(
16_290_336_000,
562_893,
)));

assert_expected_events!(
AssetHubWestend,
vec![
RuntimeEvent::Assets(pallet_assets::Event::Burned { asset_id, owner, balance }) => {
asset_id: *asset_id == ASSET_ID,
owner: *owner == para_sovereign_account,
balance: *balance == fee_amount,
},
RuntimeEvent::Assets(pallet_assets::Event::Issued { asset_id, .. }) => {
asset_id: *asset_id == ASSET_ID,
},
]
);
});
}
Loading