Skip to content

Commit

Permalink
Allow to use evm foreign assets to pay XCM fees (#2908)
Browse files Browse the repository at this point in the history
* create pallet xcm-weight-trader

* add rust unit tests for trader fix trader impl

* add functions for runtime api xcm-fee-payment

* add rust test scenario: unpause and edit asset price

* add pallet-xcm-weight-trader to all runtimes & migrate assets fees data

* avoid div by zero

* refactor moonbase rust tests to use new pallet xcm-weight-trader

* refactor moonbeam/moonriver rust tests to use new pallet xcm-weight-trader

* fix pallet compilation with feature runtime-benchmark and tests

* fix rust tests

* add weight info for pallet_xcm_weight_trader

* fix migration formula

* fix pallet tests

* fix linting

* fix typo

* configure origins for xcmWeightTrader

* fix: edit asset should not unpause asset

* update registerOldForeignAssets to use xcmWeightTrader

* fix tests using setAssetUnitsPerSecond

* Update pallets/xcm-weight-trader/src/lib.rs

Co-authored-by: Agustín Rodriguez <[email protected]>

* fix rust compilation

* benchmarks: use evm foreign assets for worst_case_holding

* impl post-upgrade

* fix migration code

* fix rust test

* rustfmt

* remove unused import

---------

Co-authored-by: Rodrigo Quelhas <[email protected]>
Co-authored-by: Pablo Labarta <[email protected]>
Co-authored-by: Agustín Rodriguez <[email protected]>
  • Loading branch information
4 people authored Sep 13, 2024
1 parent 7623155 commit dd3a4a4
Show file tree
Hide file tree
Showing 42 changed files with 2,714 additions and 2,062 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ members = [
"pallets/precompile-benchmarks",
"pallets/proxy-genesis-companion",
"pallets/xcm-transactor",
"pallets/xcm-weight-trader",
"precompiles/balances-erc20",
"precompiles/batch",
"precompiles/call-permit",
Expand Down Expand Up @@ -107,6 +108,7 @@ pallet-parachain-staking = { path = "pallets/parachain-staking", default-feature
pallet-precompile-benchmarks = { path = "pallets/precompile-benchmarks", default-features = false }
pallet-proxy-genesis-companion = { path = "pallets/proxy-genesis-companion", default-features = false }
pallet-xcm-transactor = { path = "pallets/xcm-transactor", default-features = false }
pallet-xcm-weight-trader = { path = "pallets/xcm-weight-trader", default-features = false }
precompile-foreign-asset-migrator = { path = "precompiles/foreign-asset-migrator", default-features = false }
xcm-primitives = { path = "primitives/xcm", default-features = false }

Expand Down Expand Up @@ -185,6 +187,7 @@ sp-runtime-interface = { git = "https://github.com/moonbeam-foundation/polkadot-
sp-session = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
sp-std = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
sp-state-machine = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
sp-tracing = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
sp-transaction-pool = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
sp-trie = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
sp-version = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
Expand Down
75 changes: 0 additions & 75 deletions pallets/asset-manager/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,7 @@ benchmarks! {
assert_eq!(Pallet::<T>::asset_id_type(asset_id), Some(asset_type));
}

set_asset_units_per_second {
// We make it dependent on the number of existing assets already
let x in 5..100;
for i in 0..x {
let asset_type: T::ForeignAssetType = Location::new(
0,
X1(GeneralIndex(i as u128))
).into();
let metadata = T::AssetRegistrarMetadata::default();
let amount = 1u32.into();
Pallet::<T>::register_foreign_asset(
RawOrigin::Root.into(),
asset_type.clone(),
metadata,
amount,
true
)?;
Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?;
}

// does not really matter what we register, as long as it is different than the previous
let asset_type = T::ForeignAssetType::default();
let metadata = T::AssetRegistrarMetadata::default();
let amount = 1u32.into();
let asset_id: T::AssetId = asset_type.clone().into();
Pallet::<T>::register_foreign_asset(
RawOrigin::Root.into(),
asset_type.clone(),
metadata,
amount,
true
)?;

}: _(RawOrigin::Root, asset_type.clone(), 1, x)
verify {
assert!(Pallet::<T>::supported_fee_payment_assets().contains(&asset_type));
assert_eq!(Pallet::<T>::asset_type_units_per_second(asset_type), Some(1));
}

change_existing_asset_type {
// We make it dependent on the number of existing assets already
let x in 5..100;
for i in 0..x {
let asset_type: T::ForeignAssetType = Location::new(0, X1(GeneralIndex(i as u128))).into();
Expand All @@ -89,7 +49,6 @@ benchmarks! {
amount,
true
)?;
Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?;
}

let new_asset_type = T::ForeignAssetType::default();
Expand All @@ -101,40 +60,9 @@ benchmarks! {
}: _(RawOrigin::Root, asset_id_to_be_changed, new_asset_type.clone(), x)
verify {
assert_eq!(Pallet::<T>::asset_id_type(asset_id_to_be_changed), Some(new_asset_type.clone()));
assert_eq!(Pallet::<T>::asset_type_units_per_second(&new_asset_type), Some(1));
assert!(Pallet::<T>::supported_fee_payment_assets().contains(&new_asset_type));
}

remove_supported_asset {
// We make it dependent on the number of existing assets already
let x in 5..100;
for i in 0..x {
let asset_type: T::ForeignAssetType = Location::new(0, X1(GeneralIndex(i as u128))).into();
let metadata = T::AssetRegistrarMetadata::default();
let amount = 1u32.into();
Pallet::<T>::register_foreign_asset(
RawOrigin::Root.into(),
asset_type.clone(),
metadata,
amount,
true
)?;
Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?;
}
let asset_type_to_be_removed: T::ForeignAssetType = Location::new(
0,
X1(GeneralIndex((x-1) as u128))
).into();
// We try to remove the last asset type
}: _(RawOrigin::Root, asset_type_to_be_removed.clone(), x)
verify {
assert!(!Pallet::<T>::supported_fee_payment_assets().contains(&asset_type_to_be_removed));
assert_eq!(Pallet::<T>::asset_type_units_per_second(asset_type_to_be_removed), None);
}

remove_existing_asset_type {
// We make it dependent on the number of existing assets already
// Worst case is we need to remove it from SupportedAAssetsFeePayment too
let x in 5..100;
for i in 0..x {
let asset_type: T::ForeignAssetType = Location::new(0, X1(GeneralIndex(i as u128))).into();
Expand All @@ -147,7 +75,6 @@ benchmarks! {
amount,
true
)?;
Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?;
}

let asset_type_to_be_removed: T::ForeignAssetType = Location::new(
Expand All @@ -158,8 +85,6 @@ benchmarks! {
}: _(RawOrigin::Root, asset_id, x)
verify {
assert!(Pallet::<T>::asset_id_type(asset_id).is_none());
assert!(Pallet::<T>::asset_type_units_per_second(&asset_type_to_be_removed).is_none());
assert!(!Pallet::<T>::supported_fee_payment_assets().contains(&asset_type_to_be_removed));
}
}

Expand Down
Loading

0 comments on commit dd3a4a4

Please sign in to comment.