You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before routing a large split payment through the Stellar DEX, the SDK should sample the order book depth to estimate price impact and warn when available liquidity is insufficient to fill the payment without excessive slippage. The current src/pathRouter.ts routes blindly without checking order book depth. A depth sampler should query the Horizon order book and compute fill cost for the target amount.
Technical Context
Add src/orderBookSampler.ts. Uses @stellar/stellar-sdkServer.orderbook() to fetch the order book for a given asset pair. Simulates a market order fill by walking the asks or bids array and computing cumulative fill cost and slippage percentage. Adds OrderBookSample and FillEstimate to src/types.ts. src/pathRouter.ts calls the sampler and emits highSlippageWarning via src/events.ts when slippage exceeds a threshold.
Description
Before routing a large split payment through the Stellar DEX, the SDK should sample the order book depth to estimate price impact and warn when available liquidity is insufficient to fill the payment without excessive slippage. The current
src/pathRouter.tsroutes blindly without checking order book depth. A depth sampler should query the Horizon order book and compute fill cost for the target amount.Technical Context
Add
src/orderBookSampler.ts. Uses@stellar/stellar-sdkServer.orderbook()to fetch the order book for a given asset pair. Simulates a market order fill by walking theasksorbidsarray and computing cumulative fill cost and slippage percentage. AddsOrderBookSampleandFillEstimatetosrc/types.ts.src/pathRouter.tscalls the sampler and emitshighSlippageWarningviasrc/events.tswhen slippage exceeds a threshold.Acceptance Criteria
OrderBookSampler.sample(baseAsset, counterAsset, side: 'buy' | 'sell', amount): Promise<FillEstimate>returns{ estimatedCost, slippagePercent, worstPrice, filledAtLevels }(worstPrice - bestPrice) / bestPrice × 100{ filledFraction: number < 1 }when the order book cannot fill the full amount at any pricesrc/pathRouter.tscallssample()before selecting a DEX path and emitshighSlippageWarningwhenslippagePercent > slippageTolerancePercent