-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup Chain Contract Deployment Script (#486)
Contract changes: * Emitting NewBlock event and including transitions in it Deployment: * Adding deploy script to deploy rollup-chain smart contracts * Adding configuration for different environments and requiring the user to pass an environment parameter to prevent mistakes Other: * Updating README to remove a bunch of old stuff.
- Loading branch information
1 parent
648da33
commit f9a6158
Showing
8 changed files
with
186 additions
and
69 deletions.
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,23 @@ | ||
################ | ||
# Instructions # | ||
################ | ||
# Create environment file(s) named ".<environment>.env" in this same location using this file as a template | ||
# For instance `yarn run deploy:some-contract local` will use .local.env for configuration. | ||
|
||
|
||
############ | ||
# Template # | ||
############ | ||
|
||
# REQUIRED | ||
DEPLOY_MNEMONIC='your mnemonic here' | ||
# Note: can use any network name. 'local' or leaving it blank will deploy to DEPLOY_LOCAL_URL | ||
DEPLOY_NETWORK='local' | ||
|
||
# Only if deploying locally | ||
DEPLOY_LOCAL_URL='http://127.0.0.1:7545' | ||
|
||
# Only if contracts are already deployed | ||
DEPLOY_EVALUATOR_CONTRACT_ADDRESS='address if it is deployed' | ||
DEPLOY_MERKLE_UTILS_CONTRACT_ADDRESS='address if it is deployed' | ||
|
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,2 @@ | ||
.*.env | ||
|
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,69 +1,39 @@ | ||
# plasma-contracts | ||
[![Build Status](https://travis-ci.org/plasma-group/plasma-contracts.svg?branch=master)](https://travis-ci.org/plasma-group/plasma-contracts) | ||
|
||
`plasma-contracts` is the set of smart contracts written in Vyper for the Plasma Group series of projects. It includes an implementation of a Plasma Cash variant, and a registry contract for discovering Plasma chains. This repo is used for compiling those contracts--If you don't need any modifications, you can spin up your own with [`plasma-chain-operator`](https://github.com/plasma-group/plasma-chain-operator) or try out other chains with [`@pigi/plasma-js`](https://github.com/plasma-group/@pigi/plasma-js). | ||
|
||
## Contributing | ||
If you're looking to contribute to `plasma-contracts`, you're in the right place. Welcome! | ||
|
||
### Contributing Guide and CoC | ||
Plasma Group follows a [Contributing Guide and Code of Conduct](https://github.com/plasma-group/plasma-utils/blob/master/.github/CONTRIBUTING.md) adapted slightly from the [Contributor Covenant](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html). All contributors are expected to read through this guide. We're here to cultivate a welcoming and inclusive contributing environment, and every new contributor needs to do their part to uphold our community standards. | ||
# contracts | ||
`contracts` is the set of smart contracts written in Solidity for the Plasma Group series of projects. | ||
|
||
### Requirements and Setup | ||
The first step is cloning this repo. Via https: | ||
|
||
```sh | ||
git clone https://github.com/plasma-group/plasma-contracts.git | ||
``` | ||
or ssh: | ||
```sh | ||
git clone git@github.com:plasma-group/plasma-contracts.git | ||
``` | ||
Clone the parent repo `pigi` and follow its instructions. | ||
|
||
#### Node.js | ||
`plasma-contracts` is tested with [`Node.js`](https://nodejs.org/en/) and has been tested on the following versions of Node: | ||
`contracts` is tested with [`Node.js`](https://nodejs.org/en/) and has been tested on the following versions of Node: | ||
|
||
- 11.6.0 | ||
|
||
If you're having trouble getting `plasma-contracts` tests running, please make sure you have one of the above `Node.js` versions installed. | ||
If you're having trouble getting `contracts` tests running, please make sure you have one of the above `Node.js` versions installed. | ||
|
||
#### Packages | ||
`plasma-contracts` makes use of several `npm` packages. | ||
### Running Tests | ||
`contracts` makes use of a combination of [`Mocha`](https://mochajs.org/) (a testing framework) and [`Chai`](https://www.chaijs.com/) (an assertion library) for testing. | ||
|
||
Install all required packages with: | ||
Run all tests with: | ||
|
||
```sh | ||
npm install | ||
yarn test | ||
``` | ||
So that Python and Vyper aren't requirements for our other components, we do include a `compiled-contracts` folder which contains JS exports of the bytecode and ABI. Compilation is done automatically before testing. | ||
|
||
#### Python and Vyper | ||
`plasma-contracts` is written in Vyper, a pythonic Ethereum smart contract language. You'll need [Python 3.6 or above](https://www.python.org/downloads/) to install Vyper. | ||
|
||
We reccomend setting up a [virtual environment](https://cewing.github.io/training.python_web/html/presentations/venv_intro.html) instead of installing globally: | ||
### Deploying | ||
You can deploy by running: | ||
|
||
```sh | ||
python3 -m venv venv | ||
yarn run deploy:<contract-specific-task-here> <environment> | ||
``` | ||
|
||
To activate: | ||
|
||
```sh | ||
source venv/bin/activate | ||
``` | ||
The `environment` parameter tells the deployment script which config file to use (expected filename `.<environment>.env`). | ||
|
||
Install Vyper: | ||
For instance, to deploy the RollupChain contract using `.local.env` as the config file, you would run: | ||
|
||
```sh | ||
pip3 install vyper | ||
yarn run deploy:rollup-chain local | ||
``` | ||
Your `venv` must be activated whenever testing or otherwise using Vyper, but it will break the `npm install`, so be sure to `$ deactivate` if you still need to do that and reactivate afterwards. | ||
|
||
### Running Tests | ||
`plasma-contracts` makes use of a combination of [`Mocha`](https://mochajs.org/) (a testing framework) and [`Chai`](https://www.chaijs.com/) (an assertion library) for testing. | ||
|
||
Run all tests with: | ||
|
||
```sh | ||
npm test | ||
``` | ||
So that Python and Vyper aren't requirements for our other components, we do include a `compiled-contracts` folder which contains JS exports of the bytecode and ABI. Compilation is done automatically before testing. | ||
See `.env.example` for more information. |
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
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,113 @@ | ||
import { Contract, ContractFactory, Wallet, ethers } from 'ethers' | ||
import { config } from 'dotenv' | ||
import { resolve } from 'path' | ||
|
||
import * as RollupChain from '../build/RollupChain.json' | ||
import * as UnipigTransitionEvaluator from '../build/UnipigTransitionEvaluator.json' | ||
import * as RollupMerkleUtils from '../build/RollupMerkleUtils.json' | ||
import { Provider } from 'ethers/providers' | ||
|
||
// Make sure an environment argument was passed | ||
if ( | ||
!process.argv.length || | ||
process.argv[process.argv.length - 1].endsWith('.js') | ||
) { | ||
console.log( | ||
'\n\nError: Environment argument not provided. Usage: "yarn run deploy:rollup-chain <env>"\n' | ||
) | ||
process.exit(0) | ||
} | ||
|
||
// Get the environment and read the appropriate environment file | ||
const environment = process.argv[process.argv.length - 1] | ||
// Note: Path is from 'build/deploy/deploy-rollup-chain.js' | ||
config({ path: resolve(__dirname, `../../.${environment}.env`) }) | ||
|
||
const deployContract = async ( | ||
contractJson: any, | ||
wallet: Wallet, | ||
...args: any | ||
): Promise<Contract> => { | ||
const factory = new ContractFactory( | ||
contractJson.abi, | ||
contractJson.bytecode, | ||
wallet | ||
) | ||
const contract = await factory.deploy(...args) | ||
console.log( | ||
`Address: [${contract.address}], Tx: [${contract.deployTransaction.hash}]` | ||
) | ||
return contract.deployed() | ||
} | ||
|
||
const deployContracts = async (wallet: Wallet): Promise<void> => { | ||
let evaluatorContractAddress = process.env.DEPLOY_EVALUATOR_CONTRACT_ADDRESS | ||
if (!evaluatorContractAddress) { | ||
console.log('Deploying UnipigTransitionEvaluator...') | ||
const transitionEvaluator = await deployContract( | ||
UnipigTransitionEvaluator, | ||
wallet | ||
) | ||
evaluatorContractAddress = transitionEvaluator.address | ||
console.log('UnipigTransitionEvaluator deployed!\n\n') | ||
} else { | ||
console.log( | ||
`Using UnipigTransitionEvaluator contract at ${evaluatorContractAddress}\n` | ||
) | ||
} | ||
|
||
let merkleUtilsCnontractAddress = | ||
process.env.DEPLOY_MERKLE_UTILS_CONTRACT_ADDRESS | ||
if (!merkleUtilsCnontractAddress) { | ||
console.log('Deploying RollupMerkleUtils...') | ||
const merkleUtils = await deployContract(RollupMerkleUtils, wallet) | ||
merkleUtilsCnontractAddress = merkleUtils.address | ||
console.log('RollupMerkleUtils deployed!\n\n') | ||
} else { | ||
console.log( | ||
`Using RollupMerkleUtils contract at ${merkleUtilsCnontractAddress}\n` | ||
) | ||
} | ||
|
||
console.log('Deploying RollupChain...') | ||
const rollupChain = await deployContract( | ||
RollupChain, | ||
wallet, | ||
evaluatorContractAddress, | ||
merkleUtilsCnontractAddress | ||
) | ||
console.log('RollupChain deployed!\n\n') | ||
} | ||
|
||
const deploy = async (): Promise<void> => { | ||
console.log(`\n\n********** STARTING DEPLOYMENT ***********\n\n`) | ||
// Make sure mnemonic exists | ||
const deployMnemonic = process.env.DEPLOY_MNEMONIC | ||
if (!deployMnemonic) { | ||
console.log( | ||
`Error: No DEPLOY_MNEMONIC env var set. Please add it to .<environment>.env file it and try again. See .env.example for more info.\n` | ||
) | ||
return | ||
} | ||
|
||
// Connect provider | ||
let provider: Provider | ||
const network = process.env.DEPLOY_NETWORK | ||
if (!network || network === 'local') { | ||
provider = new ethers.providers.JsonRpcProvider( | ||
process.env.DEPLOY_LOCAL_URL || 'http://127.0.0.1:7545' | ||
) | ||
} else { | ||
provider = ethers.getDefaultProvider(network) | ||
} | ||
|
||
// Create wallet | ||
const wallet = Wallet.fromMnemonic(deployMnemonic).connect(provider) | ||
|
||
console.log(`\nDeploying to network [${network || 'local'}] in 5 seconds!\n`) | ||
setTimeout(() => { | ||
deployContracts(wallet) | ||
}, 5_000) | ||
} | ||
|
||
deploy() |
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
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,6 +1,7 @@ | ||
{ | ||
"extends": ["./../../tslint.json"], | ||
"rules": { | ||
"prettier": [true, "./.prettierrc.js"] | ||
"prettier": [true, "./.prettierrc.js"], | ||
"no-console": false | ||
} | ||
} |
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