aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-05-30 21:27:51 +0800
committerFabio Berger <me@fabioberger.com>2017-05-30 21:27:51 +0800
commitb5e496ea0f04206b74b37d71d6ba3e6975206efc (patch)
tree27d6a82455a942ee6ede80fa32d6d619fd5a1d84 /src/contract_wrappers
parent86cdb6cb83078f9f29f473e0ebb8425a2d90f5ec (diff)
downloaddexon-sol-tools-b5e496ea0f04206b74b37d71d6ba3e6975206efc.tar
dexon-sol-tools-b5e496ea0f04206b74b37d71d6ba3e6975206efc.tar.gz
dexon-sol-tools-b5e496ea0f04206b74b37d71d6ba3e6975206efc.tar.bz2
dexon-sol-tools-b5e496ea0f04206b74b37d71d6ba3e6975206efc.tar.lz
dexon-sol-tools-b5e496ea0f04206b74b37d71d6ba3e6975206efc.tar.xz
dexon-sol-tools-b5e496ea0f04206b74b37d71d6ba3e6975206efc.tar.zst
dexon-sol-tools-b5e496ea0f04206b74b37d71d6ba3e6975206efc.zip
Implement zeroEx.token.getProxyAllowanceAsync
Diffstat (limited to 'src/contract_wrappers')
-rw-r--r--src/contract_wrappers/token_wrapper.ts27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts
index fe1d0c89f..0282d8266 100644
--- a/src/contract_wrappers/token_wrapper.ts
+++ b/src/contract_wrappers/token_wrapper.ts
@@ -4,7 +4,8 @@ import {Web3Wrapper} from '../web3_wrapper';
import {assert} from '../utils/assert';
import {ContractWrapper} from './contract_wrapper';
import * as TokenArtifacts from '../artifacts/Token.json';
-import {TokenContract} from '../types';
+import * as ProxyArtifacts from '../artifacts/Proxy.json';
+import {TokenContract, InternalError} from '../types';
export class TokenWrapper extends ContractWrapper {
private tokenContractsByAddress: {[address: string]: TokenContract};
@@ -29,6 +30,19 @@ export class TokenWrapper extends ContractWrapper {
balance = _.isUndefined(balance) ? new BigNumber(0) : new BigNumber(balance);
return balance;
}
+ /**
+ * Retrieves the allowance of an ERC20 token set to the 0x proxy contract by an owner address
+ */
+ public async getProxyAllowanceAsync(tokenAddress: string, ownerAddress: string) {
+ assert.isETHAddressHex('ownerAddress', ownerAddress);
+ assert.isETHAddressHex('tokenAddress', tokenAddress);
+
+ const tokenContract = await this.getTokenContractAsync(tokenAddress);
+ const proxyAddress = await this.getProxyAddressAsync();
+ let allowance = await tokenContract.allowance.call(ownerAddress, proxyAddress);
+ allowance = _.isUndefined(allowance) ? new BigNumber(0) : new BigNumber(allowance);
+ return allowance;
+ }
private async getTokenContractAsync(tokenAddress: string): Promise<TokenContract> {
let tokenContract = this.tokenContractsByAddress[tokenAddress];
if (!_.isUndefined(tokenContract)) {
@@ -39,4 +53,15 @@ export class TokenWrapper extends ContractWrapper {
this.tokenContractsByAddress[tokenAddress] = tokenContract;
return tokenContract;
}
+ private async getProxyAddressAsync() {
+ const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync();
+ const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ?
+ undefined :
+ (ProxyArtifacts as any).networks[networkIdIfExists];
+ if (_.isUndefined(proxyNetworkConfigsIfExists)) {
+ throw new Error(InternalError.PROXY_ADDRESS_NOT_FOUND);
+ }
+ const proxyAddress = proxyNetworkConfigsIfExists.address;
+ return proxyAddress;
+ }
}