Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(nft-fractionalization): use asset-ops #11

Draft
wants to merge 2 commits into
base: xcm-nft-dev-env
Choose a base branch
from
Draft
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
46 changes: 34 additions & 12 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ use frame_support::{
genesis_builder_helper::{build_state, get_preset},
ord_parameter_types, parameter_types,
traits::{
fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool,
ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Equals, InstanceFilter,
MapSuccess, TransformOrigin,
fungible, fungibles,
tokens::{
asset_ops::{common_strategies::Bytes, AssetDefinition, AssetIdOf, InspectMetadata},
imbalance::ResolveAssetTo,
},
AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse,
Equals, InstanceFilter, MapSuccess, TransformOrigin,
},
weights::{ConstantMultiplier, Weight, WeightToFee as _},
BoundedVec, PalletId,
Expand All @@ -72,14 +76,16 @@ use frame_system::{
EnsureRoot, EnsureSigned, EnsureSignedBy,
};
use pallet_asset_conversion_tx_payment::SwapAssetAdapter;
use pallet_nft_fractionalization::{FractionalizedName, FractionalizedSymbol};
use pallet_nfts::PalletFeatures;
use parachains_common::{
impls::DealWithFees,
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, CollectionId, Hash,
Header, ItemId, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO, NORMAL_DISPATCH_RATIO,
};
use sp_runtime::{Perbill, RuntimeDebug};
use scale_info::prelude::{format, string::String};
use sp_runtime::{DispatchError, Perbill, RuntimeDebug};
use testnet_parachains_constants::rococo::{consensus::*, currency::*, fee::WeightToFee, time::*};
use xcm_config::{
ForeignAssetsConvertedConcreteId, ForeignCreatorsSovereignAccountOf, GovernanceLocation,
Expand Down Expand Up @@ -868,23 +874,39 @@ impl pallet_uniques::Config<pallet_uniques::Instance2> for Runtime {

parameter_types! {
pub const NftFractionalizationPalletId: PalletId = PalletId(*b"fraction");
pub NewAssetSymbol: BoundedVec<u8, AssetsStringLimit> = (*b"FRAC").to_vec().try_into().unwrap();
pub NewAssetName: BoundedVec<u8, AssetsStringLimit> = (*b"Frac").to_vec().try_into().unwrap();
}

pub struct FractionalizedNfts;
impl AssetDefinition for FractionalizedNfts {
type Id = AssetIdOf<pallet_nfts::asset_ops::Item<Nfts>>;
}
impl InspectMetadata<Bytes<FractionalizedName>> for FractionalizedNfts {
fn inspect_metadata(
(collection_id, item_id): &Self::Id,
_frac_name: Bytes<FractionalizedName>,
) -> Result<Vec<u8>, DispatchError> {
Ok(format!("Frac {collection_id}-{item_id}").into_bytes())
}
}
impl InspectMetadata<Bytes<FractionalizedSymbol>> for FractionalizedNfts {
fn inspect_metadata(
_instance_id: &Self::Id,
_frac_name: Bytes<FractionalizedSymbol>,
) -> Result<Vec<u8>, DispatchError> {
Ok(String::from("FRAC").into_bytes())
}
}

impl pallet_nft_fractionalization::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Deposit = AssetDeposit;
type Currency = Balances;
type NewAssetSymbol = NewAssetSymbol;
type NewAssetName = NewAssetName;
type StringLimit = AssetsStringLimit;
type NftCollectionId = <Self as pallet_nfts::Config>::CollectionId;
type NftId = <Self as pallet_nfts::Config>::ItemId;
type AssetBalance = <Self as pallet_balances::Config>::Balance;
type AssetId = <Self as pallet_assets::Config<TrustBackedAssetsInstance>>::AssetId;
type Assets = Assets;
type Nfts = Nfts;
type NftId = AssetIdOf<pallet_nfts::asset_ops::Item<Nfts>>;
type Nfts = pallet_nfts::asset_ops::Item<Nfts>;
type FractionalizedNfts = FractionalizedNfts;
type PalletId = NftFractionalizationPalletId;
type WeightInfo = pallet_nft_fractionalization::weights::SubstrateWeight<Runtime>;
type RuntimeHoldReason = RuntimeHoldReason;
Expand Down
43 changes: 33 additions & 10 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ use frame_support::{
ord_parameter_types, parameter_types,
traits::{
fungible, fungibles,
tokens::{imbalance::ResolveAssetTo, nonfungibles_v2::Inspect, ConversionToAssetBalance},
tokens::{
asset_ops::{common_strategies::Bytes, AssetDefinition, AssetIdOf, InspectMetadata},
imbalance::ResolveAssetTo,
nonfungibles_v2::Inspect,
ConversionToAssetBalance,
},
AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Equals,
InstanceFilter, MapSuccess, TransformOrigin,
},
Expand All @@ -56,13 +61,15 @@ use frame_system::{
EnsureRoot, EnsureSigned, EnsureSignedBy,
};
use pallet_asset_conversion_tx_payment::SwapAssetAdapter;
use pallet_nft_fractionalization::{FractionalizedName, FractionalizedSymbol};
use pallet_nfts::{DestroyWitness, PalletFeatures};
use pallet_xcm::EnsureXcm;
use parachains_common::{
impls::DealWithFees, message_queue::*, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance,
BlockNumber, CollectionId, Hash, Header, ItemId, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO,
NORMAL_DISPATCH_RATIO,
};
use scale_info::prelude::{format, string::String};
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
Expand All @@ -72,7 +79,7 @@ use sp_runtime::{
Saturating, Verify,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Perbill, Permill, RuntimeDebug,
ApplyExtrinsicResult, DispatchError, Perbill, Permill, RuntimeDebug,
};
#[cfg(feature = "std")]
use sp_version::NativeVersion;
Expand Down Expand Up @@ -860,23 +867,39 @@ impl pallet_uniques::Config<pallet_uniques::Instance2> for Runtime {

parameter_types! {
pub const NftFractionalizationPalletId: PalletId = PalletId(*b"fraction");
pub NewAssetSymbol: BoundedVec<u8, AssetsStringLimit> = (*b"FRAC").to_vec().try_into().unwrap();
pub NewAssetName: BoundedVec<u8, AssetsStringLimit> = (*b"Frac").to_vec().try_into().unwrap();
}

pub struct FractionalizedNfts;
impl AssetDefinition for FractionalizedNfts {
type Id = AssetIdOf<pallet_nfts::asset_ops::Item<Nfts>>;
}
impl InspectMetadata<Bytes<FractionalizedName>> for FractionalizedNfts {
fn inspect_metadata(
(collection_id, item_id): &Self::Id,
_frac_name: Bytes<FractionalizedName>,
) -> Result<Vec<u8>, DispatchError> {
Ok(format!("Frac {collection_id}-{item_id}").into_bytes())
}
}
impl InspectMetadata<Bytes<FractionalizedSymbol>> for FractionalizedNfts {
fn inspect_metadata(
_instance_id: &Self::Id,
_frac_name: Bytes<FractionalizedSymbol>,
) -> Result<Vec<u8>, DispatchError> {
Ok(String::from("FRAC").into_bytes())
}
}

impl pallet_nft_fractionalization::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Deposit = AssetDeposit;
type Currency = Balances;
type NewAssetSymbol = NewAssetSymbol;
type NewAssetName = NewAssetName;
type StringLimit = AssetsStringLimit;
type NftCollectionId = <Self as pallet_nfts::Config>::CollectionId;
type NftId = <Self as pallet_nfts::Config>::ItemId;
type AssetBalance = <Self as pallet_balances::Config>::Balance;
type AssetId = <Self as pallet_assets::Config<TrustBackedAssetsInstance>>::AssetId;
type Assets = Assets;
type Nfts = Nfts;
type NftId = AssetIdOf<pallet_nfts::asset_ops::Item<Nfts>>;
type Nfts = pallet_nfts::asset_ops::Item<Nfts>;
type FractionalizedNfts = FractionalizedNfts;
type PalletId = NftFractionalizationPalletId;
type WeightInfo = pallet_nft_fractionalization::weights::SubstrateWeight<Runtime>;
type RuntimeHoldReason = RuntimeHoldReason;
Expand Down
Loading