harb/onchain/CLAUDE.md
2025-08-17 15:09:41 +02:00

78 lines
No EOL
2.5 KiB
Markdown

# Smart Contracts - CLAUDE.md
This directory contains the core smart contracts for the KRAIKEN protocol.
## Architecture Overview
### Core Contracts
**Kraiken.sol** - ERC20 token with Harberger tax staking
- Controlled minting exclusively by LiquidityManager
- Tax collection and redistribution mechanism
- 20% supply cap for staking (20,000 positions)
**LiquidityManager.sol** - Dominant liquidity provider
- Three-position anti-arbitrage strategy (ANCHOR, DISCOVERY, FLOOR)
- Dynamic parameter adjustment via Optimizer contract
- Asymmetric slippage profile prevents profitable arbitrage
**VWAPTracker.sol** - Price memory protection
- Volume-weighted average with data compression (max 1000x)
- Prevents dormant whale manipulation
**Optimizer.sol** - Dynamic parameter optimization
- Analyzes staking sentiment (% staked, average tax)
- Returns four key parameters for liquidity management
- Upgradeable for future algorithms
**Stake.sol** - Harberger tax implementation
- Continuous auction mechanism
- Self-assessed valuations create prediction market
### Three-Position Strategy
**ANCHOR**: Near current price, fast price discovery (1-100% width)
**DISCOVERY**: Borders anchor, captures fees (11000 tick spacing)
**FLOOR**: Deep liquidity at VWAP-adjusted prices
**Technical Specs**:
- Fee Tier: 1% (10,000 basis points)
- Tick Spacing: 200 (base), 11,000 (discovery)
- Price Validation: 5-minute TWAP, 50-tick tolerance
### Optimizer Parameters
1. **capitalInefficiency** (0 to 1e18): Capital buffer level
2. **anchorShare** (0 to 1e18): % of non-floor ETH in anchor
3. **anchorWidth** (0 to 100): Anchor position width %
4. **discoveryDepth** (0 to 1e18): Discovery liquidity density (2x-10x)
## Development
```bash
forge build # Build contracts
forge test # Run tests
forge test --gas-report # Gas optimization
forge test --fuzz-runs 10000 # Extended fuzzing
```
## Testing
- `test/helpers/UniswapTestBase.sol` - Uniswap integration base
- `test/helpers/KraikenTestBase.sol` - Common utilities
- Key tests: LiquidityManager.t.sol, Stake.t.sol, VWAPTracker.t.sol
## Code Guidelines
- **Check lib/uni-v3-lib** for existing Uniswap math
- **Use test/helpers** for common patterns
- **Security**: Reentrancy protection, oracle validation
- **Gas**: Batch operations, optimize storage
## Analysis Tools
See `analysis/CLAUDE.md` for fuzzing and attack vector testing.
## Uniswap V3 Math
See [UNISWAP_V3_MATH.md](UNISWAP_V3_MATH.md) for detailed math concepts.