From 0adad6e2bc5fe06edabe72ed6e46dc720c42ddb2 Mon Sep 17 00:00:00 2001 From: Stefan Date: Mon, 14 Aug 2023 11:26:56 +0700 Subject: [PATCH] Stefan/fix apis (#315) * decrease supply * edit comments * re-name --- game/pallet-game/README.md | 16 +- game/pallet-game/src/benchmarking.rs | 43 ++-- game/pallet-game/src/features/common.rs | 66 +++++- game/pallet-game/src/features/create_item.rs | 52 +++-- game/pallet-game/src/features/minting.rs | 6 +- game/pallet-game/src/features/mutate_item.rs | 8 +- .../pallet-game/src/features/transfer_item.rs | 4 +- game/pallet-game/src/lib.rs | 209 +++++++++--------- game/pallet-game/src/tests.rs | 107 ++++----- game/pallet-game/src/trades/retail.rs | 2 +- game/pallet-game/src/types.rs | 2 +- game/pallet-game/src/weights.rs | 48 ++-- support/src/game/game.rs | 3 +- support/src/game/types.rs | 2 +- 14 files changed, 309 insertions(+), 259 deletions(-) diff --git a/game/pallet-game/README.md b/game/pallet-game/README.md index 69a61fa4..4546f2db 100644 --- a/game/pallet-game/README.md +++ b/game/pallet-game/README.md @@ -86,18 +86,18 @@ The highest bid when the auction expired is the winner. ### Trade dispatchables * `set_price`: Set price for NFTs. * `buy_item`: Buy NFTs from `set_price`. -* `add_retail_supply`: Add NFTs for `set_price`. +* `add_set_price`: Add NFTs for `set_price`. * `set_bundle`: Set a price for a bundle. * `buy_bundle`: Buy a bundle from `set_bundle`. -* `set_buy`: Place a buy trade for NFTs. -* `claim_set_buy`: Sell NFTs for `set_buy`. -* `set_wishlist`: Order a buy-all for a bundle. -* `claim_wishlist`: Sell a bundle for `set_wishlist`. -* `set_swap`: Set an exchange a bundle for a bundle may have an additional cost. -* `claim_swap`: Make an exchange from `set_swap`. +* `set_order`: Place a buy trade for NFTs. +* `sell_item`: Sell NFTs for `set_order`. +* `order_bundle`: Order a buy-all for a bundle. +* `sell_bundle`: Sell a bundle for `order_bundle`. +* `create_swap`: Set an exchange a bundle for a bundle may have an additional cost. +* `make_swap`: Make an exchange from `create_swap`. * `set_auction`: Bid for a bundle, starting on a specific block with a minimum bid and duration. * `bid_auction`: Make a bid. -* `claim_auction`: End the auction when it expires. +* `close_auction`: End the auction when it expires. * `cancel_trade`: Cancel a trade with trade id. * `create_dynamic_pool`: Create a minting pool with a dynamic weight loot table. diff --git a/game/pallet-game/src/benchmarking.rs b/game/pallet-game/src/benchmarking.rs index d0db6026..77263af2 100644 --- a/game/pallet-game/src/benchmarking.rs +++ b/game/pallet-game/src/benchmarking.rs @@ -99,7 +99,6 @@ fn do_create_item, I: 'static>( RawOrigin::Signed(admin.clone()).into(), ::Helper::collection(collection), ::Helper::item(item), - default_item_config(), supply, )); } @@ -268,7 +267,7 @@ fn do_set_wishlist, I: 'static>(who: &T::AccountId) { }, ]; - assert_ok!(PalletGame::::set_wishlist( + assert_ok!(PalletGame::::order_bundle( RawOrigin::Signed(who.clone()).into(), bundle, >::Currency::minimum_balance(), @@ -328,8 +327,8 @@ benchmarks_instance_pallet! { create_item { let (caller, admin) = do_create_collection::(); let call = Call::::create_item { collection: ::Helper::collection(0), - item: ::Helper::item(0), - config: default_item_config(), maybe_supply: Some(10) }; + item: ::Helper::item(0), + maybe_supply: Some(10) }; }: { call.dispatch_bypass_filter(RawOrigin::Signed(admin.clone()).into())? } verify { assert_last_event::(Event::ItemCreated { who: admin, @@ -523,7 +522,7 @@ benchmarks_instance_pallet! { }.into() ); } - set_wishlist { + order_bundle { let s in 0 .. >::MaxBundle::get(); let (who, _, _) = new_account_with_item::(0); let bundle = vec![ @@ -533,7 +532,7 @@ benchmarks_instance_pallet! { amount: 1, }; s as usize]; - let call = Call::::set_wishlist { + let call = Call::::order_bundle { bundle: bundle.clone(), price: >::Currency::minimum_balance(), start_block: None, @@ -549,13 +548,13 @@ benchmarks_instance_pallet! { }.into() ); } - claim_wishlist { + sell_bundle { let player = new_funded_account::(1, 1, 1000_000_000u128 * UNIT); do_set_wishlist::(&player); let (who, _, _) = new_account_with_item::(0); - let call = Call::::claim_wishlist { + let call = Call::::sell_bundle { trade: >::Helper::trade(0), ask_price: >::Currency::minimum_balance(), }; @@ -584,7 +583,7 @@ benchmarks_instance_pallet! { }.into() ); } - set_swap { + create_swap { let s in 0 .. >::MaxBundle::get(); let x in 0 .. >::MaxBundle::get(); @@ -603,7 +602,7 @@ benchmarks_instance_pallet! { amount: 1, }; x as usize]; - let call = Call::::set_swap { + let call = Call::::create_swap { source: bundle.clone(), required: required.clone(), maybe_price: Some(>::Currency::minimum_balance()), @@ -621,7 +620,7 @@ benchmarks_instance_pallet! { }.into() ); } - claim_swap { + make_swap { let (player1, _, _) = new_account_with_item::(0); let (player2, _, _) = new_account_with_item::(1); @@ -649,7 +648,7 @@ benchmarks_instance_pallet! { amount: 10, }]; - assert_ok!(PalletGame::::set_swap( + assert_ok!(PalletGame::::create_swap( RawOrigin::Signed(player1.clone()).into(), source.clone(), required.clone(), @@ -658,7 +657,7 @@ benchmarks_instance_pallet! { None, )); - let call = Call::::claim_swap { + let call = Call::::make_swap { trade: >::Helper::trade(0), maybe_bid_price: Some(>::Currency::minimum_balance()), }; @@ -717,7 +716,7 @@ benchmarks_instance_pallet! { }.into() ); } - claim_auction { + close_auction { let _ = do_set_auction::(); let bidder = new_funded_account::(0, 0, 1000_000_000u128 * UNIT); @@ -731,7 +730,7 @@ benchmarks_instance_pallet! { frame_system::Pallet::::set_block_number(>::Helper::block(10)); - let call = Call::::claim_auction { + let call = Call::::close_auction { trade: >::Helper::trade(0), }; }: { call.dispatch_bypass_filter(RawOrigin::Signed(caller.clone()).into())? } @@ -742,7 +741,7 @@ benchmarks_instance_pallet! { }.into() ); } - set_buy { + set_order { let caller = new_funded_account::(0, 0, 1000_000_000u128 * UNIT); let package = Package { @@ -751,7 +750,7 @@ benchmarks_instance_pallet! { amount: 10, }; - let call = Call::::set_buy { + let call = Call::::set_order { package: package.clone(), unit_price: >::Currency::minimum_balance(), start_block: None, @@ -769,7 +768,7 @@ benchmarks_instance_pallet! { }.into() ); } - claim_set_buy { + sell_item { let (who, _, _) = new_account_with_item::(0); let player = new_funded_account::(0, 0, 1000_000_000u128 * UNIT); @@ -778,7 +777,7 @@ benchmarks_instance_pallet! { item: ::Helper::item(0), amount: 10, }; - assert_ok!(PalletGame::::set_buy( + assert_ok!(PalletGame::::set_order( RawOrigin::Signed(player.clone()).into(), package.clone(), >::Currency::minimum_balance(), @@ -786,7 +785,7 @@ benchmarks_instance_pallet! { None, )); - let call = Call::::claim_set_buy { + let call = Call::::sell_item { trade: >::Helper::trade(0), amount: 10, ask_price: >::Currency::minimum_balance(), @@ -863,7 +862,7 @@ benchmarks_instance_pallet! { }.into() ); } - add_retail_supply { + add_set_price { let (who, _, _) = new_account_with_item::(0); do_set_price::(&who); let package = Package { @@ -872,7 +871,7 @@ benchmarks_instance_pallet! { amount: 5, }; - let call = Call::::add_retail_supply { + let call = Call::::add_set_price { trade: >::Helper::trade(0), supply: package, }; diff --git a/game/pallet-game/src/features/common.rs b/game/pallet-game/src/features/common.rs index bac9b406..ed749aa0 100644 --- a/game/pallet-game/src/features/common.rs +++ b/game/pallet-game/src/features/common.rs @@ -9,7 +9,7 @@ impl, I: 'static> Pallet { collection: &T::CollectionId, item: &T::ItemId, to: &T::AccountId, - amount: u32, + amount: Amount, ) -> Result<(), Error> { Self::sub_item_balance(from, collection, item, amount)?; Self::add_item_balance(to, collection, item, amount)?; @@ -22,7 +22,7 @@ impl, I: 'static> Pallet { collection: &T::CollectionId, old_item: &T::ItemId, new_item: &T::ItemId, - amount: u32, + amount: Amount, ) -> Result<(), Error> { Self::sub_item_balance(who, collection, old_item, amount)?; Self::add_item_balance(who, collection, new_item, amount)?; @@ -34,7 +34,7 @@ impl, I: 'static> Pallet { who: &T::AccountId, collection: &T::CollectionId, item: &T::ItemId, - amount: u32, + amount: Amount, ) -> Result<(), Error> { ensure!(amount > 0, Error::::InvalidAmount); let balance = ItemBalanceOf::::get((&who, &collection, &item)); @@ -47,7 +47,7 @@ impl, I: 'static> Pallet { who: &T::AccountId, collection: &T::CollectionId, item: &T::ItemId, - amount: u32, + amount: Amount, ) -> Result<(), Error> { ensure!(amount > 0, Error::::InvalidAmount); let balance = ItemBalanceOf::::get((&who, &collection, &item)); @@ -67,7 +67,7 @@ impl, I: 'static> Pallet { who: &T::AccountId, collection: &T::CollectionId, item: &T::ItemId, - amount: u32, + amount: Amount, ) -> Result<(), Error> { ensure!(amount > 0, Error::::InvalidAmount); let balance = ReservedBalanceOf::::get((&who, &collection, &item)); @@ -80,7 +80,7 @@ impl, I: 'static> Pallet { who: &T::AccountId, collection: &T::CollectionId, item: &T::ItemId, - amount: u32, + amount: Amount, ) -> Result<(), Error> { ensure!(amount > 0, Error::::InvalidAmount); let balance = ReservedBalanceOf::::get((who, collection, item)); @@ -102,7 +102,7 @@ impl, I: 'static> Pallet { who: &T::AccountId, collection: &T::CollectionId, item: &T::ItemId, - amount: u32, + amount: Amount, ) -> Result<(), Error> { Self::sub_item_balance(who, collection, item, amount)?; Self::add_reserved_balance(who, collection, item, amount)?; @@ -123,7 +123,7 @@ impl, I: 'static> Pallet { who: &T::AccountId, collection: &T::CollectionId, item: &T::ItemId, - amount: u32, + amount: Amount, ) -> Result<(), Error> { Self::sub_reserved_balance(who, collection, item, amount)?; Self::add_item_balance(who, collection, item, amount)?; @@ -137,7 +137,7 @@ impl, I: 'static> Pallet { collection: &T::CollectionId, item: &T::ItemId, beneficiary: &T::AccountId, - amount: u32, + amount: Amount, status: ItemBalanceStatus, ) -> Result<(), Error> { Self::sub_reserved_balance(slashed, collection, item, amount)?; @@ -179,4 +179,52 @@ impl, I: 'static> Pallet { .map(|maybe_supply| maybe_supply.is_none()) .unwrap_or_default() } + + /// Decreases the finite supply of a specific item within a collection by a given amount. + /// + /// If the collection and item exist, their finite supply is decremented by the specified + /// amount, with saturation to prevent underflow. + /// + /// # Parameters + /// + /// - `collection`: The identifier of the collection. + /// - `item`: The identifier of the item. + /// - `amount`: The amount to decrease the item's supply by. + pub(crate) fn decrease_finite_item_supply( + collection: &T::CollectionId, + item: &T::ItemId, + amount: Amount, + ) { + if let Some(Some(existing_supply)) = SupplyOf::::get(collection, item) { + SupplyOf::::insert( + collection, + item, + Some(existing_supply.saturating_sub(amount)), + ); + } + } + + /// Increases the finite supply of a specific item within a collection by a given amount. + /// + /// If the collection and item exist, their finite supply is incremented by the specified + /// amount, with saturation to prevent overflow. + /// + /// # Parameters + /// + /// - `collection`: The identifier of the collection. + /// - `item`: The identifier of the item. + /// - `amount`: The amount to increase the item's supply by. + pub(crate) fn increase_finite_item_supply( + collection: &T::CollectionId, + item: &T::ItemId, + amount: Amount, + ) { + if let Some(Some(existing_supply)) = SupplyOf::::get(collection, item) { + SupplyOf::::insert( + collection, + item, + Some(existing_supply.saturating_add(amount)), + ); + } + } } diff --git a/game/pallet-game/src/features/create_item.rs b/game/pallet-game/src/features/create_item.rs index 206e2291..c7290f53 100644 --- a/game/pallet-game/src/features/create_item.rs +++ b/game/pallet-game/src/features/create_item.rs @@ -8,7 +8,6 @@ impl, I: 'static> CreateItem, ) -> DispatchResult { if let Some(collection_owner) = T::Nfts::collection_owner(collection) { @@ -17,7 +16,13 @@ impl, I: 'static> CreateItem::NoPermission ); - T::Nfts::mint_into(&collection, &item, &collection_owner, &config, false)?; + T::Nfts::mint_into( + &collection, + &item, + &collection_owner, + &ItemConfig::default(), + false, + )?; if let Some(supply) = maybe_supply { // issues new amount of item @@ -37,40 +42,51 @@ impl, I: 'static> CreateItem::UnknownCollection.into()) } + /// Adds a specified amount of an item to a collection's finite supply and the balance of + /// `collection` owner, subject to permissions. + /// + /// # Parameters + /// + /// - `who`: The account identifier of the caller attempting to add supply. + /// - `collection`: The identifier of the collection to which the item belongs. + /// - `item`: The identifier of the item to add supply for. + /// - `amount`: The amount to add to both the balance and the finite supply of the item. fn do_add_supply( who: &T::AccountId, collection: &T::CollectionId, item: &T::ItemId, amount: Amount, ) -> DispatchResult { - // ensure permission + // Ensure the caller has the required permission if let Some(collection_owner) = T::Nfts::collection_owner(collection) { ensure!( - T::Nfts::is_admin(collection, who) | T::Nfts::is_issuer(collection, who), + T::Nfts::is_admin(collection, who) || T::Nfts::is_issuer(collection, who), Error::::NoPermission ); - if let Some(supply) = SupplyOf::::get(collection, item) { - match supply { - Some(val) => { - let new_supply = val + amount; - Self::add_item_balance(&collection_owner, collection, item, amount)?; - SupplyOf::::insert(collection, item, Some(new_supply)); - }, - None => return Err(Error::::InfiniteSupply.into()), - }; - } else { - return Err(Error::::UnknownItem.into()) - } + // Ensure the item's supply is not infinite + ensure!( + !Self::is_infinite(collection, item), + Error::::InfiniteSupply + ); + + // Add the item to the collection owner's balance + Self::add_item_balance(&collection_owner, collection, item, amount)?; + // Increase the finite supply of the item + Self::increase_finite_item_supply(collection, item, amount); + + // Emit an event to indicate the successful addition of supply Self::deposit_event(Event::::ItemAdded { who: who.clone(), collection: *collection, item: *item, amount, }); - return Ok(()) + + Ok(()) + } else { + Err(Error::::UnknownCollection.into()) } - return Err(Error::::UnknownCollection.into()) } } diff --git a/game/pallet-game/src/features/minting.rs b/game/pallet-game/src/features/minting.rs index 73427814..20b690ba 100644 --- a/game/pallet-game/src/features/minting.rs +++ b/game/pallet-game/src/features/minting.rs @@ -102,7 +102,7 @@ impl, I: 'static> pool: &T::PoolId, who: &T::AccountId, target: &T::AccountId, - amount: u32, + amount: Amount, ) -> DispatchResult { if let Some(pool_details) = PoolOf::::get(pool) { // verify mint settings @@ -161,7 +161,7 @@ impl, I: 'static> pool: &T::PoolId, who: &T::AccountId, target: &T::AccountId, - amount: u32, + amount: Amount, ) -> DispatchResult { // validating item amount let mut table = LootTableOf::::get(pool).clone().into(); @@ -224,7 +224,7 @@ impl, I: 'static> pool: &T::PoolId, who: &T::AccountId, target: &T::AccountId, - amount: u32, + amount: Amount, ) -> DispatchResult { // random minting let mut nfts: Vec> = Vec::new(); diff --git a/game/pallet-game/src/features/mutate_item.rs b/game/pallet-game/src/features/mutate_item.rs index aabfc892..0a1b160e 100644 --- a/game/pallet-game/src/features/mutate_item.rs +++ b/game/pallet-game/src/features/mutate_item.rs @@ -1,10 +1,14 @@ use crate::*; -use frame_support::{pallet_prelude::*}; +use frame_support::pallet_prelude::*; use gafi_support::game::{Amount, MutateItem}; impl, I: 'static> MutateItem for Pallet { + /// Burns a specified amount of an item from an account's balance and decreases the finite + /// supply. + /// + /// Emits `Burned` event on success. fn do_burn( who: &T::AccountId, collection: &T::CollectionId, @@ -13,6 +17,8 @@ impl, I: 'static> MutateItem DispatchResult { Self::sub_item_balance(who, collection, item, amount)?; + Self::decrease_finite_item_supply(collection, item, amount); + Self::deposit_event(Event::::Burned { who: who.clone(), collection: *collection, diff --git a/game/pallet-game/src/features/transfer_item.rs b/game/pallet-game/src/features/transfer_item.rs index 5132656f..7f99db0e 100644 --- a/game/pallet-game/src/features/transfer_item.rs +++ b/game/pallet-game/src/features/transfer_item.rs @@ -5,6 +5,9 @@ use gafi_support::game::{Amount, TransferItem}; impl, I: 'static> TransferItem for Pallet { + /// Transfers a specified amount of an item from one account to another within a collection. + /// + /// Emits `Transferred` event on success. fn do_transfer_item( who: &T::AccountId, collection: &T::CollectionId, @@ -12,7 +15,6 @@ impl, I: 'static> TransferItem DispatchResult { - Self::transfer_item(who, collection, item, destination, amount)?; Self::deposit_event(Event::::Transferred { diff --git a/game/pallet-game/src/lib.rs b/game/pallet-game/src/lib.rs index 3671c100..ffb0ce31 100644 --- a/game/pallet-game/src/lib.rs +++ b/game/pallet-game/src/lib.rs @@ -428,13 +428,13 @@ pub mod pallet { who: T::AccountId, collection: T::CollectionId, item: T::ItemId, - amount: u32, + amount: Amount, }, RequestMint { who: T::AccountId, pool: T::PoolId, target: T::AccountId, - block_number: T::BlockNumber, + block_number: T::BlockNumber, }, Minted { who: T::AccountId, @@ -446,14 +446,14 @@ pub mod pallet { who: T::AccountId, collection: T::CollectionId, item: T::ItemId, - amount: u32, + amount: Amount, }, Transferred { from: T::AccountId, collection: T::CollectionId, item: T::ItemId, dest: T::AccountId, - amount: u32, + amount: Amount, }, UpgradeSet { who: T::AccountId, @@ -467,20 +467,20 @@ pub mod pallet { collection: T::CollectionId, item: T::ItemId, new_item: T::ItemId, - amount: u32, + amount: Amount, }, PriceSet { trade: T::TradeId, who: T::AccountId, collection: T::CollectionId, item: T::ItemId, - amount: u32, + amount: Amount, unit_price: BalanceOf, }, ItemBought { trade: T::TradeId, who: T::AccountId, - amount: u32, + amount: Amount, bid_unit_price: BalanceOf, }, BundleSet { @@ -548,13 +548,13 @@ pub mod pallet { who: T::AccountId, collection: T::CollectionId, item: T::ItemId, - amount: u32, + amount: Amount, unit_price: BalanceOf, }, SetBuyClaimed { trade: T::TradeId, who: T::AccountId, - amount: u32, + amount: Amount, ask_unit_price: BalanceOf, }, MiningPoolCreated { @@ -653,7 +653,6 @@ pub mod pallet { #[pallet::hooks] impl, I: 'static> Hooks> for Pallet { - /// Process minting requests in `block_number`. fn on_initialize(block_number: BlockNumber) -> Weight { for request in MintRequestOf::::get(block_number) { @@ -806,21 +805,24 @@ pub mod pallet { origin: OriginFor, collection: T::CollectionId, item: T::ItemId, - config: ItemConfig, maybe_supply: Option, ) -> DispatchResult { let sender = ensure_signed(origin)?; - Self::do_create_item(&sender, &collection, &item, &config, maybe_supply)?; + Self::do_create_item(&sender, &collection, &item, maybe_supply)?; Ok(()) } - /// Add supplies for the item. + //// Adds a specified amount of an item to a collection's finite supply and balance of + //// `collection` owner. /// - /// The origin must be Signed and the sender should be the Admin of `collection`. + /// Origin must be signed and have permission. Item's supply must not be infinite. /// - /// - `collection`: The collection of the item to be minted. - /// - `item`: An identifier of the new item. - /// - `amount`: Supply amount. + /// # Parameters + /// + /// - `origin`: Signed origin of the transaction. + /// - `collection`: Identifier of the collection. + /// - `item`: Identifier of the item. + /// - `amount`: Amount to add to balance and finite supply. /// /// Emits `ItemAdded` event when successful. /// @@ -831,7 +833,7 @@ pub mod pallet { origin: OriginFor, collection: T::CollectionId, item: T::ItemId, - amount: u32, + amount: Amount, ) -> DispatchResult { let sender = ensure_signed(origin)?; Self::do_add_supply(&sender, &collection, &item, amount)?; @@ -856,22 +858,23 @@ pub mod pallet { origin: OriginFor, collection: T::CollectionId, item: T::ItemId, - amount: u32, + amount: Amount, ) -> DispatchResult { let sender = ensure_signed(origin)?; Self::do_burn(&sender, &collection, &item, amount)?; Ok(()) } - /// Move an item from the sender account to another. + /// Transfers a specified amount of an item between accounts within a collection. /// - /// Origin must be Signed and the signing account must be the owner of the `item`. + /// # Parameters + /// + /// - `origin`: Origin must be signed, indicating the sender. + /// - `collection`: Collection identifier. + /// - `item`: Item identifier. + /// - `dest`: Destination account lookup. + /// - `amount`: Amount of the item to transfer. /// - /// Arguments: - /// - `collection`: The collection of the item to be transferred. - /// - `item`: The item to be transferred. - /// - `dest`: The account to receive ownership of the item. - /// - `amount`: The amount of item to be transferred. /// /// Emits `Transferred`. /// @@ -883,7 +886,7 @@ pub mod pallet { collection: T::CollectionId, item: T::ItemId, dest: AccountIdLookupOf, - amount: u32, + amount: Amount, ) -> DispatchResult { let sender = ensure_signed(origin)?; let destination = T::Lookup::lookup(dest)?; @@ -950,14 +953,14 @@ pub mod pallet { origin: OriginFor, collection: T::CollectionId, item: T::ItemId, - amount: u32, + amount: Amount, ) -> DispatchResult { let sender = ensure_signed(origin)?; Self::do_upgrade_item(&sender, &collection, &item, amount)?; Ok(()) } - /// Set the price for a package. + /// Set the price for NFTs within a collection. /// /// Origin must be Signed and must be the owner of the `item`. /// @@ -1002,7 +1005,7 @@ pub mod pallet { pub fn buy_item( origin: OriginFor, trade: T::TradeId, - amount: u32, + amount: Amount, bid_price: BalanceOf, ) -> DispatchResult { let sender = ensure_signed(origin)?; @@ -1019,14 +1022,67 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(15)] - #[pallet::weight(>::WeightInfo::add_retail_supply())] - pub fn add_retail_supply( + #[pallet::weight(>::WeightInfo::add_set_price())] + pub fn add_set_price( origin: OriginFor, trade: T::TradeId, supply: Package, ) -> DispatchResult { let sender = ensure_signed(origin)?; - Self::do_add_retail_supply(&trade, &sender, supply)?; + Self::do_add_set_price(&trade, &sender, supply)?; + Ok(()) + } + + /// Set up a purchase for `package`. + /// + /// It is possible to trade for a small part of the `package`. + /// + /// Origin must be Signed. + /// + /// - `package`: A number of an item in a collection want to buy. + /// - `unit_price`: The price of each item the sender is willing to pay. + /// - `start_block`: The block to start set buy. + /// - `end_block`: The block to end set buy. + /// + /// Emits `BuySet`. + /// + /// Weight: `O(1)` + #[pallet::call_index(29)] + #[pallet::weight(>::WeightInfo::set_order())] + pub fn set_order( + origin: OriginFor, + package: Package, + unit_price: BalanceOf, + start_block: Option, + end_block: Option, + ) -> DispatchResult { + let sender = ensure_signed(origin)?; + let trade = Self::get_trade_id(); + Self::do_set_buy(&trade, &sender, package, unit_price, start_block, end_block)?; + Ok(()) + } + + /// Sell ​​`amount` of the item for `set_order`. + /// + /// Origin must be Signed. + /// + /// - `trade`: The set_order trade id. + /// - `amount`: The amount of items to sell. + /// - `ask_price`: The price that the sender willing to accept. + /// + /// Emits `BuySet`. + /// + /// Weight: `O(1)` + #[pallet::call_index(30)] + #[pallet::weight(>::WeightInfo::sell_item())] + pub fn sell_item( + origin: OriginFor, + trade: T::TradeId, + amount: Amount, + ask_price: BalanceOf, + ) -> DispatchResult { + let sender = ensure_signed(origin)?; + Self::do_claim_set_buy(&trade, &sender, amount, ask_price)?; Ok(()) } @@ -1116,8 +1172,8 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(19)] - #[pallet::weight(>::WeightInfo::set_wishlist(bundle.len() as u32))] - pub fn set_wishlist( + #[pallet::weight(>::WeightInfo::order_bundle(bundle.len() as u32))] + pub fn order_bundle( origin: OriginFor, bundle: Bundle, price: BalanceOf, @@ -1128,25 +1184,25 @@ pub mod pallet { let trade = Self::get_trade_id(); let bundle_len = bundle.len() as u32; Self::do_set_wishlist(&trade, &sender, bundle, price, start_block, end_block)?; - Ok(Some(>::WeightInfo::set_wishlist( + Ok(Some(>::WeightInfo::order_bundle( bundle_len, )) .into()) } - /// Sell the bundle for `set_wishlist`. + /// Sell the bundle for `order_bundle`. /// /// Origin must be Signed. /// - /// - `trade`: The set_wishlist trade id. + /// - `trade`: The order_bundle trade id. /// - `ask_price`: The price the sender is willing to accept. /// /// Emits `WishlistFilled`. /// /// Weight: `O(1)` #[pallet::call_index(20)] - #[pallet::weight(>::WeightInfo::claim_wishlist())] - pub fn claim_wishlist( + #[pallet::weight(>::WeightInfo::sell_bundle())] + pub fn sell_bundle( origin: OriginFor, trade: T::TradeId, ask_price: BalanceOf, @@ -1234,8 +1290,8 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(24)] - #[pallet::weight(>::WeightInfo::set_swap(source.len() as u32, required.len() as u32))] - pub fn set_swap( + #[pallet::weight(>::WeightInfo::create_swap(source.len() as u32, required.len() as u32))] + pub fn create_swap( origin: OriginFor, source: Bundle, required: Bundle, @@ -1258,26 +1314,26 @@ pub mod pallet { start_block, end_block, )?; - Ok(Some(>::WeightInfo::set_swap( + Ok(Some(>::WeightInfo::create_swap( source_len, required_len, )) .into()) } - /// Make an exchange for `set_swap`. + /// Make an exchange for `create_swap`. /// /// Origin must be Signed. /// - /// - `trade`: The set_swap trade id. + /// - `trade`: The create_swap trade id. /// - `maybe_bid_price`: Maybe a price sender willing to pay. /// /// Emits `SwapClaimed`. /// /// Weight: `O(1)` #[pallet::call_index(25)] - #[pallet::weight(>::WeightInfo::claim_swap())] - pub fn claim_swap( + #[pallet::weight(>::WeightInfo::make_swap())] + pub fn make_swap( origin: OriginFor, trade: T::TradeId, maybe_bid_price: Option>, @@ -1355,66 +1411,13 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(28)] - #[pallet::weight(>::WeightInfo::claim_auction())] - pub fn claim_auction(origin: OriginFor, trade: T::TradeId) -> DispatchResult { + #[pallet::weight(>::WeightInfo::close_auction())] + pub fn close_auction(origin: OriginFor, trade: T::TradeId) -> DispatchResult { let _ = ensure_signed(origin)?; Self::do_claim_auction(&trade)?; Ok(()) } - /// Set up a purchase for `package`. - /// - /// It is possible to trade for a small part of the `package`. - /// - /// Origin must be Signed. - /// - /// - `package`: A number of an item in a collection want to buy. - /// - `unit_price`: The price of each item the sender is willing to pay. - /// - `start_block`: The block to start set buy. - /// - `end_block`: The block to end set buy. - /// - /// Emits `BuySet`. - /// - /// Weight: `O(1)` - #[pallet::call_index(29)] - #[pallet::weight(>::WeightInfo::set_buy())] - pub fn set_buy( - origin: OriginFor, - package: Package, - unit_price: BalanceOf, - start_block: Option, - end_block: Option, - ) -> DispatchResult { - let sender = ensure_signed(origin)?; - let trade = Self::get_trade_id(); - Self::do_set_buy(&trade, &sender, package, unit_price, start_block, end_block)?; - Ok(()) - } - - /// Sell ​​`amount` of the item for `set_buy`. - /// - /// Origin must be Signed. - /// - /// - `trade`: The set_buy trade id. - /// - `amount`: The amount of items to sell. - /// - `ask_price`: The price that the sender willing to accept. - /// - /// Emits `BuySet`. - /// - /// Weight: `O(1)` - #[pallet::call_index(30)] - #[pallet::weight(>::WeightInfo::claim_set_buy())] - pub fn claim_set_buy( - origin: OriginFor, - trade: T::TradeId, - amount: u32, - ask_price: BalanceOf, - ) -> DispatchResult { - let sender = ensure_signed(origin)?; - Self::do_claim_set_buy(&trade, &sender, amount, ask_price)?; - Ok(()) - } - /// Set an attribute for a collection or item. /// /// Simply re-call `set_attribute` of `pallet-nfts`. @@ -1706,7 +1709,7 @@ pub mod pallet { origin: OriginFor, pool: T::PoolId, mint_to: AccountIdLookupOf, - amount: u32, + amount: Amount, ) -> DispatchResult { let sender = ensure_signed(origin)?; let target = T::Lookup::lookup(mint_to)?; diff --git a/game/pallet-game/src/tests.rs b/game/pallet-game/src/tests.rs index 779eeca2..aee7b89b 100644 --- a/game/pallet-game/src/tests.rs +++ b/game/pallet-game/src/tests.rs @@ -65,18 +65,11 @@ fn do_create_collection(game: u32, admin: &sr25519::Public) { )); } -fn do_create_item( - admin: &sr25519::Public, - collection: u32, - item: u32, - item_config: &ItemConfig, - amount: u32, -) { +fn do_create_item(admin: &sr25519::Public, collection: u32, item: u32, amount: Amount) { assert_ok!(PalletGame::create_item( RuntimeOrigin::signed(admin.clone()), collection, item, - *item_config, Some(amount) )); } @@ -148,13 +141,7 @@ fn do_all_create_dynamic_pool( do_create_collection(0, &admin); for package in TEST_BUNDLE.clone() { - do_create_item( - &admin, - package.collection, - package.item, - &default_item_config(), - package.amount, - ); + do_create_item(&admin, package.collection, package.item, package.amount); } assert_ok!(PalletGame::create_dynamic_pool( @@ -177,7 +164,6 @@ fn do_all_create_stable_pool( RuntimeOrigin::signed(admin.clone()), package.collection, package.item, - default_item_config(), None )); } @@ -201,13 +187,7 @@ fn create_account_with_item( do_create_collection(latest_game, &admin); for pack in source.clone() { - do_create_item( - &admin, - pack.collection, - pack.item, - &default_item_config(), - u32::MAX, - ); + do_create_item(&admin, pack.collection, pack.item, 1000); } let player = new_account(3, 1000 * unit(GAKI)); @@ -528,7 +508,6 @@ fn create_item_should_works() { RuntimeOrigin::signed(admin.clone()), 0, 0, - default_item_config(), Some(1000) )); @@ -542,7 +521,7 @@ fn add_supply_should_works() { run_to_block(1); let (_, admin) = do_create_game(); do_create_collection(0, &admin); - do_create_item(&admin, 0, 0, &default_item_config(), 1000); + do_create_item(&admin, 0, 0, 1000); assert_ok!(PalletGame::add_supply( RuntimeOrigin::signed(admin.clone()), @@ -563,13 +542,23 @@ pub fn burn_items_should_works() { assert_eq!(ItemBalanceOf::::get((player.clone(), 0, 0)), 10); + let amount = 5; + let before_supply = SupplyOf::::get(0, 0); + assert_ok!(PalletGame::burn( RuntimeOrigin::signed(player.clone()), 0, 0, - 5 + amount )); - assert_eq!(ItemBalanceOf::::get((player.clone(), 0, 0)), 5); + + let after_supply = SupplyOf::::get(0, 0); + + assert_eq!( + before_supply.unwrap().unwrap(), + after_supply.unwrap().unwrap() + amount + ); + assert_eq!(ItemBalanceOf::::get((player.clone(), 0, 0)), amount); assert_err!( PalletGame::burn(RuntimeOrigin::signed(player.clone()), 0, 0, 6), @@ -609,7 +598,7 @@ pub fn set_upgrade_item_should_works() { run_to_block(1); let (owner, admin) = do_create_game(); do_create_collection(0, &admin); - do_create_item(&admin, 0, 0, &default_item_config(), 1000); + do_create_item(&admin, 0, 0, 1000); let byte = 50; @@ -838,7 +827,7 @@ pub fn buy_item_should_fails() { } #[test] -pub fn add_retail_supply_should_works() { +pub fn add_set_price_should_works() { new_test_ext().execute_with(|| { run_to_block(1); @@ -853,7 +842,7 @@ pub fn add_retail_supply_should_works() { ReservedBalanceOf::::get((player.clone(), supply.collection, supply.item)), supply.amount ); - assert_ok!(PalletGame::add_retail_supply( + assert_ok!(PalletGame::add_set_price( RuntimeOrigin::signed(player.clone()), 0, supply @@ -866,7 +855,7 @@ pub fn add_retail_supply_should_works() { } #[test] -pub fn add_retail_supply_should_failss() { +pub fn add_set_price_should_failss() { new_test_ext().execute_with(|| { run_to_block(1); @@ -874,7 +863,7 @@ pub fn add_retail_supply_should_failss() { let player1 = new_account(1, 1000 * unit(GAKI)); assert_err!( - PalletGame::add_retail_supply( + PalletGame::add_set_price( RuntimeOrigin::signed(player1.clone()), 0, TEST_BUNDLE[0].clone() @@ -883,7 +872,7 @@ pub fn add_retail_supply_should_failss() { ); assert_err!( - PalletGame::add_retail_supply( + PalletGame::add_set_price( RuntimeOrigin::signed(player.clone()), 0, TEST_BUNDLE1[1].clone() @@ -892,7 +881,7 @@ pub fn add_retail_supply_should_failss() { ); assert_err!( - PalletGame::add_retail_supply( + PalletGame::add_set_price( RuntimeOrigin::signed(player.clone()), 0, TEST_BUNDLE[1].clone() @@ -901,7 +890,7 @@ pub fn add_retail_supply_should_failss() { ); assert_err!( - PalletGame::add_retail_supply( + PalletGame::add_set_price( RuntimeOrigin::signed(player.clone()), 0, TEST_BUNDLE[0].clone() @@ -1088,7 +1077,7 @@ pub fn cancel_set_wishlist_should_works() { let (player, _, _) = create_account_with_item(TEST_BUNDLE); let price = 3 * unit(GAKI); - assert_ok!(PalletGame::set_wishlist( + assert_ok!(PalletGame::order_bundle( RuntimeOrigin::signed(player.clone()), TEST_BUNDLE.clone().to_vec(), price, @@ -1118,7 +1107,7 @@ pub fn do_cancel_set_swap_should_works() { let price = 100 * unit(GAKI); - assert_ok!(PalletGame::set_swap( + assert_ok!(PalletGame::create_swap( RuntimeOrigin::signed(player.clone()), TEST_BUNDLE.clone().to_vec(), TEST_BUNDLE1.clone().to_vec(), @@ -1146,7 +1135,7 @@ pub fn set_wishlist_should_works() { let buyer = new_account(3, 1000 * unit(GAKI)); let price = 3 * unit(GAKI); let before_balance = Balances::free_balance(&buyer); - assert_ok!(PalletGame::set_wishlist( + assert_ok!(PalletGame::order_bundle( RuntimeOrigin::signed(buyer.clone()), TEST_BUNDLE.clone().to_vec(), price, @@ -1181,7 +1170,7 @@ pub fn fill_wishlist_should_works() { let price = 3 * unit(GAKI); let buyer = new_account(3, 1000 * unit(GAKI)); - assert_ok!(PalletGame::set_wishlist( + assert_ok!(PalletGame::order_bundle( RuntimeOrigin::signed(buyer.clone()), TEST_BUNDLE.clone().to_vec(), price, @@ -1190,7 +1179,7 @@ pub fn fill_wishlist_should_works() { )); let before_player_balance = Balances::free_balance(&player); - assert_ok!(PalletGame::claim_wishlist( + assert_ok!(PalletGame::sell_bundle( RuntimeOrigin::signed(player.clone()), 0, price @@ -1221,7 +1210,7 @@ pub fn set_swap_should_works() { let price = 100 * unit(GAKI); let player_balance = Balances::free_balance(&player); - assert_ok!(PalletGame::set_swap( + assert_ok!(PalletGame::create_swap( RuntimeOrigin::signed(player.clone()), TEST_BUNDLE.clone().to_vec(), TEST_BUNDLE1.clone().to_vec(), @@ -1266,7 +1255,7 @@ pub fn claim_swap_should_works() { let price = 100 * unit(GAKI); - assert_ok!(PalletGame::set_swap( + assert_ok!(PalletGame::create_swap( RuntimeOrigin::signed(player1.clone()), TEST_BUNDLE.clone().to_vec(), TEST_BUNDLE1.clone().to_vec(), @@ -1278,7 +1267,7 @@ pub fn claim_swap_should_works() { let player1_balance = Balances::free_balance(&player1); let player2_balance = Balances::free_balance(&player2); - assert_ok!(PalletGame::claim_swap( + assert_ok!(PalletGame::make_swap( RuntimeOrigin::signed(player2.clone()), 0, Some(price) @@ -1441,7 +1430,7 @@ pub fn claim_auction_should_works() { let player_balance = Balances::free_balance(&player); run_to_block(11); - assert_ok!(PalletGame::claim_auction( + assert_ok!(PalletGame::close_auction( RuntimeOrigin::signed(player.clone()), 0 )); @@ -1474,7 +1463,7 @@ pub fn claim_auction_should_fails() { let (player, _, _) = create_account_with_item(TEST_BUNDLE); assert_err!( - PalletGame::claim_auction(RuntimeOrigin::signed(player.clone()), 0), + PalletGame::close_auction(RuntimeOrigin::signed(player.clone()), 0), Error::::UnknownAuction ); @@ -1487,7 +1476,7 @@ pub fn claim_auction_should_fails() { )); assert_err!( - PalletGame::claim_auction(RuntimeOrigin::signed(player.clone()), 0), + PalletGame::close_auction(RuntimeOrigin::signed(player.clone()), 0), Error::::AuctionInProgress ); }) @@ -1502,7 +1491,7 @@ pub fn set_buy_should_works() { let player_balance = Balances::free_balance(&player); let unit_price = 5 * unit(GAKI); - assert_ok!(PalletGame::set_buy( + assert_ok!(PalletGame::set_order( RuntimeOrigin::signed(player.clone()), TEST_BUNDLE[0].clone(), unit_price, @@ -1526,7 +1515,7 @@ pub fn claim_set_buy_should_works() { let player = new_account(0, 1000 * unit(GAKI)); let unit_price = 5 * unit(GAKI); - assert_ok!(PalletGame::set_buy( + assert_ok!(PalletGame::set_order( RuntimeOrigin::signed(player.clone()), TEST_BUNDLE[0].clone(), unit_price, @@ -1538,7 +1527,7 @@ pub fn claim_set_buy_should_works() { let amount = TEST_BUNDLE[0].clone().amount / 2; let seller_balance = Balances::free_balance(&seller); - assert_ok!(PalletGame::claim_set_buy( + assert_ok!(PalletGame::sell_item( RuntimeOrigin::signed(seller.clone()), 0, amount, @@ -1587,7 +1576,7 @@ fn cancel_trade_should_works() { // set buy { let player = new_account(0, 1000 * unit(GAKI)); - assert_ok!(PalletGame::set_buy( + assert_ok!(PalletGame::set_order( RuntimeOrigin::signed(player.clone()), TEST_BUNDLE[0].clone(), unit(GAKI), @@ -1622,7 +1611,7 @@ fn cancel_trade_should_works() { // wishlist { let player = new_account(0, 1000 * unit(GAKI)); - assert_ok!(PalletGame::set_wishlist( + assert_ok!(PalletGame::order_bundle( RuntimeOrigin::signed(player.clone()), TEST_BUNDLE.clone().to_vec(), unit(GAKI), @@ -1639,7 +1628,7 @@ fn cancel_trade_should_works() { // swap { let player = funded_account_with_item(TEST_BUNDLE.clone()); - assert_ok!(PalletGame::set_swap( + assert_ok!(PalletGame::create_swap( RuntimeOrigin::signed(player.clone()), TEST_BUNDLE.clone().to_vec(), TEST_BUNDLE1.clone().to_vec(), @@ -1686,7 +1675,6 @@ fn create_stable_pool_should_works() { RuntimeOrigin::signed(admin.clone()), 0, 0, - default_item_config(), None )); @@ -1694,7 +1682,6 @@ fn create_stable_pool_should_works() { RuntimeOrigin::signed(admin.clone()), 0, 1, - default_item_config(), None )); @@ -1702,7 +1689,6 @@ fn create_stable_pool_should_works() { RuntimeOrigin::signed(admin.clone()), 0, 2, - default_item_config(), None )); @@ -1732,7 +1718,6 @@ fn create_stable_pool_should_fails() { RuntimeOrigin::signed(admin.clone()), 0, 0, - default_item_config(), None )); @@ -1740,7 +1725,6 @@ fn create_stable_pool_should_fails() { RuntimeOrigin::signed(admin.clone()), 0, 1, - default_item_config(), None )); @@ -1758,7 +1742,6 @@ fn create_stable_pool_should_fails() { RuntimeOrigin::signed(admin.clone()), 0, 2, - default_item_config(), Some(1000) )); @@ -1782,13 +1765,7 @@ fn create_dynamic_pool_should_works() { do_create_collection(0, &admin); for package in TEST_BUNDLE.clone() { - do_create_item( - &admin, - package.collection, - package.item, - &default_item_config(), - package.amount, - ); + do_create_item(&admin, package.collection, package.item, package.amount); } let owner_balance = Balances::free_balance(owner.clone()); diff --git a/game/pallet-game/src/trades/retail.rs b/game/pallet-game/src/trades/retail.rs index 0df000ae..68f1f2bb 100644 --- a/game/pallet-game/src/trades/retail.rs +++ b/game/pallet-game/src/trades/retail.rs @@ -173,7 +173,7 @@ impl, I: 'static> Err(Error::::UnknownTrade.into()) } - fn do_add_retail_supply( + fn do_add_set_price( trade: &T::TradeId, who: &T::AccountId, supply: Package, diff --git a/game/pallet-game/src/types.rs b/game/pallet-game/src/types.rs index 7564037f..09c00b92 100644 --- a/game/pallet-game/src/types.rs +++ b/game/pallet-game/src/types.rs @@ -126,7 +126,7 @@ pub struct MintRequest { pub(super) target: AccountId, /// Number of mint request - pub(super) amount: u32, + pub(super) amount: Amount, /// Mining fee of the pool pub(super) mining_fee: Balance, diff --git a/game/pallet-game/src/weights.rs b/game/pallet-game/src/weights.rs index 0cf5a67f..bf61e468 100644 --- a/game/pallet-game/src/weights.rs +++ b/game/pallet-game/src/weights.rs @@ -52,20 +52,20 @@ pub trait WeightInfo { fn buy_item() -> Weight; fn set_bundle(s: u32, ) -> Weight; fn buy_bundle() -> Weight; - fn set_wishlist(s: u32, ) -> Weight; - fn claim_wishlist() -> Weight; + fn order_bundle(s: u32, ) -> Weight; + fn sell_bundle() -> Weight; fn remove_collection() -> Weight; - fn set_swap(s: u32, x: u32, ) -> Weight; - fn claim_swap() -> Weight; + fn create_swap(s: u32, x: u32, ) -> Weight; + fn make_swap() -> Weight; fn set_auction(s: u32, ) -> Weight; fn bid_auction() -> Weight; - fn claim_auction() -> Weight; - fn set_buy() -> Weight; - fn claim_set_buy() -> Weight; + fn close_auction() -> Weight; + fn set_order() -> Weight; + fn sell_item() -> Weight; fn create_collection() -> Weight; fn set_accept_adding() -> Weight; fn add_game_collection() -> Weight; - fn add_retail_supply() -> Weight; + fn add_set_price() -> Weight; fn cancel_trade() -> Weight; fn create_dynamic_pool(s: u32, ) -> Weight; fn create_stable_pool(s: u32, ) -> Weight; @@ -344,7 +344,7 @@ impl WeightInfo for SubstrateWeight { /// Storage: Game TradeConfigOf (r:0 w:1) /// Proof: Game TradeConfigOf (max_values: None, max_size: Some(202), added: 2677, mode: MaxEncodedLen) /// The range of component `s` is `[0, 10]`. - fn set_wishlist(s: u32, ) -> Weight { + fn order_bundle(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `179` // Estimated: `3606` @@ -367,7 +367,7 @@ impl WeightInfo for SubstrateWeight { /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Game ItemBalanceOf (r:4 w:4) /// Proof: Game ItemBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) - fn claim_wishlist() -> Weight { + fn sell_bundle() -> Weight { // Proof Size summary in bytes: // Measured: `986` // Estimated: `11226` @@ -407,7 +407,7 @@ impl WeightInfo for SubstrateWeight { /// Proof: Game TradeConfigOf (max_values: None, max_size: Some(202), added: 2677, mode: MaxEncodedLen) /// The range of component `s` is `[0, 10]`. /// The range of component `x` is `[0, 10]`. - fn set_swap(s: u32, x: u32, ) -> Weight { + fn create_swap(s: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `294` // Estimated: `3606` @@ -430,7 +430,7 @@ impl WeightInfo for SubstrateWeight { /// Proof: Game ReservedBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) /// Storage: System Account (r:1 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - fn claim_swap() -> Weight { + fn make_swap() -> Weight { // Proof Size summary in bytes: // Measured: `726` // Estimated: `11226` @@ -490,7 +490,7 @@ impl WeightInfo for SubstrateWeight { /// Proof: Game ReservedBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) /// Storage: Game ItemBalanceOf (r:2 w:2) /// Proof: Game ItemBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) - fn claim_auction() -> Weight { + fn close_auction() -> Weight { // Proof Size summary in bytes: // Measured: `712` // Estimated: `6108` @@ -507,7 +507,7 @@ impl WeightInfo for SubstrateWeight { /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Game TradeConfigOf (r:0 w:1) /// Proof: Game TradeConfigOf (max_values: None, max_size: Some(202), added: 2677, mode: MaxEncodedLen) - fn set_buy() -> Weight { + fn set_order() -> Weight { // Proof Size summary in bytes: // Measured: `109` // Estimated: `3606` @@ -528,7 +528,7 @@ impl WeightInfo for SubstrateWeight { /// Proof: Game ItemBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) /// Storage: System Account (r:1 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - fn claim_set_buy() -> Weight { + fn sell_item() -> Weight { // Proof Size summary in bytes: // Measured: `871` // Estimated: `3667` @@ -604,7 +604,7 @@ impl WeightInfo for SubstrateWeight { /// Proof: Game ItemBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) /// Storage: Game ReservedBalanceOf (r:1 w:1) /// Proof: Game ReservedBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) - fn add_retail_supply() -> Weight { + fn add_set_price() -> Weight { // Proof Size summary in bytes: // Measured: `874` // Estimated: `3667` @@ -968,7 +968,7 @@ impl WeightInfo for () { /// Storage: Game TradeConfigOf (r:0 w:1) /// Proof: Game TradeConfigOf (max_values: None, max_size: Some(202), added: 2677, mode: MaxEncodedLen) /// The range of component `s` is `[0, 10]`. - fn set_wishlist(s: u32, ) -> Weight { + fn order_bundle(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `179` // Estimated: `3606` @@ -991,7 +991,7 @@ impl WeightInfo for () { /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Game ItemBalanceOf (r:4 w:4) /// Proof: Game ItemBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) - fn claim_wishlist() -> Weight { + fn sell_bundle() -> Weight { // Proof Size summary in bytes: // Measured: `986` // Estimated: `11226` @@ -1031,7 +1031,7 @@ impl WeightInfo for () { /// Proof: Game TradeConfigOf (max_values: None, max_size: Some(202), added: 2677, mode: MaxEncodedLen) /// The range of component `s` is `[0, 10]`. /// The range of component `x` is `[0, 10]`. - fn set_swap(s: u32, x: u32, ) -> Weight { + fn create_swap(s: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `294` // Estimated: `3606` @@ -1054,7 +1054,7 @@ impl WeightInfo for () { /// Proof: Game ReservedBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) /// Storage: System Account (r:1 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - fn claim_swap() -> Weight { + fn make_swap() -> Weight { // Proof Size summary in bytes: // Measured: `726` // Estimated: `11226` @@ -1114,7 +1114,7 @@ impl WeightInfo for () { /// Proof: Game ReservedBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) /// Storage: Game ItemBalanceOf (r:2 w:2) /// Proof: Game ItemBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) - fn claim_auction() -> Weight { + fn close_auction() -> Weight { // Proof Size summary in bytes: // Measured: `712` // Estimated: `6108` @@ -1131,7 +1131,7 @@ impl WeightInfo for () { /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: Game TradeConfigOf (r:0 w:1) /// Proof: Game TradeConfigOf (max_values: None, max_size: Some(202), added: 2677, mode: MaxEncodedLen) - fn set_buy() -> Weight { + fn set_order() -> Weight { // Proof Size summary in bytes: // Measured: `109` // Estimated: `3606` @@ -1152,7 +1152,7 @@ impl WeightInfo for () { /// Proof: Game ItemBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) /// Storage: System Account (r:1 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - fn claim_set_buy() -> Weight { + fn sell_item() -> Weight { // Proof Size summary in bytes: // Measured: `871` // Estimated: `3667` @@ -1228,7 +1228,7 @@ impl WeightInfo for () { /// Proof: Game ItemBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) /// Storage: Game ReservedBalanceOf (r:1 w:1) /// Proof: Game ReservedBalanceOf (max_values: None, max_size: Some(84), added: 2559, mode: MaxEncodedLen) - fn add_retail_supply() -> Weight { + fn add_set_price() -> Weight { // Proof Size summary in bytes: // Measured: `874` // Estimated: `3667` diff --git a/support/src/game/game.rs b/support/src/game/game.rs index 331c9168..b2dde9bb 100644 --- a/support/src/game/game.rs +++ b/support/src/game/game.rs @@ -107,7 +107,6 @@ pub trait CreateItem { who: &AccountId, collection: &CollectionId, item: &ItemId, - config: &ItemConfig, maybe_supply: Option, ) -> DispatchResult; @@ -335,7 +334,7 @@ pub trait Retail { /// - `who`: seller /// - `collection`: collection id /// - `item`: item id - fn do_add_retail_supply( + fn do_add_set_price( trade: &TradeId, who: &AccountId, supply: Package, diff --git a/support/src/game/types.rs b/support/src/game/types.rs index c222b37b..69c5482a 100644 --- a/support/src/game/types.rs +++ b/support/src/game/types.rs @@ -13,7 +13,7 @@ pub type LootTable = Vec>; pub struct Package { pub collection: CollectionId, pub item: ItemId, - pub amount: u32, + pub amount: Amount, } impl Package {