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!: consolidate currency-related traits and add Currency enum #85

Merged
merged 1 commit into from
Oct 6, 2024

Conversation

shuhuiluo
Copy link
Collaborator

@shuhuiluo shuhuiluo commented Oct 6, 2024

Reorganized BaseCurrency and BaseCurrencyCore traits, encapsulating their functionalities. Introduced Currency enum to represent both native and token currencies, providing a unified interface for currency operations. Updated version to 3.0.0 to reflect these breaking changes.

Summary by CodeRabbit

  • New Features

    • Updated package version for uniswap-sdk-core from 2.4.0 to 3.0.0.
    • Enhanced currency representation with new BaseCurrencyCore and BaseCurrency traits.
    • Introduced a new Currency enum to simplify currency handling.
  • Bug Fixes

    • Adjusted type constraints in various structures and implementations to ensure compatibility with the new base currency model.
  • Documentation

    • Updated README.md to reflect the new version of uniswap-sdk-core.
  • Chores

    • Consolidated module imports in src/prelude.rs for easier access to public items.

Reorganized `BaseCurrency` and `BaseCurrencyCore` traits, encapsulating their functionalities. Introduced `Currency` enum to represent both native and token currencies, providing a unified interface for currency operations. Updated version to 3.0.0 to reflect these breaking changes.
Copy link

coderabbitai bot commented Oct 6, 2024

Walkthrough

The pull request includes significant updates to the uniswap-sdk-core package, primarily marked by a version increment from 2.4.0 to 3.0.0 in the Cargo.toml and README.md files. The changes also introduce a new trait structure in the currency representation, transitioning from a trait-based system to an enum-based system in various files, enhancing the clarity and usability of currency handling. Additionally, there are updates to type constraints across multiple files to utilize the new BaseCurrency trait.

Changes

File Change Summary
Cargo.toml Updated package version from 2.4.0 to 3.0.0. Dependencies and features remain consistent.
README.md Updated dependency version from 2.4.0 to 3.0.0 in the Quickstart section.
src/entities/base_currency.rs Introduced BaseCurrencyCore trait, updated BaseCurrency trait to inherit from it, and added new methods.
src/entities/currency.rs Replaced Currency trait with a Currency enum, simplifying currency representation.
src/entities/ether.rs Renamed macro from impl_currency! to impl_base_currency!, updated trait implementations accordingly.
src/entities/fractions/currency_amount.rs Updated generic type constraints from Currency to BaseCurrency in CurrencyMeta and CurrencyAmount.
src/entities/fractions/price.rs Updated generic type constraints from Currency to BaseCurrency in PriceMeta and multiply method.
src/entities/native_currency.rs Changed NativeCurrency trait to extend BaseCurrencyCore instead of BaseCurrency.
src/entities/token.rs Updated macro and trait implementations to use BaseCurrency instead of Currency.
src/prelude.rs Consolidated module imports for base_currency and currency using wildcard imports.
src/utils/compute_price_impact.rs Updated function signature to change type constraints from Currency to BaseCurrency.

Possibly related PRs

Suggested reviewers

  • malik672

Poem

🐰 In the garden where currencies play,
A new version hops in today!
With traits that dance and enums that sing,
The Uniswap SDK takes to the spring.
From two to three, we leap with delight,
In the world of tokens, everything feels right! 🌼


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 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.

Copy link

@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

🧹 Outside diff range and nitpick comments (7)
src/entities/native_currency.rs (1)

Line range hint 1-15: Summary of changes and recommendations

The changes to src/entities/native_currency.rs appear to be part of a larger refactoring effort to improve the currency trait hierarchy. The main points to consider are:

  1. The NativeCurrency trait now extends BaseCurrencyCore instead of BaseCurrency, which may have significant implications across the codebase.
  2. The existing methods is_native and is_token seem compatible with the new structure, but this should be verified against the BaseCurrencyCore definition.
  3. The implementation for CurrencyLike<true, M> needs to be checked to ensure it satisfies the requirements of BaseCurrencyCore.

To ensure the consistency and correctness of these changes:

  1. Review all usages of NativeCurrency and BaseCurrency throughout the codebase.
  2. Update any documentation related to the currency trait hierarchy.
  3. Consider adding tests to verify that the behavior of NativeCurrency implementations remains consistent with the expected functionality after this change.

These steps will help maintain the integrity of the currency system while benefiting from the new, more refined trait structure.

src/entities/ether.rs (1)

Ether does not implement the BaseCurrency trait

  • The Ether type does not implement the BaseCurrency trait as expected after recent changes.
  • Ensure that impl BaseCurrency for Ether is provided and all required methods are implemented.
  • Verify that existing test cases cover all aspects of the BaseCurrency trait implementation for Ether.
🔗 Analysis chain

Line range hint 1-6: Verify compatibility of unchanged code with new trait structure

While the Ether type definition, struct methods, and test cases remain unchanged, it's crucial to ensure they are still valid and complete given the introduction of the BaseCurrency trait. Please verify that:

  1. The Ether type definition still accurately represents the concept of Ether in the new trait hierarchy.
  2. Existing struct methods fulfill all requirements of the new BaseCurrency trait.
  3. Test cases cover all aspects of the BaseCurrency trait implementation.

To assist with this verification, you can run the following script:

This script will help ensure that the Ether type fully implements the BaseCurrency trait and that all methods are adequately tested.

Also applies to: 29-78


Further verification needed for BaseCurrency trait implementation and test coverage

To ensure comprehensive verification, please run the following scripts:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the completeness of BaseCurrency trait implementation for Ether

# Test 1: Check if all BaseCurrency methods are implemented for Ether
echo "Checking BaseCurrency trait implementation for Ether:"
ast-grep --lang rust --pattern $'impl BaseCurrency for Ether {
  $$$
}'

# Test 2: Verify test coverage for BaseCurrency methods
echo "Checking test coverage for BaseCurrency methods:"
rg --type rust -A 5 $'#[test]' src/entities/ether.rs

Length of output: 350


Script:

#!/bin/bash

# Test 1: Check if BaseCurrency trait is implemented for Ether
echo "Verifying BaseCurrency trait implementation for Ether:"
ast-grep --lang rust --pattern $'impl BaseCurrency for Ether {
  $$$
}'

# Test 2: List all test functions related to BaseCurrency in ether.rs
echo "Listing test cases for BaseCurrency methods in Ether:"
rg --type rust '#\[test\]' src/entities/ether.rs

Length of output: 407

README.md (1)

Line range hint 1-138: Consider updating README to reflect recent changes

While the version number has been correctly updated, it might be beneficial to review and potentially update other parts of the README to reflect the significant changes mentioned in the PR objectives. Specifically:

  1. Consider adding information about the new Currency enum and its usage.
  2. Update the example code to demonstrate the use of consolidated currency-related traits, if applicable.
  3. Add a note about the breaking changes in version 3.0.0 to alert users who might be upgrading.

These additions would provide users with a more comprehensive understanding of the recent changes and how to use the new features.

🧰 Tools
🪛 Markdownlint

19-19: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

src/entities/token.rs (1)

Line range hint 1-324: Summary: Successful transition to BaseCurrency trait

The changes in this file successfully implement the transition from the Currency trait to the BaseCurrency trait. This refactoring aligns well with the PR objectives to consolidate currency-related traits. The modifications are consistent throughout the file and maintain the existing functionality while potentially allowing for more flexible currency comparisons.

However, it's crucial to ensure that this change is reflected consistently across the entire codebase. The verification script provided earlier will help identify any remaining references to the Currency trait that might need updating.

Consider adding a brief comment in the file explaining the rationale behind the BaseCurrency trait and its relationship to other currency-related traits in the system. This would help future developers understand the design decisions made in this refactoring.

src/entities/currency.rs (1)

Line range hint 99-127: Update test cases to utilize the new Currency enum variants

The current tests use Ether and Token directly. To fully exercise the new Currency enum structure, consider updating the tests to use Currency::NativeCurrency(Ether::on_chain(chain_id)) and Currency::Token(token_instance). This will ensure that the enum's behavior is thoroughly validated.

For example, modify the test as follows:

-assert!(Ether::on_chain(1).equals(&Ether::on_chain(1)));
+let currency_a = Currency::NativeCurrency(Ether::on_chain(1));
+let currency_b = Currency::NativeCurrency(Ether::on_chain(1));
+assert!(currency_a.equals(&currency_b));
src/entities/fractions/currency_amount.rs (1)

Line range hint 71-73: Use a more descriptive error variant in to_fixed method.

Currently, when decimal_places exceed the currency's decimals, the method returns Error::NotEqual, which might not clearly convey the issue. Consider defining a new error variant, such as Error::InvalidDecimalPlaces, to provide clearer feedback to the user about the nature of the error.

Apply this diff to introduce a new error variant and update the error handling:

 // In your Error enum definition:
+/// Error indicating that the provided decimal places exceed the currency's decimals.
+InvalidDecimalPlaces,

 // In the `to_fixed` method:
 if decimal_places > self.currency.decimals() {
-    return Err(Error::NotEqual);
+    return Err(Error::InvalidDecimalPlaces);
 }
src/entities/base_currency.rs (1)

Line range hint 32-39: Prefer returning Option<&str> instead of Option<&String>

In the BaseCurrencyCore trait, the methods symbol and name return Option<&String>. It's more idiomatic in Rust to return Option<&str> to provide greater flexibility and avoid unnecessary indirection.

Apply the following changes:

- fn symbol(&self) -> Option<&String>;
+ fn symbol(&self) -> Option<&str>;

- fn name(&self) -> Option<&String>;
+ fn name(&self) -> Option<&str>;

Ensure that the implementations of these methods return Option<&str> accordingly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6fd1059 and 01d1dbf.

📒 Files selected for processing (11)
  • Cargo.toml (1 hunks)
  • README.md (1 hunks)
  • src/entities/base_currency.rs (3 hunks)
  • src/entities/currency.rs (2 hunks)
  • src/entities/ether.rs (2 hunks)
  • src/entities/fractions/currency_amount.rs (1 hunks)
  • src/entities/fractions/price.rs (3 hunks)
  • src/entities/native_currency.rs (1 hunks)
  • src/entities/token.rs (2 hunks)
  • src/prelude.rs (1 hunks)
  • src/utils/compute_price_impact.rs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Cargo.toml
🧰 Additional context used
🔇 Additional comments (21)
src/entities/native_currency.rs (3)

Line range hint 6-13: Verify compatibility of existing methods with BaseCurrencyCore

The is_native and is_token methods appear to be compatible with the new BaseCurrencyCore supertrait, as they implement basic currency type checking functionality. However, it's important to ensure that these methods align with the expectations set by BaseCurrencyCore.

Please run the following script to check the BaseCurrencyCore trait definition:

#!/bin/bash
# Description: Check the BaseCurrencyCore trait definition

echo "Searching for BaseCurrencyCore trait definition:"
rg --type rust "trait BaseCurrencyCore" -A 10

After reviewing the BaseCurrencyCore trait definition, please confirm that is_native and is_token are either required by BaseCurrencyCore or are appropriate extensions for NativeCurrency.


Line range hint 15-15: Verify CurrencyLike<true, M> implements BaseCurrencyCore

The implementation of NativeCurrency for CurrencyLike<true, M> remains syntactically valid. However, with the change in the NativeCurrency trait's supertrait from BaseCurrency to BaseCurrencyCore, it's crucial to ensure that CurrencyLike<true, M> satisfies all the requirements of BaseCurrencyCore.

Please run the following script to check the implementation of BaseCurrencyCore for CurrencyLike:

#!/bin/bash
# Description: Check BaseCurrencyCore implementation for CurrencyLike

echo "Searching for BaseCurrencyCore implementation for CurrencyLike:"
rg --type rust "impl.*BaseCurrencyCore.*for.*CurrencyLike" -C 5

After reviewing the results, please confirm that CurrencyLike<true, M> properly implements BaseCurrencyCore. If it doesn't, you may need to add an explicit implementation or adjust the trait bounds on CurrencyLike.


4-4: 🛠️ Refactor suggestion

Verify the impact of changing the supertrait to BaseCurrencyCore

The change from BaseCurrency to BaseCurrencyCore as the supertrait for NativeCurrency represents a significant alteration in the trait hierarchy. This modification might have far-reaching effects on the codebase, particularly in areas where NativeCurrency is used and expected to have all the methods from BaseCurrency.

Please run the following script to check for potential inconsistencies or breaking changes:

Consider updating the documentation for NativeCurrency to reflect this change in the trait hierarchy. Also, ensure that any code relying on NativeCurrency having all methods from BaseCurrency is updated accordingly.

src/prelude.rs (1)

6-7: 🛠️ Refactor suggestion

Consider the implications of using wildcard imports.

The changes from specific imports to wildcard imports (*) for base_currency and currency modules have both advantages and potential drawbacks:

Pros:

  1. Simplifies import statements, reducing code verbosity.
  2. Allows easy access to all public items in these modules without explicitly listing them.

Cons:

  1. May lead to name conflicts if multiple modules export items with the same name.
  2. Reduces code readability as it's less clear which specific items are being imported.
  3. Can potentially expose more of the API than intended, which might complicate future refactoring.

These changes align with the PR objectives of consolidating currency-related traits. However, consider the following:

  1. Ensure that this change doesn't introduce any name conflicts in the codebase.
  2. Verify that exposing all public items from these modules is intentional and doesn't break encapsulation principles.
  3. Consider adding comments to clarify which specific items are commonly used from these modules.

If you decide to keep the wildcard imports, consider adding comments like this for clarity:

// Imports BaseCurrency, BaseCurrencyCore, etc.
pub use crate::entities::base_currency::*;
// Imports Currency, CurrencyLike, etc.
pub use crate::entities::currency::*;

To ensure these changes don't introduce conflicts, run the following script:

This will help identify any potential issues arising from the wildcard imports.

src/entities/ether.rs (2)

7-12: Approve the refactoring of currency traits

The changes to the macro definition and implementation are well-aligned with the PR objectives. The transition from impl_currency to impl_base_currency and the use of BaseCurrency instead of Currency indicate a more specialized and hierarchical approach to currency representations. This refactoring should lead to improved code organization and clarity.

Key improvements:

  1. Renamed macro reflects its more specific purpose.
  2. Use of BaseCurrency trait aligns with the consolidation of currency-related traits.
  3. Updated equals method signature ensures type consistency with the new trait hierarchy.

These changes contribute to a more robust and maintainable codebase.


28-28: Approve the updated macro usage

The change in macro usage from impl_currency! to impl_base_currency! is consistent with the earlier modification to the macro definition. This update ensures that the new impl_base_currency macro is correctly utilized for both Ether and &Ether types.

This change maintains consistency throughout the file and aligns with the overall refactoring strategy.

src/utils/compute_price_impact.rs (2)

13-13: Approve the trait bound change, but verify its impact.

The change from Currency to BaseCurrency for the generic type constraints is likely part of a larger refactoring effort to improve the type system. This change appears to be in line with the PR objectives of consolidating currency-related traits.

To ensure this change doesn't introduce unintended consequences, please run the following script to check for any other occurrences of the Currency trait that might need updating:

✅ Verification successful

Trait Bound Change Verified Successfully

The update from Currency to BaseCurrency in the generic type constraints does not affect other parts of the codebase. No additional usages of the Currency trait were found, ensuring the change is safe and isolated.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other occurrences of the Currency trait
# that might need updating after this change.

# Search for Currency trait usage
echo "Searching for Currency trait usage:"
rg --type rust "trait.*Currency" -g '!target/'

# Search for Currency trait bounds
echo "Searching for Currency trait bounds:"
rg --type rust "<.*: Currency" -g '!target/'

Length of output: 476


Line range hint 14-38: Verify BaseCurrency trait implementation and test validity.

The function body remains unchanged, which is good. However, we should ensure that:

  1. All method calls on TBase and TQuote in the function body are still valid with the BaseCurrency trait.
  2. The concrete types used in the tests (Ether, token, token_1) implement the BaseCurrency trait.

Please run the following script to verify the BaseCurrency trait implementation:

If any of these checks fail, you may need to update the trait implementations or the test cases accordingly.

README.md (1)

21-21: Version update reflects significant changes

The update from version 2.4.0 to 3.0.0 correctly reflects the major changes described in the PR objectives, including the consolidation of currency-related traits and the addition of the Currency enum. This change follows semantic versioning principles, indicating breaking changes to users.

Let's verify if this version update is consistent across the project:

src/entities/fractions/price.rs (4)

26-27: LGTM: Consistent update of type constraints in Price implementation.

The change from Currency to BaseCurrency for TBase and TQuote in the Price implementation is consistent with the earlier update in the PriceMeta struct. This ensures that the entire Price structure uses the more specific BaseCurrency trait.

To ensure this change doesn't affect any methods within the Price implementation, please run the following check:

#!/bin/bash
# Description: Check for any methods in Price implementation that might be affected by the trait change

echo "Checking for methods in Price implementation that use Currency trait:"
rg --type rust -A 10 "impl<TBase, TQuote>.*Price<TBase, TQuote>" src/entities/fractions/price.rs | rg "fn.*Currency"

82-82: LGTM: Consistent update of type constraint in multiply method.

The change from Currency to BaseCurrency for TOtherQuote in the multiply method signature is consistent with the earlier updates. This ensures that the method uses the more specific BaseCurrency trait for its generic parameter.

To ensure this change doesn't break any existing usage of the multiply method, please run the following check:

#!/bin/bash
# Description: Check for any usage of the multiply method that might be affected by the trait change

echo "Checking for usage of multiply method:"
rg --type rust "\.multiply\(<.*>" -A 5

Line range hint 1-238: Summary: Consistent and appropriate updates to currency-related type constraints.

The changes in this file consistently update the type constraints from Currency to BaseCurrency for the PriceMeta struct, Price implementation, and multiply method. These updates align well with the PR objectives of consolidating currency-related traits and likely provide more appropriate constraints for the price-related structures and methods.

To ensure the overall consistency and correctness of these changes, please run the following final verification:

#!/bin/bash
# Description: Verify the consistency of BaseCurrency usage and check for any remaining Currency usages

echo "Checking for any remaining Currency trait usage in price.rs:"
rg --type rust "Currency[^A-Za-z]" src/entities/fractions/price.rs

echo "Verifying consistent usage of BaseCurrency in price.rs:"
rg --type rust "BaseCurrency" src/entities/fractions/price.rs

echo "Checking for any Currency to BaseCurrency changes in other files:"
rg --type rust -g "!price.rs" "BaseCurrency"

This will help ensure that the changes are consistent throughout the file and identify any potential areas that might need attention in other parts of the codebase.


11-12: LGTM: Type constraint update aligns with PR objectives.

The change from Currency to BaseCurrency for TBase and TQuote aligns with the PR's goal of consolidating currency-related traits. This update likely provides a more specific and appropriate constraint for the PriceMeta struct.

To ensure this change doesn't unintentionally restrict the usage of PriceMeta, please verify the trait hierarchy:

src/entities/token.rs (3)

17-20: LGTM: Macro updated to use BaseCurrency

The change from impl_currency to impl_base_currency and the use of BaseCurrency instead of Currency is consistent with the PR objectives to consolidate currency-related traits. This modification enhances the clarity of the trait hierarchy and maintains consistency throughout the implementation.


22-24: LGTM: equals method updated for broader compatibility

The equals method signature has been updated to accept &impl BaseCurrency, which is consistent with the earlier changes and the PR objectives. This modification potentially allows for greater flexibility in comparing different currency types that implement the BaseCurrency trait.


35-35: LGTM: Trait implementation updated to BaseCurrency

The trait implementation for Token has been correctly updated to use BaseCurrency instead of Currency. This change is consistent with the earlier modifications and aligns with the PR objectives.

To ensure this change doesn't have unintended consequences, let's verify its impact on the wider codebase:

src/entities/currency.rs (2)

5-7: Implementation of Currency enum enhances code clarity

The introduction of the Currency enum with variants NativeCurrency and Token consolidates the currency representation, simplifying the handling of different currency types within the codebase.


83-88: Verify correctness of equals method when comparing different currency types

In the equals implementation, Currency::NativeCurrency(ether) calls ether.equals(other). Ensure that the equals method in Ether correctly handles cases where other may be a Token and returns false as expected to prevent incorrect equality evaluations.

You can run the following script to check the equals method implementations:

src/entities/fractions/currency_amount.rs (2)

Line range hint 104-108: Ensure test tokens implement BaseCurrency trait.

With the updated trait bound to BaseCurrency, verify that the test tokens TOKEN18 and TOKEN0 implement the BaseCurrency trait. This ensures that all unit tests remain valid and pass without issues.


9-16: Verify that BaseCurrency trait provides required methods used in CurrencyAmount.

The change from Currency to BaseCurrency in the trait bounds affects how CurrencyAmount interacts with the currency field. Ensure that all methods called on currency, such as decimals(), equals(), and wrapped(), are available in the BaseCurrency trait. This is crucial for maintaining the functionality of methods like new, to_fixed, add, subtract, and wrapped.

You can run the following script to confirm that the BaseCurrency trait includes the necessary method definitions:

✅ Verification successful

Verification Successful: BaseCurrency trait includes decimals and equals methods.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check that `BaseCurrency` defines the required methods.

# Expected output: Definitions of `decimals`, `equals`, and `wrapped` methods within `BaseCurrency`.

rg --type rust --context 5 'trait BaseCurrency' src/entities

Length of output: 1490


Script:

#!/bin/bash
# Description: Verify that `BaseCurrency` defines `decimals` and `equals` methods.

# Search for the `decimals` method within the `BaseCurrency` trait
rg --type rust 'trait BaseCurrency' src/entities -A 10 | rg 'fn decimals\(&self\) ->'

# Search for the `equals` method within the `BaseCurrency` trait
rg --type rust 'trait BaseCurrency' src/entities -A 10 | rg 'fn equals\(&self, _\) ->'

Length of output: 176


Script:

#!/bin/bash
# Description: List all method definitions in the `BaseCurrency` trait and its supertraits.

# List methods in BaseCurrency trait
echo "Methods in BaseCurrency trait:"
rg --type rust 'trait BaseCurrency' src/entities -A 20 | rg 'fn ' 

# List methods in BaseCurrencyCore trait
echo -e "\nMethods in BaseCurrencyCore trait:"
rg --type rust 'trait BaseCurrencyCore' src/entities -A 20 | rg 'fn ' 

Length of output: 1290

src/entities/base_currency.rs (1)

Line range hint 43-75: Review generic parameters in macro implementation

In the impl_base_currency_core! macro, the implementation block specifies generic parameters const IS_NATIVE: bool, M. If $currency already includes these generic parameters, declaring them again may be redundant or lead to conflicts.

Please verify if the generic parameters const IS_NATIVE: bool, M are necessary in the impl block or if they can be inferred from $currency. Consider simplifying the macro as follows:

- impl<const IS_NATIVE: bool, M> BaseCurrencyCore for $currency {
+ impl BaseCurrencyCore for $currency {

src/entities/currency.rs Show resolved Hide resolved
src/entities/currency.rs Show resolved Hide resolved
src/entities/base_currency.rs Show resolved Hide resolved
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