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: support vyper on contract details #1223

Merged
merged 3 commits into from
Feb 10, 2025

Conversation

evilpeach
Copy link
Collaborator

@evilpeach evilpeach commented Feb 10, 2025

Summary by CodeRabbit

  • New Features

    • Introduced Vyper support for enhanced EVM contract details.
    • Added a dedicated optimization display component to clearly present contract verification results.
    • Enhanced the code editor to dynamically adjust syntax highlighting based on the selected file’s language.
  • Refactor

    • Streamlined verification configurations and improved the file explorer’s ability to identify file languages for a more intuitive user experience.

Copy link

vercel bot commented Feb 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
celatone-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 10, 2025 10:12am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
celatone-frontend-main ⬜️ Ignored (Inspect) Visit Preview Feb 10, 2025 10:12am
initia-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 10, 2025 10:12am
neutron-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 10, 2025 10:12am
osmosis-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 10, 2025 10:12am
sei-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 10, 2025 10:12am
terra-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 10, 2025 10:12am

Copy link

coderabbitai bot commented Feb 10, 2025

Walkthrough

A new feature has been introduced to support Vyper on EVM contract details. The changelog now documents this addition. In the codebase, the editor components now derive the language from the selected file instead of a hardcoded value, and related types have been updated to include Vyper support. A new Optimizer component has been implemented to encapsulate and display optimization details in the EVM contract overview. Verification types and configurations have also been refactored and enhanced to streamline support for both Solidity and Vyper contract details.

Changes

File(s) Change Summary
CHANGELOG.md Added new feature entry for Vyper support on EVM contract details under the "Features" → "Unreleased" section.
src/lib/components/editor/FullEditor.tsx, .../types.ts, .../helpers.ts Updated editor behavior: switched from hardcoded "sol" to a dynamic language from the selected file; extended EXTENSION_LIB from ["sol"] to ["sol", "vy"]; added a new language property in source tree nodes.
src/lib/pages/evm-contract-details/.../Optimizer.tsx, .../OverviewVerifiedInfo.tsx Introduced a new Optimizer component to display optimization details. Replaced inline optimization logic in the overview component with this encapsulated component.
src/lib/services/types/verification/evm.ts Restructured verification types: added new methods/types for EVM verification configuration, source file and library info; renamed optimizer configuration to EvmOptimizerConfig; introduced support for Vyper optimizer handling.
src/lib/utils/evm.ts Modified the condition in findAndDecodeEvmConstructorArgs to check for the existence of a non-empty inputs array.

Sequence Diagram(s)

sequenceDiagram
    participant OV as OverviewVerifiedInfo
    participant OP as Optimizer
    participant LT as LabelText
    OV->>OP: Pass evmVerifyInfo
    OP->>OP: Determine type of optimizer info
    alt Optimizer is a string
        OP->>LT: Render LabelText with string value
    else Optimizer is object or undefined
        OP->>LT: Render LabelText with "Enabled/Disabled" status
    end
Loading
sequenceDiagram
    participant FE as FullEditor
    participant E as Editor
    FE->>E: Provide selectedFile (code & language)
    E->>E: Render content using dynamic language prop
Loading

Possibly related PRs

Suggested reviewers

  • songwongtp

Poem

I'm a rabbit coding with delight,
Hopping through changes in the night.
Vyper now dances with Solidity's song,
In our codebase, both now belong.
Leaping high with each clever byte—
Hooray for updates so shiny and bright!
🐇


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c7a7f56 and 4dc3a3e.

📒 Files selected for processing (3)
  • src/lib/components/editor/FullEditor.tsx (1 hunks)
  • src/lib/components/editor/helpers.ts (1 hunks)
  • src/lib/components/editor/types.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/lib/components/editor/FullEditor.tsx
  • src/lib/components/editor/types.ts
🔇 Additional comments (1)
src/lib/components/editor/helpers.ts (1)

34-34: Consider enhancing language mapping for better IDE integration.

The current implementation maps .vy files to "python" language mode, which is a good start for syntax highlighting. However, consider these improvements:

  1. Create a dedicated language mapping constant for maintainability
  2. Consider using "vyper" instead of "python" if your editor supports it
  3. Handle edge cases where extension could be undefined
+ const LANGUAGE_MAP: Record<string, string> = {
+   vy: "python", // or "vyper" if supported
+   sol: "solidity",
+   // Add other mappings as needed
+ };
+
  existingNode = {
    // ... other properties
-   language: extension === "vy" ? "python" : extension,
+   language: extension ? (LANGUAGE_MAP[extension] || extension) : undefined,
  };
✅ Verification successful

🌐 Web query:

Does Monaco Editor support Vyper syntax highlighting? What language mode should be used for Vyper files?

💡 Result:

Monaco Editor does not natively support Vyper syntax highlighting based on current implementations[1][4][10]. However, there are two potential approaches to enable Vyper support:

  1. Custom Monarch Grammar Implementation
    You would need to create a Monarch grammar configuration for Vyper using JSON rules[1][5], similar to how Apex support was added[1]. This involves:

    • Defining tokenization rules for keywords, operators, and syntax structures
    • Creating state transitions for different code contexts
    • Testing in Monaco's playground environment[1]
  2. VS Code Extension Adaptation
    While VS Code has a Vyper extension[10], Monaco uses different highlighting mechanics:

    • VS Code uses TextMate grammars with Oniguruma regex[4]
    • Browser-based Monaco requires Monarch grammars[1][4]
    • Direct porting from VS Code's TextMate grammar isn't possible without modification[4]

For language mode configuration:

monaco.languages.register({ id: 'vyper' });
monaco.languages.setMonarchTokensProvider('vyper', vyperLanguageDefinition);

Key considerations:

  • No existing open-source Vyper Monarch implementations were found in searched resources[1-10]
  • Python mode could serve as temporary fallback due to syntactic similarities[1][4]
  • Custom implementation would require deep Vyper language specification analysis[5][6]

The most robust solution involves creating a dedicated Vyper language definition using Monarch's JSON format[1][5], though this requires significant development effort. For immediate needs without custom development, using Python syntax highlighting (language: 'python') might provide partial compatibility while awaiting native support[1][4].

Citations:


Enhance language mapping to improve maintainability and future flexibility.

The current approach—mapping Vyper ("vy") files to "python"—is a valid temporary solution given that Monaco Editor does not natively support Vyper. However, for maintainability and clearer intent, consider the following improvements:

  • Use a dedicated mapping constant. This centralizes language mappings and makes future adjustments easier.
  • Handle undefined file extensions. Adding protection for cases where extension might be undefined can avoid potential issues.
  • Plan for future enhancements. While "python" serves as an acceptable fallback for now, you might later opt for a dedicated "vyper" language mode through a custom Monarch grammar implementation if improved syntax support becomes available.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

@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

🧹 Nitpick comments (3)
src/lib/pages/evm-contract-details/components/evm-contract-details-overview/Optimizer.tsx (2)

4-6: Add documentation for optimizer configurations.

Consider adding JSDoc comments to document the different optimizer configurations supported by the component.

+/**
+ * Props for the Optimizer component
+ * @property {EvmVerifyInfo} evmVerifyInfo - Contains optimizer configuration which can be:
+ * - A string value representing the optimization status
+ * - An object with enabled flag and runs count
+ */
 interface OptimizerProps {
   evmVerifyInfo: EvmVerifyInfo;
 }

8-22: Improve type safety with type predicates.

Consider using type predicates to narrow down the optimizer types for better type safety.

+type StringOptimizer = string;
+type ObjectOptimizer = { enabled: boolean; runs: number };
+
+const isStringOptimizer = (optimizer: any): optimizer is StringOptimizer =>
+  typeof optimizer === "string";
+
+const isObjectOptimizer = (optimizer: any): optimizer is ObjectOptimizer =>
+  optimizer && typeof optimizer === "object" && "enabled" in optimizer;
+
 export const Optimizer = ({ evmVerifyInfo: { optimizer } }: OptimizerProps) => {
-  if (typeof optimizer === "string") {
+  if (isStringOptimizer(optimizer)) {
     return <LabelText label="Optimization">{optimizer}</LabelText>;
   }
 
   return (
     <LabelText label="Optimization Enabled">
-      {optimizer
-        ? optimizer.enabled
+      {isObjectOptimizer(optimizer)
+        ? optimizer.enabled
           ? `Yes with ${optimizer.runs} runs`
           : "No"
         : "N/A"}
     </LabelText>
   );
 };
src/lib/pages/evm-contract-details/components/evm-contract-details-contract-info/ContractCode.tsx (1)

65-65: LGTM! Consider extracting language mapping.

The implementation correctly sets the editor language based on file extension. However, consider extracting the language mapping logic for better maintainability.

+const getEditorLanguage = (filePath: string): "python" | "sol" => {
+  const LANGUAGE_MAP: Record<string, "python" | "sol"> = {
+    ".vy": "python",
+    ".sol": "sol",
+  };
+  const ext = filePath.substring(filePath.lastIndexOf("."));
+  return LANGUAGE_MAP[ext] || "sol";
+};
+
-          editorLanguage={contractPath.endsWith(".vy") ? "python" : "sol"}
+          editorLanguage={getEditorLanguage(contractPath)}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ced1d23 and c7a7f56.

📒 Files selected for processing (8)
  • CHANGELOG.md (1 hunks)
  • src/lib/components/editor/FullEditor.tsx (2 hunks)
  • src/lib/components/editor/types.ts (1 hunks)
  • src/lib/pages/evm-contract-details/components/evm-contract-details-contract-info/ContractCode.tsx (1 hunks)
  • src/lib/pages/evm-contract-details/components/evm-contract-details-overview/Optimizer.tsx (1 hunks)
  • src/lib/pages/evm-contract-details/components/evm-contract-details-overview/OverviewVerifiedInfo.tsx (2 hunks)
  • src/lib/services/types/verification/evm.ts (8 hunks)
  • src/lib/utils/evm.ts (1 hunks)
🔇 Additional comments (8)
src/lib/components/editor/types.ts (1)

1-1: LGTM! Extension added for Vyper support.

The addition of the "vy" extension to EXTENSION_LIB aligns with the PR objective to support Vyper files.

src/lib/pages/evm-contract-details/components/evm-contract-details-overview/OverviewVerifiedInfo.tsx (1)

34-34: LGTM! Good component extraction.

The optimization display logic has been cleanly extracted into a separate component, improving code organization while maintaining the existing layout.

src/lib/components/editor/FullEditor.tsx (1)

15-21: LGTM! Well-implemented language support.

The addition of the editorLanguage prop and its integration with the Editor component is clean and follows React best practices.

Also applies to: 23-30

src/lib/utils/evm.ts (1)

139-139: LGTM! Improved input validation.

The change enhances the constructor arguments validation by checking both existence and non-emptiness of the inputs array, which is a good defensive programming practice.

src/lib/services/types/verification/evm.ts (3)

146-155: LGTM! Well-structured verification config.

The verification config schema is well-defined with proper type transformations and validation.


183-199: LGTM! Robust optimizer parsing.

The optimizer JSON parsing includes proper error handling and type validation using Zod.


201-204: LGTM! Good Vyper support.

The Vyper optimizer enum properly handles all possible optimization values with a default.

CHANGELOG.md (1)

42-42: LGTM! Clear changelog entry.

The changelog entry follows the project's conventions and clearly documents the Vyper support feature.

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

Successfully merging this pull request may close these issues.

2 participants