Skip to content

Commit

Permalink
UnionOf types for merged fungible and fungibles implementations (
Browse files Browse the repository at this point in the history
…paritytech#2033)

Introduces `UnionOf` types, crafted to merge `fungible` and `fungibles`
implementations or two `fungibles` implementations into a single type
implementing `fungibles`.

This also addresses an issue where `ItemOf` initiates a double drop for
an imbalance type, leading to inaccurate total issuance accounting.

Find the application of these types in this PR -
[link](paritytech#2031), places in
code -
[1](https://github.com/paritytech/polkadot-sdk/blob/4ec7496fa2632385b08fae860fcf28a523a7b5de/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs#L327),
[2](https://github.com/paritytech/polkadot-sdk/blob/4ec7496fa2632385b08fae860fcf28a523a7b5de/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs#L343).

---------

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: joepetrowski <joe@parity.io>
  • Loading branch information
5 people committed Dec 19, 2023
1 parent f56d5f0 commit 0b34d19
Show file tree
Hide file tree
Showing 13 changed files with 2,329 additions and 35 deletions.
6 changes: 3 additions & 3 deletions substrate/frame/asset-conversion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,15 @@ pub mod pallet {
match T::MultiAssetIdConverter::try_convert(asset1) {
MultiAssetIdConversionResult::Converted(asset) =>
if !T::Assets::contains(&asset, &pool_account) {
T::Assets::touch(asset, pool_account.clone(), sender.clone())?
T::Assets::touch(asset, &pool_account, &sender)?
},
MultiAssetIdConversionResult::Unsupported(_) => Err(Error::<T>::UnsupportedAsset)?,
MultiAssetIdConversionResult::Native => (),
}
match T::MultiAssetIdConverter::try_convert(asset2) {
MultiAssetIdConversionResult::Converted(asset) =>
if !T::Assets::contains(&asset, &pool_account) {
T::Assets::touch(asset, pool_account.clone(), sender.clone())?
T::Assets::touch(asset, &pool_account, &sender)?
},
MultiAssetIdConversionResult::Unsupported(_) => Err(Error::<T>::UnsupportedAsset)?,
MultiAssetIdConversionResult::Native => (),
Expand All @@ -438,7 +438,7 @@ pub mod pallet {
NextPoolAssetId::<T>::set(Some(next_lp_token_id));

T::PoolAssets::create(lp_token.clone(), pool_account.clone(), false, 1u32.into())?;
T::PoolAssets::touch(lp_token.clone(), pool_account.clone(), sender.clone())?;
T::PoolAssets::touch(lp_token.clone(), &pool_account, &sender)?;

let pool_info = PoolInfo { lp_token: lp_token.clone() };
Pools::<T>::insert(pool_id.clone(), pool_info);
Expand Down
16 changes: 14 additions & 2 deletions substrate/frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1648,8 +1648,20 @@ pub mod pallet {
T::AssetAccountDeposit::get()
}

fn touch(asset: T::AssetId, who: T::AccountId, depositor: T::AccountId) -> DispatchResult {
Self::do_touch(asset, who, depositor, false)
fn should_touch(asset: T::AssetId, who: &T::AccountId) -> bool {
match Asset::<T, I>::get(&asset) {
Some(info) if info.is_sufficient => false,
Some(_) => !Account::<T, I>::contains_key(asset, who),
_ => true,
}
}

fn touch(
asset: T::AssetId,
who: &T::AccountId,
depositor: &T::AccountId,
) -> DispatchResult {
Self::do_touch(asset, who.clone(), depositor.clone(), false)
}
}

Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/assets/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use pallet_balances::Error as BalancesError;
use sp_io::storage;
use sp_runtime::{traits::ConvertInto, TokenError};

mod sets;

fn asset_ids() -> Vec<u32> {
let mut s: Vec<_> = Assets::asset_ids().collect();
s.sort();
Expand Down
Loading

0 comments on commit 0b34d19

Please sign in to comment.