-
Notifications
You must be signed in to change notification settings - Fork 60
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
feat: uml diagrams & diagram generate script #266
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe recent updates introduce a new automation script for generating UML diagrams from Solidity contracts, enhancing project documentation. A corresponding dependency on Changes
Poem
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 as PR comments)
Additionally, you can add 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: 4
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files ignored due to path filters (14)
contract-class-diagrams/evm/ERC20Custody.sol.png
is excluded by!**/*.png
contract-class-diagrams/evm/Zeta.eth.sol.png
is excluded by!**/*.png
contract-class-diagrams/evm/Zeta.non-eth.sol.png
is excluded by!**/*.png
contract-class-diagrams/evm/ZetaConnector.base.sol.png
is excluded by!**/*.png
contract-class-diagrams/evm/ZetaConnector.eth.sol.png
is excluded by!**/*.png
contract-class-diagrams/evm/ZetaConnector.non-eth.sol.png
is excluded by!**/*.png
contract-class-diagrams/zevm/SystemContract.sol.png
is excluded by!**/*.png
contract-class-diagrams/zevm/Uniswap.sol.png
is excluded by!**/*.png
contract-class-diagrams/zevm/UniswapPeriphery.sol.png
is excluded by!**/*.png
contract-class-diagrams/zevm/WZETA.sol.png
is excluded by!**/*.png
contract-class-diagrams/zevm/ZRC20.sol.png
is excluded by!**/*.png
contract-class-diagrams/zevm/ZRC20New.sol.png
is excluded by!**/*.png
contract-class-diagrams/zevm/ZetaConnectorZEVM.sol.png
is excluded by!**/*.png
yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
Files selected for processing (2)
- package.json (2 hunks)
- scripts/generate_uml_diagrams.sh (1 hunks)
Additional context used
Path-based instructions (1)
scripts/generate_uml_diagrams.sh (1)
Pattern
scripts/**
: Review the Hardhat scripts for best practices.
Additional comments not posted (4)
scripts/generate_uml_diagrams.sh (2)
1-4
: LGTM!The shebang line and initial comments are appropriate and provide context for the script.
47-48
: LGTM!The script ends appropriately after processing all files in all folders.
package.json (2)
87-87
: LGTM!The new script command
generate:diagrams
appropriately executes the shell script for generating UML diagrams.
102-102
: LGTM!The new dependency
sol2uml
is appropriately added to facilitate UML diagram generation.
folders=("/evm" "/zevm") | ||
|
||
# Output directory for the flattened files | ||
output_dir="./contracts" | ||
|
||
# Directory for the class diagrams | ||
diagram_folder="./contract-class-diagrams" | ||
|
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.
Ensure the diagram folder exists.
Before processing files, ensure that the diagram folder exists to avoid potential errors.
+ # Ensure the diagram folder exists
+ mkdir -p "$diagram_folder"
folders=("/evm" "/zevm")
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.
folders=("/evm" "/zevm") | |
# Output directory for the flattened files | |
output_dir="./contracts" | |
# Directory for the class diagrams | |
diagram_folder="./contract-class-diagrams" | |
# Ensure the diagram folder exists | |
mkdir -p "$diagram_folder" | |
folders=("/evm" "/zevm") | |
# Output directory for the flattened files | |
output_dir="./contracts" | |
# Directory for the class diagrams | |
diagram_folder="./contract-class-diagrams" |
# Run the sol2uml command | ||
npx sol2uml class "$output_file" -f png -o "$diagram_folder/$folder/$base_name.png" | ||
|
||
# Remove the flattened file | ||
rm "$output_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.
Improve error handling for sol2uml command.
If the sol2uml command fails, consider exiting the script or retrying the command.
npx sol2uml class "$output_file" -f png -o "$diagram_folder/$folder/$base_name.png"
# Check if the command was successful
if [ $? -eq 0 ]; then
echo "Successfully generated UML diagram for $file"
else
echo "Error generating UML diagram for $file"
+ exit 1
fi
# Remove the flattened file
rm "$output_file"
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.
# Run the sol2uml command | |
npx sol2uml class "$output_file" -f png -o "$diagram_folder/$folder/$base_name.png" | |
# Remove the flattened file | |
rm "$output_file" | |
# Run the sol2uml command | |
npx sol2uml class "$output_file" -f png -o "$diagram_folder/$folder/$base_name.png" | |
# Check if the command was successful | |
if [ $? -eq 0 ]; then | |
echo "Successfully generated UML diagram for $file" | |
else | |
echo "Error generating UML diagram for $file" | |
exit 1 | |
fi | |
# Remove the flattened file | |
rm "$output_file" |
|
||
# Get the base name of the file (without path) | ||
base_name=$(basename "$file") | ||
echo "Processing file: $file" | ||
|
||
# Construct the output file path | ||
output_file="$output_dir/Flattened_$base_name" | ||
|
||
# Run the flatten command | ||
npx hardhat flatten "$file" > "$output_file" | ||
|
||
# Check if the command was successful | ||
if [ $? -eq 0 ]; then | ||
echo "Successfully flattened $file to $output_file" | ||
else | ||
echo "Error flattening $file" | ||
fi |
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.
Improve error handling for flatten command.
If the flatten command fails, consider exiting the script or retrying the command.
npx hardhat flatten "$file" > "$output_file"
# Check if the command was successful
if [ $? -eq 0 ]; then
echo "Successfully flattened $file to $output_file"
else
echo "Error flattening $file"
+ exit 1
fi
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.
# Get the base name of the file (without path) | |
base_name=$(basename "$file") | |
echo "Processing file: $file" | |
# Construct the output file path | |
output_file="$output_dir/Flattened_$base_name" | |
# Run the flatten command | |
npx hardhat flatten "$file" > "$output_file" | |
# Check if the command was successful | |
if [ $? -eq 0 ]; then | |
echo "Successfully flattened $file to $output_file" | |
else | |
echo "Error flattening $file" | |
fi | |
# Get the base name of the file (without path) | |
base_name=$(basename "$file") | |
echo "Processing file: $file" | |
# Construct the output file path | |
output_file="$output_dir/Flattened_$base_name" | |
# Run the flatten command | |
npx hardhat flatten "$file" > "$output_file" | |
# Check if the command was successful | |
if [ $? -eq 0 ]; then | |
echo "Successfully flattened $file to $output_file" | |
else | |
echo "Error flattening $file" | |
exit 1 | |
fi |
# Loop through all .sol files in the contracts_dir | ||
for folder in "${folders[@]}"; do | ||
contracts_dir="$baseFolder$folder" | ||
echo "Processing folder: $contracts_dir" | ||
|
||
for file in "$contracts_dir"/*.sol; do | ||
# Check if any .sol files exist in the directory | ||
if [[ ! -e "$file" ]]; then | ||
echo "No .sol files found in $contracts_dir" | ||
continue | ||
fi |
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.
Handle cases where no .sol files are found more gracefully.
Instead of continuing silently, consider exiting the script or skipping to the next folder if no .sol files are found.
if [[ ! -e "$file" ]]; then
echo "No .sol files found in $contracts_dir"
+ break
continue
fi
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.
# Loop through all .sol files in the contracts_dir | |
for folder in "${folders[@]}"; do | |
contracts_dir="$baseFolder$folder" | |
echo "Processing folder: $contracts_dir" | |
for file in "$contracts_dir"/*.sol; do | |
# Check if any .sol files exist in the directory | |
if [[ ! -e "$file" ]]; then | |
echo "No .sol files found in $contracts_dir" | |
continue | |
fi | |
# Loop through all .sol files in the contracts_dir | |
for folder in "${folders[@]}"; do | |
contracts_dir="$baseFolder$folder" | |
echo "Processing folder: $contracts_dir" | |
for file in "$contracts_dir"/*.sol; do | |
# Check if any .sol files exist in the directory | |
if [[ ! -e "$file" ]]; then | |
echo "No .sol files found in $contracts_dir" | |
break | |
continue | |
fi |
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.
Hey @mikelord007, thank you very much working on this.
To give some updates on the development. We decided to separate the codebase into v1 and v2: #268
We're mostly interested in v2 for the diagrams but we also decided to switch from Hardhat to Foundry for it. Do you have a similar solution for diagram generation using Foundry suite?
Hey @lumtis I don't think there is a tool in foundry that can do the same. |
Summary by CodeRabbit
New Features
Dependencies
sol2uml
) to support UML diagram generation, enriching the functionality related to Solidity contracts.