aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/migrations/3_register_tokens.ts
blob: c72ac1510056b5d88795e89fb8cdfc7b0b0a8d48 (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
76
77
78
79
80
81
82
83
84
85
86
import * as Bluebird from 'bluebird';
import * as _ from 'lodash';

import {Artifacts} from '../util/artifacts';
import {constants} from '../util/constants';
import {ContractInstance, Token, TokenInfoByNetwork} from '../util/types';

import {tokenInfo} from './config/token_info';
const {
    DummyToken,
    EtherToken,
    ZRXToken,
    TokenRegistry,
} = new Artifacts(artifacts);

module.exports = (deployer: any, network: string) => {
    const tokens = network === 'live' ? tokenInfo.live : tokenInfo.development;
    deployer.then(() => {
        return TokenRegistry.deployed();
    }).then((tokenRegistry: ContractInstance) => {
        if (network !== 'live') {
            const totalSupply = Math.pow(10, 18) * 1000000000;
            return Bluebird.each(tokens.map((token: Token) => DummyToken.new(
                token.name,
                token.symbol,
                token.decimals,
                totalSupply,
        )), _.noop).then((dummyTokens: ContractInstance[]) => {
                const weth = {
                    address: EtherToken.address,
                    name: 'Ether Token',
                    symbol: 'WETH',
                    url: '',
                    decimals: 18,
                    ipfsHash: constants.NULL_BYTES,
                    swarmHash: constants.NULL_BYTES,
                };
                return Bluebird.each(dummyTokens.map((tokenContract: ContractInstance, i: number) => {
                    const token = tokens[i];
                    return tokenRegistry.addToken(
                        tokenContract.address,
                        token.name,
                        token.symbol,
                        token.decimals,
                        token.ipfsHash,
                        token.swarmHash,
                    );
                }).concat(tokenRegistry.addToken(
                    weth.address,
                    weth.name,
                    weth.symbol,
                    weth.decimals,
                    weth.ipfsHash,
                    weth.swarmHash,
            )), _.noop);
            });
        } else {
            const zrx = {
                address: ZRXToken.address,
                name: '0x Protocol Token',
                symbol: 'ZRX',
                url: 'https://www.0xproject.com/',
                decimals: 18,
                ipfsHash: constants.NULL_BYTES,
                swarmHash: constants.NULL_BYTES,
            };
            return Bluebird.each(tokens.map((token: Token) => {
                return tokenRegistry.addToken(
                    token.address,
                    token.name,
                    token.symbol,
                    token.decimals,
                    token.ipfsHash,
                    token.swarmHash,
                );
            }).concat(tokenRegistry.addToken(
                zrx.address,
                zrx.name,
                zrx.symbol,
                zrx.decimals,
                zrx.ipfsHash,
                zrx.swarmHash,
        )), _.noop);
        }
    });
};