Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mdjakovic/update curve #767

Merged
merged 6 commits into from
Jan 16, 2025
Merged

Mdjakovic/update curve #767

merged 6 commits into from
Jan 16, 2025

Conversation

mdjakovic0920
Copy link
Contributor

@mdjakovic0920 mdjakovic0920 commented Jan 15, 2025

Motivation

We have to resolve the query error caused by float data type.
The chain does not support that type.

image

Implementation

To resolve this issue, I used u64 instead of float64 as the input type, and implemented the Decimal as the calculation.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed a query error in the Curve ADO related to Float data type handling.
  • Improvements

    • Enhanced type safety for curve calculations by changing input types from f64 to u64.
    • Improved mathematical precision using Decimal type for curve computations.
  • Testing

    • Added new test case for growth curve with base 4.
    • Updated existing test cases to align with new type requirements.

Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request addresses a query error in the Curve ADO related to Float data type handling. The changes primarily involve modifying the query_plot_y_from_x function across multiple files, changing the input parameter type from f64 to u64. The modifications enhance precision and type safety by using Decimal for calculations and introducing more robust error handling. A new test case for a growth curve with base 4 has also been added to improve test coverage.

Changes

File Change Summary
CHANGELOG.md Added fixed entry for Curve ADO query error
contracts/math/andromeda-curve/src/contract.rs Changed x_value type from f64 to u64, updated calculations using Decimal
contracts/math/andromeda-curve/src/testing/mock.rs Updated query_plot_y_from_x function signature to use u64
contracts/math/andromeda-curve/src/testing/tests.rs Modified test functions to use u64, added new test case for base 4 growth
packages/andromeda-math/src/curve.rs Updated GetPlotYFromX enum variant to use u64
contracts/math/andromeda-curve/src/mock.rs Updated query_plot_y_from_x method signature to use u64

Possibly related PRs

  • Update Curve ADO(Fix errors from #qa) #762: The changes in the main PR address an error in the Curve ADO's query related to the Float data type, while this PR updates the Curve ADO's configuration handling, which may relate to the overall functionality and data types used in the Curve ADO operations.

Suggested reviewers

  • joemonem
  • crnbarr93

Poem

🐰 A rabbit's tale of numeric might,
Where floats once danced in decimal light,
Now integers stride with precision's grace,
Curve calculations find their rightful place,
Math magic transformed, clean and bright! 🧮


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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. (Beta)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@mdjakovic0920 mdjakovic0920 added the backport/release/4 backport to release/4 label Jan 15, 2025
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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93abfa9 and 1dd3a0e.

📒 Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • contracts/math/andromeda-curve/src/contract.rs (3 hunks)
  • contracts/math/andromeda-curve/src/testing/mock.rs (1 hunks)
  • contracts/math/andromeda-curve/src/testing/tests.rs (4 hunks)
  • packages/andromeda-math/src/curve.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Contract Tests (ubuntu-latest, unit-test)
  • GitHub Check: Contract Tests (ubuntu-latest, integration-test)
  • GitHub Check: Contracts
  • GitHub Check: Schemas
  • GitHub Check: Summary
🔇 Additional comments (6)
contracts/math/andromeda-curve/src/testing/mock.rs (1)

81-81: Update tests to reflect the x_value type change

The parameter x_value in query_plot_y_from_x within the mock has been updated from f64 to u64. Please ensure all test cases and mock implementations are adjusted accordingly to prevent type mismatches and test failures.

contracts/math/andromeda-curve/src/testing/tests.rs (4)

Line range hint 157-172: LGTM! Test cases for base 2 growth curve are well-structured.

The test cases correctly verify exponential growth with base 2, and the type change from f64 to u64 aligns with the PR objectives to fix float-related issues.


Line range hint 175-190: LGTM! Test cases for base 3 growth curve are well-structured.

The test cases correctly verify exponential growth with base 3, and the type change from f64 to u64 aligns with the PR objectives.


193-209: Great addition! Test cases for base 4 growth curve with constant value enhance coverage.

The new test cases correctly verify exponential growth with base 4 and constant value 2, providing better coverage for the curve configurations.


Line range hint 211-226: LGTM! Test cases for base 2 decay curve handle decimals correctly.

The test cases correctly verify exponential decay with base 2, and the string comparison ensures precise handling of decimal values.

CHANGELOG.md (1)

42-42: LGTM! Changelog entry is clear and properly placed.

The entry accurately describes the fix for the Curve ADO's query error related to float data type.

contracts/math/andromeda-curve/src/contract.rs Outdated Show resolved Hide resolved
packages/andromeda-math/src/curve.rs Show resolved Hide resolved
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: 0

🧹 Nitpick comments (1)
contracts/math/andromeda-curve/src/contract.rs (1)

185-190: Consider using Decimal::from_ratio for cleaner initialization.

Instead of using Decimal::percent, consider using Decimal::from_ratio for a more direct and cleaner way to initialize the decimal values.

-            let base_value_decimal = Decimal::percent(base_value * 100);
-            let constant_value_decimal =
-                Decimal::percent(constant_value.unwrap_or(DEFAULT_CONSTANT_VALUE) * 100);
-            let multiple_variable_value_decimal = Decimal::percent(
-                multiple_variable_value.unwrap_or(DEFAULT_MULTIPLE_VARIABLE_VALUE) * 100,
-            );
+            let base_value_decimal = Decimal::from_ratio(base_value, 1u64);
+            let constant_value_decimal =
+                Decimal::from_ratio(constant_value.unwrap_or(DEFAULT_CONSTANT_VALUE), 1u64);
+            let multiple_variable_value_decimal =
+                Decimal::from_ratio(multiple_variable_value.unwrap_or(DEFAULT_MULTIPLE_VARIABLE_VALUE), 1u64);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1dd3a0e and 166fc9c.

📒 Files selected for processing (2)
  • contracts/math/andromeda-curve/src/contract.rs (3 hunks)
  • contracts/math/andromeda-curve/src/mock.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Contract Tests (ubuntu-latest, unit-test)
  • GitHub Check: Contract Tests (ubuntu-latest, integration-test)
  • GitHub Check: Contract Tests (ubuntu-latest, unit-test)
  • GitHub Check: Contract Tests (ubuntu-latest, integration-test)
  • GitHub Check: Contracts
  • GitHub Check: Schemas
  • GitHub Check: Summary
🔇 Additional comments (7)
contracts/math/andromeda-curve/src/mock.rs (1)

83-86: LGTM! Parameter type change aligns with contract implementation.

The change from f64 to u64 for x_value parameter matches the contract implementation and helps resolve the float data type issue.

contracts/math/andromeda-curve/src/contract.rs (6)

18-19: LGTM! Added Decimal import for precise calculations.

The addition of Decimal type from cosmwasm_std is appropriate for handling precise numerical calculations.


174-174: LGTM! Parameter type change matches mock implementation.

The change from f64 to u64 for x_value parameter aligns with the mock implementation and helps resolve the float data type issue.


192-199: LGTM! Proper error handling for decimal conversion.

The code properly handles potential errors during decimal conversion and multiplication operations.


201-208: LGTM! Overflow check for u32 conversion.

The code properly checks if the exponent value exceeds u32::MAX before attempting the conversion.


211-218: LGTM! Safe decimal operations with overflow checks.

The code uses checked operations (checked_mul, checked_pow) to safely handle potential overflows in decimal calculations.


220-225: LGTM! Proper handling of curve types with underflow check.

The code correctly handles both Growth and Decay curve types, with proper error handling for potential underflow in division operations.

@@ -60,7 +60,7 @@ pub enum QueryMsg {
#[returns(GetCurveConfigResponse)]
GetCurveConfig {},
#[returns(GetPlotYFromXResponse)]
GetPlotYFromX { x_value: f64 },
GetPlotYFromX { x_value: u64 },
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want to use ::cosmwasm_std::Decimal type here rather than u64

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, Decimal's checked_pow() function must have u32 type parameter.
So it can only be calculated by u32 exponent.
In this case, the usage of u64 and Decimal are the same.
But if you want to Decimal as x_value's input type, I will do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I use the Decimal as x_value?

@mdjakovic0920
Copy link
Contributor Author

Looks good!

@crnbarr93 crnbarr93 merged commit fa3aa1d into main Jan 16, 2025
12 checks passed
@crnbarr93 crnbarr93 deleted the mdjakovic/update-curve branch January 16, 2025 13:17
mergify bot pushed a commit that referenced this pull request Jan 16, 2025
Co-authored-by: Connor Barr <[email protected]>
(cherry picked from commit fa3aa1d)
crnbarr93 pushed a commit that referenced this pull request Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/release/4 backport to release/4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants