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

[IND-489] Update order side when replacing. Fix liquidations side bug. #807

Merged
merged 2 commits into from
Nov 27, 2023

Conversation

vincentwschau
Copy link
Contributor

Changelist

  • Update SQL handlers to update the order side when replacing an order
  • Update SQL handlers for liquidations, fixing bug where liquidation fills always have side SELL

Test Plan

Unit tests.

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

@vincentwschau vincentwschau added the bug Something isn't working label Nov 27, 2023
Copy link

linear bot commented Nov 27, 2023

IND-489 BUG: Replaced order does not have all fields updated correctly

When an order is replaced (same order id), the side is not set to the side of the replacing order, and instead the original side of the old order is kept.

Additionally, it may be possible to update the createdAtHeight of the order if the status of the old order is a terminal state (FILLED / CANCELED).

Copy link
Contributor

coderabbitai bot commented Nov 27, 2023

Walkthrough

The changes across the various files seem to focus on enhancing the testing and functionality of order handling, particularly for liquidation and order fill events. New test cases have been added to ensure the correct behavior when replacing orders, with attention to timing and order side details. The SQL scripts have been updated to accurately record the 'side' of orders in the database, ensuring that the order handling logic remains consistent with the new test scenarios.

Changes

File Path Change Summary
.../handlers/order-fills/liquidation-handler.test.ts
.../handlers/order-fills/order-handler.test.ts
Added new test cases for simulating the replacement of maker orders with new ones, covering various scenarios and updating Kafka messages and timing statistics.
.../scripts/dydx_liquidation_fill_handler_per_order.sql
.../scripts/dydx_order_fill_handler_per_order.sql
Updated SQL scripts to assign and update the order_side variable, ensuring accurate recording of order side information in the database.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 37e5119 and 8683a32.
Files selected for processing (4)
  • indexer/services/ender/tests/handlers/order-fills/liquidation-handler.test.ts (1 hunks)
  • indexer/services/ender/tests/handlers/order-fills/order-handler.test.ts (2 hunks)
  • indexer/services/ender/src/scripts/dydx_liquidation_fill_handler_per_order.sql (3 hunks)
  • indexer/services/ender/src/scripts/dydx_order_fill_handler_per_order.sql (2 hunks)
Additional comments: 6
indexer/services/ender/__tests__/handlers/order-fills/order-handler.test.ts (2)
  • 758-758: The comment on line 758 seems to incorrectly state the expected quote amount as '2' when the code calculates it as '1'. Please verify and correct the comment to match the expected value from the code or update the code if the comment is correct.

  • 856-1161: The changes from lines 856 to 1161 introduce a complex test case for replacing existing orders. Ensure that the test case is well-structured, covers all relevant scenarios, and has clear and accurate assertions. Given the complexity, it is recommended to review this test case thoroughly to ensure it meets the intended requirements and correctly validates the functionality.

indexer/services/ender/src/scripts/dydx_liquidation_fill_handler_per_order.sql (3)
  • 80-94: The logic for determining order_side based on the side field for 'makerOrder' and a conditional for other cases appears to be correctly implemented.

  • 99-105: The order_record is correctly updated with the side information before the UPSERT operation, ensuring that the orders table will have the accurate side data.

  • 117-123: The UPSERT operation correctly updates the orders table with the new side information from the order_record, which is essential for maintaining accurate order side information in the database.

indexer/services/ender/src/scripts/dydx_order_fill_handler_per_order.sql (1)
  • 86-90: The update to the 'side' field in the 'orders' table is correctly implemented to reflect the new value of 'order_side'. This change is critical for maintaining the consistency of order information after a fill event.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8683a32 and 1462120.
Files selected for processing (1)
  • indexer/services/ender/src/scripts/dydx_liquidation_fill_handler_per_order.sql (3 hunks)
Additional comments: 3
indexer/services/ender/src/scripts/dydx_liquidation_fill_handler_per_order.sql (3)
  • 80-95: The logic for determining the order_side based on the 'side' or 'isBuy' property is correctly implemented and aligns with the summary provided.

  • 100-106: The order_record is correctly updated with the new order_side and other order details before performing an UPSERT operation.

  • 118-124: The orders table is correctly updated with the new order_record values, ensuring that the order side and other details are consistent with the latest state.

@vincentwschau
Copy link
Contributor Author

Opened https://linear.app/dydx/issue/IND-493/backfill-incorrect-liquidated-fills-with-wrong-side for the backfill task to fix any incorrectly created liquidated fills due to the bug fixed in this PR.

@vincentwschau vincentwschau merged commit 1c32c5f into main Nov 27, 2023
11 checks passed
@vincentwschau vincentwschau deleted the vincentc/ind-489-replaced-order-update-side branch November 27, 2023 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working indexer
Development

Successfully merging this pull request may close these issues.

2 participants