Summary
Between the moment a user sees a price quote and the moment their transaction lands on chain, other trades can move the price. Without slippage protection the user has no on-chain guarantee about what they will pay or receive. Adding a max_price param to buy and min_proceeds to sell gives users a hard limit that reverts the transaction if the market moved too far before their trade executed.
Scope
- Add optional
max_price: Option<i128> parameter to the buy function
- If provided and the computed buy price exceeds
max_price, the transaction panics with a new SlippageExceeded error variant
- Add optional
min_proceeds: Option<i128> parameter to the sell function
- If provided and the computed sell proceeds are below
min_proceeds, the transaction panics with SlippageExceeded
- Add
SlippageExceeded to the contract error enum
- Quote view functions remain unchanged — they are read-only and do not need the parameter
Acceptance Criteria
Coordinate on Telegram
Summary
Between the moment a user sees a price quote and the moment their transaction lands on chain, other trades can move the price. Without slippage protection the user has no on-chain guarantee about what they will pay or receive. Adding a
max_priceparam to buy andmin_proceedsto sell gives users a hard limit that reverts the transaction if the market moved too far before their trade executed.Scope
max_price: Option<i128>parameter to the buy functionmax_price, the transaction panics with a newSlippageExceedederror variantmin_proceeds: Option<i128>parameter to the sell functionmin_proceeds, the transaction panics withSlippageExceededSlippageExceededto the contract error enumAcceptance Criteria
max_pricereverts withSlippageExceededwhen price exceeds the limitmax_pricesucceeds when price is at or below the limitmin_proceedsreverts withSlippageExceededwhen proceeds fall below the limitmin_proceedssucceeds when proceeds meet or exceed the limitNone) preserves existing behavior with no revertSlippageExceededis a stable error variant with a fixed discriminantCoordinate on Telegram