A lightweight Rust crate modeling core DeFi primitives: assets and liquidity pools based on the constant product formula (x·y=k).
Warning
Built as a learning exercise toward DeFi development. Not production-ready.
Asset— native tokens, ERC20/SPL tokens, and recursive LP tokensPool— liquidity pool with two assets and position trackingPool::quote()— AMM output calculation using the x·y=k invariantPool::constant_product()— returns k for a given pool state
Given a pool with reserves x and y, the invariant k is:
k = x · y
For a trade of amount_in:
amount_out = y · amount_in / (x + amount_in)
let pool = Pool { ... };
let out = pool.quote(1_000, &pool.asset_a);- Position management (deposit, withdraw)
- Fee calculation
- Multi-hop routing
Marco Kergeist - marcokergeist@proton.me