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

feat: uml diagrams & diagram generate script #266

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contract-class-diagrams/evm/Zeta.eth.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contract-class-diagrams/zevm/Uniswap.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contract-class-diagrams/zevm/WZETA.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contract-class-diagrams/zevm/ZRC20.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contract-class-diagrams/zevm/ZRC20New.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"coverage": "forge clean && cross-env FOUNDRY_SRC='contracts/prototypes' forge coverage --report lcov",
"docs": "forge doc",
"generate": "yarn compile && ./scripts/generate_go.sh || true && ./scripts/generate_addresses.sh && yarn lint:fix",
"generate:diagrams": "./scripts/generate_uml_diagrams.sh",
"lint": "npx eslint . --ext .js,.ts --ignore-pattern lib/",
"lint:fix": "npx eslint . --ext .js,.ts,.json --fix --ignore-pattern coverage/ --ignore-pattern coverage.json --ignore-pattern lib/ --ignore-pattern out --ignore-pattern cache_forge/",
"lint:sol": "solhint 'contracts/**/*.sol'",
Expand All @@ -96,5 +97,8 @@
"worker": "npx hardhat run scripts/worker.ts --network localhost"
},
"types": "./dist/lib/index.d.ts",
"version": "0.0.8"
"version": "0.0.8",
"dependencies": {
"sol2uml": "^2.5.20"
}
}
48 changes: 48 additions & 0 deletions scripts/generate_uml_diagrams.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Directory containing the .sol files
baseFolder="./contracts"
folders=("/evm" "/zevm")

# Output directory for the flattened files
output_dir="./contracts"

# Directory for the class diagrams
diagram_folder="./contract-class-diagrams"

Comment on lines +5 to +12
Copy link
Contributor

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.

Suggested change
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"

# 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
Comment on lines +13 to +23
Copy link
Contributor

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.

Suggested change
# 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


# 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
Comment on lines +24 to +40
Copy link
Contributor

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.

Suggested change
# 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


# 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"
Comment on lines +42 to +46
Copy link
Contributor

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.

Suggested change
# 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"

done
done
710 changes: 667 additions & 43 deletions yarn.lock

Large diffs are not rendered by default.