aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/contract_wrappers
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-11-22 06:50:14 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-11-24 05:13:36 +0800
commit63dc606a9c08dad5e0aae09b86178fcd3e78e867 (patch)
tree1b82eb0d3da14ab22d614d69338623086214c3db /packages/0x.js/src/contract_wrappers
parent131236305bff6cdf85a7edb7e3c61c50ffbb1956 (diff)
downloaddexon-sol-tools-63dc606a9c08dad5e0aae09b86178fcd3e78e867.tar
dexon-sol-tools-63dc606a9c08dad5e0aae09b86178fcd3e78e867.tar.gz
dexon-sol-tools-63dc606a9c08dad5e0aae09b86178fcd3e78e867.tar.bz2
dexon-sol-tools-63dc606a9c08dad5e0aae09b86178fcd3e78e867.tar.lz
dexon-sol-tools-63dc606a9c08dad5e0aae09b86178fcd3e78e867.tar.xz
dexon-sol-tools-63dc606a9c08dad5e0aae09b86178fcd3e78e867.tar.zst
dexon-sol-tools-63dc606a9c08dad5e0aae09b86178fcd3e78e867.zip
Make getZRXTokenAddress non async
Diffstat (limited to 'packages/0x.js/src/contract_wrappers')
-rw-r--r--packages/0x.js/src/contract_wrappers/exchange_wrapper.ts32
-rw-r--r--packages/0x.js/src/contract_wrappers/token_wrapper.ts4
2 files changed, 22 insertions, 14 deletions
diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
index 3e631b73e..96b642a90 100644
--- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
@@ -63,6 +63,7 @@ export class ExchangeWrapper extends ContractWrapper {
[ExchangeContractErrCodes.ERROR_FILL_BALANCE_ALLOWANCE]: ExchangeContractErrs.FillBalanceAllowanceError,
};
private _contractAddressIfExists?: string;
+ private _zrxContractAddressIfExists?: string;
private static _getOrderAddressesAndValues(order: Order): [OrderAddresses, OrderValues] {
const orderAddresses: OrderAddresses = [
order.maker,
@@ -177,7 +178,7 @@ export class ExchangeWrapper extends ContractWrapper {
SHOULD_VALIDATE_BY_DEFAULT :
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
- const zrxTokenAddress = await this.getZRXTokenAddressAsync();
+ const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
@@ -249,7 +250,7 @@ export class ExchangeWrapper extends ContractWrapper {
SHOULD_VALIDATE_BY_DEFAULT :
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
- const zrxTokenAddress = await this.getZRXTokenAddressAsync();
+ const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
for (const signedOrder of signedOrders) {
await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
@@ -339,7 +340,7 @@ export class ExchangeWrapper extends ContractWrapper {
SHOULD_VALIDATE_BY_DEFAULT :
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
- const zrxTokenAddress = await this.getZRXTokenAddressAsync();
+ const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
for (const orderFillRequest of orderFillRequests) {
await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
@@ -419,7 +420,7 @@ export class ExchangeWrapper extends ContractWrapper {
SHOULD_VALIDATE_BY_DEFAULT :
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
- const zrxTokenAddress = await this.getZRXTokenAddressAsync();
+ const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
await this._orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
@@ -483,7 +484,7 @@ export class ExchangeWrapper extends ContractWrapper {
SHOULD_VALIDATE_BY_DEFAULT :
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
- const zrxTokenAddress = await this.getZRXTokenAddressAsync();
+ const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
for (const orderFillRequest of orderFillRequests) {
await this._orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
@@ -719,7 +720,7 @@ export class ExchangeWrapper extends ContractWrapper {
signedOrder: SignedOrder, opts?: ValidateOrderFillableOpts,
): Promise<void> {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
- const zrxTokenAddress = await this.getZRXTokenAddressAsync();
+ const zrxTokenAddress = this.getZRXTokenAddress();
const expectedFillTakerTokenAmount = !_.isUndefined(opts) ? opts.expectedFillTakerTokenAmount : undefined;
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
await this._orderValidationUtils.validateOrderFillableOrThrowAsync(
@@ -740,7 +741,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isValidBaseUnitAmount('fillTakerTokenAmount', fillTakerTokenAmount);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
- const zrxTokenAddress = await this.getZRXTokenAddressAsync();
+ const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
@@ -774,7 +775,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isValidBaseUnitAmount('fillTakerTokenAmount', fillTakerTokenAmount);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
- const zrxTokenAddress = await this.getZRXTokenAddressAsync();
+ const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
await this._orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
@@ -819,10 +820,17 @@ export class ExchangeWrapper extends ContractWrapper {
* Returns the ZRX token address used by the exchange contract.
* @return Address of ZRX token
*/
- public async getZRXTokenAddressAsync(): Promise<string> {
- const exchangeInstance = await this._getExchangeContractAsync();
- const ZRXtokenAddress = await exchangeInstance.ZRX_TOKEN_CONTRACT.callAsync();
- return ZRXtokenAddress;
+ public getZRXTokenAddress(): string {
+ const networkId = this._web3Wrapper.getNetworkId();
+ if (_.isUndefined(this._zrxContractAddressIfExists)) {
+ const zrxTokenAddress = artifacts.ZRXArtifact.networks[networkId].address;
+ if (_.isUndefined(zrxTokenAddress)) {
+ throw new Error(ZeroExError.ZRXContractDoesNotExist);
+ }
+ return zrxTokenAddress;
+ } else {
+ return this._zrxContractAddressIfExists;
+ }
}
private async _invalidateContractInstancesAsync(): Promise<void> {
this.unsubscribeAll();
diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
index 4b89d3cfc..5fd3a2a5d 100644
--- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
@@ -76,8 +76,8 @@ export class TokenWrapper extends ContractWrapper {
// Hack: for some reason default estimated gas amount causes `base fee exceeds gas limit` exception
// on testrpc. Probably related to https://github.com/ethereumjs/testrpc/issues/294
// TODO: Debug issue in testrpc and submit a PR, then remove this hack
- const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync();
- const gas = networkIdIfExists === constants.TESTRPC_NETWORK_ID ? ALLOWANCE_TO_ZERO_GAS_AMOUNT : undefined;
+ const networkId = this._web3Wrapper.getNetworkId();
+ const gas = networkId === constants.TESTRPC_NETWORK_ID ? ALLOWANCE_TO_ZERO_GAS_AMOUNT : undefined;
const txHash = await tokenContract.approve.sendTransactionAsync(spenderAddress, amountInBaseUnits, {
from: ownerAddress,
gas,