Merge branch 'development' into v2-prototype
This commit is contained in:
@@ -85,7 +85,7 @@ contract Exchange_v1 is SafeMath {
|
||||
bytes32 orderHash;
|
||||
}
|
||||
|
||||
function Exchange(address _zrxToken, address _tokenTransferProxy) {
|
||||
function Exchange_v1(address _zrxToken, address _tokenTransferProxy) {
|
||||
ZRX_TOKEN_CONTRACT = _zrxToken;
|
||||
TOKEN_TRANSFER_PROXY_CONTRACT = _tokenTransferProxy;
|
||||
}
|
||||
|
@@ -1,19 +1,37 @@
|
||||
import * as DummyERC20TokenArtifact from '../artifacts/DummyERC20Token.json';
|
||||
import * as ExchangeArtifact from '../artifacts/Exchange.json';
|
||||
import * as MultiSigWalletWithTimeLockArtifact from '../artifacts/MultiSigWalletWithTimeLock.json';
|
||||
import * as MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact from '../artifacts/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.json';
|
||||
import * as TokenRegistryArtifact from '../artifacts/TokenRegistry.json';
|
||||
import * as EtherTokenArtifact from '../artifacts/WETH9.json';
|
||||
import * as ZRXArtifact from '../artifacts/ZRXToken.json';
|
||||
import { ContractArtifact } from '@0xproject/sol-compiler';
|
||||
|
||||
import { Artifact } from './types';
|
||||
import * as DummyERC20Token from '../artifacts/DummyERC20Token.json';
|
||||
import * as DummyERC721Token from '../artifacts/DummyERC721Token.json';
|
||||
import * as ERC20Proxy from '../artifacts/ERC20Proxy.json';
|
||||
import * as ERC721Proxy from '../artifacts/ERC721Proxy.json';
|
||||
import * as Exchange from '../artifacts/Exchange.json';
|
||||
import * as MixinAuthorizable from '../artifacts/MixinAuthorizable.json';
|
||||
import * as MultiSigWallet from '../artifacts/MultiSigWallet.json';
|
||||
import * as MultiSigWalletWithTimeLock from '../artifacts/MultiSigWalletWithTimeLock.json';
|
||||
import * as MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress from '../artifacts/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.json';
|
||||
import * as TestAssetProxyDispatcher from '../artifacts/TestAssetProxyDispatcher.json';
|
||||
import * as TestLibBytes from '../artifacts/TestLibBytes.json';
|
||||
import * as TestLibs from '../artifacts/TestLibs.json';
|
||||
import * as TestSignatureValidator from '../artifacts/TestSignatureValidator.json';
|
||||
import * as TokenRegistry from '../artifacts/TokenRegistry.json';
|
||||
import * as EtherToken from '../artifacts/WETH9.json';
|
||||
import * as ZRX from '../artifacts/ZRXToken.json';
|
||||
|
||||
export const artifacts = {
|
||||
ZRXArtifact: (ZRXArtifact as any) as Artifact,
|
||||
DummyERC20TokenArtifact: (DummyERC20TokenArtifact as any) as Artifact,
|
||||
ExchangeArtifact: (ExchangeArtifact as any) as Artifact,
|
||||
EtherTokenArtifact: (EtherTokenArtifact as any) as Artifact,
|
||||
TokenRegistryArtifact: (TokenRegistryArtifact as any) as Artifact,
|
||||
MultiSigWalletWithTimeLockArtifact: (MultiSigWalletWithTimeLockArtifact as any) as Artifact,
|
||||
MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact as any) as Artifact,
|
||||
DummyERC20Token: (DummyERC20Token as any) as ContractArtifact,
|
||||
DummyERC721Token: (DummyERC721Token as any) as ContractArtifact,
|
||||
ERC20Proxy: (ERC20Proxy as any) as ContractArtifact,
|
||||
ERC721Proxy: (ERC721Proxy as any) as ContractArtifact,
|
||||
Exchange: (Exchange as any) as ContractArtifact,
|
||||
EtherToken: (EtherToken as any) as ContractArtifact,
|
||||
MixinAuthorizable: (MixinAuthorizable as any) as ContractArtifact,
|
||||
MultiSigWallet: (MultiSigWallet as any) as ContractArtifact,
|
||||
MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact,
|
||||
MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress as any) as ContractArtifact,
|
||||
TestAssetProxyDispatcher: (TestAssetProxyDispatcher as any) as ContractArtifact,
|
||||
TestLibBytes: (TestLibBytes as any) as ContractArtifact,
|
||||
TestLibs: (TestLibs as any) as ContractArtifact,
|
||||
TestSignatureValidator: (TestSignatureValidator as any) as ContractArtifact,
|
||||
TokenRegistry: (TokenRegistry as any) as ContractArtifact,
|
||||
ZRX: (ZRX as any) as ContractArtifact,
|
||||
};
|
||||
|
13
packages/contracts/src/utils/chai_setup.ts
Normal file
13
packages/contracts/src/utils/chai_setup.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import * as chai from 'chai';
|
||||
import chaiAsPromised = require('chai-as-promised');
|
||||
import ChaiBigNumber = require('chai-bignumber');
|
||||
import * as dirtyChai from 'dirty-chai';
|
||||
|
||||
export const chaiSetup = {
|
||||
configure() {
|
||||
chai.config.includeStack = true;
|
||||
chai.use(ChaiBigNumber());
|
||||
chai.use(dirtyChai);
|
||||
chai.use(chaiAsPromised);
|
||||
},
|
||||
};
|
@@ -3,10 +3,6 @@ import { BigNumber } from '@0xproject/utils';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
const DUMMY_TOKEN_NAME = '';
|
||||
const DUMMY_TOKEN_SYMBOL = '';
|
||||
const DUMMY_TOKEN_DECIMALS = 18;
|
||||
const DUMMY_TOKEN_TOTAL_SUPPLY = 0;
|
||||
const TESTRPC_PRIVATE_KEYS_STRINGS = [
|
||||
'0xf2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0164837257d',
|
||||
'0x5d862464fe9303452126c8bc94274b8c5f9874cbd219789b3eb2128075a76f72',
|
||||
@@ -27,8 +23,10 @@ export const constants = {
|
||||
MAX_ETHERTOKEN_WITHDRAW_GAS: 43000,
|
||||
MAX_TOKEN_TRANSFERFROM_GAS: 80000,
|
||||
MAX_TOKEN_APPROVE_GAS: 60000,
|
||||
DUMMY_ERC20_TOKEN_ARGS: [DUMMY_TOKEN_NAME, DUMMY_TOKEN_SYMBOL, DUMMY_TOKEN_DECIMALS, DUMMY_TOKEN_TOTAL_SUPPLY],
|
||||
DUMMY_ERC721_TOKEN_ARGS: [DUMMY_TOKEN_NAME, DUMMY_TOKEN_SYMBOL],
|
||||
DUMMY_TOKEN_NAME: '',
|
||||
DUMMY_TOKEN_SYMBOL: '',
|
||||
DUMMY_TOKEN_DECIMALS: new BigNumber(18),
|
||||
DUMMY_TOKEN_TOTAL_SUPPLY: new BigNumber(0),
|
||||
NUM_DUMMY_ERC20_TO_DEPLOY: 3,
|
||||
NUM_DUMMY_ERC721_TO_DEPLOY: 1,
|
||||
NUM_ERC721_TOKENS_TO_MINT: 2,
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import { Deployer } from '@0xproject/deployer';
|
||||
import { Provider } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
@@ -6,41 +5,43 @@ import * as _ from 'lodash';
|
||||
import { DummyERC20TokenContract } from '../contract_wrappers/generated/dummy_e_r_c20_token';
|
||||
import { ERC20ProxyContract } from '../contract_wrappers/generated/e_r_c20_proxy';
|
||||
|
||||
import { artifacts } from './artifacts';
|
||||
import { constants } from './constants';
|
||||
import { ContractName, ERC20BalancesByOwner } from './types';
|
||||
import { ERC20BalancesByOwner } from './types';
|
||||
import { txDefaults } from './web3_wrapper';
|
||||
|
||||
export class ERC20Wrapper {
|
||||
private _tokenOwnerAddresses: string[];
|
||||
private _contractOwnerAddress: string;
|
||||
private _deployer: Deployer;
|
||||
private _provider: Provider;
|
||||
private _dummyTokenContracts?: DummyERC20TokenContract[];
|
||||
private _proxyContract?: ERC20ProxyContract;
|
||||
constructor(deployer: Deployer, provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
|
||||
this._deployer = deployer;
|
||||
constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
|
||||
this._provider = provider;
|
||||
this._tokenOwnerAddresses = tokenOwnerAddresses;
|
||||
this._contractOwnerAddress = contractOwnerAddress;
|
||||
}
|
||||
public async deployDummyTokensAsync(): Promise<DummyERC20TokenContract[]> {
|
||||
const tokenContractInstances = await Promise.all(
|
||||
this._dummyTokenContracts = await Promise.all(
|
||||
_.times(constants.NUM_DUMMY_ERC20_TO_DEPLOY, () =>
|
||||
this._deployer.deployAsync(ContractName.DummyERC20Token, constants.DUMMY_ERC20_TOKEN_ARGS),
|
||||
DummyERC20TokenContract.deployFrom0xArtifactAsync(
|
||||
artifacts.DummyERC20Token,
|
||||
this._provider,
|
||||
txDefaults,
|
||||
constants.DUMMY_TOKEN_NAME,
|
||||
constants.DUMMY_TOKEN_SYMBOL,
|
||||
constants.DUMMY_TOKEN_DECIMALS,
|
||||
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||
),
|
||||
),
|
||||
);
|
||||
this._dummyTokenContracts = _.map(
|
||||
tokenContractInstances,
|
||||
tokenContractInstance =>
|
||||
new DummyERC20TokenContract(tokenContractInstance.abi, tokenContractInstance.address, this._provider),
|
||||
);
|
||||
return this._dummyTokenContracts;
|
||||
}
|
||||
public async deployProxyAsync(): Promise<ERC20ProxyContract> {
|
||||
const proxyContractInstance = await this._deployer.deployAsync(ContractName.ERC20Proxy);
|
||||
this._proxyContract = new ERC20ProxyContract(
|
||||
proxyContractInstance.abi,
|
||||
proxyContractInstance.address,
|
||||
this._proxyContract = await ERC20ProxyContract.deployFrom0xArtifactAsync(
|
||||
artifacts.ERC20Proxy,
|
||||
this._provider,
|
||||
txDefaults,
|
||||
);
|
||||
return this._proxyContract;
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import { ZeroEx } from '0x.js';
|
||||
import { Deployer } from '@0xproject/deployer';
|
||||
import { Provider } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
@@ -7,42 +6,42 @@ import * as _ from 'lodash';
|
||||
import { DummyERC721TokenContract } from '../contract_wrappers/generated/dummy_e_r_c721_token';
|
||||
import { ERC721ProxyContract } from '../contract_wrappers/generated/e_r_c721_proxy';
|
||||
|
||||
import { artifacts } from './artifacts';
|
||||
import { constants } from './constants';
|
||||
import { ContractName, ERC721TokenIdsByOwner } from './types';
|
||||
import { ERC721TokenIdsByOwner } from './types';
|
||||
import { txDefaults } from './web3_wrapper';
|
||||
|
||||
export class ERC721Wrapper {
|
||||
private _tokenOwnerAddresses: string[];
|
||||
private _contractOwnerAddress: string;
|
||||
private _deployer: Deployer;
|
||||
private _provider: Provider;
|
||||
private _dummyTokenContracts?: DummyERC721TokenContract[];
|
||||
private _proxyContract?: ERC721ProxyContract;
|
||||
private _initialTokenIdsByOwner: ERC721TokenIdsByOwner = {};
|
||||
constructor(deployer: Deployer, provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
|
||||
this._deployer = deployer;
|
||||
constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
|
||||
this._provider = provider;
|
||||
this._tokenOwnerAddresses = tokenOwnerAddresses;
|
||||
this._contractOwnerAddress = contractOwnerAddress;
|
||||
}
|
||||
public async deployDummyTokensAsync(): Promise<DummyERC721TokenContract[]> {
|
||||
const tokenContractInstances = await Promise.all(
|
||||
this._dummyTokenContracts = await Promise.all(
|
||||
_.times(constants.NUM_DUMMY_ERC721_TO_DEPLOY, () =>
|
||||
this._deployer.deployAsync(ContractName.DummyERC721Token, constants.DUMMY_ERC721_TOKEN_ARGS),
|
||||
DummyERC721TokenContract.deployFrom0xArtifactAsync(
|
||||
artifacts.DummyERC721Token,
|
||||
this._provider,
|
||||
txDefaults,
|
||||
constants.DUMMY_TOKEN_NAME,
|
||||
constants.DUMMY_TOKEN_SYMBOL,
|
||||
),
|
||||
),
|
||||
);
|
||||
this._dummyTokenContracts = _.map(
|
||||
tokenContractInstances,
|
||||
tokenContractInstance =>
|
||||
new DummyERC721TokenContract(tokenContractInstance.abi, tokenContractInstance.address, this._provider),
|
||||
);
|
||||
return this._dummyTokenContracts;
|
||||
}
|
||||
public async deployProxyAsync(): Promise<ERC721ProxyContract> {
|
||||
const proxyContractInstance = await this._deployer.deployAsync(ContractName.ERC721Proxy);
|
||||
this._proxyContract = new ERC721ProxyContract(
|
||||
proxyContractInstance.abi,
|
||||
proxyContractInstance.address,
|
||||
this._proxyContract = await ERC721ProxyContract.deployFrom0xArtifactAsync(
|
||||
artifacts.ERC721Proxy,
|
||||
this._provider,
|
||||
txDefaults,
|
||||
);
|
||||
return this._proxyContract;
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { ContractArtifact } from '@0xproject/sol-compiler';
|
||||
import { AbiDefinition, LogEntry, LogWithDecodedArgs, RawLog } from '@0xproject/types';
|
||||
import { AbiDecoder, BigNumber } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { artifacts } from './artifacts';
|
||||
import { Artifact } from './types';
|
||||
|
||||
export class LogDecoder {
|
||||
private _abiDecoder: AbiDecoder;
|
||||
@@ -12,12 +12,9 @@ export class LogDecoder {
|
||||
throw new Error('networkId not specified');
|
||||
}
|
||||
const abiArrays: AbiDefinition[][] = [];
|
||||
_.forEach(artifacts, (artifact: Artifact) => {
|
||||
const networkIfExists = artifact.networks[networkIdIfExists];
|
||||
if (_.isUndefined(networkIfExists)) {
|
||||
throw new Error(`Artifact does not exist on network ${networkIdIfExists}`);
|
||||
}
|
||||
abiArrays.push(networkIfExists.abi);
|
||||
_.forEach(artifacts, (artifact: ContractArtifact) => {
|
||||
const compilerOutput = artifact.compilerOutput;
|
||||
abiArrays.push(compilerOutput.abi);
|
||||
});
|
||||
this._abiDecoder = new AbiDecoder(abiArrays);
|
||||
}
|
||||
|
@@ -103,22 +103,6 @@ export enum ContractName {
|
||||
Authorizable = 'Authorizable',
|
||||
}
|
||||
|
||||
export interface Artifact {
|
||||
contract_name: ContractName;
|
||||
networks: {
|
||||
[networkId: number]: {
|
||||
abi: ContractAbi;
|
||||
solc_version: string;
|
||||
keccak256: string;
|
||||
optimizer_enabled: number;
|
||||
unlinked_binary: string;
|
||||
updated_at: number;
|
||||
address: string;
|
||||
constructor_args: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface SignedOrder extends UnsignedOrder {
|
||||
signature: string;
|
||||
}
|
||||
|
12
packages/contracts/src/utils/web3_wrapper.ts
Normal file
12
packages/contracts/src/utils/web3_wrapper.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { devConstants, web3Factory } from '@0xproject/dev-utils';
|
||||
import { Provider } from '@0xproject/types';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
|
||||
export const txDefaults = {
|
||||
from: devConstants.TESTRPC_FIRST_ADDRESS,
|
||||
gas: devConstants.GAS_ESTIMATE,
|
||||
};
|
||||
const providerConfigs = { shouldUseInProcessGanache: true };
|
||||
export const web3 = web3Factory.create(providerConfigs);
|
||||
export const provider = web3.currentProvider;
|
||||
export const web3Wrapper = new Web3Wrapper(provider);
|
Reference in New Issue
Block a user