aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/migrations/package.json22
-rw-r--r--packages/migrations/src/1.0.0/migration.ts2
-rw-r--r--packages/migrations/src/2.0.0-beta-kovan/artifacts.ts13
-rw-r--r--packages/migrations/src/2.0.0-beta-testnet/artifacts.ts13
-rw-r--r--packages/migrations/src/2.0.0-beta-testnet/migration.ts (renamed from packages/migrations/src/2.0.0-beta-kovan/migration.ts)15
-rw-r--r--packages/migrations/src/2.0.0/migration.ts2
-rw-r--r--packages/migrations/src/globals.d.ts23
-rw-r--r--packages/migrations/src/index.ts2
-rw-r--r--packages/migrations/src/migrate.ts35
-rw-r--r--packages/migrations/src/types.ts36
-rw-r--r--packages/migrations/src/utils/artifact_writer.ts (renamed from packages/migrations/src/artifact_writer.ts)0
-rw-r--r--packages/migrations/src/utils/constants.ts (renamed from packages/migrations/src/2.0.0-beta-kovan/constants.ts)5
-rw-r--r--packages/migrations/src/utils/provider_factory.ts37
13 files changed, 159 insertions, 46 deletions
diff --git a/packages/migrations/package.json b/packages/migrations/package.json
index 11212bc1a..7f5a789e4 100644
--- a/packages/migrations/package.json
+++ b/packages/migrations/package.json
@@ -17,23 +17,23 @@
"tslint --project . --exclude **/src/v2/contract_wrappers/**/* --exclude **/src/v1/contract_wrappers/**/*",
"migrate:v1": "run-s build compile:v1 script:migrate:v1",
"migrate:v2": "run-s build compile:v2 script:migrate:v2",
- "migrate:v2-beta-kovan": "run-s build compile:v2-beta-kovan script:migrate:v2-beta-kovan",
+ "migrate:v2-beta-testnet": "run-s build compile:v2-beta-testnet script:migrate:v2-beta-testnet",
"script:migrate:v1": "node ./lib/migrate.js --contracts-version 1.0.0",
"script:migrate:v2": "node ./lib/migrate.js --contracts-version 2.0.0",
- "script:migrate:v2-beta-kovan": "node ./lib/migrate.js --contracts-version 2.0.0-beta-kovan",
+ "script:migrate:v2-beta-testnet": "node ./lib/migrate.js --contracts-version 2.0.0-beta-testnet",
"generate_contract_wrappers": "run-p generate_contract_wrappers:*",
"generate_contract_wrappers:v1":
"abi-gen --abis ${npm_package_config_abis_v1} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/1.0.0/contract_wrappers --backend ethers",
"generate_contract_wrappers:v2":
"abi-gen --abis ${npm_package_config_abis_v2} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0/contract_wrappers --backend ethers",
- "generate_contract_wrappers:v2-beta-kovan":
- "abi-gen --abis ${npm_package_config_abis_v2BetaKovan} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0-beta-kovan/contract_wrappers --backend ethers",
+ "generate_contract_wrappers:v2-beta-testnet":
+ "abi-gen --abis ${npm_package_config_abis_v2BetaTestnet} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0-beta-testnet/contract_wrappers --backend ethers",
"compile:v1":
"sol-compiler --artifacts-dir artifacts/1.0.0 --contracts Exchange_v1,DummyERC20Token,ZRXToken,WETH9,TokenTransferProxy_v1,MultiSigWallet,MultiSigWalletWithTimeLock,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,TokenRegistry",
"compile:v2":
"sol-compiler --artifacts-dir artifacts/2.0.0 --contracts ERC20Token,DummyERC20Token,ERC721Token,DummyERC721Token,ERC20Proxy,ERC721Proxy,Exchange,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,ZRXToken,WETH9,IWallet,IValidator",
- "compile:v2-beta-kovan":
- "sol-compiler --artifacts-dir artifacts/2.0.0-beta-kovan --contracts AssetProxyOwner,ERC20Proxy,ERC721Proxy,Exchange"
+ "compile:v2-beta-testnet":
+ "sol-compiler --artifacts-dir artifacts/2.0.0-beta-testnet --contracts AssetProxyOwner,ERC20Proxy,ERC721Proxy,Exchange"
},
"config": {
"abis": {
@@ -41,7 +41,7 @@
"artifacts/1.0.0/@(DummyERC20Token|TokenTransferProxy_v1|Exchange_v1|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|WETH9).json",
"v2":
"artifacts/2.0.0/@(ERC20Token|DummyERC20Token|ERC721Token|DummyERC721Token|ERC20Proxy|ERC721Proxy|Exchange|AssetProxyOwner|ZRXToken|WETH9|IWallet|IValidator).json",
- "v2BetaKovan": "artifacts/2.0.0-beta-kovan/@(ERC20Proxy|ERC721Proxy|Exchange|AssetProxyOwner).json"
+ "v2BetaTestnet": "artifacts/2.0.0-beta-testnet/@(ERC20Proxy|ERC721Proxy|Exchange|AssetProxyOwner).json"
}
},
"license": "Apache-2.0",
@@ -62,12 +62,18 @@
"@0xproject/base-contract": "^0.3.4",
"@0xproject/order-utils": "^1.0.0",
"@0xproject/sol-compiler": "^0.5.2",
+ "@0xproject/subproviders": "^0.10.4",
"@0xproject/typescript-typings": "^0.4.1",
"@0xproject/utils": "^0.7.1",
"@0xproject/web3-wrapper": "^0.7.1",
+ "@ledgerhq/hw-app-eth": "^4.3.0",
"ethereum-types": "^0.0.1",
"ethers": "3.0.22",
- "lodash": "^4.17.4"
+ "lodash": "^4.17.4",
+ "web3-provider-engine": "^14.0.4"
+ },
+ "optionalDependencies": {
+ "@ledgerhq/hw-transport-node-hid": "^4.3.0"
},
"publishConfig": {
"access": "public"
diff --git a/packages/migrations/src/1.0.0/migration.ts b/packages/migrations/src/1.0.0/migration.ts
index 3398537e5..6cc8dc4ef 100644
--- a/packages/migrations/src/1.0.0/migration.ts
+++ b/packages/migrations/src/1.0.0/migration.ts
@@ -2,7 +2,7 @@ import { BigNumber, NULL_BYTES } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider, TxData } from 'ethereum-types';
-import { ArtifactWriter } from '../artifact_writer';
+import { ArtifactWriter } from '../utils/artifact_writer';
import { erc20TokenInfo } from '../utils/token_info';
import { artifacts } from './artifacts';
diff --git a/packages/migrations/src/2.0.0-beta-kovan/artifacts.ts b/packages/migrations/src/2.0.0-beta-kovan/artifacts.ts
deleted file mode 100644
index 5e7bb2de7..000000000
--- a/packages/migrations/src/2.0.0-beta-kovan/artifacts.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { ContractArtifact } from '@0xproject/sol-compiler';
-
-import * as AssetProxyOwner from '../../artifacts/2.0.0-beta-kovan/AssetProxyOwner.json';
-import * as ERC20Proxy from '../../artifacts/2.0.0-beta-kovan/ERC20Proxy.json';
-import * as ERC721Proxy from '../../artifacts/2.0.0-beta-kovan/ERC721Proxy.json';
-import * as Exchange from '../../artifacts/2.0.0-beta-kovan/Exchange.json';
-
-export const artifacts = {
- AssetProxyOwner: (AssetProxyOwner as any) as ContractArtifact,
- Exchange: (Exchange as any) as ContractArtifact,
- ERC20Proxy: (ERC20Proxy as any) as ContractArtifact,
- ERC721Proxy: (ERC721Proxy as any) as ContractArtifact,
-};
diff --git a/packages/migrations/src/2.0.0-beta-testnet/artifacts.ts b/packages/migrations/src/2.0.0-beta-testnet/artifacts.ts
new file mode 100644
index 000000000..c9a341eb3
--- /dev/null
+++ b/packages/migrations/src/2.0.0-beta-testnet/artifacts.ts
@@ -0,0 +1,13 @@
+import { ContractArtifact } from '@0xproject/sol-compiler';
+
+import * as AssetProxyOwner from '../../artifacts/2.0.0-beta-testnet/AssetProxyOwner.json';
+import * as ERC20Proxy from '../../artifacts/2.0.0-beta-testnet/ERC20Proxy.json';
+import * as ERC721Proxy from '../../artifacts/2.0.0-beta-testnet/ERC721Proxy.json';
+import * as Exchange from '../../artifacts/2.0.0-beta-testnet/Exchange.json';
+
+export const artifacts = {
+ AssetProxyOwner: (AssetProxyOwner as any) as ContractArtifact,
+ Exchange: (Exchange as any) as ContractArtifact,
+ ERC20Proxy: (ERC20Proxy as any) as ContractArtifact,
+ ERC721Proxy: (ERC721Proxy as any) as ContractArtifact,
+};
diff --git a/packages/migrations/src/2.0.0-beta-kovan/migration.ts b/packages/migrations/src/2.0.0-beta-testnet/migration.ts
index bc0cbe090..df41fd401 100644
--- a/packages/migrations/src/2.0.0-beta-kovan/migration.ts
+++ b/packages/migrations/src/2.0.0-beta-testnet/migration.ts
@@ -1,25 +1,25 @@
-import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider, TxData } from 'ethereum-types';
-import { ArtifactWriter } from '../artifact_writer';
+import { ArtifactWriter } from '../utils/artifact_writer';
+
+import { constants } from '../utils/constants';
import { artifacts } from './artifacts';
-import { constants } from './constants';
import { AssetProxyOwnerContract } from './contract_wrappers/asset_proxy_owner';
import { ERC20ProxyContract } from './contract_wrappers/e_r_c20_proxy';
import { ERC721ProxyContract } from './contract_wrappers/e_r_c721_proxy';
import { ExchangeContract } from './contract_wrappers/exchange';
/**
- * Custom migrations should be defined in this function. This will be called with the CLI 'migrate:v2' command.
+ * Custom migrations should be defined in this function. This will be called with the CLI 'migrate:v2-beta-testnet' command.
* Migrations could be written to run in parallel, but if you want contract addresses to be created deterministically,
* the migration should be written to run synchronously.
* @param provider Web3 provider instance.
* @param artifactsDir The directory with compiler artifact files.
* @param txDefaults Default transaction values to use when deploying contracts.
*/
-export const runV2BetaKovanMigrationsAsync = async (
+export const runV2TestnetMigrationsAsync = async (
provider: Provider,
artifactsDir: string,
txDefaults: Partial<TxData>,
@@ -43,18 +43,19 @@ export const runV2BetaKovanMigrationsAsync = async (
artifactsWriter.saveArtifact(exchange);
// Register AssetProxies in Exchange
+ const oldAssetProxy = constants.NULL_ADDRESS;
await web3Wrapper.awaitTransactionSuccessAsync(
await exchange.registerAssetProxy.sendTransactionAsync(
constants.ERC20_PROXY_ID,
erc20proxy.address,
- constants.NULL_ADDRESS,
+ oldAssetProxy,
),
);
await web3Wrapper.awaitTransactionSuccessAsync(
await exchange.registerAssetProxy.sendTransactionAsync(
constants.ERC721_PROXY_ID,
erc721proxy.address,
- constants.NULL_ADDRESS,
+ oldAssetProxy,
),
);
diff --git a/packages/migrations/src/2.0.0/migration.ts b/packages/migrations/src/2.0.0/migration.ts
index 76a31e2a0..91a4cbd13 100644
--- a/packages/migrations/src/2.0.0/migration.ts
+++ b/packages/migrations/src/2.0.0/migration.ts
@@ -3,7 +3,7 @@ import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider, TxData } from 'ethereum-types';
-import { ArtifactWriter } from '../artifact_writer';
+import { ArtifactWriter } from '../utils/artifact_writer';
import { erc20TokenInfo, erc721TokenInfo } from '../utils/token_info';
import { artifacts } from './artifacts';
diff --git a/packages/migrations/src/globals.d.ts b/packages/migrations/src/globals.d.ts
index 94e63a32d..b11849b05 100644
--- a/packages/migrations/src/globals.d.ts
+++ b/packages/migrations/src/globals.d.ts
@@ -4,3 +4,26 @@ declare module '*.json' {
export default json;
/* tslint:enable */
}
+
+declare module '@ledgerhq/hw-app-eth' {
+ class Eth {
+ public transport: LedgerTransport;
+ constructor(transport: LedgerTransport);
+ public getAddress(
+ path: string,
+ boolDisplay?: boolean,
+ boolChaincode?: boolean,
+ ): Promise<{ publicKey: string; address: string; chainCode: string }>;
+ public signTransaction(path: string, rawTxHex: string): Promise<ECSignatureString>;
+ public getAppConfiguration(): Promise<{ arbitraryDataEnabled: number; version: string }>;
+ public signPersonalMessage(path: string, messageHex: string): Promise<ECSignature>;
+ }
+ export default Eth;
+}
+
+declare module '@ledgerhq/hw-transport-node-hid' {
+ export default class TransportNodeHid implements LedgerTransport {
+ public static create(): Promise<LedgerTransport>;
+ public close(): Promise<void>;
+ }
+}
diff --git a/packages/migrations/src/index.ts b/packages/migrations/src/index.ts
index bb4b1f1e2..188f566df 100644
--- a/packages/migrations/src/index.ts
+++ b/packages/migrations/src/index.ts
@@ -1,3 +1,3 @@
export { runV1MigrationsAsync } from './1.0.0/migration';
export { runV2MigrationsAsync } from './2.0.0/migration';
-export { runV2BetaKovanMigrationsAsync } from './2.0.0-beta-kovan/migration';
+export { runV2TestnetMigrationsAsync } from './2.0.0-beta-testnet/migration';
diff --git a/packages/migrations/src/migrate.ts b/packages/migrations/src/migrate.ts
index 35e086382..d9cc1ae01 100644
--- a/packages/migrations/src/migrate.ts
+++ b/packages/migrations/src/migrate.ts
@@ -6,13 +6,15 @@ import { Provider } from 'ethereum-types';
import * as yargs from 'yargs';
import { runV1MigrationsAsync } from './1.0.0/migration';
-import { runV2BetaKovanMigrationsAsync } from './2.0.0-beta-kovan/migration';
+import { runV2TestnetMigrationsAsync } from './2.0.0-beta-testnet/migration';
import { runV2MigrationsAsync } from './2.0.0/migration';
+import { providerFactory } from './utils/provider_factory';
+
enum ContractVersions {
V1 = '1.0.0',
V2 = '2.0.0',
- V2BetaKovan = '2.0.0-beta-kovan',
+ V2Testnet = '2.0.0-beta-testnet',
}
const args = yargs.argv;
@@ -24,17 +26,24 @@ const args = yargs.argv;
};
const contractsVersion = args.contractsVersion;
const artifactsDir = `artifacts/${contractsVersion}`;
- if (contractsVersion === ContractVersions.V1) {
- await runV1MigrationsAsync(provider, artifactsDir, txDefaults);
- } else if (contractsVersion === ContractVersions.V2) {
- await runV2MigrationsAsync(provider, artifactsDir, txDefaults);
- } else {
- const web3Wrapper = new Web3Wrapper(provider);
- const accounts = await web3Wrapper.getAvailableAddressesAsync();
- const kovanTxDefaults = {
- from: accounts[0],
- };
- await runV2BetaKovanMigrationsAsync(provider, artifactsDir, kovanTxDefaults);
+ switch (contractsVersion) {
+ case ContractVersions.V1:
+ await runV1MigrationsAsync(provider, artifactsDir, txDefaults);
+ break;
+ case ContractVersions.V2:
+ await runV2MigrationsAsync(provider, artifactsDir, txDefaults);
+ break;
+ case ContractVersions.V2Testnet:
+ const ledgerProvider = await providerFactory.getLedgerProviderAsync();
+ const web3Wrapper = new Web3Wrapper(ledgerProvider);
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ const testnetTxDefaults = {
+ from: accounts[0],
+ };
+ await runV2TestnetMigrationsAsync(ledgerProvider, artifactsDir, testnetTxDefaults);
+ break;
+ default:
+ throw new Error(`Unsupported contract version: ${contractsVersion}`);
}
process.exit(0);
})().catch(err => {
diff --git a/packages/migrations/src/types.ts b/packages/migrations/src/types.ts
index 65f685797..7347f27fe 100644
--- a/packages/migrations/src/types.ts
+++ b/packages/migrations/src/types.ts
@@ -1,3 +1,4 @@
+import { ECSignature } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
export interface ERC20Token {
@@ -27,3 +28,38 @@ export enum ContractName {
EtherDelta = 'EtherDelta',
Arbitrage = 'Arbitrage',
}
+
+export interface LedgerCommunicationClient {
+ close: () => Promise<void>;
+}
+
+export interface LedgerGetAddressResult {
+ address: string;
+ publicKey: string;
+ chainCode: string;
+}
+
+export interface ECSignatureString {
+ v: string;
+ r: string;
+ s: string;
+}
+
+export interface LedgerGetAddressResult {
+ address: string;
+ publicKey: string;
+ chainCode: string;
+}
+
+export interface LedgerEthereumClient {
+ // shouldGetChainCode is defined as `true` instead of `boolean` because other types rely on the assumption
+ // that we get back the chain code and we don't have dependent types to express it properly
+ getAddress: (
+ derivationPath: string,
+ askForDeviceConfirmation: boolean,
+ shouldGetChainCode: true,
+ ) => Promise<LedgerGetAddressResult>;
+ signTransaction: (derivationPath: string, rawTxHex: string) => Promise<ECSignatureString>;
+ signPersonalMessage: (derivationPath: string, messageHex: string) => Promise<ECSignature>;
+ transport: LedgerCommunicationClient;
+}
diff --git a/packages/migrations/src/artifact_writer.ts b/packages/migrations/src/utils/artifact_writer.ts
index 2da5a09dd..2da5a09dd 100644
--- a/packages/migrations/src/artifact_writer.ts
+++ b/packages/migrations/src/utils/artifact_writer.ts
diff --git a/packages/migrations/src/2.0.0-beta-kovan/constants.ts b/packages/migrations/src/utils/constants.ts
index e4fc8339d..21887ab16 100644
--- a/packages/migrations/src/2.0.0-beta-kovan/constants.ts
+++ b/packages/migrations/src/utils/constants.ts
@@ -8,7 +8,8 @@ export const constants = {
],
ASSET_PROXY_OWNER_TIMELOCK: new BigNumber(0),
ASSET_PROXY_OWNER_CONFIRMATIONS: new BigNumber(1),
- ERC20_PROXY_ID: new BigNumber(0),
- ERC721_PROXY_ID: new BigNumber(1),
+ ERC20_PROXY_ID: '0xf47261b0',
+ ERC721_PROXY_ID: '0x08e937fa',
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
+ RPC_URL: 'http://localhost:8545',
};
diff --git a/packages/migrations/src/utils/provider_factory.ts b/packages/migrations/src/utils/provider_factory.ts
new file mode 100644
index 000000000..14b1be982
--- /dev/null
+++ b/packages/migrations/src/utils/provider_factory.ts
@@ -0,0 +1,37 @@
+import { LedgerSubprovider } from '@0xproject/subproviders';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import Eth from '@ledgerhq/hw-app-eth';
+import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
+import { Provider } from 'ethereum-types';
+import ProviderEngine = require('web3-provider-engine');
+import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
+
+import { LedgerEthereumClient } from '../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 getLedgerProviderAsync(): Promise<Provider> {
+ const provider = new ProviderEngine();
+ provider.addProvider(
+ new RpcSubprovider({
+ rpcUrl: constants.RPC_URL,
+ }),
+ );
+ const web3Wrapper = new Web3Wrapper(provider);
+ const networkId = await web3Wrapper.getNetworkIdAsync();
+ const ledgerWalletConfigs = {
+ networkId,
+ ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync,
+ };
+ const ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs);
+ provider.addProvider(ledgerSubprovider);
+ provider.start();
+ return provider;
+ },
+};