Skip to content

[ENG-159] Script to auto launch markets #2938

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Kefancao
Copy link
Contributor

@Kefancao Kefancao commented Jun 23, 2025

Changelist

ENG-159

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 script to automate syncing and launching new markets on the blockchain testnet environment.
    • Script ensures necessary user permissions, compares mainnet and testnet markets, and adds missing markets to the testnet.
    • Supports configuration via command-line arguments for node URL, chain ID, and the number of markets to add.
    • Provides automated handling of governance approvals and market creation steps.

Copy link
Contributor

coderabbitai bot commented Jun 23, 2025

"""

Walkthrough

A new Python script was introduced to automate the synchronization and launch of blockchain markets on a testnet. The script manages authority assignment, market map comparison between mainnet and testnet, governance proposal handling, and market creation, all via command-line interactions. Several helper functions and a command-line interface were added.

Changes

File(s) Change Summary
protocol/scripts/markets/launch_markets.py Added a script to automate syncing and launching markets on testnet, including authority management, governance proposal handling, market map querying and comparison, and market creation logic. Introduced multiple helper functions and a CLI interface.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script
    participant Blockchain CLI
    participant Mainnet Node
    participant Testnet Node

    User->>Script: Run script with arguments
    Script->>Blockchain CLI: Query authorities
    alt Alice not authority
        Script->>Blockchain CLI: Submit proposal to add Alice
        Script->>Blockchain CLI: Vote "yes" on proposal
        Script->>Blockchain CLI: Wait for proposal to pass
    end
    Script->>Mainnet Node: Download mainnet market map
    Script->>Testnet Node: Download testnet market map
    Script->>Script: Compare market maps
    loop For each missing market (up to limit)
        Script->>Blockchain CLI: Add market to testnet
        Script->>Blockchain CLI: Wait for confirmation
        Script->>Blockchain CLI: Launch market on listing module
    end
Loading

Poem

In burrows deep, a script was spun,
To sync the markets, one by one.
Alice gains her seat with cheer,
Mainnet whispers, testnet hears—
With every hop, a market grows,
Blockchain magic, as the rabbit knows!
🐇✨
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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: 10

🧹 Nitpick comments (5)
protocol/scripts/markets/launch_markets.py (5)

10-10: Remove unused imports

The imports sys and List are not used in the code.

-import sys
 import tempfile
 import yaml
 import json
-from typing import Dict, Any, List
+from typing import Dict, Any

Also applies to: 14-14


17-21: Consider making hardcoded values configurable

Hardcoded addresses and endpoints reduce flexibility and maintainability. Consider moving these to configuration parameters or environment variables.

Consider implementing a configuration approach:

# Option 1: Environment variables
alice_address = os.getenv("ALICE_ADDRESS", "dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4")
bob_address = os.getenv("BOB_ADDRESS", "dydx10fx7sy6ywd5senxae9dwytf8jxek3t2gcen2vs")
mainnet_node = os.getenv("MAINNET_NODE", "https://dydx-ops-rpc.kingnodes.com:443")
mainnet_chain = os.getenv("MAINNET_CHAIN", "dydx-mainnet-1")

# Option 2: Configuration file
# Load from config.json or config.yaml

144-164: Consider logging errors instead of printing

The function handles errors well, but consider using Python's logging module for better error tracking.

import logging

def load_yml(file_path) -> Dict[str, Any]:
    """
    Loads any yml file and returns the data as a dictionary.
    
    Args:
        file_path: Path to the yml file
        
    Returns:
        Dictionary containing the parsed data
    """
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            data = yaml.safe_load(file)
        return data
    except FileNotFoundError:
        logging.error(f"File '{file_path}' not found.")
        return {}
    except yaml.YAMLError as e:
        logging.error(f"Error parsing YAML file: {e}")
        return {}

259-259: Fix misleading comment

The comment mentions "bob" but the --from parameter is "alice".

-                        "--from=alice", # bob has a decent amount of native tokens in subaccount 0 for gas. 
+                        "--from=alice",

1-286: Consider adding structured logging and configuration management

The script would benefit from:

  1. Using Python's logging module instead of print statements
  2. Implementing a configuration class or using a config file for all constants
  3. Adding a --dry-run option to preview actions without executing them
  4. Consider breaking down the main function into smaller, testable functions

Would you like me to help implement a more robust configuration and logging system for this script?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 883afc1 and 2f75ea7.

📒 Files selected for processing (1)
  • protocol/scripts/markets/launch_markets.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
protocol/scripts/markets/launch_markets.py

10-10: sys imported but unused

Remove unused import: sys

(F401)


14-14: typing.List imported but unused

Remove unused import: typing.List

(F401)

🪛 Flake8 (7.2.0)
protocol/scripts/markets/launch_markets.py

[error] 10-10: 'sys' imported but unused

(F401)


[error] 14-14: 'typing.List' imported but unused

(F401)


[error] 22-22: expected 2 blank lines, found 1

(E302)


[error] 36-36: expected 2 blank lines, found 1

(E302)


[error] 54-54: expected 2 blank lines, found 1

(E302)


[error] 144-144: expected 2 blank lines, found 1

(E302)


[error] 165-165: expected 2 blank lines, found 1

(E302)


[error] 191-191: expected 2 blank lines, found 1

(E302)


[error] 206-206: expected 2 blank lines, found 1

(E302)


[error] 259-259: at least two spaces before inline comment

(E261)


[error] 284-284: expected 2 blank lines after class or function definition, found 1

(E305)

🪛 Pylint (3.3.7)
protocol/scripts/markets/launch_markets.py

[refactor] 138-142: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)

⏰ Context from checks skipped due to timeout of 90000ms (28)
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-ecs-service-roundtable / (roundtable) Build and Push
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-vulcan / (vulcan) Build and Push
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-bazooka-lambda / (bazooka) Build and Push Lambda
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-auxo-lambda / (auxo) Build and Push Lambda
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-ecs-service-socks / (socks) Build and Push
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-ecs-service-comlink / (comlink) Build and Push
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-ecs-service-ender / (ender) Build and Push
  • GitHub Check: benchmark
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-auxo-lambda / (auxo) Build and Push Lambda
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-ecs-service-roundtable / (roundtable) Build and Push
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-vulcan / (vulcan) Build and Push
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-bazooka-lambda / (bazooka) Build and Push Lambda
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-ecs-service-socks / (socks) Build and Push
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-ecs-service-ender / (ender) Build and Push
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-ecs-service-comlink / (comlink) Build and Push
  • GitHub Check: build
  • GitHub Check: build-and-push-mainnet
  • GitHub Check: check-sample-pregenesis-up-to-date
  • GitHub Check: container-tests
  • GitHub Check: build-and-push-testnet
  • GitHub Check: golangci-lint
  • GitHub Check: test-coverage-upload
  • GitHub Check: unit-end-to-end-and-integration
  • GitHub Check: test-race
  • GitHub Check: liveness-test
  • GitHub Check: Summary

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

♻️ Duplicate comments (6)
protocol/scripts/markets/launch_markets.py (6)

23-35: Improve subprocess handling and eliminate temporary file usage.

This function still uses the inefficient temporary file approach and lacks error handling that was flagged in previous reviews.


77-95: Address hardcoded governance values.

The authority proposal still contains hardcoded addresses and deposit amounts that should be moved to constants as flagged in previous reviews.


170-194: Add error handling for subprocess commands.

The subprocess calls still lack error handling as flagged in previous reviews.


196-209: Remove debug output and add safe dictionary access.

The function still contains debug print statements and unsafe nested dictionary access as flagged in previous reviews.


238-239: Use command line arguments instead of hardcoded values.

The subprocess commands still use hardcoded node and chain-id values instead of the provided arguments, as flagged in previous reviews.

Also applies to: 266-267


283-285: Improve exception handling specificity.

The broad exception handling catches all exceptions which can mask programming errors, as flagged in previous reviews.

🧹 Nitpick comments (2)
protocol/scripts/markets/launch_markets.py (2)

10-10: Remove unused imports.

The sys and typing.List imports are not used in the code and should be removed for cleaner code.

-import sys
-from typing import Dict, Any, List
+from typing import Dict, Any

Also applies to: 14-14


23-23: Fix PEP8 formatting issues.

Multiple PEP8 formatting violations detected:

  • Missing blank lines between function definitions
  • Insufficient spacing before inline comments
  • Missing blank lines after class/function definitions

Consider running a code formatter like black or autopep8 to automatically fix these formatting issues.

Also applies to: 37-37, 57-57, 149-149, 170-170, 196-196, 211-211, 265-265, 291-291

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f75ea7 and a720356.

📒 Files selected for processing (1)
  • protocol/scripts/markets/launch_markets.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
protocol/scripts/markets/launch_markets.py

10-10: sys imported but unused

Remove unused import: sys

(F401)


14-14: typing.List imported but unused

Remove unused import: typing.List

(F401)

🪛 Flake8 (7.2.0)
protocol/scripts/markets/launch_markets.py

[error] 10-10: 'sys' imported but unused

(F401)


[error] 14-14: 'typing.List' imported but unused

(F401)


[error] 23-23: expected 2 blank lines, found 1

(E302)


[error] 37-37: expected 2 blank lines, found 1

(E302)


[error] 57-57: expected 2 blank lines, found 1

(E302)


[error] 149-149: expected 2 blank lines, found 1

(E302)


[error] 170-170: expected 2 blank lines, found 1

(E302)


[error] 196-196: expected 2 blank lines, found 1

(E302)


[error] 211-211: expected 2 blank lines, found 1

(E302)


[error] 265-265: at least two spaces before inline comment

(E261)


[error] 291-291: expected 2 blank lines after class or function definition, found 1

(E305)

🪛 Pylint (3.3.7)
protocol/scripts/markets/launch_markets.py

[refactor] 143-147: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 221-289: Too many nested blocks (6/5)

(R1702)

⏰ Context from checks skipped due to timeout of 90000ms (27)
  • GitHub Check: benchmark
  • GitHub Check: check-sample-pregenesis-up-to-date
  • GitHub Check: test-race
  • GitHub Check: test-coverage-upload
  • GitHub Check: unit-end-to-end-and-integration
  • GitHub Check: liveness-test
  • GitHub Check: container-tests
  • GitHub Check: build
  • GitHub Check: golangci-lint
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-auxo-lambda / (auxo) Build and Push Lambda
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-ecs-service-socks / (socks) Build and Push
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-vulcan / (vulcan) Build and Push
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-ecs-service-roundtable / (roundtable) Build and Push
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-bazooka-lambda / (bazooka) Build and Push Lambda
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-ecs-service-comlink / (comlink) Build and Push
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-ecs-service-ender / (ender) Build and Push
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-ecs-service-socks / (socks) Build and Push
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-auxo-lambda / (auxo) Build and Push Lambda
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-bazooka-lambda / (bazooka) Build and Push Lambda
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-ecs-service-roundtable / (roundtable) Build and Push
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-vulcan / (vulcan) Build and Push
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-ecs-service-comlink / (comlink) Build and Push
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-ecs-service-ender / (ender) Build and Push
  • GitHub Check: build-and-push-mainnet
  • GitHub Check: build-and-push-testnet
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (3)
protocol/scripts/markets/launch_markets.py (3)

37-55: Good error handling implementation.

The function now properly handles subprocess errors with appropriate exception raising, addressing the previous review feedback.


149-168: Well-implemented error handling.

The function properly handles file and YAML parsing errors with appropriate fallbacks and clear error messages.


291-292: Standard main execution guard.

Proper implementation of the main execution guard.

@Kefancao Kefancao changed the title Script to auto launch markets [ENG-159] Script to auto launch markets Jun 24, 2025
Copy link

linear bot commented Jun 24, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

1 participant