fix(trading): a 0 bps slippage suggestion is not a falsy value - #970
fix(trading): a 0 bps slippage suggestion is not a falsy value#970gomesalexandre wants to merge 2 commits into
Conversation
|
Warning Review limit reachedNext included review available in 56 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (4)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change preserves an explicit slippage suggestion of ChangesZero Slippage Preservation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change preserves explicit 0 bps slippage suggestions instead of replacing them with the default, while retaining the existing fee-derived slippage behavior. No actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
|
Thanks for the suggestion @gomesalexandre |
|
Fair ask — the use case is a partner using To be precise about the effect (also noted in the PR description): this doesn't produce a zero-slippage order outright — Checked direction-safety too: sell orders subtract slippage from min-receive, buy orders add it to max-pay, so honoring a smaller/zero suggestion only ever tightens the limit in both directions — never a worse execution price, only a marginally higher chance of no-fill. Grepped the rest of the monorepo for anything relying on the old behavior — nothing does; every other caller either passes an explicit Also pushed a commit refreshing an unrelated stale live-API snapshot in |
SlippageToleranceResponse.slippageBps is typed number | null, with null as the explicit "no suggestion" sentinel distinct from a legitimate 0. Three call sites used truthiness checks instead of a null-check, so a genuine 0 suggestion (e.g. a partner's model concluding a highly-correlated pair like USDC/USDT needs zero slippage buffer, via the public advancedSettings.getSlippageSuggestion extension point) was silently discarded and replaced with the nonzero default: - resolveSlippageSuggestion.ts:55 fell through to defaultSuggestion instead of routing 0 through suggestSlippageBps(). - getQuote.ts:165 corrupted the suggestedSlippageBps metadata field returned to callers/UIs. - getQuote.ts:170 skipped the order-rebuild branch entirely, leaving the order built with a stale nonzero slippage. Swapped the truthy checks for != null / ?? at all three sites.
0c221c8 to
2a744da
Compare
|
Rebased onto latest |
Found by inspection, no filed issue.
SlippageToleranceResponse.slippageBpsis typednumber | null, withnullasthe explicit "no suggestion" sentinel, distinct from a legitimate
0. Three callsites in
packages/trading/checked this with plain truthiness instead of anull-check, so a partner explicitly supplying
slippageBps: 0via the publicadvancedSettings.getSlippageSuggestionextension point (e.g. their own modelconcluding a highly-correlated pair like USDC/USDT needs zero slippage buffer) got
silently discarded and replaced with the nonzero default:
resolveSlippageSuggestion.ts:55fell through todefaultSuggestioninstead ofrouting
0throughsuggestSlippageBps().getQuote.ts:165corrupted thesuggestedSlippageBpsmetadata field returned tocallers/UIs (a UI showing "AUTO: 0%" would instead show "AUTO: 0.5%").
getQuote.ts:170skipped the order-rebuild branch entirely, leaving the orderbuilt with a stale nonzero slippage instead of the partner's explicit
0.Fix: swapped the truthy checks for
!= null/??at all three sites.One precision worth calling out: honoring a
0suggestion doesn't produce azero-slippage order outright.
suggestSlippageBps()always adds a fee-derivedcomponent on top of the volume component it's fed (
suggestSlippageBps.ts:47-60)0suggestion only zeroes the volume part, same treatment as any othersuggested value. Final slippage is typically a few bps from the fee component
alone,
0only when the fee itself rounds to0. That's the correct, consistentbehavior for this input - just flagging it so the fix doesn't read like a
straight
0-in/0-out passthrough.Direction is safe either way
Checked
getQuoteAmountsAfterSlippage.tsandgetOrderToSign.ts: sell orderssubtract slippage from the min-receive amount, buy orders add it to the max-pay
amount. Honoring a smaller (or
0) suggestion means a tighter limit in bothdirections - the user can never end up with a worse execution price than quoted,
only a higher chance of no-fill. Grepped the rest of the monorepo (order-book,
bridging, composable, examples) for anything relying on the old behavior - nothing
does; every current caller either passes an explicit
slippageBps(bypassing theAUTO/suggestion lane entirely) or forwards its own slippage value directly. The
only lane whose output changes is a partner callback that actually returns
0.Testing
New test cases in
resolveSlippageSuggestion.test.tsandgetQuote.test.tscovering the
slippageBps === 0suggestion at all three sites. Guard-validatedper-site: reverting each fix individually causes its corresponding new test to
fail with the exact predicted wrong value (falls to
defaultSuggestion/50 BPS, orthe rebuild branch gets skipped so
appData.metadata.quote.slippageBipsstays atthe stale default instead of reflecting
0), restoring passes. Also fixed apre-existing misleading log line in the branch this change makes always-taken when
a suggestion exists (was unconditionally claiming the suggestion is "greater than"
the default, which is false at
0and in general).Full
packages/tradingsuite: 256 passed / 2 skipped (pre-existing, unrelated) /258 total.
typecheckandlintboth clean.prettier --checkclean on allchanged files.
Summary by CodeRabbit
Bug Fixes
Tests