Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds supersim pkg #488

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lazy-monkeys-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"supersim": patch
---

Initial publish
5 changes: 5 additions & 0 deletions packages/supersim/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: ['../../.eslintrc.js'],
ignorePatterns: ['.eslintrc.cjs']
}

1 change: 1 addition & 0 deletions packages/supersim/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin
22 changes: 22 additions & 0 deletions packages/supersim/README.md
Original file line number Diff line number Diff line change
@@ -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
```
80 changes: 80 additions & 0 deletions packages/supersim/install.js
Original file line number Diff line number Diff line change
@@ -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) => {
Dismissed Show dismissed Hide dismissed
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)
Fixed Show fixed Hide fixed
process.exit(1)
})
}

;(async () => {
try {
await main()
} catch (err) {
console.error('Error setting up supersim', err)
process.exit(1)
}
})()
24 changes: 24 additions & 0 deletions packages/supersim/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"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"
}
}
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading