Merge branch 'deployment/2.0.0-beta-testnet/ropsten' of github.com:0xProject/0x-monorepo into deployment/2.0.0-beta-testnet/ropsten

This commit is contained in:
Jacob Evans
2018-09-04 20:32:43 +01:00
24 changed files with 6042 additions and 46 deletions

1
.gitignore vendored
View File

@@ -101,6 +101,7 @@ packages/order-utils/src/generated_contract_wrappers/
packages/migrations/src/1.0.0/contract_wrappers
packages/migrations/src/2.0.0/contract_wrappers
packages/migrations/src/2.0.0-beta-testnet/contract_wrappers
packages/migrations/src/2.0.0-mainnet/contract_wrappers
# solc-bin in sol-compiler
packages/sol-compiler/solc_bin/

View File

@@ -10,6 +10,7 @@ lib
/packages/migrations/src/1.0.0/contract_wrappers
/packages/migrations/src/2.0.0/contract_wrappers
/packages/migrations/src/2.0.0-beta-testnet/contract_wrappers
/packages/migrations/src/2.0.0-mainnet/contract_wrappers
/packages/0x.js/src/artifacts
/packages/contracts/src/artifacts
/packages/contract-wrappers/src/artifacts
@@ -21,5 +22,6 @@ lib
/packages/migrations/artifacts/1.0.0
/packages/migrations/artifacts/2.0.0
/packages/migrations/artifacts/2.0.0-beta-testnet
/packages/migrations/artifacts/2.0.0-mainnet
package.json
scripts/postpublish_utils.js

View File

@@ -46,6 +46,7 @@ export {
BalanceAndAllowance,
OrderAndTraderInfo,
TraderInfo,
ValidateOrderFillableOpts,
} from '@0xproject/contract-wrappers';
export { OrderWatcher, OnOrderStateChangeCallback, OrderWatcherConfig } from '@0xproject/order-watcher';

View File

@@ -4,6 +4,16 @@
"changes": [
{
"note": "Add `OrderValidatorWrapper`"
},
{
"note":
"Export `AssetBalanceAndProxyAllowanceFetcher` and `OrderFilledCancelledFetcher` implementations",
"pr": 1054
},
{
"note":
"Add `validateOrderFillableOrThrowAsync` and `validateFillOrderThrowIfInvalidAsync` to ExchangeWrapper",
"pr": 1054
}
]
},

View File

@@ -111,6 +111,8 @@ export class ContractWrappers {
this.exchange = new ExchangeWrapper(
this._web3Wrapper,
config.networkId,
this.erc20Token,
this.erc721Token,
config.exchangeContractAddress,
config.zrxContractAddress,
blockPollingIntervalMs,

View File

@@ -1,12 +1,19 @@
import { schemas } from '@0xproject/json-schemas';
import { assetDataUtils } from '@0xproject/order-utils';
import {
assetDataUtils,
BalanceAndProxyAllowanceLazyStore,
ExchangeTransferSimulator,
OrderValidationUtils,
} from '@0xproject/order-utils';
import { AssetProxyId, Order, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { ContractAbi, LogWithDecodedArgs } from 'ethereum-types';
import { BlockParamLiteral, ContractAbi, LogWithDecodedArgs } from 'ethereum-types';
import * as _ from 'lodash';
import { artifacts } from '../artifacts';
import { AssetBalanceAndProxyAllowanceFetcher } from '../fetchers/asset_balance_and_proxy_allowance_fetcher';
import { OrderFilledCancelledFetcher } from '../fetchers/order_filled_cancelled_fetcher';
import { methodOptsSchema } from '../schemas/method_opts_schema';
import { orderTxOptsSchema } from '../schemas/order_tx_opts_schema';
import { txOptsSchema } from '../schemas/tx_opts_schema';
@@ -17,13 +24,17 @@ import {
IndexedFilterValues,
MethodOpts,
OrderInfo,
OrderStatus,
OrderTransactionOpts,
ValidateOrderFillableOpts,
} from '../types';
import { assert } from '../utils/assert';
import { decorators } from '../utils/decorators';
import { TransactionEncoder } from '../utils/transaction_encoder';
import { ContractWrapper } from './contract_wrapper';
import { ERC20TokenWrapper } from './erc20_token_wrapper';
import { ERC721TokenWrapper } from './erc721_token_wrapper';
import { ExchangeContract, ExchangeEventArgs, ExchangeEvents } from './generated/exchange';
/**
@@ -33,6 +44,8 @@ import { ExchangeContract, ExchangeEventArgs, ExchangeEvents } from './generated
export class ExchangeWrapper extends ContractWrapper {
public abi: ContractAbi = artifacts.Exchange.compilerOutput.abi;
private _exchangeContractIfExists?: ExchangeContract;
private _erc721TokenWrapper: ERC721TokenWrapper;
private _erc20TokenWrapper: ERC20TokenWrapper;
private _contractAddressIfExists?: string;
private _zrxContractAddressIfExists?: string;
/**
@@ -48,11 +61,15 @@ export class ExchangeWrapper extends ContractWrapper {
constructor(
web3Wrapper: Web3Wrapper,
networkId: number,
erc20TokenWrapper: ERC20TokenWrapper,
erc721TokenWrapper: ERC721TokenWrapper,
contractAddressIfExists?: string,
zrxContractAddressIfExists?: string,
blockPollingIntervalMs?: number,
) {
super(web3Wrapper, networkId, blockPollingIntervalMs);
this._erc20TokenWrapper = erc20TokenWrapper;
this._erc721TokenWrapper = erc721TokenWrapper;
this._contractAddressIfExists = contractAddressIfExists;
this._zrxContractAddressIfExists = zrxContractAddressIfExists;
}
@@ -1084,6 +1101,64 @@ export class ExchangeWrapper extends ContractWrapper {
);
return logs;
}
/**
* Validate if the supplied order is fillable, and throw if it isn't
* @param signedOrder SignedOrder of interest
* @param opts ValidateOrderFillableOpts options (e.g expectedFillTakerTokenAmount.
* If it isn't supplied, we check if the order is fillable for a non-zero amount)
*/
public async validateOrderFillableOrThrowAsync(
signedOrder: SignedOrder,
opts: ValidateOrderFillableOpts = {},
): Promise<void> {
const balanceAllowanceFetcher = new AssetBalanceAndProxyAllowanceFetcher(
this._erc20TokenWrapper,
this._erc721TokenWrapper,
BlockParamLiteral.Latest,
);
const balanceAllowanceStore = new BalanceAndProxyAllowanceLazyStore(balanceAllowanceFetcher);
const exchangeTradeSimulator = new ExchangeTransferSimulator(balanceAllowanceStore);
const expectedFillTakerTokenAmountIfExists = opts.expectedFillTakerTokenAmount;
const filledCancelledFetcher = new OrderFilledCancelledFetcher(this, BlockParamLiteral.Latest);
const orderValidationUtils = new OrderValidationUtils(filledCancelledFetcher);
await orderValidationUtils.validateOrderFillableOrThrowAsync(
exchangeTradeSimulator,
signedOrder,
this.getZRXAssetData(),
expectedFillTakerTokenAmountIfExists,
);
}
/**
* Validate a call to FillOrder and throw if it wouldn't succeed
* @param signedOrder SignedOrder of interest
* @param fillTakerAssetAmount Amount we'd like to fill the order for
* @param takerAddress The taker of the order
*/
public async validateFillOrderThrowIfInvalidAsync(
signedOrder: SignedOrder,
fillTakerAssetAmount: BigNumber,
takerAddress: string,
): Promise<void> {
const balanceAllowanceFetcher = new AssetBalanceAndProxyAllowanceFetcher(
this._erc20TokenWrapper,
this._erc721TokenWrapper,
BlockParamLiteral.Latest,
);
const balanceAllowanceStore = new BalanceAndProxyAllowanceLazyStore(balanceAllowanceFetcher);
const exchangeTradeSimulator = new ExchangeTransferSimulator(balanceAllowanceStore);
const filledCancelledFetcher = new OrderFilledCancelledFetcher(this, BlockParamLiteral.Latest);
const orderValidationUtils = new OrderValidationUtils(filledCancelledFetcher);
await orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
exchangeTradeSimulator,
this._web3Wrapper.getProvider(),
signedOrder,
fillTakerAssetAmount,
takerAddress,
this.getZRXAssetData(),
);
}
/**
* Retrieves the Ethereum address of the Exchange contract deployed on the network
* that the user-passed web3 provider is connected to.

View File

@@ -1,8 +1,11 @@
// tslint:disable:no-unnecessary-type-assertion
import { BlockParamLiteral, ERC20TokenWrapper, ERC721TokenWrapper } from '@0xproject/contract-wrappers';
import { AbstractBalanceAndProxyAllowanceFetcher, assetDataUtils } from '@0xproject/order-utils';
import { AssetProxyId, ERC20AssetData, ERC721AssetData } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { BlockParamLiteral } from 'ethereum-types';
import { ERC20TokenWrapper } from '../contract_wrappers/erc20_token_wrapper';
import { ERC721TokenWrapper } from '../contract_wrappers/erc721_token_wrapper';
export class AssetBalanceAndProxyAllowanceFetcher implements AbstractBalanceAndProxyAllowanceFetcher {
private readonly _erc20Token: ERC20TokenWrapper;

View File

@@ -1,7 +1,10 @@
// tslint:disable:no-unnecessary-type-assertion
import { BlockParamLiteral, ExchangeWrapper } from '@0xproject/contract-wrappers';
import { AbstractOrderFilledCancelledFetcher } from '@0xproject/order-utils';
import { BigNumber } from '@0xproject/utils';
import { BlockParamLiteral } from 'ethereum-types';
import { ERC20TokenWrapper } from '../contract_wrappers/erc20_token_wrapper';
import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper';
export class OrderFilledCancelledFetcher implements AbstractOrderFilledCancelledFetcher {
private readonly _exchange: ExchangeWrapper;

View File

@@ -25,6 +25,7 @@ export {
BalanceAndAllowance,
OrderAndTraderInfo,
TraderInfo,
ValidateOrderFillableOpts,
} from './types';
export { Order, SignedOrder, AssetProxyId } from '@0xproject/types';
@@ -85,3 +86,8 @@ export {
ExchangeEventArgs,
ExchangeEvents,
} from './contract_wrappers/generated/exchange';
export { AbstractBalanceAndProxyAllowanceFetcher, AbstractOrderFilledCancelledFetcher } from '@0xproject/order-utils';
export { AssetBalanceAndProxyAllowanceFetcher } from './fetchers/asset_balance_and_proxy_allowance_fetcher';
export { OrderFilledCancelledFetcher } from './fetchers/order_filled_cancelled_fetcher';

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -11,27 +11,32 @@
"build": "yarn pre_build && tsc -b",
"pre_build": "run-s compile:v2 copy_artifacts generate_contract_wrappers",
"copy_artifacts": "copyfiles 'artifacts/**/*' ./lib",
"clean": "shx rm -rf lib src/1.0.0/contract_wrappers src/2.0.0/contract_wrappers src/2.0.0-beta-testnet/contract_wrappers artifacts/2.0.0",
"clean": "shx rm -rf lib src/1.0.0/contract_wrappers src/2.0.0/contract_wrappers src/2.0.0-beta-testnet/contract_wrappers src/2.0.0-mainnet/contract_wrappers artifacts/2.0.0",
"lint": "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-testnet": "run-s build compile:v2-beta-testnet script:migrate:v2-beta-testnet",
"migrate:v2-mainnet": "run-s compile:v2-mainnet copy_artifacts generate_contract_wrappers:v2-mainnet && tsc && yarn script:migrate:v2-mainnet",
"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-testnet": "node ./lib/migrate.js --contracts-version 2.0.0-beta-testnet",
"script:migrate:v2-mainnet": "node ./lib/migrate.js --contracts-version 2.0.0-mainnet",
"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-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",
"generate_contract_wrappers:v2-mainnet": "abi-gen --abis ${npm_package_config_abis_v2Mainnet} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0-mainnet/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 AssetProxyOwner,ERC20Token,DummyERC20Token,ERC721Token,DummyERC721Token,ERC20Proxy,ERC721Proxy,Exchange,Forwarder,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,ZRXToken,WETH9,IWallet,IValidator,OrderValidator",
"compile:v2-beta-testnet": "sol-compiler --artifacts-dir artifacts/2.0.0-beta-testnet --contracts AssetProxyOwner,DummyERC20Token,DummyERC721Token,ERC20Proxy,ERC721Proxy,Exchange,Forwarder,IWallet,IValidator,ERC20Token,ERC721Token,OrderValidator,ZRXToken"
"compile:v2-beta-testnet": "sol-compiler --artifacts-dir artifacts/2.0.0-beta-testnet --contracts AssetProxyOwner,DummyERC20Token,DummyERC721Token,ERC20Proxy,ERC721Proxy,Exchange,Forwarder,IWallet,IValidator,ERC20Token,ERC721Token,OrderValidator,ZRXToken",
"compile:v2-mainnet": "sol-compiler --artifacts-dir artifacts/2.0.0-mainnet --contracts AssetProxyOwner,ERC20Proxy,ERC721Proxy,Exchange,Forwarder,OrderValidator"
},
"config": {
"abis": {
"v1": "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|Forwarder|AssetProxyOwner|ZRXToken|WETH9|IWallet|IValidator|OrderValidator).json",
"v2BetaTestnet": "artifacts/2.0.0-beta-testnet/@(DummyERC721Token|DummyERC20Token|ERC20Token|ERC721Token|ERC20Proxy|ERC721Proxy|Exchange|Forwarder|AssetProxyOwner|IWallet|IValidator|OrderValidator|ZRXToken).json"
"v2BetaTestnet": "artifacts/2.0.0-beta-testnet/@(DummyERC721Token|DummyERC20Token|ERC20Token|ERC721Token|ERC20Proxy|ERC721Proxy|Exchange|Forwarder|AssetProxyOwner|IWallet|IValidator|OrderValidator|ZRXToken).json",
"v2Mainnet": "artifacts/2.0.0-mainnet/@(AssetProxyOwner|ERC20Proxy|ERC721Proxy|Exchange|Forwarder|OrderValidator).json"
}
},
"license": "Apache-2.0",

View File

@@ -0,0 +1,17 @@
import { ContractArtifact } from 'ethereum-types';
import * as AssetProxyOwner from '../../artifacts/2.0.0-mainnet/AssetProxyOwner.json';
import * as ERC20Proxy from '../../artifacts/2.0.0-mainnet/ERC20Proxy.json';
import * as ERC721Proxy from '../../artifacts/2.0.0-mainnet/ERC721Proxy.json';
import * as Exchange from '../../artifacts/2.0.0-mainnet/Exchange.json';
import * as Forwarder from '../../artifacts/2.0.0-mainnet/Forwarder.json';
import * as OrderValidator from '../../artifacts/2.0.0-mainnet/OrderValidator.json';
export const artifacts = {
AssetProxyOwner: (AssetProxyOwner as any) as ContractArtifact,
ERC20Proxy: (ERC20Proxy as any) as ContractArtifact,
ERC721Proxy: (ERC721Proxy as any) as ContractArtifact,
Exchange: (Exchange as any) as ContractArtifact,
Forwarder: (Forwarder as any) as ContractArtifact,
OrderValidator: (OrderValidator as any) as ContractArtifact,
};

View File

@@ -0,0 +1,13 @@
import { BigNumber } from '@0xproject/utils';
export const constants = {
ASSET_PROXY_OWNER_OWNERS: [
'0x257619b7155d247e43c8b6d90c8c17278ae481f0',
'0x5ee2a00f8f01d099451844af7f894f26a57fcbf2',
'0x894d623e0e0e8ed12c4a73dada999e275684a37d',
],
ASSET_PROXY_OWNER_REQUIRED_CONFIRMATIONS: new BigNumber(2),
ASSET_PROXY_OWNER_SECONDS_TIMELOCKED: new BigNumber(1209600),
WETH_ADDRESS: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
ZRX_ADDRESS: '0xe41d2489571d322189246dafa5ebde1f4699f498',
};

View File

@@ -0,0 +1,122 @@
import { assetDataUtils } from '@0xproject/order-utils';
import { logUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider, TxData } from 'ethereum-types';
import { ArtifactWriter } from '../utils/artifact_writer';
import { artifacts } from './artifacts';
import { constants } from './constants';
import { AssetProxyOwnerContract } from './contract_wrappers/asset_proxy_owner';
import { ERC20ProxyContract } from './contract_wrappers/erc20_proxy';
import { ERC721ProxyContract } from './contract_wrappers/erc721_proxy';
import { ExchangeContract } from './contract_wrappers/exchange';
import { ForwarderContract } from './contract_wrappers/forwarder';
import { OrderValidatorContract } from './contract_wrappers/order_validator';
/**
* Custom migrations should be defined in this function. This will be called with the CLI 'migrate:v2-mainnet' 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 runV2MainnetMigrationsAsync = async (
provider: Provider,
artifactsDir: string,
txDefaults: Partial<TxData>,
) => {
const web3Wrapper = new Web3Wrapper(provider);
const networkId = await web3Wrapper.getNetworkIdAsync();
const artifactsWriter = new ArtifactWriter(artifactsDir, networkId);
// Deploy AssetProxies
const erc20proxy = await ERC20ProxyContract.deployFrom0xArtifactAsync(artifacts.ERC20Proxy, provider, txDefaults);
artifactsWriter.saveArtifact(erc20proxy);
const erc721proxy = await ERC721ProxyContract.deployFrom0xArtifactAsync(
artifacts.ERC721Proxy,
provider,
txDefaults,
);
artifactsWriter.saveArtifact(erc721proxy);
// Deploy Exchange
const exchange = await ExchangeContract.deployFrom0xArtifactAsync(artifacts.Exchange, provider, txDefaults);
artifactsWriter.saveArtifact(exchange);
let txHash;
// Register AssetProxies in Exchange
txHash = await exchange.registerAssetProxy.sendTransactionAsync(erc20proxy.address);
logUtils.log(`transactionHash: ${txHash}`);
logUtils.log('Registering ERC20Proxy');
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
txHash = await exchange.registerAssetProxy.sendTransactionAsync(erc721proxy.address);
logUtils.log(`transactionHash: ${txHash}`);
logUtils.log('Registering ERC721Proxy');
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
// Deploy AssetProxyOwner
const assetProxies = [erc20proxy.address, erc721proxy.address];
const assetProxyOwner = await AssetProxyOwnerContract.deployFrom0xArtifactAsync(
artifacts.AssetProxyOwner,
provider,
txDefaults,
constants.ASSET_PROXY_OWNER_OWNERS,
assetProxies,
constants.ASSET_PROXY_OWNER_REQUIRED_CONFIRMATIONS,
constants.ASSET_PROXY_OWNER_SECONDS_TIMELOCKED,
);
artifactsWriter.saveArtifact(assetProxyOwner);
// Deploy Forwarder
const zrxAssetData = assetDataUtils.encodeERC20AssetData(constants.ZRX_ADDRESS);
const wethAssetData = assetDataUtils.encodeERC20AssetData(constants.WETH_ADDRESS);
const forwarder = await ForwarderContract.deployFrom0xArtifactAsync(
artifacts.Forwarder,
provider,
txDefaults,
exchange.address,
zrxAssetData,
wethAssetData,
);
artifactsWriter.saveArtifact(forwarder);
// Deploy OrderValidator
const orderValidator = await OrderValidatorContract.deployFrom0xArtifactAsync(
artifacts.OrderValidator,
provider,
txDefaults,
exchange.address,
zrxAssetData,
);
artifactsWriter.saveArtifact(orderValidator);
// Authorize Exchange contracts to call AssetProxies
txHash = await erc20proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address);
logUtils.log(`transactionHash: ${txHash}`);
logUtils.log('Authorizing Exchange on ERC20Proxy');
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
txHash = await erc721proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address);
logUtils.log(`transactionHash: ${txHash}`);
logUtils.log('Authorizing Exchange on ERC721Proxy');
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
// Transfer ownership of AssetProxies and Exchange to AssetProxyOwner
txHash = await erc20proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address);
logUtils.log(`transactionHash: ${txHash}`);
logUtils.log('Transferring ownership of ERC20Proxy');
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
txHash = await erc721proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address);
logUtils.log(`transactionHash: ${txHash}`);
logUtils.log('Transferring ownership of ERC721Proxy');
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
txHash = await exchange.transferOwnership.sendTransactionAsync(assetProxyOwner.address);
logUtils.log(`transactionHash: ${txHash}`);
logUtils.log('Transferring ownership of Exchange');
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
};

View File

@@ -7,6 +7,7 @@ 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';
@@ -15,6 +16,7 @@ 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;
@@ -24,6 +26,8 @@ const args = yargs.argv;
let providerConfigs;
let provider: Provider;
let txDefaults;
let web3Wrapper: Web3Wrapper;
let accounts: string[];
switch (contractsVersion) {
case ContractVersions.V1:
providerConfigs = { shouldUseInProcessGanache: false };
@@ -42,15 +46,26 @@ const args = yargs.argv;
await runV2MigrationsAsync(provider, artifactsDir, txDefaults);
break;
case ContractVersions.V2Testnet:
provider = await providerFactory.getLedgerProviderAsync();
const web3Wrapper = new Web3Wrapper(provider);
const accounts = await web3Wrapper.getAvailableAddressesAsync();
provider = await providerFactory.getKovanLedgerProviderAsync();
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.getMainnetLedgerProviderAsync();
web3Wrapper = new Web3Wrapper(provider);
accounts = await web3Wrapper.getAvailableAddressesAsync();
txDefaults = {
from: accounts[2],
gas: devConstants.GAS_LIMIT,
gasPrice: 6000000000,
};
await runV2MainnetMigrationsAsync(provider, artifactsDir, txDefaults);
break;
default:
throw new Error(`Unsupported contract version: ${contractsVersion}`);
}

View File

@@ -13,4 +13,6 @@ export const constants = {
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
KOVAN_RPC_URL: 'https://kovan.infura.io/',
KOVAN_NETWORK_ID: 42,
MAINNET_RPC_URL: 'https://mainnet.infura.io/',
MAINNET_NETWORK_ID: 1,
};

View File

@@ -12,7 +12,7 @@ async function ledgerEthereumNodeJsClientFactoryAsync(): Promise<LedgerEthereumC
return ledgerEthClient;
}
export const providerFactory = {
async getLedgerProviderAsync(): Promise<Provider> {
async getKovanLedgerProviderAsync(): Promise<Provider> {
const provider = new Web3ProviderEngine();
const ledgerWalletConfigs = {
networkId: constants.KOVAN_NETWORK_ID,
@@ -24,4 +24,16 @@ export const providerFactory = {
provider.start();
return provider;
},
async getMainnetLedgerProviderAsync(): Promise<Provider> {
const provider = new Web3ProviderEngine();
const ledgerWalletConfigs = {
networkId: constants.MAINNET_NETWORK_ID,
ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync,
};
const ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs);
provider.addProvider(ledgerSubprovider);
provider.addProvider(new RPCSubprovider(constants.MAINNET_RPC_URL));
provider.start();
return provider;
},
};

View File

@@ -1,5 +1,6 @@
// tslint:disable:no-unnecessary-type-assertion
import {
AssetBalanceAndProxyAllowanceFetcher,
ContractWrappers,
ERC20TokenApprovalEventArgs,
ERC20TokenEventArgs,
@@ -15,6 +16,7 @@ import {
ExchangeEventArgs,
ExchangeEvents,
ExchangeFillEventArgs,
OrderFilledCancelledFetcher,
WETH9DepositEventArgs,
WETH9EventArgs,
WETH9Events,
@@ -34,8 +36,6 @@ import { BlockParamLiteral, LogEntryEvent, LogWithDecodedArgs, Provider } from '
import * as _ from 'lodash';
import { artifacts } from '../artifacts';
import { AssetBalanceAndProxyAllowanceFetcher } from '../fetchers/asset_balance_and_proxy_allowance_fetcher';
import { OrderFilledCancelledFetcher } from '../fetchers/order_filled_cancelled_fetcher';
import { orderWatcherPartialConfigSchema } from '../schemas/order_watcher_partial_config_schema';
import { OnOrderStateChangeCallback, OrderWatcherConfig, OrderWatcherError } from '../types';
import { assert } from '../utils/assert';

View File

@@ -1411,9 +1411,9 @@ aes-js@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-3.0.0.tgz#e21df10ad6c2053295bcbb8dab40b09dbea87e4d"
aes-js@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-3.1.1.tgz#89fd1f94ae51b4c72d62466adc1a7323ff52f072"
aes-js@^0.2.3:
version "0.2.4"
resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-0.2.4.tgz#94b881ab717286d015fa219e08fb66709dda5a3d"
ajv-keywords@^2.1.0:
version "2.1.1"
@@ -2479,6 +2479,10 @@ balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
base-x@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/base-x/-/base-x-1.1.0.tgz#42d3d717474f9ea02207f6d1aa1f426913eeb7ac"
base-x@^3.0.2:
version "3.0.4"
resolved "https://registry.yarnpkg.com/base-x/-/base-x-3.0.4.tgz#94c1788736da065edb1d68808869e357c977fa77"
@@ -2886,7 +2890,7 @@ browserslist@^2.1.2:
caniuse-lite "^1.0.30000792"
electron-to-chromium "^1.3.30"
bs58@=4.0.1, bs58@^4.0.0:
bs58@=4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/bs58/-/bs58-4.0.1.tgz#be161e76c354f6f788ae4071f63f34e8c4f0a42a"
dependencies:
@@ -2896,13 +2900,18 @@ bs58@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/bs58/-/bs58-2.0.1.tgz#55908d58f1982aba2008fa1bed8f91998a29bf8d"
bs58check@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/bs58check/-/bs58check-2.1.2.tgz#53b018291228d82a5aa08e7d796fdafda54aebfc"
bs58@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/bs58/-/bs58-3.1.0.tgz#d4c26388bf4804cac714141b1945aa47e5eb248e"
dependencies:
bs58 "^4.0.0"
base-x "^1.1.0"
bs58check@^1.0.8:
version "1.3.4"
resolved "https://registry.yarnpkg.com/bs58check/-/bs58check-1.3.4.tgz#c52540073749117714fa042c3047eb8f9151cbf8"
dependencies:
bs58 "^3.1.0"
create-hash "^1.1.0"
safe-buffer "^5.1.2"
btoa@1.1.2:
version "1.1.2"
@@ -5288,7 +5297,7 @@ ethereumjs-util@5.1.5, ethereumjs-util@^5.0.0, ethereumjs-util@^5.0.1, ethereumj
safe-buffer "^5.1.1"
secp256k1 "^3.0.1"
ethereumjs-util@^4.0.1, ethereumjs-util@^4.3.0:
ethereumjs-util@^4.0.1, ethereumjs-util@^4.3.0, ethereumjs-util@^4.4.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-4.5.0.tgz#3e9428b317eebda3d7260d854fddda954b1f1bc6"
dependencies:
@@ -5342,18 +5351,17 @@ ethereumjs-vm@^2.0.2, ethereumjs-vm@^2.1.0, ethereumjs-vm@^2.3.4:
rustbn.js "~0.1.1"
safe-buffer "^5.1.1"
ethereumjs-wallet@~0.6.0:
version "0.6.2"
resolved "https://registry.yarnpkg.com/ethereumjs-wallet/-/ethereumjs-wallet-0.6.2.tgz#67244b6af3e8113b53d709124b25477b64aeccda"
ethereumjs-wallet@0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/ethereumjs-wallet/-/ethereumjs-wallet-0.6.0.tgz#82763b1697ee7a796be7155da9dfb49b2f98cfdb"
dependencies:
aes-js "^3.1.1"
bs58check "^2.1.2"
ethereumjs-util "^5.2.0"
hdkey "^1.0.0"
safe-buffer "^5.1.2"
aes-js "^0.2.3"
bs58check "^1.0.8"
ethereumjs-util "^4.4.0"
hdkey "^0.7.0"
scrypt.js "^0.2.0"
utf8 "^3.0.0"
uuid "^3.3.2"
utf8 "^2.1.1"
uuid "^2.0.1"
ethers@0xproject/ethers.js#eip-838-reasons, ethers@3.0.22:
version "3.0.18"
@@ -6794,21 +6802,13 @@ hawk@~6.0.2:
hoek "4.x.x"
sntp "2.x.x"
hdkey@^0.7.1:
hdkey@^0.7.0, hdkey@^0.7.1:
version "0.7.1"
resolved "https://registry.yarnpkg.com/hdkey/-/hdkey-0.7.1.tgz#caee4be81aa77921e909b8d228dd0f29acaee632"
dependencies:
coinstring "^2.0.0"
secp256k1 "^3.0.1"
hdkey@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/hdkey/-/hdkey-1.1.0.tgz#e74e7b01d2c47f797fa65d1d839adb7a44639f29"
dependencies:
coinstring "^2.0.0"
safe-buffer "^5.1.1"
secp256k1 "^3.0.1"
he@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd"
@@ -14311,10 +14311,6 @@ utf8@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/utf8/-/utf8-2.1.2.tgz#1fa0d9270e9be850d9b05027f63519bf46457d96"
utf8@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/utf8/-/utf8-3.0.0.tgz#f052eed1364d696e769ef058b183df88c87f69d1"
util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"