1 unstable release
Uses new Rust 2024
| 0.1.0 | Jan 18, 2026 |
|---|
#11 in #matching-engine
Used in 2 crates
4.5MB
114K
SLoC
kaccy-core
Core business logic for Kaccy Protocol.
Overview
This crate contains the fundamental domain models, bonding curve calculations, order matching, and trade execution logic for the Kaccy personal token platform.
Modules
models
Domain models representing the core entities:
User- User account with DID, KYC status, and reputation scoreToken- Personal FOT (Future Output Token) with bonding curve parametersOrder- Buy/sell orders with BTC payment informationTrade- Executed trade recordsBalance- User token balances
pricing
Bonding curve implementations for automatic price discovery:
BondingCurve- Trait defining the bonding curve interfaceLinearBondingCurve- Linear price model:P(n) = initial_price + (n * increment)- (Planned)
BancorCurve,SigmoidCurve,AdaptiveCurve
trading
Trade execution logic:
TradeExecutor- Executes trades with ACID guarantees- Order matching engine (Phase 2: Limit orders)
error
Error types for the core module.
Usage
use kaccy_core::pricing::{BondingCurve, LinearBondingCurve};
use rust_decimal_macros::dec;
// Create a linear bonding curve
let curve = LinearBondingCurve::new(
dec!(0.0001), // Initial price: 0.0001 BTC
dec!(0.00001), // Increment: 0.00001 BTC per token
);
// Calculate buy price for 10 tokens at supply 0
let cost = curve.buy_price(dec!(0), dec!(10));
println!("Cost to buy 10 tokens: {} BTC", cost);
// Get current spot price at supply 100
let price = curve.spot_price(dec!(100));
println!("Spot price at supply 100: {} BTC", price);
Architecture
kaccy-core/
├── src/
│ ├── lib.rs # Crate root
│ ├── error.rs # Error types
│ ├── models/
│ │ ├── mod.rs
│ │ ├── user.rs # User model
│ │ ├── token.rs # Token model
│ │ ├── order.rs # Order model
│ │ ├── trade.rs # Trade model
│ │ └── balance.rs # Balance model
│ ├── pricing/
│ │ ├── mod.rs
│ │ └── bonding_curve.rs # Bonding curve implementations
│ └── trading/
│ ├── mod.rs
│ └── executor.rs # Trade execution
└── Cargo.toml
Dependencies
rust_decimal- High-precision decimal arithmeticchrono- Date/time handlinguuid- UUID generationserde- Serialization/deserializationsqlx- Database types
Testing
cargo test -p kaccy-core
Dependencies
~85MB
~1.5M SLoC