From 3a41e7ddef410883ac4b9b042d416f8fc49b27e9 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Mon, 5 Jun 2023 23:48:56 -0300 Subject: [PATCH 01/11] Removed FixedRateOfFungibles --- Cargo.lock | 17 +++++++++++++++++ runtime/stout/src/constants.rs | 10 ---------- runtime/stout/src/xcm_config.rs | 8 +------- runtime/trappist/Cargo.toml | 2 ++ runtime/trappist/src/constants.rs | 16 +--------------- runtime/trappist/src/xcm_config.rs | 20 +++++++++----------- 6 files changed, 30 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bdf116e2..68346d62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -406,6 +406,22 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" +[[package]] +name = "assets-common" +version = "0.1.0" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.40#e05c8d7f71734ed71188337c6cb0d30715f6320f" +dependencies = [ + "frame-support", + "parachains-common", + "parity-scale-codec", + "sp-api", + "sp-std", + "substrate-wasm-builder", + "xcm", + "xcm-builder", + "xcm-executor", +] + [[package]] name = "async-channel" version = "1.8.0" @@ -12398,6 +12414,7 @@ dependencies = [ name = "trappist-runtime" version = "1.0.0" dependencies = [ + "assets-common", "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", diff --git a/runtime/stout/src/constants.rs b/runtime/stout/src/constants.rs index 6148f5eb..1f97a69f 100644 --- a/runtime/stout/src/constants.rs +++ b/runtime/stout/src/constants.rs @@ -71,14 +71,4 @@ pub mod fee { }] } } - - pub fn base_tx_fee() -> Balance { - CENTS / 10 - } - - pub fn default_fee_per_second() -> u128 { - let base_weight = Balance::from(ExtrinsicBaseWeight::get().ref_time()); - let base_tx_per_second = (WEIGHT_REF_TIME_PER_SECOND as u128) / base_weight; - base_tx_per_second * base_tx_fee() - } } diff --git a/runtime/stout/src/xcm_config.rs b/runtime/stout/src/xcm_config.rs index 01112320..8798d4d1 100644 --- a/runtime/stout/src/xcm_config.rs +++ b/runtime/stout/src/xcm_config.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{constants::fee::default_fee_per_second, AllPalletsWithSystem}; +use crate::{AllPalletsWithSystem}; use super::{ AccountId, Assets, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, @@ -192,11 +192,6 @@ parameter_types! { // Statemine's Assets pallet index pub StatemineAssetsPalletLocation: MultiLocation = MultiLocation::new(1, X2(Parachain(1000), PalletInstance(50))); - pub XUsdPerSecond: (AssetId, u128, u128) = ( - MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(1))).into(), - default_fee_per_second() * 10, - 0 - ); } //- From PR https://github.com/paritytech/cumulus/pull/936 @@ -239,7 +234,6 @@ impl xcm_executor::Config for XcmConfig { type Barrier = Barrier; type Weigher = FixedWeightBounds; type Trader = ( - FixedRateOfFungible, UsingComponents>, ); type ResponseHandler = PolkadotXcm; diff --git a/runtime/trappist/Cargo.toml b/runtime/trappist/Cargo.toml index 37a77cb3..3470af91 100644 --- a/runtime/trappist/Cargo.toml +++ b/runtime/trappist/Cargo.toml @@ -70,6 +70,7 @@ pallet-utility = { git = "https://github.com/paritytech/substrate", default-feat pallet-treasury = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } # Cumulus dependencies +assets-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40", default-features = false } cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40", default-features = false } cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40", default-features = false } cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40", default-features = false } @@ -156,6 +157,7 @@ std = [ "pallet-uniques/std", "pallet-utility/std", "pallet-xcm/std", + "assets-common/std", "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-xcm/std", diff --git a/runtime/trappist/src/constants.rs b/runtime/trappist/src/constants.rs index 116f3a87..9479b3ff 100644 --- a/runtime/trappist/src/constants.rs +++ b/runtime/trappist/src/constants.rs @@ -33,9 +33,8 @@ pub mod currency { /// Fee-related. pub mod fee { - use super::currency::CENTS; use frame_support::weights::{ - constants::{ExtrinsicBaseWeight, WEIGHT_REF_TIME_PER_SECOND}, + constants::{ExtrinsicBaseWeight}, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, }; use polkadot_core_primitives::Balance; @@ -45,9 +44,6 @@ pub mod fee { /// The block saturation level. Fees will be updates based on this value. pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25); - //TODO: Update WeightToFee functionality to match cummulus implementation (Should be done in a - // separated issue) - /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the /// node's balance type. /// @@ -74,14 +70,4 @@ pub mod fee { }] } } - - pub fn base_tx_fee() -> Balance { - CENTS / 10 - } - - pub fn default_fee_per_second() -> u128 { - let base_weight = Balance::from(ExtrinsicBaseWeight::get().ref_time()); - let base_tx_per_second = (WEIGHT_REF_TIME_PER_SECOND as u128) / base_weight; - base_tx_per_second * base_tx_fee() - } } diff --git a/runtime/trappist/src/xcm_config.rs b/runtime/trappist/src/xcm_config.rs index 3af2b35c..85370c6c 100644 --- a/runtime/trappist/src/xcm_config.rs +++ b/runtime/trappist/src/xcm_config.rs @@ -14,13 +14,13 @@ // limitations under the License. use crate::{ - constants::fee::default_fee_per_second, impls::ToAuthor, weights::TrappistDropAssetsWeigher, - AllPalletsWithSystem, + constants::fee::{WeightToFee}, impls::ToAuthor, weights::TrappistDropAssetsWeigher, + AllPalletsWithSystem, }; use super::{ AccountId, AssetRegistry, Assets, Balance, Balances, ParachainInfo, ParachainSystem, - PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, XcmpQueue, }; use frame_support::{ match_types, parameter_types, @@ -46,7 +46,7 @@ use xcm::latest::{prelude::*, Fungibility::Fungible, MultiAsset, MultiLocation}; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, - ConvertedConcreteId, CurrencyAdapter, EnsureXcmOrigin, FixedRateOfFungible, FungiblesAdapter, + ConvertedConcreteId, CurrencyAdapter, EnsureXcmOrigin, FungiblesAdapter, IsConcrete, MintLocation, NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, @@ -90,6 +90,11 @@ pub type LocationToAccountId = ( AccountId32Aliases, ); + +/// `AssetId/Balancer` converter for `TrustBackedAssets` +pub type TrustBackedAssetsConvertedConcreteId = + assets_common::TrustBackedAssetsConvertedConcreteId; + /// Means for transacting the native currency on this chain. pub type LocalAssetTransactor = CurrencyAdapter< // Use this currency: @@ -221,11 +226,6 @@ parameter_types! { // Rockmine's Assets pallet index pub RockmineAssetsPalletLocation: MultiLocation = MultiLocation::new(1, X2(Parachain(1000), PalletInstance(50))); - pub XUsdPerSecond: (xcm::v3::AssetId, u128, u128) = ( - MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(1))).into(), - default_fee_per_second() * 10, - 0 - ); } //- From PR https://github.com/paritytech/cumulus/pull/936 @@ -270,9 +270,7 @@ impl xcm_executor::Config for XcmConfig { RuntimeCall, MaxInstructions, >; - //TODO: Modify current config of Trader removing XUsdPerSecond Implementation type Trader = ( - FixedRateOfFungible, UsingComponents>, ); type ResponseHandler = PolkadotXcm; From aa53b9d4ca5970be4923e04908d1cf8e3558f65b Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Tue, 6 Jun 2023 10:53:55 -0300 Subject: [PATCH 02/11] fmt --- runtime/trappist/src/constants.rs | 12 +++++++----- runtime/trappist/src/impls.rs | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/runtime/trappist/src/constants.rs b/runtime/trappist/src/constants.rs index bcd8c3c5..e7fe1913 100644 --- a/runtime/trappist/src/constants.rs +++ b/runtime/trappist/src/constants.rs @@ -39,11 +39,11 @@ pub mod fee { }; use polkadot_core_primitives::Balance; use smallvec::smallvec; - + pub use sp_runtime::Perbill; use sp_runtime::SaturatedConversion; -use crate::impls::WeightCoefficientCalc; + use crate::impls::WeightCoefficientCalc; /// The block saturation level. Fees will be updates based on this value. pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25); @@ -63,8 +63,10 @@ use crate::impls::WeightCoefficientCalc; type Balance = Balance; fn weight_to_fee(weight: &Weight) -> Self::Balance { - let ref_poly: smallvec::SmallVec<[WeightToFeeCoefficient; 4]> = RefTimeToFee::polynomial(); - let proof_poly: smallvec::SmallVec<[WeightToFeeCoefficient; 4]> = ProofSizeToFee::polynomial(); + let ref_poly: smallvec::SmallVec<[WeightToFeeCoefficient; 4]> = + RefTimeToFee::polynomial(); + let proof_poly: smallvec::SmallVec<[WeightToFeeCoefficient; 4]> = + ProofSizeToFee::polynomial(); let ref_fee: Balance = ref_poly.iter().fold(0, |acc, term| { term.saturating_eval(acc, Balance::saturated_from(weight.ref_time())) @@ -78,7 +80,7 @@ use crate::impls::WeightCoefficientCalc; ref_fee.max(proof_fee) } } - + pub struct RefTimeToFee; impl WeightToFeePolynomial for RefTimeToFee { type Balance = Balance; diff --git a/runtime/trappist/src/impls.rs b/runtime/trappist/src/impls.rs index b26fdf41..82e59f5f 100644 --- a/runtime/trappist/src/impls.rs +++ b/runtime/trappist/src/impls.rs @@ -23,8 +23,8 @@ use frame_support::{ weights::{Weight, WeightToFeeCoefficient}, }; pub use log; -use sp_runtime::{DispatchResult, SaturatedConversion}; use sp_arithmetic::traits::{BaseArithmetic, Unsigned}; +use sp_runtime::{DispatchResult, SaturatedConversion}; use sp_std::marker::PhantomData; From 9e44559ddaf2192526b4472dc7433a7fe2c5dede Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Tue, 6 Jun 2023 11:02:08 -0300 Subject: [PATCH 03/11] added comments --- runtime/trappist/src/constants.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/runtime/trappist/src/constants.rs b/runtime/trappist/src/constants.rs index e7fe1913..0d9558cc 100644 --- a/runtime/trappist/src/constants.rs +++ b/runtime/trappist/src/constants.rs @@ -58,6 +58,10 @@ pub mod fee { /// Yet, it can be used for any other sort of change to weight-fee. Some examples being: /// - Setting it to `0` will essentially disable the weight fee. /// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. + /// + /// TODO: Once the runtime is upgraded to polkadot v0.9.42 or above refactor this using + /// the FeePolynomial struct that already includes the methods to make this calculations + /// and remove the custom WeightCoefficientCalc inside ./trappist/src/impls.rs pub struct WeightToFee; impl frame_support::weights::WeightToFee for WeightToFee { type Balance = Balance; @@ -68,12 +72,14 @@ pub mod fee { let proof_poly: smallvec::SmallVec<[WeightToFeeCoefficient; 4]> = ProofSizeToFee::polynomial(); + // Get fee amount from ref_time based on the RefTime polynomial let ref_fee: Balance = ref_poly.iter().fold(0, |acc, term| { term.saturating_eval(acc, Balance::saturated_from(weight.ref_time())) }); + // Get fee amount from proof_size based on the ProofSize polynomial let proof_fee: Balance = proof_poly.iter().fold(0, |acc, term| { - term.saturating_eval(acc, Balance::saturated_from(weight.ref_time())) + term.saturating_eval(acc, Balance::saturated_from(weight.proof_size())) }); // Take the maximum instead of the sum to charge by the more scarce resource. @@ -81,6 +87,7 @@ pub mod fee { } } + /// Maps the Ref time component of `Weight` to a fee. pub struct RefTimeToFee; impl WeightToFeePolynomial for RefTimeToFee { type Balance = Balance; From 89cbdfcf70b30f065e4d5ab1656e48f7060e2a0d Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Tue, 6 Jun 2023 12:22:58 -0300 Subject: [PATCH 04/11] fmt --- runtime/trappist/src/constants.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/trappist/src/constants.rs b/runtime/trappist/src/constants.rs index 0d9558cc..72a86a45 100644 --- a/runtime/trappist/src/constants.rs +++ b/runtime/trappist/src/constants.rs @@ -58,9 +58,9 @@ pub mod fee { /// Yet, it can be used for any other sort of change to weight-fee. Some examples being: /// - Setting it to `0` will essentially disable the weight fee. /// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. - /// - /// TODO: Once the runtime is upgraded to polkadot v0.9.42 or above refactor this using - /// the FeePolynomial struct that already includes the methods to make this calculations + /// + /// TODO: Once the runtime is upgraded to polkadot v0.9.42 or above refactor this using + /// the FeePolynomial struct that already includes the methods to make this calculations /// and remove the custom WeightCoefficientCalc inside ./trappist/src/impls.rs pub struct WeightToFee; impl frame_support::weights::WeightToFee for WeightToFee { From 9a2f98ab1970da5dd800a6eecded04f5675bf5c9 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Mon, 12 Jun 2023 11:14:51 -0300 Subject: [PATCH 05/11] removed unused imports --- runtime/trappist/src/xcm_config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/trappist/src/xcm_config.rs b/runtime/trappist/src/xcm_config.rs index ae7bfb5b..ecb5a4ad 100644 --- a/runtime/trappist/src/xcm_config.rs +++ b/runtime/trappist/src/xcm_config.rs @@ -45,8 +45,8 @@ use xcm::latest::{prelude::*, Fungibility::Fungible, MultiAsset, MultiLocation}; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, - AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, - ConvertedConcreteId, CurrencyAdapter, EnsureXcmOrigin, FungiblesAdapter, IsConcrete, + AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, + CurrencyAdapter, EnsureXcmOrigin, FungiblesAdapter, IsConcrete, MintLocation, NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, From d140056b3dba8dbd333c8d9e5afc30ea9bb1ea2f Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Mon, 12 Jun 2023 11:17:10 -0300 Subject: [PATCH 06/11] fmt --- runtime/trappist/src/xcm_config.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/runtime/trappist/src/xcm_config.rs b/runtime/trappist/src/xcm_config.rs index ecb5a4ad..f07b6928 100644 --- a/runtime/trappist/src/xcm_config.rs +++ b/runtime/trappist/src/xcm_config.rs @@ -45,12 +45,11 @@ use xcm::latest::{prelude::*, Fungibility::Fungible, MultiAsset, MultiLocation}; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, - AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, - CurrencyAdapter, EnsureXcmOrigin, FungiblesAdapter, IsConcrete, - MintLocation, NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, - SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, - WeightInfoBounds, + AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin, + FungiblesAdapter, IsConcrete, MintLocation, NativeAsset, NoChecking, ParentAsSuperuser, + ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + UsingComponents, WeightInfoBounds, }; use xcm_executor::XcmExecutor; From 40f0005ef838dfd8902c099974dc40fdd0796e47 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Mon, 12 Jun 2023 11:20:59 -0300 Subject: [PATCH 07/11] removed allow unpaid execution from rockmine following PR #211 --- runtime/trappist/src/xcm_config.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/trappist/src/xcm_config.rs b/runtime/trappist/src/xcm_config.rs index f07b6928..151418f9 100644 --- a/runtime/trappist/src/xcm_config.rs +++ b/runtime/trappist/src/xcm_config.rs @@ -205,7 +205,6 @@ pub type Barrier = DenyThenTry< AllowTopLevelPaidExecutionFrom, // Parent and its exec plurality get free execution AllowUnpaidExecutionFrom, - AllowUnpaidExecutionFrom, // Expected responses are OK. AllowKnownQueryResponses, // Subscriptions for version tracking are OK. From 1867ab35d0ef58cb27b2ef7aaccab838d0e272a0 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Tue, 13 Jun 2023 10:51:17 -0300 Subject: [PATCH 08/11] Include new traders from PR #221 --- runtime/trappist/src/constants.rs | 16 +++++++++++++-- runtime/trappist/src/xcm_config.rs | 32 ++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/runtime/trappist/src/constants.rs b/runtime/trappist/src/constants.rs index 72a86a45..4c5bd1e3 100644 --- a/runtime/trappist/src/constants.rs +++ b/runtime/trappist/src/constants.rs @@ -34,8 +34,8 @@ pub mod currency { /// Fee-related. pub mod fee { use frame_support::weights::{ - constants::ExtrinsicBaseWeight, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, + constants::{ExtrinsicBaseWeight, WEIGHT_REF_TIME_PER_SECOND}, + Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, }; use polkadot_core_primitives::Balance; use smallvec::smallvec; @@ -45,6 +45,8 @@ pub mod fee { use crate::impls::WeightCoefficientCalc; + use super::currency::CENTS; + /// The block saturation level. Fees will be updates based on this value. pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25); @@ -122,4 +124,14 @@ pub mod fee { }] } } + + pub fn base_tx_fee() -> Balance { + CENTS / 10 + } + + pub fn default_fee_per_second() -> u128 { + let base_weight = Balance::from(ExtrinsicBaseWeight::get().ref_time()); + let base_tx_per_second = (WEIGHT_REF_TIME_PER_SECOND as u128) / base_weight; + base_tx_per_second * base_tx_fee() + } } diff --git a/runtime/trappist/src/xcm_config.rs b/runtime/trappist/src/xcm_config.rs index 151418f9..b912faf8 100644 --- a/runtime/trappist/src/xcm_config.rs +++ b/runtime/trappist/src/xcm_config.rs @@ -14,7 +14,9 @@ // limitations under the License. use crate::{ - constants::fee::WeightToFee, impls::ToAuthor, weights::TrappistDropAssetsWeigher, + constants::fee::{default_fee_per_second, WeightToFee}, + impls::ToAuthor, + weights::TrappistDropAssetsWeigher, AllPalletsWithSystem, }; @@ -46,10 +48,10 @@ use xcm::latest::{prelude::*, Fungibility::Fungible, MultiAsset, MultiLocation}; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin, - FungiblesAdapter, IsConcrete, MintLocation, NativeAsset, NoChecking, ParentAsSuperuser, - ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, - UsingComponents, WeightInfoBounds, + FixedRateOfFungible, FungiblesAdapter, IsConcrete, MintLocation, NativeAsset, NoChecking, + ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WeightInfoBounds, }; use xcm_executor::XcmExecutor; @@ -218,6 +220,14 @@ parameter_types! { // Rockmine's Assets pallet index pub RockmineAssetsPalletLocation: MultiLocation = MultiLocation::new(1, X2(Parachain(1000), PalletInstance(50))); + + pub RUsdPerSecond: (xcm::v3::AssetId, u128, u128) = ( + MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984))).into(), + default_fee_per_second() * 10, + 0u128 + ); + /// Roc = 7 RUSD + pub RocPerSecond: (xcm::v3::AssetId, u128,u128) = (MultiLocation::parent().into(), default_fee_per_second() * 70, 0u128); } //- From PR https://github.com/paritytech/cumulus/pull/936 @@ -244,7 +254,14 @@ impl> ContainsPair for ReserveA } } -//-- +pub type Traders = ( + // RUSD + FixedRateOfFungible, + // Roc + FixedRateOfFungible, + // Everything else + UsingComponents>, +); pub type Reserves = (NativeAsset, ReserveAssetsFrom); @@ -262,8 +279,7 @@ impl xcm_executor::Config for XcmConfig { RuntimeCall, MaxInstructions, >; - type Trader = UsingComponents>; - + type Trader = Traders; type ResponseHandler = PolkadotXcm; type AssetTrap = TrappistDropAssets< AssetIdForTrustBackedAssets, From 426114e95fb22a4c13718ab5817fd91553e7a666 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Wed, 14 Jun 2023 09:28:30 -0300 Subject: [PATCH 09/11] minor fixes --- runtime/stout/src/constants.rs | 10 ++++++++++ runtime/trappist/src/constants.rs | 20 ++++++++++---------- runtime/trappist/src/impls.rs | 2 +- runtime/trappist/src/xcm_config.rs | 1 - 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/runtime/stout/src/constants.rs b/runtime/stout/src/constants.rs index 1f97a69f..6148f5eb 100644 --- a/runtime/stout/src/constants.rs +++ b/runtime/stout/src/constants.rs @@ -71,4 +71,14 @@ pub mod fee { }] } } + + pub fn base_tx_fee() -> Balance { + CENTS / 10 + } + + pub fn default_fee_per_second() -> u128 { + let base_weight = Balance::from(ExtrinsicBaseWeight::get().ref_time()); + let base_tx_per_second = (WEIGHT_REF_TIME_PER_SECOND as u128) / base_weight; + base_tx_per_second * base_tx_fee() + } } diff --git a/runtime/trappist/src/constants.rs b/runtime/trappist/src/constants.rs index 4c5bd1e3..22a40b5b 100644 --- a/runtime/trappist/src/constants.rs +++ b/runtime/trappist/src/constants.rs @@ -69,20 +69,20 @@ pub mod fee { type Balance = Balance; fn weight_to_fee(weight: &Weight) -> Self::Balance { - let ref_poly: smallvec::SmallVec<[WeightToFeeCoefficient; 4]> = - RefTimeToFee::polynomial(); - let proof_poly: smallvec::SmallVec<[WeightToFeeCoefficient; 4]> = - ProofSizeToFee::polynomial(); + let ref_time = Balance::saturated_from(weight.ref_time()); + let proof_size = Balance::saturated_from(weight.proof_size()); + + let ref_polynomial = RefTimeToFee::polynomial(); + let proof_polynomial = ProofSizeToFee::polynomial(); // Get fee amount from ref_time based on the RefTime polynomial - let ref_fee: Balance = ref_poly.iter().fold(0, |acc, term| { - term.saturating_eval(acc, Balance::saturated_from(weight.ref_time())) - }); + let ref_fee: Balance = + ref_polynomial.iter().fold(0, |acc, term| term.saturating_eval(acc, ref_time)); // Get fee amount from proof_size based on the ProofSize polynomial - let proof_fee: Balance = proof_poly.iter().fold(0, |acc, term| { - term.saturating_eval(acc, Balance::saturated_from(weight.proof_size())) - }); + let proof_fee: Balance = proof_polynomial + .iter() + .fold(0, |acc, term| term.saturating_eval(acc, proof_size)); // Take the maximum instead of the sum to charge by the more scarce resource. ref_fee.max(proof_fee) diff --git a/runtime/trappist/src/impls.rs b/runtime/trappist/src/impls.rs index 82e59f5f..a060ddbe 100644 --- a/runtime/trappist/src/impls.rs +++ b/runtime/trappist/src/impls.rs @@ -124,7 +124,7 @@ where fn saturating_eval(&self, mut result: Balance, x: Balance) -> Balance { let power = x.saturating_pow(self.degree.into()); - let frac = self.coeff_frac * power; // Overflow safe. + let frac = self.coeff_frac * power; // Overflow safe since coeff_frac is strictly less than 1. let integer = self.coeff_integer.saturating_mul(power); // Do not add them together here to avoid an underflow. diff --git a/runtime/trappist/src/xcm_config.rs b/runtime/trappist/src/xcm_config.rs index b912faf8..2203dada 100644 --- a/runtime/trappist/src/xcm_config.rs +++ b/runtime/trappist/src/xcm_config.rs @@ -220,7 +220,6 @@ parameter_types! { // Rockmine's Assets pallet index pub RockmineAssetsPalletLocation: MultiLocation = MultiLocation::new(1, X2(Parachain(1000), PalletInstance(50))); - pub RUsdPerSecond: (xcm::v3::AssetId, u128, u128) = ( MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984))).into(), default_fee_per_second() * 10, From 671f1e149933768e881ebc1b5bf7aa54fd069b58 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Wed, 14 Jun 2023 14:10:02 -0300 Subject: [PATCH 10/11] minor fixes --- runtime/stout/src/xcm_config.rs | 2 +- runtime/trappist/src/constants.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/stout/src/xcm_config.rs b/runtime/stout/src/xcm_config.rs index f49bbab5..a418b50e 100644 --- a/runtime/stout/src/xcm_config.rs +++ b/runtime/stout/src/xcm_config.rs @@ -43,7 +43,7 @@ use xcm::latest::{prelude::*, Fungibility::Fungible, MultiAsset, MultiLocation}; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, - ConvertedConcreteId, CurrencyAdapter, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, + ConvertedConcreteId, CurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, IsConcrete, MintLocation, NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, diff --git a/runtime/trappist/src/constants.rs b/runtime/trappist/src/constants.rs index 22a40b5b..08a49d5b 100644 --- a/runtime/trappist/src/constants.rs +++ b/runtime/trappist/src/constants.rs @@ -96,7 +96,7 @@ pub mod fee { fn polynomial() -> WeightToFeeCoefficients { // in Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: // in Statemine, we map to 1/10 of that, or 1/100 CENT - let p = super::currency::CENTS; + let p = CENTS; let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); smallvec![WeightToFeeCoefficient { degree: 1, @@ -113,7 +113,7 @@ pub mod fee { type Balance = Balance; fn polynomial() -> WeightToFeeCoefficients { // Map 10kb proof to 1 CENT. - let p = super::currency::CENTS; + let p = CENTS; let q = 10_000; smallvec![WeightToFeeCoefficient { From 2b563ed56edb92b1d9304c963a7c30b0d7e62165 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Wed, 14 Jun 2023 14:13:36 -0300 Subject: [PATCH 11/11] fmt --- runtime/stout/src/xcm_config.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/stout/src/xcm_config.rs b/runtime/stout/src/xcm_config.rs index a418b50e..4dda78a3 100644 --- a/runtime/stout/src/xcm_config.rs +++ b/runtime/stout/src/xcm_config.rs @@ -43,9 +43,9 @@ use xcm::latest::{prelude::*, Fungibility::Fungible, MultiAsset, MultiLocation}; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, - ConvertedConcreteId, CurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, - FungiblesAdapter, IsConcrete, MintLocation, NativeAsset, NoChecking, ParentAsSuperuser, - ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + ConvertedConcreteId, CurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, + IsConcrete, MintLocation, NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, };