Skip to content

Commit

Permalink
Merge pull request #5 from paritytech/marketplace-mock-update
Browse files Browse the repository at this point in the history
update marketplace mock
  • Loading branch information
José Molina Colmenero authored Feb 15, 2024
2 parents 553dc87 + 750fca3 commit bba26f4
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 28 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

# dotfiles in the repo root
/.*
target/
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Mythical Testnet
# Mythical Parachain Node

### 🔰 Description

Mythical is a Web3 gaming platform. Building an NFT marketplace based on old chain (private Ethereum) Solidity Smart Contracts, integration with Mythical backend, bridge integration, and migrating chain state from old contracts.
Parachain node for the Mythical Games blockchain platform.

### 🦀 Rust Setup
### 🦀 Setup

First, complete the [basic Rust setup instructions](./docs/rust-setup.md).

Expand Down
3 changes: 2 additions & 1 deletion pallets/marketplace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ sp-std = { workspace = true }
sp-runtime = { workspace = true, default-features = false }
pallet-nfts = { workspace = true, default-features = false }
sp-core = { workspace = true, default-features = false }
pallet-balances = { workspace = true, default-features = false }
pallet-timestamp = { workspace = true, default-features = false }

[dev-dependencies]
sp-io = { workspace = true, default-features = false }
pallet-balances = { workspace = true, default-features = false }

[features]
default = ["std"]
Expand Down
33 changes: 20 additions & 13 deletions pallets/marketplace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ pub mod pallet {
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config: frame_system::Config + pallet_nfts::Config {
pub trait Config:
frame_system::Config + pallet_nfts::Config + pallet_timestamp::Config
{
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

type RuntimeCall: Parameter
Expand All @@ -44,7 +46,7 @@ pub mod pallet {

/// The minimum amount of time for an ask duration.
#[pallet::constant]
type MinOrderDuration: Get<BlockNumberFor<Self>>;
type MinOrderDuration: Get<Self::Moment>;

/// Used for calculation of fees
#[pallet::constant]
Expand Down Expand Up @@ -96,7 +98,7 @@ pub mod pallet {
NMapKey<Blake2_128Concat, T::ItemId>,
NMapKey<Blake2_128Concat, BalanceOf<T>>,
),
Bid<T::AccountId, BlockNumberFor<T>>,
Bid<T::AccountId, BlockNumberFor<T>, BalanceOf<T>>,
>;

#[pallet::storage]
Expand Down Expand Up @@ -147,13 +149,11 @@ pub mod pallet {
/// An Ask/Bid order was created.
OrderCreated {
who: T::AccountId,
order: Order<
T::CollectionId,
T::ItemId,
BalanceOf<T>,
BlockNumberFor<T>,
BoundedVec<u8, T::NonceStringLimit>,
>,
order_type: OrderType,
collection: T::CollectionId,
item: T::ItemId,
price: BalanceOf<T>,
expires_at: T::Moment,
},
/// A trade of Ask and Bid was executed.
OrderExecuted {
Expand Down Expand Up @@ -325,7 +325,7 @@ pub mod pallet {
T::CollectionId,
T::ItemId,
BalanceOf<T>,
BlockNumberFor<T>,
T::Moment,
BoundedVec<u8, T::NonceStringLimit>,
>,
) -> DispatchResult {
Expand All @@ -335,7 +335,14 @@ pub mod pallet {
// - If orderType Ask is received then an orderCreated event is emitted
//- If orderType Bid is received then an orderExecuted event is emitted
match order.clone().order_type {
OrderType::Ask => Self::deposit_event(Event::OrderCreated { who, order }),
OrderType::Ask => Self::deposit_event(Event::OrderCreated {
who,
order_type: order.order_type,
collection: order.collection,
item: order.item,
price: order.price,
expires_at: order.expires_at,
}),
OrderType::Bid => Self::deposit_event(Event::OrderExecuted {
collection: order.collection,
item: order.item,
Expand Down Expand Up @@ -406,7 +413,7 @@ pub mod pallet {
exchange: HashId,
collection: T::CollectionId,
item: T::ItemId,
fee: Permill,
fee: BalanceOf<T>,
) -> DispatchResult {
let who = ensure_signed(origin)?;

Expand Down
19 changes: 9 additions & 10 deletions pallets/marketplace/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use frame_support::traits::Currency;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::Permill;

use crate::Config;

Expand All @@ -15,14 +14,14 @@ pub struct Ask<AccountId, Amount, Expiration> {
pub seller: AccountId,
pub price: Amount,
pub expiration: Expiration,
pub fee: Permill,
pub fee: Amount,
}

#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo, MaxEncodedLen)]
pub struct Bid<AccountId, Expiration> {
pub struct Bid<AccountId, Expiration, Amount> {
pub buyer: AccountId,
pub expiration: Expiration,
pub fee: Permill,
pub fee: Amount,
}

#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)]
Expand All @@ -32,13 +31,13 @@ pub enum OrderType {
}

#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)]
pub struct Order<CollectionId, ItemId, Price, Expiration, BoundedString> {
pub struct Order<CollectionId, ItemId, Amount, Expiration, BoundedString> {
pub order_type: OrderType,
pub collection: CollectionId,
pub item: ItemId,
pub price: Price,
pub price: Amount,
pub expires_at: Expiration,
pub fee_percent: Permill,
pub fee_percent: Amount,
pub signature_data: SignatureData<BoundedString>,
}

Expand All @@ -53,23 +52,23 @@ pub struct Suggestion<CollectionId, ItemId, Amount, AccountId> {
pub collection: CollectionId,
pub item: ItemId,
pub price: Amount,
pub fee_percent: Permill,
pub fee_percent: Amount,
pub suggestion_fill: SuggestionFill<AccountId, Amount>,
}

#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo, MaxEncodedLen)]
pub struct SuggestionFill<AccountId, Amount> {
who: AccountId,
value: Amount,
fee: Permill,
fee: Amount,
}

#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo, MaxEncodedLen)]
pub struct WantAsk<CollectionId, ItemId, Amount> {
pub collection: CollectionId,
pub item: ItemId,
pub price: Amount,
pub fee_percent: Permill,
pub fee_percent: Amount,
}
#[derive(Clone, Encode, Decode, Debug, PartialEq, Eq, TypeInfo)]
pub struct ExecSuggestion<BoundedString> {
Expand Down
2 changes: 1 addition & 1 deletion runtime/devnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl pallet_marketplace::Config for Runtime {
type Currency = Balances;
type MaxExchangeItems = ConstU32<100>;
type MaxBasisPoints = ConstU128<10000>;
type MinOrderDuration = ConstU32<10>;
type MinOrderDuration = ConstU64<10>;
type NonceStringLimit = ConstU32<50>;
}

Expand Down

0 comments on commit bba26f4

Please sign in to comment.