CRITICAL FIX (Dec 9, 2025): Drift state verifier now stops retry loop when close transaction confirms, preventing infinite retries that cancel orders. Problem: - Drift state verifier detected 'closed' positions still open on Drift - Sent close transaction which CONFIRMED on-chain - But Drift API still showed position (5-minute propagation delay) - Verifier thought close failed, retried immediately - Infinite loop: close → confirm → Drift still shows position → retry - Eventually Position Manager gave up, cancelled ALL orders - User's position left completely unprotected Root Cause (Bug #80): - Solana transaction confirms in ~400ms on-chain - Drift.getPosition() caches state, takes 5+ minutes to update - Verifier didn't account for propagation delay - Kept retrying every 10 minutes because Drift API lagged behind - Each retry attempt potentially cancelled orders as side effect Solution: - Check configSnapshot.retryCloseTime before retrying - If last retry was <5 minutes ago, SKIP (wait for Drift to catch up) - Log: 'Skipping retry - last attempt Xs ago (Drift propagation delay)' - Prevents retry loop while Drift state propagates - After 5 minutes, can retry if position truly stuck Impact: - Orders no longer disappear repeatedly due to retry loop - Position stays protected with TP1/TP2/SL between retries - User doesn't need to manually replace orders every 3 minutes - System respects Drift API propagation delay Testing: - Deployed fix, orders placed successfully - Database synced: tp1OrderTx and tp2OrderTx populated - Monitoring logs for 'Skipping retry' messages on next verifier run - Position tracking: 1 active trade, monitoring active Note: This fixes the symptom (retry loop). Root cause is Drift SDK caching getPosition() results. Real fix would be to query on-chain state directly or increase cache TTL. Files changed: - lib/monitoring/drift-state-verifier.ts (added 5-minute skip window)
11 KiB
11 KiB