Skip to content

Commit

Permalink
Add initial setup + pause/unpause commands
Browse files Browse the repository at this point in the history
  • Loading branch information
nmlinaric committed Aug 10, 2023
1 parent 5eee8ec commit 177126a
Show file tree
Hide file tree
Showing 26 changed files with 10,560 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
root: true,
extends: ['@chainsafe'],
}
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
**/*/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build
/bin
rpcEndpoints.json

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

.env
.vscode
.history

# runtime config
public/chainbridge-runtime-config.js

# IDE
.idea/

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
20 changes: 20 additions & 0 deletions @types/gluegun/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Bridge } from '@buildwithsygma/sygma-contracts'
import { RawConfig } from '@buildwithsygma/sygma-sdk-core'
import { Wallet } from 'ethers'

declare module 'gluegun' {
interface GluegunToolbox {
bridge: {
initBridgeInstances(
rawConfig: RawConfig,
wallets: Array<Wallet | KeyringPair>
): Array<Bridge>
}
wallet: {
initializeWallets(rawConfig: RawConfig): InitializedWallets
}
sharedConfig: {
fetchSharedConfig(): Promise<RawConfig>
}
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# maintenance-utils
# maintenance-utils CLI

A CLI for maintenance-utils.

## How to run the maintenance-utils CLI

* populate `rpcEndpoints.json` with your supported networks
* run `yarn build` - this will generate a executable file

## Commands

`bridge pause` - pauses all bridge instances across the selected network
`bridge unpause` - unpauses all bridge instances across the selected network
3 changes: 3 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Command Reference for maintenance-utils

TODO: Add your command reference here
47 changes: 47 additions & 0 deletions docs/plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Plugin guide for maintenance-utils

Plugins allow you to add features to maintenance-utils, such as commands and
extensions to the `toolbox` object that provides the majority of the functionality
used by maintenance-utils.

Creating a maintenance-utils plugin is easy. Just create a repo with two folders:

```
commands/
extensions/
```

A command is a file that looks something like this:

```js
// commands/foo.js

module.exports = {
run: (toolbox) => {
const { print, filesystem } = toolbox

const desktopDirectories = filesystem.subdirectories(`~/Desktop`)
print.info(desktopDirectories)
}
}
```

An extension lets you add additional features to the `toolbox`.

```js
// extensions/bar-extension.js

module.exports = (toolbox) => {
const { print } = toolbox

toolbox.bar = () => { print.info('Bar!') }
}
```

This is then accessible in your plugin's commands as `toolbox.bar`.

# Loading a plugin

To load a particular plugin (which has to start with `maintenance-utils-*`),
install it to your project using `npm install --save-dev maintenance-utils-PLUGINNAME`,
and maintenance-utils will pick it up automatically.
65 changes: 65 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "maintenance-utils",
"version": "0.0.1",
"description": "maintenance-utils CLI",
"private": true,
"types": "build/types/types.d.ts",
"bin": {
"maintenance-utils": "bin/maintenance-utils"
},
"scripts": {
"clean-build": "rm -rf ./build",
"compile": "tsc -p .",
"copy-templates": "copyfiles ./src/templates/* ./build/templates",
"build": "yarn clean-build && yarn compile && yarn copy-templates",
"prepublishOnly": "yarn build",
"format": "eslint \"src/**/*.{ts,tsx}\" --fix && prettier \"src/**/*.{ts,tsx}\" --write",
"test": "jest",
"watch": "jest --watch",
"snapupdate": "jest --updateSnapshot",
"coverage": "jest --coverage"
},
"files": [
"build",
"LICENSE",
"readme.md",
"docs",
"bin"
],
"license": "MIT",
"dependencies": {
"@buildwithsygma/sygma-contracts": "^2.3.0",
"@polkadot/api": "^10.9.1",
"@polkadot/keyring": "^12.3.2",
"gluegun": "^5.1.2"
},
"devDependencies": {
"@buildwithsygma/sygma-sdk-core": "^2.1.0",
"@chainsafe/eslint-config": "^2.0.0",
"@polkadot/types": "^10.9.1",
"@rushstack/eslint-patch": "^1.3.2",
"@types/jest": "^26.0.20",
"@types/node": "^12.7.11",
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"copyfiles": "^2.4.1",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"ethers": "^5",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"pretty-quick": "^3.1.0",
"ts-jest": "^26.5.3",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node"
},
"prettier": {
"semi": false,
"singleQuote": true
}
}
5 changes: 5 additions & 0 deletions rpcEndpoints.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"chainId": "rpcUrl",
"chainId": "rpcUrl",
"chainId": "rpcUrl"
}
29 changes: 29 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { GluegunToolbox, build } from 'gluegun'
import { Options } from 'gluegun/build/types/domain/options'

/**
* Create the cli and kick it off
*/
async function run(argv: Options): Promise<GluegunToolbox> {
// create a CLI runtime
const cli = build()
.brand('maintenance-utils')
.src(__dirname)
.plugins('./node_modules', {
matching: 'maintenance-utils-*',
hidden: true,
})
.help() // provides default for help, h, --help, -h
.version() // provides default for version, v, --version, -v
.create()
// enable the following method if you'd like to skip loading one of these core extensions
// this can improve performance if they're not necessary for your project:
// .exclude(['meta', 'strings', 'print', 'filesystem', 'semver', 'system', 'prompt', 'http', 'template', 'patching', 'package-manager'])
// and run it
const toolbox = await cli.run(argv).finally(() => process.exit())

// send it back (for testing, mostly)
return toolbox
}

module.exports = { run }
56 changes: 56 additions & 0 deletions src/commands/bridge/pause.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { KeyringPair } from '@polkadot/keyring/types'
import { GluegunToolbox, filesystem } from 'gluegun'
import {
EthereumConfig,
Network,
SubstrateConfig,
} from '@buildwithsygma/sygma-sdk-core'
import { Wallet } from 'ethers'
import { InitializedWallets, RpcEndpoints } from '../../types'
import {
sendEvmPauseTransaction,
sendSubstratePauseTransaction,
} from '../../utils'

module.exports = {
name: 'pause',
run: async (toolbox: GluegunToolbox) => {
const { sharedConfig, wallet } = toolbox

const rawConfig = await sharedConfig.fetchSharedConfig()

const initializedWallets = (await wallet.initializeWallets(
rawConfig
)) as InitializedWallets

const evmNetworks = rawConfig.domains.filter(
(domain) => domain.type === Network.EVM
) as Array<EthereumConfig>

const substrateNetworks = rawConfig.domains.filter(
(domain) => domain.type === Network.SUBSTRATE
) as Array<SubstrateConfig>

const rpcEndpoints = filesystem.read(
'rpcEndpoints.json',
'json'
) as RpcEndpoints

if (evmNetworks) {
await sendEvmPauseTransaction(
evmNetworks,
rpcEndpoints,
initializedWallets[Network.EVM] as Wallet
)
}

if (substrateNetworks) {
await sendSubstratePauseTransaction(
substrateNetworks,
rpcEndpoints,
initializedWallets[Network.SUBSTRATE] as unknown as KeyringPair,
true
)
}
},
}
56 changes: 56 additions & 0 deletions src/commands/bridge/unpause.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { GluegunToolbox, filesystem } from 'gluegun'
import {
EthereumConfig,
Network,
SubstrateConfig,
} from '@buildwithsygma/sygma-sdk-core'
import { Wallet } from 'ethers'
import { KeyringPair } from '@polkadot/keyring/types'
import { InitializedWallets, RpcEndpoints } from '../../types'
import {
sendEvmUnpauseTransaction,
sendSubstrateUnpauseTransaction,
} from '../../utils'

module.exports = {
name: 'unpause',
run: async (toolbox: GluegunToolbox) => {
const { sharedConfig, wallet } = toolbox

const rawConfig = await sharedConfig.fetchSharedConfig()

const initializedWallets = (await wallet.initializeWallets(
rawConfig
)) as InitializedWallets

const evmNetworks = rawConfig.domains.filter(
(domain) => domain.type === Network.EVM
) as Array<EthereumConfig>

const substrateNetworks = rawConfig.domains.filter(
(domain) => domain.type === Network.SUBSTRATE
) as Array<SubstrateConfig>

const rpcEndpoints = filesystem.read(
'rpcEndpoints.json',
'json'
) as RpcEndpoints

if (evmNetworks) {
await sendEvmUnpauseTransaction(
evmNetworks,
rpcEndpoints,
initializedWallets[Network.EVM] as Wallet
)
}

if (substrateNetworks) {
await sendSubstrateUnpauseTransaction(
substrateNetworks,
rpcEndpoints,
initializedWallets[Network.SUBSTRATE] as unknown as KeyringPair,
true
)
}
},
}
4 changes: 4 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const EVM_BLOCK_CONFIRMATIONS: number = 2
export const EVM_DOMAIN_ID = 1

export * from './sharedConfig'
8 changes: 8 additions & 0 deletions src/constants/sharedConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const sharedConfig = {
devnet:
'https://chainbridge-assets-stage.s3.us-east-2.amazonaws.com/shared-config-dev.json',
testnet:
'https://chainbridge-assets-stage.s3.us-east-2.amazonaws.com/shared-config-test.json',
mainnet:
'https://sygma-assets-mainnet.s3.us-east-2.amazonaws.com/shared-config-mainnet.json',
}
Loading

0 comments on commit 177126a

Please sign in to comment.