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

feat(mainnet): introduce assets #465

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cf99ad4
refactor(mainnet): include assets
al3mart Feb 5, 2025
726b377
test(assets): add nfts config unit tests
al3mart Feb 11, 2025
e614927
refactor(proxy): Add assets & smart contract proxy type
al3mart Feb 11, 2025
f8fdeea
refactor(assets): implement nfts runtime api
al3mart Feb 11, 2025
6b4b505
fix(pallet-nfts-api): workspace linters are not defined
al3mart Feb 11, 2025
5c75dc7
docs(assets): clarify deposits
al3mart Feb 11, 2025
e94a545
chore(proxy): improve usage of references
al3mart Feb 11, 2025
13a2392
docs(assets): update src reference
al3mart Feb 11, 2025
47b3c92
chore(assets): update MetadataDepositBase
al3mart Feb 11, 2025
e5f4212
docs(assets): remove TODOs
al3mart Feb 11, 2025
6a7fb18
refactor(proxy): revert SmartContract ProxyType
al3mart Feb 12, 2025
88f5eab
revert: e614927728f48ae8b176f86ee4207083c062c71a
al3mart Feb 13, 2025
fb92342
style(Cargo): revert format changes on dep comments
al3mart Feb 13, 2025
84188ad
chore(assets): apply feedback to tests
al3mart Feb 13, 2025
b813b52
chore(assets): removed unused type
al3mart Feb 13, 2025
5263090
revert: fb9234215336ce342c3edb6c15fff56ec2130c98
al3mart Feb 13, 2025
8708e32
docs(assets): better comments
al3mart Feb 13, 2025
976a845
chore(assets): lower nfts deposit costs
al3mart Feb 13, 2025
84790c1
chore(assets): reduced deposit cost for AssetAccountDeposit
al3mart Feb 13, 2025
b332ba1
chore(assets): use SDK's pallet_nfts
al3mart Feb 13, 2025
759e51a
chore(assets): better deposits & fmt Cargo
al3mart Feb 13, 2025
f10ccd8
chore(assets): better comments
al3mart Feb 13, 2025
645fb3d
chore(assets): more explicit comments for deposits
al3mart Feb 14, 2025
08b3369
chore(assets): provide src for NftsCollectionDeposit deposit
al3mart Feb 14, 2025
098a035
chore(assets): apply feedback
al3mart Feb 14, 2025
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
16 changes: 14 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", b
# Local
pallet-api = { path = "pallets/api", default-features = false }
pallet-nfts = { path = "pallets/nfts", default-features = false }
pallet-nfts-runtime-api = { path = "pallets/nfts/runtime-api", default-features = false }
pop-chain-extension = { path = "./extension", default-features = false }
pop-primitives = { path = "./primitives", default-features = false }
pop-runtime-common = { path = "runtime/common", default-features = false }
pop-runtime-devnet = { path = "runtime/devnet", default-features = true } # default-features=true required for `-p pop-node` builds
pop-runtime-mainnet = { path = "runtime/mainnet", default-features = true } # default-features=true required for `-p pop-node` builds
pop-runtime-testnet = { path = "runtime/testnet", default-features = true } # default-features=true required for `-p pop-node` builds
pop-runtime-devnet = { path = "runtime/devnet", default-features = true } # default-features=true required for `-p pop-node` builds
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
pop-runtime-mainnet = { path = "runtime/mainnet", default-features = true } # default-features=true required for `-p pop-node` builds
pop-runtime-testnet = { path = "runtime/testnet", default-features = true } # default-features=true required for `-p pop-node` builds

# Substrate
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412", default-features = false }
Expand All @@ -94,7 +95,6 @@ pallet-contracts = { git = "https://github.com/paritytech/polkadot-sdk", branch
pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412", default-features = false }
pallet-multisig = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412", default-features = false }
pallet-nft-fractionalization = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412", default-features = false }
pallet-nfts-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412", default-features = false }
pallet-preimage = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412", default-features = false }
pallet-proxy = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412", default-features = false }
pallet-revive = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2412", default-features = false }
Expand Down
3 changes: 0 additions & 3 deletions pallets/nfts/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ readme = "README.md"
repository.workspace = true
version = "23.0.0"

[lints]
workspace = true

[package.metadata.docs.rs]
targets = [ "x86_64-unknown-linux-gnu" ]

Expand Down
1 change: 1 addition & 0 deletions pallets/nfts/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,39 @@
extern crate alloc;

use alloc::vec::Vec;

use codec::{Decode, Encode};

sp_api::decl_runtime_apis! {
pub trait NftsApi<AccountId, CollectionId, ItemId>
where
AccountId: Encode + Decode,
CollectionId: Encode,
ItemId: Encode,
{
fn owner(collection: CollectionId, item: ItemId) -> Option<AccountId>;

fn collection_owner(collection: CollectionId) -> Option<AccountId>;

fn attribute(
collection: CollectionId,
item: ItemId,
key: Vec<u8>,
) -> Option<Vec<u8>>;

fn custom_attribute(
account: AccountId,
collection: CollectionId,
item: ItemId,
key: Vec<u8>,
) -> Option<Vec<u8>>;

fn system_attribute(
collection: CollectionId,
item: Option<ItemId>,
key: Vec<u8>,
) -> Option<Vec<u8>>;

fn collection_attribute(collection: CollectionId, key: Vec<u8>) -> Option<Vec<u8>>;
}

Check warning on line 59 in pallets/nfts/runtime-api/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a trait

warning: missing documentation for a trait --> pallets/nfts/runtime-api/src/lib.rs:29:2 | 29 | / pub trait NftsApi<AccountId, CollectionId, ItemId> 30 | | where 31 | | AccountId: Encode + Decode, 32 | | CollectionId: Encode, ... | 58 | | fn collection_attribute(collection: CollectionId, key: Vec<u8>) -> Option<Vec<u8>>; 59 | | } | |_____^ | = note: requested on the command line with `-W missing-docs`
}

Check warning on line 60 in pallets/nfts/runtime-api/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a method

warning: missing documentation for a method --> pallets/nfts/runtime-api/src/lib.rs:28:1 | 28 | / sp_api::decl_runtime_apis! { 29 | | pub trait NftsApi<AccountId, CollectionId, ItemId> 30 | | where 31 | | AccountId: Encode + Decode, ... | 59 | | } 60 | | } | |_^ | = note: this warning originates in the macro `sp_api::decl_runtime_apis` (in Nightly builds, run with -Z macro-backtrace for more info)
74 changes: 2 additions & 72 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#![cfg_attr(not(feature = "std"), no_std)]
use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight};
// Cumulus types re-export
// These types are shared between the devnet and testnet runtimes
pub use parachains_common::{AccountId, AuraId, Balance, Block, BlockNumber, Hash, Signature};
pub use polkadot_primitives::MAX_POV_SIZE;
use sp_runtime::Perbill;

pub mod proxy;

Check warning on line 9 in runtime/common/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a module

warning: missing documentation for a module --> runtime/common/src/lib.rs:9:1 | 9 | pub mod proxy; | ^^^^^^^^^^^^^

/// Nonce for an account
pub type Nonce = u32;

Expand Down Expand Up @@ -73,75 +75,3 @@
pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
}
pub use async_backing_params::*;

Check warning on line 77 in runtime/common/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for the crate

warning: missing documentation for the crate --> runtime/common/src/lib.rs:1:1 | 1 | / #![cfg_attr(not(feature = "std"), no_std)] 2 | | use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}; 3 | | // Cumulus types re-export 4 | | // These types are shared between the devnet and testnet runtimes ... | 76 | | } 77 | | pub use async_backing_params::*; | |________________________________^ | = note: requested on the command line with `-W missing-docs`

/// Proxy commons for Pop runtimes
pub mod proxy {

use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::parameter_types;
use sp_runtime::RuntimeDebug;

use super::{deposit, Balance};

parameter_types! {
// One storage item; key size 32, value size 8; .
pub const ProxyDepositBase: Balance = deposit(1, 40);
// Additional storage item size of 33 bytes.
pub const ProxyDepositFactor: Balance = deposit(0, 33);
pub const MaxProxies: u16 = 32;
// One storage item; key size 32, value size 16
pub const AnnouncementDepositBase: Balance = deposit(1, 48);
pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
pub const MaxPending: u16 = 32;
}

/// The type used to represent the kinds of proxying allowed.
#[derive(
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Encode,
Decode,
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
)]
pub enum ProxyType {
/// Fully permissioned proxy. Can execute any call on behalf of _proxied_.
Any,
/// Can execute any call that does not transfer funds or assets.
NonTransfer,
/// Proxy with the ability to reject time-delay proxy announcements.
CancelProxy,
/// Assets proxy. Can execute any call from `assets`, **including asset transfers**.
Assets,
/// Owner proxy. Can execute calls related to asset ownership.
AssetOwner,
/// Asset manager. Can execute calls related to asset management.
AssetManager,
/// Collator selection proxy. Can execute calls related to collator selection mechanism.
Collator,
}
impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}

impl ProxyType {
pub fn is_superset(s: &ProxyType, o: &ProxyType) -> bool {
match (s, o) {
(x, y) if x == y => true,
(ProxyType::Any, _) => true,
(_, ProxyType::Any) => false,
(ProxyType::Assets, ProxyType::AssetOwner) => true,
(ProxyType::Assets, ProxyType::AssetManager) => true,
(ProxyType::NonTransfer, ProxyType::Collator) => true,
_ => false,
}
}
}
}
72 changes: 72 additions & 0 deletions runtime/common/src/proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/// Proxy commons for Pop runtimes
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::parameter_types;
use sp_runtime::RuntimeDebug;

use crate::{deposit, Balance};

parameter_types! {
// One storage item; key size 32, value size 8; .
pub const ProxyDepositBase: Balance = deposit(1, 40);
// Additional storage item size of 33 bytes.
pub const ProxyDepositFactor: Balance = deposit(0, 33);
pub const MaxProxies: u16 = 32;
// One storage item; key size 32, value size 16
pub const AnnouncementDepositBase: Balance = deposit(1, 48);
pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
pub const MaxPending: u16 = 32;
}

/// The type used to represent the kinds of proxying allowed.
#[derive(
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Encode,
Decode,
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
)]
pub enum ProxyType {
/// Fully permissioned proxy. Can execute any call on behalf of _proxied_.
Any,
/// Can execute any call that does not transfer funds or assets.
NonTransfer,
/// Proxy with the ability to reject time-delay proxy announcements.
CancelProxy,
/// Assets proxy. Can execute any call from `assets`, **including asset transfers**.
Assets,
/// Owner proxy. Can execute calls related to asset ownership.
AssetOwner,
/// Asset manager. Can execute calls related to asset management.
AssetManager,
/// Collator selection proxy. Can execute calls related to collator selection mechanism.
Collator,
}
impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}

impl ProxyType {
/// Defines proxies permission hierarchy.
// Example: A proxy that is not superset of another one won't be able to remove
// that proxy relationship
// src: https://github.com/paritytech/polkadot-sdk/blob/4cd07c56378291fddb9fceab3b508cf99034126a/substrate/frame/proxy/src/lib.rs#L802
pub fn is_superset(s: &ProxyType, o: &ProxyType) -> bool {
match (s, o) {
(x, y) if x == y => true,
(ProxyType::Any, _) => true,
(_, ProxyType::Any) => false,
(ProxyType::Assets, ProxyType::AssetOwner) => true,
(ProxyType::Assets, ProxyType::AssetManager) => true,
(ProxyType::NonTransfer, ProxyType::Collator) => true,
_ => false,
}
}
}
10 changes: 10 additions & 0 deletions runtime/mainnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ scale-info.workspace = true
smallvec.workspace = true

# Local
pallet-nfts.workspace = true
pallet-nfts-runtime-api.workspace = true
pop-runtime-common = { workspace = true, default-features = false }

# Substrate
Expand All @@ -33,6 +35,7 @@ frame-system.workspace = true
frame-system-benchmarking.workspace = true
frame-system-rpc-runtime-api.workspace = true
frame-try-runtime.workspace = true
pallet-assets.workspace = true
pallet-aura.workspace = true
pallet-authorship.workspace = true
pallet-balances.workspace = true
Expand Down Expand Up @@ -114,12 +117,15 @@ std = [
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"frame-try-runtime/std",
"pallet-assets/std",
"pallet-aura/std",
"pallet-authorship/std",
"pallet-balances/std",
"pallet-collator-selection/std",
"pallet-message-queue/std",
"pallet-multisig/std",
"pallet-nfts-runtime-api/std",
"pallet-nfts/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-revive/std",
Expand Down Expand Up @@ -166,10 +172,12 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-nfts/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-revive/runtime-benchmarks",
Expand Down Expand Up @@ -199,12 +207,14 @@ try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame-try-runtime/try-runtime",
"pallet-assets/try-runtime",
"pallet-aura/try-runtime",
"pallet-authorship/try-runtime",
"pallet-balances/try-runtime",
"pallet-collator-selection/try-runtime",
"pallet-message-queue/try-runtime",
"pallet-multisig/try-runtime",
"pallet-nfts/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
"pallet-revive/try-runtime",
Expand Down
55 changes: 51 additions & 4 deletions runtime/mainnet/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use codec::Encode;
use frame_support::{
genesis_builder_helper::{build_state, get_preset},
traits::tokens::{Fortitude::Polite, Preservation::Preserve},
traits::{
nonfungibles_v2::Inspect,
tokens::{Fortitude::Polite, Preservation::Preserve},
},
weights::{Weight, WeightToFee as _},
};
use pallet_revive::AddressMapper;
Expand All @@ -30,9 +33,9 @@
use super::{
config::{monetary::fee::WeightToFee, system::RuntimeBlockWeights, xcm as xcm_config},
AccountId, Balance, Balances, Block, BlockNumber, BlockWeights, EventRecord, Executive,
ExtrinsicInclusionMode, InherentDataExt, Nonce, OriginCaller, ParachainSystem, PolkadotXcm,
Revive, Runtime, RuntimeCall, RuntimeEvent, RuntimeGenesisConfig, RuntimeOrigin, SessionKeys,
System, TransactionPayment, UncheckedExtrinsic, VERSION,
ExtrinsicInclusionMode, InherentDataExt, Nfts, Nonce, OriginCaller, ParachainSystem,
PolkadotXcm, Revive, Runtime, RuntimeCall, RuntimeEvent, RuntimeGenesisConfig, RuntimeOrigin,
SessionKeys, System, TransactionPayment, UncheckedExtrinsic, VERSION,
};

impl_runtime_apis! {
Expand Down Expand Up @@ -189,6 +192,50 @@
}
}

impl pallet_nfts_runtime_api::NftsApi<Block, AccountId, u32, u32> for Runtime {
fn owner(collection: u32, item: u32) -> Option<AccountId> {
<Nfts as Inspect<AccountId>>::owner(&collection, &item)
}

fn collection_owner(collection: u32) -> Option<AccountId> {
<Nfts as Inspect<AccountId>>::collection_owner(&collection)
}

fn attribute(
collection: u32,
item: u32,
key: Vec<u8>,
) -> Option<Vec<u8>> {
<Nfts as Inspect<AccountId>>::attribute(&collection, &item, &key)
}

fn custom_attribute(
account: AccountId,
collection: u32,
item: u32,
key: Vec<u8>,
) -> Option<Vec<u8>> {
<Nfts as Inspect<AccountId>>::custom_attribute(
&account,
&collection,
&item,
&key,
)
}

fn system_attribute(
collection: u32,
item: Option<u32>,
key: Vec<u8>,
) -> Option<Vec<u8>> {
<Nfts as Inspect<AccountId>>::system_attribute(&collection, item.as_ref(), &key)
}

fn collection_attribute(collection: u32, key: Vec<u8>) -> Option<Vec<u8>> {
<Nfts as Inspect<AccountId>>::collection_attribute(&collection, &key)
}
}

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
Expand Down Expand Up @@ -236,7 +283,7 @@

use frame_system_benchmarking::Pallet as SystemBench;

impl frame_system_benchmarking::Config for Runtime {

Check warning on line 286 in runtime/mainnet/src/apis.rs

View workflow job for this annotation

GitHub Actions / clippy

non-local `impl` definition, `impl` blocks should be written at the same level as their item

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item --> runtime/mainnet/src/apis.rs:286:4 | 278 | / fn dispatch_benchmark( 279 | | config: frame_benchmarking::BenchmarkConfig 280 | | ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> { | |___________________________________________________________________________________- move the `impl` block outside of this associated function `dispatch_benchmark` ... 286 | impl frame_system_benchmarking::Config for Runtime { | ^^^^^---------------------------------^^^^^------- | | | | | `Runtime` is not local | `Config` is not local | = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` = note: `#[warn(non_local_definitions)]` on by default
fn setup_set_code_requirements(code: &Vec<u8>) -> Result<(), BenchmarkError> {
ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32);
Ok(())
Expand Down
Loading
Loading