aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-11-10 01:50:25 +0800
committerFabio Berger <me@fabioberger.com>2018-11-10 01:50:25 +0800
commit3980bf39a9ae8cb5b5cc3cbc33b6e84d1bcf6c28 (patch)
tree2cf26ce183b0d4924fa60d2db20535a5480503da /packages/order-utils
parenteb5f514d25e9392a9226cb778e94c5d7dd6e47f7 (diff)
downloaddexon-sol-tools-3980bf39a9ae8cb5b5cc3cbc33b6e84d1bcf6c28.tar
dexon-sol-tools-3980bf39a9ae8cb5b5cc3cbc33b6e84d1bcf6c28.tar.gz
dexon-sol-tools-3980bf39a9ae8cb5b5cc3cbc33b6e84d1bcf6c28.tar.bz2
dexon-sol-tools-3980bf39a9ae8cb5b5cc3cbc33b6e84d1bcf6c28.tar.lz
dexon-sol-tools-3980bf39a9ae8cb5b5cc3cbc33b6e84d1bcf6c28.tar.xz
dexon-sol-tools-3980bf39a9ae8cb5b5cc3cbc33b6e84d1bcf6c28.tar.zst
dexon-sol-tools-3980bf39a9ae8cb5b5cc3cbc33b6e84d1bcf6c28.zip
Keep more helpful error messages, and stop swallowing errors when returning contract error
Diffstat (limited to 'packages/order-utils')
-rw-r--r--packages/order-utils/src/order_validation_utils.ts131
1 files changed, 72 insertions, 59 deletions
diff --git a/packages/order-utils/src/order_validation_utils.ts b/packages/order-utils/src/order_validation_utils.ts
index 0af82f5cc..345e9099e 100644
--- a/packages/order-utils/src/order_validation_utils.ts
+++ b/packages/order-utils/src/order_validation_utils.ts
@@ -1,4 +1,4 @@
-import { RevertReason, SignedOrder } from '@0x/types';
+import { ExchangeContractErrs, RevertReason, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { Provider } from 'ethereum-types';
import * as _ from 'lodash';
@@ -57,57 +57,53 @@ export class OrderValidationUtils {
senderAddress: string,
zrxAssetData: string,
): Promise<void> {
- try {
- const fillMakerTokenAmount = utils.getPartialAmountFloor(
- fillTakerAssetAmount,
- signedOrder.takerAssetAmount,
- signedOrder.makerAssetAmount,
- );
- await exchangeTradeEmulator.transferFromAsync(
- signedOrder.makerAssetData,
- signedOrder.makerAddress,
- senderAddress,
- fillMakerTokenAmount,
- TradeSide.Maker,
- TransferType.Trade,
- );
- await exchangeTradeEmulator.transferFromAsync(
- signedOrder.takerAssetData,
- senderAddress,
- signedOrder.makerAddress,
- fillTakerAssetAmount,
- TradeSide.Taker,
- TransferType.Trade,
- );
- const makerFeeAmount = utils.getPartialAmountFloor(
- fillTakerAssetAmount,
- signedOrder.takerAssetAmount,
- signedOrder.makerFee,
- );
- await exchangeTradeEmulator.transferFromAsync(
- zrxAssetData,
- signedOrder.makerAddress,
- signedOrder.feeRecipientAddress,
- makerFeeAmount,
- TradeSide.Maker,
- TransferType.Fee,
- );
- const takerFeeAmount = utils.getPartialAmountFloor(
- fillTakerAssetAmount,
- signedOrder.takerAssetAmount,
- signedOrder.takerFee,
- );
- await exchangeTradeEmulator.transferFromAsync(
- zrxAssetData,
- senderAddress,
- signedOrder.feeRecipientAddress,
- takerFeeAmount,
- TradeSide.Taker,
- TransferType.Fee,
- );
- } catch (err) {
- throw new Error(RevertReason.TransferFailed);
- }
+ const fillMakerTokenAmount = utils.getPartialAmountFloor(
+ fillTakerAssetAmount,
+ signedOrder.takerAssetAmount,
+ signedOrder.makerAssetAmount,
+ );
+ await exchangeTradeEmulator.transferFromAsync(
+ signedOrder.makerAssetData,
+ signedOrder.makerAddress,
+ senderAddress,
+ fillMakerTokenAmount,
+ TradeSide.Maker,
+ TransferType.Trade,
+ );
+ await exchangeTradeEmulator.transferFromAsync(
+ signedOrder.takerAssetData,
+ senderAddress,
+ signedOrder.makerAddress,
+ fillTakerAssetAmount,
+ TradeSide.Taker,
+ TransferType.Trade,
+ );
+ const makerFeeAmount = utils.getPartialAmountFloor(
+ fillTakerAssetAmount,
+ signedOrder.takerAssetAmount,
+ signedOrder.makerFee,
+ );
+ await exchangeTradeEmulator.transferFromAsync(
+ zrxAssetData,
+ signedOrder.makerAddress,
+ signedOrder.feeRecipientAddress,
+ makerFeeAmount,
+ TradeSide.Maker,
+ TransferType.Fee,
+ );
+ const takerFeeAmount = utils.getPartialAmountFloor(
+ fillTakerAssetAmount,
+ signedOrder.takerAssetAmount,
+ signedOrder.takerFee,
+ );
+ await exchangeTradeEmulator.transferFromAsync(
+ zrxAssetData,
+ senderAddress,
+ signedOrder.feeRecipientAddress,
+ takerFeeAmount,
+ TradeSide.Taker,
+ TransferType.Fee,
+ );
}
private static _validateOrderNotExpiredOrThrow(expirationTimeSeconds: BigNumber): void {
const currentUnixTimestampSec = utils.getCurrentUnixTimestampSec();
@@ -211,13 +207,30 @@ export class OrderValidationUtils {
const desiredFillTakerTokenAmount = remainingTakerTokenAmount.lessThan(fillTakerAssetAmount)
? remainingTakerTokenAmount
: fillTakerAssetAmount;
- await OrderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
- exchangeTradeEmulator,
- signedOrder,
- desiredFillTakerTokenAmount,
- takerAddress,
- zrxAssetData,
- );
+ try {
+ await OrderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
+ exchangeTradeEmulator,
+ signedOrder,
+ desiredFillTakerTokenAmount,
+ takerAddress,
+ zrxAssetData,
+ );
+ } catch (err) {
+ const transferFailedErrorMessages = [
+ ExchangeContractErrs.InsufficientMakerBalance,
+ ExchangeContractErrs.InsufficientMakerFeeBalance,
+ ExchangeContractErrs.InsufficientTakerBalance,
+ ExchangeContractErrs.InsufficientTakerFeeBalance,
+ ExchangeContractErrs.InsufficientMakerAllowance,
+ ExchangeContractErrs.InsufficientMakerFeeAllowance,
+ ExchangeContractErrs.InsufficientTakerAllowance,
+ ExchangeContractErrs.InsufficientTakerFeeAllowance,
+ ];
+ if (_.includes(transferFailedErrorMessages, err.message)) {
+ throw new Error(RevertReason.TransferFailed);
+ }
+ throw err;
+ }
const wouldRoundingErrorOccur = OrderValidationUtils.isRoundingErrorFloor(
desiredFillTakerTokenAmount,