fix: respect maxPnlCap==0 as ADL-disabled, bound insurance excess (C5+C6)#83
fix: respect maxPnlCap==0 as ADL-disabled, bound insurance excess (C5+C6)#830x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
Conversation
…(C5+C6) C5: checkAdlTrigger() allowed ADL on markets where maxPnlCap==0 (meaning ADL-disabled) when insurance utilization threshold fired. Gate adlNeeded with maxPnlCap > 0n to match isAdlNeeded semantics. C6: When ADL was triggered by insurance (not cap exceeded), the excess was set to the full pnlPosTot, causing massive over-deleveraging of every profitable position. Now uses pnlPosTot/5 (20% per scan) for a conservative ramp-down that lets multiple scans gradually reduce exposure. Both bugs interacted: on a maxPnlCap==0 market with high insurance utilization, C5 triggered ADL and C6 deleveraged the entire positive PnL pool. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 11 minutes and 50 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Two interacting ADL bugs fixed:
C5 — ADL triggers on disabled markets:
checkAdlTrigger()allowed ADL on markets wheremaxPnlCap==0(protocol semantics: "ADL disabled") when insurance utilization threshold firedisAdlNeeded()correctly returned false formaxPnlCap==0adlNeededwithmaxPnlCap > 0n, matchingisAdlNeededsemanticsC6 — Over-deleveraging on insurance-triggered ADL:
excesswas set to the fullpnlPosTot— the entire positive PnL poolADL_MAX_TX_PER_SCAN)pnlPosTot / 5n(20% per scan) for a conservative ramp-down that lets multiple scans gradually reduce exposureCombined impact: On a
maxPnlCap==0market with high insurance utilization, C5 triggered ADL and C6 then attempted to deleverage the entire positive PnL pool — maximum damage to traders.Changes
src/services/adl.ts:209adlNeededwithmaxPnlCap > 0nsrc/services/adl.ts:212-215pnlPosTotwithpnlPosTot / 5nin insurance-triggered excesstests/services/adl.test.tsmaxPnlCap==0with 90% insurance utilization → no ADLTest plan
maxPnlCap==0with high insurance utilization returns 0 (C5)🤖 Generated with Claude Code