aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-04-05 20:06:58 +0800
committerFabio Berger <me@fabioberger.com>2018-04-05 20:06:58 +0800
commit89a72ebf0dbff606d511ae51bfee7ffc0a5df18f (patch)
tree65c935c4c372d2c497bec08164b314866050192b /packages/0x.js
parent20aaab0847d0ec8b2a44f392ddd467f0c475cfb5 (diff)
parent7f7ddee0f95f3ed3e903c230088dbee4648771bd (diff)
downloaddexon-sol-tools-89a72ebf0dbff606d511ae51bfee7ffc0a5df18f.tar
dexon-sol-tools-89a72ebf0dbff606d511ae51bfee7ffc0a5df18f.tar.gz
dexon-sol-tools-89a72ebf0dbff606d511ae51bfee7ffc0a5df18f.tar.bz2
dexon-sol-tools-89a72ebf0dbff606d511ae51bfee7ffc0a5df18f.tar.lz
dexon-sol-tools-89a72ebf0dbff606d511ae51bfee7ffc0a5df18f.tar.xz
dexon-sol-tools-89a72ebf0dbff606d511ae51bfee7ffc0a5df18f.tar.zst
dexon-sol-tools-89a72ebf0dbff606d511ae51bfee7ffc0a5df18f.zip
Merge branch 'development' into removeMigrateStep
* development: Fix tests Call static functions as static Address feedback Move our contract templates to accept Provider instead of Web3Wrapper
Diffstat (limited to 'packages/0x.js')
-rw-r--r--packages/0x.js/CHANGELOG.json9
-rw-r--r--packages/0x.js/src/0x.ts26
-rw-r--r--packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts7
-rw-r--r--packages/0x.js/src/contract_wrappers/exchange_wrapper.ts21
-rw-r--r--packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts7
-rw-r--r--packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts7
-rw-r--r--packages/0x.js/src/contract_wrappers/token_wrapper.ts7
-rw-r--r--packages/0x.js/src/globals.d.ts7
-rw-r--r--packages/0x.js/src/index.ts2
-rw-r--r--packages/0x.js/src/types.ts8
-rw-r--r--packages/0x.js/test/ether_token_wrapper_test.ts5
-rw-r--r--packages/0x.js/test/utils/fill_scenarios.ts7
12 files changed, 65 insertions, 48 deletions
diff --git a/packages/0x.js/CHANGELOG.json b/packages/0x.js/CHANGELOG.json
index fd248ff44..6d5dc0dd2 100644
--- a/packages/0x.js/CHANGELOG.json
+++ b/packages/0x.js/CHANGELOG.json
@@ -1,5 +1,14 @@
[
{
+ "version": "0.36.0",
+ "changes": [
+ {
+ "note": "Moved Web3.Provider to `@0xproject/types:Provider`",
+ "pr": 501
+ }
+ ]
+ },
+ {
"version": "0.35.0",
"changes": [
{
diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts
index 774b9ac12..94d97c23e 100644
--- a/packages/0x.js/src/0x.ts
+++ b/packages/0x.js/src/0x.ts
@@ -1,5 +1,5 @@
import { schemas, SchemaValidator } from '@0xproject/json-schemas';
-import { ECSignature, Order, SignedOrder, TransactionReceiptWithDecodedLogs } from '@0xproject/types';
+import { ECSignature, Order, Provider, SignedOrder, TransactionReceiptWithDecodedLogs } from '@0xproject/types';
import { AbiDecoder, BigNumber, intervalUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as ethUtil from 'ethereumjs-util';
@@ -15,7 +15,7 @@ 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 { OrderStateWatcherConfig, Web3Provider, ZeroExConfig, ZeroExError } from './types';
+import { OrderStateWatcherConfig, ZeroExConfig, ZeroExError } from './types';
import { assert } from './utils/assert';
import { constants } from './utils/constants';
import { decorators } from './utils/decorators';
@@ -115,10 +115,8 @@ export class ZeroEx {
public static toUnitAmount(amount: BigNumber, decimals: number): BigNumber {
assert.isValidBaseUnitAmount('amount', amount);
assert.isNumber('decimals', decimals);
-
- const aUnit = new BigNumber(10).pow(decimals);
- const unit = amount.div(aUnit);
- return unit;
+ const unitAmount = Web3Wrapper.toUnitAmount(amount, decimals);
+ return unitAmount;
}
/**
* A baseUnit is defined as the smallest denomination of a token. An amount expressed in baseUnits
@@ -131,13 +129,7 @@ export class ZeroEx {
public static toBaseUnitAmount(amount: BigNumber, decimals: number): BigNumber {
assert.isBigNumber('amount', amount);
assert.isNumber('decimals', decimals);
-
- const unit = new BigNumber(10).pow(decimals);
- const baseUnitAmount = amount.times(unit);
- const hasDecimals = baseUnitAmount.decimalPlaces() !== 0;
- if (hasDecimals) {
- throw new Error(`Invalid unit amount: ${amount.toString()} - Too many decimal places`);
- }
+ const baseUnitAmount = Web3Wrapper.toBaseUnitAmount(amount, decimals);
return baseUnitAmount;
}
/**
@@ -153,12 +145,12 @@ export class ZeroEx {
}
/**
* Instantiates a new ZeroEx instance that provides the public interface to the 0x.js library.
- * @param provider The Web3.js Provider instance you would like the 0x.js library to use for interacting with
+ * @param provider The Provider instance you would like the 0x.js library to use for interacting with
* the Ethereum network.
* @param config The configuration object. Look up the type for the description.
* @return An instance of the 0x.js ZeroEx class.
*/
- constructor(provider: Web3Provider, config: ZeroExConfig) {
+ constructor(provider: Provider, config: ZeroExConfig) {
assert.isWeb3Provider('provider', provider);
assert.doesConformToSchema('config', config, zeroExConfigSchema, [
zeroExPrivateNetworkConfigSchema,
@@ -199,7 +191,7 @@ export class ZeroEx {
* @param provider The Web3Provider you would like the 0x.js library to use from now on.
* @param networkId The id of the network your provider is connected to
*/
- public setProvider(provider: Web3Provider, networkId: number): void {
+ public setProvider(provider: Provider, networkId: number): void {
this._web3Wrapper.setProvider(provider);
(this.exchange as any)._invalidateContractInstances();
(this.exchange as any)._setNetworkId(networkId);
@@ -225,7 +217,7 @@ export class ZeroEx {
* This method currently supports TestRPC, Geth and Parity above and below V1.6.6
* @param orderHash Hex encoded orderHash to sign.
* @param signerAddress The hex encoded Ethereum address you wish to sign it with. This address
- * must be available via the Web3.Provider supplied to 0x.js.
+ * must be available via the Provider supplied to 0x.js.
* @param shouldAddPersonalMessagePrefix Some signers add the personal message prefix `\x19Ethereum Signed Message`
* themselves (e.g Parity Signer, Ledger, TestRPC) and others expect it to already be done by the client
* (e.g Metamask). Depending on which signer this request is going to, decide on whether to add the prefix
diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
index f52dba2f1..fd39de34b 100644
--- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
@@ -191,7 +191,12 @@ export class EtherTokenWrapper extends ContractWrapper {
artifacts.EtherTokenArtifact,
etherTokenAddress,
);
- const contractInstance = new EtherTokenContract(this._web3Wrapper, abi, address);
+ const contractInstance = new EtherTokenContract(
+ abi,
+ address,
+ this._web3Wrapper.getProvider(),
+ this._web3Wrapper.getContractDefaults(),
+ );
etherTokenContract = contractInstance;
this._etherTokenContractsByAddress[etherTokenAddress] = etherTokenContract;
return etherTokenContract;
diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
index 53f32f111..378ae8111 100644
--- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
@@ -170,7 +170,7 @@ export class ExchangeWrapper extends ContractWrapper {
* @param shouldThrowOnInsufficientBalanceOrAllowance Whether or not you wish for the contract call to throw
* if upon execution the tokens cannot be transferred.
* @param takerAddress The user Ethereum address who would like to fill this order.
- * Must be available via the supplied Web3.Provider
+ * Must be available via the supplied Provider
* passed to 0x.js.
* @param orderTransactionOpts Optional arguments this method accepts.
* @return Transaction hash.
@@ -235,7 +235,7 @@ export class ExchangeWrapper extends ContractWrapper {
* If set to false, the call will continue to fill subsequent
* signedOrders even when some cannot be filled.
* @param takerAddress The user Ethereum address who would like to fill these
- * orders. Must be available via the supplied Web3.Provider
+ * orders. Must be available via the supplied Provider
* passed to 0x.js.
* @param orderTransactionOpts Optional arguments this method accepts.
* @return Transaction hash.
@@ -335,7 +335,7 @@ export class ExchangeWrapper extends ContractWrapper {
* cannot be filled.
* @param takerAddress The user Ethereum address who would like to fill
* these orders. Must be available via the supplied
- * Web3.Provider passed to 0x.js.
+ * Provider passed to 0x.js.
* @param orderTransactionOpts Optional arguments this method accepts.
* @return Transaction hash.
*/
@@ -416,7 +416,7 @@ export class ExchangeWrapper extends ContractWrapper {
* signedOrder you wish to fill.
* @param fillTakerTokenAmount The total amount of the takerTokens you would like to fill.
* @param takerAddress The user Ethereum address who would like to fill this order.
- * Must be available via the supplied Web3.Provider passed to 0x.js.
+ * Must be available via the supplied Provider passed to 0x.js.
* @param orderTransactionOpts Optional arguments this method accepts.
* @return Transaction hash.
*/
@@ -470,7 +470,7 @@ export class ExchangeWrapper extends ContractWrapper {
* filled (each to the specified fillAmount) or aborted.
* @param orderFillRequests An array of objects that conform to the OrderFillRequest interface.
* @param takerAddress The user Ethereum address who would like to fill there orders.
- * Must be available via the supplied Web3.Provider passed to 0x.js.
+ * Must be available via the supplied Provider passed to 0x.js.
* @param orderTransactionOpts Optional arguments this method accepts.
* @return Transaction hash.
*/
@@ -765,7 +765,7 @@ export class ExchangeWrapper extends ContractWrapper {
* signedOrder you wish to fill.
* @param fillTakerTokenAmount The total amount of the takerTokens you would like to fill.
* @param takerAddress The user Ethereum address who would like to fill this order.
- * Must be available via the supplied Web3.Provider passed to 0x.js.
+ * Must be available via the supplied Provider passed to 0x.js.
*/
public async validateFillOrderThrowIfInvalidAsync(
signedOrder: SignedOrder,
@@ -812,7 +812,7 @@ export class ExchangeWrapper extends ContractWrapper {
* signedOrder you wish to fill.
* @param fillTakerTokenAmount The total amount of the takerTokens you would like to fill.
* @param takerAddress The user Ethereum address who would like to fill this order.
- * Must be available via the supplied Web3.Provider passed to 0x.js.
+ * Must be available via the supplied Provider passed to 0x.js.
*/
public async validateFillOrKillOrderThrowIfInvalidAsync(
signedOrder: SignedOrder,
@@ -920,7 +920,12 @@ export class ExchangeWrapper extends ContractWrapper {
artifacts.ExchangeArtifact,
this._contractAddressIfExists,
);
- const contractInstance = new ExchangeContract(this._web3Wrapper, abi, address);
+ const contractInstance = new ExchangeContract(
+ abi,
+ address,
+ this._web3Wrapper.getProvider(),
+ this._web3Wrapper.getContractDefaults(),
+ );
this._exchangeContractIfExists = contractInstance;
return this._exchangeContractIfExists;
}
diff --git a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts
index e1806c6f2..c4a193264 100644
--- a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts
@@ -121,7 +121,12 @@ export class TokenRegistryWrapper extends ContractWrapper {
artifacts.TokenRegistryArtifact,
this._contractAddressIfExists,
);
- const contractInstance = new TokenRegistryContract(this._web3Wrapper, abi, address);
+ const contractInstance = new TokenRegistryContract(
+ abi,
+ address,
+ this._web3Wrapper.getProvider(),
+ this._web3Wrapper.getContractDefaults(),
+ );
this._tokenRegistryContractIfExists = contractInstance;
return this._tokenRegistryContractIfExists;
}
diff --git a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts
index 211c7dfb4..be558b5be 100644
--- a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts
@@ -63,7 +63,12 @@ export class TokenTransferProxyWrapper extends ContractWrapper {
artifacts.TokenTransferProxyArtifact,
this._contractAddressIfExists,
);
- const contractInstance = new TokenTransferProxyContract(this._web3Wrapper, abi, address);
+ const contractInstance = new TokenTransferProxyContract(
+ abi,
+ address,
+ this._web3Wrapper.getProvider(),
+ this._web3Wrapper.getContractDefaults(),
+ );
this._tokenTransferProxyContractIfExists = contractInstance;
return this._tokenTransferProxyContractIfExists;
}
diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
index 5224d451c..194cfb5aa 100644
--- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
@@ -421,7 +421,12 @@ export class TokenWrapper extends ContractWrapper {
artifacts.TokenArtifact,
normalizedTokenAddress,
);
- const contractInstance = new TokenContract(this._web3Wrapper, abi, address);
+ const contractInstance = new TokenContract(
+ abi,
+ address,
+ this._web3Wrapper.getProvider(),
+ this._web3Wrapper.getContractDefaults(),
+ );
tokenContract = contractInstance;
this._tokenContractsByAddress[normalizedTokenAddress] = tokenContract;
return tokenContract;
diff --git a/packages/0x.js/src/globals.d.ts b/packages/0x.js/src/globals.d.ts
index b9b691ba1..94e63a32d 100644
--- a/packages/0x.js/src/globals.d.ts
+++ b/packages/0x.js/src/globals.d.ts
@@ -1,10 +1,3 @@
-declare module 'web3_beta';
-
-// semver-sort declarations
-declare module 'semver-sort' {
- const desc: (versions: string[]) => string[];
-}
-
declare module '*.json' {
const json: any;
/* tslint:disable */
diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts
index e353a1d3d..3b973bd54 100644
--- a/packages/0x.js/src/index.ts
+++ b/packages/0x.js/src/index.ts
@@ -11,7 +11,6 @@ export {
OrderCancellationRequest,
OrderFillRequest,
ContractEventArgs,
- Web3Provider,
ZeroExConfig,
MethodOpts,
OrderTransactionOpts,
@@ -32,6 +31,7 @@ export {
ContractEventArg,
LogWithDecodedArgs,
Order,
+ Provider,
SignedOrder,
ECSignature,
TransactionReceipt,
diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts
index 1f128d656..d1c643a57 100644
--- a/packages/0x.js/src/types.ts
+++ b/packages/0x.js/src/types.ts
@@ -154,14 +154,6 @@ export interface OrderFillRequest {
export type AsyncMethod = (...args: any[]) => Promise<any>;
export type SyncMethod = (...args: any[]) => any;
-/**
- * We re-export the `Web3.Provider` type specified in the Web3 Typescript typings
- * since it is the type of the `provider` argument to the `ZeroEx` constructor.
- * It is however a `Web3` library type, not a native `0x.js` type. To learn more
- * about providers, visit https://0xproject.com/wiki#Web3-Provider-Explained
- */
-export type Web3Provider = Web3.Provider;
-
/*
* orderExpirationCheckingIntervalMs: How often to check for expired orders. Default: 50
* eventPollingIntervalMs: How often to poll the Ethereum node for new events. Default: 200
diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts
index 6687c48e1..5be3eaff3 100644
--- a/packages/0x.js/test/ether_token_wrapper_test.ts
+++ b/packages/0x.js/test/ether_token_wrapper_test.ts
@@ -1,5 +1,6 @@
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import 'mocha';
import * as Web3 from 'web3';
@@ -59,7 +60,7 @@ describe('EtherTokenWrapper', () => {
userAddresses = await zeroEx.getAvailableAddressesAsync();
addressWithETH = userAddresses[0];
wethContractAddress = zeroEx.etherToken.getContractAddressIfExists() as string;
- depositWeiAmount = (zeroEx as any)._web3Wrapper.toWei(new BigNumber(5));
+ depositWeiAmount = Web3Wrapper.toWei(new BigNumber(5));
decimalPlaces = 7;
addressWithoutFunds = userAddresses[1];
});
@@ -105,7 +106,7 @@ describe('EtherTokenWrapper', () => {
it('should throw if user has insufficient ETH balance for deposit', async () => {
const preETHBalance = await (zeroEx as any)._web3Wrapper.getBalanceInWeiAsync(addressWithETH);
- const extraETHBalance = (zeroEx as any)._web3Wrapper.toWei(5, 'ether');
+ const extraETHBalance = Web3Wrapper.toWei(new BigNumber(5));
const overETHBalanceinWei = preETHBalance.add(extraETHBalance);
return expect(
diff --git a/packages/0x.js/test/utils/fill_scenarios.ts b/packages/0x.js/test/utils/fill_scenarios.ts
index 25e2aa36f..cd68b7dfa 100644
--- a/packages/0x.js/test/utils/fill_scenarios.ts
+++ b/packages/0x.js/test/utils/fill_scenarios.ts
@@ -37,7 +37,12 @@ export class FillScenarios {
for (const token of this._tokens) {
if (token.symbol !== 'ZRX' && token.symbol !== 'WETH') {
const defaults = {};
- const dummyToken = new DummyTokenContract(web3Wrapper, artifacts.DummyTokenArtifact.abi, token.address);
+ const dummyToken = new DummyTokenContract(
+ artifacts.DummyTokenArtifact.abi,
+ token.address,
+ web3Wrapper.getProvider(),
+ web3Wrapper.getContractDefaults(),
+ );
const tokenSupply = ZeroEx.toBaseUnitAmount(INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS, token.decimals);
const txHash = await dummyToken.setBalance.sendTransactionAsync(this._coinbase, tokenSupply, {
from: this._coinbase,