diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-01 01:26:18 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-01 01:26:18 +0800 |
commit | 886ed9180d4e59f6ef1e72509d003726a5a898e9 (patch) | |
tree | 528727ff19cc54e2d51a6a794acd9c52a1a980f5 /src | |
parent | 82a46b4938902009896bef1d296b887f66b284fd (diff) | |
parent | 1c765cd55f227d99941f5944ff60022884890fe1 (diff) | |
download | dexon-0x-contracts-886ed9180d4e59f6ef1e72509d003726a5a898e9.tar dexon-0x-contracts-886ed9180d4e59f6ef1e72509d003726a5a898e9.tar.gz dexon-0x-contracts-886ed9180d4e59f6ef1e72509d003726a5a898e9.tar.bz2 dexon-0x-contracts-886ed9180d4e59f6ef1e72509d003726a5a898e9.tar.lz dexon-0x-contracts-886ed9180d4e59f6ef1e72509d003726a5a898e9.tar.xz dexon-0x-contracts-886ed9180d4e59f6ef1e72509d003726a5a898e9.tar.zst dexon-0x-contracts-886ed9180d4e59f6ef1e72509d003726a5a898e9.zip |
Merge branch 'master' into fillOrderAsync
Diffstat (limited to 'src')
-rw-r--r-- | src/contract_wrappers/token_wrapper.ts | 14 | ||||
-rw-r--r-- | src/types.ts | 15 |
2 files changed, 14 insertions, 15 deletions
diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index e93b6b7c2..cedbfbdae 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -6,7 +6,7 @@ import {constants} from '../utils/constants'; import {ContractWrapper} from './contract_wrapper'; import * as TokenArtifacts from '../artifacts/Token.json'; import * as ProxyArtifacts from '../artifacts/Proxy.json'; -import {TokenContract, InternalError} from '../types'; +import {TokenContract, ZeroExError} from '../types'; const ALLOWANCE_TO_ZERO_GAS_AMOUNT = 45730; @@ -20,7 +20,7 @@ export class TokenWrapper extends ContractWrapper { this.tokenContractsByAddress = {}; } /** - * Returns an owner's ERC20 token balance + * Returns an owner's ERC20 token balance. */ public async getBalanceAsync(tokenAddress: string, ownerAddress: string): Promise<BigNumber.BigNumber> { assert.isETHAddressHex('ownerAddress', ownerAddress); @@ -30,12 +30,12 @@ export class TokenWrapper extends ContractWrapper { let balance = await tokenContract.balanceOf.call(ownerAddress); // The BigNumber instance returned by Web3 is of a much older version then our own, we therefore // should always re-instantiate the returned BigNumber after retrieval. - balance = _.isUndefined(balance) ? new BigNumber(0) : new BigNumber(balance); + balance = new BigNumber(balance); return balance; } /** * Retrieves the allowance in baseUnits of the ERC20 token set to the 0x proxy contract - * by an owner address + * by an owner address. */ public async getProxyAllowanceAsync(tokenAddress: string, ownerAddress: string) { assert.isETHAddressHex('ownerAddress', ownerAddress); @@ -44,9 +44,7 @@ export class TokenWrapper extends ContractWrapper { const tokenContract = await this.getTokenContractAsync(tokenAddress); const proxyAddress = await this.getProxyAddressAsync(); let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, proxyAddress); - allowanceInBaseUnits = _.isUndefined(allowanceInBaseUnits) ? - new BigNumber(0) : - new BigNumber(allowanceInBaseUnits); + allowanceInBaseUnits = new BigNumber(allowanceInBaseUnits); return allowanceInBaseUnits; } /** @@ -102,7 +100,7 @@ export class TokenWrapper extends ContractWrapper { undefined : (ProxyArtifacts as any).networks[networkIdIfExists]; if (_.isUndefined(proxyNetworkConfigsIfExists)) { - throw new Error(InternalError.PROXY_ADDRESS_NOT_FOUND); + throw new Error(ZeroExError.CONTRACT_NOT_DEPLOYED_ON_NETWORK); } const proxyAddress = proxyNetworkConfigsIfExists.address; return proxyAddress; diff --git a/src/types.ts b/src/types.ts index b70afe298..8c378816f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,14 +14,10 @@ export const ZeroExError = strEnum([ 'UNHANDLED_ERROR', 'USER_HAS_NO_ASSOCIATED_ADDRESSES', 'INVALID_SIGNATURE', + 'CONTRACT_NOT_DEPLOYED_ON_NETWORK', ]); export type ZeroExError = keyof typeof ZeroExError; -export const InternalError = strEnum([ - 'PROXY_ADDRESS_NOT_FOUND', -]); -export type InternalError = keyof typeof InternalError; - /** * Elliptic Curve signature */ @@ -57,8 +53,8 @@ export interface TokenContract { allowance: { call: (ownerAddress: string, allowedAddress: string) => Promise<BigNumber.BigNumber>; }; - transfer: (to: string, amountInBaseUnits: BigNumber.BigNumber, opts: any) => Promise<boolean>; - approve: (proxyAddress: string, amountInBaseUnits: BigNumber.BigNumber, opts: any) => void; + transfer: (to: string, amountInBaseUnits: BigNumber.BigNumber, txOpts: TxOpts) => Promise<boolean>; + approve: (proxyAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts: TxOpts) => void; } export interface TokenRegistryContract { @@ -122,3 +118,8 @@ export interface Token { decimals: number; url: string; } + +export interface TxOpts { + from: string; + gas?: number; +} |