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

Allow to use evm foreign assets to pay XCM fees #2908

Merged
merged 33 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
84b1d32
create pallet xcm-weight-trader
librelois Aug 18, 2024
7c7212d
add rust unit tests for trader fix trader impl
librelois Aug 21, 2024
27b51cf
add functions for runtime api xcm-fee-payment
librelois Aug 22, 2024
3d9c721
add rust test scenario: unpause and edit asset price
librelois Aug 22, 2024
83157cd
add pallet-xcm-weight-trader to all runtimes & migrate assets fees data
librelois Aug 22, 2024
2499887
avoid div by zero
librelois Aug 23, 2024
2492d89
refactor moonbase rust tests to use new pallet xcm-weight-trader
librelois Aug 23, 2024
d6ff588
refactor moonbeam/moonriver rust tests to use new pallet xcm-weight-t…
RomarQ Aug 23, 2024
9532086
Merge branch 'master' into elois-evm-foreign-fees
RomarQ Aug 25, 2024
90537cb
fix pallet compilation with feature runtime-benchmark and tests
RomarQ Aug 26, 2024
9a399e3
fix rust tests
RomarQ Aug 26, 2024
1678021
add weight info for pallet_xcm_weight_trader
RomarQ Aug 26, 2024
a1e7004
fix migration formula
librelois Aug 26, 2024
fd30cb7
fix pallet tests
RomarQ Aug 26, 2024
af305a0
fix linting
RomarQ Aug 26, 2024
01c317d
fix typo
librelois Aug 28, 2024
87dd277
configure origins for xcmWeightTrader
librelois Aug 28, 2024
871626d
fix: edit asset should not unpause asset
librelois Aug 29, 2024
35f2b1b
Merge branch 'master' into elois-evm-foreign-fees
librelois Sep 2, 2024
0a70b3f
update registerOldForeignAssets to use xcmWeightTrader
pLabarta Sep 2, 2024
5788820
Merge branch 'pablo/evm-foreign-fees' into elois-evm-foreign-fees
pLabarta Sep 2, 2024
dff2a26
fix tests using setAssetUnitsPerSecond
pLabarta Sep 2, 2024
6d7be3b
Update pallets/xcm-weight-trader/src/lib.rs
librelois Sep 6, 2024
8fc6346
Merge branch 'master' into elois-evm-foreign-fees
librelois Sep 6, 2024
86f837e
fix rust compilation
librelois Sep 6, 2024
a6bdc47
benchmarks: use evm foreign assets for worst_case_holding
librelois Sep 6, 2024
0916c9d
Merge branch 'master' into elois-evm-foreign-fees
RomarQ Sep 10, 2024
7cd1b35
impl post-upgrade
librelois Sep 12, 2024
3c772e5
fix migration code
RomarQ Sep 12, 2024
dd9040e
Merge branch 'master' into elois-evm-foreign-fees
librelois Sep 12, 2024
58a5b40
fix rust test
librelois Sep 13, 2024
6c02815
rustfmt
librelois Sep 13, 2024
c8d8a7f
remove unused import
librelois Sep 13, 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
20 changes: 20 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 @@ -184,6 +186,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
52 changes: 52 additions & 0 deletions pallets/xcm-weight-trader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
authors = {workspace = true}
description = "A pallet to trade weight for XCM execution"
edition = "2021"
name = "pallet-xcm-weight-trader"
version = "0.1.0"

[dependencies]
log = {workspace = true}

# Substrate
frame-support = {workspace = true}
frame-system = {workspace = true}
pallet-balances = {workspace = true}
parity-scale-codec = {workspace = true}
scale-info = {workspace = true, features = ["derive"]}
sp-core = {workspace = true}
sp-io = {workspace = true}
sp-runtime = {workspace = true}
sp-std = {workspace = true}

# Polkadot
xcm = { workspace = true }
xcm-executor = { workspace = true }

# Benchmarks
frame-benchmarking = {workspace = true, optional = true}

[dev-dependencies]
frame-benchmarking = {workspace = true, features = ["std"]}
pallet-balances = {workspace = true, features = ["std", "insecure_zero_ed"]}
sp-tracing = {workspace = true, features = ["std"] }

[features]
default = ["std"]
runtime-benchmarks = [
"frame-benchmarking",
"frame-system/runtime-benchmarks"
]
std = [
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"xcm/std",
"xcm-executor/std"
]
try-runtime = ["frame-support/try-runtime"]
139 changes: 139 additions & 0 deletions pallets/xcm-weight-trader/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Copyright 2024 Moonbeam foundation
// This file is part of Moonbeam.

// Moonbeam is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Moonbeam is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

#![cfg(feature = "runtime-benchmarks")]

use super::*;

use frame_benchmarking::{v2::*, BenchmarkError};
use frame_support::traits::EnsureOrigin;
use frame_system::EventRecord;

fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
let events = frame_system::Pallet::<T>::events();
let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();
// compare to the last event record
let EventRecord { event, .. } = &events[events.len() - 1];
assert_eq!(event, &system_event);
}

fn setup_one_asset<T: Config>() -> Result<Location, BenchmarkError> {
let origin = T::AddSupportedAssetOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;

let location = T::NotFilteredLocation::get();

Pallet::<T>::add_asset(origin, location.clone(), 1_000).expect("fail to setup asset");

Ok(location)
}

#[benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn add_asset() -> Result<(), BenchmarkError> {
let origin = T::AddSupportedAssetOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;

let location = T::NotFilteredLocation::get();

#[extrinsic_call]
_(origin as T::RuntimeOrigin, location.clone(), 1_000);

assert_last_event::<T>(
Event::SupportedAssetAdded {
location,
units_for_one_billion_native: 1_000,
}
.into(),
);
Ok(())
}

#[benchmark]
fn edit_asset() -> Result<(), BenchmarkError> {
// Setup one asset
let location = setup_one_asset::<T>()?;

let origin = T::EditSupportedAssetOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(origin as T::RuntimeOrigin, location.clone(), 2_000);

assert_last_event::<T>(
Event::SupportedAssetEdited {
location,
units_for_one_billion_native: 2_000,
}
.into(),
);
Ok(())
}

#[benchmark]
fn resume_asset_support() -> Result<(), BenchmarkError> {
// Setup one asset
let location = setup_one_asset::<T>()?;
let pause_origin = T::PauseSupportedAssetOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
Pallet::<T>::pause_asset_support(pause_origin, location.clone())
.expect("fail to pause asset");

let origin = T::ResumeSupportedAssetOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(origin as T::RuntimeOrigin, location.clone());

assert_last_event::<T>(Event::ResumeAssetSupport { location }.into());
Ok(())
}

#[benchmark]
fn pause_asset_support() -> Result<(), BenchmarkError> {
// Setup one asset
let location = setup_one_asset::<T>()?;

let origin = T::PauseSupportedAssetOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(origin as T::RuntimeOrigin, location.clone());

assert_last_event::<T>(Event::PauseAssetSupport { location }.into());
Ok(())
}

#[benchmark]
fn remove_asset() -> Result<(), BenchmarkError> {
// Setup one asset
let location = setup_one_asset::<T>()?;

let origin = T::RemoveSupportedAssetOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(origin as T::RuntimeOrigin, location.clone());

assert_last_event::<T>(Event::SupportedAssetRemoved { location }.into());
Ok(())
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test,);
}
Loading
Loading