optimism icon indicating copy to clipboard operation
optimism copied to clipboard

feat: Remove contracts-ts in favor of @eth-optimism/constants

Open roninjin10 opened this issue 1 year ago • 5 comments

This pr is a simpler attempt at accomplishing the goal of the contracts-ts package. That package had goals of being the source of truth for JavaScript but had the following problems

  • It only worked for op-mainnet
  • The wagmi-cli generation tool used was complicated buggy and poorly maintained

Base and us came to conclusion that instead we want a simple package that has chain constants ready to be used in JavaScript packages. This generates that from the superchain registry in one go.

I am putting this in the monorepo for now based on:

  • Conversation in office hours folks preferred keeping code out of the superchain registry if possible
  • Later this may move to the ecopod repo or a base maintained repo but it's final home hasn't been decided as of now.

I wrote the code generation script in JavaScript to reduce dependencies. It depends on yaml parsing since JS doesn't have it natively. It depends on viem to get the rpc urls for a given chain.

This script will also let us know if any chains are missing from viem that need to be upstreamed

roninjin10 avatar Jan 17 '24 17:01 roninjin10

Current dependencies on/for this PR:

  • develop
    • PR #9041 Graphite 👈
      • PR #9045 Graphite

This stack of pull requests is managed by Graphite.

roninjin10 avatar Jan 17 '24 17:01 roninjin10

Walkthrough

Walkthrough

The changes encompass the integration of chain constants from a superchain registry into the project. This includes scripts for generating chain constants, managing genesis blocks, and integrating Optimistic Rollup contracts. A new script is introduced to create viem chains for each chain in the superchain registry. Additionally, a function to retrieve Layer 2 predeployed contracts is added. The build configuration is optimized, and the package now consolidates all functionalities through a single entry point.

Changes

File Change Summary
packages/chains/README.md Introduces chain constants from the superchain registry with installation and usage instructions.
packages/chains/scripts/chains/OP_GENESIS_BLOCK.js
.../paths.js
Imports a YAML file to extract specific values as OP_GENESIS_BLOCK and provides functionality for defining file paths.
.../OpStackChain.ts Introduces OpStackChain type extending Chain to include OP contracts for L1 and L2 chains.
.../generate.js Introduces a script to generate viem chain files from the superchain registry data.
.../getL2Predeploys.js Introduces a function to return L2 predeployed contract information.
.../index.ts Exports all functionality from chains.js.
packages/chains/tsup.config.ts Modifies the build entry point to a single file and enables declaration file generation.
.circleci/config.yml Removes the contracts-ts-tests job and associated configurations.
.changeset/config.json Removes the linked field affecting linked dependencies configuration.
.github/mergify.yml Updates label rules based on specific file conditions.
op-bindings/README.md Removes the "See also" section.
op-bindings/predeploys/addresses.go Refactors address constants in the predeploys package.

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

coderabbitai[bot] avatar Jan 17 '24 17:01 coderabbitai[bot]

The generated objects look good to me!

nitaliano avatar Jan 18 '24 17:01 nitaliano

Hey @roninjin10 this needs a rebase

tynes avatar Jan 18 '24 22:01 tynes

Semgrep found 1 sol-style-return-arg-fmt finding:

  • packages/contracts-bedrock/scripts/Artifacts.s.sol: L53

Named return arguments to functions must be appended with an underscore (_)

Ignore this finding from sol-style-return-arg-fmt.

Semgrep found 1 missing-integrity finding:

  • op-node/cmd/stateviz/assets/index.html: L8

This tag is missing an 'integrity' subresource integrity attribute. The 'integrity' attribute allows for the browser to verify that externally hosted files (for example from a CDN) are delivered without unexpected manipulation. Without this attribute, if an attacker can modify the externally hosted resource, this could lead to XSS and other types of attacks. To prevent this, include the base64-encoded cryptographic hash of the resource (file) you’re telling the browser to fetch in the 'integrity' attribute for all externally hosted files.

Ignore this finding from missing-integrity.

Semgrep found 4 ifs-tampering findings:

  • op-challenger/scripts/list_games.sh: L22, L19
  • op-challenger/scripts/list_claims.sh: L18, L15

The special variable IFS affects how splitting takes place when expanding unquoted variables. Don't set it globally. Prefer a dedicated utility such as 'cut' or 'awk' if you need to split input data. If you must use 'read', set IFS locally using e.g. 'IFS="," read -a my_array'.

Ignore this finding from ifs-tampering.

Semgrep found 4 todos_require_linear findings:

  • op-node/cmd/stateviz/main.go: L115
  • op-node/cmd/stateviz/assets/main.js: L89, L79, L62

Please create a GitHub ticket for this TODO.

Ignore this finding from todos_require_linear.

semgrep-app[bot] avatar Feb 08 '24 02:02 semgrep-app[bot]

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Mar 08 '24 01:03 github-actions[bot]

It's back

roninjin10 avatar Mar 13 '24 15:03 roninjin10

Code gen has been implemented in the tevm/opstack package. The next TODO here is basically to just copy it in here https://github.com/evmts/tevm-monorepo/blob/main/extensions/opstack/scripts/generate.ts

Beyond what it's already doing it needs to get the addresses (code available in ecopod file) and use viem chains instead of tevm contracts (as this pr is already doing)

roninjin10 avatar Mar 13 '24 20:03 roninjin10

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Mar 28 '24 01:03 github-actions[bot]

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Apr 14 '24 02:04 github-actions[bot]

@roninjin10 Huge fan of this PR- monitoring services will need to scale as other projects launch op-stack L2s as the chain monitoring services are crucial to secure operations.

I mention monitoring services specifically because I found this PR through a TODO: https://github.com/ethereum-optimism/optimism/blob/e30ccc041a8ed8854be724f54e3eb707dfa15789/packages/chain-mon/src/wd-mon/constants.ts#L3-L4

It would be helpful having monitoring services provided out-of-box for superchain-compatible chains. As the Superchain expands, we will need to monitor all connected chains.

pegahcarter avatar May 15 '24 21:05 pegahcarter

Unfortunate I didn't get this pr over the finish line. @pegahcarter if you are interested in picking this up I'm happy to help advise you to getting this over finish line.

Also my project tevm has an @tevm/opstack package that also has these constants as well as contract objects.

roninjin10 avatar May 15 '24 21:05 roninjin10