Skip to content

Commit

Permalink
feat: xtokens non-fungible multiassets support PoC
Browse files Browse the repository at this point in the history
  • Loading branch information
mrshiposha committed Nov 15, 2023
1 parent b45942e commit 86191d8
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions xtokens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,25 +526,39 @@ pub mod module {
let asset_len = assets.len();
for i in 0..asset_len {
let asset = assets.get(i).ok_or(Error::<T>::AssetIndexNonExistent)?;
ensure!(
matches!(asset.fun, Fungibility::Fungible(x) if !x.is_zero()),
Error::<T>::InvalidAsset
);
// `assets` includes fee, the reserve location is decided by non fee asset
if (fee != *asset && non_fee_reserve.is_none()) || asset_len == 1 {
non_fee_reserve = T::ReserveProvider::reserve(asset);
}
// make sure all non fee assets share the same reserve
if non_fee_reserve.is_some() {

if fee == *asset {
// Fee payment can only be made by using fungibles
ensure!(
non_fee_reserve == T::ReserveProvider::reserve(asset),
Error::<T>::DistinctReserveForAssetAndFee
matches!(asset.fun, Fungibility::Fungible(x) if !x.is_zero()),
Error::<T>::InvalidAsset
);
} else {
match asset.fun {
Fungibility::Fungible(x) => ensure!(!x.is_zero(), Error::<T>::InvalidAsset),
Fungibility::NonFungible(AssetInstance::Undefined) => {
return Err(Error::<T>::InvalidAsset.into())
}
_ => {}
}

// `assets` includes fee, the reserve location is decided by non fee asset
if non_fee_reserve.is_none() {
non_fee_reserve = T::ReserveProvider::reserve(asset);
}

// make sure all non fee assets share the same reserve
if non_fee_reserve.is_some() {
ensure!(
non_fee_reserve == T::ReserveProvider::reserve(asset),
Error::<T>::DistinctReserveForAssetAndFee
);
}
}
}

let fee_reserve = T::ReserveProvider::reserve(&fee);
if fee_reserve != non_fee_reserve {
if asset_len > 1 && fee_reserve != non_fee_reserve {
// Current only support `ToReserve` with relay-chain asset as fee. other case
// like `NonReserve` or `SelfReserve` with relay-chain fee is not support.
ensure!(non_fee_reserve == dest.chain_part(), Error::<T>::InvalidAsset);
Expand Down Expand Up @@ -610,7 +624,7 @@ pub mod module {
origin_location,
assets.clone(),
fee.clone(),
non_fee_reserve,
fee_reserve,
&dest,
None,
dest_weight_limit,
Expand Down

0 comments on commit 86191d8

Please sign in to comment.