From d4d99edb481a59dcf43feedc3aefe2f34f803abe Mon Sep 17 00:00:00 2001 From: Andrew Kirillov Date: Wed, 11 Sep 2024 11:41:49 -0700 Subject: [PATCH] wip --- Cargo.lock | 1 - .../events-collector-api/Cargo.toml | 1 - .../events-collector-api/src/types/events.rs | 26 +++---- .../events-collector-server/src/db/models.rs | 73 +++++++++++++++++++ 4 files changed, 84 insertions(+), 17 deletions(-) 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 b0b5998..0287062 100644 --- a/events-collector/events-collector-api/src/types/events.rs +++ b/events-collector/events-collector-api/src/types/events.rs @@ -1,6 +1,7 @@ //! Event types collected by the events collector -use alloy_primitives::Address; +use alloy_primitives::{Address, U256}; +use renegade_common::types::exchange::Exchange; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -45,8 +46,8 @@ pub struct OrderPlacement { /// The mint of the quote asset in the order pub quote_mint: Address, /// The amount of the base asset in the order - pub amount: u128, - /// Whether or not the order is to sell the base asset + pub amount: U256, + /// Whether the order is selling the base asset pub is_sell: bool, } @@ -60,16 +61,10 @@ pub struct OrderCancellation { pub wallet_id: Uuid, /// The ID of the order being cancelled pub order_id: Uuid, - /// The mint of the base asset in the order - pub base_mint: Address, - /// The mint of the quote asset in the order - pub quote_mint: Address, - /// The remaining amount of the base asset in the order - pub amount_remaining: u128, - /// The filled amount of the base asset in the order - pub amount_filled: u128, - /// Whether or not the order is to sell the base asset - pub is_sell: bool, + // 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 @@ -90,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. @@ -102,7 +97,8 @@ pub struct Match { /// The amount of the base asset exchanged in the match pub base_amount: u128, /// The amount of the quote asset exchanged in the match - pub quote_amount: u128, + 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, +}