-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial setup + pause/unpause commands
- Loading branch information
Showing
27 changed files
with
10,633 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require("@rushstack/eslint-patch/modern-module-resolution"); | ||
/** | ||
* @type {import("eslint").Linter.Config} | ||
*/ | ||
|
||
module.exports = { | ||
// parser: '@typescript-eslint/parser', | ||
|
||
// parserOptions: { | ||
// ecmaVersion: 2020, | ||
// sourceType: 'module', | ||
// }, | ||
extends: [ | ||
"@chainsafe", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { system, filesystem } from 'gluegun' | ||
|
||
const src = filesystem.path(__dirname, '..') | ||
|
||
const cli = async (cmd) => | ||
system.run( | ||
'node ' + filesystem.path(src, 'bin', 'maintenance-utils') + ` ${cmd}` | ||
) | ||
|
||
test('outputs version', async () => { | ||
const output = await cli('--version') | ||
expect(output).toContain('0.0.1') | ||
}) | ||
|
||
test('outputs help', async () => { | ||
const output = await cli('--help') | ||
expect(output).toContain('0.0.1') | ||
}) | ||
|
||
test('generates file', async () => { | ||
const output = await cli('generate foo') | ||
|
||
expect(output).toContain('Generated file at models/foo-model.ts') | ||
const foomodel = filesystem.read('models/foo-model.ts') | ||
|
||
expect(foomodel).toContain(`module.exports = {`) | ||
expect(foomodel).toContain(`name: 'foo'`) | ||
|
||
// cleanup artifact | ||
filesystem.remove('models') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 \"**/*.{js,jsx,ts,tsx}\" --fix && prettier \"**/*.{js,jsx,ts,tsx,json}\" --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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"chainId": "rpcUrl", | ||
"chainId": "rpcUrl", | ||
"chainId": "rpcUrl" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { build } from 'gluegun' | ||
|
||
/** | ||
* Create the cli and kick it off | ||
*/ | ||
async function run(argv) { | ||
// 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) | ||
|
||
// send it back (for testing, mostly) | ||
return toolbox | ||
} | ||
|
||
module.exports = { run } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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 { parameters, sharedConfig, wallet } = toolbox | ||
console.log('paramters-pause', parameters) | ||
|
||
const rawConfig = await sharedConfig.fetchSharedConfig() | ||
console.log('raw config', rawConfig) | ||
const initializedWallets = (await wallet.initializeWallets( | ||
rawConfig | ||
)) as InitializedWallets | ||
console.log('wallet', 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) { | ||
sendEvmPauseTransaction( | ||
evmNetworks, | ||
rpcEndpoints, | ||
initializedWallets[Network.EVM] as Wallet | ||
) | ||
} | ||
|
||
if (substrateNetworks) { | ||
sendSubstratePauseTransaction( | ||
substrateNetworks, | ||
rpcEndpoints, | ||
initializedWallets[Network.SUBSTRATE] as unknown as KeyringPair, | ||
true | ||
) | ||
} | ||
}, | ||
} |
Oops, something went wrong.