Merge pull request #139 from 0xProject/feature/gas-price-config
Gas price config
This commit is contained in:
commit
07a872f802
@ -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)
|
||||
|
16
src/0x.ts
16
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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
/**
|
||||
|
@ -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 = [];
|
||||
|
@ -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
|
||||
|
@ -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 = [];
|
||||
}
|
||||
|
2
src/globals.d.ts
vendored
2
src/globals.d.ts
vendored
@ -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 {
|
||||
|
@ -29,4 +29,5 @@ export {
|
||||
TokenContractEventArgs,
|
||||
ContractEventArgs,
|
||||
Web3Provider,
|
||||
ZeroExConfig,
|
||||
} from './types';
|
||||
|
@ -385,3 +385,7 @@ export interface JSONRPCPayload {
|
||||
params: any[];
|
||||
method: string;
|
||||
}
|
||||
|
||||
export interface ZeroExConfig {
|
||||
gasPrice?: BigNumber.BigNumber; // Gas price to use with every transaction
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user