aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-09-18 21:55:26 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-09-18 21:55:26 +0800
commit504e7a25a5ee138941ca35d4aad1b63444e47033 (patch)
treec60208acd76a53cae30050ebd768d9fa0562f88e /src
parent8db90538a17a0458fba6d2ed8a8b51bf9edf0fa4 (diff)
downloaddexon-0x-contracts-504e7a25a5ee138941ca35d4aad1b63444e47033.tar.gz
dexon-0x-contracts-504e7a25a5ee138941ca35d4aad1b63444e47033.tar.zst
dexon-0x-contracts-504e7a25a5ee138941ca35d4aad1b63444e47033.zip
Make contract addresses configurable
Diffstat (limited to 'src')
-rw-r--r--src/0x.ts9
-rw-r--r--src/contract_wrappers/ether_token_wrapper.ts6
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts6
-rw-r--r--src/contract_wrappers/token_registry_wrapper.ts6
-rw-r--r--src/types.ts3
5 files changed, 21 insertions, 9 deletions
diff --git a/src/0x.ts b/src/0x.ts
index 8a69bec30..37e25eb0f 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -198,13 +198,16 @@ export class ZeroEx {
this._web3Wrapper,
this._getTokenTransferProxyAddressAsync.bind(this),
);
- this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token);
+ const exchangeContractAddress = _.isUndefined(config) ? undefined : config.exchangeContractAddress;
+ this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token, exchangeContractAddress);
this.proxy = new TokenTransferProxyWrapper(
this._web3Wrapper,
this._getTokenTransferProxyAddressAsync.bind(this),
);
- this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper);
- this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token);
+ const tokenRegistryContractAddress = _.isUndefined(config) ? undefined : config.tokenRegistryContractAddress;
+ this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper, tokenRegistryContractAddress);
+ const etherTokenContractAddress = _.isUndefined(config) ? undefined : config.etherTokenContractAddress;
+ this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token, etherTokenContractAddress);
}
/**
* Sets a new web3 provider for 0x.js. Updating the provider will stop all
diff --git a/src/contract_wrappers/ether_token_wrapper.ts b/src/contract_wrappers/ether_token_wrapper.ts
index b86309f90..efe3fe06c 100644
--- a/src/contract_wrappers/ether_token_wrapper.ts
+++ b/src/contract_wrappers/ether_token_wrapper.ts
@@ -13,9 +13,11 @@ import {artifacts} from '../artifacts';
export class EtherTokenWrapper extends ContractWrapper {
private _etherTokenContractIfExists?: EtherTokenContract;
private _tokenWrapper: TokenWrapper;
- constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper) {
+ private _contractAddress?: string;
+ constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper, contractAddress?: string) {
super(web3Wrapper);
this._tokenWrapper = tokenWrapper;
+ this._contractAddress = contractAddress;
}
/**
* Deposit ETH into the Wrapped ETH smart contract and issues the equivalent number of wrapped ETH tokens
@@ -76,7 +78,7 @@ export class EtherTokenWrapper extends ContractWrapper {
return this._etherTokenContractIfExists;
}
const contractInstance = await this._instantiateContractIfExistsAsync<EtherTokenContract>(
- artifacts.EtherTokenArtifact,
+ artifacts.EtherTokenArtifact, this._contractAddress,
);
this._etherTokenContractIfExists = contractInstance as EtherTokenContract;
return this._etherTokenContractIfExists;
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index 17e8095a4..2360f639d 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -56,6 +56,7 @@ export class ExchangeWrapper extends ContractWrapper {
[ExchangeContractErrCodes.ERROR_FILL_TRUNCATION]: ExchangeContractErrs.OrderFillRoundingError,
[ExchangeContractErrCodes.ERROR_FILL_BALANCE_ALLOWANCE]: ExchangeContractErrs.FillBalanceAllowanceError,
};
+ private _contractAddress?: string;
private static _getOrderAddressesAndValues(order: Order): [OrderAddresses, OrderValues] {
const orderAddresses: OrderAddresses = [
order.maker,
@@ -74,11 +75,12 @@ export class ExchangeWrapper extends ContractWrapper {
];
return [orderAddresses, orderValues];
}
- constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper) {
+ constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper, contractAddress?: string) {
super(web3Wrapper);
this._tokenWrapper = tokenWrapper;
this._orderValidationUtils = new OrderValidationUtils(tokenWrapper, this);
this._exchangeLogEventEmitters = [];
+ this._contractAddress = contractAddress;
}
/**
* Returns the unavailable takerAmount of an order. Unavailable amount is defined as the total
@@ -738,7 +740,7 @@ export class ExchangeWrapper extends ContractWrapper {
return this._exchangeContractIfExists;
}
const contractInstance = await this._instantiateContractIfExistsAsync<ExchangeContract>(
- artifacts.ExchangeArtifact,
+ artifacts.ExchangeArtifact, this._contractAddress,
);
this._exchangeContractIfExists = contractInstance as ExchangeContract;
return this._exchangeContractIfExists;
diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts
index 528a88e06..0807982b1 100644
--- a/src/contract_wrappers/token_registry_wrapper.ts
+++ b/src/contract_wrappers/token_registry_wrapper.ts
@@ -11,8 +11,10 @@ import {artifacts} from '../artifacts';
*/
export class TokenRegistryWrapper extends ContractWrapper {
private _tokenRegistryContractIfExists?: TokenRegistryContract;
- constructor(web3Wrapper: Web3Wrapper) {
+ private _contractAddress?: string;
+ constructor(web3Wrapper: Web3Wrapper, contractAddress?: string) {
super(web3Wrapper);
+ this._contractAddress = contractAddress;
}
/**
* Retrieves all the tokens currently listed in the Token Registry smart contract
@@ -102,7 +104,7 @@ export class TokenRegistryWrapper extends ContractWrapper {
return this._tokenRegistryContractIfExists;
}
const contractInstance = await this._instantiateContractIfExistsAsync<TokenRegistryContract>(
- artifacts.TokenRegistryArtifact,
+ artifacts.TokenRegistryArtifact, this._contractAddress,
);
this._tokenRegistryContractIfExists = contractInstance as TokenRegistryContract;
return this._tokenRegistryContractIfExists;
diff --git a/src/types.ts b/src/types.ts
index c7204a9fc..9583d5bd4 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -391,6 +391,9 @@ export interface JSONRPCPayload {
export interface ZeroExConfig {
gasPrice?: BigNumber.BigNumber; // Gas price to use with every transaction
+ exchangeContractAddress?: string;
+ tokenRegistryContractAddress?: string;
+ etherTokenContractAddress?: string;
}
export type TransactionReceipt = Web3.TransactionReceipt;