Skip to content

Add slippage protection parameter to buy and sell functions #975

Description

@Chucks1093

Summary

Extend buy and sell contract functions with an optional max_slippage_bps parameter that causes the transaction to revert if the actual price impact exceeds the caller's specified tolerance.

Scope

  • buy(key_id, amount, max_slippage_bps?) and sell(key_id, amount, max_slippage_bps?) updated
  • Price impact computed against current curve state before execution
  • SlippageExceeded error returned with actual_bps and max_bps when violated
  • max_slippage_bps of 0 or absent skips the check (opt-in)
  • Impact computed after fee deduction

Acceptance Criteria

  • SlippageExceeded returned when impact exceeds max_slippage_bps
  • Trade executes when impact is within tolerance
  • Omitting max_slippage_bps skips check without error
  • actual_bps in error matches true price impact
  • Impact computation accounts for fees correctly

ETA

24 hours

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions