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-617] Fix calculation for atomic resolution #2360

Merged
merged 18 commits into from
Sep 26, 2024
Merged

[TRA-617] Fix calculation for atomic resolution #2360

merged 18 commits into from
Sep 26, 2024

Conversation

shrenujb
Copy link
Contributor

@shrenujb shrenujb commented Sep 25, 2024

Changelist

The atomic resolution calculation did not account for decimal offset of the reference prices from x/marketmap. This change makes this adjustment

Test Plan

Existing 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

Release Notes

  • New Features

    • Introduced a new branch trigger in workflows for automated processes.
    • Added listingVaultDepositParams for enhanced vault deposit configurations.
    • Implemented a new deposit function for megavault operations related to market listings.
    • Updated default parameters for vault deposits, increasing initial deposit amounts significantly.
    • Enhanced market creation process with additional deposit functionality.
  • Bug Fixes

    • Improved error handling in market creation and deposit operations.
  • Tests

    • Added comprehensive tests for the new deposit functionality and refined existing tests for clob pair creation.

Signed-off-by: Shrenuj Bansal <[email protected]>
Signed-off-by: Shrenuj Bansal <[email protected]>
Signed-off-by: Shrenuj Bansal <[email protected]>
Signed-off-by: Shrenuj Bansal <[email protected]>
Signed-off-by: Shrenuj Bansal <[email protected]>
Signed-off-by: Shrenuj Bansal <[email protected]>
Signed-off-by: Shrenuj Bansal <[email protected]>
Signed-off-by: Shrenuj Bansal <[email protected]>
Signed-off-by: Shrenuj Bansal <[email protected]>
Signed-off-by: Shrenuj Bansal <[email protected]>
@shrenujb shrenujb requested a review from a team as a code owner September 25, 2024 21:14
Copy link

linear bot commented Sep 25, 2024

Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

Warning

Rate limit exceeded

@shrenujb has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 8 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between f976558 and 2f3eae2.

Walkthrough

The changes introduce several enhancements to the protocol's listing and vault management functionalities. Key modifications include the addition of a new branch trigger in the GitHub Actions workflow, updates to the GenesisState interface to include listing vault deposit parameters, and the introduction of a VaultKeeper to manage vault-related operations. Other changes involve adjustments to various configuration files and test cases to reflect these updates, ensuring that the protocol can effectively handle market listings and vault deposits.

Changes

File Path Change Summary
.github/workflows/protocol-build-and-push.yml Added a new branch trigger tra617 for workflow on push events.
indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/genesis.ts Updated GenesisState and GenesisStateSDKType interfaces to include a new optional property for listing vault deposit parameters.
proto/dydxprotocol/listing/genesis.proto Added a new field listing_vault_deposit_params to the GenesisState message and imported additional proto files.
protocol/app/app.go Updated NewAppModule to include app.VaultKeeper in the instantiation of listingModule.
protocol/app/testdata/default_genesis_state.json Modified hard_cap_for_markets and added listing_vault_deposit_params with specific parameters.
protocol/scripts/genesis/sample_pregenesis.json Updated hard_cap_for_markets and added listing_vault_deposit_params with specific parameters.
protocol/testing/genesis.sh Added configurations for market listings and vault deposits in the edit_genesis function.
protocol/testutil/constants/genesis.go Updated GenesisState constant with new fields related to market listings and vault deposit parameters.
protocol/testutil/keeper/listing.go Added vaultkeeper as a new dependency in the ListingKeepers and createListingKeeper functions.
protocol/x/clob/keeper/clob_pair.go Refactored CreatePerpetualClobPair to streamline state management and orderbook creation.
protocol/x/listing/genesis.go Added a call to set listing vault deposit parameters in the InitGenesis function.
protocol/x/listing/keeper/keeper.go Introduced VaultKeeper field to the Keeper struct and updated the constructor accordingly.
protocol/x/listing/keeper/listing.go Added DepositToMegavaultforPML function for depositing into a megavault and updated CreateClobPair.
protocol/x/listing/keeper/listing_test.go Introduced tests for DepositToMegavaultforPML and streamlined TestCreateClobPair.
protocol/x/listing/keeper/msg_create_market_permissionless.go Modified CreateMarketPermissionless to include a deposit step after creating a CLOB pair.
protocol/x/listing/keeper/msg_create_market_permissionless_test.go Enhanced test setup to reflect balance conditions for market creation.
protocol/x/listing/module.go Added vaultKeeper field to AppModule struct and updated the constructor.
protocol/x/listing/types/expected_keepers.go Updated ClobKeeper interface methods and introduced a new VaultKeeper interface for vault operations.
protocol/x/listing/types/genesis.go Updated DefaultGenesis to initialize HardCapForMarkets and ListingVaultDepositParams.
protocol/x/listing/types/params.go Updated DefaultParams to increase the NewVaultDepositAmount.
protocol/x/vault/keeper/params.go Added SetVaultStatus method to modify vault status within the state management.

Possibly related PRs

Suggested labels

protocol, proto

Suggested reviewers

  • vincentwschau

🐇 In the land of code where changes bloom,
New vaults and listings dispel the gloom.
With parameters set and triggers in play,
Our protocol hops into a brighter day!
So let’s cheer for the updates, both big and small,
For a future of vaults that will benefit all! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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: 12

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

Line range hint 1-16: Overall concerns about the changes and validation

The changes made in this file seem to diverge from the stated PR objective of fixing the calculation for atomic resolution. Instead, we see significant modifications to the default genesis state that could have far-reaching implications for the system.

Additionally, I noticed that the Validate function remains unchanged and always returns nil. Given the new parameters added to the genesis state, it might be prudent to implement some validation logic.

Consider the following:

  1. Align the changes with the PR objective or update the PR description to accurately reflect these modifications.
  2. Implement validation logic in the Validate function to ensure the integrity of the new and modified fields in the genesis state.
  3. Document the rationale behind these changes and their expected impact on the system.

Here's a suggestion for improving the Validate function:

func (gs GenesisState) Validate() error {
    if gs.HardCapForMarkets <= 0 {
        return fmt.Errorf("HardCapForMarkets must be positive, got %d", gs.HardCapForMarkets)
    }
    // Add validation for ListingVaultDepositParams if necessary
    return gs.ListingVaultDepositParams.Validate()
}

Please review and adjust as needed based on the specific requirements of your system.

protocol/x/listing/types/params.go (2)

Line range hint 14-27: Consider adding an upper limit check in the Validate() function.

While the current validation logic correctly checks for non-negative values, it might be beneficial to add a sanity check for extremely large values to prevent potential overflow issues, especially considering the significant increase in the NewVaultDepositAmount.

Consider adding an upper limit check in the Validate() function. For example:

func (p ListingVaultDepositParams) Validate() error {
	// if any of the deposit params are negative, return an error
-	if p.NewVaultDepositAmount.Sign() <= 0 || p.MainVaultDepositAmount.Sign() < 0 {
+	if p.NewVaultDepositAmount.Sign() <= 0 || p.MainVaultDepositAmount.Sign() < 0 ||
+		p.NewVaultDepositAmount.GT(dtypes.NewIntFromUint64(1_000_000_000_000)) || // 1 trillion
+		p.MainVaultDepositAmount.GT(dtypes.NewIntFromUint64(1_000_000_000_000)) { // 1 trillion
		return ErrInvalidDepositAmount
	}

	// if the number of blocks to lock shares is negative, return an error
	if p.NumBlocksToLockShares <= 0 {
		return ErrInvalidNumBlocksToLockShares
	}

	return nil
}

This change adds an upper limit of 1 trillion for both NewVaultDepositAmount and MainVaultDepositAmount. Adjust the limit as appropriate for your use case.


Line range hint 1-27: Summary of changes and potential impact

The primary change in this file is a significant increase in the NewVaultDepositAmount from 10,000 to 10,000,000,000 USDC. This 1000x increase could have substantial implications on the system's behavior, particularly in areas related to vault deposits and possibly token economics.

Key points to consider:

  1. The change is correctly implemented, but the accompanying comment needs to be updated.
  2. The Validate() function still works correctly with this new value, but adding an upper limit check could provide additional safety.
  3. This change might require updates to other parts of the codebase, particularly test cases and any logic that depends on this default value.
  4. Documentation should be updated to reflect this change, especially if it affects user-facing aspects of the system.

Given the magnitude of this change, please ensure that:

  1. The rationale for this increase is well-documented.
  2. All relevant stakeholders are aware of this change and its potential impacts.
  3. Thorough testing is conducted, including integration and system-wide tests, to verify that this change doesn't introduce unexpected behaviors.
  4. Consider a phased rollout or feature flag if possible, to mitigate risks associated with such a significant change.
protocol/x/listing/keeper/msg_create_market_permissionless.go (1)

40-44: LGTM: New DepositToMegavaultforPML operation with proper error handling.

The addition of the DepositToMegavaultforPML operation enhances the functionality of the market creation process. The error handling is consistent with the existing pattern in the function.

Consider adding more context to the error log by including the clobPairId and SubaccountId:

-		k.Logger(ctx).Error("failed to deposit to megavault for PML market", "error", err)
+		k.Logger(ctx).Error("failed to deposit to megavault for PML market", "error", err, "clobPairId", clobPairId, "subaccountId", msg.SubaccountId)

This will provide more detailed information for debugging purposes.

protocol/x/listing/keeper/keeper.go (1)

35-35: Approved. Consider adding a comment for the new parameter.

The update to NewKeeper function is correct and consistent with the Keeper struct changes.

For improved readability, consider adding a comment for the new vaultKeeper parameter:

 func NewKeeper(
   cdc codec.BinaryCodec,
   storeKey storetypes.StoreKey,
   authorities []string,
   pricesKeeper types.PricesKeeper,
   clobKeeper types.ClobKeeper,
   marketMapKeeper types.MarketMapKeeper,
   perpetualsKeeper types.PerpetualsKeeper,
-  vaultKeeper types.VaultKeeper,
+  vaultKeeper types.VaultKeeper, // Keeper for managing vault-related operations
 ) *Keeper {
   // ...
 }

Also applies to: 45-45

protocol/x/listing/module.go (1)

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

The changes to protocol/x/listing/module.go introduce a new vaultKeeper field to the AppModule struct and update the NewAppModule constructor accordingly. These modifications appear to be implemented correctly.

However, to ensure the completeness and correctness of this change, please consider the following:

  1. Verify the necessity of adding VaultKeeper to the listing module and its impact on the module's responsibilities.
  2. Ensure all NewAppModule calls across the codebase have been updated to include the vaultKeeper argument.
  3. Check for any additional files that might require updates due to this change (e.g., tests, dependency injections, or module initialization code).
  4. Update relevant documentation and comments to reflect the new dependency on VaultKeeper.

Consider documenting the reason for adding VaultKeeper to the listing module in a comment or in the PR description. This will help future maintainers understand the design decision and the relationship between the listing and vault modules.

protocol/x/clob/keeper/clob_pair.go (1)

168-172: LGTM! Consider clarifying the comment.

The renaming of this function to CreateClobPairStructures and the addition of error return improve clarity and error handling. This change aligns well with the separation of concerns observed earlier.

Consider updating the comment to more accurately reflect the function's new name and purpose. For example:

-// CreateClobPair performs all non stateful operations to create a CLOB pair.
+// CreateClobPairStructures performs all non-stateful operations to set up the structures for a CLOB pair.
protocol/testing/genesis.sh (2)

Line range hint 1-2260: Review of edit_genesis function

The edit_genesis function is quite long and complex. While it seems to cover all necessary aspects of genesis configuration, there are some potential improvements and concerns:

  1. Function length: The function is over 2000 lines long, which makes it hard to maintain and understand. Consider breaking it down into smaller, more focused functions.

  2. Hardcoded values: There are many hardcoded values throughout the function. It might be beneficial to move these to configuration files or environment variables for easier management and flexibility.

  3. Error handling: The script doesn't have explicit error handling. Consider adding checks and error messages for critical operations.

  4. Comments: While there are some comments, more detailed explanations for each section would improve readability and maintainability.

  5. Consistency: The script uses a mix of dasel commands and direct file writes. Consider standardizing the approach for consistency.

  6. Security: Ensure that all the parameters set, especially those related to economics (like fees, limits, and tiers), have been thoroughly reviewed and tested.

  7. Testability: Consider adding unit tests for critical parts of the script to ensure it behaves as expected under different scenarios.

To improve maintainability and readability, consider refactoring the edit_genesis function into smaller, more focused functions. For example:

function edit_genesis() {
    update_consensus_params
    update_crisis_module
    update_gov_module
    update_staking_module
    update_assets_module
    update_bridge_module
    update_ibc_module
    update_perpetuals_module
    # ... and so on for each major section
}

This approach would make the script easier to understand, maintain, and test.

Also applies to: 2268-2779


Line range hint 1-2779: Consistency and error handling improvements

Throughout the script, I noticed some areas where consistency and error handling could be improved:

  1. Error handling: Many commands assume success without checking. Consider adding error checks, especially for critical operations. For example:
if ! dasel put -t string -f "$GENESIS" '.some.path' -v "some_value"; then
    echo "Error: Failed to set .some.path in genesis file"
    exit 1
fi
  1. Variable usage: Some parts of the script use hardcoded values where variables are defined earlier. Ensure consistent use of variables throughout the script.

  2. Function naming: Consider adopting a consistent naming convention for functions. Currently, there's a mix of snake_case and camelCase.

  3. Comments: While some sections are well-commented, others lack explanation. Consider adding more inline comments to explain the purpose of each section.

To improve consistency and error handling, consider implementing a wrapper function for dasel commands:

function set_genesis_value() {
    local path=$1
    local type=$2
    local value=$3
    if ! dasel put -t "$type" -f "$GENESIS" "$path" -v "$value"; then
        echo "Error: Failed to set $path in genesis file"
        exit 1
    fi
}

# Usage
set_genesis_value '.app_state.gov.params.voting_period' 'string' '120s'

This approach would centralize error handling and make the script more consistent and robust.

protocol/x/listing/types/expected_keepers.go (1)

69-90: Suggestion: Add method documentation for VaultKeeper interface.

For better readability and maintenance, consider adding comments to each method in the VaultKeeper interface to explain their purpose, parameters, and return values. This will help other developers understand the intended functionality.

protocol/x/listing/keeper/listing.go (1)

205-208: Function name should follow Go naming conventions.

The function name DepositToMegavaultforPML should be DepositToMegavaultForPML, capitalizing 'For' to adhere to Go naming conventions for exported functions.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4270782 and f976558.

🔇 Files ignored due to path filters (1)
  • protocol/x/listing/types/genesis.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (21)
  • .github/workflows/protocol-build-and-push.yml (1 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/genesis.ts (6 hunks)
  • proto/dydxprotocol/listing/genesis.proto (1 hunks)
  • protocol/app/app.go (2 hunks)
  • protocol/app/testdata/default_genesis_state.json (1 hunks)
  • protocol/scripts/genesis/sample_pregenesis.json (1 hunks)
  • protocol/testing/genesis.sh (1 hunks)
  • protocol/testutil/constants/genesis.go (1 hunks)
  • protocol/testutil/keeper/listing.go (4 hunks)
  • protocol/x/clob/keeper/clob_pair.go (4 hunks)
  • protocol/x/listing/genesis.go (1 hunks)
  • protocol/x/listing/keeper/keeper.go (3 hunks)
  • protocol/x/listing/keeper/listing.go (4 hunks)
  • protocol/x/listing/keeper/listing_test.go (3 hunks)
  • protocol/x/listing/keeper/msg_create_market_permissionless.go (1 hunks)
  • protocol/x/listing/keeper/msg_create_market_permissionless_test.go (2 hunks)
  • protocol/x/listing/module.go (3 hunks)
  • protocol/x/listing/types/expected_keepers.go (3 hunks)
  • protocol/x/listing/types/genesis.go (1 hunks)
  • protocol/x/listing/types/params.go (1 hunks)
  • protocol/x/vault/keeper/params.go (1 hunks)
🧰 Additional context used
buf
proto/dydxprotocol/listing/genesis.proto

4-4: import "gogoproto/gogo.proto": file does not exist

(COMPILE)

🔇 Additional comments not posted (43)
protocol/x/listing/types/genesis.go (2)

7-7: New ListingVaultDepositParams field requires explanation

A new field ListingVaultDepositParams has been added to the genesis state, initialized with DefaultParams(). This addition could have significant implications for the system's initialization and operation.

Please provide more information:

  • What is the purpose of ListingVaultDepositParams?
  • How does this relate to the PR objective of fixing the calculation for atomic resolution?
  • Are there corresponding changes in other parts of the codebase to handle this new parameter?

Let's verify the implementation and usage of DefaultParams():

✅ Verification successful

Addition of ListingVaultDepositParams Verified

The new ListingVaultDepositParams field has been correctly added and initialized with DefaultParams(), consistent with patterns in other modules. This addition aligns with the module's parameter initialization and does not impact the PR objective negatively.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the definition and usage of DefaultParams
rg --type go "func DefaultParams" -C 5
rg --type go "DefaultParams\(\)" -C 3

Length of output: 9700


6-6: Significant change in HardCapForMarkets requires explanation

The HardCapForMarkets value has been changed from 0 to 500. This is a substantial modification to the default genesis state that could significantly impact the system's behavior and capacity.

Could you please provide more context for this change?

  • What is the rationale behind setting a hard cap of 500 markets?
  • How does this relate to the PR objective of fixing the calculation for atomic resolution?
  • Have potential impacts on system performance and scalability been considered?

Additionally, let's verify if this change is consistent across the codebase:

✅ Verification successful

Change to HardCapForMarkets Verified as Isolated

The modification of HardCapForMarkets from 0 to 500 has been thoroughly verified and is confined to protocol/x/listing/types/genesis.go. No other instances of HardCapForMarkets were found in the codebase, ensuring that this change does not affect other modules or functionalities.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of HardCapForMarkets
rg --type go "HardCapForMarkets" -C 3

Length of output: 9700

proto/dydxprotocol/listing/genesis.proto (1)

15-17: LGTM! New field added correctly. Please provide more context.

The new listing_vault_deposit_params field is correctly added to the GenesisState message with proper formatting and numbering. The non-nullable option is appropriate for ensuring this field is always present in the genesis state.

Could you please provide more context about the ListingVaultDepositParams type and how it relates to the atomic resolution calculation mentioned in the PR objective? This would help ensure the change aligns with the intended purpose of the PR.

protocol/x/listing/genesis.go (1)

17-19: LGTM, but verify new function and consider error handling.

The addition of SetListingVaultDepositParams is consistent with the existing code structure and initializes an important parameter for the module. However, please ensure the following:

  1. Verify that the SetListingVaultDepositParams function is correctly implemented in the keeper package.
  2. Consider if panicking is the most appropriate error handling strategy for genesis initialization. While it's consistent with the existing code, it might be worth discussing if a more graceful error handling approach could be beneficial.

To verify the existence and correct implementation of the SetListingVaultDepositParams function, please run the following script:

✅ Verification successful

Verification Successful: SetListingVaultDepositParams is correctly implemented.

The SetListingVaultDepositParams function exists in the keeper package and is properly integrated with the genesis state. However, consider reviewing the error handling strategy to determine if using panic is the most appropriate approach for genesis initialization.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of SetListingVaultDepositParams function

# Test: Search for the SetListingVaultDepositParams function definition
ast-grep --lang go --pattern $'func (k Keeper) SetListingVaultDepositParams(ctx sdk.Context, listingVaultDepositParams types.ListingVaultDepositParams) error {
  $$$
}'

# Test: Check for any references or usages of ListingVaultDepositParams
rg --type go "ListingVaultDepositParams"

Length of output: 27699

protocol/x/listing/keeper/msg_create_market_permissionless.go (1)

34-38: LGTM: Proper capture and error handling of CreateClobPair return value.

The modification to capture the clobPairId returned by CreateClobPair is correct and necessary for the subsequent operation. The error handling remains consistent with the existing pattern in the function.

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

23-23: Approved. Please clarify the purpose of adding VaultKeeper.

The addition of VaultKeeper to the Keeper struct is structurally correct. However, could you please elaborate on how this addition relates to fixing the calculation for atomic resolution? This context would help in understanding the broader implications of this change.

To ensure the VaultKeeper type is properly defined, let's verify its existence:


23-23: ```shell
#!/bin/bash

Description: Search for the definition of the VaultKeeper interface

find . -type f -name ".go" ! -path "./**/_test.go" -exec grep -H "type VaultKeeper interface" {} ;


```shell
#!/bin/bash
# Description: Find implementations and usages of VaultKeeper related to atomic resolution

# Search for methods of VaultKeeper that mention atomic resolution
rg --type go 'VaultKeeper\..*atomicResolution' .

# Additionally, search for atomic resolution calculations interacting with VaultKeeper
rg --type go 'atomicResolution.*VaultKeeper' .
indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/genesis.ts (6)

1-1: LGTM: Import statement added correctly.

The new import for ListingVaultDepositParams and ListingVaultDepositParamsSDKType is correctly added and necessary for the new property in the GenesisState interface.


12-14: LGTM: New property added to GenesisState interface.

The listingVaultDepositParams property is correctly added to the GenesisState interface with the appropriate type and optionality. The comment provides a clear description of its purpose.


24-26: LGTM: New property added to GenesisStateSDKType interface.

The listing_vault_deposit_params property is correctly added to the GenesisStateSDKType interface with the appropriate type, optionality, and naming convention (snake_case). The comment provides a clear description of its purpose.


31-32: LGTM: New property correctly initialized in createBaseGenesisState.

The listingVaultDepositParams property is correctly initialized as undefined in the createBaseGenesisState function, which is consistent with its optional nature in the interface definition.


42-44: LGTM: GenesisState object methods updated correctly.

The encode, decode, and fromPartial methods of the GenesisState object have been correctly updated to handle the new listingVaultDepositParams property:

  1. The encode method correctly checks if listingVaultDepositParams is defined before encoding.
  2. The decode method correctly decodes the new property.
  3. The fromPartial method correctly handles the new property, including cases where it might be undefined or null.

These changes ensure proper serialization, deserialization, and partial object creation for the updated GenesisState structure.

Also applies to: 62-64, 78-78


Line range hint 1-82: Summary: New property added for PML megavault deposits.

The changes in this file introduce a new optional property listingVaultDepositParams to the GenesisState and GenesisStateSDKType interfaces. This property is related to PML megavault deposits and could be part of the atomic resolution calculation mentioned in the PR objectives. The changes are consistently implemented throughout the file, including imports, interface definitions, and related methods.

These modifications appear to enhance the functionality related to listing parameters, potentially improving the atomic resolution calculation as intended by the PR.

To ensure consistency across the codebase, please run the following verification script:

This script will help identify any other locations in the codebase where similar updates might be necessary or where the new ListingVaultDepositParams is being used.

protocol/testutil/keeper/listing.go (4)

17-17: LGTM: New import for vaultkeeper added correctly.

The new import for vaultkeeper is properly formatted and consistent with the existing import style and project structure.


169-169: LGTM: vaultKeeper parameter added to createListingKeeper call.

The vaultKeeper parameter is correctly added to the createListingKeeper function call, maintaining consistency with the updated function signature.


Line range hint 1-210: Summary: vaultkeeper integration with Listing keeper

The changes in this file consistently introduce the vaultkeeper as a new dependency for the Listing keeper. This modification appears to be part of a larger refactoring or feature addition involving the Vault keeper.

Consider the following points:

  1. Ensure that all relevant tests have been updated to include the vaultkeeper when creating a Listing keeper.
  2. Review the actual Listing keeper implementation to verify that the vaultkeeper is being used appropriately.
  3. Check for any potential circular dependencies between the Listing and Vault keepers.
  4. Update relevant documentation to reflect this new dependency in the Listing keeper's architecture.

To ensure comprehensive test coverage, run the following script to check for test files that might need updating:

#!/bin/bash
# Description: Find test files that might need updating due to the new vaultkeeper dependency

echo "Searching for test files that create a Listing keeper:"
rg --type go -l 'func TestListing' | xargs rg 'createListingKeeper'

echo "Searching for mock Listing keepers that might need updating:"
rg --type go -l 'mock.ListingKeeper'

187-187: LGTM: vaultkeeper parameter added to createListingKeeper and passed to keeper.NewKeeper.

The vaultkeeper parameter is correctly added to the createListingKeeper function signature and passed to the keeper.NewKeeper function call. This change is consistent with the modifications in the ListingKeepers function.

Please ensure that the keeper.NewKeeper function in the actual implementation file has been updated to accept and utilize the vaultkeeper parameter. Run the following script to verify:

Also applies to: 207-207

protocol/x/vault/keeper/params.go (1)

Line range hint 1-132: Overall assessment of the changes

The addition of the SetVaultStatus method to the Keeper struct is a positive enhancement to the vault management functionality. It provides a dedicated method for updating the vault status, which can improve code organization and readability.

Key points:

  1. The new method integrates well with existing code.
  2. It leverages existing methods (GetVaultParams and SetVaultParams) for consistency.
  3. The change is focused and doesn't introduce unnecessary complexity.

To ensure the full benefit of this addition:

  1. Implement the suggested improvements in the method implementation.
  2. Verify its usage across the codebase as suggested in the previous comment.
  3. Consider updating relevant documentation or comments in other parts of the code that deal with vault status changes.
protocol/x/listing/module.go (2)

116-116: LGTM. Please verify all NewAppModule calls have been updated.

The addition of the vaultKeeper parameter to the NewAppModule constructor and its initialization in the returned AppModule struct are implemented correctly. However, please ensure that:

  1. All calls to NewAppModule throughout the codebase have been updated to include the vaultKeeper argument.
  2. The order of parameters in the constructor remains consistent with other similar constructors in the codebase.

To help verify that all NewAppModule calls have been updated, please run the following script:

This script will help identify all calls to NewAppModule and highlight any that might be missing the vaultKeeper argument, ensuring consistency across the codebase.

Also applies to: 125-125


106-106: LGTM. Please verify the necessity and impacts of adding vaultKeeper.

The addition of the vaultKeeper field to the AppModule struct is syntactically correct. However, please ensure that:

  1. The VaultKeeper is necessary for the listing module's functionality.
  2. The addition of this dependency doesn't introduce circular dependencies.
  3. The impact on the module's responsibilities and separation of concerns has been considered.

To help verify the necessity of this change, please run the following script:

This script will help identify where and how the VaultKeeper is being used in the listing module, providing context for its addition.

.github/workflows/protocol-build-and-push.yml (1)

6-6: Approve the addition of 'tra617' branch trigger with a suggestion.

The addition of the 'tra617' branch to the workflow triggers is approved. This change allows for continuous integration and deployment specifically for this feature branch, which is beneficial for testing the current PR (TRA-617).

However, please consider the following:

  1. Remove this branch trigger after merging the PR to prevent unnecessary workflow runs in the future.
  2. Verify if adding feature branch triggers to the main workflow file aligns with your team's practices. If not, consider using a separate workflow file for feature-specific CI/CD.

To verify the impact of this change, you can run the following script:

This script will help you identify any other feature branch triggers that might have been left in the workflow file and show recent workflow runs, which can help in understanding the impact of this change.

✅ Verification successful

The 'tra617' branch trigger has been successfully verified.

  • Only the 'tra617' branch trigger has been added, with no additional feature branch triggers present.
  • Recent workflow runs are limited to 'main', 'release/protocol/v6.x', and 'tra617', all functioning as expected.

Please ensure to:

  1. Remove the 'tra617' branch trigger after merging the PR to avoid unnecessary future workflow runs.
  2. Confirm that adding feature branch triggers aligns with your team's CI/CD practices.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other feature branch triggers and recent workflow runs

# Check for other potential feature branch triggers
echo "Checking for other feature branch triggers:"
grep -nE '^\s+- [a-z0-9]+$' .github/workflows/protocol-build-and-push.yml | grep -vE '(main|release|tra617)'

# Check recent workflow runs (requires GitHub CLI)
echo "Recent workflow runs:"
gh run list --workflow=protocol-build-and-push.yml --limit=5 --json event,headBranch,conclusion --jq '.[] | "\(.event) on \(.headBranch): \(.conclusion)"'

Length of output: 539

protocol/app/testdata/default_genesis_state.json (1)

356-361: Please clarify the implications of the new listing parameters

The changes to the listing section introduce new parameters that may have significant impacts on the system's behavior:

  1. The hard_cap_for_markets is set to 500. Can you confirm if this aligns with the intended design and explain its purpose?

  2. The new listing_vault_deposit_params object introduces three parameters:

    • new_vault_deposit_amount is set to a large value (10 billion in the smallest unit). What are the economic implications of this amount?
    • main_vault_deposit_amount is set to 0. Does this mean main vault deposits are not required or handled differently?
    • num_blocks_to_lock_shares is set to 2,592,000 (approximately 30 days worth of blocks). What's the rationale behind this lock period?

Could you provide more context on how these parameters will be used and their potential impact on the system?

To ensure these changes align with the PR objectives, let's verify the PR description:

Consider documenting these new parameters and their implications in the project's technical documentation to ensure clarity for future development and maintenance.

protocol/x/clob/keeper/clob_pair.go (2)

212-213: LGTM, but consider the implications of making this function public.

The renaming of setClobPair to SetClobPair makes the function public, which is consistent with the new architecture. However, this change could have implications for the module's API and potential misuse.

Please run the following script to check for any external usage of this newly public function:

#!/bin/bash
# Description: Check for any external usage of the newly public SetClobPair function

# Search for imports of the clob keeper package
echo "Packages importing clob keeper:"
rg "\"github.com/dydxprotocol/v4-chain/protocol/x/clob/keeper\"" --type go

echo "\nUsage of SetClobPair outside the clob package:"
rg "keeper\.SetClobPair\s*\(" --type go | grep -v "protocol/x/clob"

If there are any results from the second search, please review them carefully to ensure that the public access is intentional and secure.


69-72: LGTM! Consider verifying the order of operations.

The separation of SetClobPair and CreateClobPairStructures is a good practice for modularity. However, please ensure that this order of operations doesn't introduce any potential race conditions or inconsistencies in the system state.

To verify the correctness of this change, please run the following script:

protocol/app/app.go (3)

1209-1209: Summary of VaultKeeper addition to ListingKeeper

The changes introduce VaultKeeper as a new dependency for ListingKeeper. While the modification is straightforward, it has potential implications for the application's architecture and module interactions.

Key points to consider:

  1. The change increases coupling between the listing and vault modules.
  2. It may affect module initialization order and overall application architecture.
  3. There might be a need for additional documentation and test updates.

The changes appear to be intentional and likely necessary for new functionality. However, to ensure a smooth integration, please:

  1. Review and update relevant documentation, including architecture diagrams if they exist.
  2. Adjust any affected tests, particularly those involving ListingKeeper.
  3. Verify that this change doesn't introduce any unintended circular dependencies.
  4. Consider adding comments in the code to explain why VaultKeeper is now required by ListingKeeper.

These steps will help maintain the clarity and maintainability of the codebase as it evolves.

Also applies to: 1218-1218


1209-1209: Consider architectural implications of VaultKeeper dependency

The addition of VaultKeeper to ListingKeeper introduces a new dependency between these modules. This change may have broader architectural implications:

  1. It increases the coupling between the listing and vault modules.
  2. It may affect the module initialization order in the application.

Please consider the following actions:

  1. Review the listing module's responsibilities and ensure that this new dependency aligns with its intended purpose.
  2. Update the overall application architecture documentation to reflect this new relationship between modules.
  3. Consider if this change impacts the application's modularity or if it introduces any circular dependencies.
  4. Ensure that the VaultKeeper methods used by ListingKeeper are well-defined and properly encapsulated to maintain clear module boundaries.
#!/bin/bash
# Check for potential circular dependencies and module documentation

# Look for imports between listing and vault modules
rg --type go "import\s+\([^)]*vault[^)]*listing[^)]*\)" ./protocol/x
rg --type go "import\s+\([^)]*listing[^)]*vault[^)]*\)" ./protocol/x

# Check for updates in module documentation
rg --type md "VaultKeeper" ./protocol/x/listing/spec

Also applies to: 1218-1218


1209-1209: Vault Keeper added to Listing Keeper

The VaultKeeper has been added as a dependency to the ListingKeeper. This change suggests that the listing functionality now requires access to vault-related operations or data.

To ensure this change is properly integrated, please verify the following:

  1. The VaultKeeper is initialized before the ListingKeeper in the application setup.
  2. The listing module's documentation is updated to reflect this new dependency.
  3. Any relevant unit or integration tests are updated to include mock VaultKeeper when testing ListingKeeper.

Also applies to: 1218-1218

protocol/scripts/genesis/sample_pregenesis.json (2)

872-877: Review of changes in the "listing" module

The changes introduce new configuration parameters for the "listing" module:

  1. hard_cap_for_markets: Set to 500, which likely represents a limit on the number of markets that can be listed.
  2. listing_vault_deposit_params: A new object with the following properties:
    • main_vault_deposit_amount: Set to "0"
    • new_vault_deposit_amount: Set to "10000000000"
    • num_blocks_to_lock_shares: Set to 2592000

These changes appear to introduce a cap on the number of markets and define parameters for vault deposits related to listings.

The changes seem reasonable, but I have a few points to consider:

  1. The hard_cap_for_markets value of 500 seems appropriate, but it's worth confirming if this aligns with the intended scalability of the system.
  2. The main_vault_deposit_amount is set to "0". Is this intentional, or should it have a non-zero value?
  3. The num_blocks_to_lock_shares is set to 2592000, which likely represents a significant time period. It would be helpful to have a comment explaining the duration this represents (e.g., in days or hours) for better readability.

Consider adding comments to explain the purpose and implications of these new parameters, especially for future maintainers of the configuration.


Line range hint 1-3844: Overall assessment of the configuration file

The changes to the sample_pregenesis.json file are focused on the "listing" module and introduce new parameters for market caps and vault deposits. These changes appear to be self-contained and don't seem to directly impact other modules in the configuration.

The modifications seem appropriate for their intended purpose. However, to enhance the maintainability and clarity of the configuration:

  1. Consider adding comments throughout the file to explain the purpose and implications of key configuration parameters, especially for complex or critical settings.
  2. Ensure that the new listing module parameters are consistent with the overall system design and performance goals.
  3. It may be beneficial to review other modules to see if any adjustments are needed in response to these changes, particularly if there are any cross-module dependencies related to market listings or vault operations.

Overall, the changes appear to be a positive addition to the configuration, providing more control over market listings and associated deposits.

protocol/testutil/constants/genesis.go (3)

876-881: New listing parameters added. Please clarify their purpose and impact.

The changes introduce new parameters in the listing section:

  • hard_cap_for_markets: 500
  • listing_vault_deposit_params with fields for new and main vault deposit amounts, and number of blocks to lock shares.

These additions seem to be related to market listings and vault deposit parameters. Could you please provide more context on:

  1. The purpose of the hard_cap_for_markets and its implications?
  2. The significance of the listing_vault_deposit_params and how they affect the system?
  3. How these changes relate to fixing the calculation for atomic resolution, as mentioned in the PR objectives?

876-881: Summary of changes and clarification request

The changes in this PR are focused on the listing section of the GenesisState constant, introducing new parameters for market cap and vault deposits. While these changes appear to be well-structured and self-contained, it's not immediately clear how they address the PR objective of "fixing calculation for atomic resolution."

Could you please provide more context on:

  1. How these new parameters in the listing section contribute to fixing the calculation for atomic resolution?
  2. Are there any other changes or considerations outside this file that work in conjunction with these modifications to achieve the PR's goal?

This additional information will help ensure that the changes fully address the intended objectives and maintain the overall integrity of the system.


876-881: Verify potential impacts on other sections

The changes to the listing section appear to be self-contained. However, it's important to ensure that these new parameters don't require corresponding changes in other sections of the file, such as assets or perpetuals. Could you please confirm that:

  1. The hard_cap_for_markets doesn't need to be referenced or checked in any other part of the configuration?
  2. The listing_vault_deposit_params don't affect any existing vault or asset configurations?
✅ Verification successful

Verification Successful: Changes are Self-Contained

The new parameters in the listing section of protocol/testutil/constants/genesis.go are only referenced within lines 876-880. No impacts detected on other sections of the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potential references to the new parameters in other parts of the file

echo "Searching for potential references to hard_cap_for_markets:"
grep -n "hard_cap_for_markets" protocol/testutil/constants/genesis.go

echo "Searching for potential references to listing_vault_deposit_params:"
grep -n "listing_vault_deposit_params" protocol/testutil/constants/genesis.go

echo "Searching for potential references to new_vault_deposit_amount:"
grep -n "new_vault_deposit_amount" protocol/testutil/constants/genesis.go

echo "Searching for potential references to main_vault_deposit_amount:"
grep -n "main_vault_deposit_amount" protocol/testutil/constants/genesis.go

echo "Searching for potential references to num_blocks_to_lock_shares:"
grep -n "num_blocks_to_lock_shares" protocol/testutil/constants/genesis.go

Length of output: 1293

protocol/testing/genesis.sh (2)

2261-2267: New listing functionality added

The changes introduce new listing functionality to the genesis configuration:

  1. A hard cap for markets is set to 500.
  2. Default listing vault deposit parameters are established:
    • New vault deposit amount: 10,000 USDC
    • Main vault deposit amount: 0 USDC
    • Number of blocks to lock shares: 2,592,000 (equivalent to 30 days)

These changes seem reasonable, but consider the following:

  1. The hard cap of 500 markets might need adjustment in the future. Consider making this configurable or document the process for changing it.
  2. The main vault deposit amount is set to 0. Ensure this is intentional and doesn't pose any security risks.
  3. The 30-day lock period for shares is a significant duration. Make sure this aligns with your tokenomics and governance model.

Line range hint 1-2779: Security considerations

While reviewing the entire script, I noticed some potential security considerations:

  1. Sensitive data: The script handles sensitive economic parameters. Ensure that the values set are thoroughly reviewed and approved by the economic design team.

  2. Input validation: There's limited input validation for the parameters passed to the script. Consider adding more robust checks to prevent potential misconfigurations.

  3. Permissions: Ensure that this script is only executable by authorized personnel, as it has the power to significantly alter the network's economic parameters.

  4. Audit trail: Consider adding logging functionality to keep track of who ran the script and what changes were made.

To verify the security of the economic parameters, you could run the following script:

This script would help ensure that critical economic parameters are set within expected ranges.

protocol/x/listing/types/expected_keepers.go (1)

4-7: Approval: Necessary imports added.

The imports for "math/big" and vaulttypes are added appropriately to support the new functionalities introduced in the code.

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

4-5: Importing "math/big" for big integer computations

The addition of "math/big" import is appropriate for handling large integer values required for the balance field in the test cases.


27-27: *Adding 'balance big.Int' enhances test flexibility

Introducing the balance field in the test case struct allows each test case to specify its own initial balance. This improves the configurability and coverage of the tests.


34-55: Setting 'balance' in test cases ensures accurate test scenarios

Providing specific balance values in each test case ensures that the subaccounts are funded appropriately for the test scenarios. This change enhances the validity of the test outcomes.


63-94: Initializing genesis state with subaccounts and specified balances

The genesis state is correctly updated to include subaccounts with asset positions based on tc.balance. This ensures that each test case starts with the intended initial state, enhancing test reliability.

protocol/x/listing/keeper/listing.go (3)

5-6: Imports added are appropriate.

The addition of "math/big" is necessary for handling big integer operations used in the deposit calculations.


7-9: New imports for vault and subaccount types are correctly added.

The imports of vaulttypes and satypes are needed for interacting with vault functionalities and subaccount identifiers.


109-109: Properly setting the ClobPair before creating structures.

Adding k.ClobKeeper.SetClobPair(ctx, clobPair) ensures that the clob pair is stored in the keeper before creating associated structures. This is important for maintaining consistency within the clob module.

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

281-295: LGTM!

The added assertions correctly verify the clob pair's properties when in deliverTx mode.

proto/dydxprotocol/listing/genesis.proto Outdated Show resolved Hide resolved
protocol/x/listing/types/params.go Outdated Show resolved Hide resolved
protocol/x/vault/keeper/params.go Outdated Show resolved Hide resolved
protocol/x/listing/types/expected_keepers.go Outdated Show resolved Hide resolved
protocol/x/listing/keeper/listing.go Outdated Show resolved Hide resolved
protocol/x/listing/keeper/listing.go Outdated Show resolved Hide resolved
protocol/x/listing/keeper/listing.go Outdated Show resolved Hide resolved
protocol/x/listing/keeper/listing.go Show resolved Hide resolved
protocol/x/listing/keeper/listing_test.go Outdated Show resolved Hide resolved
Signed-off-by: Shrenuj Bansal <[email protected]>
Signed-off-by: Shrenuj Bansal <[email protected]>
@shrenujb shrenujb added the pml permissionless market listing label Sep 26, 2024
@shrenujb shrenujb merged commit 5d082e2 into main Sep 26, 2024
22 checks passed
@shrenujb shrenujb deleted the tra617 branch September 26, 2024 19:24
@shrenujb
Copy link
Contributor Author

shrenujb commented Oct 2, 2024

@Mergifyio backport release/protocol/v7.x

Copy link
Contributor

mergify bot commented Oct 2, 2024

backport release/protocol/v7.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Oct 2, 2024
Signed-off-by: Shrenuj Bansal <[email protected]>
(cherry picked from commit 5d082e2)
shrenujb added a commit that referenced this pull request Oct 2, 2024
adamfraser pushed a commit that referenced this pull request Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pml permissionless market listing protocol
Development

Successfully merging this pull request may close these issues.

2 participants