This repository was archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Refactor WeightToFee to include ProofSize
#215
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3a41e7d
Removed FixedRateOfFungibles
valentinfernandez1 0278191
Proposed WeightToFee and xcmv3-dev merge
valentinfernandez1 aa53b9d
fmt
valentinfernandez1 9e44559
added comments
valentinfernandez1 71e896f
Merge branch 'xcmv3-dev' into vf-weight-to-fee
valentinfernandez1 89cbdfc
fmt
valentinfernandez1 9a2f98a
removed unused imports
valentinfernandez1 d140056
fmt
valentinfernandez1 40f0005
removed allow unpaid execution from rockmine following PR #211
valentinfernandez1 1867ab3
Include new traders from PR #221
valentinfernandez1 426114e
minor fixes
valentinfernandez1 671f1e1
minor fixes
valentinfernandez1 2b563ed
fmt
valentinfernandez1 f23705f
fix import issue
valentinfernandez1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,10 +20,11 @@ use super::*; | |
| use cumulus_primitives_core::{relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler}; | ||
| use frame_support::{ | ||
| traits::{Contains, Currency, Imbalance, OnUnbalanced}, | ||
| weights::Weight, | ||
| weights::{Weight, WeightToFeeCoefficient}, | ||
| }; | ||
| pub use log; | ||
| use sp_runtime::DispatchResult; | ||
| use sp_arithmetic::traits::{BaseArithmetic, Unsigned}; | ||
| use sp_runtime::{DispatchResult, SaturatedConversion}; | ||
|
|
||
| use sp_std::marker::PhantomData; | ||
|
|
||
|
|
@@ -111,6 +112,34 @@ impl xcm_primitives::PauseXcmExecution for XcmExecutionManager { | |
| XcmpQueue::resume_xcm_execution(RuntimeOrigin::root()) | ||
| } | ||
| } | ||
|
|
||
| pub trait WeightCoefficientCalc<Balance> { | ||
| fn saturating_eval(&self, result: Balance, x: Balance) -> Balance; | ||
| } | ||
|
|
||
| impl<Balance> WeightCoefficientCalc<Balance> for WeightToFeeCoefficient<Balance> | ||
| where | ||
| Balance: BaseArithmetic + From<u32> + Copy + Unsigned + SaturatedConversion, | ||
| { | ||
| 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 integer = self.coeff_integer.saturating_mul(power); | ||
| // Do not add them together here to avoid an underflow. | ||
|
|
||
| if self.negative { | ||
| result = result.saturating_sub(frac); | ||
| result = result.saturating_sub(integer); | ||
| } else { | ||
| result = result.saturating_add(frac); | ||
| result = result.saturating_add(integer); | ||
| } | ||
|
|
||
| result | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,13 +14,15 @@ | |
| // limitations under the License. | ||
|
|
||
| use crate::{ | ||
| constants::fee::default_fee_per_second, impls::ToAuthor, weights::TrappistDropAssetsWeigher, | ||
| constants::fee::{default_fee_per_second, 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, | ||
|
|
@@ -45,12 +47,11 @@ use xcm::latest::{prelude::*, Fungibility::Fungible, MultiAsset, MultiLocation}; | |
|
|
||
| use xcm_builder::{ | ||
| AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, | ||
| AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, | ||
| ConvertedConcreteId, CurrencyAdapter, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, | ||
| FungiblesAdapter, IsConcrete, MintLocation, NativeAsset, NoChecking, ParentAsSuperuser, | ||
| ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, | ||
| SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, | ||
| UsingComponents, WeightInfoBounds, | ||
| AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin, | ||
| FixedRateOfFungible, FungiblesAdapter, IsConcrete, MintLocation, NativeAsset, NoChecking, | ||
| ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, | ||
| SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, | ||
| SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WeightInfoBounds, | ||
| }; | ||
| use xcm_executor::XcmExecutor; | ||
|
|
||
|
|
@@ -206,7 +207,6 @@ pub type Barrier = DenyThenTry< | |
| AllowTopLevelPaidExecutionFrom<Everything>, | ||
| // Parent and its exec plurality get free execution | ||
| AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>, | ||
| AllowUnpaidExecutionFrom<Rockmine>, | ||
| // Expected responses are OK. | ||
| AllowKnownQueryResponses<PolkadotXcm>, | ||
| // Subscriptions for version tracking are OK. | ||
|
|
@@ -220,11 +220,14 @@ 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(), | ||
|
|
||
| pub RUsdPerSecond: (xcm::v3::AssetId, u128, u128) = ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: changes to this files probably shouldn't be part of this PR. |
||
| MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984))).into(), | ||
| default_fee_per_second() * 10, | ||
| 0 | ||
| 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 | ||
|
|
@@ -251,7 +254,14 @@ impl<T: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation> for ReserveA | |
| } | ||
| } | ||
|
|
||
| //-- | ||
| pub type Traders = ( | ||
| // RUSD | ||
| FixedRateOfFungible<RUsdPerSecond, ()>, | ||
| // Roc | ||
| FixedRateOfFungible<RocPerSecond, ()>, | ||
| // Everything else | ||
| UsingComponents<WeightToFee, SelfReserve, AccountId, Balances, ToAuthor<Runtime>>, | ||
| ); | ||
|
|
||
| pub type Reserves = (NativeAsset, ReserveAssetsFrom<RockmineLocation>); | ||
|
|
||
|
|
@@ -269,11 +279,7 @@ impl xcm_executor::Config for XcmConfig { | |
| RuntimeCall, | ||
| MaxInstructions, | ||
| >; | ||
| //TODO: Modify current config of Trader removing XUsdPerSecond Implementation | ||
| type Trader = ( | ||
| FixedRateOfFungible<XUsdPerSecond, ()>, | ||
| UsingComponents<WeightToFee, SelfReserve, AccountId, Balances, ToAuthor<Runtime>>, | ||
| ); | ||
| type Trader = Traders; | ||
| type ResponseHandler = PolkadotXcm; | ||
| type AssetTrap = TrappistDropAssets< | ||
| AssetIdForTrustBackedAssets, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.