Skip to content

Commit

Permalink
events-collector: events-collector-api: add routes & request types
Browse files Browse the repository at this point in the history
  • Loading branch information
akirillo committed Sep 11, 2024
1 parent 6d8bd8f commit b3fd8ba
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 41 deletions.
3 changes: 3 additions & 0 deletions events-collector/events-collector-api/src/constants/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Constants for the events collector API

pub mod routes;
10 changes: 10 additions & 0 deletions events-collector/events-collector-api/src/constants/routes.rs
Original file line number Diff line number Diff line change
@@ -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";
1 change: 1 addition & 0 deletions events-collector/events-collector-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
#![deny(clippy::needless_pass_by_ref_mut)]
#![deny(clippy::missing_docs_in_private_items)]

pub mod constants;
pub mod types;
62 changes: 25 additions & 37 deletions events-collector/events-collector-api/src/types/events.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
}
2 changes: 2 additions & 0 deletions events-collector/events-collector-api/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! API types for the events collector

pub mod events;
pub mod requests;
pub mod wallet_annotations;
49 changes: 49 additions & 0 deletions events-collector/events-collector-api/src/types/requests.rs
Original file line number Diff line number Diff line change
@@ -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,
}
Original file line number Diff line number Diff line change
@@ -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,
}
8 changes: 4 additions & 4 deletions price-reporter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");

Expand All @@ -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, &quote_token, &config);
let supported_exchanges = get_supported_exchanges(&base_token, &quote_token, config);
for exchange in supported_exchanges.into_iter() {
init_price_stream(
base_token.clone(),
Expand Down

0 comments on commit b3fd8ba

Please sign in to comment.