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

Range test variants and precision #569

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open

Conversation

magiodev
Copy link
Member

@magiodev magiodev commented Feb 14, 2024

1. Overview

This PR enhances precision and accuracy in smart contract calculations related to Concentrated Liquidity (CL) pools. Key updates include the introduction of scale_if_needed in helpers.rs, application of this scaling logic within get_single_sided_deposit_0_to_1_swap_amount and get_single_sided_deposit_1_to_0_swap_amount functions, addition of a new test case for CL pool initialization with tokens of differing decimal precisions, and general enhancements to the test suite and initialize.rs.

2. Implementation details

  • scale_if_needed Function: Implemented in helpers.rs to dynamically determine the need for scaling based on the product of Decimal256 values against a predefined threshold. This function ensures precision in smart contract calculations by scaling values up when necessary.
  • Scaling Logic Integration: Applied scale_if_needed within get_single_sided_deposit_0_to_1_swap_amount and get_single_sided_deposit_1_to_0_swap_amount functions to maintain calculation accuracy, especially in financial computations involving tokens with different decimal precisions.
  • Test Case for CL Pool Initialization: Added a test case, move_range_works_18dec_usdc, to verify the correct initialization and operation of a CL pool with 18DEC and USDC tokens, demonstrating real-world application scenarios and ensuring the system behaves as expected with tokens of varying decimal places.
  • Test Suite and initialize.rs Enhancements: The test suite has been expanded to cover the newly implemented scaling logic, and initialize.rs has been generalized to support a wider range of initialization scenarios, improving the robustness and flexibility of smart contract testing and deployment.

3. How to test/use

  • Unit Tests: Run the updated unit tests test_scale_if_needed_variants, including the new move_range_works_18dec_usdc test tube case.

4. Checklist

  • Does the Readme need to be updated?

5. Limitations (optional)

The current scaling implementation assumes a static threshold for determining the need for scaling. Future market dynamics or additional use cases may require revisiting this threshold or the scaling logic to ensure continued accuracy and precision.

6. Future Work (optional)

  • Dynamic Scaling Thresholds: Explore mechanisms for adjusting the scaling threshold dynamically based on real-time market conditions or specific contract states.
  • Optimization: Assess the impact of the current scaling logic on gas costs and computational efficiency, identifying opportunities for optimization.

@magiodev magiodev changed the title Feat/range test variants Range test variants and precision Feb 14, 2024
Copy link
Member

@ajansari95 ajansari95 left a comment

Choose a reason for hiding this comment

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

just a single nit otherwise lgtm

ajansari95
ajansari95 previously approved these changes Feb 15, 2024
Copy link
Member

@ajansari95 ajansari95 left a comment

Choose a reason for hiding this comment

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

lgtm 🚢

LaurensKubat
LaurensKubat previously approved these changes Feb 15, 2024
Copy link
Contributor

@LaurensKubat LaurensKubat left a comment

Choose a reason for hiding this comment

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

lgtm

smart-contracts/contracts/cl-vault/src/helpers.rs Outdated Show resolved Hide resolved
## 1. Overview

Minor code changes that should not affect functionality and refactoring
of test-tube init functions

## 2. Implementation details

- Bump osmosis-std and osmosis-test-tube versions
- Refactor a boolean condition for easier readability
- test tube init refactor

## 3. How to test/use

<!-- How can people test/use this? -->

## 4. Checklist

<!-- Checklist for PR author(s). -->

[x] Does the Readme need to be updated?
No

## 5. Limitations (optional)

N/A

## 6. Future Work (optional)

N/A
@magiodev magiodev marked this pull request as ready for review February 15, 2024 19:20
@LaurensKubat LaurensKubat self-requested a review February 15, 2024 19:31
LaurensKubat
LaurensKubat previously approved these changes Feb 15, 2024
Copy link
Contributor

@LaurensKubat LaurensKubat left a comment

Choose a reason for hiding this comment

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

lgtm

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.

None yet

3 participants