Skip to content

Commit

Permalink
Update to latest SDK version
Browse files Browse the repository at this point in the history
  • Loading branch information
dudo50 committed Sep 15, 2024
1 parent d66dee3 commit 0477be2
Show file tree
Hide file tree
Showing 13 changed files with 3,831 additions and 1,463 deletions.
2,975 changes: 1,518 additions & 1,457 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ members = [
"templates/minimal/runtime",
"templates/parachain/node",
"templates/parachain/pallets/template",
"templates/parachain/pallets/xcnft",
"templates/parachain/runtime",
"templates/solochain/node",
"templates/solochain/pallets/template",
Expand Down Expand Up @@ -949,6 +950,7 @@ pallet-offences = { path = "substrate/frame/offences", default-features = false
pallet-offences-benchmarking = { path = "substrate/frame/offences/benchmarking", default-features = false }
pallet-paged-list = { path = "substrate/frame/paged-list", default-features = false }
pallet-parachain-template = { path = "templates/parachain/pallets/template", default-features = false }
pallet-parachain-xcnft = { path = "templates/parachain/pallets/xcnft", default-features = false }
pallet-parameters = { path = "substrate/frame/parameters", default-features = false }
pallet-preimage = { path = "substrate/frame/preimage", default-features = false }
pallet-proxy = { path = "substrate/frame/proxy", default-features = false }
Expand Down
40 changes: 40 additions & 0 deletions binaries/config.toml
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"
]
77 changes: 77 additions & 0 deletions templates/parachain/pallets/xcnft/Cargo.toml
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",
]
60 changes: 60 additions & 0 deletions templates/parachain/pallets/xcnft/README.md
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
```
99 changes: 99 additions & 0 deletions templates/parachain/pallets/xcnft/src/benchmarking.rs
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);
}
Loading

0 comments on commit 0477be2

Please sign in to comment.