Rename x.call -> x.callAsync x() -> x.sendTransactionAsync() x.estimateGas() -> x.estimateGasAsync()

This commit is contained in:
Leonid Logvinov
2017-09-05 13:43:46 +02:00
parent e05dfab1fc
commit 9f12ef61b0
7 changed files with 132 additions and 110 deletions

View File

@@ -21,16 +21,18 @@ export class Contract implements Web3.ContractInstance {
private populateFunctions(): void { private populateFunctions(): void {
const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === 'function'); const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === 'function');
_.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => { _.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => {
const cbStyleFunction = this.contract[functionAbi.name];
if (functionAbi.constant) { if (functionAbi.constant) {
this[functionAbi.name] = promisify(cbStyleFunction, this.contract);
const cbStyleCallFunction = this.contract[functionAbi.name].call; const cbStyleCallFunction = this.contract[functionAbi.name].call;
this[functionAbi.name].call = promisify(cbStyleCallFunction, this.contract); this[functionAbi.name] = {
callAsync: promisify(cbStyleCallFunction, this.contract),
};
} else { } else {
this[functionAbi.name] = this.promisifyWithDefaultParams(cbStyleFunction); const cbStyleFunction = this.contract[functionAbi.name];
const cbStyleEstimateGasFunction = this.contract[functionAbi.name].estimateGas; const cbStyleEstimateGasFunction = this.contract[functionAbi.name].estimateGas;
this[functionAbi.name].estimateGas = this[functionAbi.name] = {
promisify(cbStyleEstimateGasFunction, this.contract); estimateGasAsync: promisify(cbStyleEstimateGasFunction, this.contract),
sendTransactionAsync: this.promisifyWithDefaultParams(cbStyleFunction),
};
} }
}); });
} }

View File

@@ -33,7 +33,7 @@ export class EtherTokenWrapper extends ContractWrapper {
assert.assert(ethBalanceInWei.gte(amountInWei), ZeroExError.InsufficientEthBalanceForDeposit); assert.assert(ethBalanceInWei.gte(amountInWei), ZeroExError.InsufficientEthBalanceForDeposit);
const wethContract = await this._getEtherTokenContractAsync(); const wethContract = await this._getEtherTokenContractAsync();
const txHash = await wethContract.deposit({ const txHash = await wethContract.deposit.sendTransactionAsync({
from: depositor, from: depositor,
value: amountInWei, value: amountInWei,
}); });
@@ -55,7 +55,7 @@ export class EtherTokenWrapper extends ContractWrapper {
assert.assert(WETHBalanceInBaseUnits.gte(amountInWei), ZeroExError.InsufficientWEthBalanceForWithdrawal); assert.assert(WETHBalanceInBaseUnits.gte(amountInWei), ZeroExError.InsufficientWEthBalanceForWithdrawal);
const wethContract = await this._getEtherTokenContractAsync(); const wethContract = await this._getEtherTokenContractAsync();
const txHash = await wethContract.withdraw(amountInWei, { const txHash = await wethContract.withdraw.sendTransactionAsync(amountInWei, {
from: withdrawer, from: withdrawer,
}); });
return txHash; return txHash;

View File

@@ -90,7 +90,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
const exchangeContract = await this._getExchangeContractAsync(); const exchangeContract = await this._getExchangeContractAsync();
let unavailableTakerTokenAmount = await exchangeContract.getUnavailableTakerTokenAmount.call(orderHash); let unavailableTakerTokenAmount = await exchangeContract.getUnavailableTakerTokenAmount.callAsync(orderHash);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
unavailableTakerTokenAmount = new BigNumber(unavailableTakerTokenAmount); unavailableTakerTokenAmount = new BigNumber(unavailableTakerTokenAmount);
return unavailableTakerTokenAmount; return unavailableTakerTokenAmount;
@@ -104,7 +104,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
const exchangeContract = await this._getExchangeContractAsync(); const exchangeContract = await this._getExchangeContractAsync();
let fillAmountInBaseUnits = await exchangeContract.filled.call(orderHash); let fillAmountInBaseUnits = await exchangeContract.filled.callAsync(orderHash);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
fillAmountInBaseUnits = new BigNumber(fillAmountInBaseUnits); fillAmountInBaseUnits = new BigNumber(fillAmountInBaseUnits);
return fillAmountInBaseUnits; return fillAmountInBaseUnits;
@@ -119,7 +119,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
const exchangeContract = await this._getExchangeContractAsync(); const exchangeContract = await this._getExchangeContractAsync();
let cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHash); let cancelledAmountInBaseUnits = await exchangeContract.cancelled.callAsync(orderHash);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
cancelledAmountInBaseUnits = new BigNumber(cancelledAmountInBaseUnits); cancelledAmountInBaseUnits = new BigNumber(cancelledAmountInBaseUnits);
return cancelledAmountInBaseUnits; return cancelledAmountInBaseUnits;
@@ -156,7 +156,7 @@ export class ExchangeWrapper extends ContractWrapper {
const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(signedOrder); const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(signedOrder);
const gas = await exchangeInstance.fillOrder.estimateGas( const gas = await exchangeInstance.fillOrder.estimateGasAsync(
orderAddresses, orderAddresses,
orderValues, orderValues,
fillTakerTokenAmount, fillTakerTokenAmount,
@@ -168,7 +168,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: takerAddress, from: takerAddress,
}, },
); );
const txHash: string = await exchangeInstance.fillOrder( const txHash: string = await exchangeInstance.fillOrder.sendTransactionAsync(
orderAddresses, orderAddresses,
orderValues, orderValues,
fillTakerTokenAmount, fillTakerTokenAmount,
@@ -235,7 +235,7 @@ export class ExchangeWrapper extends ContractWrapper {
); );
const exchangeInstance = await this._getExchangeContractAsync(); const exchangeInstance = await this._getExchangeContractAsync();
const gas = await exchangeInstance.fillOrdersUpTo.estimateGas( const gas = await exchangeInstance.fillOrdersUpTo.estimateGasAsync(
orderAddressesArray, orderAddressesArray,
orderValuesArray, orderValuesArray,
fillTakerTokenAmount, fillTakerTokenAmount,
@@ -247,7 +247,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: takerAddress, from: takerAddress,
}, },
); );
const txHash = await exchangeInstance.fillOrdersUpTo( const txHash = await exchangeInstance.fillOrdersUpTo.sendTransactionAsync(
orderAddressesArray, orderAddressesArray,
orderValuesArray, orderValuesArray,
fillTakerTokenAmount, fillTakerTokenAmount,
@@ -316,7 +316,7 @@ export class ExchangeWrapper extends ContractWrapper {
); );
const exchangeInstance = await this._getExchangeContractAsync(); const exchangeInstance = await this._getExchangeContractAsync();
const gas = await exchangeInstance.batchFillOrders.estimateGas( const gas = await exchangeInstance.batchFillOrders.estimateGasAsync(
orderAddressesArray, orderAddressesArray,
orderValuesArray, orderValuesArray,
fillTakerTokenAmounts, fillTakerTokenAmounts,
@@ -328,7 +328,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: takerAddress, from: takerAddress,
}, },
); );
const txHash = await exchangeInstance.batchFillOrders( const txHash = await exchangeInstance.batchFillOrders.sendTransactionAsync(
orderAddressesArray, orderAddressesArray,
orderValuesArray, orderValuesArray,
fillTakerTokenAmounts, fillTakerTokenAmounts,
@@ -366,7 +366,7 @@ export class ExchangeWrapper extends ContractWrapper {
const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(signedOrder); const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(signedOrder);
const gas = await exchangeInstance.fillOrKillOrder.estimateGas( const gas = await exchangeInstance.fillOrKillOrder.estimateGasAsync(
orderAddresses, orderAddresses,
orderValues, orderValues,
fillTakerTokenAmount, fillTakerTokenAmount,
@@ -377,7 +377,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: takerAddress, from: takerAddress,
}, },
); );
const txHash = await exchangeInstance.fillOrKillOrder( const txHash = await exchangeInstance.fillOrKillOrder.sendTransactionAsync(
orderAddresses, orderAddresses,
orderValues, orderValues,
fillTakerTokenAmount, fillTakerTokenAmount,
@@ -434,7 +434,7 @@ export class ExchangeWrapper extends ContractWrapper {
const [orderAddresses, orderValues, fillTakerTokenAmounts, vParams, rParams, sParams] = const [orderAddresses, orderValues, fillTakerTokenAmounts, vParams, rParams, sParams] =
_.unzip<any>(orderAddressesValuesAndTakerTokenFillAmounts); _.unzip<any>(orderAddressesValuesAndTakerTokenFillAmounts);
const gas = await exchangeInstance.batchFillOrKillOrders.estimateGas( const gas = await exchangeInstance.batchFillOrKillOrders.estimateGasAsync(
orderAddresses, orderAddresses,
orderValues, orderValues,
fillTakerTokenAmounts, fillTakerTokenAmounts,
@@ -445,7 +445,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: takerAddress, from: takerAddress,
}, },
); );
const txHash = await exchangeInstance.batchFillOrKillOrders( const txHash = await exchangeInstance.batchFillOrKillOrders.sendTransactionAsync(
orderAddresses, orderAddresses,
orderValues, orderValues,
fillTakerTokenAmounts, fillTakerTokenAmounts,
@@ -477,7 +477,7 @@ export class ExchangeWrapper extends ContractWrapper {
await this.validateCancelOrderThrowIfInvalidAsync(order, cancelTakerTokenAmount); await this.validateCancelOrderThrowIfInvalidAsync(order, cancelTakerTokenAmount);
const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(order); const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(order);
const gas = await exchangeInstance.cancelOrder.estimateGas( const gas = await exchangeInstance.cancelOrder.estimateGasAsync(
orderAddresses, orderAddresses,
orderValues, orderValues,
cancelTakerTokenAmount, cancelTakerTokenAmount,
@@ -485,7 +485,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: order.maker, from: order.maker,
}, },
); );
const txHash = await exchangeInstance.cancelOrder( const txHash = await exchangeInstance.cancelOrder.sendTransactionAsync(
orderAddresses, orderAddresses,
orderValues, orderValues,
cancelTakerTokenAmount, cancelTakerTokenAmount,
@@ -535,7 +535,7 @@ export class ExchangeWrapper extends ContractWrapper {
// We use _.unzip<any> because _.unzip doesn't type check if values have different types :'( // We use _.unzip<any> because _.unzip doesn't type check if values have different types :'(
const [orderAddresses, orderValues, cancelTakerTokenAmounts] = const [orderAddresses, orderValues, cancelTakerTokenAmounts] =
_.unzip<any>(orderAddressesValuesAndTakerTokenCancelAmounts); _.unzip<any>(orderAddressesValuesAndTakerTokenCancelAmounts);
const gas = await exchangeInstance.batchCancelOrders.estimateGas( const gas = await exchangeInstance.batchCancelOrders.estimateGasAsync(
orderAddresses, orderAddresses,
orderValues, orderValues,
cancelTakerTokenAmounts, cancelTakerTokenAmounts,
@@ -543,7 +543,7 @@ export class ExchangeWrapper extends ContractWrapper {
from: maker, from: maker,
}, },
); );
const txHash = await exchangeInstance.batchCancelOrders( const txHash = await exchangeInstance.batchCancelOrders.sendTransactionAsync(
orderAddresses, orderAddresses,
orderValues, orderValues,
cancelTakerTokenAmounts, cancelTakerTokenAmounts,
@@ -677,7 +677,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.isBigNumber('takerTokenAmount', takerTokenAmount); assert.isBigNumber('takerTokenAmount', takerTokenAmount);
assert.isBigNumber('makerTokenAmount', makerTokenAmount); assert.isBigNumber('makerTokenAmount', makerTokenAmount);
const exchangeInstance = await this._getExchangeContractAsync(); const exchangeInstance = await this._getExchangeContractAsync();
const isRoundingError = await exchangeInstance.isRoundingError.call( const isRoundingError = await exchangeInstance.isRoundingError.callAsync(
fillTakerTokenAmount, takerTokenAmount, makerTokenAmount, fillTakerTokenAmount, takerTokenAmount, makerTokenAmount,
); );
return isRoundingError; return isRoundingError;
@@ -694,7 +694,7 @@ export class ExchangeWrapper extends ContractWrapper {
const exchangeInstance = await this._getExchangeContractAsync(); const exchangeInstance = await this._getExchangeContractAsync();
const isValidSignature = await exchangeInstance.isValidSignature.call( const isValidSignature = await exchangeInstance.isValidSignature.callAsync(
signerAddressHex, signerAddressHex,
dataHex, dataHex,
ecSignature.v, ecSignature.v,
@@ -706,7 +706,7 @@ export class ExchangeWrapper extends ContractWrapper {
private async _getOrderHashHexUsingContractCallAsync(order: Order|SignedOrder): Promise<string> { private async _getOrderHashHexUsingContractCallAsync(order: Order|SignedOrder): Promise<string> {
const exchangeInstance = await this._getExchangeContractAsync(); const exchangeInstance = await this._getExchangeContractAsync();
const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(order); const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(order);
const orderHashHex = await exchangeInstance.getOrderHash.call(orderAddresses, orderValues); const orderHashHex = await exchangeInstance.getOrderHash.callAsync(orderAddresses, orderValues);
return orderHashHex; return orderHashHex;
} }
private _throwErrorLogsAsErrors(logs: ContractEvent[]): void { private _throwErrorLogsAsErrors(logs: ContractEvent[]): void {
@@ -729,7 +729,7 @@ export class ExchangeWrapper extends ContractWrapper {
} }
private async _getZRXTokenAddressAsync(): Promise<string> { private async _getZRXTokenAddressAsync(): Promise<string> {
const exchangeInstance = await this._getExchangeContractAsync(); const exchangeInstance = await this._getExchangeContractAsync();
const ZRXtokenAddress = await exchangeInstance.ZRX_TOKEN_CONTRACT.call(); const ZRXtokenAddress = await exchangeInstance.ZRX_TOKEN_CONTRACT.callAsync();
return ZRXtokenAddress; return ZRXtokenAddress;
} }
} }

View File

@@ -35,7 +35,7 @@ export class TokenRegistryWrapper extends ContractWrapper {
*/ */
public async getTokenAddressesAsync(): Promise<string[]> { public async getTokenAddressesAsync(): Promise<string[]> {
const tokenRegistryContract = await this._getTokenRegistryContractAsync(); const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const addresses = await tokenRegistryContract.getTokenAddresses.call(); const addresses = await tokenRegistryContract.getTokenAddresses.callAsync();
return addresses; return addresses;
} }
/** /**
@@ -46,14 +46,14 @@ export class TokenRegistryWrapper extends ContractWrapper {
assert.isETHAddressHex('address', address); assert.isETHAddressHex('address', address);
const tokenRegistryContract = await this._getTokenRegistryContractAsync(); const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const metadata = await tokenRegistryContract.getTokenMetaData.call(address); const metadata = await tokenRegistryContract.getTokenMetaData.callAsync(address);
const token = this._createTokenFromMetadata(metadata); const token = this._createTokenFromMetadata(metadata);
return token; return token;
} }
public async getTokenAddressBySymbolIfExistsAsync(symbol: string): Promise<string|undefined> { public async getTokenAddressBySymbolIfExistsAsync(symbol: string): Promise<string|undefined> {
assert.isString('symbol', symbol); assert.isString('symbol', symbol);
const tokenRegistryContract = await this._getTokenRegistryContractAsync(); const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const addressIfExists = await tokenRegistryContract.getTokenAddressBySymbol.call(symbol); const addressIfExists = await tokenRegistryContract.getTokenAddressBySymbol.callAsync(symbol);
if (addressIfExists === constants.NULL_ADDRESS) { if (addressIfExists === constants.NULL_ADDRESS) {
return undefined; return undefined;
} }
@@ -62,7 +62,7 @@ export class TokenRegistryWrapper extends ContractWrapper {
public async getTokenAddressByNameIfExistsAsync(name: string): Promise<string|undefined> { public async getTokenAddressByNameIfExistsAsync(name: string): Promise<string|undefined> {
assert.isString('name', name); assert.isString('name', name);
const tokenRegistryContract = await this._getTokenRegistryContractAsync(); const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const addressIfExists = await tokenRegistryContract.getTokenAddressByName.call(name); const addressIfExists = await tokenRegistryContract.getTokenAddressByName.callAsync(name);
if (addressIfExists === constants.NULL_ADDRESS) { if (addressIfExists === constants.NULL_ADDRESS) {
return undefined; return undefined;
} }
@@ -71,14 +71,14 @@ export class TokenRegistryWrapper extends ContractWrapper {
public async getTokenBySymbolIfExistsAsync(symbol: string): Promise<Token|undefined> { public async getTokenBySymbolIfExistsAsync(symbol: string): Promise<Token|undefined> {
assert.isString('symbol', symbol); assert.isString('symbol', symbol);
const tokenRegistryContract = await this._getTokenRegistryContractAsync(); const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const metadata = await tokenRegistryContract.getTokenBySymbol.call(symbol); const metadata = await tokenRegistryContract.getTokenBySymbol.callAsync(symbol);
const token = this._createTokenFromMetadata(metadata); const token = this._createTokenFromMetadata(metadata);
return token; return token;
} }
public async getTokenByNameIfExistsAsync(name: string): Promise<Token|undefined> { public async getTokenByNameIfExistsAsync(name: string): Promise<Token|undefined> {
assert.isString('name', name); assert.isString('name', name);
const tokenRegistryContract = await this._getTokenRegistryContractAsync(); const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const metadata = await tokenRegistryContract.getTokenByName.call(name); const metadata = await tokenRegistryContract.getTokenByName.callAsync(name);
const token = this._createTokenFromMetadata(metadata); const token = this._createTokenFromMetadata(metadata);
return token; return token;
} }

View File

@@ -15,7 +15,7 @@ export class TokenTransferProxyWrapper extends ContractWrapper {
*/ */
public async isAuthorizedAsync(exchangeContractAddress: string): Promise<boolean> { public async isAuthorizedAsync(exchangeContractAddress: string): Promise<boolean> {
const tokenTransferProxyContractInstance = await this._getTokenTransferProxyContractAsync(); const tokenTransferProxyContractInstance = await this._getTokenTransferProxyContractAsync();
const isAuthorized = await tokenTransferProxyContractInstance.authorized.call(exchangeContractAddress); const isAuthorized = await tokenTransferProxyContractInstance.authorized.callAsync(exchangeContractAddress);
return isAuthorized; return isAuthorized;
} }
/** /**
@@ -24,7 +24,7 @@ export class TokenTransferProxyWrapper extends ContractWrapper {
*/ */
public async getAuthorizedAddressesAsync(): Promise<string[]> { public async getAuthorizedAddressesAsync(): Promise<string[]> {
const tokenTransferProxyContractInstance = await this._getTokenTransferProxyContractAsync(); const tokenTransferProxyContractInstance = await this._getTokenTransferProxyContractAsync();
const authorizedAddresses = await tokenTransferProxyContractInstance.getAuthorizedAddresses.call(); const authorizedAddresses = await tokenTransferProxyContractInstance.getAuthorizedAddresses.callAsync();
return authorizedAddresses; return authorizedAddresses;
} }
/** /**

View File

@@ -47,7 +47,7 @@ export class TokenWrapper extends ContractWrapper {
assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isETHAddressHex('tokenAddress', tokenAddress);
const tokenContract = await this._getTokenContractAsync(tokenAddress); const tokenContract = await this._getTokenContractAsync(tokenAddress);
let balance = await tokenContract.balanceOf.call(ownerAddress); let balance = await tokenContract.balanceOf.callAsync(ownerAddress);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
balance = new BigNumber(balance); balance = new BigNumber(balance);
return balance; return balance;
@@ -75,7 +75,7 @@ export class TokenWrapper extends ContractWrapper {
// TODO: Debug issue in testrpc and submit a PR, then remove this hack // TODO: Debug issue in testrpc and submit a PR, then remove this hack
const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync();
const gas = networkIdIfExists === constants.TESTRPC_NETWORK_ID ? ALLOWANCE_TO_ZERO_GAS_AMOUNT : undefined; const gas = networkIdIfExists === constants.TESTRPC_NETWORK_ID ? ALLOWANCE_TO_ZERO_GAS_AMOUNT : undefined;
const txHash = await tokenContract.approve(spenderAddress, amountInBaseUnits, { const txHash = await tokenContract.approve.sendTransactionAsync(spenderAddress, amountInBaseUnits, {
from: ownerAddress, from: ownerAddress,
gas, gas,
}); });
@@ -112,7 +112,7 @@ export class TokenWrapper extends ContractWrapper {
assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isETHAddressHex('tokenAddress', tokenAddress);
const tokenContract = await this._getTokenContractAsync(tokenAddress); const tokenContract = await this._getTokenContractAsync(tokenAddress);
let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, spenderAddress); let allowanceInBaseUnits = await tokenContract.allowance.callAsync(ownerAddress, spenderAddress);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
allowanceInBaseUnits = new BigNumber(allowanceInBaseUnits); allowanceInBaseUnits = new BigNumber(allowanceInBaseUnits);
return allowanceInBaseUnits; return allowanceInBaseUnits;
@@ -187,7 +187,7 @@ export class TokenWrapper extends ContractWrapper {
throw new Error(ZeroExError.InsufficientBalanceForTransfer); throw new Error(ZeroExError.InsufficientBalanceForTransfer);
} }
const txHash = await tokenContract.transfer(toAddress, amountInBaseUnits, { const txHash = await tokenContract.transfer.sendTransactionAsync(toAddress, amountInBaseUnits, {
from: fromAddress, from: fromAddress,
}); });
return txHash; return txHash;
@@ -226,9 +226,12 @@ export class TokenWrapper extends ContractWrapper {
throw new Error(ZeroExError.InsufficientBalanceForTransfer); throw new Error(ZeroExError.InsufficientBalanceForTransfer);
} }
const txHash = await tokenContract.transferFrom(fromAddress, toAddress, amountInBaseUnits, { const txHash = await tokenContract.transferFrom.sendTransactionAsync(
from: senderAddress, fromAddress, toAddress, amountInBaseUnits,
}); {
from: senderAddress,
},
);
return txHash; return txHash;
} }
/** /**

View File

@@ -42,85 +42,90 @@ export type CreateContractEvent = (indexFilterValues: IndexedFilterValues,
subscriptionOpts: SubscriptionOpts) => ContractEventObj; subscriptionOpts: SubscriptionOpts) => ContractEventObj;
export interface ExchangeContract extends Web3.ContractInstance { export interface ExchangeContract extends Web3.ContractInstance {
isValidSignature: { isValidSignature: {
call: (signerAddressHex: string, dataHex: string, v: number, r: string, s: string, callAsync: (signerAddressHex: string, dataHex: string, v: number, r: string, s: string,
txOpts?: TxOpts) => Promise<boolean>; txOpts?: TxOpts) => Promise<boolean>;
}; };
LogFill: CreateContractEvent; LogFill: CreateContractEvent;
LogCancel: CreateContractEvent; LogCancel: CreateContractEvent;
LogError: CreateContractEvent; LogError: CreateContractEvent;
ZRX_TOKEN_CONTRACT: { ZRX_TOKEN_CONTRACT: {
call: () => Promise<string>; callAsync: () => Promise<string>;
}; };
getUnavailableTakerTokenAmount: { getUnavailableTakerTokenAmount: {
call: (orderHash: string) => Promise<BigNumber.BigNumber>; callAsync: (orderHash: string) => Promise<BigNumber.BigNumber>;
}; };
isRoundingError: { isRoundingError: {
call: (fillTakerAmount: BigNumber.BigNumber, takerTokenAmount: BigNumber.BigNumber, callAsync: (fillTakerAmount: BigNumber.BigNumber, takerTokenAmount: BigNumber.BigNumber,
makerTokenAmount: BigNumber.BigNumber, txOpts?: TxOpts) => Promise<boolean>; makerTokenAmount: BigNumber.BigNumber, txOpts?: TxOpts) => Promise<boolean>;
}; };
fillOrder: { fillOrder: {
(orderAddresses: OrderAddresses, orderValues: OrderValues, fillTakerTokenAmount: BigNumber.BigNumber, sendTransactionAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues,
shouldThrowOnInsufficientBalanceOrAllowance: boolean, fillTakerTokenAmount: BigNumber.BigNumber,
v: number, r: string, s: string, txOpts?: TxOpts): Promise<string>; shouldThrowOnInsufficientBalanceOrAllowance: boolean,
estimateGas: (orderAddresses: OrderAddresses, orderValues: OrderValues, v: number, r: string, s: string, txOpts?: TxOpts) => Promise<string>;
fillTakerTokenAmount: BigNumber.BigNumber, estimateGasAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues,
shouldThrowOnInsufficientBalanceOrAllowance: boolean, fillTakerTokenAmount: BigNumber.BigNumber,
v: number, r: string, s: string, txOpts?: TxOpts) => Promise<number>; shouldThrowOnInsufficientBalanceOrAllowance: boolean,
v: number, r: string, s: string, txOpts?: TxOpts) => Promise<number>;
}; };
batchFillOrders: { batchFillOrders: {
(orderAddresses: OrderAddresses[], orderValues: OrderValues[], fillTakerTokenAmounts: BigNumber.BigNumber[], sendTransactionAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
shouldThrowOnInsufficientBalanceOrAllowance: boolean, fillTakerTokenAmounts: BigNumber.BigNumber[],
v: number[], r: string[], s: string[], txOpts?: TxOpts): Promise<string>; shouldThrowOnInsufficientBalanceOrAllowance: boolean,
estimateGas: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise<string>;
fillTakerTokenAmounts: BigNumber.BigNumber[], estimateGasAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
shouldThrowOnInsufficientBalanceOrAllowance: boolean, fillTakerTokenAmounts: BigNumber.BigNumber[],
v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise<number>; shouldThrowOnInsufficientBalanceOrAllowance: boolean,
v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise<number>;
}; };
fillOrdersUpTo: { fillOrdersUpTo: {
(orderAddresses: OrderAddresses[], orderValues: OrderValues[], fillTakerTokenAmount: BigNumber.BigNumber, sendTransactionAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
shouldThrowOnInsufficientBalanceOrAllowance: boolean, fillTakerTokenAmount: BigNumber.BigNumber,
v: number[], r: string[], s: string[], txOpts?: TxOpts): Promise<string>; shouldThrowOnInsufficientBalanceOrAllowance: boolean,
estimateGas: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise<string>;
fillTakerTokenAmount: BigNumber.BigNumber, estimateGasAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
shouldThrowOnInsufficientBalanceOrAllowance: boolean, fillTakerTokenAmount: BigNumber.BigNumber,
v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise<number>; shouldThrowOnInsufficientBalanceOrAllowance: boolean,
v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise<number>;
}; };
cancelOrder: { cancelOrder: {
(orderAddresses: OrderAddresses, orderValues: OrderValues, cancelTakerTokenAmount: BigNumber.BigNumber, sendTransactionAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues,
txOpts?: TxOpts): Promise<string>; cancelTakerTokenAmount: BigNumber.BigNumber, txOpts?: TxOpts) => Promise<string>;
estimateGas: (orderAddresses: OrderAddresses, orderValues: OrderValues, estimateGasAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues,
cancelTakerTokenAmount: BigNumber.BigNumber, cancelTakerTokenAmount: BigNumber.BigNumber,
txOpts?: TxOpts) => Promise<number>; txOpts?: TxOpts) => Promise<number>;
}; };
batchCancelOrders: { batchCancelOrders: {
(orderAddresses: OrderAddresses[], orderValues: OrderValues[], cancelTakerTokenAmounts: BigNumber.BigNumber[], sendTransactionAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
txOpts?: TxOpts): Promise<string>; cancelTakerTokenAmounts: BigNumber.BigNumber[], txOpts?: TxOpts) => Promise<string>;
estimateGas: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], estimateGasAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
cancelTakerTokenAmounts: BigNumber.BigNumber[], cancelTakerTokenAmounts: BigNumber.BigNumber[],
txOpts?: TxOpts) => Promise<number>; txOpts?: TxOpts) => Promise<number>;
}; };
fillOrKillOrder: { fillOrKillOrder: {
(orderAddresses: OrderAddresses, orderValues: OrderValues, fillTakerTokenAmount: BigNumber.BigNumber, sendTransactionAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues,
v: number, r: string, s: string, txOpts?: TxOpts): Promise<string>; fillTakerTokenAmount: BigNumber.BigNumber,
estimateGas: (orderAddresses: OrderAddresses, orderValues: OrderValues, v: number, r: string, s: string, txOpts?: TxOpts) => Promise<string>;
fillTakerTokenAmount: BigNumber.BigNumber, estimateGasAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues,
v: number, r: string, s: string, txOpts?: TxOpts) => Promise<number>; fillTakerTokenAmount: BigNumber.BigNumber,
v: number, r: string, s: string, txOpts?: TxOpts) => Promise<number>;
}; };
batchFillOrKillOrders: { batchFillOrKillOrders: {
(orderAddresses: OrderAddresses[], orderValues: OrderValues[], fillTakerTokenAmounts: BigNumber.BigNumber[], sendTransactionAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
v: number[], r: string[], s: string[], txOpts: TxOpts): Promise<string>; fillTakerTokenAmounts: BigNumber.BigNumber[],
estimateGas: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], v: number[], r: string[], s: string[], txOpts: TxOpts) => Promise<string>;
fillTakerTokenAmounts: BigNumber.BigNumber[], estimateGasAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[],
v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise<number>; fillTakerTokenAmounts: BigNumber.BigNumber[],
v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise<number>;
}; };
filled: { filled: {
call: (orderHash: string) => Promise<BigNumber.BigNumber>; callAsync: (orderHash: string) => Promise<BigNumber.BigNumber>;
}; };
cancelled: { cancelled: {
call: (orderHash: string) => Promise<BigNumber.BigNumber>; callAsync: (orderHash: string) => Promise<BigNumber.BigNumber>;
}; };
getOrderHash: { getOrderHash: {
call: (orderAddresses: OrderAddresses, orderValues: OrderValues) => Promise<string>; callAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues) => Promise<string>;
}; };
} }
@@ -128,49 +133,61 @@ export interface TokenContract extends Web3.ContractInstance {
Transfer: CreateContractEvent; Transfer: CreateContractEvent;
Approval: CreateContractEvent; Approval: CreateContractEvent;
balanceOf: { balanceOf: {
call: (address: string) => Promise<BigNumber.BigNumber>; callAsync: (address: string) => Promise<BigNumber.BigNumber>;
}; };
allowance: { allowance: {
call: (ownerAddress: string, allowedAddress: string) => Promise<BigNumber.BigNumber>; callAsync: (ownerAddress: string, allowedAddress: string) => Promise<BigNumber.BigNumber>;
};
transfer: {
sendTransactionAsync: (toAddress: string, amountInBaseUnits: BigNumber.BigNumber,
txOpts?: TxOpts) => Promise<string>;
};
transferFrom: {
sendTransactionAsync: (fromAddress: string, toAddress: string, amountInBaseUnits: BigNumber.BigNumber,
txOpts?: TxOpts) => Promise<string>;
};
approve: {
sendTransactionAsync: (proxyAddress: string, amountInBaseUnits: BigNumber.BigNumber,
txOpts?: TxOpts) => Promise<string>;
}; };
transfer: (toAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts?: TxOpts) => Promise<string>;
transferFrom: (fromAddress: string, toAddress: string, amountInBaseUnits: BigNumber.BigNumber,
txOpts?: TxOpts) => Promise<string>;
approve: (proxyAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts?: TxOpts) => Promise<string>;
} }
export interface TokenRegistryContract extends Web3.ContractInstance { export interface TokenRegistryContract extends Web3.ContractInstance {
getTokenMetaData: { getTokenMetaData: {
call: (address: string) => Promise<TokenMetadata>; callAsync: (address: string) => Promise<TokenMetadata>;
}; };
getTokenAddresses: { getTokenAddresses: {
call: () => Promise<string[]>; callAsync: () => Promise<string[]>;
}; };
getTokenAddressBySymbol: { getTokenAddressBySymbol: {
call: (symbol: string) => Promise<string>; callAsync: (symbol: string) => Promise<string>;
}; };
getTokenAddressByName: { getTokenAddressByName: {
call: (name: string) => Promise<string>; callAsync: (name: string) => Promise<string>;
}; };
getTokenBySymbol: { getTokenBySymbol: {
call: (symbol: string) => Promise<TokenMetadata>; callAsync: (symbol: string) => Promise<TokenMetadata>;
}; };
getTokenByName: { getTokenByName: {
call: (name: string) => Promise<TokenMetadata>; callAsync: (name: string) => Promise<TokenMetadata>;
}; };
} }
export interface EtherTokenContract extends Web3.ContractInstance { export interface EtherTokenContract extends Web3.ContractInstance {
deposit: (txOpts: TxOpts) => Promise<string>; deposit: {
withdraw: (amount: BigNumber.BigNumber, txOpts: TxOpts) => Promise<string>; sendTransactionAsync: (txOpts: TxOpts) => Promise<string>;
};
withdraw: {
sendTransactionAsync: (amount: BigNumber.BigNumber, txOpts: TxOpts) => Promise<string>;
};
} }
export interface TokenTransferProxyContract extends Web3.ContractInstance { export interface TokenTransferProxyContract extends Web3.ContractInstance {
getAuthorizedAddresses: { getAuthorizedAddresses: {
call: () => Promise<string[]>; callAsync: () => Promise<string[]>;
}; };
authorized: { authorized: {
call: (address: string) => Promise<boolean>; callAsync: (address: string) => Promise<boolean>;
}; };
} }