Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: collection and trait offers #7

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl From<Network> for Url {
/// [`Payload`](crate::schema::Payload).
#[derive(Clone, Copy, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum Event {
/// An item been listed for sale.
ItemListed,
Expand All @@ -95,4 +96,8 @@ pub enum Event {
ItemReceivedOffer,
/// An item has received a bid.
ItemReceivedBid,
/// A collection has received an offer.
CollectionOffer,
/// A collection has received a trait offer.
TraitOffer,
}
77 changes: 77 additions & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct StreamEvent {
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "event_type", content = "payload")]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum Payload {
/// An item has been listed for sale.
ItemListed(ItemListedData),
Expand All @@ -40,6 +41,10 @@ pub enum Payload {
ItemReceivedOffer(ItemReceivedOfferData),
/// An item has received a bid.
ItemReceivedBid(ItemReceivedBidData),
/// A collection has received an offer.
CollectionOffer(CollectionOfferData),
/// A collection has received a trait offer.
TraitOffer(TraitOfferData),
}

impl From<Payload> for Event {
Expand All @@ -52,6 +57,8 @@ impl From<Payload> for Event {
Payload::ItemCancelled(_) => Event::ItemCancelled,
Payload::ItemReceivedOffer(_) => Event::ItemReceivedOffer,
Payload::ItemReceivedBid(_) => Event::ItemReceivedBid,
Payload::CollectionOffer(_) => Event::CollectionOffer,
Payload::TraitOffer(_) => Event::TraitOffer,
}
}
}
Expand Down Expand Up @@ -451,6 +458,76 @@ pub struct ItemReceivedBidData {
pub taker: Option<Address>,
}

/// Payload data for [`Payload::CollectionOffer`].
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CollectionOfferData {
/// Context
#[serde(flatten)]
pub context: Context,

/// Timestamp of when the bid was received.
pub event_timestamp: DateTime<Utc>,
/// Bid price. See `payment_token` for the actual value of each unit.
#[serde(with = "u256_fromstr_radix_10")]
pub base_price: U256,
/// Timestamp of when the bid was created.
pub created_date: DateTime<Utc>,
/// Timestamp of when the bid will expire.
pub expiration_date: DateTime<Utc>,
/// Creator of the bid.
#[serde(with = "address_fromjson")]
pub maker: Address,
/// Hash id of the listing.
pub order_hash: H256,
/// Token offered for payment.
pub payment_token: PaymentToken,
/// Number of items on the offer. This is always `1` for ERC-721 tokens.
pub quantity: u64,
/// Taker of the bid.
#[serde(with = "address_fromjson_opt", default)]
pub taker: Option<Address>,
/// Collection criteria.
pub collection_criteria: serde_json::Value,
/// Asset contract criteria.
pub asset_contract_criteria: serde_json::Value,
}

/// Payload data for [`Payload::TraitOffer`].
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct TraitOfferData {
/// Context
#[serde(flatten)]
pub context: Context,

/// Timestamp of when the bid was received.
pub event_timestamp: DateTime<Utc>,
/// Bid price. See `payment_token` for the actual value of each unit.
#[serde(with = "u256_fromstr_radix_10")]
pub base_price: U256,
/// Timestamp of when the bid was created.
pub created_date: DateTime<Utc>,
/// Timestamp of when the bid will expire.
pub expiration_date: DateTime<Utc>,
/// Creator of the bid.
#[serde(with = "address_fromjson")]
pub maker: Address,
/// Hash id of the listing.
pub order_hash: H256,
/// Token offered for payment.
pub payment_token: PaymentToken,
/// Number of items on the offer. This is always `1` for ERC-721 tokens.
pub quantity: u64,
/// Taker of the bid.
#[serde(with = "address_fromjson_opt", default)]
pub taker: Option<Address>,
/// Collection criteria.
pub collection_criteria: serde_json::Value,
/// Asset contract criteria.
pub asset_contract_criteria: serde_json::Value,
/// Trait criteria.
pub trait_criteria: serde_json::Value,
}

/// Auctioning system used by the listing.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "lowercase")]
Expand Down
Loading