fix(card): revert to collateral-first spend routing (incident: smart-first reverts on-chain)#2233
fix(card): revert to collateral-first spend routing (incident: smart-first reverts on-chain)#2233jjramirezn wants to merge 1 commit into
Conversation
…rts on-chain) #2230 reordered computeSpendStrategy to smart-first, but card funds are swept smart→collateral to back the card, so the smart account is normally ~empty. The FE's smartBalance (useBalance, 30s-cached / pre-sweep) could read >= amount while the on-chain smart account is empty → smart-only was chosen → the USDC transfer reverts at the paymaster with "ERC20: transfer amount exceeds balance" for collateral-funded users (prod incident). Collateral-first never trusted the smart balance for these users, so it was safe. Restore collateral-first. Re-introducing smart-first (to avoid Rain's withdrawal-signature cooldown when the user genuinely holds smart-account USDC) needs a live/uncached balance read AND a fallback to collateral when the smart-only path can't be funded — tracked as a follow-up.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Walkthrough
ChangescomputeSpendStrategy Collateral-First Routing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
Code-analysis diffPainscore total: 5786.03 → 5786.17 (+0.14) 🆕 New findings (9)
✅ Resolved (9)
|
🧪 UI test report — ✅ all greenSuites
📊 Coverage (unit)
⏱ 10 slowest test cases
|
|
Superseded by #2234 — keeping smart-first and fixing the root cause (route on a live on-chain balance) instead of reverting. Branch retained as an emergency fallback. |
🚨 Incident mitigation — reverts #2230
Symptom (prod): card users whose funds live in collateral get
Paymaster error … UserOperation reverted during simulation … ERC20: transfer amount exceeds balancewhen trying to pay — the payment hard-fails.Cause: #2230 reordered
computeSpendStrategyto smart-first. But card funds are swept smart→collateral to back the card, so the smart account is normally ~empty. The FE'ssmartBalance(useBalance, 30s-cached / read before a sweep) can be>= amountwhile the on-chain smart account is empty →smart-onlyis chosen → the kernel USDC transfer reverts at the paymaster. The old collateral-first ordering never trusted the smart balance for these users, so it was safe.This PR: restores collateral-first ordering + its test, and leaves a
NOTEin the code documenting why smart-first was reverted.Trade-off
QA
npx jest src/hooks/wallet— strategy returnscollateral-onlywhen collateral covers (single recipient),smart-onlyonly when collateral path ineligible and smart covers,mixedfor shortfall.🤖 Generated with Claude Code