aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-08-25 18:00:02 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-08-29 16:01:13 +0800
commita6a16017997fbe53ac709f2f0d874e348da35621 (patch)
tree9c0bf98ddef5e9f073c7e5c795fc79eb2b9d3e35 /src
parenta8fd3f30cf87660f08fa7b1c249606b7f8872ba1 (diff)
downloaddexon-sol-tools-a6a16017997fbe53ac709f2f0d874e348da35621.tar
dexon-sol-tools-a6a16017997fbe53ac709f2f0d874e348da35621.tar.gz
dexon-sol-tools-a6a16017997fbe53ac709f2f0d874e348da35621.tar.bz2
dexon-sol-tools-a6a16017997fbe53ac709f2f0d874e348da35621.tar.lz
dexon-sol-tools-a6a16017997fbe53ac709f2f0d874e348da35621.tar.xz
dexon-sol-tools-a6a16017997fbe53ac709f2f0d874e348da35621.tar.zst
dexon-sol-tools-a6a16017997fbe53ac709f2f0d874e348da35621.zip
Allow user to specify the gas price
Diffstat (limited to 'src')
-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
7 files changed, 26 insertions, 15 deletions
diff --git a/src/0x.ts b/src/0x.ts
index e8b6b77b0..36ebb8ec2 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -159,15 +159,19 @@ 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 gasPrice The gas price to use for sending transactions. Defaults to 21 GWei.
* @return An instance of the 0x.js ZeroEx class.
*/
- constructor(provider: Web3Provider) {
+ constructor(provider: Web3Provider, gasPrice?: BigNumber.BigNumber) {
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);
+ if (_.isUndefined(gasPrice)) {
+ gasPrice = this._web3Wrapper.toWei(new BigNumber(21), 'gwei');
+ }
+ 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..015ed275a 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..eae84feec 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..8ae51da43 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..5469b4a95 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..24f56a24a 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 {