aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src/order_validation_utils.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-08-04 03:27:01 +0800
committerFabio Berger <me@fabioberger.com>2018-08-04 03:27:01 +0800
commit343cd05363166a7a93fca361d5547b39f3e83d99 (patch)
treeae1eafee9070a4f712faa19e10f3ac5894f9d954 /packages/order-utils/src/order_validation_utils.ts
parentd9f09b5e1e7ecc8dc56ac7184cfc0152b3c2ff32 (diff)
downloaddexon-sol-tools-343cd05363166a7a93fca361d5547b39f3e83d99.tar
dexon-sol-tools-343cd05363166a7a93fca361d5547b39f3e83d99.tar.gz
dexon-sol-tools-343cd05363166a7a93fca361d5547b39f3e83d99.tar.bz2
dexon-sol-tools-343cd05363166a7a93fca361d5547b39f3e83d99.tar.lz
dexon-sol-tools-343cd05363166a7a93fca361d5547b39f3e83d99.tar.xz
dexon-sol-tools-343cd05363166a7a93fca361d5547b39f3e83d99.tar.zst
dexon-sol-tools-343cd05363166a7a93fca361d5547b39f3e83d99.zip
Add missing comments
Diffstat (limited to 'packages/order-utils/src/order_validation_utils.ts')
-rw-r--r--packages/order-utils/src/order_validation_utils.ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/packages/order-utils/src/order_validation_utils.ts b/packages/order-utils/src/order_validation_utils.ts
index ccc6e653f..972e6f6d6 100644
--- a/packages/order-utils/src/order_validation_utils.ts
+++ b/packages/order-utils/src/order_validation_utils.ts
@@ -12,8 +12,18 @@ import { orderHashUtils } from './order_hash';
import { signatureUtils } from './signature_utils';
import { utils } from './utils';
+/**
+ * A utility class for validating orders
+ */
export class OrderValidationUtils {
private readonly _orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher;
+ /**
+ * A Typescript implementation mirroring the implementation of isRoundingError in the
+ * Exchange smart contract
+ * @param numerator Numerator value. When used to check an order, pass in `takerAssetFilledAmount`
+ * @param denominator Denominator value. When used to check an order, pass in `order.takerAssetAmount`
+ * @param target Target value. When used to check an order, pass in `order.makerAssetAmount`
+ */
public static isRoundingError(numerator: BigNumber, denominator: BigNumber, target: BigNumber): boolean {
// Solidity's mulmod() in JS
// Source: https://solidity.readthedocs.io/en/latest/units-and-global-variables.html#mathematical-and-cryptographic-functions
@@ -31,6 +41,15 @@ export class OrderValidationUtils {
const isError = errPercentageTimes1000000.gt(1000);
return isError;
}
+ /**
+ * Validate that the maker & taker have sufficient balances/allowances
+ * to fill the supplied order to the fillTakerAssetAmount amount
+ * @param exchangeTradeEmulator ExchangeTradeEmulator to use
+ * @param signedOrder SignedOrder to test
+ * @param fillTakerAssetAmount Amount of takerAsset to fill the signedOrder
+ * @param senderAddress Sender of the fillOrder tx
+ * @param zrxAssetData AssetData for the ZRX token
+ */
public static async validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
exchangeTradeEmulator: ExchangeTransferSimulator,
signedOrder: SignedOrder,
@@ -104,9 +123,22 @@ export class OrderValidationUtils {
throw new Error(RevertReason.OrderUnfillable);
}
}
+ /**
+ * Instantiate OrderValidationUtils
+ * @param orderFilledCancelledFetcher A module that implements the AbstractOrderFilledCancelledFetcher
+ * @return An instance of OrderValidationUtils
+ */
constructor(orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher) {
this._orderFilledCancelledFetcher = orderFilledCancelledFetcher;
}
+ /**
+ * Validate if the supplied order is fillable, and throw if it isn't
+ * @param exchangeTradeEmulator ExchangeTradeEmulator instance
+ * @param signedOrder SignedOrder of interest
+ * @param zrxAssetData ZRX assetData
+ * @param expectedFillTakerTokenAmount If supplied, this call will make sure this amount is fillable.
+ * If it isn't supplied, we check if the order is fillable for a non-zero amount
+ */
public async validateOrderFillableOrThrowAsync(
exchangeTradeEmulator: ExchangeTransferSimulator,
signedOrder: SignedOrder,
@@ -132,6 +164,15 @@ export class OrderValidationUtils {
zrxAssetData,
);
}
+ /**
+ * Validate a call to FillOrder and throw if it wouldn't succeed
+ * @param exchangeTradeEmulator ExchangeTradeEmulator to use
+ * @param provider Web3 provider to use for JSON RPC requests
+ * @param signedOrder SignedOrder of interest
+ * @param fillTakerAssetAmount Amount we'd like to fill the order for
+ * @param takerAddress The taker of the order
+ * @param zrxAssetData ZRX asset data
+ */
public async validateFillOrderThrowIfInvalidAsync(
exchangeTradeEmulator: ExchangeTransferSimulator,
provider: Provider,
@@ -187,6 +228,15 @@ export class OrderValidationUtils {
}
return filledTakerTokenAmount;
}
+ /**
+ * Validate a call to fillOrKillOrder and throw if it would fail
+ * @param exchangeTradeEmulator ExchangeTradeEmulator to use
+ * @param provider Web3 provider to use for JSON RPC requests
+ * @param signedOrder SignedOrder of interest
+ * @param fillTakerAssetAmount Amount we'd like to fill the order for
+ * @param takerAddress The taker of the order
+ * @param zrxAssetData ZRX asset data
+ */
public async validateFillOrKillOrderThrowIfInvalidAsync(
exchangeTradeEmulator: ExchangeTransferSimulator,
provider: Provider,