Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
akirillo committed Sep 11, 2024
1 parent 59649c6 commit ef86bc4
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 6 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion events-collector/events-collector-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2021"
[dependencies]

# === Renegade === #
renegade-circuit-types = { workspace = true }
renegade-common = { workspace = true }

# === Blockchain === #
Expand Down
12 changes: 8 additions & 4 deletions events-collector/events-collector-api/src/types/events.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down
73 changes: 73 additions & 0 deletions events-collector/events-collector-server/src/db/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::time::SystemTime;

use bigdecimal::BigDecimal;
use diesel::prelude::*;
use uuid::Uuid;

Expand All @@ -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,
}

0 comments on commit ef86bc4

Please sign in to comment.