Skip to content

Commit

Permalink
auth-server: fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
joeykraut committed Jan 21, 2025
1 parent f4feb0e commit bd8bf0e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions auth/auth-server/src/telemetry/quote_comparison/handler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Defines the quote comparison handler
use ethers::utils::format_units;
use ethers::{providers::Middleware, types::U256};
use futures_util::future::join_all;
Expand All @@ -20,8 +22,11 @@ use super::{price_reporter_client::PriceReporterClient, QuoteComparison};

/// Records metrics comparing quotes from different sources
pub struct QuoteComparisonHandler {
/// The sources to compare quotes from
sources: Vec<QuoteSource>,
/// The arbitrum client
arbitrum_client: ArbitrumClient,
/// The price reporter client
price_reporter_client: PriceReporterClient,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! A client for the price reporter
use renegade_common::types::{exchange::Exchange, token::Token};

use crate::telemetry::sources::http_utils::{send_get_request, HttpError};
Expand All @@ -7,16 +9,19 @@ pub const PRICE_ROUTE: &str = "/price";
/// Default timeout for requests to the price reporter
const DEFAULT_TIMEOUT_SECS: u64 = 5;

/// A client for the price reporter
pub struct PriceReporterClient {
/// The base URL of the price reporter
base_url: String,
}

impl PriceReporterClient {
/// Create a new PriceReporterClient
pub fn new(base_url: &str) -> Self {
Self { base_url: base_url.to_string() }
}

/// Get the price of a token from the price reporter
pub async fn get_binance_price(&self, mint: &str) -> Result<Option<f64>, HttpError> {
let exchange = Exchange::Binance;
let quote_mint = Token::from_ticker("USDT").get_addr();
Expand Down
6 changes: 6 additions & 0 deletions auth/auth-server/src/telemetry/sources/http_utils.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
//! Utilities for HTTP requests
use reqwest::{Client, Response};
use serde::Serialize;
use std::time::Duration;
use thiserror::Error;

/// An error with the HTTP client
#[derive(Debug, Error)]
pub enum HttpError {
/// A network error
#[error("Network error: {0}")]
Network(String, #[source] reqwest::Error),

/// An API error
#[error("API error: {0}")]
Api(String),
}

/// Sends a basic GET request
pub async fn send_get_request(url: &str, timeout_secs: u64) -> Result<Response, HttpError> {
let client = Client::builder()
.timeout(Duration::from_secs(timeout_secs))
Expand Down
2 changes: 2 additions & 0 deletions auth/auth-server/src/telemetry/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ impl QuoteSource {
}

impl QuoteSource {
/// Creates a new quote source for the Odos API
pub fn odos(config: odos::OdosConfig) -> Self {
QuoteSource::Odos(odos::OdosQuoteSource::new(config))
}

/// Creates a new quote source for the Odos API with default configuration
pub fn odos_default() -> Self {
Self::odos(odos::OdosConfig::default())
}
Expand Down
8 changes: 7 additions & 1 deletion auth/auth-server/src/telemetry/sources/odos/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! A client for the Odos API
use super::types::{OdosQuoteRequest, OdosQuoteResponse};
use crate::telemetry::sources::http_utils::{send_post_request, HttpError};

Expand All @@ -11,9 +13,13 @@ const BASE_URL: &str = "https://api.odos.xyz";
const QUOTE_ROUTE: &str = "/sor/quote/v2";

// Default configuration values
const DEFAULT_CHAIN_ID: u64 = 42161; // Arbitrum
/// Default chain ID for the target blockchain (Arbitrum)
const DEFAULT_CHAIN_ID: u64 = 42161;
/// Default value for disabling RFQs
const DEFAULT_DISABLE_RFQS: bool = false;
/// Default slippage limit as a percentage
const DEFAULT_SLIPPAGE_LIMIT_PERCENT: f64 = 0.3;
/// Default request timeout in seconds
const DEFAULT_TIMEOUT_SECS: u64 = 5;

/// Configuration options for the Odos client
Expand Down
4 changes: 4 additions & 0 deletions auth/auth-server/src/telemetry/sources/odos/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//! Error types for the Odos client
use thiserror::Error;

/// An error with the Odos client
#[derive(Debug, Error)]
pub enum OdosError {
/// An error with the input
#[error("Invalid input: {0}")]
Input(String),
}
2 changes: 2 additions & 0 deletions auth/auth-server/src/telemetry/sources/odos/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! A client for the Odos API
mod client;
mod error;
mod types;
Expand Down
6 changes: 6 additions & 0 deletions auth/auth-server/src/telemetry/sources/odos/types.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//! Types for the Odos API
use super::{client::OdosConfig, error::OdosError};
use serde::{Deserialize, Serialize};

/// Request structure for the Odos API quote endpoint.
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[allow(clippy::missing_docs_in_private_items)]
pub(crate) struct OdosQuoteRequest {
pub chain_id: u64,
pub input_tokens: Vec<InputToken>,
Expand All @@ -15,6 +18,7 @@ pub(crate) struct OdosQuoteRequest {
/// Response structure from the Odos API quote endpoint.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
#[allow(clippy::missing_docs_in_private_items)]
pub(crate) struct OdosQuoteResponse {
pub in_amounts: Vec<String>,
pub in_tokens: Vec<String>,
Expand All @@ -25,13 +29,15 @@ pub(crate) struct OdosQuoteResponse {

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[allow(clippy::missing_docs_in_private_items)]
pub(crate) struct InputToken {
pub token_address: String,
pub amount: String,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[allow(clippy::missing_docs_in_private_items)]
pub(crate) struct OutputToken {
pub token_address: String,
pub proportion: f32,
Expand Down

0 comments on commit bd8bf0e

Please sign in to comment.