Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ polkadot-runtime-parachains = { git = "https://github.com/moonbeam-foundation/po
xcm = { package = "staging-xcm", git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }
xcm-fee-payment-runtime-api = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0", default-features = false }

# Polkadot / XCM (client)
#kusama-runtime = { package = "staging-kusama-runtime", git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" }
Expand Down
1 change: 1 addition & 0 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ polkadot-parachain = { workspace = true }
polkadot-primitives = { workspace = true }
polkadot-service = { workspace = true }
xcm = { workspace = true }
xcm-fee-payment-runtime-api = { workspace = true }

# Benchmarking
frame-benchmarking = { workspace = true, features = ["std"] }
Expand Down
2 changes: 2 additions & 0 deletions node/service/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub trait RuntimeApiCollection:
+ cumulus_primitives_core::CollectCollationInfo<Block>
+ session_keys_primitives::VrfApi<Block>
+ async_backing_primitives::UnincludedSegmentApi<Block>
+ xcm_fee_payment_runtime_api::XcmPaymentApi<Block>
{
}

Expand All @@ -67,6 +68,7 @@ impl<Api> RuntimeApiCollection for Api where
+ cumulus_primitives_core::CollectCollationInfo<Block>
+ session_keys_primitives::VrfApi<Block>
+ async_backing_primitives::UnincludedSegmentApi<Block>
+ xcm_fee_payment_runtime_api::XcmPaymentApi<Block>
{
}

Expand Down
2 changes: 2 additions & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pallet-author-slot-filter = { workspace = true }
xcm = { workspace = true }
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }
xcm-fee-payment-runtime-api = { workspace = true }

# Parity
parity-scale-codec = { workspace = true }
Expand Down Expand Up @@ -111,6 +112,7 @@ std = [
"sp-std/std",
"sp-genesis-builder/std",
"xcm-executor/std",
"xcm-fee-payment-runtime-api/std",
"xcm/std",
"account/std",
]
Expand Down
80 changes: 80 additions & 0 deletions runtime/common/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,86 @@ macro_rules! impl_runtime_apis_plus_common {
}
}

impl xcm_fee_payment_runtime_api::XcmPaymentApi<Block> for Runtime {
fn query_acceptable_payment_assets(
xcm_version: xcm::Version
) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
if !matches!(xcm_version, 3) {
return Err(XcmPaymentApiError::UnhandledXcmVersion);
}

let self_reserve_location: Location = Location::try_from(xcm_config::SelfReserve::get())
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;

Ok([VersionedAssetId::V3(XcmAssetId::from(self_reserve_location))]
.into_iter()
.chain(
pallet_asset_manager::AssetTypeId::<Runtime>::iter_keys().filter_map(|asset_location| {
if !AssetManager::payment_is_supported(asset_location.clone()) {
return None;
}

let location: Option<Location> = asset_location.into();
if let Some(loc) = location {
return Some(VersionedAssetId::V3(loc.into()))
}
None
})
)
.filter_map(|asset| asset.into_version(xcm_version).ok())
.collect())
}

fn query_weight_to_asset_fee(
weight: Weight, asset: VersionedAssetId
) -> Result<u128, XcmPaymentApiError> {
let self_reserve_location: Location = Location::try_from(xcm_config::SelfReserve::get())
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;

let local_asset = VersionedAssetId::V3(XcmAssetId::from(self_reserve_location));
let asset = asset
.into_version(3)
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;

if asset == local_asset {
Ok(TransactionPayment::weight_to_fee(weight))
}else {
let asset_v3: XcmAssetId = asset.try_into()
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;

if let XcmAssetId::Concrete(asset_location) = asset_v3 {
let asset_type: AssetType = AssetType::from(asset_location);
if !AssetManager::payment_is_supported(asset_type.clone()) {
return Err(XcmPaymentApiError::AssetNotFound);
}

let units_per_sec = AssetManager::get_units_per_second(asset_type);
if let None = units_per_sec {
return Err(XcmPaymentApiError::WeightNotComputable);
}

let final_asset_fee = units_per_sec
.unwrap_or_default()
.saturating_mul(weight.ref_time() as u128)
/ (WEIGHT_REF_TIME_PER_SECOND as u128);

return Ok(final_asset_fee)
}
Err(XcmPaymentApiError::AssetNotFound)
}
}

fn query_xcm_weight(message: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {
PolkadotXcm::query_xcm_weight(message)
}

fn query_delivery_fees(
destination: VersionedLocation, message: VersionedXcm<()>
) -> Result<VersionedAssets, XcmPaymentApiError> {
PolkadotXcm::query_delivery_fees(destination, message)
}
}

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {

Expand Down
2 changes: 2 additions & 0 deletions runtime/moonbase/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ polkadot-runtime-common = { workspace = true }
xcm = { workspace = true }
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }
xcm-fee-payment-runtime-api = { workspace = true }

# Cumulus
cumulus-pallet-dmp-queue = { workspace = true }
Expand Down Expand Up @@ -307,6 +308,7 @@ std = [
"strum/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm-fee-payment-runtime-api/std",
"xcm-primitives/std",
"xcm/std",
]
Expand Down
7 changes: 7 additions & 0 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ use sp_std::{
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use xcm::{
v3::{AssetId as XcmAssetId, Location},
IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
};
use xcm_config::AssetType;
use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;
use xcm_primitives::UnitsToWeightRatio;

use smallvec::smallvec;
use sp_runtime::serde::{Deserialize, Serialize};
Expand Down
2 changes: 2 additions & 0 deletions runtime/moonbeam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ polkadot-parachain = { workspace = true }
xcm = { workspace = true }
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }
xcm-fee-payment-runtime-api = { workspace = true }

# Cumulus
cumulus-pallet-dmp-queue = { workspace = true }
Expand Down Expand Up @@ -298,6 +299,7 @@ std = [
"strum/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm-fee-payment-runtime-api/std",
"xcm-primitives/std",
"xcm/std",
]
Expand Down
7 changes: 7 additions & 0 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ use sp_runtime::{
Perquintill, SaturatedConversion,
};
use sp_std::{convert::TryFrom, prelude::*};
use xcm::{
v3::{AssetId as XcmAssetId, Location},
IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
};
use xcm_config::AssetType;
use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;
use xcm_primitives::UnitsToWeightRatio;
Comment thread
Agusrodri marked this conversation as resolved.

#[cfg(feature = "std")]
use sp_version::NativeVersion;
Expand Down
2 changes: 2 additions & 0 deletions runtime/moonriver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ polkadot-runtime-common = { workspace = true }
xcm = { workspace = true }
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }
xcm-fee-payment-runtime-api = { workspace = true }
pallet-message-queue = { workspace = true }

# Cumulus
Expand Down Expand Up @@ -298,6 +299,7 @@ std = [
"strum/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm-fee-payment-runtime-api/std",
"xcm-primitives/std",
"xcm/std",
]
Expand Down
7 changes: 7 additions & 0 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ use sp_runtime::{
Perquintill, SaturatedConversion,
};
use sp_std::{convert::TryFrom, prelude::*};
use xcm::{
v3::{AssetId as XcmAssetId, Location},
IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
};
use xcm_config::AssetType;
use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;
use xcm_primitives::UnitsToWeightRatio;

use smallvec::smallvec;
#[cfg(feature = "std")]
Expand Down
Loading