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

Add a cli method for vault withdrawal #2369

Merged
merged 20 commits into from
Sep 26, 2024
Merged

Conversation

shrenujb
Copy link
Contributor

@shrenujb shrenujb commented Sep 26, 2024

Changelist

Add a cli method for vault withdrawal

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.

Summary by CodeRabbit

  • New Features

    • Introduced a new command to the CLI for withdrawing shares from a megavault.
    • Added a branch trigger for the GitHub Actions workflow.
  • Bug Fixes

    • Adjusted the calculation logic for atomicResolution to incorporate decimal precision.
  • Tests

    • Updated test cases to reflect changes in decimal precision and expected resolution values.

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]>
Signed-off-by: Shrenuj Bansal <[email protected]>
@shrenujb shrenujb requested a review from a team as a code owner September 26, 2024 17:55
Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

Walkthrough

This pull request introduces several changes across multiple files. A new branch trigger tra617 is added to the GitHub Actions workflow for build and push events. The calculation of the atomicResolution variable in the CreatePerpetual function is modified to include the ticker's decimal precision. Additionally, the CLI for the vault client is enhanced with a new command, CmdWithdrawFromMegavault, enabling users to withdraw shares from a megavault.

Changes

File Change Summary
.github/workflows/protocol-build-and-push.yml Added a new branch trigger tra617 to the workflow configuration.
protocol/x/listing/keeper/listing.go Modified the calculation of atomicResolution in the CreatePerpetual function to include ticker decimals.
protocol/x/listing/keeper/listing_test.go Updated the TestCreatePerpetual function to reflect changes in Decimals and the expected value for AtomicResolution.
protocol/x/vault/client/cli/tx.go Added CmdWithdrawFromMegavault command to allow users to withdraw shares from a megavault with error handling.

Possibly related PRs

Suggested reviewers

  • vincentwschau
  • tqin7

Poem

In the code where bunnies hop,
New triggers bloom, and changes pop.
With vaults and resolutions bright,
We code by day and dream by night.
Hooray for updates, swift and true,
A rabbit's cheer for all we do! 🐇✨


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

🧹 Outside diff range and nitpick comments (3)
protocol/x/vault/client/cli/tx.go (1)

248-297: Consider checking name consistency

The function is named CmdWithdrawFromVault, but it creates a MsgWithdrawFromMegavault message. This inconsistency might be confusing. Consider aligning the names or adding a comment explaining the difference if it's intentional.

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

Line range hint 1-324: Overall assessment of changes in listing.go

The primary change in this file is the modification of the atomicResolution calculation in the CreatePerpetual function. While this change appears to improve precision by accounting for the ticker's decimal places, it's crucial to ensure that this modification aligns with the overall system design and doesn't introduce unintended consequences.

Additional considerations:

  1. Update relevant documentation to reflect this change in atomic resolution calculation.
  2. Consider adding unit tests specifically for this new calculation, covering various decimal precision scenarios.
  3. Evaluate if any other parts of the system (e.g., order books, price feeds) need adjustments to accommodate this change.
  4. Assess the potential impact on gas costs if this calculation is performed frequently.

Given the importance of price resolution in a financial system, consider implementing a comprehensive suite of integration tests that verify the entire lifecycle of a perpetual, from creation to trading and settlement, using this new atomic resolution calculation.

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

188-189: Approved: AtomicResolution adjustment and explanation.

The change in the expected AtomicResolution value from -15 to -5 is consistent with the increase in the Decimals field. The added comment clearly explains the calculation:

// Expected resolution = -6 - (Floor(log10(1000000000))+10) = -5

This adjustment ensures that the test remains accurate with the new precision level.

Consider slightly expanding the comment for even more clarity:

// Expected resolution = -Exponent - (Floor(log10(ReferencePrice)) + Decimals)
//                     = -6 - (Floor(log10(1000000000)) + 10) = -5

This expanded comment explicitly shows where each value in the calculation comes from, making it easier for future developers to understand the logic.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 59b6b7a and 37754e3.

📒 Files selected for processing (4)
  • .github/workflows/protocol-build-and-push.yml (1 hunks)
  • protocol/x/listing/keeper/listing.go (1 hunks)
  • protocol/x/listing/keeper/listing_test.go (2 hunks)
  • protocol/x/vault/client/cli/tx.go (2 hunks)
🔇 Additional comments (6)
.github/workflows/protocol-build-and-push.yml (1)

6-6: Approved, but clarification needed on the purpose of the new branch trigger.

The addition of the 'tra617' branch to the workflow trigger looks correct. However, could you please clarify the purpose of this new branch trigger? Is it related to the CLI method for vault withdrawal mentioned in the PR objectives?

To ensure this branch exists and contains relevant changes, please run:

protocol/x/vault/client/cli/tx.go (3)

33-33: LGTM: New command added correctly

The new CmdWithdrawFromVault command is correctly added to the list of commands in the GetTxCmd function. This addition aligns with the PR objective of introducing a CLI method for vault withdrawal.


248-297: LGTM: New CmdWithdrawFromVault function implemented correctly

The implementation of CmdWithdrawFromVault follows the established pattern for CLI commands in this module. It correctly handles argument parsing, message creation, and transaction broadcasting.


248-297: Reminder: Add tests for the new command

The PR objectives mention an empty test plan. As this is a new feature, it's crucial to have comprehensive tests to ensure its correctness and prevent regressions. Please add appropriate unit tests for this new command.

To help with test coverage, you can run the following command to check for existing tests and identify gaps:

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

151-154: Verify the impact of the atomic resolution calculation change.

The modification to the atomicResolution calculation now incorporates the ticker's decimal precision. This change appears to aim for a more accurate representation of the perpetual's price resolution.

However, please address the following points:

  1. Can you provide more context on why this change was necessary?
  2. How does this affect existing perpetuals, if at all?
  3. Have you considered any potential edge cases, especially for tickers with extreme decimal values?
  4. Are there any implications for order placement, matching, or settlement that need to be addressed in other parts of the system?

To ensure this change doesn't introduce any inconsistencies, please run the following verification:

This script will help identify any areas of the codebase that might need adjustment due to this change in atomic resolution calculation.

✅ Verification successful

Atomic resolution calculation change verified successfully.

  • No hardcoded atomic resolution values or conflicting constants found.
  • Incorporating ticker's decimal precision does not introduce inconsistencies.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any hardcoded atomic resolution values or assumptions in the codebase that might conflict with this new calculation.

# Test: Search for hardcoded atomic resolution values or related constants
rg --type go -e 'atomicResolution\s*:=\s*\d+' -e 'const\s+.*Resolution.*=\s*\d+'

# Test: Look for any other usage of ResolutionOffset to ensure consistency
rg --type go 'ResolutionOffset'

# Test: Check for any price-related calculations that might be affected by this change
rg --type go -e 'price.*calculation' -e 'calculate.*price'

Length of output: 5640

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

155-155: Please clarify the reason for increasing the Decimals value.

The Decimals field in the Ticker struct has been changed from 6 to 10. This increases the precision of the currency pair significantly. Could you please explain:

  1. Why was this change necessary?
  2. What are the implications of this change on the test cases and the system in general?
  3. Are there any other parts of the codebase that need to be updated to accommodate this change?
✅ Verification successful

Verification Successful: The change to the Decimals field is isolated to listing_test.go and does not affect other parts of the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of Decimals field in Ticker structs
rg --type go 'Ticker\s*{[^}]*Decimals:\s*\d+' .

Length of output: 172


Script:

#!/bin/bash
# Corrected search for other occurrences of Decimals field in Ticker structs
rg --type go 'Ticker\s*\{\s*[^}]*Decimals:\s*\d+' .

Length of output: 53


Script:

#!/bin/bash
# Using ast-grep to find all Decimals field definitions within Ticker structs
ast-grep --lang go --pattern 'Ticker { $$$ Decimals: $_, $$$ }' .

Length of output: 67

Comment on lines +259 to +276
// Parse withdrawer owner and number
withdrawerOwner := args[0]
withdrawerNumber, err := cast.ToUint32E(args[1])
if err != nil {
return err
}

// Parse shares.
shares, err := cast.ToUint64E(args[2])
if err != nil {
return err
}

// Parse min quote quantums.
minQuoteQuantums, err := cast.ToUint64E(args[3])
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding more input validation

While the current implementation checks for type correctness, consider adding more validation for the input values. For example, you might want to ensure that shares and minQuoteQuantums are non-zero, or that withdrawerNumber is within a valid range.

Signed-off-by: Shrenuj Bansal <[email protected]>
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/x/vault/client/cli/tx.go (1)

248-297: Overall structure and implementation look good

The new CmdWithdrawFromMegavault function is well-structured and consistent with other command implementations in this file. It correctly handles argument parsing, message creation, and transaction broadcasting/generation.

Consider enhancing input validation

While the current implementation checks for type correctness, consider adding more validation for the input values:

  1. Ensure that shares and minQuoteQuantums are non-zero.
  2. Add checks for potential overflow when converting to uint64.

Example implementation:

shares, err := cast.ToUint64E(args[2])
if err != nil {
    return fmt.Errorf("invalid shares value: %w", err)
}
if shares == 0 {
    return fmt.Errorf("shares must be greater than zero")
}

// Similar checks for minQuoteQuantums

Improve error messages for better user experience

Consider providing more descriptive error messages when parsing fails. This will help users understand and correct their input more easily.

Example:

withdrawerNumber, err := cast.ToUint32E(args[1])
if err != nil {
    return fmt.Errorf("invalid withdrawer number '%s': %w", args[1], err)
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 37754e3 and c012711.

📒 Files selected for processing (1)
  • protocol/x/vault/client/cli/tx.go (2 hunks)
🔇 Additional comments (1)
protocol/x/vault/client/cli/tx.go (1)

33-33: LGTM: New command added correctly

The new CmdWithdrawFromMegavault command is correctly added to the list of commands in the GetTxCmd function. This addition is consistent with the existing pattern and allows the new functionality to be accessible through the CLI.

@shrenujb shrenujb merged commit 53258cb into main Sep 26, 2024
21 checks passed
@shrenujb shrenujb deleted the sbansal/vault-withdraw-cli branch September 26, 2024 20:06
@tqin7
Copy link
Contributor

tqin7 commented Sep 27, 2024

@Mergifyio backport release/protocol/v7.x

Copy link
Contributor

mergify bot commented Sep 27, 2024

backport release/protocol/v7.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Sep 27, 2024
Signed-off-by: Shrenuj Bansal <[email protected]>
(cherry picked from commit 53258cb)
tqin7 pushed a commit that referenced this pull request Sep 27, 2024
@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

@shrenujb shrenujb added the pml permissionless market listing label 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.

3 participants