-
Notifications
You must be signed in to change notification settings - Fork 19
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
Prepare submission proxy deployment #2316
Prepare submission proxy deployment #2316
Conversation
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (13)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including You can disable this status message by setting the 📝 Walkthrough📝 WalkthroughWalkthroughThe pull request introduces a new Python script, Changes
Possibly related PRs
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (1)
contracts/v0.2/script/prepare-submission-proxy-migration.py (1)
1-75
: Consider adding documentation for migration processAs this script is part of a larger contract migration system, consider:
- Adding a module docstring explaining the script's role in the migration process
- Documenting the expected format of input data and generated migration files
- Adding examples of usage in the documentation
This will help other developers understand how to use the script correctly in the deployment workflow.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (15)
contracts/v0.2/addresses/baobab/SubmissionProxy.json
is excluded by!**/*.json
contracts/v0.2/addresses/others-addresses.json
is excluded by!**/*.json
contracts/v0.2/deployments/Feed.s.sol/1001/run-1731394623.json
is excluded by!**/*.json
contracts/v0.2/deployments/Feed.s.sol/1001/run-1731394630.json
is excluded by!**/*.json
contracts/v0.2/deployments/Feed.s.sol/1001/run-1731394636.json
is excluded by!**/*.json
contracts/v0.2/deployments/Feed.s.sol/1001/run-latest.json
is excluded by!**/*.json
contracts/v0.2/deployments/SubmissionProxy.s.sol/1001/run-1731394146.json
is excluded by!**/*.json
contracts/v0.2/deployments/SubmissionProxy.s.sol/1001/run-1731394152.json
is excluded by!**/*.json
contracts/v0.2/deployments/SubmissionProxy.s.sol/1001/run-latest.json
is excluded by!**/*.json
contracts/v0.2/migration/baobab/Feed/20241112155555_update.json
is excluded by!**/*.json
contracts/v0.2/migration/baobab/Feed/migration.lock
is excluded by!**/*.lock
,!**/*.lock
contracts/v0.2/migration/baobab/SubmissionProxy/20241112153831_update.json
is excluded by!**/*.json
contracts/v0.2/migration/baobab/SubmissionProxy/migration.lock
is excluded by!**/*.lock
,!**/*.lock
contracts/v0.2/migration/cypress/Feed/20241112155823_update.json
is excluded by!**/*.json
contracts/v0.2/migration/cypress/SubmissionProxy/20241112154038_update.json
is excluded by!**/*.json
📒 Files selected for processing (1)
contracts/v0.2/script/prepare-submission-proxy-migration.py
(1 hunks)
🔇 Additional comments (2)
contracts/v0.2/script/prepare-submission-proxy-migration.py (2)
74-75
: LGTM!
The entry point implementation follows the standard Python pattern.
29-42
:
Add type hints and handle empty submitter field
The function lacks type hints and the empty submitter field could cause issues downstream.
-def prepareForFeed(data, network):
+def prepareForFeed(data: dict, network: str) -> dict:
+ """Prepare feed migration data.
+
+ Args:
+ data: Dictionary containing network data
+ network: Target network name
+
+ Returns:
+ Dictionary containing submitter and feed addresses
+
+ Raises:
+ KeyError: If required keys are missing in the data
+ """
entries = []
for _, networks in data.items():
+ if not isinstance(networks, dict):
+ raise ValueError(f"Invalid network data structure")
for key, item in networks.items():
if key == network:
+ if "feed" not in item:
+ raise KeyError(f"Missing 'feed' key in {network}")
entries.append(item["feed"])
+
+ if not entries:
+ raise ValueError(f"No feed addresses found for network {network}")
+
result = {
"updateSubmitter": {
- "submitter": "",
+ "submitter": None, # TODO: This needs to be set to a valid address
"feedAddresses": entries
}
}
return result
Let's verify if the submitter address is required:
import os | ||
from datetime import datetime | ||
|
||
file_path = "./addresses/datafeeds-addresses.json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve path handling for better portability
The hardcoded file path with forward slashes might cause issues on Windows systems. Consider using os.path.join()
for platform-independent path handling.
-file_path = "./addresses/datafeeds-addresses.json"
+file_path = os.path.join("addresses", "datafeeds-addresses.json")
Committable suggestion skipped: line range outside the PR's diff.
def prepareForSubmissionProxy(data, network): | ||
entries = [] | ||
for symbol, networks in data.items(): | ||
name = symbol | ||
for key, item in networks.items(): | ||
if key == network: | ||
entries.append({ | ||
"name": name, | ||
"address": item["feed"] | ||
}) | ||
|
||
result = { | ||
"deploy": {}, | ||
"addOracle": { | ||
"oracles": [] | ||
}, | ||
"updateFeed": entries | ||
} | ||
|
||
return result | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add type hints and error handling
The function lacks type hints and proper error handling for malformed input data. Also, some fields in the result dictionary are empty.
-def prepareForSubmissionProxy(data, network):
+def prepareForSubmissionProxy(data: dict, network: str) -> dict:
+ """Prepare submission proxy migration data.
+
+ Args:
+ data: Dictionary containing network data
+ network: Target network name
+
+ Returns:
+ Dictionary containing deployment and oracle information
+
+ Raises:
+ KeyError: If required keys are missing in the data
+ """
entries = []
for symbol, networks in data.items():
+ if not isinstance(networks, dict):
+ raise ValueError(f"Invalid network data for symbol {symbol}")
name = symbol
for key, item in networks.items():
if key == network:
+ if "feed" not in item:
+ raise KeyError(f"Missing 'feed' key for {symbol} in {network}")
entries.append({
"name": name,
"address": item["feed"]
})
Committable suggestion skipped: line range outside the PR's diff.
def main(): | ||
with open(file_path, "r") as f: | ||
data = json.load(f) | ||
|
||
parser = argparse.ArgumentParser(description="parse args") | ||
parser.add_argument('--network', type=str, default="baobab") | ||
parser.add_argument('--contract', type=str, default="SubmissionProxy") | ||
|
||
args = parser.parse_args() | ||
network = args.network | ||
contract = args.contract | ||
|
||
if contract == "SubmissionProxy": | ||
result = prepareForSubmissionProxy(data, network) | ||
elif contract == "Feed": | ||
result = prepareForFeed(data, network) | ||
else: | ||
raise ValueError("Invalid contract name") | ||
|
||
timestamp = datetime.now().strftime('%Y%m%d%H%M%S') | ||
|
||
# Create the file path with the timestamp | ||
write_file_path = f"./migration/{network}/{contract}/{timestamp}_update.json" | ||
|
||
# Ensure the directories exist | ||
os.makedirs(os.path.dirname(write_file_path), exist_ok=True) | ||
|
||
with open(write_file_path, 'w') as file: | ||
json.dump(result, file, indent=2) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add network validation and improve error handling
The function needs network validation and better error handling for file operations.
def main():
- with open(file_path, "r") as f:
- data = json.load(f)
+ try:
+ with open(file_path, "r") as f:
+ data = json.load(f)
+ except FileNotFoundError:
+ raise FileNotFoundError(f"Data file not found: {file_path}")
+ except json.JSONDecodeError:
+ raise ValueError(f"Invalid JSON format in {file_path}")
parser = argparse.ArgumentParser(description="parse args")
- parser.add_argument('--network', type=str, default="baobab")
+ parser.add_argument('--network', type=str, default="baobab",
+ choices=['baobab', 'cypress'], # Add all valid networks
+ help="Target network for migration")
parser.add_argument('--contract', type=str, default="SubmissionProxy")
args = parser.parse_args()
network = args.network
contract = args.contract
+ valid_contracts = ["SubmissionProxy", "Feed"]
+ if contract not in valid_contracts:
+ raise ValueError(f"Invalid contract name. Must be one of: {valid_contracts}")
if contract == "SubmissionProxy":
result = prepareForSubmissionProxy(data, network)
elif contract == "Feed":
result = prepareForFeed(data, network)
- else:
- raise ValueError("Invalid contract name")
timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
write_file_path = f"./migration/{network}/{contract}/{timestamp}_update.json"
os.makedirs(os.path.dirname(write_file_path), exist_ok=True)
- with open(write_file_path, 'w') as file:
- json.dump(result, file, indent=2)
+ try:
+ with open(write_file_path, 'w') as file:
+ json.dump(result, file, indent=2)
+ except IOError as e:
+ raise IOError(f"Failed to write migration file: {e}")
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
def main(): | |
with open(file_path, "r") as f: | |
data = json.load(f) | |
parser = argparse.ArgumentParser(description="parse args") | |
parser.add_argument('--network', type=str, default="baobab") | |
parser.add_argument('--contract', type=str, default="SubmissionProxy") | |
args = parser.parse_args() | |
network = args.network | |
contract = args.contract | |
if contract == "SubmissionProxy": | |
result = prepareForSubmissionProxy(data, network) | |
elif contract == "Feed": | |
result = prepareForFeed(data, network) | |
else: | |
raise ValueError("Invalid contract name") | |
timestamp = datetime.now().strftime('%Y%m%d%H%M%S') | |
# Create the file path with the timestamp | |
write_file_path = f"./migration/{network}/{contract}/{timestamp}_update.json" | |
# Ensure the directories exist | |
os.makedirs(os.path.dirname(write_file_path), exist_ok=True) | |
with open(write_file_path, 'w') as file: | |
json.dump(result, file, indent=2) | |
def main(): | |
try: | |
with open(file_path, "r") as f: | |
data = json.load(f) | |
except FileNotFoundError: | |
raise FileNotFoundError(f"Data file not found: {file_path}") | |
except json.JSONDecodeError: | |
raise ValueError(f"Invalid JSON format in {file_path}") | |
parser = argparse.ArgumentParser(description="parse args") | |
parser.add_argument('--network', type=str, default="baobab", | |
choices=['baobab', 'cypress'], # Add all valid networks | |
help="Target network for migration") | |
parser.add_argument('--contract', type=str, default="SubmissionProxy") | |
args = parser.parse_args() | |
network = args.network | |
contract = args.contract | |
valid_contracts = ["SubmissionProxy", "Feed"] | |
if contract not in valid_contracts: | |
raise ValueError(f"Invalid contract name. Must be one of: {valid_contracts}") | |
if contract == "SubmissionProxy": | |
result = prepareForSubmissionProxy(data, network) | |
elif contract == "Feed": | |
result = prepareForFeed(data, network) | |
timestamp = datetime.now().strftime('%Y%m%d%H%M%S') | |
write_file_path = f"./migration/{network}/{contract}/{timestamp}_update.json" | |
os.makedirs(os.path.dirname(write_file_path), exist_ok=True) | |
try: | |
with open(write_file_path, 'w') as file: | |
json.dump(result, file, indent=2) | |
except IOError as e: | |
raise IOError(f"Failed to write migration file: {e}") |
Description
It'll be merged once both testnet and mainnet has been deployed
Type of change
Please delete options that are not relevant.
Checklist before requesting a review
Deployment