Skip to content

[ENG-87] Implement price library#49

Merged
alnoki merged 47 commits intomainfrom
ENG-87
Dec 13, 2025
Merged

[ENG-87] Implement price library#49
alnoki merged 47 commits intomainfrom
ENG-87

Conversation

@xbtmatt
Copy link
Contributor

@xbtmatt xbtmatt commented Nov 26, 2025

Description

This PR introduces the standalone price representation module used for Dropset’s order and matching logic.

The implementation provides a deterministic, overflow-safe encoding of prices using a mantissa + biased exponent scheme without the usage of intermediate u128 values when storing price order info.

Summary of Changes

  • Adds a standalone Rust module defining the canonical encoded price format
  • Implements price_mantissa validation and bounds checking
  • Adds biased exponent encoding with protection against underflow/overflow
  • Adds conversion from (price_mantissa, base_scalar_exponent, quote_exponent) into the packed integer price.
  • Ensures all intermediate arithmetic avoids u128 overflow using checked operations
  • Implements decoding utilities for test/debug
  • Unit tests:
    • Mantissa lower/upper boundary behavior
    • Precision limits
    • Exponent bias correctness
    • Encoding/decoding round-trip accuracy
  • Mantissa bit-width, exponent bias, and masks follow the spec of 27-bit price mantissa and 5-bit exponent with a BIAS of 16
  • Precision tests check extreme exponent differences
  • Module is self-contained and ready for integration

@DASMAC-com DASMAC-com deleted a comment from linear bot Dec 3, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements a new price library for encoding and decoding fixed-point decimal prices using a mantissa-exponent representation within a 32-bit integer. The library provides validation, encoding/decoding capabilities, and utilities for converting between different decimal representations.

Key Changes

  • Introduces a price encoding scheme using 27 bits for mantissa and 5 bits for biased exponent
  • Implements validated mantissa with strict digit bounds (8 significant digits)
  • Provides macros for checked arithmetic operations and power-of-10 calculations with biased exponents

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
price/src/lib.rs Main library module defining constants, OrderInfo struct, and conversion logic with tests
price/src/validated_mantissa.rs Wrapper type ensuring mantissa values are within valid 8-digit range
price/src/macros.rs Utility macros for pow10 calculations and checked arithmetic operations
price/src/error.rs Error enum for order information validation failures
price/src/encoded_price.rs Encoding logic for packing mantissa and exponent into u32
price/src/decoded_price.rs Decoding logic for extracting mantissa and exponent from u32
price/Cargo.toml Package manifest with dependencies
Cargo.toml Workspace update to include price crate
Cargo.lock Lock file update for new price package

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

@xbtmatt xbtmatt requested a review from alnoki December 6, 2025 00:28
Copy link

Copilot AI left a comment

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 8 out of 9 changed files in this pull request and generated 17 comments.


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

@xbtmatt xbtmatt requested a review from Copilot December 6, 2025 02:04
@xbtmatt xbtmatt marked this pull request as ready for review December 6, 2025 02:05
Update unit test name to max and max plus one base
Copy link

Copilot AI left a comment

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 8 out of 9 changed files in this pull request and generated 5 comments.


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

Copilot AI review requested due to automatic review settings December 10, 2025 00:15
Copy link

Copilot AI left a comment

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 8 out of 9 changed files in this pull request and generated 11 comments.


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

Copy link
Contributor Author

@xbtmatt xbtmatt left a comment

Choose a reason for hiding this comment

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

Second round of addressing review comments and changes

Copilot AI review requested due to automatic review settings December 11, 2025 23:48
Copy link

Copilot AI left a comment

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 8 out of 12 changed files in this pull request and generated no new comments.


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

Copilot AI review requested due to automatic review settings December 12, 2025 00:53
Copy link
Contributor Author

@xbtmatt xbtmatt left a comment

Choose a reason for hiding this comment

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

Third round of addressing review comments and fixes!

Copy link

Copilot AI left a comment

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 8 out of 12 changed files in this pull request and generated 1 comment.


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

Copy link
Contributor Author

@xbtmatt xbtmatt left a comment

Choose a reason for hiding this comment

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

Fourth round of addressing review comments

@xbtmatt xbtmatt requested a review from alnoki December 12, 2025 21:03
@alnoki alnoki merged commit 845067c into main Dec 13, 2025
@alnoki alnoki deleted the ENG-87 branch December 13, 2025 15:54
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.

2 participants