Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getTakerFillAmountForFeeOrder(order: SignedOrder, makerFillAmount: BigNumber): [BigNumber, BigNumber] {
// For each unit of TakerAsset we buy (MakerAsset - TakerFee)
const adjustedTakerFillAmount = makerFillAmount
.multipliedBy(order.takerAssetAmount)
.div(order.makerAssetAmount.minus(order.takerFee))
.integerValue(BigNumber.ROUND_CEIL);
// The amount that we buy will be greater than makerFillAmount, since we buy some amount for fees.
const adjustedMakerFillAmount = orderUtils.getMakerFillAmount(order, adjustedTakerFillAmount);
return [adjustedTakerFillAmount, adjustedMakerFillAmount];
},
};
getTakerFillAmount(order: SignedOrder, makerFillAmount: BigNumber): BigNumber {
// Round up because exchange rate favors Maker
const takerFillAmount = makerFillAmount
.multipliedBy(order.takerAssetAmount)
.div(order.makerAssetAmount)
.integerValue(BigNumber.ROUND_CEIL);
return takerFillAmount;
},
// given a desired amount of takerAsset to fill, calculate how much fee is required by the taker to fill that amount
getTakerFillAmount(order: Order, makerFillAmount: BigNumber): BigNumber {
// Round up because exchange rate favors Maker
const takerFillAmount = makerFillAmount
.multipliedBy(order.takerAssetAmount)
.div(order.makerAssetAmount)
.integerValue(BigNumber.ROUND_CEIL);
return takerFillAmount;
},
/**
getTakerFillAmountForFeeOrder(order: Order, makerFillAmount: BigNumber): [BigNumber, BigNumber] {
// For each unit of TakerAsset we buy (MakerAsset - TakerFee)
const adjustedTakerFillAmount = makerFillAmount
.multipliedBy(order.takerAssetAmount)
.div(order.makerAssetAmount.minus(order.takerFee))
.integerValue(BigNumber.ROUND_CEIL);
// The amount that we buy will be greater than makerFillAmount, since we buy some amount for fees.
const adjustedMakerFillAmount = orderCalculationUtils.getMakerFillAmount(order, adjustedTakerFillAmount);
return [adjustedTakerFillAmount, adjustedMakerFillAmount];
},
};
takerAssetAmount,
feeTakerAssetAmount: takerAssetAmountWithFees.minus(takerAssetAmount),
};
} else if (utils.isOrderTakerFeePayableWithMakerAsset(order)) {
if (takerAssetAmountWithFees.isZero()) {
return {
takerAssetAmount: constants.ZERO_AMOUNT,
feeTakerAssetAmount: constants.ZERO_AMOUNT,
};
}
const takerFeeAmount = orderCalculationUtils.getTakerFeeAmount(order, takerAssetAmountWithFees);
const makerAssetFillAmount = orderCalculationUtils.getMakerFillAmount(order, takerAssetAmountWithFees);
const takerAssetAmount = takerFeeAmount
.div(makerAssetFillAmount)
.multipliedBy(takerAssetAmountWithFees)
.integerValue(BigNumber.ROUND_CEIL);
return {
takerAssetAmount,
feeTakerAssetAmount: takerAssetAmountWithFees.minus(takerAssetAmount),
};
}
return {
feeTakerAssetAmount: constants.ZERO_AMOUNT,
takerAssetAmount: takerAssetAmountWithFees,
};
}
private _pricePerTokenWei(): BigNumber | undefined {
const swapQuoteAccessor = oc(this.props.swapQuoteInfo);
const assetTotalInWei = swapQuoteAccessor.totalTakerAssetAmount();
const selectedAssetUnitAmount = this.props.selectedAssetUnitAmount;
return assetTotalInWei !== undefined &&
selectedAssetUnitAmount !== undefined &&
!selectedAssetUnitAmount.eq(BIG_NUMBER_ZERO)
? assetTotalInWei.div(selectedAssetUnitAmount).integerValue(BigNumber.ROUND_CEIL)
: undefined;
}
);
const adjustedFillableTakerAssetAmount = fillableAmountsUtils.getTakerAssetAmountSwappedAfterFees(
order,
);
const takerAssetAmountWithFees = BigNumber.min(
remainingTakerAssetFillAmount,
adjustedFillableTakerAssetAmount,
);
const { takerAssetAmount, feeTakerAssetAmount } = getTakerAssetAmountBreakDown(
order,
takerAssetAmountWithFees,
);
const makerAssetAmount = takerAssetAmountWithFees
.div(adjustedFillableTakerAssetAmount)
.multipliedBy(adjustedFillableMakerAssetAmount)
.integerValue(BigNumber.ROUND_CEIL);
return {
totalMakerAssetAmount: totalMakerAssetAmount.plus(makerAssetAmount),
totalTakerAssetAmount: totalTakerAssetAmount.plus(takerAssetAmount),
totalFeeTakerAssetAmount: totalFeeTakerAssetAmount.plus(feeTakerAssetAmount),
remainingTakerAssetFillAmount: BigNumber.max(
constants.ZERO_AMOUNT,
remainingTakerAssetFillAmount.minus(takerAssetAmountWithFees),
),
};
},
{