Git diff for onchain state.
chain-diff is a CLI for explaining how lending protocol state changed over time — not just what changed, but why.
Currently supports:
- Aave V3 / Ethereum / USDC
- Morpho Blue / Ethereum / USDC / wstETH
- Generic Morpho Blue USDC markets by Market ID
- Compare current and historical onchain state
- Explain liquidity and debt changes
- Attribute changes to supply, withdrawals, borrowing, repayments, and interest
- Compare protocols over the same Ethereum block window
- Normalize changes by protocol size
- Continuously watch markets for new changes
- Filter watch output by liquidity/debt thresholds
- JSON / JSONL output for automation
- Node.js 20+
- Ethereum RPC access
chain-diff can use its default RPC transport, or you can provide your own endpoint:
$env:ETH_RPC_URL="https://your-ethereum-rpc.example"From the project directory:
npm install
npm run build
npm linkThen:
chain-diff --helpchain-diff targetsExample:
aave:usdc
morpho:wsteth-usdc
A generic Morpho Blue market can also be addressed with:
morpho:<market-id>
Inspect how a market changed over a time window:
chain-diff diff aave:usdc --since 1hExplain the causes behind a state change:
chain-diff why aave:usdc --since 24hJSON output:
chain-diff why aave:usdc --since 24h --jsonCompact JSON without the full event list:
chain-diff why aave:usdc --since 24h --json --summaryCompare two markets using the exact same Ethereum block window:
chain-diff compare aave:usdc morpho:wsteth-usdc --since 24hThe comparison includes:
- Liquidity change
- Debt change
- Relative percentage change
- Utilization
- Supply APR
- Borrow APR
- Gross activity
- Activity relative to starting supply
- Causal attribution
- Interest model
- Confidence
JSON output:
chain-diff compare aave:usdc morpho:wsteth-usdc --since 24h --jsonContinuously monitor new onchain changes:
chain-diff watch aave:usdc --interval 30sRun one interval only:
chain-diff watch aave:usdc --interval 15s --onceOnly show intervals with at least $100,000 of liquidity movement:
chain-diff watch aave:usdc --interval 30s --min-liquidity 100000Debt threshold:
chain-diff watch aave:usdc --interval 30s --min-debt 100000watch --json emits machine-readable JSON Lines.
chain-diff watch aave:usdc --interval 30s --jsonThis can be piped into other tools, databases, webhooks, or monitoring systems.
PowerShell example:
chain-diff watch aave:usdc --interval 15s --once --json 2>$null |
ConvertFrom-Json |
Select-Object type, status, targetFor liquidity, chain-diff attributes observed changes to normalized protocol events such as:
- Supply
- Withdraw
- Borrow
- Repay
For debt, it separates:
- Principal changes from borrow/repay activity
- Accrued interest
Aave V3 currently uses its variable debt index for interest attribution.
Morpho Blue currently uses an average-APR approximation.
Residual unexplained change is used as part of the confidence calculation.
Type check:
npx tsc --noEmitTests:
npm testBuild:
npm run buildCurrent automated tests cover causal analysis, interest models, normalized metrics, and numerical noise handling.
Early MVP.
The current focus is lending-market state semantics and causal explanation. The longer-term direction is a reusable semantic layer for answering:
What changed onchain, and why?