Skip to content

Bridging your custom ERC-20 tutorial update#1527

Merged
krofax merged 5 commits intomainfrom
custom-ERC-20
Mar 28, 2025
Merged

Bridging your custom ERC-20 tutorial update#1527
krofax merged 5 commits intomainfrom
custom-ERC-20

Conversation

@krofax
Copy link
Contributor

@krofax krofax commented Mar 24, 2025

Description

  • Updated the smart contract and changed the op-node version

Tests

Additional context

Metadata

@krofax krofax requested a review from a team as a code owner March 24, 2025 16:49
@krofax krofax requested review from ZakAyesh and brokewhale March 24, 2025 16:50
@netlify
Copy link

netlify bot commented Mar 24, 2025

Deploy Preview for docs-optimism ready!

Name Link
🔨 Latest commit 4509421
🔍 Latest deploy log https://app.netlify.com/sites/docs-optimism/deploys/67e5b1416d967a000910e39d
😎 Deploy Preview https://deploy-preview-1527--docs-optimism.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@krofax krofax changed the title Update Bridging your custom ERC-20 Tutorial Bridging your custom ERC-20 tutorial update Mar 24, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 24, 2025

📝 Walkthrough

Walkthrough

The changes update both a documentation tutorial and a Solidity contract. In the tutorial file, links and text are revised: the referenced version of the IOptimismMintableERC20 interface is updated from v1.1.4 to v1.12.2, grammatical adjustments are made, and parameter formatting is standardized with additional inline comments. In the Solidity file, new interfaces (ILegacyMintableERC20 and IOptimismMintableERC20) are introduced, and a new Semver contract is added, with the token contract updated to implement both interfaces alongside ERC20 and Semver. Function signatures for minting, burning, and interface support are modified, ensuring that the burn function always reverts to prevent L1 withdrawals while maintaining backward compatibility through legacy getter functions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MyCustomL2Token as Contract

    User->>MyCustomL2Token: Call mint(_to, _amount)
    Note right of MyCustomL2Token: Validates against IOptimismMintableERC20 & ILegacyMintableERC20
    MyCustomL2Token-->>User: Successfully mints tokens
Loading
sequenceDiagram
    participant User
    participant MyCustomL2Token as Contract

    User->>MyCustomL2Token: Call burn(_from, _amount)
    Note right of MyCustomL2Token: burn function immediately reverts to block L1 withdrawals
    MyCustomL2Token-->>User: Error response (revert)
Loading

Possibly related PRs

Suggested reviewers

  • zainbacchus
  • sbvegan
  • bradleycamacho

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

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: 0

🧹 Nitpick comments (3)
pages/app-developers/tutorials/bridging/standard-bridge-custom-token.mdx (2)

31-31: Avoid using bold for emphasis.

Guidelines suggest limiting the use of bold for emphasis. Consider removing bold formatting to remain consistent with the style guide.

-  The Standard Bridge **does not** support [**fee on transfer tokens**] or [**rebasing tokens**]...
+  The Standard Bridge does not support [fee on transfer tokens] or [rebasing tokens]...

85-85: Add a missing comma for clarity.

A comma after "like" clarifies the sentence.

-  You can name this file whatever you'd like, for example `MyCustomL2Token.sol`.
+  You can name this file whatever you'd like, for example, `MyCustomL2Token.sol`.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~85-~85: Possible missing comma found.
Context: ...name this file whatever you'd like, for example MyCustomL2Token.sol. {

Copy the...

(AI_HYDRA_LEO_MISSING_COMMA)

public/tutorials/standard-bridge-custom-token.sol (1)

136-156: Unreachable code note.

The burn function reverts to prevent L1 withdrawals. The commented-out _burn call is unreachable. Consider removing it or clarifying with a code comment if it is only for example purposes.

149-156
-        revert("MyCustomL2Token: withdrawals are not allowed");
-
-        // Note: The following line would normally execute but is unreachable
-        // _burn(_from, _amount);
-        // emit Burn(_from, _amount);
+        revert("MyCustomL2Token: withdrawals are not allowed");
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65991f9 and 61644f0.

📒 Files selected for processing (2)
  • pages/app-developers/tutorials/bridging/standard-bridge-custom-token.mdx (3 hunks)
  • public/tutorials/standard-bridge-custom-token.sol (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.mdx`: "ALWAYS review Markdown content THOROUGHLY with the following criteria: - First, check the frontmatter section at the top of the file: 1. For regular pages, ensure AL...

**/*.mdx: "ALWAYS review Markdown content THOROUGHLY with the following criteria:

  • First, check the frontmatter section at the top of the file:
    1. For regular pages, ensure ALL these fields are present and not empty:
    ---
    title: [non-empty]
    lang: [non-empty]
    description: [non-empty]
    topic: [non-empty]
    personas: [non-empty array]
    categories: [non-empty array]
    content_type: [valid type]
    ---
    1. For landing pages (index.mdx or files with ), only these fields are required:
    ---
    title: [non-empty]
    lang: [non-empty]
    description: [non-empty]
    topic: [non-empty]
    ---
    1. If any required fields are missing or empty, comment:
      'This file appears to be missing required metadata. You can fix this by running:
    pnpm metadata-batch-cli:dry "path/to/this/file.mdx"
    Review the changes, then run without :dry to apply them.'
  • Use proper nouns in place of personal pronouns like 'We' and 'Our' to maintain consistency in communal documentation.
  • Avoid gender-specific language and use the imperative form.
  • Monitor capitalization for emphasis. Avoid using all caps, italics, or bold for emphasis.
  • Ensure proper nouns are capitalized in sentences.
  • Apply the Oxford comma.
  • Use proper title case for buttons, tab names, page names, and links. Sentence case should be used for body content and short phrases, even in links.
  • Use correct spelling and grammar at all times (IMPORTANT).
  • For H1, H2, and H3 headers:
    1. Use sentence case, capitalizing only the first word.
    2. Preserve the capitalization of proper nouns, technical terms, and acronyms as defined in the 'nouns.txt' file located in the root directory of the project.
    3. Do not automatically lowercase words that appear in the 'nouns.txt' file, regardless of their position in the header.
  • Flag any headers that seem to inconsistently apply these rules for manual review.
  • When reviewing capitalization, always refer to the 'nouns.txt' file for the correct capitalization of proper nouns and technical terms specific to the project.
    "
  • pages/app-developers/tutorials/bridging/standard-bridge-custom-token.mdx
🪛 LanguageTool
pages/app-developers/tutorials/bridging/standard-bridge-custom-token.mdx

[uncategorized] ~85-~85: Possible missing comma found.
Context: ...name this file whatever you'd like, for example MyCustomL2Token.sol. {

Copy the...

(AI_HYDRA_LEO_MISSING_COMMA)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - docs-optimism
  • GitHub Check: Header rules - docs-optimism
  • GitHub Check: Pages changed - docs-optimism
🔇 Additional comments (9)
pages/app-developers/tutorials/bridging/standard-bridge-custom-token.mdx (3)

23-23: Looks great.

The added introduction line correctly clarifies the purpose of the tutorial.


26-26: Good reference update.

Using the upgraded IOptimismMintableERC20 interface version (v1.12.2) is consistent with the latest Optimism contracts.


52-53: Faucet references look correct.

Providing the Sepolia faucet link and the Superchain Faucet link is helpful.

public/tutorials/standard-bridge-custom-token.sol (6)

2-2: Solidity version update.

Adopting pragma solidity 0.8.15; aligns with the recommended compiler version for current Optimism contracts.


8-19: New legacy interface definition.

The ILegacyMintableERC20 interface is well-defined and neatly namespaced, preserving backward compatibility.


20-29: Additional interface.

IOptimismMintableERC20 clarifies bridge-critical methods and keeps the contract consistent with Optimism’s requirements.


31-73: Semver contract.

The Semver contract is a neat approach for versioning. Implementation is straightforward, and the helper function is clearly limited in scope.


80-80: Multiple inheritance setup.

Combining IOptimismMintableERC20, ILegacyMintableERC20, ERC20, and Semver into a single contract is well-executed.


158-168: Interface support check.

Verifying supportsInterface for IERC165, ILegacyMintableERC20, and IOptimismMintableERC20 is correct.

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

🧹 Nitpick comments (2)
public/tutorials/standard-bridge-custom-token.sol (2)

31-73: Consider using OpenZeppelin's Strings library for the Semver implementation.

The custom toString implementation works for this tutorial, but in production code, it would be better to leverage OpenZeppelin's battle-tested Strings library for numeric conversion.

// Import the Strings library
+import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";

contract Semver {
    string public version;

-    // Simple function to convert uint to string for version numbers
-    function toString(uint256 value) internal pure returns (string memory) {
-        // This function handles numbers from 0 to 999 which is sufficient for versioning
-        if (value == 0) {
-            return "0";
-        }
-        
-        uint256 temp = value;
-        uint256 digits;
-        
-        while (temp != 0) {
-            digits++;
-            temp /= 10;
-        }
-        
-        bytes memory buffer = new bytes(digits);
-        
-        while (value != 0) {
-            digits -= 1;
-            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
-            value /= 10;
-        }
-        
-        return string(buffer);
-    }

    constructor(uint256 major, uint256 minor, uint256 patch) {
        version = string(abi.encodePacked(
-            toString(major),
+            Strings.toString(major),
            ".",
-            toString(minor),
+            Strings.toString(minor),
            ".",
-            toString(patch)
+            Strings.toString(patch)
        ));
    }
}

158-168: Improve the supportsInterface implementation.

The current implementation doesn't follow ERC-165 best practices. Typically, supportsInterface should also check if the parent contract supports the interface.

-    function supportsInterface(bytes4 _interfaceId) external pure virtual returns (bool) {
+    function supportsInterface(bytes4 _interfaceId) external view virtual returns (bool) {
        bytes4 iface1 = type(IERC165).interfaceId;
        // Interface corresponding to the legacy L2StandardERC20
        bytes4 iface2 = type(ILegacyMintableERC20).interfaceId;
        // Interface corresponding to the updated OptimismMintableERC20
        bytes4 iface3 = type(IOptimismMintableERC20).interfaceId;
        return _interfaceId == iface1 || _interfaceId == iface2 || _interfaceId == iface3;
    }

Also, note that this function should be view instead of pure as it's not modifying state but still accesses contract data.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61644f0 and 4509421.

📒 Files selected for processing (1)
  • public/tutorials/standard-bridge-custom-token.sol (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - docs-optimism
  • GitHub Check: Header rules - docs-optimism
  • GitHub Check: Pages changed - docs-optimism
🔇 Additional comments (7)
public/tutorials/standard-bridge-custom-token.sol (7)

2-2: Solidity version correctly updated.

The change from ^0.8.0 to 0.8.20 is appropriate and matches the recommendation from previous reviews to align with OpenZeppelin dependencies.


8-29: Well-structured interface definitions that improve compatibility.

The addition of both ILegacyMintableERC20 and IOptimismMintableERC20 interfaces provides clear separation between legacy support and current implementation. This dual-interface approach enables backward compatibility while moving toward more descriptive naming conventions in the newer interface.


80-80: Good implementation of multiple interfaces.

The contract now properly implements both the legacy and current interfaces, which ensures compatibility with existing systems while also supporting the newer interface design.


114-114: Semver initialization added correctly.

Adding semantic versioning to the token contract is a good practice that will help track contract versions in production.


129-130: Function correctly overrides both interface implementations.

The mint function properly overrides both interfaces, maintaining compatibility.


136-156: Intentional revert behavior for burn function is well-documented.

The modification to make the burn function always revert is clearly documented and implements the stated goal of preventing withdrawals to L1. The commented-out code helps explain what would normally happen in a standard implementation.


170-188: Well-implemented backward compatibility.

Adding legacy getter functions alongside the new interface functions ensures backward compatibility with existing systems. The clear documentation indicating these are legacy functions is also helpful.

Copy link
Collaborator

@ZakAyesh ZakAyesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I'll make a note we should probably not be sending them to a different tutorial at the end of this one, and rather have all the info within this tutorial. We can save that for a future update however.

@krofax krofax merged commit 44da3d8 into main Mar 28, 2025
8 checks passed
@krofax krofax deleted the custom-ERC-20 branch March 28, 2025 17:00
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