aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-08-14 08:45:50 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-08-14 08:46:43 +0800
commitd8593998414aa3234533b8fa868b05495ac54457 (patch)
treed4d2fd9d4b5f108401b7136288604f841ae472f8 /packages/order-utils/src
parentab64ea7377b4cd0a0a7e3ec219f958037c5fabbe (diff)
downloaddexon-sol-tools-d8593998414aa3234533b8fa868b05495ac54457.tar
dexon-sol-tools-d8593998414aa3234533b8fa868b05495ac54457.tar.gz
dexon-sol-tools-d8593998414aa3234533b8fa868b05495ac54457.tar.bz2
dexon-sol-tools-d8593998414aa3234533b8fa868b05495ac54457.tar.lz
dexon-sol-tools-d8593998414aa3234533b8fa868b05495ac54457.tar.xz
dexon-sol-tools-d8593998414aa3234533b8fa868b05495ac54457.tar.zst
dexon-sol-tools-d8593998414aa3234533b8fa868b05495ac54457.zip
Change rateUtils to use Order
Diffstat (limited to 'packages/order-utils/src')
-rw-r--r--packages/order-utils/src/rate_utils.ts40
1 files changed, 20 insertions, 20 deletions
diff --git a/packages/order-utils/src/rate_utils.ts b/packages/order-utils/src/rate_utils.ts
index e82c03873..c9ca72c59 100644
--- a/packages/order-utils/src/rate_utils.ts
+++ b/packages/order-utils/src/rate_utils.ts
@@ -1,5 +1,5 @@
import { schemas } from '@0xproject/json-schemas';
-import { SignedOrder } from '@0xproject/types';
+import { Order } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { assert } from './assert';
@@ -7,42 +7,42 @@ import { constants } from './constants';
export const rateUtils = {
/**
- * Takes a signed order and calculates the fee adjusted rate (takerAsset/makerAsset) by calculating how much takerAsset
+ * Takes an order and calculates the fee adjusted rate (takerAsset/makerAsset) by calculating how much takerAsset
* is required to cover the fees (feeRate * takerFee), adding the takerAssetAmount and dividing by makerAssetAmount
- * @param signedOrder An object that conforms to the signedOrder interface
- * @param feeRate The market rate of ZRX denominated in takerAssetAmount
- * (ex. feeRate is 0.1 takerAsset/ZRX if it takes 1 unit of takerAsset to buy 10 ZRX)
- * Defaults to 0
+ * @param order An object that conforms to the order interface
+ * @param feeRate The market rate of ZRX denominated in takerAssetAmount
+ * (ex. feeRate is 0.1 takerAsset/ZRX if it takes 1 unit of takerAsset to buy 10 ZRX)
+ * Defaults to 0
* @return The rate (takerAsset/makerAsset) of the order adjusted for fees
*/
- getFeeAdjustedRateOfOrder(signedOrder: SignedOrder, feeRate: BigNumber = constants.ZERO_AMOUNT): BigNumber {
- assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
+ getFeeAdjustedRateOfOrder(order: Order, feeRate: BigNumber = constants.ZERO_AMOUNT): BigNumber {
+ assert.doesConformToSchema('order', order, schemas.orderSchema);
assert.isBigNumber('feeRate', feeRate);
assert.assert(
feeRate.gte(constants.ZERO_AMOUNT),
`Expected feeRate: ${feeRate} to be greater than or equal to 0`,
);
- const takerAssetAmountNeededToPayForFees = signedOrder.takerFee.mul(feeRate);
- const totalTakerAssetAmount = takerAssetAmountNeededToPayForFees.plus(signedOrder.takerAssetAmount);
- const rate = totalTakerAssetAmount.div(signedOrder.makerAssetAmount);
+ const takerAssetAmountNeededToPayForFees = order.takerFee.mul(feeRate);
+ const totalTakerAssetAmount = takerAssetAmountNeededToPayForFees.plus(order.takerAssetAmount);
+ const rate = totalTakerAssetAmount.div(order.makerAssetAmount);
return rate;
},
/**
- * Takes a signed fee order (makerAssetData corresponds to ZRX and takerAssetData corresponds to WETH) and calculates
+ * Takes a fee order (makerAssetData corresponds to ZRX and takerAssetData corresponds to WETH) and calculates
* the fee adjusted rate (WETH/ZRX) by dividing the takerAssetAmount by the makerAmount minus the takerFee
- * @param signedFeeOrder An object that conforms to the signedOrder interface
+ * @param feeOrder An object that conforms to the order interface
* @return The rate (WETH/ZRX) of the fee order adjusted for fees
*/
- getFeeAdjustedRateOfFeeOrder(signedFeeOrder: SignedOrder): BigNumber {
- assert.doesConformToSchema('signedFeeOrder', signedFeeOrder, schemas.signedOrderSchema);
- const zrxAmountAfterFees = signedFeeOrder.makerAssetAmount.sub(signedFeeOrder.takerFee);
+ getFeeAdjustedRateOfFeeOrder(feeOrder: Order): BigNumber {
+ assert.doesConformToSchema('feeOrder', feeOrder, schemas.orderSchema);
+ const zrxAmountAfterFees = feeOrder.makerAssetAmount.sub(feeOrder.takerFee);
assert.assert(
zrxAmountAfterFees.greaterThan(constants.ZERO_AMOUNT),
- `Expected takerFee: ${JSON.stringify(
- signedFeeOrder.takerFee,
- )} to be less than makerAssetAmount: ${JSON.stringify(signedFeeOrder.makerAssetAmount)}`,
+ `Expected takerFee: ${JSON.stringify(feeOrder.takerFee)} to be less than makerAssetAmount: ${JSON.stringify(
+ feeOrder.makerAssetAmount,
+ )}`,
);
- const rate = signedFeeOrder.takerAssetAmount.div(zrxAmountAfterFees);
+ const rate = feeOrder.takerAssetAmount.div(zrxAmountAfterFees);
return rate;
},
};