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

[TRA-507] Add new gov message for upgrading markets: UpgradeIsolatedPerpetualToCross #2551

Merged
merged 30 commits into from
Nov 22, 2024

Conversation

hwray
Copy link
Contributor

@hwray hwray commented Oct 31, 2024

Changelist

  • Add new gov message for upgrading isolated perpetuals to cross and moving their insurance fund + collateral pool to cross
  • Add tests for the new message functionality
  • Move a few functions/tests (GetInsuranceFundBalance, GetCrossInsuranceFundBalance) around to avoid cyclic dependencies

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

Summary by CodeRabbit

  • New Features
    • Introduced the ability to upgrade isolated perpetual markets to cross perpetual markets.
    • Added new message types and methods to facilitate the upgrade process.
    • Implemented new methods for transferring insurance funds and collateral between isolated and cross markets.
  • Bug Fixes
    • Enhanced error handling and logging for various functions related to insurance fund management.
  • Tests
    • Added comprehensive tests for the new upgrade functionality, covering various scenarios and edge cases.
    • Extended test coverage for insurance fund balance retrieval and transfer operations.
  • Documentation
    • Updated comments and documentation to reflect the new features and changes in functionality.

Copy link

linear bot commented Oct 31, 2024

Copy link
Contributor

coderabbitai bot commented Oct 31, 2024

Walkthrough

The changes introduce new functionality to the Msg service, specifically allowing for the upgrade of isolated perpetual markets to cross-margin markets. This includes the addition of new message types, methods for handling the upgrade process, and updates to existing structures to incorporate a SubaccountsKeeper. The modifications span several files, enhancing both the core functionality and the testing framework, while also adjusting interfaces to support the new features.

Changes

File Change Summary
indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.rpc.msg.ts Added method upgradeIsolatedPerpetualToCross to Msg interface and MsgClientImpl, modified imports.
indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.ts Introduced interfaces MsgUpgradeIsolatedPerpetualToCross, MsgUpgradeIsolatedPerpetualToCrossResponse, and their SDK types; added encoding/decoding functions.
proto/dydxprotocol/listing/tx.proto Added RPC method UpgradeIsolatedPerpetualToCross and associated message types.
protocol/app/app.go Added SubaccountsKeeper field to App struct and updated ListingKeeper initialization.
protocol/app/msgs/all_msgs.go Added new message types for upgrade functionality.
protocol/mocks/ClobKeeper.go Removed GetInsuranceFundBalance method from ClobKeeper mock.
protocol/testutil/keeper/listing.go Updated ListingKeepers function to include subaccountsKeeper.
protocol/x/clob/keeper/deleveraging.go Removed GetInsuranceFundBalance and GetCrossInsuranceFundBalance functions; updated IsValidInsuranceFundDelta function.
protocol/x/clob/keeper/deleveraging_test.go Removed TestGetInsuranceFundBalance function; updated imports.
protocol/x/clob/keeper/keeper.go Added method GetCrossInsuranceFundBalance to Keeper.
protocol/x/clob/types/expected_keepers.go Added methods to SubaccountsKeeper interface for insurance fund balance retrieval.
protocol/x/clob/types/liquidations_keeper.go Removed GetInsuranceFundBalance method from LiquidationsKeeper interface.
protocol/x/listing/keeper/keeper.go Added SubaccountsKeeper field to Keeper struct and updated constructor.
protocol/x/listing/keeper/listing.go Added method UpgradeIsolatedPerpetualToCross to upgrade market types.
protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go Introduced UpgradeIsolatedPerpetualToCross function in msgServer.
protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go Added tests for UpgradeIsolatedPerpetualToCross method.
protocol/x/listing/types/errors.go Added new error variables for authority and perpetual ID validation.
protocol/x/listing/types/expected_keepers.go Added methods to PerpetualsKeeper for retrieving and setting perpetual market types.
protocol/x/perpetuals/keeper/perpetual.go Updated validation logic in SetPerpetualMarketType.
protocol/x/perpetuals/keeper/perpetual_test.go Enhanced test coverage and assertions in the keeper tests.
protocol/x/subaccounts/keeper/subaccount.go Added methods for retrieving insurance fund balances.
protocol/x/subaccounts/keeper/subaccount_test.go Added tests for insurance fund balance retrieval.
protocol/x/subaccounts/keeper/transfer.go Introduced methods for transferring funds between isolated and cross-margin pools.
protocol/x/subaccounts/types/expected_keepers.go Added methods for asset retrieval and balance querying.
protocol/app/msgs/internal_msgs.go Added new message types for upgrade functionality.
protocol/app/msgs/internal_msgs_test.go Updated tests to include new message types.
protocol/lib/ante/internal_msg.go Expanded IsInternalMsg function to recognize new message types.
protocol/x/listing/keeper/listing_test.go Updated ListingKeepers function calls to include additional parameters.

Possibly related PRs

Suggested labels

revshare

Suggested reviewers

  • vincentwschau

🐰 In the meadow where changes bloom,
New upgrades rise, dispelling gloom.
Isolated to cross, we leap with cheer,
With subaccounts near, there's nothing to fear!
Hops of progress, we celebrate today,
In the world of finance, we find our way! 🌼


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.

@shrenujb
Copy link
Contributor

You might run into a circular dependency since collateral pools reside in x/subaccounts which is dependent on x/perpetuals.
If this function resides in x/perpetuals, you'd have to depend on the collateral pool APIs in x/subaccounts

I think you have 2 options:

  • Move collateral pool stuff into x/perpetuals
  • Create the msg to be part of x/subaccounts instead

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

🧹 Outside diff range and nitpick comments (3)
protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go (1)

13-16: Consider handling AccAddressFromBech32 error in GetSigners.

The error from AccAddressFromBech32 is discarded, which could mask invalid addresses if ValidateBasic hasn't been called. While this is a common pattern in Cosmos SDK, it's worth documenting why the error is intentionally ignored.

Consider adding a comment explaining the error handling strategy:

 func (msg *MsgUpgradeIsolatedPerpetualToCross) GetSigners() []sdk.AccAddress {
+	// Error is intentionally ignored as validation is handled in ValidateBasic
 	addr, _ := sdk.AccAddressFromBech32(msg.Authority)
 	return []sdk.AccAddress{addr}
 }
protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go (2)

34-34: Fix typos in test case names

There are typos in the test case names:

  • "Invaid authority" should be "Invalid authority"
  • "Invaid perpetual ID" should be "Invalid perpetual ID"

Also applies to: 41-41


16-48: Consider adding more edge cases for perpetual ID

While the current test cases cover basic scenarios, consider adding these additional cases for better coverage:

  • Maximum allowed perpetual ID
  • Negative perpetual ID
 		"Failure: Invalid perpetual ID": {
 			msg: types.MsgUpgradeIsolatedPerpetualToCross{
 				Authority:   validAuthority,
 				PerpetualId: 0,
 			},
 			expectedErr: "Invalid perpetual ID",
 		},
+		"Failure: Negative perpetual ID": {
+			msg: types.MsgUpgradeIsolatedPerpetualToCross{
+				Authority:   validAuthority,
+				PerpetualId: -1,
+			},
+			expectedErr: "Invalid perpetual ID",
+		},
+		"Success: Maximum perpetual ID": {
+			msg: types.MsgUpgradeIsolatedPerpetualToCross{
+				Authority:   validAuthority,
+				PerpetualId: uint32(^uint32(0)),
+			},
+		},
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 90cf19c and 12d449a.

📒 Files selected for processing (2)
  • protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go (1 hunks)
  • protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go (1 hunks)
🔇 Additional comments (7)
protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go (3)

1-9: LGTM: Package and imports are well-organized.

The imports are correctly structured and include all necessary dependencies.


11-11: LGTM: Proper interface compliance check.

The compile-time check ensures MsgUpgradeIsolatedPerpetualToCross implements the sdk.Msg interface.


18-33: Consider additional validations for perpetual upgrade.

The basic validations look good, but given this is for upgrading isolated perpetuals to cross-margin, consider adding these checks:

  1. Verify if the perpetual exists
  2. Verify if the perpetual is currently in isolated mode
  3. Add upper bound check for PerpetualId

Let's check how these validations are handled in the keeper:

protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go (4)

1-9: LGTM!

The package name and imports are appropriate for a test file.


11-14: LGTM!

The validAuthority variable is well-documented and appropriately uses a test constant.


50-60: LGTM!

The test execution logic is well-structured and follows best practices for table-driven tests.


1-60: Verify module dependencies for potential circular issues

Given the concerns about circular dependencies mentioned in the PR comments, let's verify that the test file's location in the listing module aligns with the architectural decisions.

✅ Verification successful

Based on the search results, I can see that the test file msg_server_upgrade_isolated_perpetual_to_cross_test.go is part of the listing module and has dependencies only on standard testing packages and internal constants. The file tests the basic validation of the MsgUpgradeIsolatedPerpetualToCross message type.

Looking at the imports and module dependencies:

  1. The listing module is imported by perpetuals and subaccounts modules for expected keeper interfaces
  2. The test file itself only imports from the same module and test utilities
  3. There are no circular dependencies visible in the import graph

No circular dependency concerns found

The test file is appropriately placed in the listing module since it tests a message handler specific to that module. The imports are clean and follow the expected module boundaries.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential circular dependencies between modules

# Look for imports between relevant modules
echo "Checking imports between modules:"
rg -l "github.com/dydxprotocol/v4-chain/protocol/x/(perpetuals|subaccounts|listing)" protocol/x/{perpetuals,subaccounts,listing}

# Look for specific type usage
echo "Checking for collateral pool usage:"
rg "CollateralPool" protocol/x/{perpetuals,subaccounts,listing}

Length of output: 36338

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

🧹 Outside diff range and nitpick comments (1)
protocol/app/msgs/unsupported_msgs.go (1)

34-37: Remove "WIP" comment and consider message organization

  1. The "WIP" comment should be removed or replaced with a more descriptive comment explaining why these messages are unsupported.
  2. Consider grouping these messages with other similar functionality or adding a "listing" section header for better organization.
-		// WIP
+		// listing - these messages are unsupported to prevent direct usage outside of governance
 		"/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross":         &listingtypes.MsgUpgradeIsolatedPerpetualToCross{},
 		"/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCrossResponse": nil,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 12d449a and 9fb48dc.

📒 Files selected for processing (1)
  • protocol/app/msgs/unsupported_msgs.go (2 hunks)
🔇 Additional comments (2)
protocol/app/msgs/unsupported_msgs.go (2)

8-8: LGTM: Import addition follows existing patterns

The new import for listingtypes is appropriately placed and necessary for the new message types.


34-36: Verify if these messages should be marked as unsupported

According to the PR objectives, these messages are intended to be active governance messages for upgrading isolated perpetuals. However, they are currently listed in UnsupportedMsgSamples. Please verify if this is intentional or if these messages should be supported.

✅ Verification successful

Based on the gathered information, I can now provide the final response:

These messages should be marked as unsupported

The messages are correctly placed in UnsupportedMsgSamples. While there is a handler implementation in the listing module (msg_server_upgrade_isolated_perpetual_to_cross.go), the code appears to be work-in-progress ("WIP") and intentionally disabled. This is evidenced by:

  1. The message is properly registered in the module's services but listed in UnsupportedMsgSamples
  2. The implementation exists but is marked with "WIP"
  3. The message requires authority validation, suggesting it's a governance-related message that's not yet ready for use
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if these messages are used in governance handlers or other supported locations

# Search for message handler implementations
echo "Searching for message handlers..."
rg -A 5 "MsgUpgradeIsolatedPerpetualToCross"

# Check for any governance-related usage
echo "Checking governance-related usage..."
rg -l "MsgUpgradeIsolatedPerpetualToCross" protocol/x/gov/

Length of output: 35725


Script:

#!/bin/bash
# Let's check if this message is meant to be unsupported by looking at its implementation and usage

# Check if there's a handler implementation
echo "Checking for handler implementation..."
rg -A 10 "func.*UpgradeIsolatedPerpetualToCross" protocol/x/listing/keeper/

# Check if it's registered in the module's message server
echo "Checking message server registration..."
rg "RegisterServices" protocol/x/listing/module.go

# Check if it's meant to be a governance proposal
echo "Checking governance proposal registration..."
rg "RegisterProposalType" protocol/x/listing/

Length of output: 3881


Script:

#!/bin/bash
# Let's check if this message is actually registered in the module's message server
# and if it's currently marked as unsupported in other places

# Check module registration
echo "Checking module registration..."
rg -A 5 "RegisterServices.*Configurator" protocol/x/listing/module.go

# Check if it's registered in the keeper's message server
echo "Checking keeper message server..."
rg -A 10 "type msgServer struct" protocol/x/listing/keeper/

# Check if it's marked as unsupported in other places
echo "Checking other unsupported references..."
rg "UnsupportedMsgSamples" protocol/app/msgs/

Length of output: 2354

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9fb48dc and 8161136.

📒 Files selected for processing (2)
  • protocol/app/msgs/unsupported_msgs.go (2 hunks)
  • protocol/app/msgs/unsupported_msgs_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • protocol/app/msgs/unsupported_msgs.go
🔇 Additional comments (1)
protocol/app/msgs/unsupported_msgs_test.go (1)

22-24: Remove or address the "WIP" comment before merging.

The "WIP" comment suggests this implementation might be incomplete. Please either remove the comment if the implementation is complete, or clarify what remaining work needs to be done.

protocol/app/msgs/unsupported_msgs_test.go Outdated Show resolved Hide resolved
@hwray hwray changed the title [TRA-507] Add new gov message for upgrading isolated perpetuals to cross-margin [TRA-507] Add new gov message for upgrading markets: UpgradeIsolatedPerpetualToCross Nov 20, 2024
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: 3

🧹 Outside diff range and nitpick comments (6)
protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go (2)

51-145: Consider adding edge cases for perpetual ID validation.

While the test cases cover most scenarios, consider adding:

  • Test case for negative perpetual ID
  • Test case for zero perpetual ID
 tests := map[string]struct {
     // ... existing fields ...
 }{
+    "Failure: Negative perpetual ID": {
+        msg: &types.MsgUpgradeIsolatedPerpetualToCross{
+            Authority:   validAuthority,
+            PerpetualId: -1,
+        },
+        expectedErr: "perpetual ID must be positive",
+    },
+    "Failure: Zero perpetual ID": {
+        msg: &types.MsgUpgradeIsolatedPerpetualToCross{
+            Authority:   validAuthority,
+            PerpetualId: 0,
+        },
+        expectedErr: "perpetual ID must be positive",
+    },
     // ... existing test cases ...
 }

147-211: Consider extracting setup logic into helper functions.

The test setup is quite lengthy and could be more maintainable if split into helper functions:

+func setupTestState(
+    t *testing.T,
+    ctx sdk.Context,
+    perpetualId uint32,
+    balances map[string]*big.Int,
+) (
+    *listingkeeper.Keeper,
+    *perpetualskeeper.Keeper,
+    *bankkeeper.Keeper,
+) {
+    mockIndexerEventManager := &mocks.IndexerEventManager{}
+    keeper, _, _, pricesKeeper, perpetualsKeeper, _, _, assetsKeeper,
+        bankKeeper, subaccountsKeeper := keepertest.ListingKeepers(
+        t,
+        &mocks.BankKeeper{},
+        mockIndexerEventManager,
+    )
+
+    // Create test state
+    keepertest.CreateTestMarkets(t, ctx, pricesKeeper)
+    keepertest.CreateTestLiquidityTiers(t, ctx, perpetualsKeeper)
+    require.NoError(t, keepertest.CreateUsdcAsset(ctx, assetsKeeper))
+    keepertest.CreateTestPerpetuals(t, ctx, perpetualsKeeper)
+
+    // Setup balances
+    setupBalances(t, ctx, perpetualId, balances, perpetualsKeeper, subaccountsKeeper, bankKeeper)
+
+    return keeper, perpetualsKeeper, bankKeeper
+}
protocol/x/listing/keeper/listing_test.go (2)

65-65: Document the purpose of new keeper parameters

While the change to add new keeper parameters is consistent with the reorganization mentioned in the PR objectives, it would be helpful to document the purpose of these new parameters, even if they're not used in this test.


220-221: Maintain consistent line wrapping style

The line wrapping style here differs from the other ListingKeepers calls in the file. Consider maintaining a consistent style across all occurrences for better readability.

-				ctx, keeper, _, _, pricesKeeper, perpetualsKeeper, clobKeeper, marketMapKeeper,
-					_, _, _ := keepertest.ListingKeepers(
+				ctx, keeper, _, _, pricesKeeper, perpetualsKeeper, clobKeeper, marketMapKeeper, _, _, _ := keepertest.ListingKeepers(
protocol/x/subaccounts/keeper/transfer.go (2)

509-552: Consider adding metrics for monitoring transfers.

The function implementation looks good with proper validations and error handling. Consider adding metrics to track the transfer amounts and success/failure rates for monitoring purposes.

Add metrics similar to those used in the DistributeFees function:

+	// Emit transfer metrics
+	metrics.AddSampleWithLabels(
+		metrics.InsuranceFundTransfer,
+		metrics.GetMetricValueFromBigInt(isolatedInsuranceFundBalance),
+		metrics.GetLabelForStringValue(metrics.TransferType, "isolated_to_cross"),
+		metrics.GetLabelForIntValue(metrics.PerpetualId, int(perpetualId)),
+	)

554-593: Consider adding metrics for monitoring collateral transfers.

The function implementation looks good but would benefit from metrics tracking for monitoring purposes.

Add metrics similar to those used in the DistributeFees function:

+	// Emit transfer metrics
+	metrics.AddSampleWithLabels(
+		metrics.CollateralTransfer,
+		metrics.GetMetricValueFromBigInt(isolatedCollateralPoolBalance.Amount),
+		metrics.GetLabelForStringValue(metrics.TransferType, "isolated_to_cross"),
+		metrics.GetLabelForIntValue(metrics.PerpetualId, int(perpetualId)),
+	)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 12e279d and 334af8f.

📒 Files selected for processing (4)
  • protocol/testutil/keeper/listing.go (9 hunks)
  • protocol/x/listing/keeper/listing_test.go (3 hunks)
  • protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go (1 hunks)
  • protocol/x/subaccounts/keeper/transfer.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • protocol/testutil/keeper/listing.go
🧰 Additional context used
📓 Learnings (1)
protocol/x/subaccounts/keeper/transfer.go (2)
Learnt from: hwray
PR: dydxprotocol/v4-chain#2551
File: protocol/x/subaccounts/keeper/subaccount.go:852-865
Timestamp: 2024-11-15T16:00:11.304Z
Learning: The function `GetCrossInsuranceFundBalance` in `protocol/x/subaccounts/keeper/subaccount.go` already existed and was just moved in this PR; changes to its error handling may be out of scope.
Learnt from: hwray
PR: dydxprotocol/v4-chain#2551
File: protocol/x/subaccounts/keeper/subaccount.go:833-850
Timestamp: 2024-11-15T15:59:28.095Z
Learning: The function `GetInsuranceFundBalance` in `protocol/x/subaccounts/keeper/subaccount.go` already existed and was just moved in this PR; changes to its error handling may be out of scope.
🔇 Additional comments (3)
protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go (1)

1-28: LGTM! Package structure and imports are well-organized.

The test file follows Go conventions with appropriate package naming and imports. The validAuthority constant is properly defined using the governance module address.

protocol/x/listing/keeper/listing_test.go (2)

134-134: Consider adding test cases for cross-margin upgrade scenarios

Since this PR introduces functionality to upgrade isolated perpetuals to cross-margin, consider adding test cases that verify:

  1. The initial creation of an isolated perpetual (current coverage)
  2. The successful upgrade of an isolated perpetual to cross-margin
  3. Edge cases and validation during the upgrade process

Let's verify the existing test coverage for perpetual market types:


Line range hint 1-424: Consider architectural implications of module dependencies

Based on the PR objectives and the comment from shrenujb regarding circular dependencies, the addition of new keeper parameters might be addressing these concerns. However, we should carefully consider:

  1. Whether the current approach of adding new keeper parameters is the best solution
  2. If moving the collateral pool functionality to x/perpetuals or creating the governance message in x/subaccounts would be cleaner alternatives

This architectural decision could impact future maintainability and module coupling.

Let's analyze the current module dependencies:

@hwray hwray merged commit e3d812e into main Nov 22, 2024
39 checks passed
@hwray hwray deleted the harry/upgrade-isolated-to-cross branch November 22, 2024 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants