aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-12-22 04:24:54 +0800
committerFabio Berger <me@fabioberger.com>2017-12-22 04:24:54 +0800
commite01c0f054d2dbb043aec8b4cb8e1c47f83bd5eb9 (patch)
tree241b630db5044974cc17130f149ca64728d9c619 /packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
parentd725de72861c6a6218c7f4822a339175a2da7403 (diff)
parentcb3582289ff94857d5956bbd71dbf68ee3f42ecf (diff)
downloaddexon-sol-tools-e01c0f054d2dbb043aec8b4cb8e1c47f83bd5eb9.tar
dexon-sol-tools-e01c0f054d2dbb043aec8b4cb8e1c47f83bd5eb9.tar.gz
dexon-sol-tools-e01c0f054d2dbb043aec8b4cb8e1c47f83bd5eb9.tar.bz2
dexon-sol-tools-e01c0f054d2dbb043aec8b4cb8e1c47f83bd5eb9.tar.lz
dexon-sol-tools-e01c0f054d2dbb043aec8b4cb8e1c47f83bd5eb9.tar.xz
dexon-sol-tools-e01c0f054d2dbb043aec8b4cb8e1c47f83bd5eb9.tar.zst
dexon-sol-tools-e01c0f054d2dbb043aec8b4cb8e1c47f83bd5eb9.zip
Merge branch 'development' into fix/docLinks
* development: Update and standardize contracts README Add to CHANGELOG Refactor toBaseUnitAmount so that it throws if user supplies unitAmount with too many decimals Make assertion stricter so that one cannot submit invalid baseUnit amounts to `toUnitAmount` Add some missed underscores, update changelog and comments Add new underscore-privates rule to @0xproject/tslint-config and fix lint errors # Conflicts: # packages/website/ts/pages/documentation/documentation.tsx # packages/website/ts/pages/shared/nested_sidebar_menu.tsx
Diffstat (limited to 'packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts')
-rw-r--r--packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts76
1 files changed, 38 insertions, 38 deletions
diff --git a/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts b/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
index e8601e678..ddf3b763b 100644
--- a/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
+++ b/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
@@ -3,69 +3,69 @@ import {BigNumber} from 'bignumber.js';
import {SignedOrder} from '../types';
export class RemainingFillableCalculator {
- private signedOrder: SignedOrder;
- private isMakerTokenZRX: boolean;
+ private _signedOrder: SignedOrder;
+ private _isMakerTokenZRX: boolean;
// Transferrable Amount is the minimum of Approval and Balance
- private transferrableMakerTokenAmount: BigNumber;
- private transferrableMakerFeeTokenAmount: BigNumber;
- private remainingMakerTokenAmount: BigNumber;
- private remainingMakerFeeAmount: BigNumber;
+ private _transferrableMakerTokenAmount: BigNumber;
+ private _transferrableMakerFeeTokenAmount: BigNumber;
+ private _remainingMakerTokenAmount: BigNumber;
+ private _remainingMakerFeeAmount: BigNumber;
constructor(signedOrder: SignedOrder,
isMakerTokenZRX: boolean,
transferrableMakerTokenAmount: BigNumber,
transferrableMakerFeeTokenAmount: BigNumber,
remainingMakerTokenAmount: BigNumber) {
- this.signedOrder = signedOrder;
- this.isMakerTokenZRX = isMakerTokenZRX;
- this.transferrableMakerTokenAmount = transferrableMakerTokenAmount;
- this.transferrableMakerFeeTokenAmount = transferrableMakerFeeTokenAmount;
- this.remainingMakerTokenAmount = remainingMakerTokenAmount;
- this.remainingMakerFeeAmount = remainingMakerTokenAmount.times(signedOrder.makerFee)
+ this._signedOrder = signedOrder;
+ this._isMakerTokenZRX = isMakerTokenZRX;
+ this._transferrableMakerTokenAmount = transferrableMakerTokenAmount;
+ this._transferrableMakerFeeTokenAmount = transferrableMakerFeeTokenAmount;
+ this._remainingMakerTokenAmount = remainingMakerTokenAmount;
+ this._remainingMakerFeeAmount = remainingMakerTokenAmount.times(signedOrder.makerFee)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
}
public computeRemainingMakerFillable(): BigNumber {
- if (this.hasSufficientFundsForFeeAndTransferAmount()) {
- return this.remainingMakerTokenAmount;
+ if (this._hasSufficientFundsForFeeAndTransferAmount()) {
+ return this._remainingMakerTokenAmount;
}
- if (this.signedOrder.makerFee.isZero()) {
- return BigNumber.min(this.remainingMakerTokenAmount, this.transferrableMakerTokenAmount);
+ if (this._signedOrder.makerFee.isZero()) {
+ return BigNumber.min(this._remainingMakerTokenAmount, this._transferrableMakerTokenAmount);
}
- return this.calculatePartiallyFillableMakerTokenAmount();
+ return this._calculatePartiallyFillableMakerTokenAmount();
}
public computeRemainingTakerFillable(): BigNumber {
- return this.computeRemainingMakerFillable().times(this.signedOrder.takerTokenAmount)
- .dividedToIntegerBy(this.signedOrder.makerTokenAmount);
+ return this.computeRemainingMakerFillable().times(this._signedOrder.takerTokenAmount)
+ .dividedToIntegerBy(this._signedOrder.makerTokenAmount);
}
- private hasSufficientFundsForFeeAndTransferAmount(): boolean {
- if (this.isMakerTokenZRX) {
- const totalZRXTransferAmountRequired = this.remainingMakerTokenAmount.plus(this.remainingMakerFeeAmount);
- const hasSufficientFunds = this.transferrableMakerTokenAmount.greaterThanOrEqualTo(
+ private _hasSufficientFundsForFeeAndTransferAmount(): boolean {
+ if (this._isMakerTokenZRX) {
+ const totalZRXTransferAmountRequired = this._remainingMakerTokenAmount.plus(this._remainingMakerFeeAmount);
+ const hasSufficientFunds = this._transferrableMakerTokenAmount.greaterThanOrEqualTo(
totalZRXTransferAmountRequired);
return hasSufficientFunds;
} else {
- const hasSufficientFundsForTransferAmount = this.transferrableMakerTokenAmount.greaterThanOrEqualTo(
- this.remainingMakerTokenAmount);
- const hasSufficientFundsForFeeAmount = this.transferrableMakerFeeTokenAmount.greaterThanOrEqualTo(
- this.remainingMakerFeeAmount);
+ const hasSufficientFundsForTransferAmount = this._transferrableMakerTokenAmount.greaterThanOrEqualTo(
+ this._remainingMakerTokenAmount);
+ const hasSufficientFundsForFeeAmount = this._transferrableMakerFeeTokenAmount.greaterThanOrEqualTo(
+ this._remainingMakerFeeAmount);
const hasSufficientFunds = hasSufficientFundsForTransferAmount && hasSufficientFundsForFeeAmount;
return hasSufficientFunds;
}
}
- private calculatePartiallyFillableMakerTokenAmount(): BigNumber {
+ private _calculatePartiallyFillableMakerTokenAmount(): BigNumber {
// Given an order for 200 wei for 2 ZRXwei fee, find 100 wei for 1 ZRXwei. Order ratio is then 100:1
- const orderToFeeRatio = this.signedOrder.makerTokenAmount.dividedBy(this.signedOrder.makerFee);
+ const orderToFeeRatio = this._signedOrder.makerTokenAmount.dividedBy(this._signedOrder.makerFee);
// The number of times the maker can fill the order, if each fill only required the transfer of a single
// baseUnit of fee tokens.
// Given 2 ZRXwei, the maximum amount of times Maker can fill this order, in terms of fees, is 2
- const fillableTimesInFeeTokenBaseUnits = BigNumber.min(this.transferrableMakerFeeTokenAmount,
- this.remainingMakerFeeAmount);
+ const fillableTimesInFeeTokenBaseUnits = BigNumber.min(this._transferrableMakerFeeTokenAmount,
+ this._remainingMakerFeeAmount);
// The number of times the Maker can fill the order, given the Maker Token Balance
// Assuming a balance of 150 wei, and an orderToFeeRatio of 100:1, maker can fill this order 1 time.
- let fillableTimesInMakerTokenUnits = this.transferrableMakerTokenAmount.dividedBy(orderToFeeRatio);
- if (this.isMakerTokenZRX) {
+ let fillableTimesInMakerTokenUnits = this._transferrableMakerTokenAmount.dividedBy(orderToFeeRatio);
+ if (this._isMakerTokenZRX) {
// If ZRX is the maker token, the Fee and the Maker amount need to be removed from the same pool;
// 200 ZRXwei for 2ZRXwei fee can only be filled once (need 202 ZRXwei)
- const totalZRXTokenPooled = this.transferrableMakerTokenAmount;
+ const totalZRXTokenPooled = this._transferrableMakerTokenAmount;
// The purchasing power here is less as the tokens are taken from the same Pool
// For every one number of fills, we have to take an extra ZRX out of the pool
fillableTimesInMakerTokenUnits = totalZRXTokenPooled.dividedBy(
@@ -75,11 +75,11 @@ export class RemainingFillableCalculator {
// When Ratio is not fully divisible there can be remainders which cannot be represented, so they are floored.
// This can result in a RoundingError being thrown by the Exchange Contract.
const partiallyFillableMakerTokenAmount = fillableTimesInMakerTokenUnits
- .times(this.signedOrder.makerTokenAmount)
- .dividedToIntegerBy(this.signedOrder.makerFee);
+ .times(this._signedOrder.makerTokenAmount)
+ .dividedToIntegerBy(this._signedOrder.makerFee);
const partiallyFillableFeeTokenAmount = fillableTimesInFeeTokenBaseUnits
- .times(this.signedOrder.makerTokenAmount)
- .dividedToIntegerBy(this.signedOrder.makerFee);
+ .times(this._signedOrder.makerTokenAmount)
+ .dividedToIntegerBy(this._signedOrder.makerFee);
const partiallyFillableAmount = BigNumber.min(partiallyFillableMakerTokenAmount,
partiallyFillableFeeTokenAmount);
return partiallyFillableAmount;