aboutsummaryrefslogtreecommitdiffstats
path: root/packages/migrations/src/migrate.ts
blob: 6c8b38762ea88d65cfbec2b76023f1cc2d71f115 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env node
import { devConstants, web3Factory } from '@0xproject/dev-utils';
import { logUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider } from 'ethereum-types';
import * as yargs from 'yargs';

import { runV1MigrationsAsync } from './1.0.0/migration';
import { runV2TestnetMigrationsAsync } from './2.0.0-beta-testnet/migration';
import { runV2MainnetMigrationsAsync } from './2.0.0-mainnet/migration';
import { runV2MigrationsAsync } from './2.0.0/migration';

import { providerFactory } from './utils/provider_factory';

enum ContractVersions {
    V1 = '1.0.0',
    V2 = '2.0.0',
    V2Testnet = '2.0.0-beta-testnet',
    V2Mainnet = '2.0.0-mainnet',
}
const args = yargs.argv;

(async () => {
    const contractsVersion = args.contractsVersion;
    const artifactsDir = `artifacts/${contractsVersion}`;
    let providerConfigs;
    let provider: Provider;
    let txDefaults;
    let web3Wrapper: Web3Wrapper;
    let accounts: string[];
    switch (contractsVersion) {
        case ContractVersions.V1:
            providerConfigs = { shouldUseInProcessGanache: false };
            provider = web3Factory.getRpcProvider(providerConfigs);
            txDefaults = {
                from: devConstants.TESTRPC_FIRST_ADDRESS,
            };
            await runV1MigrationsAsync(provider, artifactsDir, txDefaults);
            break;
        case ContractVersions.V2:
            providerConfigs = { shouldUseInProcessGanache: false };
            provider = web3Factory.getRpcProvider(providerConfigs);
            txDefaults = {
                from: devConstants.TESTRPC_FIRST_ADDRESS,
            };
            await runV2MigrationsAsync(provider, artifactsDir, txDefaults);
            break;
        case ContractVersions.V2Testnet:
            provider = await providerFactory.getLedgerProviderAsync();
            web3Wrapper = new Web3Wrapper(provider);
            accounts = await web3Wrapper.getAvailableAddressesAsync();
            txDefaults = {
                from: accounts[0],
                gas: devConstants.GAS_LIMIT,
            };
            await runV2TestnetMigrationsAsync(provider, artifactsDir, txDefaults);
            break;
        case ContractVersions.V2Mainnet:
            provider = await providerFactory.getLedgerProviderAsync();
            web3Wrapper = new Web3Wrapper(provider);
            accounts = await web3Wrapper.getAvailableAddressesAsync();
            txDefaults = {
                from: accounts[0],
                gas: devConstants.GAS_LIMIT,
            };
            await runV2MainnetMigrationsAsync(provider, artifactsDir, txDefaults);
            break;
        default:
            throw new Error(`Unsupported contract version: ${contractsVersion}`);
    }
    process.exit(0);
})().catch(err => {
    logUtils.log(err);
    process.exit(1);
});