Buy&Sell methods for Uniques (#11398)

* Allow to set item's price

* Clean the state when we transfer/burn an item or destroy a collection

* Allow to buy an item

* Remove redundant checks

* Improve events

* Cover with tests

* Add comments

* Apply suggestions

* Fmt

* Improvements for price validation

* Improve validation

* Update to use the new terminology

* Remove multi-assets support

* Chore

* Weights + benchmarking

* Shield against human error

* Test when we pass the higher item's price

* fmt fix

* Chore

* cargo run --quiet --profile=production  --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=pallet_uniques --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/uniques/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* Remove is_frozen check when setting the price

* Try to fix benchmarking

* Fix benchmarking

* cargo run --quiet --profile=production  --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=pallet_uniques --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/uniques/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* Add transactional

* Add 'allow deprecated' flag for transactional

* Remove #[allow(deprecated)]

* ".git/.scripts/bench-bot.sh" pallet dev pallet_uniques

Co-authored-by: Parity Bot <admin@parity.io>
Co-authored-by: command-bot <>
This commit is contained in:
Jegor Sidorenko
2022-07-13 13:41:20 +01:00
committed by GitHub
parent 3ea6a88eba
commit 5d96c0a0ea
6 changed files with 485 additions and 72 deletions
@@ -408,5 +408,41 @@ benchmarks_instance_pallet! {
}.into());
}
set_price {
let (collection, caller, _) = create_collection::<T, I>();
let (item, ..) = mint_item::<T, I>(0);
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let price = ItemPrice::<T, I>::from(100u32);
}: _(SystemOrigin::Signed(caller.clone()), collection, item, Some(price), Some(delegate_lookup))
verify {
assert_last_event::<T, I>(Event::ItemPriceSet {
collection,
item,
price,
whitelisted_buyer: Some(delegate),
}.into());
}
buy_item {
let (collection, seller, _) = create_collection::<T, I>();
let (item, ..) = mint_item::<T, I>(0);
let buyer: T::AccountId = account("buyer", 0, SEED);
let buyer_lookup = T::Lookup::unlookup(buyer.clone());
let price = ItemPrice::<T, I>::from(0u32);
let origin = SystemOrigin::Signed(seller.clone()).into();
Uniques::<T, I>::set_price(origin, collection, item, Some(price.clone()), Some(buyer_lookup))?;
T::Currency::make_free_balance_be(&buyer, DepositBalanceOf::<T, I>::max_value());
}: _(SystemOrigin::Signed(buyer.clone()), collection, item, price.clone())
verify {
assert_last_event::<T, I>(Event::ItemBought {
collection,
item,
price,
seller,
buyer,
}.into());
}
impl_benchmark_test_suite!(Uniques, crate::mock::new_test_ext(), crate::mock::Test);
}
+78 -1
View File
@@ -18,7 +18,10 @@
//! Various pieces of common functionality.
use super::*;
use frame_support::{ensure, traits::Get};
use frame_support::{
ensure,
traits::{ExistenceRequirement, Get},
};
use sp_runtime::{DispatchError, DispatchResult};
impl<T: Config<I>, I: 'static> Pallet<T, I> {
@@ -46,6 +49,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
let origin = details.owner;
details.owner = dest;
Item::<T, I>::insert(&collection, &item, &details);
ItemPriceOf::<T, I>::remove(&collection, &item);
Self::deposit_event(Event::Transferred {
collection,
@@ -112,6 +116,8 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}
#[allow(deprecated)]
ItemMetadataOf::<T, I>::remove_prefix(&collection, None);
#[allow(deprecated)]
ItemPriceOf::<T, I>::remove_prefix(&collection, None);
CollectionMetadataOf::<T, I>::remove(&collection);
#[allow(deprecated)]
Attribute::<T, I>::remove_prefix((&collection,), None);
@@ -196,8 +202,79 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Item::<T, I>::remove(&collection, &item);
Account::<T, I>::remove((&owner, &collection, &item));
ItemPriceOf::<T, I>::remove(&collection, &item);
Self::deposit_event(Event::Burned { collection, item, owner });
Ok(())
}
pub fn do_set_price(
collection: T::CollectionId,
item: T::ItemId,
sender: T::AccountId,
price: Option<ItemPrice<T, I>>,
whitelisted_buyer: Option<T::AccountId>,
) -> DispatchResult {
let details = Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?;
ensure!(details.owner == sender, Error::<T, I>::NoPermission);
if let Some(ref price) = price {
ItemPriceOf::<T, I>::insert(
&collection,
&item,
(price.clone(), whitelisted_buyer.clone()),
);
Self::deposit_event(Event::ItemPriceSet {
collection,
item,
price: price.clone(),
whitelisted_buyer,
});
} else {
ItemPriceOf::<T, I>::remove(&collection, &item);
Self::deposit_event(Event::ItemPriceRemoved { collection, item });
}
Ok(())
}
pub fn do_buy_item(
collection: T::CollectionId,
item: T::ItemId,
buyer: T::AccountId,
bid_price: ItemPrice<T, I>,
) -> DispatchResult {
let details = Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?;
ensure!(details.owner != buyer, Error::<T, I>::NoPermission);
let price_info =
ItemPriceOf::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::NotForSale)?;
ensure!(bid_price >= price_info.0, Error::<T, I>::BidTooLow);
if let Some(only_buyer) = price_info.1 {
ensure!(only_buyer == buyer, Error::<T, I>::NoPermission);
}
T::Currency::transfer(
&buyer,
&details.owner,
price_info.0,
ExistenceRequirement::KeepAlive,
)?;
let old_owner = details.owner.clone();
Self::do_transfer(collection, item, buyer.clone(), |_, _| Ok(()))?;
Self::deposit_event(Event::ItemBought {
collection,
item,
price: price_info.0,
seller: old_owner,
buyer,
});
Ok(())
}
}
+86 -2
View File
@@ -24,6 +24,7 @@
//! * [`System`](../frame_system/index.html)
//! * [`Support`](../frame_support/index.html)
#![recursion_limit = "256"]
// Ensure we're `no_std` when compiling for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]
@@ -42,8 +43,11 @@ pub mod migration;
pub mod weights;
use codec::{Decode, Encode};
use frame_support::traits::{
tokens::Locker, BalanceStatus::Reserved, Currency, EnsureOriginWithArg, ReservableCurrency,
use frame_support::{
traits::{
tokens::Locker, BalanceStatus::Reserved, Currency, EnsureOriginWithArg, ReservableCurrency,
},
transactional,
};
use frame_system::Config as SystemConfig;
use sp_runtime::{
@@ -245,6 +249,18 @@ pub mod pallet {
OptionQuery,
>;
#[pallet::storage]
/// Price of an asset instance.
pub(super) type ItemPriceOf<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
_,
Blake2_128Concat,
T::CollectionId,
Blake2_128Concat,
T::ItemId,
(ItemPrice<T, I>, Option<T::AccountId>),
OptionQuery,
>;
#[pallet::storage]
/// Keeps track of the number of items a collection might have.
pub(super) type CollectionMaxSupply<T: Config<I>, I: 'static = ()> =
@@ -341,6 +357,23 @@ pub mod pallet {
OwnershipAcceptanceChanged { who: T::AccountId, maybe_collection: Option<T::CollectionId> },
/// Max supply has been set for a collection.
CollectionMaxSupplySet { collection: T::CollectionId, max_supply: u32 },
/// The price was set for the instance.
ItemPriceSet {
collection: T::CollectionId,
item: T::ItemId,
price: ItemPrice<T, I>,
whitelisted_buyer: Option<T::AccountId>,
},
/// The price for the instance was removed.
ItemPriceRemoved { collection: T::CollectionId, item: T::ItemId },
/// An item was bought.
ItemBought {
collection: T::CollectionId,
item: T::ItemId,
price: ItemPrice<T, I>,
seller: T::AccountId,
buyer: T::AccountId,
},
}
#[pallet::error]
@@ -375,6 +408,12 @@ pub mod pallet {
MaxSupplyAlreadySet,
/// The provided max supply is less to the amount of items a collection already has.
MaxSupplyTooSmall,
/// The given item ID is unknown.
UnknownItem,
/// Item is not for sale.
NotForSale,
/// The provided bid is too low.
BidTooLow,
}
impl<T: Config<I>, I: 'static> Pallet<T, I> {
@@ -1408,5 +1447,50 @@ pub mod pallet {
Self::deposit_event(Event::CollectionMaxSupplySet { collection, max_supply });
Ok(())
}
/// Set (or reset) the price for an item.
///
/// Origin must be Signed and must be the owner of the asset `item`.
///
/// - `collection`: The collection of the item.
/// - `item`: The item to set the price for.
/// - `price`: The price for the item. Pass `None`, to reset the price.
/// - `buyer`: Restricts the buy operation to a specific account.
///
/// Emits `ItemPriceSet` on success if the price is not `None`.
/// Emits `ItemPriceRemoved` on success if the price is `None`.
#[pallet::weight(T::WeightInfo::set_price())]
pub fn set_price(
origin: OriginFor<T>,
collection: T::CollectionId,
item: T::ItemId,
price: Option<ItemPrice<T, I>>,
whitelisted_buyer: Option<<T::Lookup as StaticLookup>::Source>,
) -> DispatchResult {
let origin = ensure_signed(origin)?;
let whitelisted_buyer = whitelisted_buyer.map(T::Lookup::lookup).transpose()?;
Self::do_set_price(collection, item, origin, price, whitelisted_buyer)
}
/// Allows to buy an item if it's up for sale.
///
/// Origin must be Signed and must not be the owner of the `item`.
///
/// - `collection`: The collection of the item.
/// - `item`: The item the sender wants to buy.
/// - `bid_price`: The price the sender is willing to pay.
///
/// Emits `ItemBought` on success.
#[pallet::weight(T::WeightInfo::buy_item())]
#[transactional]
pub fn buy_item(
origin: OriginFor<T>,
collection: T::CollectionId,
item: T::ItemId,
bid_price: ItemPrice<T, I>,
) -> DispatchResult {
let origin = ensure_signed(origin)?;
Self::do_buy_item(collection, item, origin, bid_price)
}
}
}
+177 -1
View File
@@ -18,7 +18,7 @@
//! Tests for Uniques pallet.
use crate::{mock::*, Event, *};
use frame_support::{assert_noop, assert_ok, traits::Currency};
use frame_support::{assert_noop, assert_ok, dispatch::Dispatchable, traits::Currency};
use pallet_balances::Error as BalancesError;
use sp_std::prelude::*;
@@ -694,3 +694,179 @@ fn max_supply_should_work() {
assert!(!CollectionMaxSupply::<Test>::contains_key(collection_id));
});
}
#[test]
fn set_price_should_work() {
new_test_ext().execute_with(|| {
let user_id = 1;
let collection_id = 0;
let item_1 = 1;
let item_2 = 2;
assert_ok!(Uniques::force_create(Origin::root(), collection_id, user_id, true));
assert_ok!(Uniques::mint(Origin::signed(user_id), collection_id, item_1, user_id));
assert_ok!(Uniques::mint(Origin::signed(user_id), collection_id, item_2, user_id));
assert_ok!(Uniques::set_price(
Origin::signed(user_id),
collection_id,
item_1,
Some(1),
None,
));
assert_ok!(Uniques::set_price(
Origin::signed(user_id),
collection_id,
item_2,
Some(2),
Some(3)
));
let item = ItemPriceOf::<Test>::get(collection_id, item_1).unwrap();
assert_eq!(item.0, 1);
assert_eq!(item.1, None);
let item = ItemPriceOf::<Test>::get(collection_id, item_2).unwrap();
assert_eq!(item.0, 2);
assert_eq!(item.1, Some(3));
assert!(events().contains(&Event::<Test>::ItemPriceSet {
collection: collection_id,
item: item_1,
price: 1,
whitelisted_buyer: None,
}));
// validate we can unset the price
assert_ok!(Uniques::set_price(Origin::signed(user_id), collection_id, item_2, None, None));
assert!(events().contains(&Event::<Test>::ItemPriceRemoved {
collection: collection_id,
item: item_2
}));
assert!(!ItemPriceOf::<Test>::contains_key(collection_id, item_2));
});
}
#[test]
fn buy_item_should_work() {
new_test_ext().execute_with(|| {
let user_1 = 1;
let user_2 = 2;
let user_3 = 3;
let collection_id = 0;
let item_1 = 1;
let item_2 = 2;
let item_3 = 3;
let price_1 = 20;
let price_2 = 30;
let initial_balance = 100;
Balances::make_free_balance_be(&user_1, initial_balance);
Balances::make_free_balance_be(&user_2, initial_balance);
Balances::make_free_balance_be(&user_3, initial_balance);
assert_ok!(Uniques::force_create(Origin::root(), collection_id, user_1, true));
assert_ok!(Uniques::mint(Origin::signed(user_1), collection_id, item_1, user_1));
assert_ok!(Uniques::mint(Origin::signed(user_1), collection_id, item_2, user_1));
assert_ok!(Uniques::mint(Origin::signed(user_1), collection_id, item_3, user_1));
assert_ok!(Uniques::set_price(
Origin::signed(user_1),
collection_id,
item_1,
Some(price_1),
None,
));
assert_ok!(Uniques::set_price(
Origin::signed(user_1),
collection_id,
item_2,
Some(price_2),
Some(user_3),
));
// can't buy for less
assert_noop!(
Uniques::buy_item(Origin::signed(user_2), collection_id, item_1, 1),
Error::<Test>::BidTooLow
);
// pass the higher price to validate it will still deduct correctly
assert_ok!(Uniques::buy_item(Origin::signed(user_2), collection_id, item_1, price_1 + 1,));
// validate the new owner & balances
let item = Item::<Test>::get(collection_id, item_1).unwrap();
assert_eq!(item.owner, user_2);
assert_eq!(Balances::total_balance(&user_1), initial_balance + price_1);
assert_eq!(Balances::total_balance(&user_2), initial_balance - price_1);
// can't buy from yourself
assert_noop!(
Uniques::buy_item(Origin::signed(user_1), collection_id, item_2, price_2),
Error::<Test>::NoPermission
);
// can't buy when the item is listed for a specific buyer
assert_noop!(
Uniques::buy_item(Origin::signed(user_2), collection_id, item_2, price_2),
Error::<Test>::NoPermission
);
// can buy when I'm a whitelisted buyer
assert_ok!(Uniques::buy_item(Origin::signed(user_3), collection_id, item_2, price_2,));
assert!(events().contains(&Event::<Test>::ItemBought {
collection: collection_id,
item: item_2,
price: price_2,
seller: user_1,
buyer: user_3,
}));
// ensure we reset the buyer field
assert!(!ItemPriceOf::<Test>::contains_key(collection_id, item_2));
// can't buy when item is not for sale
assert_noop!(
Uniques::buy_item(Origin::signed(user_2), collection_id, item_3, price_2),
Error::<Test>::NotForSale
);
// ensure we can't buy an item when the collection or an item is frozen
{
assert_ok!(Uniques::set_price(
Origin::signed(user_1),
collection_id,
item_3,
Some(price_1),
None,
));
// freeze collection
assert_ok!(Uniques::freeze_collection(Origin::signed(user_1), collection_id));
let buy_item_call = mock::Call::Uniques(crate::Call::<Test>::buy_item {
collection: collection_id,
item: item_3,
bid_price: price_1,
});
assert_noop!(buy_item_call.dispatch(Origin::signed(user_2)), Error::<Test>::Frozen);
assert_ok!(Uniques::thaw_collection(Origin::signed(user_1), collection_id));
// freeze item
assert_ok!(Uniques::freeze(Origin::signed(user_1), collection_id, item_3));
let buy_item_call = mock::Call::Uniques(crate::Call::<Test>::buy_item {
collection: collection_id,
item: item_3,
bid_price: price_1,
});
assert_noop!(buy_item_call.dispatch(Origin::signed(user_2)), Error::<Test>::Frozen);
}
});
}
+2
View File
@@ -30,6 +30,8 @@ pub(super) type CollectionDetailsFor<T, I> =
CollectionDetails<<T as SystemConfig>::AccountId, DepositBalanceOf<T, I>>;
pub(super) type ItemDetailsFor<T, I> =
ItemDetails<<T as SystemConfig>::AccountId, DepositBalanceOf<T, I>>;
pub(super) type ItemPrice<T, I = ()> =
<<T as Config<I>>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct CollectionDetails<AccountId, DepositBalance> {
+106 -68
View File
@@ -18,22 +18,22 @@
//! Autogenerated weights for pallet_uniques
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-06-03, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz`
//! DATE: 2022-07-13, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! HOSTNAME: `test-bench-bot`, CPU: `Intel(R) Xeon(R) CPU @ 3.10GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
// Executed Command:
// target/production/substrate
// benchmark
// pallet
// --chain=dev
// --steps=50
// --repeat=20
// --pallet=pallet_uniques
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --pallet=pallet_uniques
// --chain=dev
// --output=./frame/uniques/src/weights.rs
// --template=./.maintain/frame-weight-template.hbs
@@ -70,6 +70,8 @@ pub trait WeightInfo {
fn cancel_approval() -> Weight;
fn set_accept_ownership() -> Weight;
fn set_collection_max_supply() -> Weight;
fn set_price() -> Weight;
fn buy_item() -> Weight;
}
/// Weights for pallet_uniques using the Substrate node and recommended hardware.
@@ -78,14 +80,14 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:1)
fn create() -> Weight {
(27_715_000 as Weight)
(33_075_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:1)
fn force_create() -> Weight {
(16_929_000 as Weight)
(19_528_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
@@ -102,12 +104,12 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// The range of component `a` is `[0, 1000]`.
fn destroy(n: u32, m: u32, a: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 16_000
.saturating_add((10_481_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 16_000
.saturating_add((1_762_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 16_000
.saturating_add((1_590_000 as Weight).saturating_mul(a as Weight))
// Standard Error: 25_000
.saturating_add((13_639_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 25_000
.saturating_add((2_393_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 25_000
.saturating_add((2_217_000 as Weight).saturating_mul(a as Weight))
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(n as Weight)))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
@@ -120,33 +122,35 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques CollectionMaxSupply (r:1 w:0)
// Storage: Uniques Account (r:0 w:1)
fn mint() -> Weight {
(36_577_000 as Weight)
(42_146_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Account (r:0 w:1)
// Storage: Uniques ItemPriceOf (r:0 w:1)
fn burn() -> Weight {
(36_124_000 as Weight)
(42_960_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
// Storage: Uniques Class (r:1 w:0)
// Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Account (r:0 w:2)
// Storage: Uniques ItemPriceOf (r:0 w:1)
fn transfer() -> Weight {
(27_225_000 as Weight)
(33_025_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques Asset (r:100 w:100)
/// The range of component `i` is `[0, 5000]`.
fn redeposit(i: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 14_000
.saturating_add((12_407_000 as Weight).saturating_mul(i as Weight))
// Standard Error: 24_000
.saturating_add((15_540_000 as Weight).saturating_mul(i as Weight))
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
@@ -155,26 +159,26 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Class (r:1 w:0)
fn freeze() -> Weight {
(21_452_000 as Weight)
(25_194_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Class (r:1 w:0)
fn thaw() -> Weight {
(22_155_000 as Weight)
(25_397_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
fn freeze_collection() -> Weight {
(16_897_000 as Weight)
(19_278_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
fn thaw_collection() -> Weight {
(16_657_000 as Weight)
(19_304_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
@@ -182,20 +186,20 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:2)
fn transfer_ownership() -> Weight {
(25_057_000 as Weight)
(28_615_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
fn set_team() -> Weight {
(17_253_000 as Weight)
(19_943_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:1)
fn force_item_status() -> Weight {
(20_010_000 as Weight)
(22_583_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
@@ -203,7 +207,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques InstanceMetadataOf (r:1 w:0)
// Storage: Uniques Attribute (r:1 w:1)
fn set_attribute() -> Weight {
(41_159_000 as Weight)
(47_520_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
@@ -211,65 +215,81 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques InstanceMetadataOf (r:1 w:0)
// Storage: Uniques Attribute (r:1 w:1)
fn clear_attribute() -> Weight {
(39_598_000 as Weight)
(45_316_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques InstanceMetadataOf (r:1 w:1)
fn set_metadata() -> Weight {
(33_387_000 as Weight)
(38_391_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques InstanceMetadataOf (r:1 w:1)
fn clear_metadata() -> Weight {
(33_208_000 as Weight)
(38_023_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassMetadataOf (r:1 w:1)
fn set_collection_metadata() -> Weight {
(32_619_000 as Weight)
(37_398_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Uniques Class (r:1 w:0)
// Storage: Uniques ClassMetadataOf (r:1 w:1)
fn clear_collection_metadata() -> Weight {
(31_028_000 as Weight)
(35_621_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Class (r:1 w:0)
// Storage: Uniques Asset (r:1 w:1)
fn approve_transfer() -> Weight {
(22_263_000 as Weight)
(25_856_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Class (r:1 w:0)
// Storage: Uniques Asset (r:1 w:1)
fn cancel_approval() -> Weight {
(22_910_000 as Weight)
(26_098_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Uniques OwnershipAcceptance (r:1 w:1)
fn set_accept_ownership() -> Weight {
(20_716_000 as Weight)
(24_076_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Uniques CollectionMaxSupply (r:1 w:1)
// Storage: Uniques Class (r:1 w:0)
fn set_collection_max_supply() -> Weight {
(19_380_000 as Weight)
(22_035_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Asset (r:1 w:0)
// Storage: Uniques ItemPriceOf (r:0 w:1)
fn set_price() -> Weight {
(22_534_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques ItemPriceOf (r:1 w:1)
// Storage: Uniques Class (r:1 w:0)
// Storage: Uniques Account (r:0 w:2)
fn buy_item() -> Weight {
(45_272_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
}
// For backwards compatibility and tests
@@ -277,14 +297,14 @@ impl WeightInfo for () {
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:1)
fn create() -> Weight {
(27_715_000 as Weight)
(33_075_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:1)
fn force_create() -> Weight {
(16_929_000 as Weight)
(19_528_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
@@ -301,12 +321,12 @@ impl WeightInfo for () {
/// The range of component `a` is `[0, 1000]`.
fn destroy(n: u32, m: u32, a: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 16_000
.saturating_add((10_481_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 16_000
.saturating_add((1_762_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 16_000
.saturating_add((1_590_000 as Weight).saturating_mul(a as Weight))
// Standard Error: 25_000
.saturating_add((13_639_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 25_000
.saturating_add((2_393_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 25_000
.saturating_add((2_217_000 as Weight).saturating_mul(a as Weight))
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(n as Weight)))
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
@@ -319,33 +339,35 @@ impl WeightInfo for () {
// Storage: Uniques CollectionMaxSupply (r:1 w:0)
// Storage: Uniques Account (r:0 w:1)
fn mint() -> Weight {
(36_577_000 as Weight)
(42_146_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Account (r:0 w:1)
// Storage: Uniques ItemPriceOf (r:0 w:1)
fn burn() -> Weight {
(36_124_000 as Weight)
(42_960_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
}
// Storage: Uniques Class (r:1 w:0)
// Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Account (r:0 w:2)
// Storage: Uniques ItemPriceOf (r:0 w:1)
fn transfer() -> Weight {
(27_225_000 as Weight)
(33_025_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques Asset (r:100 w:100)
/// The range of component `i` is `[0, 5000]`.
fn redeposit(i: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 14_000
.saturating_add((12_407_000 as Weight).saturating_mul(i as Weight))
// Standard Error: 24_000
.saturating_add((15_540_000 as Weight).saturating_mul(i as Weight))
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
@@ -354,26 +376,26 @@ impl WeightInfo for () {
// Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Class (r:1 w:0)
fn freeze() -> Weight {
(21_452_000 as Weight)
(25_194_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Class (r:1 w:0)
fn thaw() -> Weight {
(22_155_000 as Weight)
(25_397_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
fn freeze_collection() -> Weight {
(16_897_000 as Weight)
(19_278_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
fn thaw_collection() -> Weight {
(16_657_000 as Weight)
(19_304_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
@@ -381,20 +403,20 @@ impl WeightInfo for () {
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:2)
fn transfer_ownership() -> Weight {
(25_057_000 as Weight)
(28_615_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
fn set_team() -> Weight {
(17_253_000 as Weight)
(19_943_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:1)
fn force_item_status() -> Weight {
(20_010_000 as Weight)
(22_583_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
@@ -402,7 +424,7 @@ impl WeightInfo for () {
// Storage: Uniques InstanceMetadataOf (r:1 w:0)
// Storage: Uniques Attribute (r:1 w:1)
fn set_attribute() -> Weight {
(41_159_000 as Weight)
(47_520_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
@@ -410,63 +432,79 @@ impl WeightInfo for () {
// Storage: Uniques InstanceMetadataOf (r:1 w:0)
// Storage: Uniques Attribute (r:1 w:1)
fn clear_attribute() -> Weight {
(39_598_000 as Weight)
(45_316_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques InstanceMetadataOf (r:1 w:1)
fn set_metadata() -> Weight {
(33_387_000 as Weight)
(38_391_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques InstanceMetadataOf (r:1 w:1)
fn clear_metadata() -> Weight {
(33_208_000 as Weight)
(38_023_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
// Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassMetadataOf (r:1 w:1)
fn set_collection_metadata() -> Weight {
(32_619_000 as Weight)
(37_398_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
// Storage: Uniques Class (r:1 w:0)
// Storage: Uniques ClassMetadataOf (r:1 w:1)
fn clear_collection_metadata() -> Weight {
(31_028_000 as Weight)
(35_621_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Class (r:1 w:0)
// Storage: Uniques Asset (r:1 w:1)
fn approve_transfer() -> Weight {
(22_263_000 as Weight)
(25_856_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Class (r:1 w:0)
// Storage: Uniques Asset (r:1 w:1)
fn cancel_approval() -> Weight {
(22_910_000 as Weight)
(26_098_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Uniques OwnershipAcceptance (r:1 w:1)
fn set_accept_ownership() -> Weight {
(20_716_000 as Weight)
(24_076_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Uniques CollectionMaxSupply (r:1 w:1)
// Storage: Uniques Class (r:1 w:0)
fn set_collection_max_supply() -> Weight {
(19_380_000 as Weight)
(22_035_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Asset (r:1 w:0)
// Storage: Uniques ItemPriceOf (r:0 w:1)
fn set_price() -> Weight {
(22_534_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques ItemPriceOf (r:1 w:1)
// Storage: Uniques Class (r:1 w:0)
// Storage: Uniques Account (r:0 w:2)
fn buy_item() -> Weight {
(45_272_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
}
}