Skip to content

Commit

Permalink
Rework marketplace-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
tasiov committed Apr 1, 2024
1 parent 74abf03 commit 0ea24ad
Show file tree
Hide file tree
Showing 43 changed files with 3,352 additions and 6,775 deletions.
945 changes: 785 additions & 160 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions contracts/marketplace-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ cw2 = "1.1.2"
cw721 = "0.18.0"
cw721-base = { version = "0.18.0", features = ["library"] }

sg-marketplace-common = "1.2.0"
sg-marketplace-common = { path = "../../packages/sg-marketplace-common" }
sg-index-query = "0.1.1"
sg-std = "2.1.0"
sg1 = "2.1.0"
sg2 = "2.1.0"
sg2 = { git = "https://github.com/public-awesome/launchpad.git", rev = "897d3ab057d381c1654c7246f3972ddd9f9238ce", package = "sg2" }
sg-controllers = "2.1.0"
stargaze-royalty-registry = { version = "0.3.0", features = ["library"] }
stargaze-fair-burn = { version = "1.0.4", features = ["library"] }
stargaze-royalty-registry = { git = "https://github.com/public-awesome/core.git", rev = "2b18f1fb294af6458fa7374a82204c47546c5615", package = "stargaze-royalty-registry" }
sg721-base = { version = "2.1.0", features = ["library"] }
sg721 = { version = "2.1.0", features = ["library"] }

serde = "1.0.196"
semver = "1.0.21"
thiserror = "1.0.56"
sha2 = "0.10.0"
digest = "0.10.0"

[dev-dependencies]
cw-multi-test = "0.16.2"
sg-multi-test = "2.1.0"
vending-factory = "2.1.0"
vending-minter = "2.1.0"
base-minter = "2.1.0"
test-suite = "2.1.0"
cw-multi-test = "0.20.0"
test-suite = { git = "https://github.com/public-awesome/launchpad.git", rev = "897d3ab057d381c1654c7246f3972ddd9f9238ce", package = "test-suite" }
vending-factory = { git = "https://github.com/public-awesome/launchpad.git", rev = "897d3ab057d381c1654c7246f3972ddd9f9238ce", package = "vending-factory" }
vending-minter = { git = "https://github.com/public-awesome/launchpad.git", rev = "897d3ab057d381c1654c7246f3972ddd9f9238ce", package = "vending-minter" }
base-minter = { git = "https://github.com/public-awesome/launchpad.git", rev = "897d3ab057d381c1654c7246f3972ddd9f9238ce", package = "base-minter" }
cute = "0.3.0"
anyhow = "1.0.79"

Expand Down
22 changes: 8 additions & 14 deletions contracts/marketplace-v2/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{Coin, StdError};
use cosmwasm_std::{OverflowError, StdError};
use cw_utils::PaymentError;
use sg_marketplace_common::MarketplaceStdError;
use stargaze_royalty_registry::ContractError as RoyaltyRegistryError;
Expand All @@ -9,6 +9,9 @@ pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),

#[error("{0}")]
OverflowError(#[from] OverflowError),

#[error("{0}")]
PaymentError(#[from] PaymentError),

Expand All @@ -18,21 +21,12 @@ pub enum ContractError {
#[error("{0}")]
RoyaltyRegistryError(#[from] RoyaltyRegistryError),

#[error("InternalError: {0}")]
InternalError(String),

#[error("InvalidInput: {0}")]
InvalidInput(String),

#[error("InsufficientFunds: expected {expected}")]
InsufficientFunds { expected: Coin },
#[error("InsufficientFunds")]
InsufficientFunds,

#[error("EntityNotFound: {0}")]
EntityNotFound(String),

#[error("EntityExists: {0}")]
EntityExists(String),

#[error("EntityNotExpired: {0}")]
EntityNotExpired(String),
#[error("InternalError: {0}")]
InternalError(String),
}
180 changes: 81 additions & 99 deletions contracts/marketplace-v2/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,115 +1,97 @@
use crate::state::Ask;
use crate::{
orders::{Ask, CollectionOffer, Offer},
state::{AllowDenoms, Config},
};

use cosmwasm_std::Event;
use cosmwasm_std::{attr, Addr, Event};
use std::vec;

pub struct AskEvent<'a> {
pub struct ConfigEvent<'a> {
pub ty: &'a str,
pub ask: &'a Ask,
pub config: &'a Config<Addr>,
}

impl<'a> From<AskEvent<'a>> for Event {
fn from(ae: AskEvent) -> Self {
Event::new(ae.ty.to_string()).add_attributes(ae.ask.get_event_attrs(vec![
"collection",
"token_id",
"creator",
"price",
"asset_recipient",
"finders_fee_bps",
"expiration",
"removal_reward",
]))
impl<'a> From<ConfigEvent<'a>> for Event {
fn from(ce: ConfigEvent) -> Self {
Event::new(ce.ty.to_string()).add_attributes(vec![
attr("fee_manager", ce.config.fee_manager.to_string()),
attr("royalty_registry", ce.config.royalty_registry.to_string()),
attr("protocol_fee_bps", ce.config.protocol_fee_bps.to_string()),
attr(
"max_royalty_fee_bps",
ce.config.max_royalty_fee_bps.to_string(),
),
attr("maker_reward_bps", ce.config.maker_reward_bps.to_string()),
attr("taker_reward_bps", ce.config.taker_reward_bps.to_string()),
])
}
}

// pub struct UpdatePairEvent<'a> {
// pub ty: &'a str,
// pub pair: &'a Pair,
// }

// impl<'a> From<UpdatePairEvent<'a>> for Event {
// fn from(pe: UpdatePairEvent) -> Self {
// Event::new(pe.ty.to_string()).add_attributes(pe.pair.get_event_attrs(vec![
// "pair_type",
// "swap_fee_percent",
// "reinvest_tokens",
// "reinvest_nfts",
// "bonding_curve",
// "spot_price",
// "delta",
// "is_active",
// "asset_recipient",
// ]))
// }
// }

// pub struct NftTransferEvent<'a> {
// pub ty: &'a str,
// pub pair: &'a Pair,
// pub token_ids: &'a Vec<String>,
// }

// impl<'a> From<NftTransferEvent<'a>> for Event {
// fn from(nte: NftTransferEvent) -> Self {
// Event::new(nte.ty.to_string())
// .add_attributes(nte.pair.get_event_attrs(vec!["total_nfts"]))
// .add_attributes(nte.token_ids.iter().map(|token_id| ("token_id", token_id)))
// }
// }

// pub struct TokenTransferEvent<'a> {
// pub ty: &'a str,
// pub funds: &'a Coin,
// }

// impl<'a> From<TokenTransferEvent<'a>> for Event {
// fn from(tte: TokenTransferEvent) -> Self {
// Event::new(tte.ty.to_string()).add_attribute("funds", tte.funds.to_string())
// }
// }
pub struct AllowDenomsEvent<'a> {
pub ty: &'a str,
pub allow_denoms: &'a AllowDenoms,
}

// pub struct SwapEvent<'a> {
// pub ty: &'a str,
// pub pair: &'a Pair,
// pub token_id: &'a str,
// pub sender_recipient: &'a Addr,
// pub quote_summary: &'a QuoteSummary,
// }
impl<'a> From<AllowDenomsEvent<'a>> for Event {
fn from(ade: AllowDenomsEvent) -> Self {
let mut event = Event::new(ade.ty.to_string());

let enum_type = match &ade.allow_denoms {
AllowDenoms::Includes(_) => "includes",
AllowDenoms::Excludes(_) => "excludes",
};
event = event.add_attribute("type", enum_type);

match &ade.allow_denoms {
AllowDenoms::Includes(denoms) => {
for denom in denoms {
event = event.add_attribute("denom", denom);
}
}
AllowDenoms::Excludes(denoms) => {
for denom in denoms {
event = event.add_attribute("denom", denom);
}
}
}

event
}
}

// impl<'a> From<SwapEvent<'a>> for Event {
// fn from(se: SwapEvent) -> Self {
// let mut event = Event::new(se.ty.to_string())
// .add_attributes(se.pair.get_event_attrs(vec!["spot_price", "is_active"]));
pub struct AskEvent<'a> {
pub ty: &'a str,
pub ask: &'a Ask,
pub attr_keys: Vec<&'a str>,
}

// event = event.add_attributes(vec![
// attr("token_id", se.token_id),
// attr("sender_recipient", se.sender_recipient),
// attr("fair_burn_fee", se.quote_summary.fair_burn.amount),
// attr("seller_amount", se.quote_summary.seller_amount),
// ]);
impl<'a> From<AskEvent<'a>> for Event {
fn from(ae: AskEvent) -> Self {
Event::new(ae.ty.to_string()).add_attributes(ae.ask.get_event_attrs(ae.attr_keys))
}
}

// if let Some(royalty) = se.quote_summary.royalty.as_ref() {
// event = event.add_attribute("royalty_fee", royalty.amount);
// }
// if let Some(swap) = se.quote_summary.swap.as_ref() {
// event = event.add_attribute("swap_fee", swap.amount);
// }
pub struct OfferEvent<'a> {
pub ty: &'a str,
pub offer: &'a Offer,
pub attr_keys: Vec<&'a str>,
}

// event
// }
// }
impl<'a> From<OfferEvent<'a>> for Event {
fn from(oe: OfferEvent) -> Self {
Event::new(oe.ty.to_string()).add_attributes(oe.offer.get_event_attrs(oe.attr_keys))
}
}

// pub struct PairInternalEvent<'a> {
// pub pair: &'a Pair,
// }
pub struct CollectionOfferEvent<'a> {
pub ty: &'a str,
pub collection_offer: &'a CollectionOffer,
pub attr_keys: Vec<&'a str>,
}

// impl<'a> From<PairInternalEvent<'a>> for Event {
// fn from(pie: PairInternalEvent) -> Self {
// Event::new("pair-internal".to_string()).add_attributes(pie.pair.get_event_attrs(vec![
// "total_tokens",
// "sell_to_pair_quote",
// "buy_from_pair_quote",
// ]))
// }
// }
impl<'a> From<CollectionOfferEvent<'a>> for Event {
fn from(coe: CollectionOfferEvent) -> Self {
Event::new(coe.ty.to_string())
.add_attributes(coe.collection_offer.get_event_attrs(coe.attr_keys))
}
}
Loading

0 comments on commit 0ea24ad

Please sign in to comment.