Skip to content

feat: on-chain order expiry — user-set TTL on limit and stop orders #272

Description

@abayomicornelius

Summary

Limit and stop-loss orders currently live in storage indefinitely until executed or manually cancelled. Users have no way to set an automatic expiry, which means stale orders accumulate and clutter keeper queues.

Proposed Design

Add an optional expiry_ledger: Option<u64> field to CreateOrderParams.

  • If Some(n), the order is only executable while env.ledger().sequence() <= n
  • After expiry, the keeper calls execute_order and it auto-cancels (refunding the user) instead of reverting
  • Alternatively, anyone can call cleanup_expired_order(nonce) to cancel and get a small incentive fee

Storage Impact

One extra u64 field per order — negligible.

Acceptance Criteria

  • CreateOrderParams includes expiry_ledger: Option<u64>
  • Keeper execution after expiry auto-cancels and refunds user
  • cleanup_expired_order callable by anyone; caller receives a configurable incentive
  • Order with expiry_ledger = None behaves exactly as today (no regression)
  • Integration test: limit order expires, user refunded, storage cleared
  • Integration test: limit order executed before expiry works normally

Affected Contracts

exchange_router, order_handler, data_store

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions