Skip to content

Commit

Permalink
issue #1 - added storage fees to relevant auction pallet extrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
chexware committed Jul 19, 2023
1 parent 45531b3 commit 180cd0c
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 110 deletions.
14 changes: 14 additions & 0 deletions pallets/auction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,13 @@ pub mod pallet {
Error::<T>::AuctionTypeIsNotSupported
);

T::Currency::transfer(
&from,
&T::MetaverseInfoSource::get_network_treasury(),
T::StorageDepositFee::get(),
ExistenceRequirement::KeepAlive,
)?;

Self::auction_bid_handler(from, id, value)?;

Ok(().into())
Expand Down Expand Up @@ -527,6 +534,13 @@ pub mod pallet {
listing_fee = T::MetaverseInfoSource::get_metaverse_marketplace_listing_fee(metaverse_id)?;
}

T::Currency::transfer(
&from,
&T::MetaverseInfoSource::get_network_treasury(),
T::StorageDepositFee::get(),
ExistenceRequirement::KeepAlive,
)?;

Self::create_auction(
AuctionType::BuyNow,
item_id,
Expand Down
10 changes: 5 additions & 5 deletions pallets/auction/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ fn asset_transfers_after_auction() {
// BOB only receive 200 - 2 (1% royalty fee) - 2 (1% network fee) - 4 (minting fee) = 193
// 500 + 193 = 693
assert_eq!(Balances::free_balance(BOB), 692);
assert_eq!(Balances::free_balance(ALICE), 99800);
assert_eq!(Balances::free_balance(ALICE), 99799);

// Verify Alice has the NFT and Bob doesn't
assert_eq!(NFTModule::<Runtime>::check_ownership(&ALICE, &(0, 0)), Ok(true));
Expand Down Expand Up @@ -1595,7 +1595,7 @@ fn on_finalize_should_work() {
// check account received asset
assert_eq!(NFTModule::<Runtime>::check_ownership(&ALICE, &(0, 0)), Ok(true));
// check balances were transferred
assert_eq!(Balances::free_balance(ALICE), 99900);
assert_eq!(Balances::free_balance(ALICE), 99899);
// BOB's initial balance is 500
// 100 - 1 (1% of 100 as royalty fee) - 1 (1% of 100 as network fee) - 3 minting fee = 96
// 500 + 95 = 595
Expand Down Expand Up @@ -1639,8 +1639,8 @@ fn on_finalize_with_listing_fee_should_work() {
// check account received asset
assert_eq!(NFTModule::<Runtime>::check_ownership(&BOB, &(0, 0)), Ok(true));
// check balances were transferred
// Bob bid 100 for item, his new balance will be 500 - 100
assert_eq!(Balances::free_balance(BOB), 400);
// Bob bid 100 for item, his new balance will be 500 - 100 - 1
assert_eq!(Balances::free_balance(BOB), 399);
// Alice only receive 88 for item sold:
// cost breakdown 100 - 10 (listing fee) - 1 (1% network fee) - 1 (1% royalty fee) - 1 unit (class
// stroage fee) Free balance of Alice is 99996 + 88 = 100084
Expand Down Expand Up @@ -1740,7 +1740,7 @@ fn on_finalize_with_bundle_with_listing_fee_should_work() {
assert_eq!(NFTModule::<Runtime>::check_ownership(&BOB, &(0, 1)), Ok(true));
// check balances were transferred
// Bob bid 400 for item, his new balance will be 500 - 400
assert_eq!(Balances::free_balance(BOB), 100);
assert_eq!(Balances::free_balance(BOB), 99);
// Alice only receive 176 for item solds
// Cost breakdown 400 - 4 (royalty) - 4 (1% network fee) - 40 (listing fee) = 352
// Free balance of Alice is 99992 + 352 = 100344
Expand Down
110 changes: 56 additions & 54 deletions pallets/auction/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Autogenerated weights for auction
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-06-21, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-07-19, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024

// Executed Command:
Expand Down Expand Up @@ -75,15 +75,17 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Storage: Me
// Proof Skipped: Auction Auctions (max_values: None, max_size: None, mode: Measured)
fn create_new_auction() -> Weight {
// Proof Size summary in bytes:
// Measured: `3359`
// Estimated: `54013`
// Minimum execution time: 75_737 nanoseconds.
Weight::from_parts(83_359_000, 54013)
// Measured: `3695`
// Estimated: `57373`
// Minimum execution time: 59_917 nanoseconds.
Weight::from_parts(61_885_000, 57373)
.saturating_add(T::DbWeight::get().reads(9))
.saturating_add(T::DbWeight::get().writes(7))
}
// Storage: Metaverse Metaverses (r:1 w:0)
// Proof Skipped: Metaverse Metaverses (max_values: None, max_size: None, mode: Measured)
// Storage: System Account (r:2 w:2)
// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
// Storage: Auction ItemsInAuction (r:1 w:1)
// Proof Skipped: Auction ItemsInAuction (max_values: None, max_size: None, mode: Measured)
// Storage: OrmlNFT Tokens (r:1 w:1)
Expand All @@ -96,8 +98,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Storage: Me
// Proof Skipped: Metaverse MetaverseOwner (max_values: None, max_size: None, mode: Measured)
// Storage: Auction AuctionEndTime (r:1 w:1)
// Proof Skipped: Auction AuctionEndTime (max_values: None, max_size: None, mode: Measured)
// Storage: System Account (r:1 w:1)
// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
// Storage: Auction AuctionsIndex (r:1 w:1)
// Proof Skipped: Auction AuctionsIndex (max_values: Some(1), max_size: None, mode: Measured)
// Storage: Auction AuctionItems (r:0 w:1)
Expand All @@ -106,15 +106,17 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Storage: Me
// Proof Skipped: Auction Auctions (max_values: None, max_size: None, mode: Measured)
fn create_new_buy_now() -> Weight {
// Proof Size summary in bytes:
// Measured: `3359`
// Estimated: `54013`
// Minimum execution time: 58_587 nanoseconds.
Weight::from_parts(60_938_000, 54013)
.saturating_add(T::DbWeight::get().reads(9))
.saturating_add(T::DbWeight::get().writes(7))
// Measured: `3868`
// Estimated: `61706`
// Minimum execution time: 72_460 nanoseconds.
Weight::from_parts(74_722_000, 61706)
.saturating_add(T::DbWeight::get().reads(10))
.saturating_add(T::DbWeight::get().writes(8))
}
// Storage: Auction AuctionItems (r:1 w:1)
// Proof Skipped: Auction AuctionItems (max_values: None, max_size: None, mode: Measured)
// Storage: System Account (r:2 w:2)
// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
// Storage: Auction Auctions (r:1 w:1)
// Proof Skipped: Auction Auctions (max_values: None, max_size: None, mode: Measured)
// Storage: Tokens Accounts (r:1 w:1)
Expand All @@ -123,12 +125,12 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Storage: Me
// Proof Skipped: Auction AuctionEndTime (max_values: None, max_size: None, mode: Measured)
fn bid() -> Weight {
// Proof Size summary in bytes:
// Measured: `3236`
// Estimated: `17254`
// Minimum execution time: 50_075 nanoseconds.
Weight::from_parts(52_851_000, 17254)
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(5))
// Measured: `4133`
// Estimated: `25151`
// Minimum execution time: 64_755 nanoseconds.
Weight::from_parts(75_918_000, 25151)
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(7))
}
// Storage: Auction AuctionItems (r:1 w:1)
// Proof Skipped: Auction AuctionItems (max_values: None, max_size: None, mode: Measured)
Expand All @@ -154,10 +156,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Storage: Me
// Proof Skipped: OrmlNFT TokensByOwner (max_values: None, max_size: None, mode: Measured)
fn buy_now() -> Weight {
// Proof Size summary in bytes:
// Measured: `4659`
// Estimated: `74974`
// Minimum execution time: 113_286 nanoseconds.
Weight::from_parts(117_267_000, 74974)
// Measured: `5079`
// Estimated: `78754`
// Minimum execution time: 117_209 nanoseconds.
Weight::from_parts(121_030_000, 78754)
.saturating_add(T::DbWeight::get().reads(13))
.saturating_add(T::DbWeight::get().writes(12))
}
Expand All @@ -175,10 +177,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Storage: Me
// Proof Skipped: Auction AuctionEndTime (max_values: None, max_size: None, mode: Measured)
fn cancel_listing() -> Weight {
// Proof Size summary in bytes:
// Measured: `3664`
// Estimated: `28348`
// Minimum execution time: 50_526 nanoseconds.
Weight::from_parts(76_276_000, 28348)
// Measured: `4000`
// Estimated: `30028`
// Minimum execution time: 49_038 nanoseconds.
Weight::from_parts(50_823_000, 30028)
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(6))
}
Expand All @@ -190,8 +192,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Storage: Me
// Proof Size summary in bytes:
// Measured: `1307`
// Estimated: `7564`
// Minimum execution time: 30_845 nanoseconds.
Weight::from_parts(35_078_000, 7564)
// Minimum execution time: 21_943 nanoseconds.
Weight::from_parts(23_046_000, 7564)
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand All @@ -203,8 +205,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Storage: Me
// Proof Size summary in bytes:
// Measured: `1360`
// Estimated: `7670`
// Minimum execution time: 22_308 nanoseconds.
Weight::from_parts(24_963_000, 7670)
// Minimum execution time: 22_905 nanoseconds.
Weight::from_parts(23_607_000, 7670)
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand All @@ -220,8 +222,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Storage: Me
// Proof Size summary in bytes:
// Measured: `1805`
// Estimated: `15443`
// Minimum execution time: 36_403 nanoseconds.
Weight::from_parts(38_021_000, 15443)
// Minimum execution time: 36_625 nanoseconds.
Weight::from_parts(38_079_000, 15443)
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(2))
}
Expand All @@ -233,8 +235,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Storage: Me
// Proof Size summary in bytes:
// Measured: `1534`
// Estimated: `6612`
// Minimum execution time: 28_040 nanoseconds.
Weight::from_parts(29_056_000, 6612)
// Minimum execution time: 27_880 nanoseconds.
Weight::from_parts(28_621_000, 6612)
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
}
Expand All @@ -256,72 +258,72 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { // Storage: Me
// Proof Size summary in bytes:
// Measured: `2326`
// Estimated: `31537`
// Minimum execution time: 67_215 nanoseconds.
Weight::from_parts(69_244_000, 31537)
// Minimum execution time: 68_875 nanoseconds.
Weight::from_parts(72_454_000, 31537)
.saturating_add(T::DbWeight::get().reads(7))
.saturating_add(T::DbWeight::get().writes(6))
}
fn on_finalize() -> Weight {
// Proof Size summary in bytes:
// Measured: `774`
// Estimated: `0`
// Minimum execution time: 5_355 nanoseconds.
Weight::from_parts(6_116_000, 0)
// Minimum execution time: 5_673 nanoseconds.
Weight::from_parts(7_467_000, 0)
}
}

// For backwards compatibility and tests
impl WeightInfo for () { fn create_new_auction() -> Weight {
Weight::from_parts(83_359_000, 54013)
Weight::from_parts(61_885_000, 57373)
.saturating_add(RocksDbWeight::get().reads(9))
.saturating_add(RocksDbWeight::get().writes(7))
}
fn create_new_buy_now() -> Weight {
Weight::from_parts(60_938_000, 54013)
.saturating_add(RocksDbWeight::get().reads(9))
.saturating_add(RocksDbWeight::get().writes(7))
Weight::from_parts(74_722_000, 61706)
.saturating_add(RocksDbWeight::get().reads(10))
.saturating_add(RocksDbWeight::get().writes(8))
}
fn bid() -> Weight {
Weight::from_parts(52_851_000, 17254)
.saturating_add(RocksDbWeight::get().reads(3))
.saturating_add(RocksDbWeight::get().writes(5))
Weight::from_parts(75_918_000, 25151)
.saturating_add(RocksDbWeight::get().reads(5))
.saturating_add(RocksDbWeight::get().writes(7))
}
fn buy_now() -> Weight {
Weight::from_parts(117_267_000, 74974)
Weight::from_parts(121_030_000, 78754)
.saturating_add(RocksDbWeight::get().reads(13))
.saturating_add(RocksDbWeight::get().writes(12))
}
fn cancel_listing() -> Weight {
Weight::from_parts(76_276_000, 28348)
Weight::from_parts(50_823_000, 30028)
.saturating_add(RocksDbWeight::get().reads(4))
.saturating_add(RocksDbWeight::get().writes(6))
}
fn authorise_metaverse_collection() -> Weight {
Weight::from_parts(35_078_000, 7564)
Weight::from_parts(23_046_000, 7564)
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(1))
}
fn remove_authorise_metaverse_collection() -> Weight {
Weight::from_parts(24_963_000, 7670)
Weight::from_parts(23_607_000, 7670)
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(1))
}
fn make_offer() -> Weight {
Weight::from_parts(38_021_000, 15443)
Weight::from_parts(38_079_000, 15443)
.saturating_add(RocksDbWeight::get().reads(4))
.saturating_add(RocksDbWeight::get().writes(2))
}
fn withdraw_offer() -> Weight {
Weight::from_parts(29_056_000, 6612)
Weight::from_parts(28_621_000, 6612)
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(2))
}
fn accept_offer() -> Weight {
Weight::from_parts(69_244_000, 31537)
Weight::from_parts(72_454_000, 31537)
.saturating_add(RocksDbWeight::get().reads(7))
.saturating_add(RocksDbWeight::get().writes(6))
}
fn on_finalize() -> Weight {
Weight::from_parts(6_116_000, 0)
Weight::from_parts(7_467_000, 0)
}
}
7 changes: 5 additions & 2 deletions runtime/continuum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ parameter_types! {
pub const OfferDuration: BlockNumber = 100800; // Default 100800 Blocks
pub const MinimumListingPrice: Balance = DOLLARS;
pub const AntiSnipeDuration: BlockNumber = 50; // Minimum anti snipe duration is 50 blocks
pub const ContinuumStorageDeposit: Balance = BASE_STORAGE_FEE;
pub const AuctionStorageFee: Balance = 3 * BASE_STORAGE_FEE;
}

impl auction::Config for Runtime {
Expand All @@ -1565,9 +1565,12 @@ impl auction::Config for Runtime {
type OfferDuration = OfferDuration;
type MinimumListingPrice = MinimumListingPrice;
type AntiSnipeDuration = AntiSnipeDuration;
type StorageDepositFee = StorageDepositFee;
type StorageDepositFee = AuctionStorageFee;
}

parameter_types! {
pub const ContinuumStorageDeposit: Balance = BASE_STORAGE_FEE;
}
impl continuum::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SessionDuration = ContinuumSessionDuration;
Expand Down
Loading

0 comments on commit 180cd0c

Please sign in to comment.