Root Cause: quoteAssetAmount/baseAssetAmount division producing garbage entry prices - Found 6 autosync records with impossible prices (.18, 6.30, 7.11, 116.24 for SOL) - Drift SDK values can be corrupted during state transitions Fix Layer 1 (lib/drift/client.ts): - Added per-asset price range validation (SOL: 0-000, BTC: 0k-00k, ETH: 00-0k) - Returns null for invalid prices Fix Layer 2 (lib/trading/sync-helper.ts): - Added validatedEntryPrice calculation with oracle fallback - Falls back to Pyth oracle when calculated price is garbage Fix Layer 3 (lib/trading/sync-helper.ts): - Trade creation uses validatedEntryPrice in all 4 price fields - entryPrice, peakPrice, maxFavorablePrice, maxAdversePrice Documentation: - Full Bug #93 added to COMMON_PITFALLS.md with code examples - Quick Reference table updated Cleaned: 6 garbage autosync records deleted from database
16 KiB
16 KiB