Skip to content

Commit

Permalink
add non-fungibles asset transactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Dec 28, 2023
1 parent 5b7dd3d commit 915e74e
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions runtime/shibuya/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use super::{
AccountId, AllPalletsWithSystem, AssetId, Assets, Balance, Balances, DealWithFees,
ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
ShibuyaAssetLocationIdConverter, TreasuryAccountId, XcAssetConfig, XcmWeightToFee, XcmpQueue,
CollectionId, ItemId, Uniques,
};
use crate::weights;
use frame_support::{
Expand All @@ -39,9 +40,11 @@ use xcm_builder::{
ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WithComputedOrigin,
NonFungiblesAdapter,
};
use pallet_xc_asset_config::XcAssetLocation;
use xcm_executor::{
traits::{Convert as XcmConvert, JustTry},
traits::{Convert as XcmConvert, Error as MatchError, JustTry, MatchesNonFungibles},
XcmExecutor,
};

Expand Down Expand Up @@ -109,8 +112,41 @@ pub type FungiblesTransactor = FungiblesAdapter<
DummyCheckingAccount,
>;

pub struct MultiAssetToUniquesConverter;
impl MatchesNonFungibles<CollectionId, ItemId> for MultiAssetToUniquesConverter {
fn matches_nonfungibles(a: &MultiAsset) -> Result<(CollectionId, ItemId), MatchError> {
let (instance, class) = match (&a.fun, &a.id) {
(NonFungible(ref instance), Concrete(ref class)) => (instance, class),
_ => return Err(MatchError::AssetNotHandled),
};
let collection_id = XcAssetConfig::get_asset_id(*class).unwrap();

let item_id = match instance {
Index(indx) => *indx,
_ => return Err(MatchError::AssetNotHandled),
};

Ok((collection_id, item_id))
}
}

pub type NonFungiblesTransactor = NonFungiblesAdapter<
// Use the uniques pallet:
Uniques,
// This will handle any non-fungible asset which is registered in xc-assets pallet.
MultiAssetToUniquesConverter,
// Convert an XCM MultiLocation into a local account id:
LocationToAccountId,
// This chain's account ID type (we can't get away without mentioning it explicitly):
AccountId,
// We don't support teleport so no need to check any assets.
NoChecking,
// We don't support teleport so this is just a dummy account.
(),
>;

/// Means for transacting assets on this chain.
pub type AssetTransactors = (CurrencyTransactor, FungiblesTransactor);
pub type AssetTransactors = (CurrencyTransactor, FungiblesTransactor, NonFungiblesTransactor);

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can
Expand Down

0 comments on commit 915e74e

Please sign in to comment.