Skip to content

Commit

Permalink
Add implementation guide
Browse files Browse the repository at this point in the history
  • Loading branch information
dudo50 committed Oct 26, 2024
1 parent 7150703 commit cfad766
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 144 deletions.
24 changes: 17 additions & 7 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from 'vitepress'

// https://vitepress.dev/reference/site-config
export default defineConfig({
title: "xcnft-pallet documentation",
title: "xcnft-pallet docs",
description: "A comprehensive pallet for cross-chain NFTs on Polkadot",
base: '/xcnft-docs/',
head: [
Expand All @@ -16,17 +16,27 @@ export default defineConfig({

nav: [
{ text: 'Home', link: '/' },
{ text: 'Implementation', link: '/markdown-examples' },
{ text: 'User guide', link: '/markdown-examples' }
{ text: 'Implementation', link: '/implementation-guide/introduction' },
{ text: 'User guide', link: '/user-guide/intro' }
],

sidebar: [
{
text: 'Examples',
text: 'Implementation guide',
items: [
{ text: 'Markdown Examples', link: '/markdown-examples' },
{ text: 'Runtime API Examples', link: '/api-examples' }
]
{ text: 'Introduction', link: '/implementation-guide/introduction' },
{ text: 'xcnft for pallet_nfts', link: '/implementation-guide/pallet-nfts' },
{ text: 'xcnft for pallet_uniques', link: '/implementation-guide/pallet-uniques' }
],
},
{
text: 'User guide',
items: [
{ text: 'Getting Started', link: '/user-guide/intro' },
{ text: 'Pallet storage', link: '/user-guide/storage' },
{ text: 'Pallet errors and events', link: '/user-guide/errors-events' },
{ text: 'Pallet functionality', link: '/user-guide/functions' },
],
}
],

Expand Down
49 changes: 0 additions & 49 deletions api-examples.md

This file was deleted.

90 changes: 90 additions & 0 deletions implementation-guide/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Welcome fellow Parachain developer 🧙‍♂️

Following section will guide you through implementation of the xcNFT cross-chain pallet for non-fungible assets.

## Before your journey begins 🧳

Before you begin with implementing this magical ✨ pallet into your Parachain, you must ensure, that you meet following pre-requirements:

### Your Parachain should implement following pallets:

**Substrate:**
- `frame-benchmarking`
- `frame-support`
- `frame-system`

**Cumulus:**
- `cumulus-primitives-core`
- `cumulus-pallet-xcm`

**XCMP:**
- `xcm`

**SP:**
- `sp-runtime`
- `sp-std`
- `sp-core`
- `sp-io`

**Substrate Pallets:**
- Either `pallet-nfts` or `pallet-uniques` depending on which pallet your Parachain uses
- `pallet-balances`
- `parachain-info`

**Other pallets (Only needed for pallet_uniques xcnft version):**
- `enumflags2`


### You should also make choice of xcnft version:
- If your Parachain uses **pallet_nfts** head over to [xcnft for pallet_nfts]() section.
- If your Parachain uses **pallet_uniques** head over to [xcnft for pallet_uniques]() section.

## Testing pallet functionality 🔎

Don't know whether this pallet is useful for your Parachain?

No worries!

**Try it out before you implement it!**

### Follow these steps to create local testnet that implements xcNFT:

1. Fork or clone [following repository](https://github.com/paraspell-research/polkadot-sdk)

2. Download [Zombienet binary for your system](https://github.com/paritytech/zombienet/releases)

3. Copy zombienet binary into binaries folder of the repository you just forked

4. Compile Relay chain by:
- `cd polkadot`
- `cargo build --release`

5. Compile first Parachain by:
- `cargo b -r -p parachain-template-node`

6. Compile second Parachain by:
- `cargo b -r -p parachain-template-node-two`

7. Launch zombienet localhost network by:
- `cd binaries`
- Choose config that you wish to test:
- `./zombienet-macos-arm64 -p native -c 1 spawn config-both.toml` launches network with 1 Relay chain, 1 Parachain with *pallet_nfts* and 1 Parachain with *pallet_uniques* (Best for testing pallet agnosticity)
- `./zombienet-macos-arm64 -p native -c 1 spawn config-nfts.toml` launches network with 1 Relay chain and 2 Parachains with *pallet_nfts*
- `./zombienet-macos-arm64 -p native -c 1 spawn config-uniques.toml` launches network with 1 Relay chain and 2 Parachains with *pallet_uniques*

8. Once the network is launched, connect to one of the Relay chain nodes:

![zombienet](https://github.com/user-attachments/assets/06f1d41e-55a7-4d7b-b7f3-f3e6fa276132)

9. Open HRMP channels for both chains (Needed for allowing cross-chain communication):
- Navigate to `Extrinsics` tab select `Alice` account and go to `Decode`
- Paste following hash to Decode section: `0xff00fa05e8030000e90300000800000000040000` (This hash opens channel from chain 1000 to 1001)
- Move back to Submission and sign the call with Alice
- Paste following hash to Decode section `0xff00fa05e9030000e80300000800000000040000` (This hash opens channel from chain 1001 to 1000)
- Move back to Submission and sign the call with Alice

10. Start interacting with chains by connecting to their WS endpoints from Zombienet console and try xcNFT out.

Don't know which function does what? Unsure what storage stores what?

Head over to [User guide](https://paraspell-research.github.io/xcnft-docs/user-guide/intro.html) section.
60 changes: 60 additions & 0 deletions implementation-guide/pallet-nfts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Welcome to the future of cross-chain NFTs on Polkadot 🪐

Your choice to implement xcNFT into your Parachain means a lot to us! Feel free to provide feedback or suggestions in form of issue in this [GitHub repository](https://github.com/paraspell-research/xcnft-pallet)!

Don't yet know what xcNFT has to offer? Head to [User guide](https://paraspell-research.github.io/xcnft-docs/user-guide/intro.html) section for overview.

**Let's get you started.**

## Implementing xcNFT 👨‍💻
Following subsection guides you through the implementation phase of xcNFT

Here are the steps that you should follow:

1. Copy code from the [following folder](https://github.com/paraspell-research/xcnft-pallet/tree/main/xcnft-pallet_nfts) into your Parachain's pallets folder.

2. Setup dependencies in xcNFT's `cargo.toml` to latest versions and try to compile your Parachain's code.

## Runtime setup ⚙️

xcNFT requires minimal runtime config:
```
impl pallet_parachain_xcnft::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_parachain_xcnft::weights::SubstrateWeight<Runtime>;;
type XcmSender = xcm_config::XcmRouter;
type RuntimeCall = RuntimeCall;
type ProposalTimeInBlocks = proposal_time_in_blocks_parameter; //How long should proposals for moving collections with different owners last? 100800 for approximately 2 weeks.
type MaxOwners = max_owners_parameter; //How many owners can be in the collection? Should be limited to pallet_nfts configuration.
}
```

**IMPORTANT!**

For your chain to be compatible with xcNFT of other chains, make sure to name module in same exact way as provided below:
```
#[runtime::pallet_index(INSERT_INDEX_HERE)]
pub type XcnftPallet = pallet_parachain_xcnft;
```

Also do not forget to add xcNFT pallet to `cargo.toml`:
```
pallet-parachain-xcnft = { VERSION HERE }
//Also include it into STD
"pallet-parachain-xcnft/std",
//Also into runtime benchmarks
pallet-parachain-xcnft/runtime-benchmarks,
//And try-runtime
pallet-parachain-xcnft/try-runtime,
```


## XCM Setup 🔬

The only tweak, that you should do to your XCM config is, to **enable aliasers**:
```
type Aliasers = Everything; //Only enable to Everything in testnet enviroment!
```
60 changes: 60 additions & 0 deletions implementation-guide/pallet-uniques.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Stand out in a world of replicas - be unique 👨‍🎨

Your choice to implement xcNFT into your Parachain means a lot to us! Feel free to provide feedback or suggestions in form of issue in this [GitHub repository](https://github.com/paraspell-research/xcnft-pallet)!

Don't yet know what xcNFT has to offer? Head to [User guide](https://paraspell-research.github.io/xcnft-docs/user-guide/intro.html) section for overview.

**Let's get you started.**

## Implementing xcNFT 👨‍💻
Following subsection guides you through the implementation phase of xcNFT

Here are the steps that you should follow:

1. Copy code from the [following folder](https://github.com/paraspell-research/xcnft-pallet/tree/main/xcnft-pallet_uniques) into your Parachain's pallets folder.

2. Setup dependencies in xcNFT's `cargo.toml` to latest versions and try to compile your Parachain's code.

## Runtime setup ⚙️

xcNFT requires minimal runtime config:
```
impl pallet_parachain_xcnft::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_parachain_xcnft::weights::SubstrateWeight<Runtime>;;
type XcmSender = xcm_config::XcmRouter;
type RuntimeCall = RuntimeCall;
type ProposalTimeInBlocks = proposal_time_in_blocks_parameter; //How long should proposals for moving collections with different owners last? 100800 for approximately 2 weeks.
type MaxOwners = max_owners_parameter; //How many owners can be in the collection? Should be limited to pallet_nfts configuration.
}
```

**IMPORTANT!**

For your chain to be compatible with xcNFT of other chains, make sure to name module in same exact way as provided below:
```
#[runtime::pallet_index(INSERT_INDEX_HERE)]
pub type XcnftPallet = pallet_parachain_xcnft;
```

Also do not forget to add xcNFT pallet to `cargo.toml`:
```
pallet-parachain-xcnft = { VERSION HERE }
//Also include it into STD
"pallet-parachain-xcnft/std",
//Also into runtime benchmarks
pallet-parachain-xcnft/runtime-benchmarks,
//And try-runtime
pallet-parachain-xcnft/try-runtime,
```


## XCM Setup 🔬

The only tweak, that you should do to your XCM config is, to **enable aliasers**:
```
type Aliasers = Everything; //Only enable to Everything in testnet enviroment!
```
5 changes: 2 additions & 3 deletions index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
# https://vitepress.dev/reference/default-theme-home-page
layout: home

hero:
Expand All @@ -9,10 +8,10 @@ hero:
actions:
- theme: brand
text: NFTs implementation
link: /markdown-examples
link: /implementation-guide/pallet-nfts
- theme: alt
text: Uniques implementation
link: /api-examples
link: /implementation-guide/pallet-uniques

features:
- title: Pallet agnostic
Expand Down
Loading

0 comments on commit cfad766

Please sign in to comment.