aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src
diff options
context:
space:
mode:
authorAra Kevonian <ara@dextroid.io>2018-04-10 18:46:43 +0800
committerAra Kevonian <ara@dextroid.io>2018-04-10 18:46:43 +0800
commitbf0ef055fbd4f5f798ea56868ad0beddf1111e7f (patch)
tree9d91f4ccc25e5c93638d8432c9851f293665b0bd /packages/0x.js/src
parentc80b42712a9fc73c05c32cd3d3396a6a02a7969f (diff)
downloaddexon-sol-tools-bf0ef055fbd4f5f798ea56868ad0beddf1111e7f.tar.gz
dexon-sol-tools-bf0ef055fbd4f5f798ea56868ad0beddf1111e7f.tar.zst
dexon-sol-tools-bf0ef055fbd4f5f798ea56868ad0beddf1111e7f.zip
Modify lazy stores to implement abstract fetcher classes
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r--packages/0x.js/src/fetchers/balance_and_allowance_fetcher.ts6
-rw-r--r--packages/0x.js/src/fetchers/order_filled_cancelled_fetcher.ts6
-rw-r--r--packages/0x.js/src/stores/balance_proxy_allowance_lazy_store.ts3
-rw-r--r--packages/0x.js/src/stores/order_filled_cancelled_lazy_store.ts3
-rw-r--r--packages/0x.js/src/utils/order_state_utils.ts30
5 files changed, 31 insertions, 17 deletions
diff --git a/packages/0x.js/src/fetchers/balance_and_allowance_fetcher.ts b/packages/0x.js/src/fetchers/balance_and_allowance_fetcher.ts
new file mode 100644
index 000000000..f7b1183f1
--- /dev/null
+++ b/packages/0x.js/src/fetchers/balance_and_allowance_fetcher.ts
@@ -0,0 +1,6 @@
+import { BigNumber } from '@0xproject/utils';
+
+export abstract class BalanceAndAllowanceFetcher {
+ public abstract async getBalanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber>;
+ public abstract async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber>;
+}
diff --git a/packages/0x.js/src/fetchers/order_filled_cancelled_fetcher.ts b/packages/0x.js/src/fetchers/order_filled_cancelled_fetcher.ts
new file mode 100644
index 000000000..81ae04b9c
--- /dev/null
+++ b/packages/0x.js/src/fetchers/order_filled_cancelled_fetcher.ts
@@ -0,0 +1,6 @@
+import { BigNumber } from '@0xproject/utils';
+
+export abstract class OrderFilledCancelledFetcher {
+ public abstract async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber>;
+ public abstract async getCancelledTakerAmountAsync(orderHash: string): Promise<BigNumber>;
+}
diff --git a/packages/0x.js/src/stores/balance_proxy_allowance_lazy_store.ts b/packages/0x.js/src/stores/balance_proxy_allowance_lazy_store.ts
index ede1319fe..610385356 100644
--- a/packages/0x.js/src/stores/balance_proxy_allowance_lazy_store.ts
+++ b/packages/0x.js/src/stores/balance_proxy_allowance_lazy_store.ts
@@ -3,11 +3,12 @@ import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import { TokenWrapper } from '../contract_wrappers/token_wrapper';
+import { BalanceAndAllowanceFetcher } from '../fetchers/balance_and_allowance_fetcher';
/**
* Copy on read store for balances/proxyAllowances of tokens/accounts
*/
-export class BalanceAndProxyAllowanceLazyStore {
+export class BalanceAndProxyAllowanceLazyStore implements BalanceAndAllowanceFetcher {
private _token: TokenWrapper;
private _defaultBlock: BlockParamLiteral;
private _balance: {
diff --git a/packages/0x.js/src/stores/order_filled_cancelled_lazy_store.ts b/packages/0x.js/src/stores/order_filled_cancelled_lazy_store.ts
index 0a0d93406..9ed4d3bf4 100644
--- a/packages/0x.js/src/stores/order_filled_cancelled_lazy_store.ts
+++ b/packages/0x.js/src/stores/order_filled_cancelled_lazy_store.ts
@@ -3,11 +3,12 @@ import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper';
+import { OrderFilledCancelledFetcher } from '../fetchers/order_filled_cancelled_fetcher';
/**
* Copy on read store for filled/cancelled taker amounts
*/
-export class OrderFilledCancelledLazyStore {
+export class OrderFilledCancelledLazyStore implements OrderFilledCancelledFetcher {
private _exchange: ExchangeWrapper;
private _filledTakerAmount: {
[orderHash: string]: BigNumber;
diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts
index 38189443b..6dbf7e572 100644
--- a/packages/0x.js/src/utils/order_state_utils.ts
+++ b/packages/0x.js/src/utils/order_state_utils.ts
@@ -4,16 +4,16 @@ import * as _ from 'lodash';
import { ZeroEx } from '../0x';
import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper';
+import { BalanceAndAllowanceFetcher } from '../fetchers/balance_and_allowance_fetcher';
+import { OrderFilledCancelledFetcher } from '../fetchers/order_filled_cancelled_fetcher';
import { RemainingFillableCalculator } from '../order_watcher/remaining_fillable_calculator';
-import { BalanceAndProxyAllowanceLazyStore } from '../stores/balance_proxy_allowance_lazy_store';
-import { OrderFilledCancelledLazyStore } from '../stores/order_filled_cancelled_lazy_store';
import { ExchangeContractErrs, OrderRelevantState, OrderState, OrderStateInvalid, OrderStateValid } from '../types';
const ACCEPTABLE_RELATIVE_ROUNDING_ERROR = 0.0001;
export class OrderStateUtils {
- private _balanceAndProxyAllowanceLazyStore: BalanceAndProxyAllowanceLazyStore;
- private _orderFilledCancelledLazyStore: OrderFilledCancelledLazyStore;
+ private _balanceAndAllowanceFetcher: BalanceAndAllowanceFetcher;
+ private _orderFilledCancelledFetcher: OrderFilledCancelledFetcher;
private static _validateIfOrderIsValid(signedOrder: SignedOrder, orderRelevantState: OrderRelevantState): void {
const unavailableTakerTokenAmount = orderRelevantState.cancelledTakerTokenAmount.add(
orderRelevantState.filledTakerTokenAmount,
@@ -49,11 +49,11 @@ export class OrderStateUtils {
}
}
constructor(
- balanceAndProxyAllowanceLazyStore: BalanceAndProxyAllowanceLazyStore,
- orderFilledCancelledLazyStore: OrderFilledCancelledLazyStore,
+ balanceAndProxyAllowanceFetcher: BalanceAndAllowanceFetcher,
+ orderFilledCancelledFetcher: OrderFilledCancelledFetcher,
) {
- this._balanceAndProxyAllowanceLazyStore = balanceAndProxyAllowanceLazyStore;
- this._orderFilledCancelledLazyStore = orderFilledCancelledLazyStore;
+ this._balanceAndAllowanceFetcher = balanceAndProxyAllowanceFetcher;
+ this._orderFilledCancelledFetcher = orderFilledCancelledFetcher;
}
public async getOrderStateAsync(signedOrder: SignedOrder): Promise<OrderState> {
const orderRelevantState = await this.getOrderRelevantStateAsync(signedOrder);
@@ -80,27 +80,27 @@ export class OrderStateUtils {
// If we pass it from the instantiator - there is no opportunity to get it there
// because JS doesn't support async constructors.
// Moreover - it's cached under the hood so it's equivalent to an async constructor.
- const exchange = (this._orderFilledCancelledLazyStore as any)._exchange as ExchangeWrapper;
+ const exchange = (this._orderFilledCancelledFetcher as any)._exchange as ExchangeWrapper;
const zrxTokenAddress = exchange.getZRXTokenAddress();
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- const makerBalance = await this._balanceAndProxyAllowanceLazyStore.getBalanceAsync(
+ const makerBalance = await this._balanceAndAllowanceFetcher.getBalanceAsync(
signedOrder.makerTokenAddress,
signedOrder.maker,
);
- const makerProxyAllowance = await this._balanceAndProxyAllowanceLazyStore.getProxyAllowanceAsync(
+ const makerProxyAllowance = await this._balanceAndAllowanceFetcher.getProxyAllowanceAsync(
signedOrder.makerTokenAddress,
signedOrder.maker,
);
- const makerFeeBalance = await this._balanceAndProxyAllowanceLazyStore.getBalanceAsync(
+ const makerFeeBalance = await this._balanceAndAllowanceFetcher.getBalanceAsync(
zrxTokenAddress,
signedOrder.maker,
);
- const makerFeeProxyAllowance = await this._balanceAndProxyAllowanceLazyStore.getProxyAllowanceAsync(
+ const makerFeeProxyAllowance = await this._balanceAndAllowanceFetcher.getProxyAllowanceAsync(
zrxTokenAddress,
signedOrder.maker,
);
- const filledTakerTokenAmount = await this._orderFilledCancelledLazyStore.getFilledTakerAmountAsync(orderHash);
- const cancelledTakerTokenAmount = await this._orderFilledCancelledLazyStore.getCancelledTakerAmountAsync(
+ const filledTakerTokenAmount = await this._orderFilledCancelledFetcher.getFilledTakerAmountAsync(orderHash);
+ const cancelledTakerTokenAmount = await this._orderFilledCancelledFetcher.getCancelledTakerAmountAsync(
orderHash,
);
const unavailableTakerTokenAmount = await exchange.getUnavailableTakerAmountAsync(orderHash);