kaccy_core/
lib.rs

1//! Core business logic for Kaccy Protocol
2//!
3//! This crate contains the domain models, bonding curve calculations,
4//! order matching, and trade execution logic.
5//!
6//! # Architecture
7//!
8//! The kaccy-core crate is organized into the following modules:
9//!
10//! - [`models`] - Domain models including users, tokens, orders, trades, balances, commitments, and analytics
11//! - [`pricing`] - Bonding curve implementations, fee calculation, and price oracles
12//! - [`trading`] - Order matching, execution, market maker functionality, and sentiment analysis
13//! - [`ml`] - Machine learning integration for price prediction, anomaly detection, and strategy optimization
14//! - [`events`] - Event emission system for domain events
15//! - [`utils`] - Utility functions for pagination, caching, validation, risk management, and more
16//! - [`error`] - Comprehensive error types with HTTP status mapping and retry logic
17//!
18//! # Features
19//!
20//! ## Bonding Curves
21//!
22//! The protocol supports multiple bonding curve types:
23//! - Linear curves for predictable pricing
24//! - Bancor curves with configurable reserve ratios
25//! - Sigmoid curves for price stabilization
26//! - Exponential curves for rapid growth
27//! - Adaptive curves that switch between phases
28//! - Square root and logarithmic curves for gentler growth
29//!
30//! ## Trading Features
31//!
32//! - Order book with price-time priority matching
33//! - Market maker integration with dynamic spreads
34//! - Circuit breakers for price manipulation protection
35//! - Advanced order types (stop-loss, take-profit, TWAP)
36//! - AMM-style liquidity pools with flash swaps
37//! - Position management and risk controls
38//!
39//! ## Fee System
40//!
41//! - Platform fees with reputation-based discounts
42//! - Volume-based fee tiers
43//! - Maker/taker fee differentiation
44//! - Fee distribution to stakers
45//!
46//! ## Utilities
47//!
48//! - Event emission and persistence
49//! - Caching layer with TTL management
50//! - Query optimization and N+1 detection
51//! - Benchmarking and load testing
52//! - Model factories and test fixtures
53//! - Risk management and position sizing
54//! - Price oracle integration and aggregation
55//!
56//! # Example Usage
57//!
58//! ```rust,no_run
59//! use kaccy_core::pricing::{LinearBondingCurve, BondingCurve};
60//! use rust_decimal_macros::dec;
61//!
62//! // Create a linear bonding curve
63//! let curve = LinearBondingCurve::new(dec!(0.001), dec!(1.0));
64//!
65//! // Calculate buy price for 100 tokens when supply is 1000
66//! let price = curve.buy_price(dec!(1000), dec!(100));
67//! println!("Price: {}", price);
68//! ```
69
70pub mod defi;
71pub mod error;
72pub mod events;
73pub mod ml;
74pub mod models;
75pub mod pricing;
76pub mod trading;
77pub mod utils;
78
79pub use error::{CoreError, Result};