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

[OTE-236] Evaluate subaccounts update end state with OIMF #1172

Merged
merged 8 commits into from
Mar 22, 2024

Conversation

teddyding
Copy link
Contributor

@teddyding teddyding commented Mar 13, 2024

Changelist

  • Evaluate subaccounts update end state with OIMF, by temporarily modify perpetual state and reverting the state afterwards
  • Set up existing tests with default perp OIs

Test Plan

[Describe how this PR was tested (if applicable)]

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 the PR has breaking postgres changes to the indexer add the indexer-postgres-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.

Copy link

coderabbitai bot commented Mar 13, 2024

Walkthrough

The recent updates focus on enhancing the handling and testing of perpetual contracts within a trading protocol, notably by adding new functionalities and improving existing ones. Key changes include the introduction of a method to modify open interest, updates to test utilities for setting up default perpetual order information, and adjustments in handling open interest deltas. Additionally, error handling and testing scenarios have been expanded, alongside code simplifications for better readability and maintenance.

Changes

File Path Change Summary
protocol/mocks/PerpetualsKeeper.go Mock updates with panic checks and new functions like ModifyOpenInterest.
protocol/.../constants/perpetuals.go, protocol/x/clob/keeper/..._test.go, protocol/x/clob/keeper/process_operations_test.go, protocol/testing/e2e/gov/wind_down_market_test.go, protocol/x/clob/e2e/withdrawal_gating_test.go Added/updated test setup for perpetuals, including new liquidity tiers, open interest setup, and updated constants for tests.
protocol/x/clob/keeper/orders.go, protocol/x/subaccounts/keeper/subaccount.go Functional changes in argument types and handling of open interest deltas.
protocol/x/perpetuals/genesis.go, protocol/x/perpetuals/keeper/perpetual.go Updated initialization of perpetuals and error messaging in ModifyOpenInterest.
protocol/x/subaccounts/keeper/oimf.go, protocol/x/subaccounts/keeper/oimf_test.go New functionality for computing and testing delta open interest.
protocol/x/subaccounts/types/..., protocol/x/perpetuals/types/types.go Type updates and new error definitions related to open interest modification.

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>.
    • Generate unit-tests 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@teddyding teddyding force-pushed the td/oimf-can-update branch 2 times, most recently from 721cd18 to 6b03c0a Compare March 19, 2024 19:33
@teddyding teddyding changed the title Evaluate subaccount update with OIMF on end state Evaluate subaccounts update end state with OIMF Mar 19, 2024
@teddyding teddyding marked this pull request as ready for review March 19, 2024 19:34
@teddyding teddyding changed the title Evaluate subaccounts update end state with OIMF [OTE-236] Evaluate subaccounts update end state with OIMF Mar 19, 2024
Copy link

linear bot commented Mar 19, 2024

@@ -609,6 +609,17 @@ func (k Keeper) internalCanUpdateSubaccounts(
}
}

var perpOpenInterestDelta *perptypes.OpenInterestDelta
// If update type is `Match`, calculate the open interest delta for the updated perpetual.
// Note: this assumes that `Match` can only happen for perpetuals.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIK this assumption will hold true for a very long time (we don't have plans to support spot), which is why I didn't include a TODO.

// Temporily apply open interest delta to perpetuals, so IMF is calculated based on open interest after the update.
// `perpOpenInterestDeltas` is only present for `Match` update type.
if perpOpenInterestDelta != nil {
if err := k.perpetualsKeeper.ModifyOpenInterest(
Copy link
Contributor Author

@teddyding teddyding Mar 19, 2024

Choose a reason for hiding this comment

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

This is the easiest way to do this right now. There's a more "correct" way, which is:

  • Modify ProductKeeper interface to have GetMarginRequirements() also take in an openInterestDelta (used here in the generic helper calculate)
  • Modify the input size types.Position to also return the openInterestDelta associated with this size. This is because margin requirements no longer just dependent total size of position, but also on the total open interest

I didn't do this because of the simplicity of the alternative approach used in this PR. Lmk if there's any preference.

Note: Updating perp.OpenInterest += delta and then perp.OpenInterest -= delta may modify app hash. We don't need to make any assumption here, since for DeliverTx this is called deterministically. For CheckTx, no need to keep each node CheckState the same either.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a550d20 and 30bd1de.
Files selected for processing (19)
  • protocol/mocks/PerpetualsKeeper.go (1 hunks)
  • protocol/testutil/constants/perpetuals.go (4 hunks)
  • protocol/testutil/perpetuals/perpetuals.go (2 hunks)
  • protocol/x/clob/keeper/deleveraging_test.go (8 hunks)
  • protocol/x/clob/keeper/liquidations_test.go (8 hunks)
  • protocol/x/clob/keeper/orders.go (1 hunks)
  • protocol/x/clob/keeper/orders_test.go (3 hunks)
  • protocol/x/perpetuals/keeper/perpetual.go (1 hunks)
  • protocol/x/perpetuals/types/types.go (2 hunks)
  • protocol/x/subaccounts/keeper/isolated_subaccount.go (2 hunks)
  • protocol/x/subaccounts/keeper/oimf.go (1 hunks)
  • protocol/x/subaccounts/keeper/oimf_test.go (1 hunks)
  • protocol/x/subaccounts/keeper/subaccount.go (9 hunks)
  • protocol/x/subaccounts/keeper/subaccount_helper.go (4 hunks)
  • protocol/x/subaccounts/keeper/subaccount_test.go (21 hunks)
  • protocol/x/subaccounts/keeper/update.go (1 hunks)
  • protocol/x/subaccounts/types/errors.go (2 hunks)
  • protocol/x/subaccounts/types/expected_keepers.go (1 hunks)
  • protocol/x/subaccounts/types/update.go (1 hunks)
Files skipped from review as they are similar to previous changes (18)
  • protocol/mocks/PerpetualsKeeper.go
  • protocol/testutil/constants/perpetuals.go
  • protocol/testutil/perpetuals/perpetuals.go
  • protocol/x/clob/keeper/deleveraging_test.go
  • protocol/x/clob/keeper/liquidations_test.go
  • protocol/x/clob/keeper/orders.go
  • protocol/x/clob/keeper/orders_test.go
  • protocol/x/perpetuals/keeper/perpetual.go
  • protocol/x/perpetuals/types/types.go
  • protocol/x/subaccounts/keeper/isolated_subaccount.go
  • protocol/x/subaccounts/keeper/oimf.go
  • protocol/x/subaccounts/keeper/oimf_test.go
  • protocol/x/subaccounts/keeper/subaccount.go
  • protocol/x/subaccounts/keeper/subaccount_helper.go
  • protocol/x/subaccounts/keeper/update.go
  • protocol/x/subaccounts/types/errors.go
  • protocol/x/subaccounts/types/expected_keepers.go
  • protocol/x/subaccounts/types/update.go

Comment on lines 672 to 689
// Revert the temporary open interest delta to perpetuals.
if perpOpenInterestDelta != nil {
if err := k.perpetualsKeeper.ModifyOpenInterest(
ctx,
perpOpenInterestDelta.PerpetualId,
new(big.Int).Neg(
perpOpenInterestDelta.BaseQuantumsDelta,
),
); err != nil {
return false, nil, errorsmod.Wrapf(
types.ErrCannotRevertPerpOpenInterestForOIMF,
"perpId = %v, delta = %v, settledUpdates = %+v",
perpOpenInterestDelta.PerpetualId,
perpOpenInterestDelta.BaseQuantumsDelta,
settledUpdates,
)
}
}
Copy link
Contributor

@jayy04 jayy04 Mar 20, 2024

Choose a reason for hiding this comment

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

branch the context instead? seems a little bit cleaner

up to you

Comment on lines 3250 to 3253
Id: &types.SubaccountId{
Owner: "Bob",
Number: 0,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

mega nit: just use constants.Bob_Num0

)
}

if settledUpdates[0].PerpetualUpdates[0].PerpetualId != settledUpdates[1].PerpetualUpdates[0].PerpetualId {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: The 2 perpetual updates should also have the same absolute value as their size right? If a subaccount is chaing by +1 BTC from a match, the other subaccount should be changing -1 BTC.

@vincentwschau
Copy link
Contributor

non-blocking nit, assume it may already to scoped to a different ticket. It would be good to update / add some E2E tests for this logic as well.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 30bd1de and 3164b81.
Files selected for processing (2)
  • protocol/x/subaccounts/keeper/subaccount.go (9 hunks)
  • protocol/x/subaccounts/keeper/subaccount_test.go (21 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/x/subaccounts/keeper/subaccount.go
  • protocol/x/subaccounts/keeper/subaccount_test.go

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3164b81 and ccfca2d.
Files selected for processing (3)
  • protocol/x/subaccounts/keeper/oimf.go (1 hunks)
  • protocol/x/subaccounts/keeper/subaccount_test.go (21 hunks)
  • protocol/x/subaccounts/types/errors.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/x/subaccounts/keeper/oimf.go
  • protocol/x/subaccounts/types/errors.go

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ccfca2d and d332cb5.
Files selected for processing (2)
  • protocol/x/subaccounts/keeper/oimf.go (1 hunks)
  • protocol/x/subaccounts/keeper/oimf_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/x/subaccounts/keeper/oimf.go
  • protocol/x/subaccounts/keeper/oimf_test.go

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3164b81 and 2c9f80a.
Files selected for processing (4)
  • protocol/x/subaccounts/keeper/oimf.go (1 hunks)
  • protocol/x/subaccounts/keeper/oimf_test.go (1 hunks)
  • protocol/x/subaccounts/keeper/subaccount_test.go (21 hunks)
  • protocol/x/subaccounts/types/errors.go (2 hunks)
Files skipped from review as they are similar to previous changes (4)
  • protocol/x/subaccounts/keeper/oimf.go
  • protocol/x/subaccounts/keeper/oimf_test.go
  • protocol/x/subaccounts/keeper/subaccount_test.go
  • protocol/x/subaccounts/types/errors.go

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2c9f80a and 6fe8cbb.
Files selected for processing (1)
  • protocol/x/subaccounts/keeper/subaccount_test.go (21 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/x/subaccounts/keeper/subaccount_test.go

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6fe8cbb and b04ffbb.
Files selected for processing (4)
  • protocol/x/clob/keeper/process_operations_liquidations_test.go (37 hunks)
  • protocol/x/clob/keeper/process_operations_long_term_test.go (11 hunks)
  • protocol/x/clob/keeper/process_operations_stateful_validation_test.go (16 hunks)
  • protocol/x/clob/keeper/process_operations_test.go (41 hunks)
Additional comments: 56
protocol/x/clob/keeper/process_operations_stateful_validation_test.go (2)
  • 29-29: The changes from lines 29 to 327 in TestProcessProposerMatches_LongTerm_StatefulValidation_Failure involve converting slices of pointers to structs to slices of structs for the perpetuals field. This is a positive change for performance and code clarity. Ensure that this change aligns with how perpetuals are used within the test logic.
  • 396-396: The changes from lines 396 to 623 in TestProcessProposerMatches_Conditional_Validation_Failure also involve converting slices of pointers to structs to slices of structs for the perpetuals field. As with the previous function, this is a beneficial change. Ensure that this change aligns with how perpetuals are used within the test logic.
protocol/x/clob/keeper/process_operations_long_term_test.go (5)
  • 27-27: The changes from lines 27 to 826 involve updating the type of perpetuals and subaccounts slices from pointers to values. This is a significant change that affects how these slices are used throughout the test cases. Ensure that all operations on these slices are correctly adjusted to work with value semantics instead of pointer semantics. This includes checking for any potential unintended copies or modifications that could affect test behavior.
  • 97-104: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [27-826]

The test cases introduced and modified in this file cover a wide range of scenarios related to the handling of long-term orders, including new maker and taker orders, liquidation matches, and considering state fill amounts. It's crucial to ensure that these test cases comprehensively cover the changes introduced in the PR, especially the enhancements to subaccount updates and the integration of the Open Interest Modification Framework (OIMF). Additionally, consider adding or updating end-to-end (E2E) tests as suggested by vincentwschau to further validate the changes.

Would you like assistance in adding or updating the E2E tests to cover the new logic introduced in this PR?

  • 97-104: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [27-826]

Ensure that error handling is properly implemented for all setup operations and external calls within the test cases. This includes mocking external dependencies and setting up initial states. Proper error handling is essential for maintaining test reliability and ensuring that failures are accurately reported.

  • 97-104: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [27-826]

Consider refactoring the test setup code to reduce duplication and improve maintainability. Common setup operations, such as mocking the bank keeper and setting the previous block info, are repeated across multiple test cases. Extracting these operations into helper functions could make the test code more concise and easier to maintain.

  • 97-104: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [27-826]

The test function TestProcessProposerMatches_LongTerm_Success demonstrates good use of a map to define and run multiple test cases, enhancing modularity. This approach allows for easy addition of new test cases and improves the readability of the test suite. Keep this structure in mind for future test implementations to maintain consistency and modularity.

protocol/x/clob/keeper/process_operations_liquidations_test.go (9)
  • 34-36: The conversion from slices of pointers to slices of structs for perpetuals simplifies the code and potentially improves performance by avoiding indirect references. This change enhances code readability and maintainability.
  • 166-172: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [169-183]

The conversion from slices of pointers to slices of structs for perpetuals and subaccounts in this test case also simplifies the code. It's a good practice to use struct instances directly when the overhead of copying is not significant, which seems to be the case here.

  • 261-262: Similar to previous comments, converting to slices of structs for perpetuals here is a positive change. It simplifies the handling of these objects within the test cases.
  • 347-348: Again, the conversion to slices of structs for perpetuals is consistent with the changes made throughout the file. This consistency in handling perpetuals and subaccounts as struct slices is beneficial for code clarity.
  • 445-446: The consistent application of converting to slices of structs for perpetuals across different test cases is noted and appreciated. This change contributes to a more uniform and readable codebase.
  • 550-551: The conversion to slices of structs for perpetuals here, as in other test cases, is a good practice. It simplifies the code structure and makes it more straightforward to work with these objects.
  • 654-655: The conversion from slices of pointers to slices of structs for perpetuals in this test case is consistent with the rest of the file. This change is beneficial for the reasons previously mentioned.
  • 767-768: Once again, converting to slices of structs for perpetuals is a positive change that simplifies the code. This consistency across test cases is good for maintainability.
  • 866-867: The conversion to slices of structs for perpetuals in this test case is in line with the changes throughout the file. This simplification is beneficial for code readability.
protocol/x/clob/keeper/process_operations_test.go (40)
  • 23-23: The import perptest "github.com/dydxprotocol/v4-chain/protocol/testutil/perpetuals" is added, which is necessary for the test setup, particularly for setting up default perpetual open interests.
  • 45-45: The change from []*perptypes.Perpetual to []perptypes.Perpetual in the perpetuals slice type within the processProposerOperationsTestCase struct simplifies the handling of perpetuals by avoiding the need for pointer dereferencing. This change aligns with Go best practices for slices of structs where the structs are not large or where the slice does not undergo frequent modifications that would benefit from pointer semantics.
  • 79-79: The test case "Succeeds no operations" correctly initializes an empty slice of perptypes.Perpetual to test the scenario where no operations are processed. This is a valid test case to ensure the function behaves correctly when no input is provided.
  • 91-92: The test case "Succeeds no operations with previous stateful orders" demonstrates the function's behavior when stateful orders exist but no new operations are processed. The inclusion of a perpetual in the test setup is necessary for the context of the test, ensuring that the system's state is accurately represented.
  • 110-111: The test case "Succeeds with singular match of a short term maker and short term taker" is well-constructed to test the matching logic between two short-term orders. This case is essential for verifying the core functionality of order matching within the system.
  • 234-235: The test case "Succeeds with maker rebate" introduces a scenario where a maker rebate is applied, testing the system's ability to handle fee adjustments based on order roles. This is an important aspect of the trading system that needs thorough testing.
  • 358-359: The test case "Succeeds with singular match of a preexisting maker and short term taker" tests the interaction between a preexisting long-term order and a newly placed short-term order. This scenario is crucial for ensuring that the system can correctly handle matches involving different types of orders.
  • 469-470: The test case "Succeeds with singular match of a preexisting maker and newly placed long term taker" is designed to test the matching between two long-term orders, one of which is preexisting. This scenario ensures that the system's logic for handling long-term orders is functioning as expected.
  • 561-562: The test case "preexisting stateful maker order partially matches with 2 short term taker orders" is a complex scenario that tests the system's ability to handle partial matches involving multiple orders. This test is essential for verifying the robustness of the matching engine.
  • 735-736: The test case "Succeeds with liquidation order" introduces a liquidation scenario, testing the system's ability to handle liquidations correctly. This is a critical aspect of the trading system that ensures the financial integrity of the market.
  • 801-802: The test case "Succeeds with deleveraging with no liquidation order" tests the deleveraging process in the absence of a liquidation match. This scenario is important for ensuring that deleveraging can occur under specific market conditions.
  • 851-852: The test case "Succeeds with deleveraging and partially filled liquidation" tests a complex scenario involving both deleveraging and liquidation processes. This test is crucial for ensuring that the system can handle multiple types of operations simultaneously.
  • 928-929: The test case "Zero-fill deleveraging succeeds when the account is negative TNC and updates the last negative TNC subaccount seen block number in state" tests the system's ability to handle zero-fill deleveraging for accounts with negative total net collateral (TNC). This scenario is important for ensuring the system's resilience in adverse market conditions.
  • 965-966: The test case "Zero-fill deleveraging succeeds when the account is negative TNC and has a position in final settlement market. It updates the last negative TNC subaccount seen block number in state" extends the previous test case to include accounts in final settlement markets. This adds an additional layer of complexity to the test, ensuring the system's comprehensive handling of deleveraging scenarios.
  • 1005-1006: The test case "Zero-fill deleveraging succeeds when there's multiple zero-fill deleveraging events for the same subaccount and perpetual ID" tests the system's ability to handle multiple deleveraging events for the same account. This scenario is important for ensuring that the system can correctly process multiple deleveraging operations in a single block.
  • 1048-1049: The test case "Zero-fill deleverage succeeds after the same subaccount is partially deleveraged" tests the system's ability to handle a sequence of deleveraging events, where an account is partially deleveraged before a zero-fill deleveraging occurs. This scenario is crucial for testing the system's handling of complex deleveraging sequences.
  • 1110-1111: The test case "Succeeds order removal operations with previous stateful orders" tests the system's ability to remove orders from the state. This scenario is important for ensuring that the system can correctly update its state in response to order removal operations.
  • 1143-1144: The test case "Fails when attempting to match order with invalid order side" introduces a scenario where an order with an unspecified side is processed. This test is crucial for ensuring that the system correctly handles invalid input and returns the appropriate error.
  • 1218-1219: The test case "Fails with deleveraging match for non-liquidatable subaccount" tests the system's response to a deleveraging operation for a subaccount that is not eligible for liquidation. This scenario is important for ensuring that the system correctly identifies and rejects invalid deleveraging operations.
  • 1256-1257: The test case "Fails with deleveraging match for subaccount with zero TNC" tests the system's response to a deleveraging operation for a subaccount with zero total net collateral. This scenario is important for ensuring that the system correctly identifies and rejects deleveraging operations for subaccounts that do not meet the criteria for deleveraging.
  • 1295-1296: The test case "Conditional: succeeds with singular match of a triggered conditional order" tests the system's ability to process matches involving triggered conditional orders. This scenario is important for ensuring that the system can correctly handle conditional orders once they are triggered.
  • 1389-1390: The test case "Conditional: panics with a non-existent conditional order" introduces a scenario where a match operation is attempted with a conditional order that does not exist in the system. This test is crucial for ensuring that the system correctly identifies and handles attempts to match non-existent orders, although the use of panic for control flow in production code is generally discouraged and should be handled through error returns.

Consider replacing panic with error handling to improve the robustness and maintainability of the code.

  • 1443-1444: The test case "Conditional: panics with an untriggered conditional order" tests the system's response to an attempt to match an untriggered conditional order. This scenario is important for ensuring that the system correctly identifies and rejects matches involving untriggered conditional orders, but again, the use of panic for control flow should be reconsidered.

Consider replacing panic with error handling to improve the robustness and maintainability of the code.

  • 1498-1499: The test case "Fails with clob pair not found" tests the system's response to an operation involving a clob pair that does not exist in the system. This scenario is important for ensuring that the system correctly identifies and rejects operations involving non-existent clob pairs.
  • 1516-1517: The test case "Panics with unsupported clob pair status" introduces a scenario where an operation is attempted with a clob pair in an unsupported status. This test is crucial for ensuring that the system correctly identifies and handles unsupported clob pair statuses, but the use of panic for control flow should be reconsidered.

Consider replacing panic with error handling to improve the robustness and maintainability of the code.

  • 1541-1542: The test case "Returns error if zero-fill deleveraging operation proposed for non-negative TNC subaccount in final settlement" tests the system's response to a zero-fill deleveraging operation for a non-negative TNC subaccount in a final settlement market. This scenario is important for ensuring that the system correctly identifies and rejects invalid zero-fill deleveraging operations.
  • 1577-1578: The test case "Fails with clob match for market in initializing mode" tests the system's response to a match operation for a market in initializing mode. This scenario is important for ensuring that the system correctly identifies and rejects operations for markets in unsupported statuses.
  • 1598-1599: The test case "Fails with short term order placement for market in initializing mode" tests the system's response to a short-term order placement for a market in initializing mode. This scenario is important for ensuring that the system correctly identifies and rejects short-term order placements for markets in unsupported statuses.
  • 1613-1614: The test case "Fails with order removal for market in initializing mode" tests the system's response to an order removal operation for a market in initializing mode. This scenario is important for ensuring that the system correctly identifies and rejects order removal operations for markets in unsupported statuses.
  • 1632-1633: The test case "Fails with order removal reason fully filled" tests the system's response to an order removal operation with the reason "fully filled". This scenario is important for ensuring that the system correctly identifies and rejects invalid reasons for order removal.
  • 1651-1652: The test case "Fails with order removal for market in final settlement" tests the system's response to an order removal operation for a market in final settlement. This scenario is important for ensuring that the system correctly identifies and rejects order removal operations for markets in unsupported statuses.
  • 1667-1668: The test case "Fails with short-term order placement for market in final settlement" tests the system's response to a short-term order placement for a market in final settlement. This scenario is important for ensuring that the system correctly identifies and rejects short-term order placements for markets in unsupported statuses.
  • 1682-1683: The test case "Fails with ClobMatch_MatchOrders for market in final settlement" tests the system's response to a match operation for a market in final settlement. This scenario is important for ensuring that the system correctly identifies and rejects match operations for markets in unsupported statuses.
  • 1705-1706: The test case "Fails with ClobMatch_MatchPerpetualLiquidation for market in final settlement" tests the system's response to a perpetual liquidation match operation for a market in final settlement. This scenario is important for ensuring that the system correctly identifies and rejects liquidation operations for markets in unsupported statuses.
  • 1734-1735: The test case "Succeeds with ClobMatch_MatchPerpetualDeleveraging, IsFinalSettlement is false for market in final settlement" tests the system's ability to process a deleveraging operation for a market in final settlement with the IsFinalSettlement flag set to false. This scenario is important for ensuring that the system can correctly handle deleveraging operations in final settlement markets.
  • 1779-1780: The test case "Succeeds with ClobMatch_MatchPerpetualDeleveraging, IsFinalSettlement is true for market in final settlement" tests the system's ability to process a deleveraging operation for a market in final settlement with the IsFinalSettlement flag set to true. This scenario is important for ensuring that the system can correctly handle final settlement operations.
  • 1822-1823: The test case Fails with ClobMatch_MatchPerpetualDeleveraging for negative TNC subaccount, IsFinalSettlement is true for market not in final settlement tests the system's response to a deleveraging operation with the IsFinalSettlement flag set to true for a market not in final settlement. This scenario is important for ensuring that the system correctly identifies and rejects deleveraging operations with mismatched final settlement flags.
  • 1859-1860: The test case Fails with ClobMatch_MatchPerpetualDeleveraging for negative TNC subaccount, IsFinalSettlement is true for market in final settlement tests the system's response to a deleveraging operation with the IsFinalSettlement flag set to true for a market in final settlement. This scenario is important for ensuring that the system correctly identifies and rejects deleveraging operations with mismatched final settlement flags.
  • 1898-1899: The test case Fails with ClobMatch_MatchPerpetualDeleveraging for non-negative TNC subaccount, IsFinalSettlement is true for market not in final settlement tests the system's response to a deleveraging operation with the IsFinalSettlement flag set to true for a market not in final settlement. This scenario is important for ensuring that the system correctly identifies and rejects deleveraging operations with mismatched final settlement flags.
  • 1931-1932: The test case Fails with ClobMatch_MatchPerpetualDeleveraging for non-negative TNC subaccount, IsFinalSettlement is false for market in final settlement tests the system's response to a deleveraging operation with the IsFinalSettlement flag set to false for a market in final settlement. This scenario is important for ensuring that the system correctly identifies and rejects deleveraging operations with mismatched final settlement flags.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b04ffbb and 1e2a394.
Files selected for processing (3)
  • protocol/testutil/constants/perpetuals.go (4 hunks)
  • protocol/x/clob/e2e/liquidation_deleveraging_test.go (18 hunks)
  • protocol/x/perpetuals/genesis.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/testutil/constants/perpetuals.go
Additional comments: 2
protocol/x/perpetuals/genesis.go (1)
  • 38-44: The changes from lines 38 to 44 replace CreatePerpetual with SetPerpetual to allow initializing perpetuals with non-zero values at genesis. This is a significant improvement for flexibility. However, ensure that SetPerpetual includes comprehensive initialization logic and error handling that CreatePerpetual might have provided. This includes validating input data and setting any default values if necessary.
protocol/x/clob/e2e/liquidation_deleveraging_test.go (1)
  • 68-68: The changes from lines 68 to 68, 118 to 118, 166 to 166, 228 to 228, 290 to 290, 356 to 356, 428 to 428, 501 to 501, 673 to 673, 715 to 715, 774 to 774, 815 to 815, 872 to 872, 904 to 904, 960 to 960, 1025 to 1025, 1059 to 1059, and 1088 to 1088 update the perpetual configuration constants used in various test cases. This change aligns with the PR objectives to enhance subaccount handling and integrate the Open Interest Modification Framework (OIMF) for evaluating subaccount updates. It's crucial to ensure that these new constants (BtcUsd_20PercentInitial_10PercentMaintenance_OpenInterest1) are correctly defined elsewhere in the codebase and accurately represent the intended testing scenarios. Additionally, verify that all relevant test cases have been updated to use the new constants for consistency.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 52a5783 and ecd802a.
Files selected for processing (22)
  • protocol/mocks/PerpetualsKeeper.go (1 hunks)
  • protocol/testutil/constants/perpetuals.go (4 hunks)
  • protocol/testutil/perpetuals/perpetuals.go (2 hunks)
  • protocol/x/clob/e2e/liquidation_deleveraging_test.go (18 hunks)
  • protocol/x/clob/keeper/deleveraging_test.go (8 hunks)
  • protocol/x/clob/keeper/liquidations_test.go (8 hunks)
  • protocol/x/clob/keeper/orders.go (1 hunks)
  • protocol/x/clob/keeper/orders_test.go (3 hunks)
  • protocol/x/clob/keeper/process_operations_liquidations_test.go (37 hunks)
  • protocol/x/clob/keeper/process_operations_long_term_test.go (11 hunks)
  • protocol/x/clob/keeper/process_operations_stateful_validation_test.go (16 hunks)
  • protocol/x/clob/keeper/process_operations_test.go (41 hunks)
  • protocol/x/perpetuals/genesis.go (1 hunks)
  • protocol/x/perpetuals/keeper/perpetual.go (1 hunks)
  • protocol/x/perpetuals/types/types.go (2 hunks)
  • protocol/x/subaccounts/keeper/oimf.go (1 hunks)
  • protocol/x/subaccounts/keeper/oimf_test.go (1 hunks)
  • protocol/x/subaccounts/keeper/subaccount.go (3 hunks)
  • protocol/x/subaccounts/keeper/subaccount_test.go (21 hunks)
  • protocol/x/subaccounts/types/errors.go (2 hunks)
  • protocol/x/subaccounts/types/expected_keepers.go (1 hunks)
  • protocol/x/subaccounts/types/update.go (1 hunks)
Files skipped from review as they are similar to previous changes (22)
  • protocol/mocks/PerpetualsKeeper.go
  • protocol/testutil/constants/perpetuals.go
  • protocol/testutil/perpetuals/perpetuals.go
  • protocol/x/clob/e2e/liquidation_deleveraging_test.go
  • protocol/x/clob/keeper/deleveraging_test.go
  • protocol/x/clob/keeper/liquidations_test.go
  • protocol/x/clob/keeper/orders.go
  • protocol/x/clob/keeper/orders_test.go
  • protocol/x/clob/keeper/process_operations_liquidations_test.go
  • protocol/x/clob/keeper/process_operations_long_term_test.go
  • protocol/x/clob/keeper/process_operations_stateful_validation_test.go
  • protocol/x/clob/keeper/process_operations_test.go
  • protocol/x/perpetuals/genesis.go
  • protocol/x/perpetuals/keeper/perpetual.go
  • protocol/x/perpetuals/types/types.go
  • protocol/x/subaccounts/keeper/oimf.go
  • protocol/x/subaccounts/keeper/oimf_test.go
  • protocol/x/subaccounts/keeper/subaccount.go
  • protocol/x/subaccounts/keeper/subaccount_test.go
  • protocol/x/subaccounts/types/errors.go
  • protocol/x/subaccounts/types/expected_keepers.go
  • protocol/x/subaccounts/types/update.go

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ecd802a and b4ad946.
Files selected for processing (2)
  • protocol/testing/e2e/gov/wind_down_market_test.go (1 hunks)
  • protocol/x/clob/e2e/withdrawal_gating_test.go (2 hunks)
Additional comments: 3
protocol/testing/e2e/gov/wind_down_market_test.go (1)
  • 149-149: The change from BtcUsd_20PercentInitial_10PercentMaintenance to BtcUsd_20PercentInitial_10PercentMaintenance_OpenInterest1 aligns with the PR's focus on evaluating subaccount updates using OIMF. Ensure that the new identifier is correctly defined and set up in the test constants or configurations.
protocol/x/clob/e2e/withdrawal_gating_test.go (2)
  • 76-76: The update to the perpetuals constant to include open interest considerations is consistent with the PR's objectives. Ensure that BtcUsd_20PercentInitial_10PercentMaintenance_OpenInterest1 is correctly defined and set up in the test constants or configurations.
  • 115-115: The update to the perpetuals constant to include open interest considerations is consistent with the PR's objectives. Ensure that BtcUsd_20PercentInitial_10PercentMaintenance_OpenInterest1 is correctly defined and set up in the test constants or configurations.

@teddyding teddyding merged commit 780410f into main Mar 22, 2024
17 checks passed
@teddyding teddyding deleted the td/oimf-can-update branch March 22, 2024 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants