Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier committed Dec 25, 2024
1 parent b0b9249 commit 3b94aad
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 114 deletions.
27 changes: 13 additions & 14 deletions runtime/crab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,28 +427,17 @@ sp_api::impl_runtime_apis! {

impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<xcm::VersionedAssetId>, xcm_runtime_apis::fees::Error> {
// polkadot-sdk
use xcm::IntoVersion;

let acceptable = vec![
// Native token.
xcm::VersionedAssetId::from(xcm::latest::AssetId(SelfReserve::get()))
];
let acceptable_assets = vec![xcn::latest::AssetId(RelayLocation::get())];

Ok(acceptable
.into_iter()
.filter_map(|asset| asset.into_version(xcm_version).ok())
.collect())
PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
}

fn query_weight_to_asset_fee(weight: frame_support::weights::Weight, asset: xcm::VersionedAssetId) -> Result<u128, xcm_runtime_apis::fees::Error> {
// polkadot-sdk
use frame_support::weights::WeightToFee;
use xcm::IntoVersion;

match asset.try_as::<xcm::latest::AssetId>() {
Ok(asset_id) if asset_id.0 == SelfReserve::get() => {
// Native token.
Ok(asset_id) if asset_id.0 == RelayLocation::get() => {
Ok(WeightToFee::weight_to_fee(&weight))
},
Ok(asset_id) => {
Expand All @@ -473,6 +462,16 @@ sp_api::impl_runtime_apis! {
}
}

impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result<xcm_runtime_apis::dry_run::CallDryRunEffects<RuntimeEvent>, xcm_runtime_apis::dry_run::Error> {
PolkadotXcm::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call)
}

fn dry_run_xcm(origin_location: xcm::VersionedLocation, xcm: xcm::VersionedXcm<RuntimeCall>) -> Result<xcm_runtime_apis::dry_run::XcmDryRunEffects<RuntimeEvent>, xcm_runtime_apis::dry_run::Error> {
PolkadotXcm::dry_run_xcm::<Runtime, xcm_config::XcmRouter, RuntimeCall, xcm_config::XcmConfig>(origin_location, xcm)
}
}

impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {
fn chain_id() -> u64 {
<<Runtime as pallet_evm::Config>::ChainId as sp_core::Get<u64>>::get()
Expand Down
1 change: 1 addition & 0 deletions runtime/crab/src/pallets/polkadot_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::*;
use xcm::latest::prelude::*;

frame_support::parameter_types! {
pub const RelayLocation: Location = Location::parent();
pub const RelayNetwork: NetworkId = NetworkId::Kusama;
pub const MaxAssetsIntoHolding: u32 = 64;
pub const MaxInstructions: u32 = 100;
Expand Down
27 changes: 13 additions & 14 deletions runtime/darwinia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,28 +436,17 @@ sp_api::impl_runtime_apis! {

impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<xcm::VersionedAssetId>, xcm_runtime_apis::fees::Error> {
// polkadot-sdk
use xcm::IntoVersion;

let acceptable = vec![
// Native token.
xcm::VersionedAssetId::from(xcm::latest::AssetId(SelfReserve::get()))
];
let acceptable_assets = vec![xcn::latest::AssetId(RelayLocation::get())];

Ok(acceptable
.into_iter()
.filter_map(|asset| asset.into_version(xcm_version).ok())
.collect())
PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
}

fn query_weight_to_asset_fee(weight: frame_support::weights::Weight, asset: xcm::VersionedAssetId) -> Result<u128, xcm_runtime_apis::fees::Error> {
// polkadot-sdk
use frame_support::weights::WeightToFee;
use xcm::IntoVersion;

match asset.try_as::<xcm::latest::AssetId>() {
Ok(asset_id) if asset_id.0 == SelfReserve::get() => {
// Native token.
Ok(asset_id) if asset_id.0 == RelayLocation::get() => {
Ok(WeightToFee::weight_to_fee(&weight))
},
Ok(asset_id) => {
Expand All @@ -482,6 +471,16 @@ sp_api::impl_runtime_apis! {
}
}

impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result<xcm_runtime_apis::dry_run::CallDryRunEffects<RuntimeEvent>, xcm_runtime_apis::dry_run::Error> {
PolkadotXcm::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call)
}

fn dry_run_xcm(origin_location: xcm::VersionedLocation, xcm: xcm::VersionedXcm<RuntimeCall>) -> Result<xcm_runtime_apis::dry_run::XcmDryRunEffects<RuntimeEvent>, xcm_runtime_apis::dry_run::Error> {
PolkadotXcm::dry_run_xcm::<Runtime, xcm_config::XcmRouter, RuntimeCall, xcm_config::XcmConfig>(origin_location, xcm)
}
}

impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {
fn chain_id() -> u64 {
<<Runtime as pallet_evm::Config>::ChainId as sp_core::Get<u64>>::get()
Expand Down
1 change: 1 addition & 0 deletions runtime/darwinia/src/pallets/polkadot_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{AssetId, Assets, *};
use xcm::latest::prelude::*;

frame_support::parameter_types! {
pub const RelayLocation: Location = Location::parent();
pub const RelayNetwork: NetworkId = NetworkId::Polkadot;
pub const MaxAssetsIntoHolding: u32 = 64;
pub const MaxInstructions: u32 = 100;
Expand Down
76 changes: 8 additions & 68 deletions runtime/darwinia/src/weights/pallet_asset_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,12 @@ impl<T: frame_system::Config> pallet_asset_manager::WeightInfo for WeightInfo<T>
// Proof Size summary in bytes:
// Measured: `276`
// Estimated: `3741`
// Minimum execution time: 27_000_000 picoseconds.
Weight::from_parts(28_000_000, 0)
// Minimum execution time: 26_000_000 picoseconds.
Weight::from_parts(27_000_000, 0)
.saturating_add(Weight::from_parts(0, 3741))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(4))
}
/// Storage: `AssetManager::AssetTypeId` (r:1 w:0)
/// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1)
/// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `AssetManager::AssetTypeUnitsPerSecond` (r:0 w:1)
/// Proof: `AssetManager::AssetTypeUnitsPerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `x` is `[5, 100]`.
fn set_asset_units_per_second(x: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `595 + x * (9 ±0)`
// Estimated: `3983 + x * (10 ±0)`
// Minimum execution time: 14_000_000 picoseconds.
Weight::from_parts(15_745_769, 0)
.saturating_add(Weight::from_parts(0, 3983))
// Standard Error: 1_882
.saturating_add(Weight::from_parts(311_730, 0).saturating_mul(x.into()))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
.saturating_add(Weight::from_parts(0, 10).saturating_mul(x.into()))
}
/// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1)
/// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `AssetManager::AssetIdType` (r:1 w:1)
Expand All @@ -102,57 +82,17 @@ impl<T: frame_system::Config> pallet_asset_manager::WeightInfo for WeightInfo<T>
/// Storage: `AssetManager::AssetTypeId` (r:0 w:2)
/// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `x` is `[5, 100]`.
fn change_existing_asset_type(x: u32, ) -> Weight {
fn change_existing_asset_type() -> Weight {
// Proof Size summary in bytes:
// Measured: `968 + x * (13 ±0)`
// Estimated: `4303 + x * (14 ±0)`
// Minimum execution time: 23_000_000 picoseconds.
Weight::from_parts(23_950_644, 0)
// Minimum execution time: 20_000_000 picoseconds.
Weight::from_parts(23_199_447, 0)
.saturating_add(Weight::from_parts(0, 4303))
// Standard Error: 2_239
.saturating_add(Weight::from_parts(313_174, 0).saturating_mul(x.into()))
// Standard Error: 2_109
.saturating_add(Weight::from_parts(301_010, 0))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(6))
.saturating_add(Weight::from_parts(0, 14).saturating_mul(x.into()))
}
/// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1)
/// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `AssetManager::AssetTypeUnitsPerSecond` (r:0 w:1)
/// Proof: `AssetManager::AssetTypeUnitsPerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `x` is `[5, 100]`.
fn remove_supported_asset(x: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `196 + x * (5 ±0)`
// Estimated: `1678 + x * (5 ±0)`
// Minimum execution time: 11_000_000 picoseconds.
Weight::from_parts(9_848_583, 0)
.saturating_add(Weight::from_parts(0, 1678))
// Standard Error: 1_357
.saturating_add(Weight::from_parts(271_961, 0).saturating_mul(x.into()))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(2))
.saturating_add(Weight::from_parts(0, 5).saturating_mul(x.into()))
}
/// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1)
/// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `AssetManager::AssetIdType` (r:1 w:1)
/// Proof: `AssetManager::AssetIdType` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `AssetManager::AssetTypeUnitsPerSecond` (r:0 w:1)
/// Proof: `AssetManager::AssetTypeUnitsPerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `AssetManager::AssetTypeId` (r:0 w:1)
/// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `x` is `[5, 100]`.
fn remove_existing_asset_type(x: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `486 + x * (10 ±0)`
// Estimated: `3949 + x * (10 ±0)`
// Minimum execution time: 16_000_000 picoseconds.
Weight::from_parts(17_547_073, 0)
.saturating_add(Weight::from_parts(0, 3949))
// Standard Error: 2_092
.saturating_add(Weight::from_parts(267_953, 0).saturating_mul(x.into()))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(4))
.saturating_add(Weight::from_parts(0, 10).saturating_mul(x.into()))
.saturating_add(Weight::from_parts(0, 14))
}
}
27 changes: 13 additions & 14 deletions runtime/koi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,28 +352,17 @@ sp_api::impl_runtime_apis! {

impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<xcm::VersionedAssetId>, xcm_runtime_apis::fees::Error> {
// polkadot-sdk
use xcm::IntoVersion;

let acceptable = vec![
// Native token.
xcm::VersionedAssetId::from(xcm::latest::AssetId(SelfReserve::get()))
];
let acceptable_assets = vec![xcn::latest::AssetId(RelayLocation::get())];

Ok(acceptable
.into_iter()
.filter_map(|asset| asset.into_version(xcm_version).ok())
.collect())
PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
}

fn query_weight_to_asset_fee(weight: frame_support::weights::Weight, asset: xcm::VersionedAssetId) -> Result<u128, xcm_runtime_apis::fees::Error> {
// polkadot-sdk
use frame_support::weights::WeightToFee;
use xcm::IntoVersion;

match asset.try_as::<xcm::latest::AssetId>() {
Ok(asset_id) if asset_id.0 == SelfReserve::get() => {
// Native token.
Ok(asset_id) if asset_id.0 == RelayLocation::get() => {
Ok(WeightToFee::weight_to_fee(&weight))
},
Ok(asset_id) => {
Expand All @@ -398,6 +387,16 @@ sp_api::impl_runtime_apis! {
}
}

impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result<xcm_runtime_apis::dry_run::CallDryRunEffects<RuntimeEvent>, xcm_runtime_apis::dry_run::Error> {
PolkadotXcm::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call)
}

fn dry_run_xcm(origin_location: xcm::VersionedLocation, xcm: xcm::VersionedXcm<RuntimeCall>) -> Result<xcm_runtime_apis::dry_run::XcmDryRunEffects<RuntimeEvent>, xcm_runtime_apis::dry_run::Error> {
PolkadotXcm::dry_run_xcm::<Runtime, xcm_config::XcmRouter, RuntimeCall, xcm_config::XcmConfig>(origin_location, xcm)
}
}

impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {
fn chain_id() -> u64 {
<<Runtime as pallet_evm::Config>::ChainId as sp_core::Get<u64>>::get()
Expand Down
1 change: 1 addition & 0 deletions runtime/koi/src/pallets/polkadot_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{AssetId, Assets, *};
use xcm::latest::prelude::*;

frame_support::parameter_types! {
pub const RelayLocation: Location = Location::parent();
// TODO: Paseo.
pub const RelayNetwork: NetworkId = NetworkId::Rococo;
pub const MaxAssetsIntoHolding: u32 = 64;
Expand Down
2 changes: 1 addition & 1 deletion runtime/koi/src/pallets/xcmp_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::*;

impl cumulus_pallet_xcmp_queue::Config for Runtime {
type ChannelInfo = ParachainSystem;
type ControllerOrigin = RootOr<GeneralAdmin>;
type ControllerOrigin = Root;
type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
type MaxActiveOutboundChannels = ConstU32<128>;
type MaxInboundSuspended = sp_core::ConstU32<1_000>;
Expand Down
6 changes: 3 additions & 3 deletions runtime/koi/src/weights/pallet_asset_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ impl<T: frame_system::Config> pallet_asset_manager::WeightInfo for WeightInfo<T>
/// Storage: `AssetManager::AssetTypeId` (r:0 w:2)
/// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `x` is `[5, 100]`.
fn change_existing_asset_type(x: u32, ) -> Weight {
fn change_existing_asset_type() -> Weight {
// Proof Size summary in bytes:
// Measured: `968 + x * (13 ±0)`
// Estimated: `4303 + x * (14 ±0)`
// Minimum execution time: 20_000_000 picoseconds.
Weight::from_parts(23_199_447, 0)
.saturating_add(Weight::from_parts(0, 4303))
// Standard Error: 2_109
.saturating_add(Weight::from_parts(301_010, 0).saturating_mul(x.into()))
.saturating_add(Weight::from_parts(301_010, 0))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(6))
.saturating_add(Weight::from_parts(0, 14).saturating_mul(x.into()))
.saturating_add(Weight::from_parts(0, 14))
}
}

0 comments on commit 3b94aad

Please sign in to comment.