Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

asset-conversion pallet: pool's AccountId derivation warn docs #14811

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion frame/asset-conversion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ pub mod pallet {

/// Type that identifies either the native currency or a token class from `Assets`.
/// `Ord` is added because of `get_pool_id`.
///
/// The pool's `AccountId` is derived from this type. Any changes to the type may
/// necessitate a migration.
type MultiAssetId: AssetId + Ord + From<Self::AssetId>;

/// Type to convert an `AssetId` into `MultiAssetId`.
Expand Down Expand Up @@ -1193,7 +1196,9 @@ pub mod pallet {
()
);
} else {
let MultiAssetIdConversionResult::Converted(asset_id) = T::MultiAssetIdConverter::try_convert(asset) else {
let MultiAssetIdConversionResult::Converted(asset_id) =
T::MultiAssetIdConverter::try_convert(asset)
else {
return Err(())
};
let minimal = T::Assets::minimum_balance(asset_id);
Expand Down
6 changes: 5 additions & 1 deletion frame/asset-conversion/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ fn pool_assets() -> Vec<u32> {

fn create_tokens(owner: u128, tokens: Vec<NativeOrAssetId<u32>>) {
for token_id in tokens {
let MultiAssetIdConversionResult::Converted(asset_id) = NativeOrAssetIdConverter::try_convert(&token_id) else { unreachable!("invalid token") };
let MultiAssetIdConversionResult::Converted(asset_id) =
NativeOrAssetIdConverter::try_convert(&token_id)
else {
unreachable!("invalid token")
};
assert_ok!(Assets::force_create(RuntimeOrigin::root(), asset_id, owner, false, 1));
}
}
Expand Down
4 changes: 4 additions & 0 deletions frame/asset-conversion/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_std::{cmp::Ordering, marker::PhantomData};

/// Pool ID.
///
/// The pool's `AccountId` is derived from this type. Any changes to the type may necessitate a
/// migration.
pub(super) type PoolIdOf<T> = (<T as Config>::MultiAssetId, <T as Config>::MultiAssetId);

/// Stores the lp_token asset id a particular pool has been assigned.
Expand Down