Skip to content

Install contracts pkg#119

Merged
mod merged 1 commit intomasterfrom
feat/pkg
Mar 5, 2026
Merged

Install contracts pkg#119
mod merged 1 commit intomasterfrom
feat/pkg

Conversation

@mod
Copy link
Contributor

@mod mod commented Mar 5, 2026

Summary by CodeRabbit

  • Documentation

    • Introduced auto-generated Deployed Addresses documentation page displaying contract addresses across supported blockchain networks with graceful fallback handling.
  • Chores

    • Added development dependency to support contract documentation generation features.

@mod mod requested a review from dpatsora as a code owner March 5, 2026 22:47
@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

📝 Walkthrough

Walkthrough

The changes add a new development dependency for on-chain contract integration and refactor the documentation generation script to dynamically generate a Deployed Addresses page from the newly added contracts package, replacing the previous hard-coded approach.

Changes

Cohort / File(s) Summary
Dependency Addition
package.json
Added @yellow-org/contracts as a devDependency with version ^1.0.1.
Documentation Generation Script
scripts/sync-contracts-docs.js
Refactored to dynamically generate addresses.md from @yellow-org/contracts instead of copying a static file. Introduces generateAddressesPage() function with CHAINS and ADDRESS_LABELS constants. Updates document generation flow and console output messaging. Includes graceful fallback when the contracts package is unavailable.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 With contracts now in sight so clear,
A rabbit's code does bring good cheer,
Addresses dance from chains up high,
Generated fresh before the eye!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Install contracts pkg' directly describes the main change: adding a new @yellow-org/contracts package as a development dependency and integrating it into the documentation generation workflow.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/pkg

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/sync-contracts-docs.js`:
- Around line 155-159: The loop over Object.entries(addresses) currently drops
unknown chain IDs with if (!chain) continue; instead create a fallback chain
object so unknown chains are rendered rather than skipped: when CHAINS[chainId]
is falsy, set a fallback like { id: chainId, name: `chain-${chainId}` } (or a
descriptive label) and use that fallback for subsequent rendering logic (replace
usages of chain with this fallbackChain variable); ensure any downstream
properties accessed (e.g., chain.name or chain.id) are read from the fallback so
new deployments appear in the docs.
- Around line 23-28: The try/catch around
require('@yellow-org/contracts').addresses is too broad and hides real errors;
update the try/catch in scripts/sync-contracts-docs.js that assigns addresses so
it only swallows a MODULE_NOT_FOUND error and rethrows any other
exceptions—i.e., after calling require('@yellow-org/contracts') (the expression
used to set addresses), inspect the caught error.code and if it equals
'MODULE_NOT_FOUND' set addresses = null, otherwise throw the error so issues
like syntax or export problems surface.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e5444538-8f8e-404a-8074-37db6004e5ef

📥 Commits

Reviewing files that changed from the base of the PR and between 00aa153 and 7fbe24e.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json
  • scripts/sync-contracts-docs.js

Comment on lines +23 to +28
let addresses;
try {
addresses = require('@yellow-org/contracts').addresses;
} catch {
addresses = null;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

find . -name "package*.json" -type f | head -20

Repository: layer-3/docs

Length of output: 90


🏁 Script executed:

rg "@yellow-org/contracts" --type json

Repository: layer-3/docs

Length of output: 340


🏁 Script executed:

git ls-files scripts/ | head -20

Repository: layer-3/docs

Length of output: 165


🏁 Script executed:

cat -n scripts/sync-contracts-docs.js | head -50

Repository: layer-3/docs

Length of output: 1947


🌐 Web query:

@yellow-org/contracts npm module exports addresses CommonJS

💡 Result:

If @yellow-org/contracts is published as ESM-only (common for “contracts artifacts” packages), then CommonJS require() won’t give you named exports the way you expect.

How to consume it from CommonJS

Option A (recommended): use dynamic import() from CJS

// CommonJS file (.cjs or "type": "commonjs")
const { addresses } = await import('@yellow-org/contracts');
// or whatever export name the package uses
console.log(addresses);

Node can load ESM via import(), and when importing CommonJS from ESM (or vice‑versa), interop often goes through a default export wrapper. (mirrors.aliyun.com)

Option B: require() and look for .default

const pkg = require('@yellow-org/contracts');
const addresses = pkg.addresses ?? pkg.default?.addresses ?? pkg.default;

This is needed when Node represents the other module system via a namespace object whose main value is on default. (mirrors.aliyun.com)

Option C: if you control the package, add conditional exports
In the package’s package.json, publish both entry points:

{
  "exports": {
    ".": {
      "import": "./dist/index.mjs",
      "require": "./dist/index.cjs"
    }
  }
}

This is the standard way to support both import and require. (nodejs.org)

If require() throws “ERR_REQUIRE_ESM”

That means it’s ESM-only; use Option A (dynamic import()), or ship a CJS build + conditional exports (Option C). Node only supports requiring ESM in limited/experimental ways. (mirrors.aliyun.com)

Citations:


🏁 Script executed:

cat -n package-lock.json | grep -A 20 "@yellow-org/contracts"

Repository: layer-3/docs

Length of output: 2139


🏁 Script executed:

rg "@yellow-org/contracts" --type js -A 3 -B 3

Repository: layer-3/docs

Length of output: 3341


🏁 Script executed:

cat -n scripts/sync-contracts-docs.js | tail -n +20 | head -n 50

Repository: layer-3/docs

Length of output: 1805


Avoid broad catch blocks—only catch missing module errors.

This catches every runtime failure and silently degrades to addresses = null, which masks real module issues (broken exports, syntax errors, incompatible formats). Catch MODULE_NOT_FOUND specifically and rethrow unexpected errors so actual problems surface during development.

Proposed fix
 let addresses;
 try {
   addresses = require('@yellow-org/contracts').addresses;
-} catch {
-  addresses = null;
+} catch (err) {
+  if (err && err.code === 'MODULE_NOT_FOUND') {
+    addresses = null;
+  } else {
+    throw err;
+  }
 }
📝 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
let addresses;
try {
addresses = require('@yellow-org/contracts').addresses;
} catch {
addresses = null;
}
let addresses;
try {
addresses = require('@yellow-org/contracts').addresses;
} catch (err) {
if (err && err.code === 'MODULE_NOT_FOUND') {
addresses = null;
} else {
throw err;
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/sync-contracts-docs.js` around lines 23 - 28, The try/catch around
require('@yellow-org/contracts').addresses is too broad and hides real errors;
update the try/catch in scripts/sync-contracts-docs.js that assigns addresses so
it only swallows a MODULE_NOT_FOUND error and rethrows any other
exceptions—i.e., after calling require('@yellow-org/contracts') (the expression
used to set addresses), inspect the caught error.code and if it equals
'MODULE_NOT_FOUND' set addresses = null, otherwise throw the error so issues
like syntax or export problems surface.

Comment on lines +155 to +159
for (const [chainIdStr, addrs] of Object.entries(addresses)) {
const chainId = Number(chainIdStr);
const chain = CHAINS[chainId];
if (!chain) continue;

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Unknown chain IDs are silently dropped from docs.

if (!chain) continue hides new deployments when the package adds chains not yet mapped in CHAINS. Render them with a fallback label instead of skipping.

Proposed fix
-    const chain = CHAINS[chainId];
-    if (!chain) continue;
+    const chain = CHAINS[chainId] || { name: `Chain ${chainId}`, explorer: null };
@@
-      if (addr) {
-        lines.push(`| ${label} | [\`${addr}\`](${chain.explorer}/${addr}) |`);
+      if (addr) {
+        const rendered = chain.explorer ? `[\`${addr}\`](${chain.explorer}/${addr})` : `\`${addr}\``;
+        lines.push(`| ${label} | ${rendered} |`);
       } else {
         lines.push(`| ${label} | — |`);
       }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/sync-contracts-docs.js` around lines 155 - 159, The loop over
Object.entries(addresses) currently drops unknown chain IDs with if (!chain)
continue; instead create a fallback chain object so unknown chains are rendered
rather than skipped: when CHAINS[chainId] is falsy, set a fallback like { id:
chainId, name: `chain-${chainId}` } (or a descriptive label) and use that
fallback for subsequent rendering logic (replace usages of chain with this
fallbackChain variable); ensure any downstream properties accessed (e.g.,
chain.name or chain.id) are read from the fallback so new deployments appear in
the docs.

@mod mod added this pull request to the merge queue Mar 5, 2026
Merged via the queue into master with commit 54807a4 Mar 5, 2026
3 checks passed
@mod mod deleted the feat/pkg branch March 5, 2026 22:57
ihsraham added a commit that referenced this pull request Mar 6, 2026
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.

1 participant