Skip to content

[ENG-118] Add maker order bids and asks to the market account data - #51

Merged
alnoki merged 42 commits into
mainfrom
ENG-118
Jan 14, 2026
Merged

[ENG-118] Add maker order bids and asks to the market account data#51
alnoki merged 42 commits into
mainfrom
ENG-118

Conversation

@xbtmatt

@xbtmatt xbtmatt commented Dec 13, 2025

Copy link
Copy Markdown
Contributor

Description

Adds bids and asks as individual, traversable data structures in the market account data.

This PR focuses on maker operations with limited/no support for taker operations yet.

  • Add bids_dll_head
  • Add asks_dll_head
  • No need to add tails since they are always traversed from the head (top of book)
  • Do a linear scan from top of book upon insert
  • Ensure cargo doc with flags runs cleanly as well as all cargo doc tests
  • Post only limit order should fail if the price crosses side; that is, it fails if it would immediately be filled (posted bid has a limit price >= than the lowest ask or posted ask has a limit price <= the highest bid)

Maker operations

  • Place and cancel only update state in the market account, they do not transfer tokens
    • Cancel based on the encoded price
      • When a maker cancels, they submit the price of the order they want to cancel
        • The algorithm looks in their seat at a vector that maps price to order node
        • It cancels the order
        • and updates the seat node available amounts
    • And only allow placing at unique prices
  • The tokens should already have been added to the maker's seat, otherwise it'll abort
  • Place and cancel should never contend an ATA

Tests

Adds unit tests for the market order operations:

  • Tests a utility function to create an order where the input price mantissa equals the output encoded price. This makes it easier to intuitively reason about sorting operations
  • Tests time order precedence for bids and asks (same price sorts on time)
  • Tests price order precedence for bids and asks
  • Tests inserting to the lists head, tail, and mid (some not head or tail) index for bids and asks
  • Tests the post only crossing check for bids and asks

@linear

linear Bot commented Dec 13, 2025

Copy link
Copy Markdown

ENG-118

@xbtmatt xbtmatt mentioned this pull request Dec 19, 2025
10 tasks
@xbtmatt
xbtmatt force-pushed the ENG-118 branch 2 times, most recently from b3f92b6 to c549807 Compare January 8, 2026 00:41
@xbtmatt
xbtmatt force-pushed the ENG-117 branch 2 times, most recently from 028cf58 to 96fb80b Compare January 12, 2026 18:22
@xbtmatt
xbtmatt marked this pull request as ready for review January 13, 2026 18:14
Copilot AI review requested due to automatic review settings January 13, 2026 18:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 37 out of 38 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread interface/src/state/order.rs Outdated
Comment thread interface/src/state/order.rs Outdated
Comment thread program/src/instructions/post_order.rs

@alnoki alnoki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See copilot review - appears to be copy-paste issues in tests

Copilot AI commented Jan 13, 2026

Copy link
Copy Markdown

@alnoki I've opened a new pull request, #58, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI review requested due to automatic review settings January 13, 2026 19:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 39 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread program/src/shared/order_operations.rs
Comment thread interface/src/state/bids_dll.rs
Comment thread program/src/instructions/post_order.rs
Comment thread program/src/instructions/cancel_order.rs
@xbtmatt
xbtmatt requested a review from alnoki January 13, 2026 20:21
@alnoki
alnoki merged commit 6bee2f9 into main Jan 14, 2026
@alnoki
alnoki deleted the ENG-118 branch January 14, 2026 01:56
alnoki pushed a commit that referenced this pull request Jan 14, 2026
# Description

Adds the `MarketOrder` instruction that fills up or down the book depending on the type of order.

- [x] Add the `MarketOrder` instruction
- [x] Add the `MarketOrderEvent` event data and emit it
- [x] Add unit tests for individual functions
- [x] Transfer coins to/from the taker directly rather than creating / updating a seat
- [x] Update the maker's seat on transfer
- [x] Add proper account dependencies to the context and client APIs
- [x] Remove/fix hardcoded values in the `market_order` example
- [x] Ensure the maker's seat is properly updated after filling
- [x] Ensure the maker's seat is properly updated after posting an order (can go in #51)
- [x] Clean up the huge function body in `process_market_order` and split it up into multiple different functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants