Skip to content

Conversation

@aarmoa
Copy link
Collaborator

@aarmoa aarmoa commented Mar 3, 2025

  • Added quantization in the functions that convert notional values to chain format

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced numerical precision during value conversion, ensuring more consistent rounding.
  • Chores
    • Released updated version 1.9.1.
  • Documentation
    • Updated the changelog to reflect these improvements.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 3, 2025

Walkthrough

This update bumps the project to version 1.9.1. A new entry in the CHANGELOG documents a fix in the conversion of notional values to chain format. In the pyinjective/core/market.py file, the notional_to_chain_format method in three market classes now applies an explicit quantization step (rounding up to the nearest whole number) before the conversion is finalized. The version in pyproject.toml has been updated accordingly.

Changes

File(s) Change Summary
CHANGELOG.md Added new section for version 1.9.1 (dated 2025-03-03) with a "Fixed" category documenting the quantization fix in the conversion process.
pyinjective/core/market.py Modified notional_to_chain_format in SpotMarket, DerivativeMarket, and BinaryOptionMarket to first quantize the value (using ROUND_UP) before multiplication.
pyproject.toml Updated project version from "1.9.0" to "1.9.1" in the [tool.poetry] section.

Sequence Diagram(s)

sequenceDiagram
    participant C as Caller
    participant M as Market Method
    participant Q as Quantizer
    participant X as Multiplier

    C->>M: Call notional_to_chain_format(value)
    M->>Q: Quantize chain_formatted_value (ROUND_UP)
    Q-->>M: Return quantized_value
    M->>X: Multiply quantized_value by 10^(ADDITIONAL_CHAIN_FORMAT_DECIMALS)
    X-->>M: Return extended_chain_formatted_value
    M-->>C: Return final chain formatted value
Loading

Poem

I'm a rabbit with a hop so light,
Quantizing numbers just feels so right.
With a skip and a jump in our code today,
Precision leads the playful way.
Version bumped and systems bright—
Hoppy changes guide our plight!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pyinjective/core/market.py (1)

124-125: Consider standardizing variable naming across similar methods.

While the implementation is correct, the variable is named quantized_notional here but quantized_value in the BinaryOptionMarket class. Consider standardizing the variable names for easier maintenance.

-        quantized_notional = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP)
-        extended_chain_formatted_value = quantized_notional * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
+        quantized_value = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP)
+        extended_chain_formatted_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a9b3c79 and 7074685.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • pyinjective/core/market.py (4 hunks)
  • pyproject.toml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • pyproject.toml
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: run-tests (3.11, windows-latest)
  • GitHub Check: run-tests (3.10, windows-latest)
  • GitHub Check: run-tests (3.9, windows-latest)
🔇 Additional comments (5)
pyinjective/core/market.py (4)

2-2: LGTM! Import of ROUND_UP looks good.

You've correctly imported ROUND_UP from the decimal module that will be used for the quantization implementation.


42-43: Consistent implementation of notional quantization across market types.

The quantization is correctly implemented to round up notional values to the nearest whole number before applying additional chain formatting. This will ensure that notional values are consistently handled across all market types and avoid potential precision issues in chain representation.

Also applies to: 124-125, 235-236


235-236: Good implementation of quantization in BinaryOptionMarket.

The notional quantization implementation for BinaryOptionMarket looks correct and follows the same pattern as the other market classes.


42-43:

Details

❓ Verification inconclusive

Verify impact of ROUND_UP on boundary cases.

Using ROUND_UP will always round to the next higher integer, which is different from mathematical rounding. This could potentially increase notional values slightly compared to previous behavior.

Also applies to: 124-125, 235-236


🏁 Script executed:

#!/bin/bash
# Check for existing unit tests that might be affected by the rounding change

echo "Searching for unit tests related to notional_to_chain_format:"
fd -t f -e py "test" | xargs grep -l "notional_to_chain_format" || echo "No direct test files found"

echo "Searching for usage of notional_to_chain_format method:"
rg "notional_to_chain_format" --type py

Length of output: 1582


Action Required: Confirm Rounding Behavior on Boundary Cases

The revised implementation uses ROUND_UP when quantizing values, which may push results to the next higher integer on boundary cases. This behavior differs from standard mathematical rounding and could lead to slightly increased notional values. Please ensure the following:

  • Review Unit Tests: Verify that the tests in tests/core/test_market.py for notional_to_chain_format adequately cover edge cases where the value is exactly at the quantization boundary.
  • Check Consistency Across Locations: The same rounding logic appears at lines 42-43, as well as lines 124-125 and 235-236 in pyinjective/core/market.py. Confirm that all instances behave as expected in boundary scenarios.

Once you've double-checked these areas and ensured that any potential differences in rounding behavior are intentional and correctly documented, this comment can be resolved.

CHANGELOG.md (1)

5-7: LGTM! Changelog entry correctly explains the change.

The changelog entry clearly describes the addition of quantization to notional value conversion functions, which matches the code changes made in pyinjective/core/market.py.

Comment on lines +42 to +43
quantized_balue = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP)
extended_chain_formatted_value = quantized_balue * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the typo in variable name "quantized_balue".

There's a typo in the variable name "quantized_balue" which should be "quantized_value" to maintain consistency with the naming convention used in the other market classes.

-        quantized_balue = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP)
-        extended_chain_formatted_value = quantized_balue * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
+        quantized_value = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP)
+        extended_chain_formatted_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
quantized_balue = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP)
extended_chain_formatted_value = quantized_balue * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")
quantized_value = chain_formatted_value.quantize(Decimal("1"), rounding=ROUND_UP)
extended_chain_formatted_value = quantized_value * Decimal(f"1e{ADDITIONAL_CHAIN_FORMAT_DECIMALS}")

@aarmoa aarmoa merged commit 0416c2a into master Mar 3, 2025
10 of 13 checks passed
@aarmoa aarmoa deleted the fix/add_notional_quantization branch March 3, 2025 15:29
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