Skip to content

feat(nfts + nonfungibles): sync polkadot stable2503 #558

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

Open
wants to merge 19 commits into
base: al3mart/sync-polkadot-stable2503
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
326 changes: 163 additions & 163 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pallets/api/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ type NftsInstance = pallet_nfts::Instance1;
impl pallet_nfts::Config<NftsInstance> for Test {
type ApprovalsLimit = ConstU32<10>;
type AttributeDepositBase = ConstU128<1>;
type BlockNumberProvider = frame_system::Pallet<Test>;
type CollectionApprovalDeposit = ConstU128<1>;
type CollectionBalanceDeposit = ConstU128<1>;
type CollectionDeposit = ConstU128<2>;
Expand Down
4 changes: 2 additions & 2 deletions pallets/api/src/nonfungibles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
dispatch::WithPostDispatchInfo,
traits::{nonfungibles_v2::Inspect, Currency},
};
use frame_system::pallet_prelude::BlockNumberFor;
pub use pallet::*;
use pallet_nfts::WeightInfo as NftsWeightInfoTrait;
pub use pallet_nfts::{
Expand All @@ -26,6 +25,7 @@
/// Weights for non-fungibles dispatchables.
pub mod weights;

type BlockNumberFor<T> = pallet_nfts::BlockNumberFor<T, NftsInstanceOf<T>>;
type AccountBalanceOf<T> = pallet_nfts::AccountBalance<T, NftsInstanceOf<T>>;
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
Expand Down Expand Up @@ -55,7 +55,7 @@
pallet_prelude::*,
traits::Incrementable,
};
use frame_system::pallet_prelude::*;
use frame_system::{ensure_signed, pallet_prelude::OriginFor};
use sp_runtime::BoundedVec;

use super::*;
Expand Down Expand Up @@ -149,7 +149,7 @@
.max(NftsWeightInfoOf::<T>::cancel_approval())
.max(NftsWeightInfoOf::<T>::cancel_collection_approval()))
]
pub fn approve(

Check warning on line 152 in pallets/api/src/nonfungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `frame_support::dispatch::PostDispatchInfo`

warning: useless conversion to the same type: `frame_support::dispatch::PostDispatchInfo` --> pallets/api/src/nonfungibles/mod.rs:152:17 | 152 | pub fn approve( | ^ help: consider removing | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion

Check warning on line 152 in pallets/api/src/nonfungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `sp_runtime::DispatchErrorWithPostInfo<frame_support::dispatch::PostDispatchInfo>`

warning: useless conversion to the same type: `sp_runtime::DispatchErrorWithPostInfo<frame_support::dispatch::PostDispatchInfo>` --> pallets/api/src/nonfungibles/mod.rs:152:17 | 152 | pub fn approve( | ^ help: consider removing | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
origin: OriginFor<T>,
collection: CollectionIdOf<T>,
operator: AccountIdOf<T>,
Expand Down Expand Up @@ -230,7 +230,7 @@
witness.item_configs,
witness.attributes,
))]
pub fn destroy(

Check warning on line 233 in pallets/api/src/nonfungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `frame_support::dispatch::PostDispatchInfo`

warning: useless conversion to the same type: `frame_support::dispatch::PostDispatchInfo` --> pallets/api/src/nonfungibles/mod.rs:233:17 | 233 | pub fn destroy( | ^ help: consider removing | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion

Check warning on line 233 in pallets/api/src/nonfungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `sp_runtime::DispatchErrorWithPostInfo<frame_support::dispatch::PostDispatchInfo>`

warning: useless conversion to the same type: `sp_runtime::DispatchErrorWithPostInfo<frame_support::dispatch::PostDispatchInfo>` --> pallets/api/src/nonfungibles/mod.rs:233:17 | 233 | pub fn destroy( | ^ help: consider removing | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
origin: OriginFor<T>,
collection: CollectionIdOf<T>,
witness: DestroyWitness,
Expand Down Expand Up @@ -425,7 +425,7 @@
/// - `limit` - The number of collection approvals that will be cleared.
#[pallet::call_index(19)]
#[pallet::weight(NftsWeightInfoOf::<T>::clear_collection_approvals(*limit))]
pub fn clear_collection_approvals(

Check warning on line 428 in pallets/api/src/nonfungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `frame_support::dispatch::PostDispatchInfo`

warning: useless conversion to the same type: `frame_support::dispatch::PostDispatchInfo` --> pallets/api/src/nonfungibles/mod.rs:428:36 | 428 | pub fn clear_collection_approvals( | ^ help: consider removing | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion

Check warning on line 428 in pallets/api/src/nonfungibles/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `sp_runtime::DispatchErrorWithPostInfo<frame_support::dispatch::PostDispatchInfo>`

warning: useless conversion to the same type: `sp_runtime::DispatchErrorWithPostInfo<frame_support::dispatch::PostDispatchInfo>` --> pallets/api/src/nonfungibles/mod.rs:428:36 | 428 | pub fn clear_collection_approvals( | ^ help: consider removing | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
origin: OriginFor<T>,
collection: CollectionIdOf<T>,
limit: u32,
Expand Down
20 changes: 11 additions & 9 deletions pallets/api/src/nonfungibles/weights.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@

//! Autogenerated weights for `nonfungibles`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 45.0.0
//! DATE: 2025-01-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 47.0.0
//! DATE: 2025-05-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `R0GUE`, CPU: `<UNKNOWN>`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("pop-devnet-dev")`, DB CACHE: `1024`

// Executed Command:
// ./target/production/pop-node
// benchmark
// pallet
// --chain=dev
// --wasm-execution=compiled
// --pallet=nonfungibles
// --chain=pop-devnet-dev
// --steps=50
// --repeat=20
// --json
// --template
// ./scripts/pallet-weights-template.hbs
// --pallet=nonfungibles
// --no-storage-info
// --no-median-slopes
// --no-min-squares
// --wasm-execution=compiled
// --heap-pages=4096
// --output=./pallets/api/src/nonfungibles/weights.rs
// --template=./scripts/templates/pallet-weight-template.hbs
// --extrinsic=

#![cfg_attr(rustfmt, rustfmt_skip)]
Expand Down
2 changes: 1 addition & 1 deletion pallets/nfts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license.workspace = true
name = "pallet-nfts"
readme = "README.md"
repository.workspace = true
version = "31.0.0"
version = "34.1.0"

[package.metadata.docs.rs]
targets = [ "x86_64-unknown-linux-gnu" ]
Expand Down
3 changes: 1 addition & 2 deletions pallets/nfts/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ targets = [ "x86_64-unknown-linux-gnu" ]

[dependencies]
codec = { features = [ "derive" ], workspace = true }
pallet-nfts.workspace = true
sp-api.workspace = true

[features]
default = [ "std" ]
std = [ "codec/std", "pallet-nfts/std", "sp-api/std" ]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std = [ "codec/std", "sp-api/std" ]
24 changes: 12 additions & 12 deletions pallets/nfts/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use frame_support::{
traits::{EnsureOrigin, Get, UnfilteredDispatchable},
BoundedVec,
};
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin as SystemOrigin};
use sp_runtime::traits::{Bounded, One};
use frame_system::RawOrigin as SystemOrigin;
use sp_runtime::traits::{Bounded, One, Zero};

use super::*;
use crate::Pallet as Nfts;
Expand Down Expand Up @@ -579,7 +579,7 @@ benchmarks_instance_pallet! {
let (item, ..) = mint_item::<T, I>(0);
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let deadline = BlockNumberFor::<T>::max_value();
let deadline = BlockNumberFor::<T, I>::max_value();
}: _(SystemOrigin::Signed(caller.clone()), collection, item, delegate_lookup, Some(deadline))
verify {
assert_last_event::<T, I>(Event::TransferApproved { collection, item: Some(item), owner: caller, delegate, deadline: Some(deadline) }.into());
Expand All @@ -591,7 +591,7 @@ benchmarks_instance_pallet! {
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let origin = SystemOrigin::Signed(caller.clone()).into();
let deadline = BlockNumberFor::<T>::max_value();
let deadline = BlockNumberFor::<T, I>::max_value();
Nfts::<T, I>::approve_transfer(origin, collection, item, delegate_lookup.clone(), Some(deadline))?;
}: _(SystemOrigin::Signed(caller.clone()), collection, item, delegate_lookup)
verify {
Expand All @@ -604,7 +604,7 @@ benchmarks_instance_pallet! {
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let origin = SystemOrigin::Signed(caller.clone()).into();
let deadline = BlockNumberFor::<T>::max_value();
let deadline = BlockNumberFor::<T, I>::max_value();
Nfts::<T, I>::approve_transfer(origin, collection, item, delegate_lookup.clone(), Some(deadline))?;
}: _(SystemOrigin::Signed(caller.clone()), collection, item)
verify {
Expand Down Expand Up @@ -717,7 +717,7 @@ benchmarks_instance_pallet! {
frame_system::Pallet::<T>::set_block_number(One::one());
}: _(SystemOrigin::Signed(caller.clone()), collection, item1, collection, Some(item2), Some(price_with_direction.clone()), duration)
verify {
let current_block = frame_system::Pallet::<T>::block_number();
let current_block = T::BlockNumberProvider::current_block_number();
assert_last_event::<T, I>(Event::SwapCreated {
offered_collection: collection,
offered_item: item1,
Expand Down Expand Up @@ -885,7 +885,7 @@ benchmarks_instance_pallet! {
mint_item::<T, I>(0);
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let deadline = BlockNumberFor::<T>::max_value();
let deadline = BlockNumberFor::<T, I>::max_value();
}: _(SystemOrigin::Signed(caller.clone()), collection, delegate_lookup, Some(deadline))
verify {
assert_last_event::<T, I>(Event::TransferApproved { collection, item: None, owner: caller, delegate, deadline: Some(deadline) }.into());
Expand All @@ -896,7 +896,7 @@ benchmarks_instance_pallet! {
mint_item::<T, I>(0);
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let deadline = BlockNumberFor::<T>::max_value();
let deadline = BlockNumberFor::<T, I>::max_value();
}: _(SystemOrigin::Root, caller_lookup, collection, delegate_lookup, Some(deadline))
verify {
assert_last_event::<T, I>(Event::TransferApproved { collection, item: None, owner: caller, delegate, deadline: Some(deadline) }.into());
Expand All @@ -908,7 +908,7 @@ benchmarks_instance_pallet! {
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let origin = SystemOrigin::Signed(caller.clone()).into();
let deadline = BlockNumberFor::<T>::max_value();
let deadline = BlockNumberFor::<T, I>::max_value();
Nfts::<T, I>::approve_collection_transfer(origin, collection, delegate_lookup.clone(), Some(deadline))?;
}: _(SystemOrigin::Signed(caller.clone()), collection, delegate_lookup)
verify {
Expand All @@ -920,7 +920,7 @@ benchmarks_instance_pallet! {
mint_item::<T, I>(0);
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let deadline = BlockNumberFor::<T>::max_value();
let deadline = BlockNumberFor::<T, I>::max_value();
Nfts::<T, I>::approve_collection_transfer(SystemOrigin::Signed(caller.clone()).into(), collection, delegate_lookup.clone(), Some(deadline))?;
}: _(SystemOrigin::Root, caller_lookup, collection, delegate_lookup)
verify {
Expand All @@ -937,7 +937,7 @@ benchmarks_instance_pallet! {
SystemOrigin::Signed(caller.clone()).into(),
collection,
T::Lookup::unlookup(delegate),
Some(BlockNumberFor::<T>::max_value()),
Some(BlockNumberFor::<T, I>::max_value()),
)?;
}
}: _(SystemOrigin::Signed(caller.clone()), collection, n)
Expand All @@ -956,7 +956,7 @@ benchmarks_instance_pallet! {
SystemOrigin::Signed(caller.clone()).into(),
collection,
T::Lookup::unlookup(delegate),
Some(BlockNumberFor::<T>::max_value()),
Some(BlockNumberFor::<T, I>::max_value()),
)?;
}
}: _(SystemOrigin::Root, caller_lookup, collection, n)
Expand Down
19 changes: 9 additions & 10 deletions pallets/nfts/src/features/approvals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//! to have the functionality defined in this module.

use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::BlockNumberFor;

use crate::*;

Expand Down Expand Up @@ -48,7 +47,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
collection: T::CollectionId,
item: T::ItemId,
delegate: T::AccountId,
maybe_deadline: Option<BlockNumberFor<T>>,
maybe_deadline: Option<BlockNumberFor<T, I>>,
) -> DispatchResult {
ensure!(
Self::is_pallet_feature_enabled(PalletFeature::Approvals),
Expand All @@ -66,8 +65,8 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
ensure!(check_origin == details.owner, Error::<T, I>::NoPermission);
}

let deadline =
maybe_deadline.map(|d| d.saturating_add(frame_system::Pallet::<T>::block_number()));
let now = T::BlockNumberProvider::current_block_number();
let deadline = maybe_deadline.map(|d| d.saturating_add(now));

details
.approvals
Expand Down Expand Up @@ -110,7 +109,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
let maybe_deadline = details.approvals.get(&delegate).ok_or(Error::<T, I>::NotDelegate)?;

let is_past_deadline = if let Some(deadline) = maybe_deadline {
let now = frame_system::Pallet::<T>::block_number();
let now = T::BlockNumberProvider::current_block_number();
now > *deadline
} else {
false
Expand Down Expand Up @@ -212,7 +211,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
collection: T::CollectionId,
delegate: T::AccountId,
deposit: DepositBalanceOf<T, I>,
maybe_deadline: Option<BlockNumberFor<T>>,
maybe_deadline: Option<BlockNumberFor<T, I>>,
) -> DispatchResult {
ensure!(
Self::is_pallet_feature_enabled(PalletFeature::Approvals),
Expand All @@ -230,8 +229,8 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
collection_config.is_setting_enabled(CollectionSetting::TransferableItems),
Error::<T, I>::ItemsNonTransferable
);
let deadline =
maybe_deadline.map(|d| d.saturating_add(frame_system::Pallet::<T>::block_number()));
let now = T::BlockNumberProvider::current_block_number();
let deadline = maybe_deadline.map(|d| d.saturating_add(now));

CollectionApprovals::<T, I>::try_mutate_exists(
(&collection, &owner, &delegate),
Expand Down Expand Up @@ -330,7 +329,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
CollectionApprovals::<T, I>::get((&collection, &owner, &delegate))
.ok_or(Error::<T, I>::NoPermission)?;
if let Some(deadline) = maybe_deadline {
let block_number = frame_system::Pallet::<T>::block_number();
let block_number = T::BlockNumberProvider::current_block_number();
ensure!(block_number <= deadline, Error::<T, I>::ApprovalExpired);
}
Ok(())
Expand Down Expand Up @@ -365,7 +364,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
let maybe_deadline =
details.approvals.get(delegate).ok_or(Error::<T, I>::NoPermission)?;
if let Some(deadline) = maybe_deadline {
let block_number = frame_system::Pallet::<T>::block_number();
let block_number = T::BlockNumberProvider::current_block_number();
ensure!(block_number <= *deadline, Error::<T, I>::ApprovalExpired);
}
return Ok(());
Expand Down
9 changes: 5 additions & 4 deletions pallets/nfts/src/features/atomic_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
desired_collection_id: T::CollectionId,
maybe_desired_item_id: Option<T::ItemId>,
maybe_price: Option<PriceWithDirection<ItemPrice<T, I>>>,
duration: frame_system::pallet_prelude::BlockNumberFor<T>,
duration: BlockNumberFor<T, I>,
) -> DispatchResult {
ensure!(
Self::is_pallet_feature_enabled(PalletFeature::Swaps),
Expand All @@ -77,7 +77,8 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
),
};

let deadline = duration.saturating_add(frame_system::Pallet::<T>::block_number());
let now = T::BlockNumberProvider::current_block_number();
let deadline = duration.saturating_add(now);

PendingSwapOf::<T, I>::insert(
offered_collection_id,
Expand Down Expand Up @@ -120,7 +121,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
let swap = PendingSwapOf::<T, I>::get(offered_collection_id, offered_item_id)
.ok_or(Error::<T, I>::UnknownSwap)?;

let now = frame_system::Pallet::<T>::block_number();
let now = T::BlockNumberProvider::current_block_number();
if swap.deadline > now {
let item = Item::<T, I>::get(offered_collection_id, offered_item_id)
.ok_or(Error::<T, I>::UnknownItem)?;
Expand Down Expand Up @@ -188,7 +189,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
ensure!(desired_item == send_item_id, Error::<T, I>::UnknownSwap);
}

let now = frame_system::Pallet::<T>::block_number();
let now = T::BlockNumberProvider::current_block_number();
ensure!(now <= swap.deadline, Error::<T, I>::DeadlineExpired);

if let Some(ref price) = swap.price {
Expand Down
2 changes: 1 addition & 1 deletion pallets/nfts/src/features/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Error::<T, I>::MaxAttributesLimitReached
);

let now = frame_system::Pallet::<T>::block_number();
let now = T::BlockNumberProvider::current_block_number();
ensure!(deadline >= now, Error::<T, I>::DeadlineExpired);

let item_details = Item::<T, I>::get(collection, item).ok_or(Error::<T, I>::UnknownItem)?;
Expand Down
2 changes: 1 addition & 1 deletion pallets/nfts/src/features/create_delete_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
ensure!(account == mint_to, Error::<T, I>::WrongOrigin);
}

let now = frame_system::Pallet::<T>::block_number();
let now = T::BlockNumberProvider::current_block_number();
ensure!(deadline >= now, Error::<T, I>::DeadlineExpired);

ensure!(
Expand Down
6 changes: 1 addition & 5 deletions pallets/nfts/src/features/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
pub(crate) fn do_update_mint_settings(
maybe_check_origin: Option<T::AccountId>,
collection: T::CollectionId,
mint_settings: MintSettings<
BalanceOf<T, I>,
frame_system::pallet_prelude::BlockNumberFor<T>,
T::CollectionId,
>,
mint_settings: MintSettings<BalanceOf<T, I>, BlockNumberFor<T, I>, T::CollectionId>,
) -> DispatchResult {
if let Some(check_origin) = &maybe_check_origin {
ensure!(
Expand Down
Loading
Loading