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 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/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 diff --git a/packages/supersim/install.js b/packages/supersim/install.js new file mode 100644 index 00000000..1e9efcc4 --- /dev/null +++ b/packages/supersim/install.js @@ -0,0 +1,80 @@ +const fs = require('fs') +const { https } = require('follow-redirects') +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..998cf32e --- /dev/null +++ b/packages/supersim/package.json @@ -0,0 +1,27 @@ +{ + "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" + ], + "engines": { + "node": ">=18.0.0" + }, + "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" + }, + "dependencies": { + "follow-redirects": "^1.15.9" + } +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cfcc6ab5..d35c4a76 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1221,6 +1221,12 @@ importers: specifier: ^3.22.4 version: 3.22.4 + packages/supersim: + dependencies: + follow-redirects: + specifier: ^1.15.9 + version: 1.15.9 + packages/ui-components: dependencies: '@hookform/resolvers': @@ -9537,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==} @@ -15103,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'} @@ -21336,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 @@ -28748,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 @@ -36041,8 +36053,6 @@ snapshots: yaml@2.4.1: {} - yaml@2.4.5: {} - yaml@2.5.1: {} yargs-parser@18.1.3: