Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
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,147 +1,77 @@
#![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;

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

#[docify::export]
mod block_times {
/// This determines the average expected block time that we are targeting.
/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.
/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked
/// up by `pallet_aura` to implement `fn slot_duration()`.
///
/// Change this to adjust the block time.
pub const MILLISECS_PER_BLOCK: u64 = 6000;
/// The duration of a slot.
// NOTE: Currently it is not possible to change the slot duration after the chain has started.
// Attempting to do so will brick block production.
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
}
pub use block_times::*;

// Time is measured by number of blocks.
/// A minute, measured by number of blocks.
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
/// An hour, measured by number of blocks.
pub const HOURS: BlockNumber = MINUTES * 60;
/// A day, measured by number of blocks.
pub const DAYS: BlockNumber = HOURS * 24;

/// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is
/// used to limit the maximal weight of a single extrinsic.
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);

/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by
/// `Operational` extrinsics.
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);

/// We allow for 2 seconds of compute with a 6-second average block.
#[docify::export(max_block_weight)]
pub const MAXIMUM_BLOCK_WEIGHT: Weight =
Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), MAX_POV_SIZE as u64);

/// A unit of the native asset.
pub const UNIT: Balance = 10_000_000_000; // 10 decimals
/// A milli-unit of the native asset.
pub const MILLI_UNIT: Balance = UNIT / 1_000; // 10_000_000
/// A micro-unit of the native asset.
pub const MICRO_UNIT: Balance = UNIT / 1_000_000; // 10_000

/// Deposits.
pub const fn deposit(items: u32, bytes: u32) -> Balance {
(items as Balance * UNIT + (bytes as Balance) * (5 * MILLI_UNIT / 100)) / 10
}
/// The existential deposit. Set to 1/1_000 of the Connected Relay Chain.
pub const EXISTENTIAL_DEPOSIT: Balance = MILLI_UNIT;

#[docify::export]
mod async_backing_params {
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
/// into the relay chain.
pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3;
/// How many parachain blocks are processed by the relay chain per parent. Limits the
/// number of blocks authored per slot.
pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;
/// Relay chain slot duration, in milliseconds.
// Value is 6000 millisecs. If `MILLISECS_PER_BLOCK` changes this needs addressing.
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,
}
}
}
}
74 changes: 74 additions & 0 deletions runtime/common/src/proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/// 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,
/// Smart contract proxy. Can execute calls related to smart contract management.
SmartContract,
}
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,
}
}
}
6 changes: 6 additions & 0 deletions runtime/devnet/src/config/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
RuntimeCall::Utility { .. } |
RuntimeCall::Multisig { .. }
),
ProxyType::SmartContract => matches!(
c,
RuntimeCall::Contracts { .. } |
RuntimeCall::Utility { .. } |
RuntimeCall::Multisig { .. }
),
}
}

Expand Down
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
Loading
Loading