aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-08-29 16:03:00 +0800
committerGitHub <noreply@github.com>2017-08-29 16:03:00 +0800
commit07a872f80213a71d17d61a47e7faeee0e87d1822 (patch)
tree8d29f3f7c180400f48b2b0f150ed603729cc061f
parent05ce9733dadd1f83afa2d96ff55a23cd1477216d (diff)
parent9516a50f645587bcc79ec5e17b8a353221f1d7e2 (diff)
downloaddexon-sol-tools-07a872f80213a71d17d61a47e7faeee0e87d1822.tar
dexon-sol-tools-07a872f80213a71d17d61a47e7faeee0e87d1822.tar.gz
dexon-sol-tools-07a872f80213a71d17d61a47e7faeee0e87d1822.tar.bz2
dexon-sol-tools-07a872f80213a71d17d61a47e7faeee0e87d1822.tar.lz
dexon-sol-tools-07a872f80213a71d17d61a47e7faeee0e87d1822.tar.xz
dexon-sol-tools-07a872f80213a71d17d61a47e7faeee0e87d1822.tar.zst
dexon-sol-tools-07a872f80213a71d17d61a47e7faeee0e87d1822.zip
Merge pull request #139 from 0xProject/feature/gas-price-config
Gas price config
-rw-r--r--CHANGELOG.md4
-rw-r--r--src/0x.ts16
-rw-r--r--src/contract_wrappers/contract_wrapper.ts7
-rw-r--r--src/contract_wrappers/ether_token_wrapper.ts4
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts4
-rw-r--r--src/contract_wrappers/token_registry_wrapper.ts4
-rw-r--r--src/contract_wrappers/token_wrapper.ts4
-rw-r--r--src/globals.d.ts2
-rw-r--r--src/index.ts1
-rw-r--r--src/types.ts4
-rw-r--r--test/ether_token_wrapper_test.ts6
11 files changed, 39 insertions, 17 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 03d0ab44c..6c859a097 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG
+vTBD - _TBD_
+ * Added the optional `zeroExConfig` parameter to the constructor of `ZeroEx` (#139)
+ * Added the ability to specify `gasPrice` when instantiating `ZeroEx` (#139)
+
v0.11.0 - _August 24, 2017_
------------------------
* Added `zeroEx.token.setUnlimitedProxyAllowanceAsync` (#137)
diff --git a/src/0x.ts b/src/0x.ts
index e8b6b77b0..7fe6331c1 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -16,7 +16,7 @@ import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper';
import {EtherTokenWrapper} from './contract_wrappers/ether_token_wrapper';
import {TokenWrapper} from './contract_wrappers/token_wrapper';
import {TokenTransferProxyWrapper} from './contract_wrappers/token_transfer_proxy_wrapper';
-import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider} from './types';
+import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider, ZeroExConfig} from './types';
// Customize our BigNumber instances
bigNumberConfigs.configure();
@@ -159,15 +159,17 @@ 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
* 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) {
+ constructor(provider: Web3Provider, config?: ZeroExConfig) {
this._web3Wrapper = new Web3Wrapper(provider);
- this.token = new TokenWrapper(this._web3Wrapper);
- this.proxy = new TokenTransferProxyWrapper(this._web3Wrapper);
- this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token);
- this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper);
- this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token);
+ const gasPrice = _.isUndefined(config) ? undefined : config.gasPrice;
+ this.token = new TokenWrapper(this._web3Wrapper, gasPrice);
+ this.proxy = new TokenTransferProxyWrapper(this._web3Wrapper, gasPrice);
+ this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token, gasPrice);
+ this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper, gasPrice);
+ this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token, gasPrice);
}
/**
* Sets a new web3 provider for 0x.js. Updating the provider will stop all
diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts
index 7efa229a5..28df82cee 100644
--- a/src/contract_wrappers/contract_wrapper.ts
+++ b/src/contract_wrappers/contract_wrapper.ts
@@ -6,11 +6,16 @@ import {utils} from '../utils/utils';
export class ContractWrapper {
protected _web3Wrapper: Web3Wrapper;
- constructor(web3Wrapper: Web3Wrapper) {
+ private _gasPrice?: BigNumber.BigNumber;
+ constructor(web3Wrapper: Web3Wrapper, gasPrice?: BigNumber.BigNumber) {
this._web3Wrapper = web3Wrapper;
+ this._gasPrice = gasPrice;
}
protected async _instantiateContractIfExistsAsync(artifact: Artifact, address?: string): Promise<ContractInstance> {
const c = await contract(artifact);
+ c.defaults({
+ gasPrice: this._gasPrice,
+ });
const providerObj = this._web3Wrapper.getCurrentProvider();
c.setProvider(providerObj);
diff --git a/src/contract_wrappers/ether_token_wrapper.ts b/src/contract_wrappers/ether_token_wrapper.ts
index ee0ac2d8c..3c282510f 100644
--- a/src/contract_wrappers/ether_token_wrapper.ts
+++ b/src/contract_wrappers/ether_token_wrapper.ts
@@ -13,8 +13,8 @@ import * as EtherTokenArtifacts from '../artifacts/EtherToken.json';
export class EtherTokenWrapper extends ContractWrapper {
private _etherTokenContractIfExists?: EtherTokenContract;
private _tokenWrapper: TokenWrapper;
- constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper) {
- super(web3Wrapper);
+ constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper, gasPrice?: BigNumber.BigNumber) {
+ super(web3Wrapper, gasPrice);
this._tokenWrapper = tokenWrapper;
}
/**
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index a01940f4b..d09df236b 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -73,8 +73,8 @@ export class ExchangeWrapper extends ContractWrapper {
];
return [orderAddresses, orderValues];
}
- constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper) {
- super(web3Wrapper);
+ constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper, gasPrice?: BigNumber.BigNumber) {
+ super(web3Wrapper, gasPrice);
this._tokenWrapper = tokenWrapper;
this._orderValidationUtils = new OrderValidationUtils(tokenWrapper, this);
this._exchangeLogEventEmitters = [];
diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts
index 5fee1304e..822e69460 100644
--- a/src/contract_wrappers/token_registry_wrapper.ts
+++ b/src/contract_wrappers/token_registry_wrapper.ts
@@ -11,8 +11,8 @@ import * as TokenRegistryArtifacts from '../artifacts/TokenRegistry.json';
*/
export class TokenRegistryWrapper extends ContractWrapper {
private _tokenRegistryContractIfExists?: TokenRegistryContract;
- constructor(web3Wrapper: Web3Wrapper) {
- super(web3Wrapper);
+ constructor(web3Wrapper: Web3Wrapper, gasPrice?: BigNumber.BigNumber) {
+ super(web3Wrapper, gasPrice);
}
/**
* Retrieves all the tokens currently listed in the Token Registry smart contract
diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts
index 51490359e..f7070f1f4 100644
--- a/src/contract_wrappers/token_wrapper.ts
+++ b/src/contract_wrappers/token_wrapper.ts
@@ -31,8 +31,8 @@ export class TokenWrapper extends ContractWrapper {
public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
private _tokenContractsByAddress: {[address: string]: TokenContract};
private _tokenLogEventEmitters: ContractEventEmitter[];
- constructor(web3Wrapper: Web3Wrapper) {
- super(web3Wrapper);
+ constructor(web3Wrapper: Web3Wrapper, gasPrice?: BigNumber.BigNumber) {
+ super(web3Wrapper, gasPrice);
this._tokenContractsByAddress = {};
this._tokenLogEventEmitters = [];
}
diff --git a/src/globals.d.ts b/src/globals.d.ts
index 9879a57ad..1ef70d679 100644
--- a/src/globals.d.ts
+++ b/src/globals.d.ts
@@ -39,6 +39,8 @@ declare interface ContractInstance {
declare interface ContractFactory {
setProvider: (providerObj: any) => void;
deployed: () => ContractInstance;
+ // Both any's are Web3.CallData, but I was unable to import it in this file
+ defaults: (config: any) => any;
at: (address: string) => ContractInstance;
}
declare interface Artifact {
diff --git a/src/index.ts b/src/index.ts
index 81523953e..6d6e4484c 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -29,4 +29,5 @@ export {
TokenContractEventArgs,
ContractEventArgs,
Web3Provider,
+ ZeroExConfig,
} from './types';
diff --git a/src/types.ts b/src/types.ts
index 71227647b..7c2f79538 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -385,3 +385,7 @@ export interface JSONRPCPayload {
params: any[];
method: string;
}
+
+export interface ZeroExConfig {
+ gasPrice?: BigNumber.BigNumber; // Gas price to use with every transaction
+}
diff --git a/test/ether_token_wrapper_test.ts b/test/ether_token_wrapper_test.ts
index a8186499c..b40061a41 100644
--- a/test/ether_token_wrapper_test.ts
+++ b/test/ether_token_wrapper_test.ts
@@ -26,9 +26,13 @@ describe('EtherTokenWrapper', () => {
let wethContractAddress: string;
let depositWeiAmount: BigNumber.BigNumber;
let decimalPlaces: number;
+ const gasPrice = new BigNumber(1);
+ const zeroExConfig = {
+ gasPrice,
+ };
before(async () => {
web3 = web3Factory.create();
- zeroEx = new ZeroEx(web3.currentProvider);
+ zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig);
userAddresses = await promisify(web3.eth.getAccounts)();
addressWithETH = userAddresses[0];
wethContractAddress = await zeroEx.etherToken.getContractAddressAsync();