diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-09 19:02:25 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-09 19:02:25 +0800 |
commit | ea14913b412e78ff458bdfba47182f7363e776e5 (patch) | |
tree | 3ee220bfbbd9923b5e1adc36ee51f9b5d39ad640 /packages/migrations | |
parent | 5868c91cfb54cfa9177572b201d88d1168bf5b06 (diff) | |
parent | 5dd55491b86bf8577405e37d0f2d668aa1273b10 (diff) | |
download | dexon-0x-contracts-ea14913b412e78ff458bdfba47182f7363e776e5.tar dexon-0x-contracts-ea14913b412e78ff458bdfba47182f7363e776e5.tar.gz dexon-0x-contracts-ea14913b412e78ff458bdfba47182f7363e776e5.tar.bz2 dexon-0x-contracts-ea14913b412e78ff458bdfba47182f7363e776e5.tar.lz dexon-0x-contracts-ea14913b412e78ff458bdfba47182f7363e776e5.tar.xz dexon-0x-contracts-ea14913b412e78ff458bdfba47182f7363e776e5.tar.zst dexon-0x-contracts-ea14913b412e78ff458bdfba47182f7363e776e5.zip |
Merge development
Diffstat (limited to 'packages/migrations')
-rw-r--r-- | packages/migrations/.gitignore | 2 | ||||
-rw-r--r-- | packages/migrations/CHANGELOG.json | 56 | ||||
-rw-r--r-- | packages/migrations/CHANGELOG.md | 18 | ||||
-rw-r--r-- | packages/migrations/Dockerfile | 15 | ||||
-rw-r--r-- | packages/migrations/README.md | 41 | ||||
-rwxr-xr-x | packages/migrations/bin/0x-migrate.js | 2 | ||||
-rw-r--r-- | packages/migrations/package.json | 53 | ||||
-rw-r--r-- | packages/migrations/src/cli.ts | 38 | ||||
-rw-r--r-- | packages/migrations/src/index.ts | 10 | ||||
-rw-r--r-- | packages/migrations/src/migrate_snapshot.ts | 32 | ||||
-rw-r--r-- | packages/migrations/src/migration.ts | 28 | ||||
-rw-r--r-- | packages/migrations/typedoc-tsconfig.json | 7 |
12 files changed, 279 insertions, 23 deletions
diff --git a/packages/migrations/.gitignore b/packages/migrations/.gitignore new file mode 100644 index 000000000..4de81c5a8 --- /dev/null +++ b/packages/migrations/.gitignore @@ -0,0 +1,2 @@ +*.zip +0x_ganache_snapshot diff --git a/packages/migrations/CHANGELOG.json b/packages/migrations/CHANGELOG.json index 5b0d58909..cee64a69f 100644 --- a/packages/migrations/CHANGELOG.json +++ b/packages/migrations/CHANGELOG.json @@ -1,5 +1,61 @@ [ { + "version": "2.3.0", + "changes": [ + { + "note": "Added migrations for Dutch Auction contract", + "pr": 1465 + } + ] + }, + { + "version": "2.2.2", + "changes": [ + { + "note": "Dependencies updated" + } + ], + "timestamp": 1544739608 + }, + { + "version": "2.2.1", + "changes": [ + { + "note": "Dependencies updated" + } + ], + "timestamp": 1544570656 + }, + { + "version": "2.2.0", + "changes": [ + { + "note": "Add CLI `0x-migrate` for running the 0x migrations in a language-agnostic way", + "pr": 1324 + }, + { + "note": "Deploy testnet Exchange arfitact. Previously mainnet Exchange artifact was deployed.", + "pr": 1309 + }, + { + "note": "Fund the Forwarder with ZRX for fees.", + "pr": 1309 + } + ], + "timestamp": 1543401373 + }, + { + "version": "2.1.0", + "changes": [ + { + "note": + "Export all type declarations used by the public interface, as well as the `ContractAddresses` mapping", + "pr": 1301 + } + ], + "timestamp": 1542821676 + }, + { "timestamp": 1542208198, "version": "2.0.4", "changes": [ diff --git a/packages/migrations/CHANGELOG.md b/packages/migrations/CHANGELOG.md index 87d0b25ca..0b7b9a364 100644 --- a/packages/migrations/CHANGELOG.md +++ b/packages/migrations/CHANGELOG.md @@ -5,6 +5,24 @@ Edit the package's CHANGELOG.json file only. CHANGELOG +## v2.2.2 - _December 13, 2018_ + + * Dependencies updated + +## v2.2.1 - _December 11, 2018_ + + * Dependencies updated + +## v2.2.0 - _November 28, 2018_ + + * Add CLI `0x-migrate` for running the 0x migrations in a language-agnostic way (#1324) + * Deploy testnet Exchange arfitact. Previously mainnet Exchange artifact was deployed. (#1309) + * Fund the Forwarder with ZRX for fees. (#1309) + +## v2.1.0 - _November 21, 2018_ + + * Export all type declarations used by the public interface, as well as the `ContractAddresses` mapping (#1301) + ## v2.0.4 - _November 14, 2018_ * Dependencies updated diff --git a/packages/migrations/Dockerfile b/packages/migrations/Dockerfile new file mode 100644 index 000000000..c4d6128c2 --- /dev/null +++ b/packages/migrations/Dockerfile @@ -0,0 +1,15 @@ +FROM mhart/alpine-node:10 + +WORKDIR /usr/src/app + +RUN npm install -g ganache-cli@6.1.6 + +ENV MNEMONIC "concert load couple harbor equip island argue ramp clarify fence smart topic" +ENV NETWORK_ID 50 +ENV VERSION "latest" +ENV SNAPSHOT_HOST "http://ganache-snapshots.0x.org.s3-website.us-east-2.amazonaws.com" +ENV SNAPSHOT_NAME "0x_ganache_snapshot" +EXPOSE 8545 + +CMD [ "sh", "-c", "wget $SNAPSHOT_HOST/$SNAPSHOT_NAME-$VERSION.zip -O snapshot.zip && unzip snapshot.zip && ganache-cli --gasLimit 10000000 --db $SNAPSHOT_NAME --noVMErrorsOnRPCResponse -p 8545 --networkId \"$NETWORK_ID\" -m \"$MNEMONIC\" -h 0.0.0.0"] + diff --git a/packages/migrations/README.md b/packages/migrations/README.md index b90d730eb..1e8b92bf8 100644 --- a/packages/migrations/README.md +++ b/packages/migrations/README.md @@ -57,3 +57,44 @@ In order to migrate the V2 0x smart contracts to TestRPC/Ganache running at `htt ```bash yarn migrate:v2 ``` + +### Publish + +#### 0x Ganache Snapshot + +The 0x Ganache snapshot can be generated and published in this package. In order to build the snapshot for this version of migrations run: + +```bash +yarn build:snapshot +``` + +This will run the migrations in Ganache and output a zip file to be uploaded to the s3 bucket. For example, after running this command you will have created `0x_ganache_snapshot-2.2.2.zip`. To publish the zip file to the s3 bucket run: + +```bash +yarn publish:snapshot +``` + +This snapshot will now be publicly available at http://ganache-snapshots.0x.org.s3.amazonaws.com/0x_ganache_snapshot-latest.zip and also versioned with the package.json version. + +#### 0x Ganache Docker Image + +We also publish a simple docker image which downloads the latest snapshot, extracts and runs Ganache. This is not required to be built when migrations change as it always downloads and runs the latest zip file. If you have made changes to the Dockerfile then a publish of the image is required. To do this run: + +```bash +yarn build:snapshot:docker +yarn publish:snapshot:docker +``` + +The result is a published docker image to the 0xorg docker registry. To start the docker image run: + +```bash +docker run -p 8545:8545 -ti 0xorg/ganache-cli:latest +``` + +This will pull the latest zip in the s3 bucket, extract and start Ganache with the snapshot. + +In the event you need a specific version of the published Ganache snapshot run the following specifying the VERSION environment variable: + +```bash +docker run -e VERSION=2.2.2 -p 8545:8545 -ti 0xorg/ganache-cli:latest +``` diff --git a/packages/migrations/bin/0x-migrate.js b/packages/migrations/bin/0x-migrate.js new file mode 100755 index 000000000..59778c0fc --- /dev/null +++ b/packages/migrations/bin/0x-migrate.js @@ -0,0 +1,2 @@ +#!/usr/bin/env node +require('../lib/cli.js'); diff --git a/packages/migrations/package.json b/packages/migrations/package.json index 8eaae96ba..0d6ad037c 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -1,6 +1,6 @@ { "name": "@0x/migrations", - "version": "2.0.4", + "version": "2.2.2", "engines": { "node": ">=6.12" }, @@ -10,37 +10,56 @@ "scripts": { "build": "tsc -b", "build:ci": "yarn build", - "clean": "shx rm -rf lib", + "clean": "shx rm -rf lib ${npm_package_config_snapshot_name} ${npm_package_config_snapshot_name}-*.zip", "lint": "tslint --format stylish --project .", "migrate:v2": "run-s build script:migrate:v2", - "script:migrate:v2": "node ./lib/migrate.js --contracts-version 2.0.0" + "migrate:v2:snapshot": "run-s build script:migrate:v2:snapshot", + "script:migrate:v2": "node ./lib/migrate.js", + "script:migrate:v2:snapshot": "node ./lib/migrate_snapshot.js", + "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES", + "build:snapshot": "rm -rf ${npm_package_config_snapshot_name} && yarn migrate:v2:snapshot && zip -r \"${npm_package_config_snapshot_name}-${npm_package_version}.zip\" ${npm_package_config_snapshot_name}", + "build:snapshot:docker": "docker build --tag ${npm_package_config_docker_snapshot_name}:${npm_package_version} --tag ${npm_package_config_docker_snapshot_name}:latest .", + "publish:snapshot": "aws s3 cp ${npm_package_config_snapshot_name}-${npm_package_version}.zip ${npm_package_config_s3_snapshot_bucket} && aws s3 cp ${npm_package_config_s3_snapshot_bucket}/${npm_package_config_snapshot_name}-${npm_package_version}.zip ${npm_package_config_s3_snapshot_bucket}/${npm_package_config_snapshot_name}-latest.zip", + "publish:snapshot:docker": "docker push ${npm_package_config_docker_snapshot_name}:latest" + }, + "config": { + "s3_snapshot_bucket": "s3://ganache-snapshots.0x.org", + "docker_snapshot_name": "0xorg/ganache-cli", + "snapshot_name": "0x_ganache_snapshot", + "postpublish": { + "assets": [] + } + }, + "bin": { + "0x-migrate": "bin/0x-migrate.js" }, "license": "Apache-2.0", "devDependencies": { - "@0x/dev-utils": "^1.0.17", - "@0x/tslint-config": "^1.0.10", - "@0x/types": "^1.2.1", + "@0x/dev-utils": "^1.0.21", + "@0x/tslint-config": "^2.0.0", + "@0x/types": "^1.4.1", "@types/yargs": "^10.0.0", "make-promises-safe": "^1.1.0", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "tslint": "5.11.0", + "typedoc": "0.13.0", "typescript": "3.0.1", "yargs": "^10.0.3" }, "dependencies": { - "@0x/abi-gen-wrappers": "^1.0.5", - "@0x/base-contract": "^3.0.6", - "@0x/contract-addresses": "^1.1.0", - "@0x/contract-artifacts": "^1.1.0", - "@0x/order-utils": "^3.0.2", - "@0x/sol-compiler": "^1.1.12", - "@0x/subproviders": "^2.1.4", - "@0x/typescript-typings": "^3.0.4", - "@0x/utils": "^2.0.5", - "@0x/web3-wrapper": "^3.1.4", + "@0x/abi-gen-wrappers": "^2.0.2", + "@0x/base-contract": "^3.0.10", + "@0x/contract-addresses": "^2.0.0", + "@0x/contract-artifacts": "^1.1.2", + "@0x/order-utils": "^3.0.7", + "@0x/sol-compiler": "^1.1.16", + "@0x/subproviders": "^2.1.8", + "@0x/typescript-typings": "^3.0.6", + "@0x/utils": "^2.0.8", + "@0x/web3-wrapper": "^3.2.1", "@ledgerhq/hw-app-eth": "^4.3.0", - "ethereum-types": "^1.1.2", + "ethereum-types": "^1.1.4", "ethers": "~4.0.4", "lodash": "^4.17.5" }, diff --git a/packages/migrations/src/cli.ts b/packages/migrations/src/cli.ts new file mode 100644 index 000000000..2404e7921 --- /dev/null +++ b/packages/migrations/src/cli.ts @@ -0,0 +1,38 @@ +#!/usr/bin/env node +import { RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders'; +import { logUtils } from '@0x/utils'; +import * as yargs from 'yargs'; + +import { runMigrationsAsync } from './migration'; + +const args = yargs + .option('rpc-url', { + describe: 'Endpoint where backing Ethereum JSON RPC interface is available', + type: 'string', + demandOption: false, + default: 'http://localhost:8545', + }) + .option('from', { + describe: 'Ethereum address from which to deploy the contracts', + type: 'string', + demandOption: true, + }) + .example( + '$0 --rpc-url http://localhost:8545 --from 0x5409ed021d9299bf6814279a6a1411a7e866a631', + 'Full usage example', + ).argv; + +(async () => { + const rpcSubprovider = new RPCSubprovider(args['rpc-url']); + const provider = new Web3ProviderEngine(); + provider.addProvider(rpcSubprovider); + provider.start(); + const txDefaults = { + from: args.from, + }; + await runMigrationsAsync(provider, txDefaults); + process.exit(0); +})().catch(err => { + logUtils.log(err); + process.exit(1); +}); diff --git a/packages/migrations/src/index.ts b/packages/migrations/src/index.ts index 8f629a24b..4f22c30b9 100644 --- a/packages/migrations/src/index.ts +++ b/packages/migrations/src/index.ts @@ -1 +1,11 @@ +export { + Provider, + TxData, + JSONRPCRequestPayload, + JSONRPCErrorCallback, + TxDataPayable, + JSONRPCResponsePayload, + JSONRPCResponseError, +} from 'ethereum-types'; +export { ContractAddresses } from '@0x/contract-addresses'; export { runMigrationsAsync, runMigrationsOnceAsync } from './migration'; diff --git a/packages/migrations/src/migrate_snapshot.ts b/packages/migrations/src/migrate_snapshot.ts new file mode 100644 index 000000000..13fb063da --- /dev/null +++ b/packages/migrations/src/migrate_snapshot.ts @@ -0,0 +1,32 @@ +#!/usr/bin/env node +import { devConstants, web3Factory } from '@0x/dev-utils'; +import { logUtils } from '@0x/utils'; +import { Provider } from 'ethereum-types'; +import * as fs from 'fs'; +import * as _ from 'lodash'; +import * as path from 'path'; + +import { runMigrationsAsync } from './migration'; + +(async () => { + let providerConfigs; + let provider: Provider; + let txDefaults; + const packageJsonPath = path.join(__dirname, '..', 'package.json'); + const packageJsonString = fs.readFileSync(packageJsonPath, 'utf8'); + const packageJson = JSON.parse(packageJsonString); + if (_.isUndefined(packageJson.config) || _.isUndefined(packageJson.config.snapshot_name)) { + throw new Error(`Did not find 'snapshot_name' key in package.json config`); + } + + providerConfigs = { shouldUseInProcessGanache: true, ganacheDatabasePath: packageJson.config.snapshot_name }; + provider = web3Factory.getRpcProvider(providerConfigs); + txDefaults = { + from: devConstants.TESTRPC_FIRST_ADDRESS, + }; + await runMigrationsAsync(provider, txDefaults); + process.exit(0); +})().catch(err => { + logUtils.log(err); + process.exit(1); +}); diff --git a/packages/migrations/src/migration.ts b/packages/migrations/src/migration.ts index 86c76a54b..99d1719f1 100644 --- a/packages/migrations/src/migration.ts +++ b/packages/migrations/src/migration.ts @@ -11,10 +11,9 @@ import { erc20TokenInfo, erc721TokenInfo } from './utils/token_info'; /** * Creates and deploys all the contracts that are required for the latest - * version of the 0x protocol. Custom migrations can be defined here. This will - * be called with the CLI 'migrate:v2' command. - * @param provider Web3 provider instance. - * @param txDefaults Default transaction values to use when deploying contracts. + * version of the 0x protocol. + * @param provider Web3 provider instance. Your provider instance should connect to the testnet you want to deploy to. + * @param txDefaults Default transaction values to use when deploying contracts (e.g., specify the desired contract creator with the `from` parameter). * @returns The addresses of the contracts that were deployed. */ export async function runMigrationsAsync(provider: Provider, txDefaults: Partial<TxData>): Promise<ContractAddresses> { @@ -48,6 +47,7 @@ export async function runMigrationsAsync(provider: Provider, txDefaults: Partial artifacts.Exchange, provider, txDefaults, + zrxAssetData, ); // Multisigs @@ -141,6 +141,21 @@ export async function runMigrationsAsync(provider: Provider, txDefaults: Partial zrxAssetData, ); + // DutchAuction + const dutchAuction = await wrappers.DutchAuctionContract.deployFrom0xArtifactAsync( + artifacts.DutchAuction, + provider, + txDefaults, + exchange.address, + ); + + // Fund the Forwarder with ZRX + const zrxDecimals = await zrxToken.decimals.callAsync(); + const zrxForwarderAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(5000), zrxDecimals); + await web3Wrapper.awaitTransactionSuccessAsync( + await zrxToken.transfer.sendTransactionAsync(forwarder.address, zrxForwarderAmount, txDefaults), + ); + return { erc20Proxy: erc20Proxy.address, erc721Proxy: erc721Proxy.address, @@ -150,6 +165,7 @@ export async function runMigrationsAsync(provider: Provider, txDefaults: Partial assetProxyOwner: assetProxyOwner.address, forwarder: forwarder.address, orderValidator: orderValidator.address, + dutchAuction: dutchAuction.address, }; } @@ -159,8 +175,8 @@ let _cachedContractAddresses: ContractAddresses; * Exactly like runMigrationsAsync but will only run the migrations the first * time it is called. Any subsequent calls will return the cached contract * addresses. - * @param provider Web3 provider instance. - * @param txDefaults Default transaction values to use when deploying contracts. + * @param provider Web3 provider instance. Your provider instance should connect to the testnet you want to deploy to. + * @param txDefaults Default transaction values to use when deploying contracts (e.g., specify the desired contract creator with the `from` parameter). * @returns The addresses of the contracts that were deployed. */ export async function runMigrationsOnceAsync( diff --git a/packages/migrations/typedoc-tsconfig.json b/packages/migrations/typedoc-tsconfig.json new file mode 100644 index 000000000..c9b0af1ae --- /dev/null +++ b/packages/migrations/typedoc-tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../typedoc-tsconfig", + "compilerOptions": { + "outDir": "lib" + }, + "include": ["./src/**/*", "./test/**/*"] +} |