From debe4836d2b67ec75636bce7536ff8838f77f22c Mon Sep 17 00:00:00 2001 From: "italiano@oplabs.co" Date: Mon, 30 Sep 2024 16:39:46 -0400 Subject: [PATCH 1/5] Adds supersim pkg --- packages/supersim/.eslintrc.cjs | 5 +++ packages/supersim/.gitignore | 1 + packages/supersim/install.js | 80 +++++++++++++++++++++++++++++++++ packages/supersim/package.json | 21 +++++++++ pnpm-lock.yaml | 2 + 5 files changed, 109 insertions(+) create mode 100644 packages/supersim/.eslintrc.cjs create mode 100644 packages/supersim/.gitignore create mode 100644 packages/supersim/install.js create mode 100644 packages/supersim/package.json diff --git a/packages/supersim/.eslintrc.cjs b/packages/supersim/.eslintrc.cjs new file mode 100644 index 00000000..77435379 --- /dev/null +++ b/packages/supersim/.eslintrc.cjs @@ -0,0 +1,5 @@ +module.exports = { + extends: ['../../.eslintrc.js'], + ignorePatterns: ['.eslintrc.cjs'] +} + \ No newline at end of file diff --git a/packages/supersim/.gitignore b/packages/supersim/.gitignore new file mode 100644 index 00000000..c5e82d74 --- /dev/null +++ b/packages/supersim/.gitignore @@ -0,0 +1 @@ +bin \ No newline at end of file diff --git a/packages/supersim/install.js b/packages/supersim/install.js new file mode 100644 index 00000000..683763f2 --- /dev/null +++ b/packages/supersim/install.js @@ -0,0 +1,80 @@ +const fs = require('fs') +const https = require('https') +const path = require('path') +const os = require('os') +const { exec } = require('child_process') + +const PLATFORM = os.platform() +const ARCH = os.arch() +const BIN_PATH = path.join(__dirname, 'bin') +const SUPERSIM_VERSION = '0.1.0-alpha.13' + +const archiveFilename = { + darwin: { + arm64: 'supersim_Darwin_arm64.tar.gz', + x64: 'supersim_Darwin_x86_64.tar.gz', + }, + linux: { + arm64: 'supersim_Linux_arm64.tar.gz', + x64: 'supersim_Linux_x86_64.tar.gz', + }, + win32: { + arm64: 'supersim_Windows_arm64.zip', + x64: 'supersim_Windows_x86_64.zip', + }, +} + +function extractRelease(filename, outputPath) { + const cmd = filename.endsWith('.tar.gz') + ? `tar -xzf ${outputPath} -C ${BIN_PATH}` + : `unzip ${outputPath} -d ${BIN_PATH}` + + exec(cmd, (err) => { + if (err) { + console.error('Error extracting', err) + } else { + console.log('Successfully extracted release') + } + }) +} + +async function main() { + const filename = archiveFilename[PLATFORM][ARCH] + if (!filename) { + console.error('Unsupported platform/architecture') + process.exit(1) + } + + const downloadUrl = `https://github.com/ethereum-optimism/supersim/releases/download/${SUPERSIM_VERSION}/${filename}` + const outputPath = path.join(BIN_PATH, filename) + + if (!fs.existsSync(BIN_PATH)) { + fs.mkdirSync(BIN_PATH) + } + + console.log(`Attempting to fetch ${filename}`) + + https + .get(downloadUrl, (res) => { + const fileStream = fs.createWriteStream(outputPath) + res.pipe(fileStream) + + fileStream.on('finish', () => { + console.log(`Downloaded ${filename}`) + fileStream.on('close', () => extractRelease(filename, outputPath)) + }) + }) + .on('error', (err) => { + console.error('Error downloading supersim', err) + process.exit(1) + }) +} + +;(async () => { + try { + await main() + } catch (err) { + console.error('Error setting up supersim', err) + process.exit(1) + } +})() diff --git a/packages/supersim/package.json b/packages/supersim/package.json new file mode 100644 index 00000000..574a31eb --- /dev/null +++ b/packages/supersim/package.json @@ -0,0 +1,21 @@ +{ + "name": "supersim", + "version": "0.0.1", + "description": "Supersim is a lightweight tool to simulate the Superchain locally", + "license": "MIT", + "author": "Optimism PBC", + "keywords": [ + "optimism", + "ethereum", + "supersim", + "superchain" + ], + "bin": { + "supersim": "./bin/supersim" + }, + "scripts": { + "lint": "eslint install.js && pnpm prettier --check install.js", + "lint:fix": "eslint install.js --fix --quiet && pnpm prettier install.js --write --loglevel=warn", + "postinstall": "node install.js" + } + } \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cfcc6ab5..5fe1a3f2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1221,6 +1221,8 @@ importers: specifier: ^3.22.4 version: 3.22.4 + packages/supersim: {} + packages/ui-components: dependencies: '@hookform/resolvers': From 09fea9ae47e6c3c227fa4bb746fec3f0d6bf7f60 Mon Sep 17 00:00:00 2001 From: "italiano@oplabs.co" Date: Mon, 30 Sep 2024 16:47:18 -0400 Subject: [PATCH 2/5] Add README --- packages/supersim/README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 packages/supersim/README.md diff --git a/packages/supersim/README.md b/packages/supersim/README.md new file mode 100644 index 00000000..502825d9 --- /dev/null +++ b/packages/supersim/README.md @@ -0,0 +1,22 @@ +# Supersim + +Supersim is a lightweight tool to simulate the Superchain locally (with a single L1 and multiple OP-Stack L2s). + +For more detailed documentation please refer to the [supersim repo](https://github.com/ethereum-optimism/supersim) + +# Installation + +**npm** +``` +npx supersim +``` + +**pnpm** +``` +pnpm dlx supersim +``` + +**yarn** +``` +yarn dlx supersim +``` \ No newline at end of file From e8e61887b520f5f886831b43df930f62464e912e Mon Sep 17 00:00:00 2001 From: "italiano@oplabs.co" Date: Mon, 30 Sep 2024 16:49:58 -0400 Subject: [PATCH 3/5] add node engine --- packages/supersim/package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/supersim/package.json b/packages/supersim/package.json index 574a31eb..ec167e35 100644 --- a/packages/supersim/package.json +++ b/packages/supersim/package.json @@ -10,6 +10,9 @@ "supersim", "superchain" ], + "engines": { + "node": ">=18.0.0" + }, "bin": { "supersim": "./bin/supersim" }, From 2d922989b2b887aa928158a994a3d7903906fb5c Mon Sep 17 00:00:00 2001 From: "italiano@oplabs.co" Date: Mon, 30 Sep 2024 16:51:32 -0400 Subject: [PATCH 4/5] Add changeset for supersim --- .changeset/lazy-monkeys-grin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lazy-monkeys-grin.md diff --git a/.changeset/lazy-monkeys-grin.md b/.changeset/lazy-monkeys-grin.md new file mode 100644 index 00000000..72d78154 --- /dev/null +++ b/.changeset/lazy-monkeys-grin.md @@ -0,0 +1,5 @@ +--- +"supersim": patch +--- + +Initial publish From a7f88489856f5bacc6e35b126e1710c3d99e3b99 Mon Sep 17 00:00:00 2001 From: "italiano@oplabs.co" Date: Mon, 30 Sep 2024 18:09:07 -0400 Subject: [PATCH 5/5] Adds follow-redirects This is for the case when github returns a 302 and we need to follow the value provided in the location header to download the archive --- packages/supersim/install.js | 2 +- packages/supersim/package.json | 13 ++++++++----- pnpm-lock.yaml | 26 +++++++++++++++++--------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/packages/supersim/install.js b/packages/supersim/install.js index 683763f2..1e9efcc4 100644 --- a/packages/supersim/install.js +++ b/packages/supersim/install.js @@ -1,5 +1,5 @@ const fs = require('fs') -const https = require('https') +const { https } = require('follow-redirects') const path = require('path') const os = require('os') const { exec } = require('child_process') diff --git a/packages/supersim/package.json b/packages/supersim/package.json index ec167e35..998cf32e 100644 --- a/packages/supersim/package.json +++ b/packages/supersim/package.json @@ -5,10 +5,10 @@ "license": "MIT", "author": "Optimism PBC", "keywords": [ - "optimism", - "ethereum", - "supersim", - "superchain" + "optimism", + "ethereum", + "supersim", + "superchain" ], "engines": { "node": ">=18.0.0" @@ -20,5 +20,8 @@ "lint": "eslint install.js && pnpm prettier --check install.js", "lint:fix": "eslint install.js --fix --quiet && pnpm prettier install.js --write --loglevel=warn", "postinstall": "node install.js" + }, + "dependencies": { + "follow-redirects": "^1.15.9" } - } \ No newline at end of file +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5fe1a3f2..d35c4a76 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1221,7 +1221,11 @@ importers: specifier: ^3.22.4 version: 3.22.4 - packages/supersim: {} + packages/supersim: + dependencies: + follow-redirects: + specifier: ^1.15.9 + version: 1.15.9 packages/ui-components: dependencies: @@ -9539,6 +9543,15 @@ packages: debug: optional: true + follow-redirects@1.15.9: + resolution: {integrity: sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==} + engines: {node: '>=4.0'} + peerDependencies: + debug: '*' + peerDependenciesMeta: + debug: + optional: true + for-each@0.3.3: resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==} @@ -15105,11 +15118,6 @@ packages: engines: {node: '>= 14'} hasBin: true - yaml@2.4.5: - resolution: {integrity: sha512-aBx2bnqDzVOyNKfsysjA2ms5ZlnjSAW2eG3/L5G/CSujfjLJTJsEw1bGw8kCf04KodQWk1pxlGnZ56CRxiawmg==} - engines: {node: '>= 14'} - hasBin: true - yaml@2.5.1: resolution: {integrity: sha512-bLQOjaX/ADgQ20isPJRvF0iRUHIxVhYvr53Of7wGcWlO2jvtUlH5m87DsmulFVxRpNLOnI4tB6p/oh8D7kpn9Q==} engines: {node: '>= 14'} @@ -21338,7 +21346,7 @@ snapshots: semver: 7.6.3 strip-ansi: 5.2.0 wcwidth: 1.0.1 - yaml: 2.4.5 + yaml: 2.5.1 transitivePeerDependencies: - encoding @@ -28750,6 +28758,8 @@ snapshots: optionalDependencies: debug: 4.3.4(supports-color@8.1.1) + follow-redirects@1.15.9: {} + for-each@0.3.3: dependencies: is-callable: 1.2.7 @@ -36043,8 +36053,6 @@ snapshots: yaml@2.4.1: {} - yaml@2.4.5: {} - yaml@2.5.1: {} yargs-parser@18.1.3: