aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r--packages/0x.js/src/contract_wrappers/exchange_wrapper.ts11
-rw-r--r--packages/0x.js/src/fetchers/simple_balance_and_proxy_allowance_fetcher.ts10
-rw-r--r--packages/0x.js/src/fetchers/simple_order_filled_cancelled_fetcher.ts18
-rw-r--r--packages/0x.js/src/order_watcher/order_state_watcher.ts6
-rw-r--r--packages/0x.js/src/stores/balance_proxy_allowance_lazy_store.ts8
-rw-r--r--packages/0x.js/src/stores/order_filled_cancelled_lazy_store.ts12
-rw-r--r--packages/0x.js/src/utils/order_state_utils.ts2
7 files changed, 39 insertions, 28 deletions
diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
index 5dea70769..eacd3ebf0 100644
--- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
@@ -879,15 +879,18 @@ export class ExchangeWrapper extends ContractWrapper {
/**
* Gets the latest OrderState of a signedOrder
* @param signedOrder The signedOrder
+ * @param stateLayer Optional, desired blockchain state layer (defaults to latest).
+ * @return OrderState of the signedOrder
*/
- public async getOrderStateAsync(signedOrder: SignedOrder): Promise<OrderState> {
+ public async getOrderStateAsync(signedOrder: SignedOrder, stateLayer: BlockParamLiteral = BlockParamLiteral.Latest): Promise<OrderState> {
const simpleBalanceAndProxyAllowanceFetcher = new SimpleBalanceAndProxyAllowanceFetcher(
this._tokenWrapper,
- BlockParamLiteral.Latest,
+ stateLayer,
);
- const simpleOrderFilledCancelledFetcher = new SimpleOrderFilledCancelledFetcher(this);
+ const simpleOrderFilledCancelledFetcher = new SimpleOrderFilledCancelledFetcher(this, stateLayer);
const orderStateUtils = new OrderStateUtils(simpleBalanceAndProxyAllowanceFetcher, simpleOrderFilledCancelledFetcher);
- return orderStateUtils.getOrderStateAsync(signedOrder);
+ const orderState = orderStateUtils.getOrderStateAsync(signedOrder);
+ return orderState;
}
/**
* Returns the ZRX token address used by the exchange contract.
diff --git a/packages/0x.js/src/fetchers/simple_balance_and_proxy_allowance_fetcher.ts b/packages/0x.js/src/fetchers/simple_balance_and_proxy_allowance_fetcher.ts
index 877f07a22..c00dba5cf 100644
--- a/packages/0x.js/src/fetchers/simple_balance_and_proxy_allowance_fetcher.ts
+++ b/packages/0x.js/src/fetchers/simple_balance_and_proxy_allowance_fetcher.ts
@@ -5,22 +5,24 @@ import {BalanceAndProxyAllowanceFetcher} from '../abstract/balance_and_proxy_all
import {TokenWrapper} from '../contract_wrappers/token_wrapper';
export class SimpleBalanceAndProxyAllowanceFetcher implements BalanceAndProxyAllowanceFetcher {
- private _token: TokenWrapper;
+ private _tokenWrapper: TokenWrapper;
private _defaultBlock: BlockParamLiteral;
constructor(token: TokenWrapper, defaultBlock: BlockParamLiteral) {
- this._token = token;
+ this._tokenWrapper = token;
this._defaultBlock = defaultBlock;
}
public async getBalanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> {
const methodOpts = {
defaultBlock: this._defaultBlock,
};
- return this._token.getBalanceAsync(tokenAddress, userAddress, methodOpts);
+ const balance = this._tokenWrapper.getBalanceAsync(tokenAddress, userAddress, methodOpts);
+ return balance;
}
public async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> {
const methodOpts = {
defaultBlock: this._defaultBlock,
};
- return this._token.getProxyAllowanceAsync(tokenAddress, userAddress, methodOpts);
+ const proxyAllowance = this._tokenWrapper.getProxyAllowanceAsync(tokenAddress, userAddress, methodOpts);
+ return proxyAllowance;
}
}
diff --git a/packages/0x.js/src/fetchers/simple_order_filled_cancelled_fetcher.ts b/packages/0x.js/src/fetchers/simple_order_filled_cancelled_fetcher.ts
index e24f02726..1c8aec1a1 100644
--- a/packages/0x.js/src/fetchers/simple_order_filled_cancelled_fetcher.ts
+++ b/packages/0x.js/src/fetchers/simple_order_filled_cancelled_fetcher.ts
@@ -5,20 +5,24 @@ import {OrderFilledCancelledFetcher} from '../abstract/order_filled_cancelled_fe
import {ExchangeWrapper} from '../contract_wrappers/exchange_wrapper';
export class SimpleOrderFilledCancelledFetcher implements OrderFilledCancelledFetcher {
- private _exchange: ExchangeWrapper;
- constructor(exchange: ExchangeWrapper) {
- this._exchange = exchange;
+ private _exchangeWrapper: ExchangeWrapper;
+ private _defaultBlock: BlockParamLiteral;
+ constructor(exchange: ExchangeWrapper, defaultBlock: BlockParamLiteral) {
+ this._exchangeWrapper = exchange;
+ this._defaultBlock = defaultBlock;
}
public async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber> {
const methodOpts = {
- defaultBlock: BlockParamLiteral.Pending,
+ defaultBlock: this._defaultBlock,
};
- return this._exchange.getFilledTakerAmountAsync(orderHash, methodOpts);
+ const filledTakerAmount = this._exchangeWrapper.getFilledTakerAmountAsync(orderHash, methodOpts);
+ return filledTakerAmount;
}
public async getCancelledTakerAmountAsync(orderHash: string): Promise<BigNumber> {
const methodOpts = {
- defaultBlock: BlockParamLiteral.Pending,
+ defaultBlock: this._defaultBlock,
};
- return this._exchange.getCancelledTakerAmountAsync(orderHash, methodOpts);
+ const cancelledTakerAmount = this._exchangeWrapper.getCancelledTakerAmountAsync(orderHash, methodOpts);
+ return cancelledTakerAmount;
}
}
diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts
index 0aa0c33bd..a9df8ac9d 100644
--- a/packages/0x.js/src/order_watcher/order_state_watcher.ts
+++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts
@@ -87,7 +87,7 @@ export class OrderStateWatcher {
_.isUndefined(config) || _.isUndefined(config.stateLayer) ? BlockParamLiteral.Latest : config.stateLayer;
this._eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalIfExistsMs, stateLayer);
this._balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(token, stateLayer);
- this._orderFilledCancelledLazyStore = new OrderFilledCancelledLazyStore(exchange);
+ this._orderFilledCancelledLazyStore = new OrderFilledCancelledLazyStore(exchange, stateLayer);
this._orderStateUtils = new OrderStateUtils(
this._balanceAndProxyAllowanceLazyStore,
this._orderFilledCancelledLazyStore,
@@ -131,7 +131,7 @@ export class OrderStateWatcher {
}
delete this._orderByOrderHash[orderHash];
delete this._orderStateByOrderHashCache[orderHash];
- const exchange = (this._orderFilledCancelledLazyStore as any)._exchange as ExchangeWrapper;
+ const exchange = (this._orderFilledCancelledLazyStore as any)._exchangeWrapper as ExchangeWrapper;
const zrxTokenAddress = exchange.getZRXTokenAddress();
this._removeFromDependentOrderHashes(signedOrder.maker, zrxTokenAddress, orderHash);
@@ -374,7 +374,7 @@ export class OrderStateWatcher {
}
}
private _getZRXTokenAddress(): string {
- const exchange = (this._orderFilledCancelledLazyStore as any)._exchange as ExchangeWrapper;
+ const exchange = (this._orderFilledCancelledLazyStore as any)._exchangeWrapper as ExchangeWrapper;
const zrxTokenAddress = exchange.getZRXTokenAddress();
return zrxTokenAddress;
}
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 97739f969..c8395415e 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
@@ -9,7 +9,7 @@ import { BalanceAndProxyAllowanceFetcher } from '../abstract/balance_and_proxy_a
* Copy on read store for balances/proxyAllowances of tokens/accounts
*/
export class BalanceAndProxyAllowanceLazyStore implements BalanceAndProxyAllowanceFetcher {
- private _token: TokenWrapper;
+ private _tokenWrapper: TokenWrapper;
private _defaultBlock: BlockParamLiteral;
private _balance: {
[tokenAddress: string]: {
@@ -22,7 +22,7 @@ export class BalanceAndProxyAllowanceLazyStore implements BalanceAndProxyAllowan
};
};
constructor(token: TokenWrapper, defaultBlock: BlockParamLiteral) {
- this._token = token;
+ this._tokenWrapper = token;
this._defaultBlock = defaultBlock;
this._balance = {};
this._proxyAllowance = {};
@@ -32,7 +32,7 @@ export class BalanceAndProxyAllowanceLazyStore implements BalanceAndProxyAllowan
const methodOpts = {
defaultBlock: this._defaultBlock,
};
- const balance = await this._token.getBalanceAsync(tokenAddress, userAddress, methodOpts);
+ const balance = await this._tokenWrapper.getBalanceAsync(tokenAddress, userAddress, methodOpts);
this.setBalance(tokenAddress, userAddress, balance);
}
const cachedBalance = this._balance[tokenAddress][userAddress];
@@ -60,7 +60,7 @@ export class BalanceAndProxyAllowanceLazyStore implements BalanceAndProxyAllowan
const methodOpts = {
defaultBlock: this._defaultBlock,
};
- const proxyAllowance = await this._token.getProxyAllowanceAsync(tokenAddress, userAddress, methodOpts);
+ const proxyAllowance = await this._tokenWrapper.getProxyAllowanceAsync(tokenAddress, userAddress, methodOpts);
this.setProxyAllowance(tokenAddress, userAddress, proxyAllowance);
}
const cachedProxyAllowance = this._proxyAllowance[tokenAddress][userAddress];
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 134508057..eebc2b52c 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
@@ -9,15 +9,17 @@ import { OrderFilledCancelledFetcher } from '../abstract/order_filled_cancelled_
* Copy on read store for filled/cancelled taker amounts
*/
export class OrderFilledCancelledLazyStore implements OrderFilledCancelledFetcher {
- private _exchange: ExchangeWrapper;
+ private _exchangeWrapper: ExchangeWrapper;
+ private _defaultBlock: BlockParamLiteral;
private _filledTakerAmount: {
[orderHash: string]: BigNumber;
};
private _cancelledTakerAmount: {
[orderHash: string]: BigNumber;
};
- constructor(exchange: ExchangeWrapper) {
- this._exchange = exchange;
+ constructor(exchange: ExchangeWrapper, defaultBlock: BlockParamLiteral) {
+ this._exchangeWrapper = exchange;
+ this._defaultBlock = defaultBlock;
this._filledTakerAmount = {};
this._cancelledTakerAmount = {};
}
@@ -26,7 +28,7 @@ export class OrderFilledCancelledLazyStore implements OrderFilledCancelledFetche
const methodOpts = {
defaultBlock: BlockParamLiteral.Pending,
};
- const filledTakerAmount = await this._exchange.getFilledTakerAmountAsync(orderHash, methodOpts);
+ const filledTakerAmount = await this._exchangeWrapper.getFilledTakerAmountAsync(orderHash, methodOpts);
this.setFilledTakerAmount(orderHash, filledTakerAmount);
}
const cachedFilled = this._filledTakerAmount[orderHash];
@@ -43,7 +45,7 @@ export class OrderFilledCancelledLazyStore implements OrderFilledCancelledFetche
const methodOpts = {
defaultBlock: BlockParamLiteral.Pending,
};
- const cancelledTakerAmount = await this._exchange.getCancelledTakerAmountAsync(orderHash, methodOpts);
+ const cancelledTakerAmount = await this._exchangeWrapper.getCancelledTakerAmountAsync(orderHash, methodOpts);
this.setCancelledTakerAmount(orderHash, cancelledTakerAmount);
}
const cachedCancelled = this._cancelledTakerAmount[orderHash];
diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts
index d8d69185f..e15ff6bc9 100644
--- a/packages/0x.js/src/utils/order_state_utils.ts
+++ b/packages/0x.js/src/utils/order_state_utils.ts
@@ -80,7 +80,7 @@ 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._orderFilledCancelledFetcher as any)._exchange as ExchangeWrapper;
+ const exchange = (this._orderFilledCancelledFetcher as any)._exchangeWrapper as ExchangeWrapper;
const zrxTokenAddress = exchange.getZRXTokenAddress();
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
const makerBalance = await this._balanceAndProxyAllowanceFetcher.getBalanceAsync(