forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
3,831 additions
and
1,463 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[relaychain] | ||
|
||
default_command = "../target/release/polkadot" | ||
default_args = [ "-lparachain=debug" ] | ||
|
||
chain = "rococo-local" | ||
|
||
[[relaychain.nodes]] | ||
name = "alice" | ||
|
||
[[relaychain.nodes]] | ||
name = "bob" | ||
|
||
[[relaychain.nodes]] | ||
name = "charlie" | ||
|
||
[[relaychain.nodes]] | ||
name = "dave" | ||
|
||
[[parachains]] | ||
id = 1000 | ||
cumulus_based = true | ||
|
||
[parachains.collator] | ||
name = "parachain-A-1000-collator01" | ||
command = "../target/release/parachain-template-node" | ||
args = [ | ||
"-lparachain=debug,xcm::process-message=trace,xcm::execute=trace,xcm::process=trace" | ||
] | ||
|
||
[[parachains]] | ||
id = 1001 | ||
cumulus_based = true | ||
|
||
[parachains.collator] | ||
name = "parachain-A-1001-collator01" | ||
command = "../target/release/parachain-template-node" | ||
args = [ | ||
"-lparachain=debug,xcm::process-message=trace,xcm::execute=trace,xcm::process=trace" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
[package] | ||
name = "pallet-parachain-xcnft" | ||
authors = ["ParaSpell Foundation"] | ||
description = "Pallet for NFT sharing using XCM." | ||
version = "0.1.0" | ||
license = "MIT" | ||
homepage = "https://docs.paraspell.io" | ||
repository.workspace = true | ||
edition.workspace = true | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
codec = { features = [ | ||
"derive", | ||
], workspace = true } | ||
scale-info = { features = [ | ||
"derive", | ||
], workspace = true } | ||
|
||
# Substrate | ||
frame-benchmarking = { optional = true, workspace = true } | ||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
|
||
#XCM | ||
xcm = { workspace = true} | ||
|
||
cumulus-primitives-core = { workspace = true } | ||
cumulus-pallet-xcm = { workspace = true } | ||
|
||
sp-runtime = { workspace = true } | ||
sp-std = {workspace = true} | ||
|
||
[dev-dependencies] | ||
serde = { version = "1.0.210", default-features = false } | ||
|
||
# Substrate | ||
sp-core = { workspace = true, default-features = true } | ||
sp-io = { workspace = true, default-features = true } | ||
|
||
pallet-balances = { workspace = true, default-features = true } | ||
|
||
|
||
[features] | ||
default = [ "std" ] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"sp-runtime/runtime-benchmarks", | ||
|
||
] | ||
std = [ | ||
"codec/std", | ||
"scale-info/std", | ||
|
||
"frame-benchmarking?/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
|
||
"sp-runtime/std", | ||
"cumulus-pallet-xcm/std", | ||
"cumulus-primitives-core/std", | ||
"sp-std/std", | ||
"xcm/std", | ||
"sp-core/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
] | ||
try-runtime = [ | ||
"cumulus-pallet-xcm/try-runtime", | ||
"frame-support/try-runtime", | ||
"frame-system/try-runtime", | ||
"sp-runtime/try-runtime", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# This repository holds xcNFT Pallet for cross-chain non-fungible asset sharing | ||
|
||
## Proof of concept implementation only! | ||
### License MIT | ||
|
||
# Compile | ||
```cargo build``` | ||
|
||
# Add to runtime | ||
``` | ||
/// Configure the pallet xcnft in pallets/xcnft. | ||
impl pallet_parachain_xcnft::Config for Runtime { | ||
type Currency = Balances; | ||
type RuntimeEvent = RuntimeEvent; | ||
type StringLimit = ConstU32<255>; | ||
type JsonLimit = ConstU32<255>; | ||
type CollectionLimit = ConstU32<255>; | ||
type ParaIDLimit = ConstU32<9999>; | ||
type CollectionsPerParachainLimit = ConstU32<9999>; | ||
type NFTsPerParachainLimit = ConstU32<9999>; | ||
type XcmSender = XcmRouter; | ||
type RuntimeCall = RuntimeCall; | ||
} | ||
``` | ||
|
||
and to construct_runtime! macro: | ||
|
||
``` | ||
XCNFTPallet: pallet_parachain_xcnft = 51, | ||
``` | ||
|
||
also import it | ||
|
||
``` | ||
/// Import pallet xcnft | ||
pub use pallet_parachain_xcnft; | ||
``` | ||
|
||
To make XCM work update XCM config: | ||
``` | ||
AllowExplicitUnpaidExecutionFrom<Everything>, | ||
``` | ||
|
||
Change type Call Dispatcher: | ||
``` | ||
use xcm_executor::traits::WithOriginFilter; | ||
``` | ||
``` | ||
type CallDispatcher = WithOriginFilter<Self::SafeCallFilter>; | ||
``` | ||
|
||
|
||
Testing benchmarks (Needs to be implemented in runtime already) | ||
``` | ||
cargo test --package pallet-parachain-xcnft --features runtime-benchmarks | ||
``` | ||
Unit tests (Needs to be implemented in runtime already) | ||
``` | ||
cargo test --package pallet-parachain-xcnft --lib -- tests --nocapture | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#![cfg(feature = "runtime-benchmarks")] | ||
use super::*; | ||
|
||
#[allow(unused)] | ||
use crate::Pallet as Template; | ||
|
||
use cumulus_primitives_core::ParaId; | ||
use frame_benchmarking::v2::*; | ||
use frame_system::RawOrigin; | ||
use sp_runtime::traits::Hash; | ||
|
||
#[benchmarks] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
#[benchmark] | ||
fn mint_collection_large() { | ||
let caller: T::AccountId = whitelisted_caller(); | ||
|
||
#[extrinsic_call] | ||
mint_collection(RawOrigin::Signed(caller),b"pHgJCOTaAPedH0mtvRVVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(), b"pHgJCOTaAPEceLC69VVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap()); | ||
} | ||
|
||
#[benchmark] | ||
fn mint_non_fungible_large() { | ||
let caller: T::AccountId = whitelisted_caller(); | ||
|
||
let collection: pallet::Collection<T> = Collection { | ||
owner: caller.clone(), | ||
collection_name: b"pHgJCOTaAPedH0mtvRVVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(), | ||
collection_description: b"pHgJCOTaAPEceLC69VVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(), | ||
collection_origin_parachain_id: 0.into(), | ||
}; | ||
|
||
let collection_hash = T::Hashing::hash_of(&collection); | ||
|
||
let collection_with_hash: pallet::CollectionWithHash<T> = CollectionWithHash { | ||
owner: caller.clone(), | ||
collection_name: b"pHgJCOTaAPedH0mtvRVVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(), | ||
collection_description: b"pHgJCOTaAPEceLC69VVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(), | ||
collection_origin_parachain_id: 0.into(), | ||
collection_hash: collection_hash, | ||
}; | ||
|
||
pallet::Collections::<T>::insert(collection_hash, collection_with_hash); | ||
pallet::CollectionSize::<T>::insert(collection_hash, 0); | ||
|
||
#[extrinsic_call] | ||
mint_non_fungible(RawOrigin::Signed(caller),b"pHgJCOTaAPedH0mtvRVVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(), b"pHgJCOTaAPEceLC69VVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(),collection_hash); | ||
} | ||
|
||
#[benchmark] | ||
fn mint_collection_received_large() { | ||
let caller: T::AccountId = whitelisted_caller(); | ||
|
||
#[extrinsic_call] | ||
mint_collection_received(RawOrigin::Signed(caller),b"pHgJCOTaAPedH0mtvRVVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(), b"pHgJCOTaAPEceLC69VVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(),1000.into(), caller.clone()); | ||
} | ||
|
||
#[benchmark] | ||
fn mint_non_fungible_received_large() { | ||
let caller: T::AccountId = whitelisted_caller(); | ||
|
||
let collection: pallet::Collection<T> = Collection { | ||
owner: caller.clone(), | ||
collection_name: b"pHgJCOTaAPedH0mtvRVVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(), | ||
collection_description: b"pHgJCOTaAPEceLC69VVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(), | ||
collection_origin_parachain_id: 0.into(), | ||
}; | ||
|
||
let collection_hash = T::Hashing::hash_of(&collection); | ||
|
||
let collection_with_hash: pallet::CollectionWithHash<T> = CollectionWithHash { | ||
owner: caller.clone(), | ||
collection_name: b"pHgJCOTaAPedH0mtvRVVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(), | ||
collection_description: b"pHgJCOTaAPEceLC69VVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(), | ||
collection_origin_parachain_id: 0.into(), | ||
collection_hash: collection_hash, | ||
}; | ||
|
||
let parachain_id: ParaId = 0.into(); | ||
let _ = ReceivedCollections::<T>::mutate(parachain_id, |x| -> Result<(), ()> { | ||
if let Some(x) = x { | ||
x.try_push(collection_with_hash).map_err(|_| ())?; | ||
Ok(()) | ||
} else { | ||
*x = Some(vec![collection_with_hash].try_into().map_err(|_| ())?); | ||
Ok(()) | ||
} | ||
}); | ||
|
||
pallet::CollectionSize::<T>::insert(collection_hash, 0); | ||
|
||
#[extrinsic_call] | ||
mint_non_fungible_received(RawOrigin::Signed(caller),b"pHgJCOTaAPedH0mtvRVVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(), b"pHgJCOTaAPEceLC69VVtYyApzDcR0WebyTdJw1sSIRTozxXKFI3cA91Yv3ZzFk5ZH00J2SC7a3aFDrlt5rPIpwGO5UE6jSplFqdu7AhoEf8t7D6aD5CDBGOL8AZnllhAIBKBLgspdsSGoacIWx0CLFpPF2ALtm1iitrDo4B39sZC2ne9PGFIe4C1PazXLnWwbF0Kea3akaoNv6HRqKWgFNv4VTxdhCoWDsAzbzzP3GSyBYuSwBlhXP".to_vec().try_into().unwrap(),collection_hash, 0.into(), caller.clone()); | ||
} | ||
|
||
impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test); | ||
} |
Oops, something went wrong.