From 7fbe24e7d509adf49afb72f1d060a555ff231531 Mon Sep 17 00:00:00 2001 From: MoD Date: Fri, 6 Mar 2026 00:38:32 +0200 Subject: [PATCH] Install contracts pkg --- package-lock.json | 8 +++ package.json | 1 + scripts/sync-contracts-docs.js | 111 +++++++++++++++++++++++++++++---- 3 files changed, 109 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8a5f4c1..1d23b04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,7 @@ "@docusaurus/tsconfig": "3.9.2", "@docusaurus/types": "3.9.2", "@tailwindcss/postcss": "^4.1.18", + "@yellow-org/contracts": "^1.0.1", "autoprefixer": "^10.4.24", "postcss": "^8.5.6", "tailwindcss": "^4.1.17", @@ -6449,6 +6450,13 @@ "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==", "license": "Apache-2.0" }, + "node_modules/@yellow-org/contracts": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@yellow-org/contracts/-/contracts-1.0.1.tgz", + "integrity": "sha512-yK5a5r6+o8Kb9DCem6uj3tzXrSnJDnY1CuUST8trO2EEn6kE6lIt5gTl7WyNY43aDuRl1LvCr22VocacrmaOSQ==", + "dev": true, + "license": "GPL-3.0-or-later" + }, "node_modules/abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", diff --git a/package.json b/package.json index 1f45209..86fc036 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "@docusaurus/tsconfig": "3.9.2", "@docusaurus/types": "3.9.2", "@tailwindcss/postcss": "^4.1.18", + "@yellow-org/contracts": "^1.0.1", "autoprefixer": "^10.4.24", "postcss": "^8.5.6", "tailwindcss": "^4.1.17", diff --git a/scripts/sync-contracts-docs.js b/scripts/sync-contracts-docs.js index f198440..aa35d0f 100644 --- a/scripts/sync-contracts-docs.js +++ b/scripts/sync-contracts-docs.js @@ -3,6 +3,8 @@ * into docs/contracts/ with Docusaurus-compatible frontmatter * and category metadata. * + * Generates the Deployed Addresses page from @yellow-org/contracts. + * * Usage: node scripts/sync-contracts-docs.js * * Safe to re-run — it wipes docs/contracts/ and rebuilds from source. @@ -14,6 +16,32 @@ const ROOT = path.resolve(__dirname, '..'); const SRC = path.join(ROOT, 'vendors', 'yellow', 'docs'); const DEST = path.join(ROOT, 'docs', 'contracts'); +// --------------------------------------------------------------------------- +// On-chain addresses from @yellow-org/contracts +// --------------------------------------------------------------------------- + +let addresses; +try { + addresses = require('@yellow-org/contracts').addresses; +} catch { + addresses = null; +} + +const CHAINS = { + 1: { name: 'Ethereum Mainnet', explorer: 'https://etherscan.io/address' }, + 11155111: { name: 'Sepolia Testnet', explorer: 'https://sepolia.etherscan.io/address' }, +}; + +const ADDRESS_LABELS = { + yellowToken: 'YellowToken', + nodeRegistry: 'NodeRegistry', + appRegistry: 'AppRegistry', + governor: 'YellowGovernor', + timelock: 'TimelockController', + treasury: 'Treasury', + faucet: 'Faucet', +}; + // --------------------------------------------------------------------------- // Helpers // --------------------------------------------------------------------------- @@ -69,7 +97,6 @@ function copyWithFrontmatter(srcFile, destFile, { title, description, sidebarPos content = content.replace(/^\n*/m, ''); // Escape curly braces in prose so MDX doesn't treat them as JSX expressions. - // Only escape {word} patterns outside of code blocks/fences. content = escapeCurlyBracesOutsideCode(content); const frontmatter = [ @@ -102,6 +129,66 @@ function writeCategory(dir, { label, position, link }) { fs.writeFileSync(path.join(dir, '_category_.json'), JSON.stringify(data, null, 2) + '\n'); } +// --------------------------------------------------------------------------- +// Address page generator +// --------------------------------------------------------------------------- + +function generateAddressesPage() { + const lines = [ + '---', + 'title: "Deployed Addresses"', + 'description: "Mainnet and testnet contract addresses for Yellow Network."', + 'sidebar_position: 2', + 'displayed_sidebar: contractsSidebar', + '---', + '', + '', + '# Deployed Addresses', + '', + ]; + + if (!addresses) { + lines.push('> Install `@yellow-org/contracts` and re-run `npm run sync:contracts` to populate addresses.', ''); + return lines.join('\n'); + } + + for (const [chainIdStr, addrs] of Object.entries(addresses)) { + const chainId = Number(chainIdStr); + const chain = CHAINS[chainId]; + if (!chain) continue; + + lines.push(`## ${chain.name} (Chain ID: ${chainId})`, ''); + lines.push('| Contract | Address |', '|---|---|'); + + for (const [key, label] of Object.entries(ADDRESS_LABELS)) { + const addr = addrs[key]; + if (addr) { + lines.push(`| ${label} | [\`${addr}\`](${chain.explorer}/${addr}) |`); + } else { + lines.push(`| ${label} | — |`); + } + } + lines.push(''); + } + + lines.push( + '## Using in Code', + '', + '```ts', + 'import { addresses } from "@yellow-org/contracts";', + '', + '// Mainnet', + 'addresses[1].yellowToken;', + '', + '// Sepolia', + 'addresses[11155111].faucet;', + '```', + '', + ); + + return lines.join('\n'); +} + // --------------------------------------------------------------------------- // Document mapping // --------------------------------------------------------------------------- @@ -114,12 +201,7 @@ const DOCS = { description: 'Overview of Yellow Network smart contracts, governance, and on-chain infrastructure.', sidebarPosition: 1, }, - addresses: { - src: 'operations/addresses.md', - title: 'Deployed Addresses', - description: 'Mainnet and testnet contract addresses for Yellow Network.', - sidebarPosition: 2, - }, + // 'addresses' is generated from @yellow-org/contracts — not copied from vendor faq: { src: 'FAQ.md', title: 'FAQ', @@ -290,7 +372,16 @@ function main() { }); } - // Copy and transform each document + // Generate addresses page from @yellow-org/contracts + const addressesPage = generateAddressesPage(); + fs.writeFileSync(path.join(DEST, 'addresses.md'), addressesPage); + if (addresses) { + console.log(' generated addresses.md (from @yellow-org/contracts)'); + } else { + console.warn(' generated addresses.md (WARNING: @yellow-org/contracts not installed)'); + } + + // Copy and transform each document from vendor let count = 0; const missing = []; @@ -315,7 +406,7 @@ function main() { } } - console.log(`\nSynced ${count} docs into docs/contracts/`); + console.log(`\nSynced ${count} vendor docs + 1 generated into docs/contracts/`); console.log('\nStructure:'); // Print tree @@ -331,9 +422,7 @@ function main() { const isLast = i === entries.length - 1; const connector = isLast ? '└── ' : '├── '; const full = path.join(dir, entry.name); - if (entry.name === '_category_.json') return; // skip noise - console.log(`${prefix}${connector}${entry.name}`); if (entry.isDirectory()) { printTree(full, prefix + (isLast ? ' ' : '│ '));