- Rewrite root README.md with proper project overview, tech stack, and repo structure - Remove duplicate CLAUDE.md files (root, onchain, ponder) — AGENTS.md is the standard - Update HARBERG.md to reflect Stage 1 completion and Stage 2 evolution - Delete stale onchain/testing_todos.md (all high-priority items completed) - Update VERSION_VALIDATION.md for VERSION=2 - Trim root AGENTS.md: replace Docker duplication with docs/docker.md reference - Trim onchain/AGENTS.md (129→71 lines): reference TECHNICAL_APPENDIX for formulas - Trim web-app/AGENTS.md (278→55 lines): remove internal API docs, keep architecture - Rewrite onchain/README.md: add contract table, deployment addresses, analysis links - Trim services/ponder/README.md: remove stale subgraph comparison - Add otterscan to docs/docker.md service topology - Update TECHNICAL_APPENDIX.md references Net: -388 lines across documentation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3.9 KiB
Agent Brief: Kraiken Protocol
Protocol Philosophy & Business Logic
What KRAIKEN is: A token with a self-managing liquidity manager (LM) on Uniswap V3. The LM positions liquidity across three positions (floor, anchor, discovery) and recenters them as price moves. An optimizer adjusts parameters based on staking sentiment.
Revenue model: TRANSACTION FEES are the product.
- Every swap through the LM's positions generates Uniswap LP fees
- Fees (WETH + KRK) flow to
feeDestination— this is what founders withdraw - Locked ETH in the protocol has NO value to founders — it's locked forever
- The protocol WANTS active trading, even if traders extract some ETH
The optimization target is NOT "minimize trader PnL". It is "maximize fee revenue while keeping the protocol solvent."
Four optimizer parameters:
capitalInefficiency (CI)— adjusts VWAP for floor placement. Zero effect on fee revenue — pure risk lever. CI=0% is safest.anchorShare (AS)— ETH split between floor and anchoranchorWidth (AW)— anchor position width in ticksdiscoveryDepth (DD)— discovery position liquidity density. Zero effect on floor safety.
See TECHNICAL_APPENDIX.md for floor placement formula, parameter safety frontier, and asymmetric slippage analysis.
OptimizerV3
src/OptimizerV3.sol — UUPS upgradeable. Binary bear/bull from staking sentiment.
Inputs: percentageStaked (0-100%), averageTaxRate (effective index 0-29)
Mapping:
staked <= 91%→ always BEAR: AS=30%, AW=100, CI=0, DD=0.3e18staked > 91%→ BULL ifdeltaS^3 * effIdx / 20 < 50: AS=100%, AW=20, CI=0, DD=1e18
The binary step avoids the AW 40-80 kill zone. ~94% of state space maps to bear.
Staking Triangle Cycle
The staking system traces a triangle in (staking%, avgTax) space:
- Fill up: Staking grows 0→100%, tax low. Optimizer stays bear. Bull at ~95%.
- Snatching wars: 100% staked, tax rises. Always bull.
- Collapse: Nervous exits. Cubic term snaps to bear within 4-6% staking drop.
System Snapshot
- Kraiken ERC20 with mint/burn via LiquidityManager. VERSION=2.
- LiquidityManager.sol: ANCHOR + DISCOVERY + FLOOR positions with asymmetric slippage.
- VWAPTracker.sol: squared price in X96, compression, directional recording (ETH inflow only).
- OptimizerV3.sol: UUPS upgradeable, direct 2D binary mapping.
- Stake.sol: self-assessed tax, snatching auctions, discrete brackets, UBI redistribution.
Development Workflow
- Foundry:
forge build,forge test,forge fmt,forge snapshot. - Repo:
src/(contracts),test/helpers/(Uniswap/Kraiken bases),lib/uni-v3-lib(math),script/(deploy). - Setup:
git submodule update --init --recursive,npm installinlib/uni-v3-lib/, Foundry installed. - ABI flow:
kraiken-lib/src/abis.tsimports fromonchain/out/. Runforge buildto update ABIs stack-wide.
Testing & Analysis
- Fuzzing under
analysis/: configurable trade/stake biases, adversarial attacks, parameter sweeps. Seeanalysis/README.md. - Adversarial testing (
run-adversarial.sh,run-v3-adversarial.sh) validates floor defense. - Background LP analysis (
run-bglp-fee-test.sh) measures fee retention under LP competition.
Containerized Builds
- Git submodules must be initialized before building.
lib/uni-v3-lib/needsnpm installfor Uniswap interfaces.- Foundry image:
ghcr.io/foundry-rs/foundry:latest(includes forge/cast/anvil, NOT jq/curl). - Volume permissions: use
:z(shared SELinux label) for multi-container mounts.
Guardrails
- Respect access controls (
onlyLiquidityManager, owner). token0isWethflips amount semantics — confirm ordering before interpreting liquidity.- Floor uses
vwapX96directly (not sqrt) in fixed-point math. - Outstanding supply excludes LM position balances and KRK held by
feeDestination/stakingPool.