Merge pull request #323 from 0xProject/feature/separate-deployer

Move deployer to a separate package
This commit is contained in:
Leonid
2018-01-19 13:43:32 +01:00
committed by GitHub
41 changed files with 244 additions and 33 deletions

View File

@@ -52,7 +52,7 @@ jobs:
name: testrpc
command: npm run testrpc -- --db testrpc_snapshot
background: true
- run: yarn lerna:run --scope contracts test:circleci:contracts
- run: yarn lerna:run --scope contracts test:circleci
test-deployer:
docker:
- image: circleci/node:6.12
@@ -65,7 +65,7 @@ jobs:
name: testrpc
command: npm run testrpc -- --db testrpc_snapshot
background: true
- run: yarn lerna:run --scope contracts test:circleci:deployer
- run: yarn lerna:run --scope @0xproject/deployer test:circleci
test-rest:
docker:
- image: circleci/node:6.12
@@ -78,7 +78,7 @@ jobs:
name: testrpc
command: npm run testrpc -- --db testrpc_snapshot
background: true
- run: yarn lerna:run --ignore contracts --ignore 0x.js --ignore subproviders test:circleci
- run: yarn lerna:run --ignore contracts --ignore 0x.js --ignore @0xproject/deployer test:circleci
lint:
working_directory: ~/repo
docker:

View File

@@ -11,14 +11,13 @@
"build":
"rm -rf ./lib; copyfiles ./build/**/* ./deploy/solc/solc_bin/* ./deploy/test/fixtures/contracts/**/* ./deploy/test/fixtures/contracts/* ./lib; tsc;",
"test": "npm run build; truffle test",
"compile": "npm run build; node lib/deploy/cli.js compile",
"compile:comment":
"Yarn workspaces do not link binaries correctly so we need to reference them directly https://github.com/yarnpkg/yarn/issues/3846",
"compile": "node ../deployer/lib/src/cli.js compile",
"clean": "rm -rf ./lib",
"migrate:truffle": "npm run build; truffle migrate",
"migrate": "npm run build; node lib/deploy/cli.js migrate",
"migrate": "node ../deployer/lib/src/cli.js migrate",
"lint": "tslint --project . 'migrations/**/*.ts' 'test/**/*.ts' 'util/**/*.ts' 'deploy/**/*.ts'",
"test:circleci:contracts": "yarn test",
"test:circleci:deployer": "yarn test:deployer",
"test:deployer": "npm run build; mocha lib/deploy/test/*_test.js"
"test:circleci": "yarn test"
},
"repository": {
"type": "git",
@@ -58,6 +57,7 @@
},
"dependencies": {
"0x.js": "^0.30.0",
"@0xproject/deployer": "*",
"@0xproject/json-schemas": "^0.7.3",
"@0xproject/utils": "^0.2.0",
"@0xproject/web3-wrapper": "^0.1.5",

View File

@@ -84,15 +84,6 @@ export interface TransactionDataParams {
args: any[];
}
export interface Token {
address?: string;
name: string;
symbol: string;
decimals: number;
ipfsHash: string;
swarmHash: string;
}
export interface MultiSigConfig {
owners: string[];
confirmationsRequired: number;
@@ -103,6 +94,15 @@ export interface MultiSigConfigByNetwork {
[networkName: string]: MultiSigConfig;
}
export interface Token {
address?: string;
name: string;
symbol: string;
decimals: number;
ipfsHash: string;
swarmHash: string;
}
export interface TokenInfoByNetwork {
development: Token[];
live: Token[];

View File

@@ -0,0 +1,73 @@
## @0xproject/deployer
This repository contains a CLI tool that facilitates compiling and deployment of smart contracts.
## Installation
```bash
yarn add @0xproject/deployer
```
## Usage
```bash
node ./node_modules/@0xproject/deployer/lib/cli.js --help
cli.js [command]
Commands:
cli.js compile compile contracts
cli.js migrate compile and deploy contracts using migration scripts
cli.js deploy deploy a single contract with provided arguments
Options:
--version Show version number [boolean]
--contracts-dir path of contracts directory to compile
[string] [default: "/Users/leonidlogvinov/Dev/0x/0x.js/contracts"]
--network-id mainnet=1, kovan=42, testrpc=50 [number] [default: 50]
--should-optimize enable optimizer [boolean] [default: false]
--artifacts-dir path to write contracts artifacts to
[string] [default: "/Users/leonidlogvinov/Dev/0x/0x.js/build/artifacts/"]
--jsonrpc-port port connected to JSON RPC [number] [default: 8545]
--gas-price gasPrice to be used for transactions
[string] [default: "2000000000"]
--account account to use for deploying contracts [string]
--help Show help [boolean]
```
## Contributing
We strongly recommend that the community help us make improvements and determine the future direction of the protocol. To report bugs within this package, please create an issue in this repository.
Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
### Install Dependencies
If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
```bash
yarn config set workspaces-experimental true
```
Then install dependencies
```bash
yarn install
```
### Build
```bash
yarn build
```
### Lint
```bash
yarn lint
```
### Run Tests
```bash
yarn test
```

View File

@@ -0,0 +1,43 @@
{
"name": "@0xproject/deployer",
"version": "0.0.1",
"description": "Smart contract deployer of 0x protocol",
"main": "lib/src/cli.js",
"scripts": {
"build": "yarn clean && copyfiles 'test/fixtures/contracts/**/*' src/solc/solc_bin/* ./lib && tsc",
"test": "npm run build; mocha lib/test/*_test.js",
"compile": "npm run build; node lib/src/cli.js compile",
"clean": "rm -rf ./lib",
"migrate": "npm run build; node lib/src/cli.js migrate",
"lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'",
"test:circleci": "yarn test"
},
"bin": {
"0x-deployer": "lib/src/cli.js"
},
"repository": {
"type": "git",
"url": "https://github.com/0xProject/0x.js.git"
},
"author": "Amir Bandeali",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/0xProject/0x.js/issues"
},
"homepage": "https://github.com/0xProject/0x.js/packages/deployer/README.md",
"devDependencies": {
"copyfiles": "^1.2.0",
"web3-typescript-typings": "^0.9.3",
"types-bn": "^0.0.1",
"typescript": "~2.6.1"
},
"dependencies": {
"@0xproject/utils": "^0.1.3",
"@0xproject/web3-wrapper": "^0.1.4",
"lodash": "^4.17.4",
"solc": "^0.4.18",
"yargs": "^10.0.3",
"web3-eth-abi": "^1.0.0-beta.24",
"web3": "^0.20.0"
}
}

View File

@@ -0,0 +1,39 @@
const execAsync = require('async-child-process').execAsync;
const postpublish_utils = require('../../../scripts/postpublish_utils');
const packageJSON = require('../package.json');
const cwd = __dirname + '/..';
const subPackageName = packageJSON.name;
const S3BucketPath = 's3://connect-docs-jsons/';
let tag;
let version;
postpublish_utils
.getLatestTagAndVersionAsync(subPackageName)
.then(function(result) {
tag = result.tag;
version = result.version;
const releaseName = postpublish_utils.getReleaseName(subPackageName, version);
return postpublish_utils.publishReleaseNotes(tag, releaseName);
})
.then(function(release) {
console.log('POSTPUBLISH: Release successful, generating docs...');
const jsonFilePath = __dirname + '/../' + postpublish_utils.generatedDocsDirectoryName + '/index.json';
return execAsync('JSON_FILE_PATH=' + jsonFilePath + ' PROJECT_DIR=' + __dirname + '/.. yarn docs:json', {
cwd,
});
})
.then(function(result) {
if (result.stderr !== '') {
throw new Error(result.stderr);
}
const fileName = 'v' + version + '.json';
console.log('POSTPUBLISH: Doc generation successful, uploading docs... as ', fileName);
const s3Url = S3BucketPath + fileName;
return execAsync('S3_URL=' + s3Url + ' yarn upload_docs_json', {
cwd,
});
})
.catch(function(err) {
throw err;
});

View File

@@ -5,8 +5,8 @@ import * as path from 'path';
import * as Web3 from 'web3';
import * as yargs from 'yargs';
import { commands } from './src/commands';
import { CliOptions, CompilerOptions, DeployerOptions } from './src/utils/types';
import { commands } from './commands';
import { CliOptions, CompilerOptions, DeployerOptions } from './utils/types';
const DEFAULT_OPTIMIZER_ENABLED = false;
const DEFAULT_CONTRACTS_DIR = path.resolve('contracts');

View File

@@ -1,4 +1,4 @@
import { migrator } from './../migrations/migrate';
import { migrator } from './migrations/migrate';
import { Compiler } from './compiler';
import { Deployer } from './deployer';
import { CompilerOptions, DeployerOptions } from './utils/types';

View File

@@ -4,7 +4,7 @@ import * as path from 'path';
import solc = require('solc');
import * as Web3 from 'web3';
import { binPaths } from './../solc/bin_paths';
import { binPaths } from './solc/bin_paths';
import { fsWrapper } from './utils/fs_wrapper';
import {
CompilerOptions,
@@ -113,7 +113,6 @@ export class Compiler {
public async compileAllAsync(): Promise<void> {
await this._createArtifactsDirIfDoesNotExistAsync();
this._contractSourcesIfExists = await Compiler._getContractSourcesAsync(this._contractsDir);
const contractBaseNames = _.keys(this._contractSourcesIfExists);
const compiledContractPromises = _.map(contractBaseNames, async (contractBaseName: string): Promise<void> => {
return this._compileContractAsync(contractBaseName);
@@ -167,7 +166,7 @@ export class Compiler {
};
const solcVersion = Compiler._parseSolidityVersion(source);
const fullSolcVersion = binPaths[solcVersion];
const solcBinPath = `./../solc/solc_bin/${fullSolcVersion}`;
const solcBinPath = `./solc/solc_bin/${fullSolcVersion}`;
const solcBin = require(solcBinPath);
const solcInstance = solc.setupMethods(solcBin);

8
packages/deployer/src/globals.d.ts vendored Normal file
View File

@@ -0,0 +1,8 @@
declare module 'solc' {
export function compile(sources: any, optimizerEnabled: number, findImports: (importPath: string) => any): any;
export function setupMethods(solcBin: any): any;
}
declare module 'web3-eth-abi' {
export function encodeParameters(typesArray: string[], parameters: any[]): string;
}

View File

@@ -0,0 +1,10 @@
import { MultiSigConfigByNetwork } from '../../types';
// Make a copy of this file named `multisig.js` and input custom params as needed
export const multiSig: MultiSigConfigByNetwork = {
kovan: {
owners: [],
confirmationsRequired: 0,
secondsRequired: 0,
},
};

View File

@@ -1,5 +1,5 @@
import { constants } from './../../src/utils/constants';
import { Token } from './../../src/utils/types';
import { constants } from '../../utils/constants';
import { Token } from '../../types';
export const tokenInfo: Token[] = [
{

View File

@@ -2,8 +2,8 @@ import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import { Deployer } from './../src/deployer';
import { constants } from './../src/utils/constants';
import { Deployer } from '../deployer';
import { constants } from '../utils/constants';
import { tokenInfo } from './config/token_info';
export const migrator = {

View File

@@ -0,0 +1,23 @@
export interface MultiSigConfig {
owners: string[];
confirmationsRequired: number;
secondsRequired: number;
}
export interface MultiSigConfigByNetwork {
[networkName: string]: MultiSigConfig;
}
export interface Token {
address?: string;
name: string;
symbol: string;
decimals: number;
ipfsHash: string;
swarmHash: string;
}
export interface TokenInfoByNetwork {
development: Token[];
live: Token[];
}

View File

@@ -1,10 +1,10 @@
import * as chai from 'chai';
import 'mocha';
import { Compiler } from './../src/compiler';
import { Deployer } from './../src/deployer';
import { fsWrapper } from './../src/utils/fs_wrapper';
import { CompilerOptions, ContractArtifact, ContractData, DoneCallback } from './../src/utils/types';
import { Compiler } from '../src/compiler';
import { Deployer } from '../src/deployer';
import { fsWrapper } from '../src/utils/fs_wrapper';
import { CompilerOptions, ContractArtifact, ContractData, DoneCallback } from '../src/utils/types';
import { constructor_args, exchange_binary } from './fixtures/exchange_bin';
import { constants } from './util/constants';

View File

@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib",
"strictFunctionTypes": false,
"strictNullChecks": false
},
"include": [
"./src/**/*",
"./test/**/*",
"../../node_modules/types-bn/index.d.ts",
"../../node_modules/types-ethereumjs-util/index.d.ts",
"../../node_modules/chai-typescript-typings/index.d.ts",
"../../node_modules/web3-typescript-typings/index.d.ts"
]
}

View File

@@ -2,7 +2,7 @@
# yarn lockfile v1
"@0xproject/utils@^0.1.0":
"@0xproject/utils@^0.1.0", "@0xproject/utils@^0.1.3":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@0xproject/utils/-/utils-0.1.3.tgz#58a9c7e19ab7710e0af17a0c2f1c7fc1b3140e85"
dependencies: