Commit c1dbcb7
XCM NFT types that use Granular NFT traits (#4300)
## Overview
This PR provides new XCM types and tools for building NFT Asset
Transactors.
The new types use general and granular NFT traits from #5620.
The new XCM adapters and utility types to work with NFTs can be
considered the main deliverable of the **[XCM NFT
proposal](https://polkadot.polkassembly.io/referenda/379)**. The new
types use a more general approach, making integration into any chain
with various NFT implementations easier.
For instance, different implementations could use:
* different ID assignment approaches
* predefined NFT IDs - pallet-uniques, pallet-nfts
* derived NFT IDs (NFT IDs are automatically derived from collection
IDs) - Unique Network, ORML/Acala, Aventus
* classless (collection-less) tokens - CoreTime NFTs, Aventus NFT
Manager NFTs
* in-class (in-collection) tokens - Unique Network, pallet-uniques,
pallet-nfts, ORML/Acala
* different approaches to storing associated data on-chain:
* data is stored entirely separately from tokens - pallet-uniques
* data is stored partially or entirely within tokens (i.e., burning a
token means destroying it with its data) - pallet-nfts
([partially](https://github.com/paritytech/polkadot-sdk/blob/8b4cfda7589325d1a34f70b3770ab494a9d4052c/substrate/frame/nfts/src/features/create_delete_item.rs#L240-L241)),
Unique Network, ORML/Acala
With new types, these differences can be abstracted away.
Moreover, the new types provide greater flexibility for supporting
derivative NFTs, allowing several possible approaches depending on the
given chain's team's goals or restrictions (see the `pallet-derivatives`
crate docs and mock docs).
Also, this is the PR I mentioned in the
#4073 issue, as it can
be viewed as the solution. In particular, the new adapter
(`UniqueInstancesAdapter`) requires the `Update` operation with the
`ChangeOwnerFrom` strategy. This brings the attention of both a
developer and a reviewer to the `ChangeOwnerFrom` strategy (meaning that
the transfer checks if the asset can be transferred from a given account
to another account), both at trait bound and at the call site, without
sacrificing the flexibility of the NFT traits.
## New types for xcm-builder and xcm-executor
This PR introduces several XCM types.
The `UniqueInstancesAdapter` is a new `TransactAsset` adapter that
supersedes both `NonFungibleAdapter` and `NonFungiblesAdapter` (for
reserve-based transfers only, as teleports can't be implemented
appropriately without transferring the NFT metadata alongside it; no
standard solution exists for that yet. Hopefully, the Felloweship RFC
125 ([PR](polkadot-fellows/RFCs#125),
[text](https://github.com/polkadot-fellows/RFCs/blob/3a24444278f22dac414fbd2b5c4b205f73d78af7/text/0125-xcm-asset-metadata.md))
will help with that).
Thanks to the new Matcher types, the new adapter can be used instead of
both `NonFungibleAdapter` and `NonFungiblesAdapter`:
* `MatchesInstance` (a trait)
* `MatchInClassInstances`
* `MatchClasslessInstances`
The `UniqueInstancesAdapter` works with existing tokens only. To create
new tokens (derivative ones), there is the
`UniqueInstancesDepositAdapter`.
See the `pallet-derivatives` mock and tests for the usage example.
### Superseding the old adapters for pallet-uniques
Here is how the new `UniqueInstancesAdapter` in Westend Asset Hub
replaces the `NonFungiblesAdapter`:
```rust
/// Means for transacting unique assets.
pub type UniquesTransactor = UniqueInstancesAdapter<
AccountId,
LocationToAccountId,
MatchInClassInstances<UniquesConvertedConcreteId>,
pallet_uniques::asset_ops::Item<Uniques>,
>;
```
`MatchInClassInstances` allows us to reuse the already existing
`UniquesConvertedConcreteId` matcher.
The `pallet_uniques::asset_ops::Item<Uniques>` already implements the
needed traits.
So, migrating from the old adapter to the new one regarding runtime
config changes is easy.
>NOTE: `pallet_uniques::asset_ops::Item` grants access to the asset
operations of NFT items of a given pallet-uniques instance, whereas
`pallet_uniques::asset_ops::Collection` grants access to the collection
operations.
### Declarative modification of an NFT engine
If an NFT-hosting pallet only implements a transfer operation but not
the `Stash` and `Restore`, one could declaratively add them using the
`UniqueInstancesWithStashAccount` adapter.
So, you can use it with the `UniqueInstancesAdapter` as follows:
```rust
parameter_types! {
pub StashAccountId: AccountId = /* Some Stash Account ID */;
}
type Transactor = UniqueInstancesAdapter<
AccountId,
LocationToAccountId,
Matcher,
UniqueInstancesWithStashAccount<StashAccountId, NftEngine>,
>;
```
### Supporting derivative NFTs (reserve-based model)
There are several possible scenarios of supporting derivative NFTs (and
their collections, if applicable).
A separate NFT-hosting pallet instance could be configured to use XCM
`AssetId` as collection ID and `AssetInstance` token ID. In that case,
the asset transaction doesn't need any special treatment.
However, registering NFT collections might require a special API.
Also, if the NFT-hosting pallet can't be configured to use XCM ID types,
we would need to store a mapping between the XCM ID of the original
token and the derivative ID.
See the `pallet-derivatives` crate docs for details.
The example of its usage can be found in its mock and tests.
#### TODO
No benchmarks were run for `pallet-derivatives`, so there is no
`weights.rs` for it yet.
---------
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>1 parent 8468c3e commit c1dbcb7
30 files changed
Lines changed: 2867 additions & 55 deletions
File tree
- cumulus/parachains/runtimes/assets
- asset-hub-rococo/src
- asset-hub-westend
- src
- tests
- polkadot/xcm
- xcm-builder/src
- unique_instances
- xcm-executor/src/traits
- prdoc
- substrate/frame
- derivatives
- src
- mock
- support/src/traits/tokens
- asset_ops
- uniques/src
- asset_ops
- umbrella
- src
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
| 359 | + | |
359 | 360 | | |
360 | 361 | | |
361 | 362 | | |
| |||
1051 | 1052 | | |
1052 | 1053 | | |
1053 | 1054 | | |
| 1055 | + | |
1054 | 1056 | | |
1055 | 1057 | | |
1056 | 1058 | | |
| |||
Lines changed: 11 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
56 | | - | |
57 | | - | |
| 57 | + | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
| 151 | + | |
158 | 152 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
163 | 156 | | |
164 | 157 | | |
165 | 158 | | |
| |||
Lines changed: 11 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
56 | | - | |
57 | | - | |
| 57 | + | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 147 | + | |
154 | 148 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
159 | 152 | | |
160 | 153 | | |
161 | 154 | | |
| |||
Lines changed: 174 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
48 | 53 | | |
49 | 54 | | |
50 | 55 | | |
| |||
55 | 60 | | |
56 | 61 | | |
57 | 62 | | |
| 63 | + | |
58 | 64 | | |
59 | 65 | | |
60 | 66 | | |
61 | | - | |
| 67 | + | |
62 | 68 | | |
63 | 69 | | |
64 | 70 | | |
| |||
68 | 74 | | |
69 | 75 | | |
70 | 76 | | |
71 | | - | |
72 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
73 | 82 | | |
74 | 83 | | |
75 | 84 | | |
| |||
503 | 512 | | |
504 | 513 | | |
505 | 514 | | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
506 | 675 | | |
507 | 676 | | |
508 | 677 | | |
| |||
0 commit comments