Better validate ZeroExConfig on public networks
This commit is contained in:
		@@ -13,6 +13,8 @@ import { TokenTransferProxyWrapper } from './contract_wrappers/token_transfer_pr
 | 
			
		||||
import { TokenWrapper } from './contract_wrappers/token_wrapper';
 | 
			
		||||
import { OrderStateWatcher } from './order_watcher/order_state_watcher';
 | 
			
		||||
import { zeroExConfigSchema } from './schemas/zero_ex_config_schema';
 | 
			
		||||
import { zeroExPrivateNetworkConfigSchema } from './schemas/zero_ex_private_network_config_schema';
 | 
			
		||||
import { zeroExPublicNetworkConfigSchema } from './schemas/zero_ex_public_network_config_schema';
 | 
			
		||||
import { ECSignature, Order, SignedOrder, Web3Provider, ZeroExConfig, ZeroExError } from './types';
 | 
			
		||||
import { assert } from './utils/assert';
 | 
			
		||||
import { constants } from './utils/constants';
 | 
			
		||||
@@ -20,6 +22,9 @@ import { decorators } from './utils/decorators';
 | 
			
		||||
import { signatureUtils } from './utils/signature_utils';
 | 
			
		||||
import { utils } from './utils/utils';
 | 
			
		||||
 | 
			
		||||
assert.schemaValidator.addSchema(zeroExPrivateNetworkConfigSchema);
 | 
			
		||||
assert.schemaValidator.addSchema(zeroExPublicNetworkConfigSchema);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The ZeroEx class is the single entry-point into the 0x.js library. It contains all of the library's functionality
 | 
			
		||||
 * and all calls to the library should be made through a ZeroEx instance.
 | 
			
		||||
 
 | 
			
		||||
@@ -1,27 +1,5 @@
 | 
			
		||||
export const zeroExConfigSchema = {
 | 
			
		||||
    id: '/ZeroExConfig',
 | 
			
		||||
    properties: {
 | 
			
		||||
        networkId: {
 | 
			
		||||
            type: 'number',
 | 
			
		||||
            minimum: 0,
 | 
			
		||||
        },
 | 
			
		||||
        gasPrice: { $ref: '/Number' },
 | 
			
		||||
        exchangeContractAddress: { $ref: '/Address' },
 | 
			
		||||
        tokenRegistryContractAddress: { $ref: '/Address' },
 | 
			
		||||
        orderWatcherConfig: {
 | 
			
		||||
            type: 'object',
 | 
			
		||||
            properties: {
 | 
			
		||||
                pollingIntervalMs: {
 | 
			
		||||
                    type: 'number',
 | 
			
		||||
                    minimum: 0,
 | 
			
		||||
                },
 | 
			
		||||
                numConfirmations: {
 | 
			
		||||
                    type: 'number',
 | 
			
		||||
                    minimum: 0,
 | 
			
		||||
                },
 | 
			
		||||
            },
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
    oneOf: [{ $ref: '/ZeroExPrivateNetworkConfig' }, { $ref: '/ZeroExPublicNetworkConfig' }],
 | 
			
		||||
    type: 'object',
 | 
			
		||||
    required: ['networkId'],
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,35 @@
 | 
			
		||||
export const zeroExPrivateNetworkConfigSchema = {
 | 
			
		||||
    id: '/ZeroExPrivateNetworkConfig',
 | 
			
		||||
    properties: {
 | 
			
		||||
        networkId: {
 | 
			
		||||
            type: 'number',
 | 
			
		||||
            minimum: 1,
 | 
			
		||||
        },
 | 
			
		||||
        gasPrice: { $ref: '/Number' },
 | 
			
		||||
        zrxContractAddress: { $ref: '/Address' },
 | 
			
		||||
        exchangeContractAddress: { $ref: '/Address' },
 | 
			
		||||
        tokenRegistryContractAddress: { $ref: '/Address' },
 | 
			
		||||
        tokenTransferProxyContractAddress: { $ref: '/Address' },
 | 
			
		||||
        orderWatcherConfig: {
 | 
			
		||||
            type: 'object',
 | 
			
		||||
            properties: {
 | 
			
		||||
                pollingIntervalMs: {
 | 
			
		||||
                    type: 'number',
 | 
			
		||||
                    minimum: 0,
 | 
			
		||||
                },
 | 
			
		||||
                numConfirmations: {
 | 
			
		||||
                    type: 'number',
 | 
			
		||||
                    minimum: 0,
 | 
			
		||||
                },
 | 
			
		||||
            },
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
    type: 'object',
 | 
			
		||||
    required: [
 | 
			
		||||
        'networkId',
 | 
			
		||||
        'zrxContractAddress',
 | 
			
		||||
        'exchangeContractAddress',
 | 
			
		||||
        'tokenRegistryContractAddress',
 | 
			
		||||
        'tokenTransferProxyContractAddress',
 | 
			
		||||
    ],
 | 
			
		||||
};
 | 
			
		||||
@@ -0,0 +1,29 @@
 | 
			
		||||
export const zeroExPublicNetworkConfigSchema = {
 | 
			
		||||
    id: '/ZeroExPublicNetworkConfig',
 | 
			
		||||
    properties: {
 | 
			
		||||
        networkId: {
 | 
			
		||||
            type: 'number',
 | 
			
		||||
            enum: [1, 3, 4, 42, 50],
 | 
			
		||||
        },
 | 
			
		||||
        gasPrice: { $ref: '/Number' },
 | 
			
		||||
        zrxContractAddress: { $ref: '/Address' },
 | 
			
		||||
        exchangeContractAddress: { $ref: '/Address' },
 | 
			
		||||
        tokenRegistryContractAddress: { $ref: '/Address' },
 | 
			
		||||
        tokenTransferProxyContractAddress: { $ref: '/Address' },
 | 
			
		||||
        orderWatcherConfig: {
 | 
			
		||||
            type: 'object',
 | 
			
		||||
            properties: {
 | 
			
		||||
                pollingIntervalMs: {
 | 
			
		||||
                    type: 'number',
 | 
			
		||||
                    minimum: 0,
 | 
			
		||||
                },
 | 
			
		||||
                numConfirmations: {
 | 
			
		||||
                    type: 'number',
 | 
			
		||||
                    minimum: 0,
 | 
			
		||||
                },
 | 
			
		||||
            },
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
    type: 'object',
 | 
			
		||||
    required: ['networkId'],
 | 
			
		||||
};
 | 
			
		||||
@@ -9,6 +9,10 @@ import { ExchangeContractEventArgs, ExchangeEvents } from './contract_wrappers/g
 | 
			
		||||
import { TokenContractEventArgs, TokenEvents } from './contract_wrappers/generated/token';
 | 
			
		||||
 | 
			
		||||
export enum ZeroExError {
 | 
			
		||||
    ZRXAddressRequired = 'ZRX_ADDREESS_REQUIRED',
 | 
			
		||||
    ExchangeAddressRequired = 'EXCHANGE_ADDREESS_REQUIRED',
 | 
			
		||||
    TokenRegistryAddressRequired = 'TOKEN_REGISTRY_ADDREESS_REQUIRED',
 | 
			
		||||
    TokenTransferProxyAddressRequired = 'TOKEN_TRANSFER_PROXY_ADDREESS_REQUIRED',
 | 
			
		||||
    ExchangeContractDoesNotExist = 'EXCHANGE_CONTRACT_DOES_NOT_EXIST',
 | 
			
		||||
    ZRXContractDoesNotExist = 'ZRX_CONTRACT_DOES_NOT_EXIST',
 | 
			
		||||
    EtherTokenContractDoesNotExist = 'ETHER_TOKEN_CONTRACT_DOES_NOT_EXIST',
 | 
			
		||||
@@ -195,17 +199,8 @@ export interface OrderStateWatcherConfig {
 | 
			
		||||
    cleanupJobIntervalMs?: number;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * networkId: The id of the underlying ethereum network your provider is connected to. (1-mainnet, 42-kovan, 50-testrpc)
 | 
			
		||||
 * gasPrice: Gas price to use with every transaction
 | 
			
		||||
 * exchangeContractAddress: The address of an exchange contract to use
 | 
			
		||||
 * zrxContractAddress: The address of the ZRX contract to use
 | 
			
		||||
 * tokenRegistryContractAddress: The address of a token registry contract to use
 | 
			
		||||
 * tokenTransferProxyContractAddress: The address of the token transfer proxy contract to use
 | 
			
		||||
 * orderWatcherConfig: All the configs related to the orderWatcher
 | 
			
		||||
 */
 | 
			
		||||
export interface ZeroExConfig {
 | 
			
		||||
    networkId: number;
 | 
			
		||||
export interface ZeroExPublicNetworkConfig {
 | 
			
		||||
    networkId: 1 | 3 | 4 | 42 | 50;
 | 
			
		||||
    gasPrice?: BigNumber;
 | 
			
		||||
    exchangeContractAddress?: string;
 | 
			
		||||
    zrxContractAddress?: string;
 | 
			
		||||
@@ -214,6 +209,27 @@ export interface ZeroExConfig {
 | 
			
		||||
    orderWatcherConfig?: OrderStateWatcherConfig;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface ZeroExPrivateNetworkConfig {
 | 
			
		||||
    networkId: number;
 | 
			
		||||
    gasPrice?: BigNumber;
 | 
			
		||||
    exchangeContractAddress: string;
 | 
			
		||||
    zrxContractAddress: string;
 | 
			
		||||
    tokenRegistryContractAddress: string;
 | 
			
		||||
    tokenTransferProxyContractAddress: string;
 | 
			
		||||
    orderWatcherConfig?: OrderStateWatcherConfig;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * networkId: The id of the underlying ethereum network your provider is connected to. (1-mainnet, 3-ropsten, 4-rinkeby, 42-kovan, 50-testrpc)
 | 
			
		||||
 * gasPrice: Gas price to use with every transaction
 | 
			
		||||
 * exchangeContractAddress: The address of an exchange contract to use
 | 
			
		||||
 * zrxContractAddress: The address of the ZRX contract to use
 | 
			
		||||
 * tokenRegistryContractAddress: The address of a token registry contract to use
 | 
			
		||||
 * tokenTransferProxyContractAddress: The address of the token transfer proxy contract to use
 | 
			
		||||
 * orderWatcherConfig: All the configs related to the orderWatcher
 | 
			
		||||
 */
 | 
			
		||||
export type ZeroExConfig = ZeroExPublicNetworkConfig | ZeroExPrivateNetworkConfig;
 | 
			
		||||
 | 
			
		||||
export type ArtifactContractName = 'ZRX' | 'TokenTransferProxy' | 'TokenRegistry' | 'Token' | 'Exchange' | 'EtherToken';
 | 
			
		||||
 | 
			
		||||
export interface Artifact {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user