diff options
author | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
---|---|---|
committer | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
commit | 7ae38906926dc09bc10670c361af0d2bf0050426 (patch) | |
tree | 5fb10ae366b987db09e4ddb4bc3ba0f75404ad08 /packages/migrations/src | |
parent | b5fd3c72a08aaa6957917d74c333387a16edf66b (diff) | |
download | dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.gz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.bz2 dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.lz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.xz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.zst dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.zip |
Update dependency packages
Diffstat (limited to 'packages/migrations/src')
-rw-r--r-- | packages/migrations/src/cli.ts | 38 | ||||
-rw-r--r-- | packages/migrations/src/index.ts | 11 | ||||
-rw-r--r-- | packages/migrations/src/migrate.ts | 23 | ||||
-rw-r--r-- | packages/migrations/src/migrate_snapshot.ts | 32 | ||||
-rw-r--r-- | packages/migrations/src/migration.ts | 232 | ||||
-rw-r--r-- | packages/migrations/src/types.ts | 29 | ||||
-rw-r--r-- | packages/migrations/src/utils/constants.ts | 18 | ||||
-rw-r--r-- | packages/migrations/src/utils/provider_factory.ts | 39 | ||||
-rw-r--r-- | packages/migrations/src/utils/token_info.ts | 62 |
9 files changed, 0 insertions, 484 deletions
diff --git a/packages/migrations/src/cli.ts b/packages/migrations/src/cli.ts deleted file mode 100644 index 2404e7921..000000000 --- a/packages/migrations/src/cli.ts +++ /dev/null @@ -1,38 +0,0 @@ -#!/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 deleted file mode 100644 index 4f22c30b9..000000000 --- a/packages/migrations/src/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -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.ts b/packages/migrations/src/migrate.ts deleted file mode 100644 index d7a76d2f8..000000000 --- a/packages/migrations/src/migrate.ts +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env node -import { devConstants, web3Factory } from '@0x/dev-utils'; -import { logUtils } from '@0x/utils'; -import { Provider } from 'ethereum-types'; - -import { runMigrationsAsync } from './migration'; - -(async () => { - let providerConfigs; - let provider: Provider; - let txDefaults; - - providerConfigs = { shouldUseInProcessGanache: false }; - 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/migrate_snapshot.ts b/packages/migrations/src/migrate_snapshot.ts deleted file mode 100644 index 13fb063da..000000000 --- a/packages/migrations/src/migrate_snapshot.ts +++ /dev/null @@ -1,32 +0,0 @@ -#!/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 deleted file mode 100644 index e0f245017..000000000 --- a/packages/migrations/src/migration.ts +++ /dev/null @@ -1,232 +0,0 @@ -import * as wrappers from '@0x/abi-gen-wrappers'; -import { ContractAddresses } from '@0x/contract-addresses'; -import * as artifacts from '@0x/contract-artifacts'; -import { assetDataUtils } from '@0x/order-utils'; -import { BigNumber } from '@0x/utils'; -import { Web3Wrapper } from '@0x/web3-wrapper'; -import { Provider, TxData } from 'ethereum-types'; -import * as _ from 'lodash'; - -import { erc20TokenInfo, erc721TokenInfo } from './utils/token_info'; - -/** - * Creates and deploys all the contracts that are required for the latest - * 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> { - const web3Wrapper = new Web3Wrapper(provider); - const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync(); - const owner = accounts[0]; - - // Proxies - const erc20Proxy = await wrappers.ERC20ProxyContract.deployFrom0xArtifactAsync( - artifacts.ERC20Proxy, - provider, - txDefaults, - ); - const erc721Proxy = await wrappers.ERC721ProxyContract.deployFrom0xArtifactAsync( - artifacts.ERC721Proxy, - provider, - txDefaults, - ); - - // ZRX - const zrxToken = await wrappers.ZRXTokenContract.deployFrom0xArtifactAsync( - artifacts.ZRXToken, - provider, - txDefaults, - ); - - // Ether token - const etherToken = await wrappers.WETH9Contract.deployFrom0xArtifactAsync(artifacts.WETH9, provider, txDefaults); - - // Exchange - const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address); - const exchange = await wrappers.ExchangeContract.deployFrom0xArtifactAsync( - artifacts.Exchange, - provider, - txDefaults, - zrxAssetData, - ); - - // Dummy ERC20 tokens - for (const token of erc20TokenInfo) { - const totalSupply = new BigNumber(1000000000000000000000000000); - // tslint:disable-next-line:no-unused-variable - const dummyErc20Token = await wrappers.DummyERC20TokenContract.deployFrom0xArtifactAsync( - artifacts.DummyERC20Token, - provider, - txDefaults, - token.name, - token.symbol, - token.decimals, - totalSupply, - ); - } - - // ERC721 - // tslint:disable-next-line:no-unused-variable - const cryptoKittieToken = await wrappers.DummyERC721TokenContract.deployFrom0xArtifactAsync( - artifacts.DummyERC721Token, - provider, - txDefaults, - erc721TokenInfo[0].name, - erc721TokenInfo[0].symbol, - ); - - const multiAssetProxy = await wrappers.MultiAssetProxyContract.deployFrom0xArtifactAsync( - artifacts.MultiAssetProxy, - provider, - txDefaults, - ); - - await web3Wrapper.awaitTransactionSuccessAsync( - await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { - from: owner, - }), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { - from: owner, - }), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await multiAssetProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { - from: owner, - }), - ); - - // MultiAssetProxy - await web3Wrapper.awaitTransactionSuccessAsync( - await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(multiAssetProxy.address, { - from: owner, - }), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(multiAssetProxy.address, { - from: owner, - }), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await multiAssetProxy.registerAssetProxy.sendTransactionAsync(erc20Proxy.address), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await multiAssetProxy.registerAssetProxy.sendTransactionAsync(erc721Proxy.address), - ); - - // Register the Asset Proxies to the Exchange - await web3Wrapper.awaitTransactionSuccessAsync( - await exchange.registerAssetProxy.sendTransactionAsync(erc20Proxy.address), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await exchange.registerAssetProxy.sendTransactionAsync(erc721Proxy.address), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await exchange.registerAssetProxy.sendTransactionAsync(multiAssetProxy.address), - ); - - // Forwarder - const forwarder = await wrappers.ForwarderContract.deployFrom0xArtifactAsync( - artifacts.Forwarder, - provider, - txDefaults, - exchange.address, - assetDataUtils.encodeERC20AssetData(zrxToken.address), - assetDataUtils.encodeERC20AssetData(etherToken.address), - ); - - // OrderValidator - const orderValidator = await wrappers.OrderValidatorContract.deployFrom0xArtifactAsync( - artifacts.OrderValidator, - provider, - txDefaults, - exchange.address, - zrxAssetData, - ); - - // DutchAuction - const dutchAuction = await wrappers.DutchAuctionContract.deployFrom0xArtifactAsync( - artifacts.DutchAuction, - provider, - txDefaults, - exchange.address, - ); - - // Multisigs - const owners = [accounts[0], accounts[1]]; - const confirmationsRequired = new BigNumber(2); - const secondsRequired = new BigNumber(0); - - // AssetProxyOwner - const assetProxyOwner = await wrappers.AssetProxyOwnerContract.deployFrom0xArtifactAsync( - artifacts.AssetProxyOwner, - provider, - txDefaults, - owners, - [erc20Proxy.address, erc721Proxy.address, multiAssetProxy.address], - confirmationsRequired, - secondsRequired, - ); - - // Transfer Ownership to the Asset Proxy Owner - await web3Wrapper.awaitTransactionSuccessAsync( - await erc20Proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address, { - from: owner, - }), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await erc721Proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address, { - from: owner, - }), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await multiAssetProxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address, { - from: owner, - }), - ); - - // 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), - ); - - const contractAddresses = { - erc20Proxy: erc20Proxy.address, - erc721Proxy: erc721Proxy.address, - zrxToken: zrxToken.address, - etherToken: etherToken.address, - exchange: exchange.address, - assetProxyOwner: assetProxyOwner.address, - forwarder: forwarder.address, - orderValidator: orderValidator.address, - dutchAuction: dutchAuction.address, - }; - - return contractAddresses; -} - -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. 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( - provider: Provider, - txDefaults: Partial<TxData>, -): Promise<ContractAddresses> { - if (!_.isUndefined(_cachedContractAddresses)) { - return _cachedContractAddresses; - } - _cachedContractAddresses = await runMigrationsAsync(provider, txDefaults); - return _cachedContractAddresses; -} diff --git a/packages/migrations/src/types.ts b/packages/migrations/src/types.ts deleted file mode 100644 index 87e66f356..000000000 --- a/packages/migrations/src/types.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { BigNumber } from '@0x/utils'; - -export interface ERC20Token { - address?: string; - name: string; - symbol: string; - decimals: BigNumber; - ipfsHash: string; - swarmHash: string; -} - -export interface ERC721Token { - name: string; - symbol: string; -} - -export enum ContractName { - TokenTransferProxy = 'TokenTransferProxy', - TokenRegistry = 'TokenRegistry', - MultiSigWalletWithTimeLock = 'MultiSigWalletWithTimeLock', - Exchange = 'Exchange', - ZRXToken = 'ZRXToken', - DummyToken = 'DummyToken', - WETH9 = 'WETH9', - MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress = 'MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', - AccountLevels = 'AccountLevels', - EtherDelta = 'EtherDelta', - Arbitrage = 'Arbitrage', -} diff --git a/packages/migrations/src/utils/constants.ts b/packages/migrations/src/utils/constants.ts deleted file mode 100644 index 8b16a0520..000000000 --- a/packages/migrations/src/utils/constants.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { BigNumber } from '@0x/utils'; - -export const constants = { - ASSET_PROXY_OWNER_OWNERS: [ - '0x9df8137872ac09a8fee71d0da5c7539923fb9bf0', - '0xcf34d44db312d188789f43a63d11cf2bebb4da15', - '0x73fd50f2a6beac9cdac9fe87ef68a18edc415831', - ], - ASSET_PROXY_OWNER_TIMELOCK: new BigNumber(0), - ASSET_PROXY_OWNER_CONFIRMATIONS: new BigNumber(1), - ERC20_PROXY_ID: '0xf47261b0', - ERC721_PROXY_ID: '0x02571792', - NULL_ADDRESS: '0x0000000000000000000000000000000000000000', - KOVAN_RPC_URL: 'https://kovan.infura.io/', - KOVAN_NETWORK_ID: 42, - MAINNET_RPC_URL: 'https://mainnet.infura.io/', - MAINNET_NETWORK_ID: 1, -}; diff --git a/packages/migrations/src/utils/provider_factory.ts b/packages/migrations/src/utils/provider_factory.ts deleted file mode 100644 index 8017b672a..000000000 --- a/packages/migrations/src/utils/provider_factory.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { LedgerEthereumClient, LedgerSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders'; -import Eth from '@ledgerhq/hw-app-eth'; -// tslint:disable:no-implicit-dependencies -import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'; -import { Provider } from 'ethereum-types'; - -import { constants } from './constants'; - -async function ledgerEthereumNodeJsClientFactoryAsync(): Promise<LedgerEthereumClient> { - const ledgerConnection = await TransportNodeHid.create(); - const ledgerEthClient = new Eth(ledgerConnection); - return ledgerEthClient; -} -export const providerFactory = { - async getKovanLedgerProviderAsync(): Promise<Provider> { - const provider = new Web3ProviderEngine(); - const ledgerWalletConfigs = { - networkId: constants.KOVAN_NETWORK_ID, - ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync, - }; - const ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs); - provider.addProvider(ledgerSubprovider); - provider.addProvider(new RPCSubprovider(constants.KOVAN_RPC_URL)); - provider.start(); - return provider; - }, - async getMainnetLedgerProviderAsync(): Promise<Provider> { - const provider = new Web3ProviderEngine(); - const ledgerWalletConfigs = { - networkId: constants.MAINNET_NETWORK_ID, - ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync, - }; - const ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs); - provider.addProvider(ledgerSubprovider); - provider.addProvider(new RPCSubprovider(constants.MAINNET_RPC_URL)); - provider.start(); - return provider; - }, -}; diff --git a/packages/migrations/src/utils/token_info.ts b/packages/migrations/src/utils/token_info.ts deleted file mode 100644 index 6e0411f60..000000000 --- a/packages/migrations/src/utils/token_info.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { BigNumber, NULL_BYTES } from '@0x/utils'; - -import { ERC20Token, ERC721Token } from '../types'; - -export const etherTokenByNetwork: { [networkId: number]: { address: string } } = { - 3: { - address: '0xc778417e063141139fce010982780140aa0cd5ab', - }, - 4: { - address: '0xc778417e063141139fce010982780140aa0cd5ab', - }, - 42: { - address: '0xd0a1e359811322d97991e03f863a0c30c2cf029c', - }, - 50: { - address: '', - }, -}; -export const erc20TokenInfo: ERC20Token[] = [ - { - name: 'Augur Reputation Token', - symbol: 'REP', - decimals: new BigNumber(18), - ipfsHash: NULL_BYTES, - swarmHash: NULL_BYTES, - }, - { - name: 'Digix DAO Token', - symbol: 'DGD', - decimals: new BigNumber(18), - ipfsHash: NULL_BYTES, - swarmHash: NULL_BYTES, - }, - { - name: 'Golem Network Token', - symbol: 'GNT', - decimals: new BigNumber(18), - ipfsHash: NULL_BYTES, - swarmHash: NULL_BYTES, - }, - { - name: 'MakerDAO', - symbol: 'MKR', - decimals: new BigNumber(18), - ipfsHash: NULL_BYTES, - swarmHash: NULL_BYTES, - }, - { - name: 'Melon Token', - symbol: 'MLN', - decimals: new BigNumber(18), - ipfsHash: NULL_BYTES, - swarmHash: NULL_BYTES, - }, -]; - -export const erc721TokenInfo: ERC721Token[] = [ - { - name: '0xen ERC721', - symbol: '0xen', - }, -]; |