Skip to content

Commit

Permalink
events-collector: events-collector-server: create unaugmented event s…
Browse files Browse the repository at this point in the history
…chema & models
  • Loading branch information
akirillo committed Sep 12, 2024
1 parent b3fd8ba commit a9a4dc6
Show file tree
Hide file tree
Showing 15 changed files with 472 additions and 14 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"funds-manager/funds-manager-server",
"price-reporter",
"events-collector/events-collector-api",
"events-collector/events-collector-server",
]

[profile.bench]
Expand Down Expand Up @@ -44,3 +45,4 @@ uuid = { version = "1.8", features = ["v4"] }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1" }
tokio = { version = "1.37", features = ["full"] }
bigdecimal = { version = "0.4", features = ["serde"] }
9 changes: 9 additions & 0 deletions events-collector/diesel.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# For documentation on how to configure this file,
# see https://diesel.rs/guides/configuring-diesel-cli

[print_schema]
file = "events-collector-server/src/db/schema.rs"
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"]

[migrations_directory]
dir = "./migrations"
26 changes: 13 additions & 13 deletions events-collector/events-collector-api/src/types/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ use uuid::Uuid;
/// Wallet creation event
#[derive(Serialize, Deserialize)]
pub struct WalletCreation {
/// The wallet ID
/// The ID of the wallet that was created
pub wallet_id: Uuid,
}

/// Deposit event
#[derive(Serialize, Deserialize)]
pub struct Deposit {
/// The wallet ID
/// The ID of the wallet that made the deposit
pub wallet_id: Uuid,
/// The mint of the asset being deposited
/// The mint of the asset that was deposited
pub mint: Address,
/// The amount of the deposit
pub amount: u128,
Expand All @@ -25,9 +25,9 @@ pub struct Deposit {
/// Withdrawal event
#[derive(Serialize, Deserialize)]
pub struct Withdrawal {
/// The wallet ID
/// The ID of the wallet that made the withdrawal
pub wallet_id: Uuid,
/// The mint of the asset being withdrawn
/// The mint of the asset that was withdrawn
pub mint: Address,
/// The amount of the withdrawal
pub amount: u128,
Expand All @@ -36,9 +36,9 @@ pub struct Withdrawal {
/// Order placement event
#[derive(Serialize, Deserialize)]
pub struct OrderPlacement {
/// The ID of the wallet placing the order
/// The ID of the wallet that placed the order
pub wallet_id: Uuid,
/// The ID of the order being placed
/// The ID of the order that was placed
pub order_id: Uuid,
/// The mint of the base asset in the order
pub base_mint: Address,
Expand All @@ -53,9 +53,9 @@ pub struct OrderPlacement {
/// Order cancellation event
#[derive(Serialize, Deserialize)]
pub struct OrderCancellation {
/// The ID of the wallet cancelling the order
/// The ID of the wallet that cancelled the order
pub wallet_id: Uuid,
/// The ID of the order being cancelled
/// The ID of the order that was cancelled
pub order_id: Uuid,
/// The mint of the base asset in the order
pub base_mint: Address,
Expand Down Expand Up @@ -95,9 +95,9 @@ pub struct Match {
/// Fee payment event
#[derive(Serialize, Deserialize)]
pub struct FeePayment {
/// The ID of the wallet paying the fee
/// The ID of the wallet that paid the fee
pub wallet_id: Uuid,
/// The mint of the asset being paid
/// The mint of the asset that was paid
pub mint: Address,
/// The amount of the fee
pub amount: u128,
Expand All @@ -106,9 +106,9 @@ pub struct FeePayment {
/// Fee collection event
#[derive(Serialize, Deserialize)]
pub struct FeeCollection {
/// The ID of the wallet collecting the fee
/// The ID of the wallet that collected the fee
pub wallet_id: Uuid,
/// The mint of the asset being collected
/// The mint of the asset that was collected
pub mint: Address,
/// The amount of the fee
pub amount: u128,
Expand Down
13 changes: 13 additions & 0 deletions events-collector/events-collector-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "events-collector-server"
version = "0.1.0"
edition = "2021"

[dependencies]
# === Database === #
diesel = { workspace = true, features = ["postgres", "numeric", "uuid"] }
diesel-async = { workspace = true, features = ["postgres", "bb8"] }

# === Misc === #
uuid = { workspace = true }
bigdecimal = { workspace = true }
7 changes: 7 additions & 0 deletions events-collector/events-collector-server/src/db/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Database code

pub mod models;

#[allow(missing_docs)]
#[allow(clippy::missing_docs_in_private_items)]
pub mod schema;
173 changes: 173 additions & 0 deletions events-collector/events-collector-server/src/db/models.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
//! Events collector database models

use std::time::SystemTime;

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

/// A wallet creation record
#[derive(Insertable)]
#[diesel(table_name = crate::db::schema::wallet_creations)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct WalletCreation {
/// The event ID
pub event_id: Uuid,
/// The event timestamp
pub event_timestamp: SystemTime,

/// The ID of the wallet that was created
pub wallet_id: Uuid,
}

/// 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 event timestamp
pub event_timestamp: SystemTime,

/// The ID of the wallet that made the deposit
pub wallet_id: Uuid,
/// The mint of the asset that was deposited
pub mint: String,
/// The amount of the deposit
pub amount: BigDecimal,
}

/// 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 event timestamp
pub event_timestamp: SystemTime,

/// The ID of the wallet that made the withdrawal
pub wallet_id: Uuid,
/// The mint of the asset that was withdrawn
pub mint: String,
/// The amount of the withdrawal
pub amount: BigDecimal,
}

/// 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 event timestamp
pub event_timestamp: SystemTime,

/// The ID of the wallet that placed the order
pub wallet_id: Uuid,
/// The ID of the order that was 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 or not the order is to sell the base asset
pub is_sell: bool,
}

/// 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 event timestamp
pub event_timestamp: SystemTime,

/// The ID of the wallet that cancelled the order
pub wallet_id: Uuid,
/// The ID of the order that was cancelled
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 remaining amount of the base asset in the order
pub amount_remaining: BigDecimal,
/// The filled amount of the base asset in the order
pub amount_filled: BigDecimal,
/// Whether or not the order is to sell the base asset
pub is_sell: bool,
}

/// A match record
#[derive(Insertable)]
#[diesel(table_name = crate::db::schema::matches)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Match {
/// The event ID
pub event_id: Uuid,
/// The event timestamp
pub event_timestamp: SystemTime,

/// The ID of the first wallet in the match
pub wallet_id_0: Uuid,
/// The ID of the second wallet in the match
pub wallet_id_1: Uuid,
/// The ID of the first order in the match
pub order_id_0: Uuid,
/// The ID of the second order in the match
pub order_id_1: Uuid,
/// Whether party 0 sold or bought the base asset
pub party_0_sells: bool,
/// The mint of the base asset in the match
pub base_mint: String,
/// The mint of the quote asset in the match
pub quote_mint: String,
/// The amount of the base asset exchanged in the match
pub base_amount: BigDecimal,
/// The amount of the quote asset exchanged in the match
pub quote_amount: BigDecimal,
}

/// A fee payment record
#[derive(Insertable)]
#[diesel(table_name = crate::db::schema::fee_payments)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct FeePayment {
/// The event ID
pub event_id: Uuid,
/// The event timestamp
pub event_timestamp: SystemTime,

/// The ID of the wallet that paid the fee
pub wallet_id: Uuid,
/// The mint of the asset that was paid
pub mint: String,
/// The amount of the fee
pub amount: BigDecimal,
}

/// A fee collection record
#[derive(Insertable)]
#[diesel(table_name = crate::db::schema::fee_collections)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct FeeCollection {
/// The event ID
pub event_id: Uuid,
/// The event timestamp
pub event_timestamp: SystemTime,

/// The ID of the wallet that collected the fee
pub wallet_id: Uuid,
/// The mint of the asset that was collected
pub mint: String,
/// The amount of the fee
pub amount: BigDecimal,
}
Loading

0 comments on commit a9a4dc6

Please sign in to comment.