FRAME: Unity Balance Conversion for Different IDs of Native Asset (#3659)

Introduce types to define 1:1 balance conversion for different relative
asset ids/locations of native asset.

Examples:
native asset on Asset Hub presented as `VersionedLocatableAsset` type in
the context of Relay Chain is
```
{
  `location`: (0, Parachain(1000)),
  `asset_id`: (1, Here),
}
```
and it's balance should be converted 1:1 by implementations of
`ConversionToAssetBalance` trait.

---------

Co-authored-by: Branislav Kontur <bkontur@gmail.com>
This commit is contained in:
Muharem
2024-04-16 18:11:14 +02:00
committed by GitHub
parent 753bf2d860
commit 6f3d890ed3
21 changed files with 790 additions and 26 deletions
+20 -8
View File
@@ -25,7 +25,10 @@ use beefy_primitives::{
ecdsa_crypto::{AuthorityId as BeefyId, Signature as BeefySignature},
mmr::{BeefyDataProvider, MmrLeafVersion},
};
use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params};
use frame_support::{
dynamic_params::{dynamic_pallet_params, dynamic_params},
traits::FromContains,
};
use pallet_nis::WithMaximumOf;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use primitives::{
@@ -40,7 +43,8 @@ use rococo_runtime_constants::system_parachain::BROKER_ID;
use runtime_common::{
assigned_slots, auctions, claims, crowdloan, identity_migrator, impl_runtime_weights,
impls::{
LocatableAssetConverter, ToAuthor, VersionedLocatableAsset, VersionedLocationConverter,
ContainsParts, LocatableAssetConverter, ToAuthor, VersionedLocatableAsset,
VersionedLocationConverter,
},
paras_registrar, paras_sudo_wrapper, prod_or_fast, slots,
traits::{Leaser, OnSwap},
@@ -74,10 +78,10 @@ use frame_support::{
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{
fungible::HoldConsideration, Contains, EitherOf, EitherOfDiverse, EnsureOrigin,
EnsureOriginWithArg, EverythingBut, InstanceFilter, KeyOwnerProofSystem,
LinearStoragePrice, PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim,
WithdrawReasons,
fungible::HoldConsideration, tokens::UnityOrOuterConversion, Contains, EitherOf,
EitherOfDiverse, EnsureOrigin, EnsureOriginWithArg, EverythingBut, InstanceFilter,
KeyOwnerProofSystem, LinearStoragePrice, PrivilegeCmp, ProcessMessage, ProcessMessageError,
StorageMapShim, WithdrawReasons,
},
weights::{ConstantMultiplier, WeightMeter, WeightToFee as _},
PalletId,
@@ -87,7 +91,7 @@ use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
use pallet_identity::legacy::IdentityInfo;
use pallet_session::historical as session_historical;
use pallet_transaction_payment::{FeeDetails, FungibleAdapter, RuntimeDispatchInfo};
use sp_core::{ConstU128, OpaqueMetadata, H256};
use sp_core::{ConstU128, ConstU8, OpaqueMetadata, H256};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
@@ -523,7 +527,15 @@ impl pallet_treasury::Config for Runtime {
LocatableAssetConverter,
VersionedLocationConverter,
>;
type BalanceConverter = AssetRate;
type BalanceConverter = UnityOrOuterConversion<
ContainsParts<
FromContains<
xcm_builder::IsChildSystemParachain<ParaId>,
xcm_builder::IsParentsOnly<ConstU8<1>>,
>,
>,
AssetRate,
>;
type PayoutPeriod = PayoutSpendPeriod;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = runtime_common::impls::benchmarks::TreasuryArguments;