From b3fd8ba22237c55dddac2561343560bc47f83bc2 Mon Sep 17 00:00:00 2001 From: Andrew Kirillov Date: Tue, 10 Sep 2024 16:20:31 -0700 Subject: [PATCH] events-collector: events-collector-api: add routes & request types --- .../events-collector-api/src/constants/mod.rs | 3 + .../src/constants/routes.rs | 10 +++ .../events-collector-api/src/lib.rs | 1 + .../events-collector-api/src/types/events.rs | 62 ++++++++----------- .../events-collector-api/src/types/mod.rs | 2 + .../src/types/requests.rs | 49 +++++++++++++++ .../src/types/wallet_annotations.rs | 16 +++++ price-reporter/src/main.rs | 8 +-- 8 files changed, 110 insertions(+), 41 deletions(-) create mode 100644 events-collector/events-collector-api/src/constants/mod.rs create mode 100644 events-collector/events-collector-api/src/constants/routes.rs create mode 100644 events-collector/events-collector-api/src/types/requests.rs create mode 100644 events-collector/events-collector-api/src/types/wallet_annotations.rs diff --git a/events-collector/events-collector-api/src/constants/mod.rs b/events-collector/events-collector-api/src/constants/mod.rs new file mode 100644 index 0000000..39026f5 --- /dev/null +++ b/events-collector/events-collector-api/src/constants/mod.rs @@ -0,0 +1,3 @@ +//! Constants for the events collector API + +pub mod routes; diff --git a/events-collector/events-collector-api/src/constants/routes.rs b/events-collector/events-collector-api/src/constants/routes.rs new file mode 100644 index 0000000..34ca269 --- /dev/null +++ b/events-collector/events-collector-api/src/constants/routes.rs @@ -0,0 +1,10 @@ +//! Events collector API routes + +/// The ping route +pub const PING_ROUTE: &str = "ping"; + +/// The event submission route +pub const EVENT_SUBMISSION_ROUTE: &str = "events"; + +/// The wallet annotation route +pub const WALLET_ANNOTATION_ROUTE: &str = "wallet-annotations"; diff --git a/events-collector/events-collector-api/src/lib.rs b/events-collector/events-collector-api/src/lib.rs index 71dcce5..a99cec9 100644 --- a/events-collector/events-collector-api/src/lib.rs +++ b/events-collector/events-collector-api/src/lib.rs @@ -6,4 +6,5 @@ #![deny(clippy::needless_pass_by_ref_mut)] #![deny(clippy::missing_docs_in_private_items)] +pub mod constants; pub mod types; diff --git a/events-collector/events-collector-api/src/types/events.rs b/events-collector/events-collector-api/src/types/events.rs index 7605481..92359b3 100644 --- a/events-collector/events-collector-api/src/types/events.rs +++ b/events-collector/events-collector-api/src/types/events.rs @@ -1,8 +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 alloy_primitives::Address; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -21,7 +19,7 @@ pub struct Deposit { /// The mint of the asset being deposited pub mint: Address, /// The amount of the deposit - pub amount: U256, + pub amount: u128, } /// Withdrawal event @@ -32,7 +30,7 @@ pub struct Withdrawal { /// The mint of the asset being withdrawn pub mint: Address, /// The amount of the withdrawal - pub amount: U256, + pub amount: u128, } /// Order placement event @@ -47,48 +45,51 @@ 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: U256, - /// The side of the order - pub side: OrderSide, + pub amount: u128, + /// Whether or not the order is to sell the base asset + pub is_sell: bool, } /// Order cancellation event #[derive(Serialize, Deserialize)] pub struct OrderCancellation { - /// The ID of the wallet cancelling the order. - /// - /// While not strictly necessary, we include the wallet ID - /// because order IDs can get overwritten. + /// The ID of the wallet cancelling the order 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, } /// Match event #[derive(Serialize, Deserialize)] pub struct Match { - /// The ID of the first wallet in the match. - /// - /// While not strictly necessary, we include the wallet ID - /// because order IDs can get overwritten. + /// The ID of the first wallet in the match pub wallet_id_0: Uuid, - /// The ID of the second wallet in the match. - /// - /// While not strictly necessary, we include the wallet ID - /// because order IDs can get overwritten. + /// 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: Address, /// The mint of the quote asset in the match pub quote_mint: Address, /// The amount of the base asset exchanged in the match - pub base_amount: U256, + pub base_amount: u128, /// The amount of the quote asset exchanged in the match - pub quote_amount: U256, + pub quote_amount: u128, } /// Fee payment event @@ -99,7 +100,7 @@ pub struct FeePayment { /// The mint of the asset being paid pub mint: Address, /// The amount of the fee - pub amount: U256, + pub amount: u128, } /// Fee collection event @@ -110,18 +111,5 @@ pub struct FeeCollection { /// The mint of the asset being collected pub mint: Address, /// The amount of the fee - pub amount: U256, -} - -/// Price update event -#[derive(Serialize, Deserialize)] -pub struct PriceUpdate { - /// The ticker of the base asset - pub base_ticker: String, - /// The ticker of the quote asset - pub quote_ticker: String, - /// The price of the asset - pub price: f64, - /// The exchange the price is from - pub exchange: Exchange, + pub amount: u128, } diff --git a/events-collector/events-collector-api/src/types/mod.rs b/events-collector/events-collector-api/src/types/mod.rs index 1a400eb..128cdc6 100644 --- a/events-collector/events-collector-api/src/types/mod.rs +++ b/events-collector/events-collector-api/src/types/mod.rs @@ -1,3 +1,5 @@ //! API types for the events collector pub mod events; +pub mod requests; +pub mod wallet_annotations; diff --git a/events-collector/events-collector-api/src/types/requests.rs b/events-collector/events-collector-api/src/types/requests.rs new file mode 100644 index 0000000..cc1bba8 --- /dev/null +++ b/events-collector/events-collector-api/src/types/requests.rs @@ -0,0 +1,49 @@ +//! API request types for the events collector + +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +use super::{ + events::{ + Deposit, FeeCollection, FeePayment, Match, OrderCancellation, OrderPlacement, + WalletCreation, Withdrawal, + }, + wallet_annotations::WalletType, +}; + +/// A single enum wrapping all possible event payloads +#[derive(Serialize, Deserialize)] +pub enum EventPayload { + /// A wallet creation event payload + WalletCreation(WalletCreation), + /// A deposit event payload + Deposit(Deposit), + /// A withdrawal event payload + Withdrawal(Withdrawal), + /// An order placement event payload + OrderPlacement(OrderPlacement), + /// An order cancellation event payload + OrderCancellation(OrderCancellation), + /// A match event payload + Match(Match), + /// A fee payment event payload + FeePayment(FeePayment), + /// A fee collection event payload + FeeCollection(FeeCollection), +} + +/// A request to submit an event +#[derive(Serialize, Deserialize)] +pub struct EventSubmissionRequest { + /// The event to submit + pub event: EventPayload, +} + +/// A request to annotate a wallet +#[derive(Serialize, Deserialize)] +pub struct WalletAnnotationRequest { + /// The wallet to annotate + pub wallet_id: Uuid, + /// The type with which to annotate the wallet + pub wallet_type: WalletType, +} diff --git a/events-collector/events-collector-api/src/types/wallet_annotations.rs b/events-collector/events-collector-api/src/types/wallet_annotations.rs new file mode 100644 index 0000000..fa5efa6 --- /dev/null +++ b/events-collector/events-collector-api/src/types/wallet_annotations.rs @@ -0,0 +1,16 @@ +//! Wallet annotation types for the events collector + +use serde::{Deserialize, Serialize}; + +/// The type of a wallet +#[derive(Serialize, Deserialize)] +pub enum WalletType { + /// A user wallet + User, + /// A relayer wallet + Relayer, + /// A protocol wallet + Protocol, + /// A quoter wallet + Quoter, +} diff --git a/price-reporter/src/main.rs b/price-reporter/src/main.rs index 0129239..8d7ca2a 100644 --- a/price-reporter/src/main.rs +++ b/price-reporter/src/main.rs @@ -54,7 +54,7 @@ async fn main() -> Result<(), ServerError> { let (closure_tx, mut closure_rx) = unbounded_channel(); let global_price_streams = GlobalPriceStreams::new(closure_tx); - init_default_price_streams(&global_price_streams, exchange_conn_config.clone()).await?; + init_default_price_streams(&global_price_streams, &exchange_conn_config)?; // Bind the server to the given port let addr: SocketAddr = format!("0.0.0.0:{:?}", ws_port).parse().unwrap(); @@ -91,9 +91,9 @@ async fn main() -> Result<(), ServerError> { } /// Initialize price streams for all default token mapped pairs -async fn init_default_price_streams( +fn init_default_price_streams( global_price_streams: &GlobalPriceStreams, - config: ExchangeConnectionsConfig, + config: &ExchangeConnectionsConfig, ) -> Result<(), ServerError> { info!("Initializing default price streams"); @@ -107,7 +107,7 @@ async fn init_default_price_streams( } let base_token = Token::from_addr(&addr); - let supported_exchanges = get_supported_exchanges(&base_token, "e_token, &config); + let supported_exchanges = get_supported_exchanges(&base_token, "e_token, config); for exchange in supported_exchanges.into_iter() { init_price_stream( base_token.clone(),