Introduce new contract-addresses package and use it everywhere
This commit is contained in:
parent
fa346d9461
commit
1e9ea09f08
@ -37,6 +37,7 @@
|
||||
"dependencies": {
|
||||
"@0xproject/assert": "^1.0.13",
|
||||
"@0xproject/connect": "^3.0.1",
|
||||
"@0xproject/contract-addresses": "^1.0.0",
|
||||
"@0xproject/contract-wrappers": "^2.0.2",
|
||||
"@0xproject/json-schemas": "^1.0.7",
|
||||
"@0xproject/order-utils": "^1.0.7",
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { getContractAddressesForNetwork } from '@0xproject/contract-addresses';
|
||||
import { ContractWrappers } from '@0xproject/contract-wrappers';
|
||||
import { schemas } from '@0xproject/json-schemas';
|
||||
import { SignedOrder } from '@0xproject/order-utils';
|
||||
@ -109,17 +110,7 @@ export class AssetBuyer {
|
||||
this.expiryBufferSeconds = expiryBufferSeconds;
|
||||
this._contractWrappers = new ContractWrappers(this.provider, {
|
||||
networkId,
|
||||
// TODO(albrow): Load in real contract addresses here.
|
||||
contractAddresses: {
|
||||
erc20Proxy: '',
|
||||
erc721Proxy: '',
|
||||
zrxToken: '',
|
||||
etherToken: '',
|
||||
exchange: '',
|
||||
assetProxyOwner: '',
|
||||
forwarder: '',
|
||||
orderValidator: '',
|
||||
},
|
||||
contractAddresses: getContractAddressesForNetwork(networkId),
|
||||
});
|
||||
}
|
||||
/**
|
||||
|
37
packages/contract-addresses/package.json
Normal file
37
packages/contract-addresses/package.json
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "@0xproject/contract-addresses",
|
||||
"version": "1.0.0",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
"description": "Addresses of deployed 0x contracts on Ethereum mainnet and testnets",
|
||||
"main": "lib/src/index.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn tsc -b",
|
||||
"build:ci": "yarn build",
|
||||
"clean": "shx rm -rf lib"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/0xProject/0x-monorepo.git"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/0xProject/0x-monorepo/issues"
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/contract-addresses/README.md",
|
||||
"devDependencies": {
|
||||
"typescript": "3.0.1",
|
||||
"shx": "^0.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0xproject/types": "1.1.4",
|
||||
"lodash": "^4.17.5"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
64
packages/contract-addresses/src/index.ts
Normal file
64
packages/contract-addresses/src/index.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import * as _ from 'lodash';
|
||||
|
||||
export interface ContractAddresses {
|
||||
erc20Proxy: string;
|
||||
erc721Proxy: string;
|
||||
zrxToken: string;
|
||||
etherToken: string;
|
||||
exchange: string;
|
||||
assetProxyOwner: string;
|
||||
forwarder: string;
|
||||
orderValidator: string;
|
||||
}
|
||||
|
||||
export enum NetworkId {
|
||||
Mainnet = 1,
|
||||
Ropsten = 3,
|
||||
Kovan = 42,
|
||||
}
|
||||
|
||||
const networkToAddresses: { [networkId: number]: ContractAddresses } = {
|
||||
1: {
|
||||
erc20Proxy: '0x2240dab907db71e64d3e0dba4800c83b5c502d4e',
|
||||
erc721Proxy: '0x208e41fb445f1bb1b6780d58356e81405f3e6127',
|
||||
zrxToken: '0xe41d2489571d322189246dafa5ebde1f4699f498',
|
||||
etherToken: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
||||
exchange: '0x4f833a24e1f95d70f028921e27040ca56e09ab0b',
|
||||
assetProxyOwner: '0x17992e4ffb22730138e4b62aaa6367fa9d3699a6',
|
||||
forwarder: '0x7afc2d5107af94c462a194d2c21b5bdd238709d6',
|
||||
orderValidator: '0x9463e518dea6810309563c81d5266c1b1d149138',
|
||||
},
|
||||
3: {
|
||||
erc20Proxy: '0xb1408f4c245a23c31b98d2c626777d4c0d766caa',
|
||||
erc721Proxy: '0xe654aac058bfbf9f83fcaee7793311dd82f6ddb4',
|
||||
zrxToken: '0xff67881f8d12f372d91baae9752eb3631ff0ed00',
|
||||
etherToken: '0xc778417e063141139fce010982780140aa0cd5ab',
|
||||
exchange: '0x4530c0483a1633c7a1c97d2c53721caff2caaaaf',
|
||||
assetProxyOwner: '0xf5fa5b5fed2727a0e44ac67f6772e97977aa358b',
|
||||
forwarder: '0x3983e204b12b3c02fb0638caf2cd406a62e0ead3',
|
||||
orderValidator: '0x90431a90516ab49af23a0530e04e8c7836e7122f',
|
||||
},
|
||||
42: {
|
||||
erc20Proxy: '0xf1ec01d6236d3cd881a0bf0130ea25fe4234003e',
|
||||
erc721Proxy: '0x2a9127c745688a165106c11cd4d647d2220af821',
|
||||
zrxToken: '0x2002d3812f58e35f0ea1ffbf80a75a38c32175fa',
|
||||
etherToken: '0xd0a1e359811322d97991e03f863a0c30c2cf029c',
|
||||
exchange: '0x35dd2932454449b14cee11a94d3674a936d5d7b2',
|
||||
assetProxyOwner: '0x2c824d2882baa668e0d5202b1e7f2922278703f8',
|
||||
forwarder: '0xd85e2fa7e7e252b27b01bf0d65c946959d2f45b8',
|
||||
orderValidator: '0xb389da3d204b412df2f75c6afb3d0a7ce0bc283d',
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Used to get addresses of contracts that have been deployed to either the
|
||||
* Ethereum mainnet or a supported testnet.
|
||||
* @returns The set of addresses for contracts which have been deployed on the
|
||||
* given networkId.
|
||||
*/
|
||||
export function getContractAddressesForNetwork(networkId: NetworkId): ContractAddresses {
|
||||
if (_.isUndefined(networkToAddresses[networkId])) {
|
||||
throw new Error(`Unknown network id (${networkId}). No known 0x contracts have been deployed on this network.`);
|
||||
}
|
||||
return networkToAddresses[networkId];
|
||||
}
|
8
packages/contract-addresses/tsconfig.json
Normal file
8
packages/contract-addresses/tsconfig.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "lib",
|
||||
"rootDir": "."
|
||||
},
|
||||
"include": ["./src/**/*"]
|
||||
}
|
3
packages/contract-addresses/tslint.json
Normal file
3
packages/contract-addresses/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": ["@0xproject/tslint-config"]
|
||||
}
|
@ -68,6 +68,7 @@
|
||||
"@0xproject/abi-gen-wrappers": "^1.0.0",
|
||||
"@0xproject/assert": "^1.0.13",
|
||||
"@0xproject/base-contract": "^3.0.1",
|
||||
"@0xproject/contract-addresses": "^1.0.0",
|
||||
"@0xproject/contract-artifacts": "^1.0.0",
|
||||
"@0xproject/fill-scenarios": "^1.0.7",
|
||||
"@0xproject/json-schemas": "^1.0.7",
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { getContractAddressesForNetwork } from '@0xproject/contract-addresses';
|
||||
import {
|
||||
ERC20Proxy,
|
||||
ERC20Token,
|
||||
@ -100,29 +101,50 @@ export class ContractWrappers {
|
||||
const blockPollingIntervalMs = _.isUndefined(config.blockPollingIntervalMs)
|
||||
? constants.DEFAULT_BLOCK_POLLING_INTERVAL
|
||||
: config.blockPollingIntervalMs;
|
||||
if (_.isUndefined(config.contractAddresses.erc20Proxy)) {
|
||||
throw new Error('config.contractAddresses.erc20Proxy is required for testing');
|
||||
}
|
||||
this.erc20Proxy = new ERC20ProxyWrapper(this._web3Wrapper, config.contractAddresses.erc20Proxy);
|
||||
this.erc721Proxy = new ERC721ProxyWrapper(this._web3Wrapper, config.contractAddresses.erc721Proxy);
|
||||
this.erc20Token = new ERC20TokenWrapper(this._web3Wrapper, this.erc20Proxy, blockPollingIntervalMs);
|
||||
this.erc721Token = new ERC721TokenWrapper(this._web3Wrapper, this.erc721Proxy, blockPollingIntervalMs);
|
||||
this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.erc20Token, blockPollingIntervalMs);
|
||||
const contractAddresses = _.isUndefined(config.contractAddresses)
|
||||
? getContractAddressesForNetwork(config.networkId)
|
||||
: config.contractAddresses;
|
||||
this.erc20Proxy = new ERC20ProxyWrapper(this._web3Wrapper, config.networkId, contractAddresses.erc20Proxy);
|
||||
this.erc721Proxy = new ERC721ProxyWrapper(this._web3Wrapper, config.networkId, contractAddresses.erc721Proxy);
|
||||
this.erc20Token = new ERC20TokenWrapper(
|
||||
this._web3Wrapper,
|
||||
config.networkId,
|
||||
this.erc20Proxy,
|
||||
blockPollingIntervalMs,
|
||||
);
|
||||
this.erc721Token = new ERC721TokenWrapper(
|
||||
this._web3Wrapper,
|
||||
config.networkId,
|
||||
this.erc721Proxy,
|
||||
blockPollingIntervalMs,
|
||||
);
|
||||
this.etherToken = new EtherTokenWrapper(
|
||||
this._web3Wrapper,
|
||||
config.networkId,
|
||||
this.erc20Token,
|
||||
blockPollingIntervalMs,
|
||||
);
|
||||
this.exchange = new ExchangeWrapper(
|
||||
this._web3Wrapper,
|
||||
config.networkId,
|
||||
this.erc20Token,
|
||||
this.erc721Token,
|
||||
config.contractAddresses.exchange,
|
||||
config.contractAddresses.zrxToken,
|
||||
contractAddresses.exchange,
|
||||
contractAddresses.zrxToken,
|
||||
blockPollingIntervalMs,
|
||||
);
|
||||
this.forwarder = new ForwarderWrapper(
|
||||
this._web3Wrapper,
|
||||
config.contractAddresses.forwarder,
|
||||
config.contractAddresses.zrxToken,
|
||||
config.contractAddresses.etherToken,
|
||||
config.networkId,
|
||||
contractAddresses.forwarder,
|
||||
contractAddresses.zrxToken,
|
||||
contractAddresses.etherToken,
|
||||
);
|
||||
this.orderValidator = new OrderValidatorWrapper(
|
||||
this._web3Wrapper,
|
||||
config.networkId,
|
||||
contractAddresses.orderValidator,
|
||||
);
|
||||
this.orderValidator = new OrderValidatorWrapper(this._web3Wrapper, config.contractAddresses.orderValidator);
|
||||
}
|
||||
/**
|
||||
* Sets a new web3 provider for 0x.js. Updating the provider will stop all
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { ContractAddresses, getContractAddressesForNetwork } from '@0xproject/contract-addresses';
|
||||
import { AbiDecoder, intervalUtils, logUtils } from '@0xproject/utils';
|
||||
import { marshaller, Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import {
|
||||
@ -25,6 +26,7 @@ import { filterUtils } from '../utils/filter_utils';
|
||||
|
||||
export abstract class ContractWrapper {
|
||||
public abstract abi: ContractAbi;
|
||||
protected _networkId: number;
|
||||
protected _web3Wrapper: Web3Wrapper;
|
||||
private _blockAndLogStreamerIfExists: BlockAndLogStreamer<Block, Log> | undefined;
|
||||
private _blockPollingIntervalMs: number;
|
||||
@ -42,8 +44,9 @@ export abstract class ContractWrapper {
|
||||
logUtils.warn(err);
|
||||
}
|
||||
}
|
||||
constructor(web3Wrapper: Web3Wrapper, blockPollingIntervalMs?: number) {
|
||||
constructor(web3Wrapper: Web3Wrapper, networkId: number, blockPollingIntervalMs?: number) {
|
||||
this._web3Wrapper = web3Wrapper;
|
||||
this._networkId = networkId;
|
||||
this._blockPollingIntervalMs = _.isUndefined(blockPollingIntervalMs)
|
||||
? constants.DEFAULT_BLOCK_POLLING_INTERVAL
|
||||
: blockPollingIntervalMs;
|
||||
@ -109,6 +112,9 @@ export abstract class ContractWrapper {
|
||||
const logWithDecodedArgs = abiDecoder.tryToDecodeLogOrNoop(log);
|
||||
return logWithDecodedArgs;
|
||||
}
|
||||
protected _getDefaultContractAddresses(): ContractAddresses {
|
||||
return getContractAddressesForNetwork(this._networkId);
|
||||
}
|
||||
private _onLogStateChanged<ArgsType extends ContractEventArgs>(isRemoved: boolean, rawLog: RawLogEntry): void {
|
||||
const log: LogEntry = marshaller.unmarshalLog(rawLog);
|
||||
_.forEach(this._filters, (filter: FilterObject, filterToken: string) => {
|
||||
|
@ -19,13 +19,14 @@ export class ERC20ProxyWrapper extends ContractWrapper {
|
||||
/**
|
||||
* Instantiate ERC20ProxyWrapper
|
||||
* @param web3Wrapper Web3Wrapper instance to use
|
||||
* @param address The address of the ERC20Proxy contract
|
||||
* @param networkId Desired networkId
|
||||
* @param address (Optional) The address of the ERC20Proxy contract. If
|
||||
* undefined, will default to the known address corresponding to the
|
||||
* networkId.
|
||||
*/
|
||||
// TODO(albrow): Make address optional and default to looking up the address
|
||||
// based in a hard-coded mapping based on web3Wrapper network id.
|
||||
constructor(web3Wrapper: Web3Wrapper, address: string) {
|
||||
super(web3Wrapper);
|
||||
this.address = address;
|
||||
constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string) {
|
||||
super(web3Wrapper, networkId);
|
||||
this.address = _.isUndefined(address) ? this._getDefaultContractAddresses().erc20Proxy : address;
|
||||
}
|
||||
/**
|
||||
* Get the 4 bytes ID of this asset proxy
|
||||
|
@ -37,11 +37,17 @@ export class ERC20TokenWrapper extends ContractWrapper {
|
||||
/**
|
||||
* Instantiate ERC20TokenWrapper
|
||||
* @param web3Wrapper Web3Wrapper instance to use
|
||||
* @param networkId Desired networkId
|
||||
* @param erc20ProxyWrapper The ERC20ProxyWrapper instance to use
|
||||
* @param blockPollingIntervalMs The block polling interval to use for active subscriptions
|
||||
*/
|
||||
constructor(web3Wrapper: Web3Wrapper, erc20ProxyWrapper: ERC20ProxyWrapper, blockPollingIntervalMs?: number) {
|
||||
super(web3Wrapper, blockPollingIntervalMs);
|
||||
constructor(
|
||||
web3Wrapper: Web3Wrapper,
|
||||
networkId: number,
|
||||
erc20ProxyWrapper: ERC20ProxyWrapper,
|
||||
blockPollingIntervalMs?: number,
|
||||
) {
|
||||
super(web3Wrapper, networkId, blockPollingIntervalMs);
|
||||
this._tokenContractsByAddress = {};
|
||||
this._erc20ProxyWrapper = erc20ProxyWrapper;
|
||||
}
|
||||
|
@ -19,13 +19,14 @@ export class ERC721ProxyWrapper extends ContractWrapper {
|
||||
/**
|
||||
* Instantiate ERC721ProxyWrapper
|
||||
* @param web3Wrapper Web3Wrapper instance to use
|
||||
* @param address The address of the ERC721Proxy contract
|
||||
* @param networkId Desired networkId
|
||||
* @param address (Optional) The address of the ERC721Proxy contract. If
|
||||
* undefined, will default to the known address corresponding to the
|
||||
* networkId.
|
||||
*/
|
||||
// TODO(albrow): Make address optional and default to looking up the address
|
||||
// based in a hard-coded mapping based on web3Wrapper network id.
|
||||
constructor(web3Wrapper: Web3Wrapper, address: string) {
|
||||
super(web3Wrapper);
|
||||
this.address = address;
|
||||
constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string) {
|
||||
super(web3Wrapper, networkId);
|
||||
this.address = _.isUndefined(address) ? this._getDefaultContractAddresses().erc721Proxy : address;
|
||||
}
|
||||
/**
|
||||
* Get the 4 bytes ID of this asset proxy
|
||||
|
@ -36,11 +36,17 @@ export class ERC721TokenWrapper extends ContractWrapper {
|
||||
/**
|
||||
* Instantiate ERC721TokenWrapper
|
||||
* @param web3Wrapper Web3Wrapper instance to use
|
||||
* @param networkId Desired networkId
|
||||
* @param erc721ProxyWrapper The ERC721ProxyWrapper instance to use
|
||||
* @param blockPollingIntervalMs The block polling interval to use for active subscriptions
|
||||
*/
|
||||
constructor(web3Wrapper: Web3Wrapper, erc721ProxyWrapper: ERC721ProxyWrapper, blockPollingIntervalMs?: number) {
|
||||
super(web3Wrapper, blockPollingIntervalMs);
|
||||
constructor(
|
||||
web3Wrapper: Web3Wrapper,
|
||||
networkId: number,
|
||||
erc721ProxyWrapper: ERC721ProxyWrapper,
|
||||
blockPollingIntervalMs?: number,
|
||||
) {
|
||||
super(web3Wrapper, networkId, blockPollingIntervalMs);
|
||||
this._tokenContractsByAddress = {};
|
||||
this._erc721ProxyWrapper = erc721ProxyWrapper;
|
||||
}
|
||||
|
@ -31,8 +31,13 @@ export class EtherTokenWrapper extends ContractWrapper {
|
||||
* @param erc20TokenWrapper The ERC20TokenWrapper instance to use
|
||||
* @param blockPollingIntervalMs The block polling interval to use for active subscriptions
|
||||
*/
|
||||
constructor(web3Wrapper: Web3Wrapper, erc20TokenWrapper: ERC20TokenWrapper, blockPollingIntervalMs?: number) {
|
||||
super(web3Wrapper, blockPollingIntervalMs);
|
||||
constructor(
|
||||
web3Wrapper: Web3Wrapper,
|
||||
networkId: number,
|
||||
erc20TokenWrapper: ERC20TokenWrapper,
|
||||
blockPollingIntervalMs?: number,
|
||||
) {
|
||||
super(web3Wrapper, networkId, blockPollingIntervalMs);
|
||||
this._erc20TokenWrapper = erc20TokenWrapper;
|
||||
}
|
||||
/**
|
||||
|
@ -50,26 +50,33 @@ export class ExchangeWrapper extends ContractWrapper {
|
||||
/**
|
||||
* Instantiate ExchangeWrapper
|
||||
* @param web3Wrapper Web3Wrapper instance to use.
|
||||
* @param networkId Desired networkId.
|
||||
* @param erc20TokenWrapper ERC20TokenWrapper instance to use.
|
||||
* @param erc721TokenWrapper ERC721TokenWrapper instance to use.
|
||||
* @param address The address of the Exchange contract.
|
||||
* @param zrxTokenAddress The address of the ZRX Token contract.
|
||||
* @param address (Optional) The address of the Exchange contract. If
|
||||
* undefined, will default to the known address corresponding to the
|
||||
* networkId.
|
||||
* @param zrxTokenAddress (Optional) The address of the ZRXToken contract.
|
||||
* If undefined, will default to the known address corresponding to the
|
||||
* networkId.
|
||||
* @param blockPollingIntervalMs The block polling interval to use for active subscriptions.
|
||||
*/
|
||||
constructor(
|
||||
web3Wrapper: Web3Wrapper,
|
||||
networkId: number,
|
||||
erc20TokenWrapper: ERC20TokenWrapper,
|
||||
erc721TokenWrapper: ERC721TokenWrapper,
|
||||
// TODO(albrow): Make address optional?
|
||||
address: string,
|
||||
zrxTokenAddress: string,
|
||||
address?: string,
|
||||
zrxTokenAddress?: string,
|
||||
blockPollingIntervalMs?: number,
|
||||
) {
|
||||
super(web3Wrapper, blockPollingIntervalMs);
|
||||
super(web3Wrapper, networkId, blockPollingIntervalMs);
|
||||
this._erc20TokenWrapper = erc20TokenWrapper;
|
||||
this._erc721TokenWrapper = erc721TokenWrapper;
|
||||
this.address = address;
|
||||
this.zrxTokenAddress = zrxTokenAddress;
|
||||
this.address = _.isUndefined(address) ? this._getDefaultContractAddresses().exchange : address;
|
||||
this.zrxTokenAddress = _.isUndefined(zrxTokenAddress)
|
||||
? this._getDefaultContractAddresses().zrxToken
|
||||
: zrxTokenAddress;
|
||||
}
|
||||
/**
|
||||
* Retrieve the address of an asset proxy by signature.
|
||||
|
@ -27,12 +27,36 @@ export class ForwarderWrapper extends ContractWrapper {
|
||||
public zrxTokenAddress: string;
|
||||
public etherTokenAddress: string;
|
||||
private _forwarderContractIfExists?: ForwarderContract;
|
||||
// TODO(albrow): Make addresses optional?
|
||||
constructor(web3Wrapper: Web3Wrapper, address: string, zrxTokenAddress: string, etherTokenAddress: string) {
|
||||
super(web3Wrapper);
|
||||
this.address = address;
|
||||
this.zrxTokenAddress = zrxTokenAddress;
|
||||
this.etherTokenAddress = etherTokenAddress;
|
||||
|
||||
/**
|
||||
* Instantiate ForwarderWrapper
|
||||
* @param web3Wrapper Web3Wrapper instance to use.
|
||||
* @param networkId Desired networkId.
|
||||
* @param address (Optional) The address of the Exchange contract. If
|
||||
* undefined, will default to the known address corresponding to the
|
||||
* networkId.
|
||||
* @param zrxTokenAddress (Optional) The address of the ZRXToken contract.
|
||||
* If undefined, will default to the known address corresponding to the
|
||||
* networkId.
|
||||
* @param etherTokenAddress (Optional) The address of a WETH (Ether token)
|
||||
* contract. If undefined, will default to the known address corresponding
|
||||
* to the networkId.
|
||||
*/
|
||||
constructor(
|
||||
web3Wrapper: Web3Wrapper,
|
||||
networkId: number,
|
||||
address?: string,
|
||||
zrxTokenAddress?: string,
|
||||
etherTokenAddress?: string,
|
||||
) {
|
||||
super(web3Wrapper, networkId);
|
||||
this.address = _.isUndefined(address) ? this._getDefaultContractAddresses().exchange : address;
|
||||
this.zrxTokenAddress = _.isUndefined(zrxTokenAddress)
|
||||
? this._getDefaultContractAddresses().zrxToken
|
||||
: zrxTokenAddress;
|
||||
this.etherTokenAddress = _.isUndefined(etherTokenAddress)
|
||||
? this._getDefaultContractAddresses().etherToken
|
||||
: etherTokenAddress;
|
||||
}
|
||||
/**
|
||||
* Purchases as much of orders' makerAssets as possible by selling up to 95% of transaction's ETH value.
|
||||
|
@ -22,12 +22,14 @@ export class OrderValidatorWrapper extends ContractWrapper {
|
||||
/**
|
||||
* Instantiate OrderValidatorWrapper
|
||||
* @param web3Wrapper Web3Wrapper instance to use.
|
||||
* @param address The address of the OrderValidator contract.
|
||||
* @param networkId Desired networkId.
|
||||
* @param address (Optional) The address of the OrderValidator contract. If
|
||||
* undefined, will default to the known address corresponding to the
|
||||
* networkId.
|
||||
*/
|
||||
// TODO(albrow): Make address optional?
|
||||
constructor(web3Wrapper: Web3Wrapper, address: string) {
|
||||
super(web3Wrapper);
|
||||
this.address = address;
|
||||
constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string) {
|
||||
super(web3Wrapper, networkId);
|
||||
this.address = _.isUndefined(address) ? this._getDefaultContractAddresses().exchange : address;
|
||||
}
|
||||
/**
|
||||
* Get an object conforming to OrderAndTraderInfo containing on-chain information of the provided order and address
|
||||
|
@ -8,7 +8,8 @@ import {
|
||||
WETH9EventArgs,
|
||||
WETH9Events,
|
||||
} from '@0xproject/abi-gen-wrappers';
|
||||
import { ContractAddresses, OrderState, SignedOrder } from '@0xproject/types';
|
||||
import { ContractAddresses } from '@0xproject/contract-addresses';
|
||||
import { OrderState, SignedOrder } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
|
||||
import { BlockParam, ContractEventArg, DecodedLogArgs, LogEntryEvent, LogWithDecodedArgs } from 'ethereum-types';
|
||||
@ -110,18 +111,13 @@ export type SyncMethod = (...args: any[]) => any;
|
||||
/**
|
||||
* 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
|
||||
* erc20ProxyContractAddress: The address of the erc20 token transfer proxy contract to use
|
||||
* erc721ProxyContractAddress: The address of the erc721 token transfer proxy contract to use
|
||||
* forwarderContractAddress: The address of the forwarder contract to use
|
||||
* orderWatcherConfig: All the configs related to the orderWatcher
|
||||
* contractAddresses: The address of all contracts to use. Defaults to the known addresses based on networkId.
|
||||
* blockPollingIntervalMs: The interval to use for block polling in event watching methods (defaults to 1000)
|
||||
*/
|
||||
export interface ContractWrappersConfig {
|
||||
networkId: number;
|
||||
gasPrice?: BigNumber;
|
||||
contractAddresses: ContractAddresses;
|
||||
contractAddresses?: ContractAddresses;
|
||||
blockPollingIntervalMs?: number;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { ContractAddresses } from '@0xproject/contract-addresses';
|
||||
import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
|
||||
import { EmptyWalletSubprovider, Web3ProviderEngine } from '@0xproject/subproviders';
|
||||
import { ContractAddresses, DoneCallback } from '@0xproject/types';
|
||||
import { DoneCallback } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as chai from 'chai';
|
||||
import { Provider } from 'ethereum-types';
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { ContractAddresses } from '@0xproject/contract-addresses';
|
||||
import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils';
|
||||
import { ContractAddresses, DoneCallback } from '@0xproject/types';
|
||||
import { DoneCallback } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import * as chai from 'chai';
|
||||
@ -16,7 +17,6 @@ import {
|
||||
WETH9TransferEventArgs,
|
||||
WETH9WithdrawalEventArgs,
|
||||
} from '../src';
|
||||
|
||||
import { DecodedLogEvent } from '../src/types';
|
||||
|
||||
import { chaiSetup } from './utils/chai_setup';
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { ContractAddresses } from '@0xproject/contract-addresses';
|
||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||
import { FillScenarios } from '@0xproject/fill-scenarios';
|
||||
import { assetDataUtils } from '@0xproject/order-utils';
|
||||
import { ContractAddresses, SignedOrder } from '@0xproject/types';
|
||||
import { SignedOrder } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ContractAddresses } from '@0xproject/contract-addresses';
|
||||
import { devConstants } from '@0xproject/dev-utils';
|
||||
import { runMigrationsOnceAsync } from '@0xproject/migrations';
|
||||
import { ContractAddresses } from '@0xproject/types';
|
||||
|
||||
import { provider } from './web3_wrapper';
|
||||
|
||||
|
@ -37,7 +37,6 @@ import * as WETH9 from '../../generated-artifacts/WETH9.json';
|
||||
import * as Whitelist from '../../generated-artifacts/Whitelist.json';
|
||||
import * as ZRXToken from '../../generated-artifacts/ZRXToken.json';
|
||||
|
||||
// TODO(albrow): Do we need to export all of these?
|
||||
export const artifacts = {
|
||||
AssetProxyOwner: (AssetProxyOwner as any) as ContractArtifact,
|
||||
DummyERC20Token: (DummyERC20Token as any) as ContractArtifact,
|
||||
|
@ -1,4 +1,3 @@
|
||||
// TODO(albrow): Do we need to export all of these?
|
||||
export * from '../../generated-wrappers/asset_proxy_owner';
|
||||
export * from '../../generated-wrappers/dummy_erc20_token';
|
||||
export * from '../../generated-wrappers/dummy_erc721_receiver';
|
||||
|
@ -31,6 +31,7 @@
|
||||
"dependencies": {
|
||||
"@0xproject/abi-gen-wrappers": "^1.0.0",
|
||||
"@0xproject/base-contract": "^3.0.1",
|
||||
"@0xproject/contract-addresses": "^1.0.0",
|
||||
"@0xproject/contract-artifacts": "^1.0.0",
|
||||
"@0xproject/order-utils": "^1.0.7",
|
||||
"@0xproject/sol-compiler": "^1.1.7",
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as wrappers from '@0xproject/abi-gen-wrappers';
|
||||
import { ContractAddresses } from '@0xproject/contract-addresses';
|
||||
import * as artifacts from '@0xproject/contract-artifacts';
|
||||
import { assetDataUtils } from '@0xproject/order-utils';
|
||||
import { ContractAddresses } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import { Provider, TxData } from 'ethereum-types';
|
||||
|
@ -60,6 +60,7 @@
|
||||
"@0xproject/abi-gen-wrappers": "^1.0.0",
|
||||
"@0xproject/assert": "^1.0.13",
|
||||
"@0xproject/base-contract": "^3.0.1",
|
||||
"@0xproject/contract-addresses": "^1.0.0",
|
||||
"@0xproject/contract-artifacts": "^1.0.0",
|
||||
"@0xproject/contract-wrappers": "^2.0.2",
|
||||
"@0xproject/fill-scenarios": "^1.0.7",
|
||||
|
@ -1,4 +1,5 @@
|
||||
// tslint:disable:no-unnecessary-type-assertion
|
||||
import { ContractAddresses } from '@0xproject/contract-addresses';
|
||||
import * as artifacts from '@0xproject/contract-artifacts';
|
||||
import {
|
||||
AssetBalanceAndProxyAllowanceFetcher,
|
||||
@ -31,14 +32,7 @@ import {
|
||||
orderHashUtils,
|
||||
OrderStateUtils,
|
||||
} from '@0xproject/order-utils';
|
||||
import {
|
||||
AssetProxyId,
|
||||
ContractAddresses,
|
||||
ExchangeContractErrs,
|
||||
OrderState,
|
||||
SignedOrder,
|
||||
Stats,
|
||||
} from '@0xproject/types';
|
||||
import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder, Stats } from '@0xproject/types';
|
||||
import { errorUtils, intervalUtils } from '@0xproject/utils';
|
||||
import { BlockParamLiteral, LogEntryEvent, LogWithDecodedArgs, Provider } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
@ -98,12 +92,14 @@ export class OrderWatcher {
|
||||
* Instantiate a new OrderWatcher
|
||||
* @param provider Web3 provider to use for JSON RPC calls
|
||||
* @param networkId NetworkId to watch orders on
|
||||
* @param contractAddresses Optional contract addresses. Defaults to known
|
||||
* addresses based on networkId.
|
||||
* @param partialConfig Optional configurations
|
||||
*/
|
||||
constructor(
|
||||
provider: Provider,
|
||||
networkId: number,
|
||||
contractAddresses: ContractAddresses,
|
||||
contractAddresses?: ContractAddresses,
|
||||
partialConfig: Partial<OrderWatcherConfig> = DEFAULT_ORDER_WATCHER_CONFIG,
|
||||
) {
|
||||
assert.isWeb3Provider('provider', provider);
|
||||
@ -122,7 +118,8 @@ export class OrderWatcher {
|
||||
);
|
||||
const contractWrappers = new ContractWrappers(provider, {
|
||||
networkId,
|
||||
// TODO(albrow): Make contract addresses optional.
|
||||
// Note(albrow): We let the contract-wrappers package handle
|
||||
// default values for contractAddresses.
|
||||
contractAddresses,
|
||||
});
|
||||
this._eventWatcher = new EventWatcher(provider, config.eventPollingIntervalMs, STATE_LAYER, config.isVerbose);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ContractAddresses } from '@0xproject/contract-addresses';
|
||||
import { devConstants } from '@0xproject/dev-utils';
|
||||
import { runMigrationsOnceAsync } from '@0xproject/migrations';
|
||||
import { ContractAddresses } from '@0xproject/types';
|
||||
|
||||
import { provider } from './web3_wrapper';
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"0x.js": "^1.0.8",
|
||||
"@0xproject/contract-addresses": "^1.0.0",
|
||||
"@0xproject/subproviders": "^2.0.7",
|
||||
"@0xproject/typescript-typings": "^3.0.2",
|
||||
"@0xproject/utils": "^2.0.2",
|
||||
|
@ -11,6 +11,7 @@ import {
|
||||
SignedOrder,
|
||||
Web3ProviderEngine,
|
||||
} from '0x.js';
|
||||
import { getContractAddressesForNetwork } from '@0xproject/contract-addresses';
|
||||
import { NonceTrackerSubprovider, PrivateKeyWalletSubprovider } from '@0xproject/subproviders';
|
||||
import { logUtils } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
@ -67,17 +68,7 @@ export class Handler {
|
||||
const networkId = parseInt(networkIdString, 10);
|
||||
const contractWrappersConfig = {
|
||||
networkId,
|
||||
// TODO(albrow): Load in real contract addresses here.
|
||||
contractAddresses: {
|
||||
erc20Proxy: '',
|
||||
erc721Proxy: '',
|
||||
zrxToken: '',
|
||||
etherToken: '',
|
||||
exchange: '',
|
||||
assetProxyOwner: '',
|
||||
forwarder: '',
|
||||
orderValidator: '',
|
||||
},
|
||||
contractAddresses: getContractAddressesForNetwork(networkId),
|
||||
};
|
||||
const contractWrappers = new ContractWrappers(providerObj, contractWrappersConfig);
|
||||
const dispatchQueue = new DispatchQueue();
|
||||
|
@ -20,6 +20,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"0x.js": "^0.38.6",
|
||||
"@0xproject/contract-addresses": "^1.0.0",
|
||||
"@0xproject/contract-wrappers": "^2.0.2",
|
||||
"@0xproject/json-schemas": "^1.0.7",
|
||||
"@0xproject/order-utils": "^1.0.7",
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { ZeroEx } from '0x.js';
|
||||
import { getContractAddressesForNetwork } from '@0xproject/contract-addresses';
|
||||
import {
|
||||
BlockRange,
|
||||
ContractWrappers,
|
||||
@ -863,17 +864,7 @@ export class Blockchain {
|
||||
} else {
|
||||
const contractWrappersConfig = {
|
||||
networkId,
|
||||
// TODO(albrow): Load in real contract addresses here.
|
||||
contractAddresses: {
|
||||
erc20Proxy: '',
|
||||
erc721Proxy: '',
|
||||
zrxToken: '',
|
||||
etherToken: '',
|
||||
exchange: '',
|
||||
assetProxyOwner: '',
|
||||
forwarder: '',
|
||||
orderValidator: '',
|
||||
},
|
||||
contractAddresses: getContractAddressesForNetwork(networkId),
|
||||
};
|
||||
this._contractWrappers = new ContractWrappers(provider, contractWrappersConfig);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user