diff --git a/Cargo.lock b/Cargo.lock index 9071a2f..1883e3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2960,7 +2960,6 @@ name = "events-collector-api" version = "0.1.0" dependencies = [ "alloy-primitives", - "circuit-types", "common", "serde", "serde_json", diff --git a/events-collector/events-collector-api/Cargo.toml b/events-collector/events-collector-api/Cargo.toml index 01104b3..385fd02 100644 --- a/events-collector/events-collector-api/Cargo.toml +++ b/events-collector/events-collector-api/Cargo.toml @@ -6,7 +6,6 @@ edition = "2021" [dependencies] # === Renegade === # -renegade-circuit-types = { workspace = true } renegade-common = { workspace = true } # === Blockchain === # diff --git a/events-collector/events-collector-api/src/types/events.rs b/events-collector/events-collector-api/src/types/events.rs index 4a30a5a..99471d1 100644 --- a/events-collector/events-collector-api/src/types/events.rs +++ b/events-collector/events-collector-api/src/types/events.rs @@ -1,7 +1,6 @@ //! Event types collected by the events collector use alloy_primitives::{Address, U256}; -use renegade_circuit_types::order::OrderSide; use renegade_common::types::exchange::Exchange; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -48,8 +47,8 @@ pub struct OrderPlacement { pub quote_mint: Address, /// The amount of the base asset in the order pub amount: U256, - /// The side of the order - pub side: OrderSide, + /// Whether the order is selling the base asset + pub is_sell: bool, } /// Order cancellation event @@ -62,6 +61,10 @@ pub struct OrderCancellation { pub wallet_id: Uuid, /// The ID of the order being cancelled pub order_id: Uuid, + // TODO: replicate all order info, i.e. pair & side + // TODO: amount filled, amount cancelled + // TODO: time since last fill + // TODO: time since creation } /// Match event @@ -82,7 +85,7 @@ pub struct Match { /// The ID of the second order in the match pub order_id_1: Uuid, /// Whether party 0 sold or bought the base. - /// + /// /// This can generally be inferred by querying for the order, /// but since order IDs can get overwritten in the relayer /// it is not reliable. @@ -95,6 +98,7 @@ pub struct Match { pub base_amount: U256, /// The amount of the quote asset exchanged in the match pub quote_amount: U256, + // TODO: Time since last fill, total fill for both orders? } /// Fee payment event diff --git a/events-collector/events-collector-server/src/db/models.rs b/events-collector/events-collector-server/src/db/models.rs index 2efcc0c..f0a7d6e 100644 --- a/events-collector/events-collector-server/src/db/models.rs +++ b/events-collector/events-collector-server/src/db/models.rs @@ -2,6 +2,7 @@ use std::time::SystemTime; +use bigdecimal::BigDecimal; use diesel::prelude::*; use uuid::Uuid; @@ -21,3 +22,75 @@ pub struct WalletCreation { /// The timestamp of the wallet creation pub ts: SystemTime, } + +/// A deposit record +#[derive(Insertable)] +#[diesel(table_name = crate::db::schema::deposits)] +#[diesel(check_for_backend(diesel::pg::Pg))] +pub struct Deposit { + /// The event ID + pub event_id: Uuid, + /// The wallet ID + pub wallet_id: Uuid, + /// The mint of the asset being deposited + pub mint: String, + /// The amount of the deposit + pub amount: BigDecimal, + /// The timestamp of the deposit + pub ts: SystemTime, +} + +/// A withdrawal record +#[derive(Insertable)] +#[diesel(table_name = crate::db::schema::withdrawals)] +#[diesel(check_for_backend(diesel::pg::Pg))] +pub struct Withdrawal { + /// The event ID + pub event_id: Uuid, + /// The wallet ID + pub wallet_id: Uuid, + /// The mint of the asset being withdrawn + pub mint: String, + /// The amount of the withdrawal + pub amount: BigDecimal, + /// The timestamp of the withdrawal + pub ts: SystemTime, +} + +/// An order placement record +#[derive(Insertable)] +#[diesel(table_name = crate::db::schema::order_placements)] +#[diesel(check_for_backend(diesel::pg::Pg))] +pub struct OrderPlacement { + /// The event ID + pub event_id: Uuid, + /// The ID of the wallet placing the order + pub wallet_id: Uuid, + /// The ID of the order being placed + pub order_id: Uuid, + /// The mint of the base asset in the order + pub base_mint: String, + /// The mint of the quote asset in the order + pub quote_mint: String, + /// The amount of the base asset in the order + pub amount: BigDecimal, + /// Whether the order is selling the base asset + pub is_sell: bool, + /// The timestamp of the order placement + pub ts: SystemTime, +} + +/// An order cancellation record +#[derive(Insertable)] +#[diesel(table_name = crate::db::schema::order_cancellations)] +#[diesel(check_for_backend(diesel::pg::Pg))] +pub struct OrderCancellation { + /// The event ID + pub event_id: Uuid, + /// The ID of the wallet placing the order + pub wallet_id: Uuid, + /// The ID of the order being placed + pub order_id: Uuid, + /// The timestamp of the order placement + pub ts: SystemTime, +}