Yield optimizer — rebalances across Kamino, MarginFi, Solend for max APY
Flux
Autonomous yield optimizer for Solana DeFi. Polls Kamino, MarginFi, and Solend every hour. Reasons with Claude. Rebalances when it's worth it.
Yield farming manually means checking three dashboards, doing the math on gas costs, and second-guessing yourself at 2am.
Flux fetches live rates across every major Solana lending protocol, builds a rate matrix, and asks Claude to reason about the optimal allocation — factoring in utilization risk, liquidity depth, and concentration limits. It only rebalances when the improvement is meaningful. Otherwise it holds.
FETCH RATES → BUILD MATRIX → REASON → ALLOCATE → ACCRUE → REBALANCE
Paper mode on by default. One env var flip for live capital.
Dashboard

Live optimizer dashboard for Flux: protocol rates, utilization risk, liquidity depth, current allocations, paper-mode execution status, and rebalance candidates in one operating view.
Allocation Logic

How Flux allocates capital: fetch rates, build a rate matrix, filter unsafe venues, compare risk-adjusted yield, and only rebalance when the expected improvement clears the configured threshold.
Architecture
┌─────────────────────────────────────────────────────┐
│ Protocol Layer │
│ ┌──────────┐ ┌───────────┐ ┌──────────┐ │
│ │ Kamino │ │ MarginFi │ │ Solend │ │
│ └────┬─────┘ └─────┬─────┘ └────┬─────┘ │
│ └──────────────┼──────────────┘ │
└──────────────────────┼──────────────────────────────┘
▼
┌─────────────────────────────────────────────────────┐
│ Aggregator │
│ Rate matrix · Best-per-asset · Health check │
└──────────────────────┬──────────────────────────────┘
▼
┌─────────────────────────────────────────────────────┐
│ Claude Agent Loop │
│ getratematrix → getcurrentpositions │
│ → getprotocolhealth → submitallocationplan │
└──────────────────────┬──────────────────────────────┘
▼
┌─────────────────────────────────────────────────────┐
│ Rebalancer │
│ Diff current vs plan · Build actions │
│ Paper execute · Yield accrual │
└─────────────────────────────────────────────────────┘
Optimization Rules
| Rule | Detail | |------|--------| | Min APY gate | Ignore any rate below 5% | | Rebalance threshold | Only move capital if improvement > 2% APY | | Max protocol concentration | 50% cap per protocol | | Utilization guard | Avoid pools above 90% utilization | | Liquidity floor | Minimum $10k available to exit |
Supported Protocols
| Protocol | Assets | Notes | |----------|--------|-------| | Kamino | USDC, SOL, USDT, JitoSOL | Highest rates, most liquid | | MarginFi | USDC, SOL, USDT | Good depth, lower utilization | | Solend | USDC, SOL, USDT, BTC | Longest track record | | Drift | USDC, SOL | Perp funding rates (opt-in) |
Quick Start
git clone https://github.com/FluxYield/FluxYield
cd FluxYield && bun install
cp .env.example .env
bun run dev
Configuration
ANTHROPICAPIKEY=sk-ant-...
HELIUSAPIKEY=...
PAPER_MODE=true
TOTALCAPITALUSD=10000
CYCLEINTERVALMS=3600000 # 1 hour
MINAPYTHRESHOLD=0.05
REBALANCE_THRESHOLD=0.02
MAXPROTOCOLALLOCATION_PCT=0.50
Technical Spec
Risk-Adjusted APY
Raw APY comparisons mislead — a 12% market at 95% utilization is less valuable than 9% at 60% because exit is unreliable at high utilization. Flux applies a penalty:
riskAdjustedApy = supplyApy (1 - max(0, u - 0.70) / 0.30 0.40)
No penalty below 70% utilization. At 100% utilization, effective APY is 40% lower than stated. getBestRatePerAsset ranks by risk-adjusted APY and filters out markets above MAXUTILIZATIONRATE (default 90%).
Gas-Economic Rebalance Gate
Before shifting capital, isRebalanceEconomic checks whether the expected APY gain over one cycle actually covers the gas cost:
const hourlyGain = capitalUsd improvementApy / 8760 periodHours;
// Only rebalance if hourlyGain > $0.02 (2 Solana txs)
A 2% APY improvement on $500 earns $0.0011/hour — rebalancing every hour would cost 18× more in gas than it earns. At $10,000 capital, the same improvement earns $0.023/hour — economic.
Compound Yield Accrual
accrueYield uses compound interest: P ((1 + r)^t - 1). The prior simple interest model (P r * t) underestimates accumulated yield by ~2% APY at 30% APR over a week — meaningful at larger capital amounts.
Utilization Spike Detection
Both Kamino and Solend adapters log a warning when utilization exceeds 85% AND available liquidity is less than 5% of total supply. This pattern precedes withdrawal freezes in lending protocols — the interest rate model has forced rates up to attract new deposits but hasn't yet resolved the liquidity crunch.
License
MIT
money finds its own level.