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

BE-594/CreateFormattedLimitOrder | OrderbookUsecase CreateFormattedLimitOrder #531

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

deividaspetraitis
Copy link
Collaborator

@deividaspetraitis deividaspetraitis commented Oct 16, 2024

This PR refactors OrderbookUsecase to expose CreateFormattedLimitOrder as public method. That allows to reuse existing code for dealing with limit orders such as for example computing fill percentage of the orders. CreateFormattedLimitOrder is exactly for that purpose used in the claimbot here.

Summary by CodeRabbit

  • New Features

    • Introduced a new method for creating formatted limit orders, enhancing order processing capabilities.
    • Added functionality to set predefined behaviors for testing limit order creation.
  • Bug Fixes

    • Improved error handling and consistency in parameter naming for better clarity and maintainability.
  • Refactor

    • Updated method signatures and refactored existing methods for improved readability and consistency.

…mitOrder method

Refactor OrderbookUsecase to expose CreateFormattedLimitOrder as public
method. That allows to reuse existing code for dealing with limit orders
such as for example computing fill percentage of the orders.
@deividaspetraitis deividaspetraitis self-assigned this Oct 16, 2024
@@ -686,28 +686,6 @@ func (s *OrderbookUsecaseTestSuite) TestProcessOrderBookActiveOrders() {
expectedOrders: nil,
expectedIsBestEffort: false,
},
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Those test cases were moved to TestCreateFormattedLimitOrder.

Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The changes in this pull request involve the addition of a new method, CreateFormattedLimitOrder, to both the OrderbookUsecaseMock struct in the mocks package and the OrderBookUsecase interface in the mvc package. The OrderbookUseCaseImpl struct is also updated to include the new method, with modifications to parameter names and error handling for consistency. Additionally, new function signatures are introduced for testing purposes, enhancing the functionality related to limit order creation.

Changes

File Change Summary
domain/mocks/orderbook_usecase_mock.go - Added method: WithCreateFormattedLimitOrder(order orderbookdomain.LimitOrder, err error)
- Added method: CreateFormattedLimitOrder(orderbook domain.CanonicalOrderBooksResult, order orderbookdomain.Order) (orderbookdomain.LimitOrder, error)
- Added function signature: CreateFormattedLimitOrderFunc func(orderbook domain.CanonicalOrderBooksResult, order orderbookdomain.Order) (orderbookdomain.LimitOrder, error)
domain/mvc/orderbook.go - Added method: CreateFormattedLimitOrder(orderbook domain.CanonicalOrderBooksResult, order orderbookdomain.Order) (orderbookdomain.LimitOrder, error) in interface OrderBookUsecase
- Updated import statements to include domain package from github.com/osmosis-labs/sqs
orderbook/usecase/orderbook_usecase.go - Updated method signature: processOrderBookActiveOrders parameter name from orderBook to orderbook
- Renamed method: createFormattedLimitOrder to CreateFormattedLimitOrder (exported)
- Adjusted parameters for CreateFormattedLimitOrder to accept orderbook as a single argument
- Modified error handling in processOrderBookActiveOrders to use the new orderbook parameter
- Standardized variable names for clarity

Possibly related PRs

  • SQS-417 | Fix orderbook order Quantity parsing #519: The changes in this PR involve modifications to the Order struct's Status method in the orderbookdomain package, which is relevant to the overall order processing functionality that the main PR enhances with the new CreateFormattedLimitOrder method.

Suggested reviewers

  • p0mvn
  • PaddyMc

Poem

🐰 In the meadow where orders bloom,
A new function brings joy, dispelling gloom.
With formatted limits, we leap and bound,
In the world of code, new treasures found!
Hopping along, with changes so bright,
We celebrate progress, a coder's delight! 🌼


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.

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

🧹 Outside diff range and nitpick comments (2)
domain/mvc/orderbook.go (1)

26-27: LGTM: New method added correctly with a minor suggestion.

The CreateFormattedLimitOrder method has been successfully added to the OrderBookUsecase interface. The method signature aligns with the PR objectives and seems appropriate for creating a formatted limit order.

Consider enhancing the method comment to provide more context:

// CreateFormattedLimitOrder creates a formatted limit order from the given orderbook and order.
// This method is used for tasks such as computing the fill percentage of limit orders.

This additional information helps developers understand the method's use case more clearly.

domain/mocks/orderbook_usecase_mock.go (1)

50-54: LGTM: WithCreateFormattedLimitOrder method is well-implemented.

The WithCreateFormattedLimitOrder method is correctly implemented and follows the existing pattern for setting up mock functions. This will be useful for configuring test scenarios.

Consider adding a comment to explain the purpose of this method, similar to other methods in the mock. For example:

// WithCreateFormattedLimitOrder sets up the mock to return the specified order and error when CreateFormattedLimitOrder is called.
func (m *OrderbookUsecaseMock) WithCreateFormattedLimitOrder(order orderbookdomain.LimitOrder, err error) {
    // ... (existing implementation)
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d61e79d and ff24b74.

⛔ Files ignored due to path filters (2)
  • orderbook/usecase/export_test.go is excluded by !**/*_test.go
  • orderbook/usecase/orderbook_usecase_test.go is excluded by !**/*_test.go
📒 Files selected for processing (3)
  • domain/mocks/orderbook_usecase_mock.go (3 hunks)
  • domain/mvc/orderbook.go (2 hunks)
  • orderbook/usecase/orderbook_usecase.go (4 hunks)
🧰 Additional context used
🔇 Additional comments (11)
domain/mvc/orderbook.go (1)

6-6: LGTM: Import statement added correctly.

The new import for the domain package is necessary and correctly placed. It aligns with the existing import style and supports the new method's parameter type.

domain/mocks/orderbook_usecase_mock.go (4)

6-8: LGTM: Import addition is correct and necessary.

The new import for the domain package is correctly added and is required for the new CreateFormattedLimitOrder method. This change aligns with the existing import style and structure.


16-20: LGTM: OrderbookUsecaseMock struct updated correctly.

The addition of the CreateFormattedLimitOrderFunc field to the OrderbookUsecaseMock struct is correct and follows the existing pattern for mock functions. This new field will allow for flexible mocking of the CreateFormattedLimitOrder method in tests.


56-61: LGTM: CreateFormattedLimitOrder method is correctly implemented.

The CreateFormattedLimitOrder method is well-implemented and follows the existing pattern for mock methods in this struct. It correctly calls the CreateFormattedLimitOrderFunc if set and panics with "unimplemented" if not set, which is consistent with other methods in this mock.


Line range hint 1-61: Overall, the changes to the OrderbookUsecaseMock are well-implemented and align with the PR objectives.

The additions to this mock file are consistent with the existing code structure and patterns. The new CreateFormattedLimitOrder functionality has been correctly added, including the necessary struct field, setup method, and implementation method. These changes will facilitate effective testing of the new public method in the OrderbookUsecase interface.

To further improve the file:

  1. Consider adding comments to new methods for better documentation.
  2. Ensure that the corresponding interface in the mvc package has been updated to include the CreateFormattedLimitOrder method.

Let's verify that the OrderBookUsecase interface in the mvc package has been updated:

orderbook/usecase/orderbook_usecase.go (6)

265-265: Consistent Parameter Naming Improves Readability

Renaming the parameter from orderBook to orderbook aligns with Go naming conventions and improves code readability.


266-266: Good Addition of Orderbook Validation

Adding the orderbook.Validate() check ensures that the orderbook data is valid before processing, enhancing robustness.


270-273: Proper Usage of orderbook.ContractAddress

Updating the method to use orderbook.ContractAddress ensures that the correct contract address is used when fetching active orders and handling errors.


293-294: Correct Refactoring of Method Call

Passing orderbook directly to CreateFormattedLimitOrder simplifies the method call and leverages the updated method signature effectively.


316-317: Making CreateFormattedLimitOrder Public Enhances Reusability

Changing createFormattedLimitOrder to CreateFormattedLimitOrder allows external packages to use this method, promoting code reuse for limit order formatting.


495-495: Consistent Use of orderbook.ContractAddress

Assigning OrderbookAddress: orderbook.ContractAddress ensures consistency across the code and accurate tracking of the orderbook address in the limit order.

Comment on lines +318 to +319
quoteToken, err := o.tokensUsecease.GetMetadataByChainDenom(orderbook.Quote)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Typo in Variable Name tokensUsecease

The field tokensUsecease appears to be a misspelling of tokensUsecase. This typo could lead to confusion and potential errors.

Apply this diff to correct the typo:

- quoteToken, err := o.tokensUsecease.GetMetadataByChainDenom(orderbook.Quote)
+ quoteToken, err := o.tokensUsecase.GetMetadataByChainDenom(orderbook.Quote)

- baseToken, err := o.tokensUsecease.GetMetadataByChainDenom(orderbook.Base)
+ baseToken, err := o.tokensUsecase.GetMetadataByChainDenom(orderbook.Base)

Also applies to: 331-332

@deividaspetraitis
Copy link
Collaborator Author

Note for reviewer: no idea why build fails on the runner, it builds locally fine, this issue is already logged as task in our backlog.

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