slippage - #156
slippage#156Siddharth2207 wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughIntroduces user-configurable slippage tolerance for market orders. The MarketOrder component adds a UI control allowing users to select from predefined slippage options, passing the selected value to the market order execution service, which now computes dynamic ratio multipliers based on the configured tolerance instead of using fixed constants. Changes
Sequence DiagramsequenceDiagram
actor User
participant MarketOrder as MarketOrder<br/>Component
participant Service as Market Order<br/>Execution Service
User->>MarketOrder: Select slippage tolerance
activate MarketOrder
MarketOrder->>MarketOrder: Update slippageBps state
deactivate MarketOrder
User->>MarketOrder: Confirm order
activate MarketOrder
MarketOrder->>Service: executeMarketOrder(input:<br/>slippageBps)
deactivate MarketOrder
activate Service
Service->>Service: Clamp slippageBps<br/>(MIN/MAX bounds)
Service->>Service: Compute ratioMultiplier<br/>= 1 + effectiveSlippageBps/10_000
Service->>Service: Execute order with<br/>dynamic ratio
deactivate Service
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/lib/services/marketOrderExecution.ts`:
- Around line 217-220: The code ignores the user-selected slippage for sell
orders by only using slippageBps when isBuy and otherwise using
EMERGENCY_RATIO_MULTIPLIER; change ratioMultiplier calculation in
marketOrderExecution.ts to use the clamped effectiveSlippageBps for both sides
(e.g., derive ratioMultiplier from effectiveSlippageBps for sells too) or
alternatively gate the UI selector in MarketOrder.svelte; update the
ratioMultiplier assignment that references isBuy, effectiveSlippageBps,
clampSlippageBps and EMERGENCY_RATIO_MULTIPLIER so sell execution honors the
configured tolerance (or remove/disable the selector in MarketOrder.svelte if
you prefer not to support sell slippage yet).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 20d76759-62e3-46ce-abce-f666486bf3ea
📒 Files selected for processing (2)
src/lib/components/orders/MarketOrder.sveltesrc/lib/services/marketOrderExecution.ts
| const effectiveSlippageBps = clampSlippageBps(slippageBps); | ||
| const ratioMultiplier = isBuy | ||
| ? String(1 + effectiveSlippageBps / 10_000) | ||
| : EMERGENCY_RATIO_MULTIPLIER; |
There was a problem hiding this comment.
Honor the selected slippage for Sell orders too.
slippageBps is only used when isBuy; Sell orders still use EMERGENCY_RATIO_MULTIPLIER. Since MarketOrder.svelte exposes the selector for both sides, a user-selected Sell tolerance is silently ignored. Either apply the configured tolerance to Sell execution as well, or hide/disable the selector for Sell orders until supported.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/lib/services/marketOrderExecution.ts` around lines 217 - 220, The code
ignores the user-selected slippage for sell orders by only using slippageBps
when isBuy and otherwise using EMERGENCY_RATIO_MULTIPLIER; change
ratioMultiplier calculation in marketOrderExecution.ts to use the clamped
effectiveSlippageBps for both sides (e.g., derive ratioMultiplier from
effectiveSlippageBps for sells too) or alternatively gate the UI selector in
MarketOrder.svelte; update the ratioMultiplier assignment that references isBuy,
effectiveSlippageBps, clampSlippageBps and EMERGENCY_RATIO_MULTIPLIER so sell
execution honors the configured tolerance (or remove/disable the selector in
MarketOrder.svelte if you prefer not to support sell slippage yet).
Resolves conflict in marketOrderExecution.ts: keeps REST API hydration block and slippage-based priceCap calculation (replaces hardcoded BUY_EXACT_RATIO_MULTIPLIER with user-configurable slippageBps). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
What Changed
src/lib/services/marketOrderExecution.tsslippageBps?: numbertoMarketOrderInput.DEFAULT_MARKET_ORDER_SLIPPAGE_BPS = 100(1%)1..5000bps1 + slippageBps/10000) and feeds it into existing price-cap derivation.src/lib/components/orders/MarketOrder.svelteslippageBpsintoexecuteMarketOrder(...).Why
getTakeOrdersCalldataflow and transaction orchestration intact.Test Plan
1%.0.5%,2%) and place Buy orders; confirm preparation/execution still succeeds.npx vitest run tests/lib/services/marketOrderExecution.test.ts.