Append -Floor to getPartialAmount and isRoundingError
This commit is contained in:
@@ -81,7 +81,7 @@ export class OrderStateUtils {
|
||||
const remainingTakerAssetAmount = signedOrder.takerAssetAmount.minus(
|
||||
sidedOrderRelevantState.filledTakerAssetAmount,
|
||||
);
|
||||
const isRoundingError = OrderValidationUtils.isRoundingError(
|
||||
const isRoundingError = OrderValidationUtils.isRoundingErrorFloor(
|
||||
remainingTakerAssetAmount,
|
||||
signedOrder.takerAssetAmount,
|
||||
signedOrder.makerAssetAmount,
|
||||
@@ -191,7 +191,7 @@ export class OrderStateUtils {
|
||||
);
|
||||
const remainingFillableTakerAssetAmountGivenMakersStatus = signedOrder.makerAssetAmount.eq(0)
|
||||
? new BigNumber(0)
|
||||
: utils.getPartialAmount(
|
||||
: utils.getPartialAmountFloor(
|
||||
orderRelevantMakerState.remainingFillableAssetAmount,
|
||||
signedOrder.makerAssetAmount,
|
||||
signedOrder.takerAssetAmount,
|
||||
|
||||
@@ -24,7 +24,7 @@ export class OrderValidationUtils {
|
||||
* @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 {
|
||||
public static isRoundingErrorFloor(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
|
||||
if (denominator.eq(0)) {
|
||||
@@ -58,7 +58,7 @@ export class OrderValidationUtils {
|
||||
zrxAssetData: string,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const fillMakerTokenAmount = utils.getPartialAmount(
|
||||
const fillMakerTokenAmount = utils.getPartialAmountFloor(
|
||||
fillTakerAssetAmount,
|
||||
signedOrder.takerAssetAmount,
|
||||
signedOrder.makerAssetAmount,
|
||||
@@ -79,7 +79,7 @@ export class OrderValidationUtils {
|
||||
TradeSide.Taker,
|
||||
TransferType.Trade,
|
||||
);
|
||||
const makerFeeAmount = utils.getPartialAmount(
|
||||
const makerFeeAmount = utils.getPartialAmountFloor(
|
||||
fillTakerAssetAmount,
|
||||
signedOrder.takerAssetAmount,
|
||||
signedOrder.makerFee,
|
||||
@@ -92,7 +92,7 @@ export class OrderValidationUtils {
|
||||
TradeSide.Maker,
|
||||
TransferType.Fee,
|
||||
);
|
||||
const takerFeeAmount = utils.getPartialAmount(
|
||||
const takerFeeAmount = utils.getPartialAmountFloor(
|
||||
fillTakerAssetAmount,
|
||||
signedOrder.takerAssetAmount,
|
||||
signedOrder.takerFee,
|
||||
@@ -218,7 +218,7 @@ export class OrderValidationUtils {
|
||||
zrxAssetData,
|
||||
);
|
||||
|
||||
const wouldRoundingErrorOccur = OrderValidationUtils.isRoundingError(
|
||||
const wouldRoundingErrorOccur = OrderValidationUtils.isRoundingErrorFloor(
|
||||
desiredFillTakerTokenAmount,
|
||||
signedOrder.takerAssetAmount,
|
||||
signedOrder.makerAssetAmount,
|
||||
|
||||
@@ -12,7 +12,7 @@ export const utils = {
|
||||
const milisecondsInSecond = 1000;
|
||||
return new BigNumber(Date.now() / milisecondsInSecond).round();
|
||||
},
|
||||
getPartialAmount(numerator: BigNumber, denominator: BigNumber, target: BigNumber): BigNumber {
|
||||
getPartialAmountFloor(numerator: BigNumber, denominator: BigNumber, target: BigNumber): BigNumber {
|
||||
const fillMakerTokenAmount = numerator
|
||||
.mul(target)
|
||||
.div(denominator)
|
||||
|
||||
Reference in New Issue
Block a user