Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #171 from 0xProject/feature/zrx-getter
Browse files Browse the repository at this point in the history
Make getZRXTokenAddressAsync public
  • Loading branch information
LogvinovLeon authored Sep 26, 2017
2 parents 0a19a7e + 8a29f12 commit 3c40526
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

v0.17.0 - _September 26, 2017_
* Made `zeroEx.exchange.getZRXTokenAddressAsync` public (#171)

v0.16.0 - _September 20, 2017_
------------------------
* Added the ability to specify custom contract addresses to be used with 0x.js (#165)
Expand Down
18 changes: 11 additions & 7 deletions src/contract_wrappers/exchange_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isBigNumber('fillTakerTokenAmount', fillTakerTokenAmount);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
const zrxTokenAddress = await this._getZRXTokenAddressAsync();
const zrxTokenAddress = await this.getZRXTokenAddressAsync();
await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
}
Expand Down Expand Up @@ -670,7 +670,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isBigNumber('fillTakerTokenAmount', fillTakerTokenAmount);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
const zrxTokenAddress = await this._getZRXTokenAddressAsync();
const zrxTokenAddress = await this.getZRXTokenAddressAsync();
await this._orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
}
Expand Down Expand Up @@ -708,6 +708,15 @@ export class ExchangeWrapper extends ContractWrapper {
throw new Error(errMessage);
}
}
/**
* 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;
}
private async _invalidateContractInstancesAsync(): Promise<void> {
await this.stopWatchingAllEventsAsync();
delete this._exchangeContractIfExists;
Expand Down Expand Up @@ -745,11 +754,6 @@ export class ExchangeWrapper extends ContractWrapper {
this._exchangeContractIfExists = contractInstance as ExchangeContract;
return this._exchangeContractIfExists;
}
private async _getZRXTokenAddressAsync(): Promise<string> {
const exchangeInstance = await this._getExchangeContractAsync();
const ZRXtokenAddress = await exchangeInstance.ZRX_TOKEN_CONTRACT.callAsync();
return ZRXtokenAddress;
}
private async _getTokenTransferProxyAddressAsync(): Promise<string> {
const exchangeInstance = await this._getExchangeContractAsync();
const tokenTransferProxyAddress = await exchangeInstance.TOKEN_TRANSFER_PROXY_CONTRACT.callAsync();
Expand Down
7 changes: 7 additions & 0 deletions test/exchange_wrapper_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,4 +591,11 @@ describe('ExchangeWrapper', () => {
expect(orderHash).to.equal(orderHashFromContract);
});
});
describe('#getZRXTokenAddressAsync', () => {
it('gets the same token as is in token registry', async () => {
const zrxAddress = await zeroEx.exchange.getZRXTokenAddressAsync();
const zrxToken = tokenUtils.getProtocolTokenOrThrow();
expect(zrxAddress).to.equal(zrxToken.address);
});
});
});

0 comments on commit 3c40526

Please sign in to comment.