fix: resolve rustfmt configuration duplicate key error and apply consistent code formatting across all source files

This commit is contained in:
floor-licker
2025-12-05 19:09:06 -05:00
parent 5576d765ee
commit 9993e51c7f
29 changed files with 2540 additions and 1673 deletions
+14 -17
View File
@@ -15,17 +15,14 @@ use std::time::Instant;
fn bench_book_creation(c: &mut Criterion) {
c.bench_function("book_creation", |b| {
b.iter(|| {
let _book = OrderBook::new(
black_box("test_token".to_string()),
black_box(100),
);
let _book = OrderBook::new(black_box("test_token".to_string()), black_box(100));
});
});
}
fn bench_delta_application(c: &mut Criterion) {
let mut book = OrderBook::new("test_token".to_string(), 100);
// Pre-populate with some levels
for i in 1..=10 {
let price = Decimal::from(50 + i) / Decimal::from(100);
@@ -57,7 +54,7 @@ fn bench_delta_application(c: &mut Criterion) {
fn bench_best_price_lookup(c: &mut Criterion) {
let mut book = OrderBook::new("test_token".to_string(), 100);
// Pre-populate with levels
for i in 1..=20 {
let price = Decimal::from(50 + i) / Decimal::from(100);
@@ -84,7 +81,7 @@ fn bench_best_price_lookup(c: &mut Criterion) {
fn bench_book_snapshot(c: &mut Criterion) {
let mut book = OrderBook::new("test_token".to_string(), 100);
// Pre-populate with levels
for i in 1..=50 {
let price = Decimal::from(50 + i) / Decimal::from(100);
@@ -108,7 +105,7 @@ fn bench_book_snapshot(c: &mut Criterion) {
fn bench_market_impact_calculation(c: &mut Criterion) {
let mut book = OrderBook::new("test_token".to_string(), 100);
// Pre-populate with levels
for i in 1..=30 {
let price = Decimal::from(50 + i) / Decimal::from(100);
@@ -135,7 +132,7 @@ fn bench_high_frequency_updates(c: &mut Criterion) {
b.iter(|| {
let mut book = OrderBook::new("test_token".to_string(), 100);
let start_time = Instant::now();
// Simulate high-frequency updates
for i in 1..=1000 {
let price = Decimal::from(500 + (i % 100)) / Decimal::from(1000);
@@ -149,14 +146,14 @@ fn bench_high_frequency_updates(c: &mut Criterion) {
sequence: i,
};
book.apply_delta(delta).unwrap();
// Check prices every 10 updates
if i % 10 == 0 {
let _bid = book.best_bid();
let _ask = book.best_ask();
}
}
let duration = start_time.elapsed();
black_box(duration);
});
@@ -166,17 +163,17 @@ fn bench_high_frequency_updates(c: &mut Criterion) {
fn bench_concurrent_access(c: &mut Criterion) {
use std::sync::Arc;
use tokio::sync::RwLock;
c.bench_function("concurrent_access", |b| {
b.iter(|| {
let book = Arc::new(RwLock::new(OrderBook::new("test_token".to_string(), 100)));
let book_clone = book.clone();
// Simulate concurrent reads and writes
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let mut tasks = Vec::new();
// Spawn writer tasks
for i in 1..=10 {
let book = book.clone();
@@ -194,7 +191,7 @@ fn bench_concurrent_access(c: &mut Criterion) {
book.apply_delta(delta).unwrap();
}));
}
// Spawn reader tasks
for _ in 0..20 {
let book = book_clone.clone();
@@ -204,7 +201,7 @@ fn bench_concurrent_access(c: &mut Criterion) {
let _ask = book.best_ask();
}));
}
// Wait for all tasks
for task in tasks {
let _ = task.await;
@@ -224,4 +221,4 @@ criterion_group!(
bench_high_frequency_updates,
bench_concurrent_access,
);
criterion_main!(benches);
criterion_main!(benches);
+16 -12
View File
@@ -1,5 +1,5 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use polyfill_rs::{OrderArgs, Side, OrderBookImpl};
use polyfill_rs::{OrderArgs, OrderBookImpl, Side};
use rust_decimal::Decimal;
use std::str::FromStr;
@@ -14,7 +14,7 @@ fn benchmark_create_order_eip712(c: &mut Criterion) {
Decimal::from_str("100.0").unwrap(),
Side::BUY,
);
// Simulate the computational work of order creation
black_box(order_args)
})
@@ -24,7 +24,7 @@ fn benchmark_create_order_eip712(c: &mut Criterion) {
// Benchmark: JSON parsing (simulate market data parsing)
fn benchmark_json_parsing(c: &mut Criterion) {
let sample_json = r#"{"data":[{"condition_id":"test","question":"Test Question","description":"Test Description","end_date_iso":"2024-01-01T00:00:00Z","game_start_time":"2024-01-01T00:00:00Z","image":"","icon":"","active":true,"closed":false,"archived":false,"accepting_orders":true,"minimum_order_size":"1.0","minimum_tick_size":"0.01","market_slug":"test","seconds_delay":0,"fpmm":"0x123","rewards":{"min_size":"1.0","max_spread":"0.1"},"tokens":[{"token_id":"123","outcome":"Yes","price":"0.5","winner":false}]}]}"#;
c.bench_function("json_parsing_markets", |b| {
b.iter(|| {
// This benchmarks JSON parsing and deserialization
@@ -39,12 +39,12 @@ fn benchmark_order_book_operations(c: &mut Criterion) {
c.bench_function("order_book_updates", |b| {
b.iter(|| {
let mut book = OrderBookImpl::new("test_token".to_string(), 100);
// Simulate rapid order book updates
for i in 0..1000 {
let price = Decimal::from_str(&format!("0.{:04}", 5000 + (i % 100))).unwrap();
let size = Decimal::from_str("100.0").unwrap();
let bid_delta = polyfill_rs::OrderDelta {
token_id: "test_token".to_string(),
timestamp: chrono::Utc::now(),
@@ -53,10 +53,10 @@ fn benchmark_order_book_operations(c: &mut Criterion) {
size,
sequence: i as u64,
};
let _ = book.apply_delta(bid_delta);
}
black_box(book)
})
});
@@ -65,24 +65,28 @@ fn benchmark_order_book_operations(c: &mut Criterion) {
// Benchmark: Fast order book operations
fn benchmark_fast_operations(c: &mut Criterion) {
let mut book = OrderBookImpl::new("test_token".to_string(), 100);
// Pre-populate the book
for i in 0..50 {
let price = Decimal::from_str(&format!("0.{:04}", 5000 + i)).unwrap();
let size = Decimal::from_str("100.0").unwrap();
let delta = polyfill_rs::OrderDelta {
token_id: "test_token".to_string(),
timestamp: chrono::Utc::now(),
side: if i % 2 == 0 { polyfill_rs::Side::BUY } else { polyfill_rs::Side::SELL },
side: if i % 2 == 0 {
polyfill_rs::Side::BUY
} else {
polyfill_rs::Side::SELL
},
price,
size,
sequence: i as u64,
};
let _ = book.apply_delta(delta);
}
c.bench_function("fast_spread_mid_calculations", |b| {
b.iter(|| {
// These use fixed-point arithmetic internally
+16 -19
View File
@@ -16,11 +16,7 @@ use std::time::Instant;
fn bench_fill_engine_creation(c: &mut Criterion) {
c.bench_function("fill_engine_creation", |b| {
b.iter(|| {
let _engine = FillEngine::new(
black_box(dec!(1)),
black_box(dec!(5)),
black_box(10),
);
let _engine = FillEngine::new(black_box(dec!(1)), black_box(dec!(5)), black_box(10));
});
});
}
@@ -28,7 +24,7 @@ fn bench_fill_engine_creation(c: &mut Criterion) {
fn bench_market_order_execution(c: &mut Criterion) {
let mut engine = FillEngine::new(dec!(1), dec!(5), 10);
let mut book = OrderBook::new("test_token".to_string(), 100);
// Pre-populate book with levels
for i in 1..=20 {
let price = Decimal::from(50 + i) / Decimal::from(100);
@@ -52,7 +48,7 @@ fn bench_market_order_execution(c: &mut Criterion) {
slippage_tolerance: Some(dec!(1.0)),
client_id: Some("bench_order".to_string()),
};
let _result = engine.execute_market_order(&request, &book);
});
});
@@ -60,7 +56,7 @@ fn bench_market_order_execution(c: &mut Criterion) {
fn bench_fill_processor(c: &mut Criterion) {
let mut processor = FillProcessor::new(1000);
c.bench_function("fill_processor", |b| {
b.iter(|| {
let fill = FillEvent {
@@ -75,7 +71,7 @@ fn bench_fill_processor(c: &mut Criterion) {
taker_address: alloy_primitives::Address::ZERO,
fee: black_box(dec!(0.1)),
};
processor.process_fill(fill).unwrap();
});
});
@@ -83,7 +79,7 @@ fn bench_fill_processor(c: &mut Criterion) {
fn bench_market_impact_calculation(c: &mut Criterion) {
let mut book = OrderBook::new("test_token".to_string(), 100);
// Pre-populate with realistic order book
for i in 1..=30 {
let price = Decimal::from(50 + i) / Decimal::from(100);
@@ -113,7 +109,7 @@ fn bench_high_frequency_fills(c: &mut Criterion) {
let mut engine = FillEngine::new(dec!(1), dec!(2), 5);
let mut book = OrderBook::new("test_token".to_string(), 100);
let start_time = Instant::now();
// Simulate high-frequency fill processing
for i in 1..=100 {
// Add some market depth
@@ -128,7 +124,7 @@ fn bench_high_frequency_fills(c: &mut Criterion) {
sequence: i,
};
book.apply_delta(delta).unwrap();
// Execute market orders
if i % 5 == 0 {
let request = MarketOrderRequest {
@@ -138,11 +134,11 @@ fn bench_high_frequency_fills(c: &mut Criterion) {
slippage_tolerance: Some(dec!(1.0)),
client_id: Some(format!("order_{}", i)),
};
let _result = engine.execute_market_order(&request, &book);
}
}
let duration = start_time.elapsed();
black_box(duration);
});
@@ -151,7 +147,7 @@ fn bench_high_frequency_fills(c: &mut Criterion) {
fn bench_fill_statistics(c: &mut Criterion) {
let mut engine = FillEngine::new(dec!(1), dec!(5), 10);
// Add some fills
for i in 1..=100 {
let request = MarketOrderRequest {
@@ -161,7 +157,7 @@ fn bench_fill_statistics(c: &mut Criterion) {
slippage_tolerance: Some(dec!(1.0)),
client_id: Some(format!("order_{}", i)),
};
let mut book = OrderBook::new("test_token".to_string(), 100);
book.apply_delta(OrderDelta {
token_id: "test_token".to_string(),
@@ -170,8 +166,9 @@ fn bench_fill_statistics(c: &mut Criterion) {
price: dec!(0.5),
size: dec!(100),
sequence: i,
}).unwrap();
})
.unwrap();
let _result = engine.execute_market_order(&request, &book);
}
@@ -191,4 +188,4 @@ criterion_group!(
bench_high_frequency_fills,
bench_fill_statistics,
);
criterion_main!(benches);
criterion_main!(benches);
+9 -9
View File
@@ -7,12 +7,12 @@ use tokio::runtime::Runtime;
// Benchmark: Real network request to get simplified markets
fn benchmark_real_simplified_markets(c: &mut Criterion) {
let rt = Runtime::new().unwrap();
c.bench_function("real_fetch_simplified_markets", |b| {
b.iter(|| {
rt.block_on(async {
let client = ClobClient::new("https://clob.polymarket.com");
// This is the real network request + JSON parsing
let result = client.get_sampling_simplified_markets(None).await;
black_box(result)
@@ -24,12 +24,12 @@ fn benchmark_real_simplified_markets(c: &mut Criterion) {
// Benchmark: Real network request to get full markets
fn benchmark_real_markets(c: &mut Criterion) {
let rt = Runtime::new().unwrap();
c.bench_function("real_fetch_markets", |b| {
b.iter(|| {
rt.block_on(async {
let client = ClobClient::new("https://clob.polymarket.com");
// This is the real network request + JSON parsing
let result = client.get_sampling_markets(None).await;
black_box(result)
@@ -41,33 +41,33 @@ fn benchmark_real_markets(c: &mut Criterion) {
// Benchmark: Real order creation (requires API credentials)
fn benchmark_real_order_creation(c: &mut Criterion) {
let rt = Runtime::new().unwrap();
// Skip if no credentials available
let private_key = std::env::var("POLYMARKET_PRIVATE_KEY").ok();
if private_key.is_none() {
println!("Skipping order creation benchmark - no POLYMARKET_PRIVATE_KEY env var");
return;
}
c.bench_function("real_create_order_eip712", |b| {
b.iter(|| {
rt.block_on(async {
let client = ClobClient::new("https://clob.polymarket.com");
// Set up credentials
if let Ok(_key) = std::env::var("POLYMARKET_PRIVATE_KEY") {
// This would require implementing credential setup
// let creds = ApiCredentials::from_private_key(&key)?;
// client.set_credentials(creds);
}
let order_args = OrderArgs::new(
"test_token_id",
Decimal::from_str("0.75").unwrap(),
Decimal::from_str("100.0").unwrap(),
Side::BUY,
);
// This is the real EIP-712 signing + network request
let result = client.create_order(&order_args, None, None, None).await;
black_box(result)