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

refactor: loosen trait bound for TickDataProvider #134

Merged
merged 1 commit into from
Feb 9, 2025
Merged

refactor: loosen trait bound for TickDataProvider #134

merged 1 commit into from
Feb 9, 2025

Conversation

shuhuiluo
Copy link
Owner

@shuhuiluo shuhuiluo commented Feb 9, 2025

Removed unnecessary Clone trait bound from multiple implementations and functions, streamlining the code where cloning wasn't needed. Updated tests and function signatures accordingly to ensure consistency. Also incremented the package version to reflect these changes.

Summary by CodeRabbit

  • New Features
     • Enhanced token swapping functionality with improved conversion calculations and robust validations for smoother trade experiences.
     • Introduced advanced trade routing that optimizes conversion paths based on user-specified criteria.
     • Streamlined position rebalancing for more intuitive management during price adjustments.

  • Documentation
     • Updated user-facing SDK information to reflect the latest improvements.

  • Chores
     • Upgraded dependency versions for enhanced performance and stability.

Removed unnecessary `Clone` trait bound from multiple implementations and functions, streamlining the code where cloning wasn't needed. Updated tests and function signatures accordingly to ensure consistency. Also incremented the package version to reflect these changes.
Copy link
Contributor

coderabbitai bot commented Feb 9, 2025

Walkthrough

This pull request updates version numbers and refines functionality across several modules. The Cargo.toml and README.md now reflect updated package versions for uniswap-v3-sdk and uniswap-sdk-core. In src/entities/pool.rs, four new methods have been introduced to calculate and update token swap amounts with improved error handling and state mutation. In src/entities/trade.rs, two methods enable recursive evaluation of trade routes. Lastly, in src/extensions/position.rs, method signatures have been revised to accept ownership rather than mutable references, with corresponding internal logic and tests updated.

Changes

File(s) Change Summary
Cargo.toml, README.md Updated version numbers: uniswap-v3-sdk from "3.6.0"/"3.5.0" to "3.6.1"/"3.6.0" respectively, and uniswap-sdk-core from "3.5.0" to "3.6.0".
src/entities/pool.rs Added four new methods (get_output_amount, get_output_amount_mut, get_input_amount, get_input_amount_mut) with token validation, error handling, and state updates.
src/entities/trade.rs Added best_trade_exact_in and best_trade_exact_out methods for recursive trade route evaluation and candidate selection.
src/extensions/position.rs Modified get_rebalanced_position and get_rebalanced_position_at_price to take ownership instead of mutable references; adjusted internal logic and tests.

Sequence Diagram(s)

sequenceDiagram
    participant C as Caller
    participant P as Pool
    C->>P: get_output_amount(input, price_limit)
    P-->>C: Validate token & liquidity
    P->>P: Compute swap amount
    alt state change required
        P->>P: Update sqrt_ratio, tick, liquidity
    end
    P-->>C: Return output amount or error
Loading
sequenceDiagram
    participant U as User
    participant T as Trade
    participant P as Pool
    U->>T: best_trade_exact_in(input, options)
    T->>P: Query pool swap parameters
    T->>T: Recursively explore trade routes
    T-->>U: Return best trade candidate(s)
Loading

Possibly related PRs

Poem

In the realm of swaps where logic prevails,
Our code refines with precision that never fails.
Versions updated, methods anew,
Trade routes discovered with a recursive view.
Each function stands firm—Bazinga, it's true!
A symphony of logic, precise and debonair too.


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.

@shuhuiluo
Copy link
Owner Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Feb 9, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 23218ec and 5c6a935.

📒 Files selected for processing (5)
  • Cargo.toml (2 hunks)
  • README.md (1 hunks)
  • src/entities/pool.rs (0 hunks)
  • src/entities/trade.rs (1 hunks)
  • src/extensions/position.rs (7 hunks)
💤 Files with no reviewable changes (1)
  • src/entities/pool.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Rust Tests
🔇 Additional comments (6)
src/entities/trade.rs (2)

620-620: All clear, dear mortals.

This closing brace appears merely to finalize the preceding implementation block. No concerns to raise.


622-627: 🧹 Nitpick (assertive)

Are we sure we need Clone on TP?

The PR aims to remove unneeded clone bounds. Validate if you actually require TP to be clonable. Eliminating unneeded constraints avoids extraneous copying.

src/extensions/position.rs (1)

477-480: Ownership pass seems consistent.

Passing 'position' by value aligns with the approach of returning a newly computed Position object. Ensure you truly intend to consume the old entity each time. This is acceptable if you don't reuse the original position afterwards.

Cargo.toml (2)

3-3: Incremented version is noted.

Upgrading from 3.6.0 to 3.6.1 is a trivial change. A wise move if it includes relevant bug fixes.


32-32: 🏁 Script executed:

#!/bin/bash
# Attempt to check for build issues with uniswap-sdk-core v3.6.0
cargo update -p uniswap-sdk-core
cargo check --all-features

Length of output: 255

README.md (1)

53-53: SDK Dependency Version Update: Approved, Yet Verify Consistency.
The upgrade from "3.5.0" to "3.6.0" is scientifically sound and elegantly executed, much like the precision of a theoretical physics formula. However, ensure that Cargo.toml reflects this same version update so that our dependency string does not become a source of quantum uncertainty.

src/extensions/position.rs Show resolved Hide resolved
@shuhuiluo shuhuiluo merged commit 09d588b into v3 Feb 9, 2025
3 checks passed
@shuhuiluo shuhuiluo deleted the bound branch February 9, 2025 07:06
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.

1 participant