quasar
quasar copied to clipboard
Range test variants and precision
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 inhelpers.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
withinget_single_sided_deposit_0_to_1_swap_amount
andget_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, andinitialize.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 newmove_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.