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
+21 -1
View File
@@ -19,7 +19,7 @@
use frame_support::traits::{
fungible::{Balanced, Credit},
tokens::imbalance::ResolveTo,
Imbalance, OnUnbalanced,
Contains, ContainsPair, Imbalance, OnUnbalanced,
};
use pallet_treasury::TreasuryAccountId;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
@@ -156,6 +156,26 @@ impl TryConvert<&VersionedLocation, xcm::latest::Location> for VersionedLocation
}
}
/// Adapter for [`Contains`] trait to match [`VersionedLocatableAsset`] type converted to the latest
/// version of itself where it's location matched by `L` and it's asset id by `A` parameter types.
pub struct ContainsParts<C>(core::marker::PhantomData<C>);
impl<C> Contains<VersionedLocatableAsset> for ContainsParts<C>
where
C: ContainsPair<xcm::latest::Location, xcm::latest::Location>,
{
fn contains(asset: &VersionedLocatableAsset) -> bool {
use VersionedLocatableAsset::*;
let (location, asset_id) = match asset.clone() {
V3 { location, asset_id } => match (location.try_into(), asset_id.try_into()) {
(Ok(l), Ok(a)) => (l, a),
_ => return false,
},
V4 { location, asset_id } => (location, asset_id),
};
C::contains(&location, &asset_id.0)
}
}
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarks {
use super::VersionedLocatableAsset;