Merge pull request #89 from 0xProject/proxy

Add zeroEx.proxy
This commit is contained in:
Leonid 2017-07-03 16:24:22 -07:00 committed by GitHub
commit 2892f45ab7
7 changed files with 41 additions and 14 deletions

View File

@ -1,9 +1,10 @@
# CHANGELOG
v0.7.2 - _Jun. 26, 2017_
v0.8.0 - TBD
------------------------
* Add the ability to call methods on different authorized versions of the Exchange smart contract (#82)
* Update contract artifacts to reflect latest changes to the smart contracts (0xproject/contracts#59)
* Add `zeroEx.proxy.isAuthorizedAsync` and `zeroEx.proxy.getAuthorizedAddressesAsync` (#89)
v0.7.1 - _Jun. 26, 2017_
------------------------

View File

@ -52,7 +52,11 @@ export class ZeroEx {
* wrapped ETH ERC20 token smart contract.
*/
public etherToken: EtherTokenWrapper;
private _proxyWrapper: ProxyWrapper;
/**
* An instance of the ProxyWrapper class containing methods for interacting with the
* proxy smart contract.
*/
public proxy: ProxyWrapper;
private _web3Wrapper: Web3Wrapper;
/**
* Verifies that the elliptic curve signature `signature` was generated
@ -150,8 +154,8 @@ export class ZeroEx {
constructor(provider: Web3Provider) {
this._web3Wrapper = new Web3Wrapper(provider);
this.token = new TokenWrapper(this._web3Wrapper);
this._proxyWrapper = new ProxyWrapper(this._web3Wrapper);
this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token, this._proxyWrapper);
this.proxy = new ProxyWrapper(this._web3Wrapper);
this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token, this.proxy);
this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper);
this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token);
}
@ -165,7 +169,7 @@ export class ZeroEx {
await this.exchange.invalidateContractInstancesAsync();
this.tokenRegistry.invalidateContractInstance();
this.token.invalidateContractInstances();
this._proxyWrapper.invalidateContractInstance();
this.proxy.invalidateContractInstance();
}
/**
* Get user Ethereum addresses available through the supplied web3 instance available for sending transactions.

View File

@ -99,7 +99,7 @@ export class ExchangeWrapper extends ContractWrapper {
* subtracting the unavailable amount from the total order takerAmount.
* @param orderHash The hex encoded orderHash for which you would like to retrieve the
* unavailable takerAmount.
* @param exchangeContractAddress The hex encoded address of the Exchange contract to use.
* @param exchangeContractAddress The hex encoded address of the Exchange contract to call.
* @return The amount of the order (in taker tokens) that has either been filled or canceled.
*/
public async getUnavailableTakerAmountAsync(orderHash: string,
@ -115,7 +115,7 @@ export class ExchangeWrapper extends ContractWrapper {
/**
* Retrieve the takerAmount of an order that has already been filled.
* @param orderHash The hex encoded orderHash for which you would like to retrieve the filled takerAmount.
* @param exchangeContractAddress The hex encoded address of the Exchange contract to use.
* @param exchangeContractAddress The hex encoded address of the Exchange contract to call.
* @return The amount of the order (in taker tokens) that has already been filled.
*/
public async getFilledTakerAmountAsync(orderHash: string,
@ -132,7 +132,7 @@ export class ExchangeWrapper extends ContractWrapper {
* Retrieve the takerAmount of an order that has been cancelled.
* @param orderHash The hex encoded orderHash for which you would like to retrieve the
* cancelled takerAmount.
* @param exchangeContractAddress The hex encoded address of the Exchange contract to use.
* @param exchangeContractAddress The hex encoded address of the Exchange contract to call.
* @return The amount of the order (in taker tokens) that has been cancelled.
*/
public async getCanceledTakerAmountAsync(orderHash: string,
@ -578,7 +578,7 @@ export class ExchangeWrapper extends ContractWrapper {
* @param subscriptionOpts Subscriptions options that let you configure the subscription.
* @param indexFilterValues An object where the keys are indexed args returned by the event and
* the value is the value you are interested in. E.g `{maker: aUserAddressHex}`
* @param exchangeContractAddress The hex encoded address of the Exchange contract to use.
* @param exchangeContractAddress The hex encoded address of the Exchange contract to call.
* @return ContractEventEmitter object
*/
public async subscribeAsync(eventName: ExchangeEvents, subscriptionOpts: SubscriptionOpts,

View File

@ -14,7 +14,7 @@ export class ProxyWrapper extends ContractWrapper {
}
/**
* Check if the Exchange contract address is authorized by the Proxy contract.
* @param exchangeContractAddress The hex encoded address of the Exchange contract to use.
* @param exchangeContractAddress The hex encoded address of the Exchange contract to call.
* @return Whether the exchangeContractAddress is authorized.
*/
public async isAuthorizedAsync(exchangeContractAddress: string): Promise<boolean> {
@ -22,6 +22,16 @@ export class ProxyWrapper extends ContractWrapper {
const isAuthorized = await proxyContractInstance.authorized.call(exchangeContractAddress);
return isAuthorized;
}
/**
* Get the list of all Exchange contract addresses authorized by the Proxy contract.
* @param exchangeContractAddress The hex encoded address of the Exchange contract to call.
* @return The list of authorized addresses.
*/
public async getAuthorizedAddressesAsync(exchangeContractAddress: string): Promise<string[]> {
const proxyContractInstance = await this._getProxyContractAsync();
const authorizedAddresses = await proxyContractInstance.getAuthorizedAddresses.call();
return authorizedAddresses;
}
private async _getProxyContractAsync(): Promise<ProxyContract> {
if (!_.isUndefined(this._proxyContractIfExists)) {
return this._proxyContractIfExists;

View File

@ -149,6 +149,9 @@ export interface EtherTokenContract extends ContractInstance {
}
export interface ProxyContract extends ContractInstance {
getAuthorizedAddresses: {
call: () => Promise<string[]>;
};
authorized: {
call: (address: string) => Promise<boolean>;
};

View File

@ -832,8 +832,7 @@ describe('ExchangeWrapper', () => {
const exchangeAddresses = await zeroEx.exchange.getProxyAuthorizedContractAddressesAsync();
for (const exchangeAddress of exchangeAddresses) {
assert.isETHAddressHex('exchangeAddress', exchangeAddress);
const proxyWrapper = (zeroEx as any)._proxyWrapper as ProxyWrapper;
const isAuthorized = await proxyWrapper.isAuthorizedAsync(exchangeAddress);
const isAuthorized = await zeroEx.proxy.isAuthorizedAsync(exchangeAddress);
expect(isAuthorized).to.be.true();
}
});

View File

@ -9,15 +9,25 @@ const expect = chai.expect;
describe('ProxyWrapper', () => {
let zeroEx: ZeroEx;
let exchangeContractAddress: string;
before(async () => {
const web3 = web3Factory.create();
zeroEx = new ZeroEx(web3.currentProvider);
[exchangeContractAddress] = await zeroEx.exchange.getAvailableContractAddressesAsync();
});
describe('#isAuthorizedAsync', () => {
it('should return false if the address is not authorized', async () => {
const proxyWrapper = (zeroEx as any)._proxyWrapper as ProxyWrapper;
const isAuthorized = await proxyWrapper.isAuthorizedAsync(ZeroEx.NULL_ADDRESS);
const isAuthorized = await zeroEx.proxy.isAuthorizedAsync(ZeroEx.NULL_ADDRESS);
expect(isAuthorized).to.be.false();
});
});
describe('#getAuthorizedAddressesAsync', () => {
it('should return the list of authorized addresses', async () => {
const authorizedAddresses = await zeroEx.proxy.getAuthorizedAddressesAsync(exchangeContractAddress);
for (const authorizedAddress of authorizedAddresses) {
const isAuthorized = await zeroEx.proxy.isAuthorizedAsync(authorizedAddress);
expect(isAuthorized).to.be.true();
}
});
});
});