aboutsummaryrefslogtreecommitdiffstats
path: root/packages/migrations/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/migrations/src')
-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
12 files changed, 145 insertions, 38 deletions
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;
+ },
+};