aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-11-24 05:21:45 +0800
committerFabio Berger <me@fabioberger.com>2017-11-24 05:21:45 +0800
commitb7b1721145f3894ade757a2ad4c366e2b6eadbe9 (patch)
tree0b724c1eb0c218a482a5b31b7438f67c33af61e3 /packages/0x.js/src
parent5068f1666a9d1dec2140f2a98e96bb880e854105 (diff)
downloaddexon-0x-contracts-b7b1721145f3894ade757a2ad4c366e2b6eadbe9.tar.gz
dexon-0x-contracts-b7b1721145f3894ade757a2ad4c366e2b6eadbe9.tar.zst
dexon-0x-contracts-b7b1721145f3894ade757a2ad4c366e2b6eadbe9.zip
Pass 'latest' to ExchangeTransferSimulator when used for validating orders, and pass 'pending' when used in the order watcher.
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r--packages/0x.js/src/contract_wrappers/exchange_wrapper.ts17
-rw-r--r--packages/0x.js/src/order_watcher/order_state_watcher.ts4
-rw-r--r--packages/0x.js/src/stores/balance_proxy_allowance_lazy_store.ts8
-rw-r--r--packages/0x.js/src/utils/exchange_transfer_simulator.ts4
4 files changed, 19 insertions, 14 deletions
diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
index 3e631b73e..7c33dc6ec 100644
--- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
@@ -29,6 +29,7 @@ import {
EventCallback,
ExchangeContractEventArgs,
DecodedLogArgs,
+ BlockParamLiteral,
} from '../types';
import {assert} from '../utils/assert';
import {utils} from '../utils/utils';
@@ -178,7 +179,7 @@ export class ExchangeWrapper extends ContractWrapper {
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const zrxTokenAddress = await this.getZRXTokenAddressAsync();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
}
@@ -250,7 +251,7 @@ export class ExchangeWrapper extends ContractWrapper {
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const zrxTokenAddress = await this.getZRXTokenAddressAsync();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
for (const signedOrder of signedOrders) {
await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
@@ -340,7 +341,7 @@ export class ExchangeWrapper extends ContractWrapper {
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const zrxTokenAddress = await this.getZRXTokenAddressAsync();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
for (const orderFillRequest of orderFillRequests) {
await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
exchangeTradeEmulator, orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount,
@@ -420,7 +421,7 @@ export class ExchangeWrapper extends ContractWrapper {
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const zrxTokenAddress = await this.getZRXTokenAddressAsync();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
await this._orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
}
@@ -484,7 +485,7 @@ export class ExchangeWrapper extends ContractWrapper {
orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const zrxTokenAddress = await this.getZRXTokenAddressAsync();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
for (const orderFillRequest of orderFillRequests) {
await this._orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
exchangeTradeEmulator, orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount,
@@ -721,7 +722,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
const zrxTokenAddress = await this.getZRXTokenAddressAsync();
const expectedFillTakerTokenAmount = !_.isUndefined(opts) ? opts.expectedFillTakerTokenAmount : undefined;
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
await this._orderValidationUtils.validateOrderFillableOrThrowAsync(
exchangeTradeEmulator, signedOrder, zrxTokenAddress, expectedFillTakerTokenAmount,
);
@@ -741,7 +742,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.isValidBaseUnitAmount('fillTakerTokenAmount', fillTakerTokenAmount);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
const zrxTokenAddress = await this.getZRXTokenAddressAsync();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
}
@@ -775,7 +776,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.isValidBaseUnitAmount('fillTakerTokenAmount', fillTakerTokenAmount);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
const zrxTokenAddress = await this.getZRXTokenAddressAsync();
- const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper);
+ const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
await this._orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
}
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 44a41669d..d02e31160 100644
--- a/packages/0x.js/src/order_watcher/order_state_watcher.ts
+++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts
@@ -74,7 +74,9 @@ export class OrderStateWatcher {
this._web3Wrapper = web3Wrapper;
const pollingIntervalIfExistsMs = _.isUndefined(config) ? undefined : config.eventPollingIntervalMs;
this._eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalIfExistsMs);
- this._balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(token);
+ this._balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
+ token, BlockParamLiteral.Pending,
+ );
this._orderFilledCancelledLazyStore = new OrderFilledCancelledLazyStore(exchange);
this._orderStateUtils = new OrderStateUtils(
this._balanceAndProxyAllowanceLazyStore, this._orderFilledCancelledLazyStore,
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 c83e61606..7c94031c3 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,6 +9,7 @@ import {BlockParamLiteral} from '../types';
*/
export class BalanceAndProxyAllowanceLazyStore {
private token: TokenWrapper;
+ private defaultBlock: BlockParamLiteral;
private balance: {
[tokenAddress: string]: {
[userAddress: string]: BigNumber,
@@ -19,15 +20,16 @@ export class BalanceAndProxyAllowanceLazyStore {
[userAddress: string]: BigNumber,
},
};
- constructor(token: TokenWrapper) {
+ constructor(token: TokenWrapper, defaultBlock: BlockParamLiteral) {
this.token = token;
+ this.defaultBlock = defaultBlock;
this.balance = {};
this.proxyAllowance = {};
}
public async getBalanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> {
if (_.isUndefined(this.balance[tokenAddress]) || _.isUndefined(this.balance[tokenAddress][userAddress])) {
const methodOpts = {
- defaultBlock: BlockParamLiteral.Pending,
+ defaultBlock: this.defaultBlock,
};
const balance = await this.token.getBalanceAsync(tokenAddress, userAddress, methodOpts);
this.setBalance(tokenAddress, userAddress, balance);
@@ -53,7 +55,7 @@ export class BalanceAndProxyAllowanceLazyStore {
if (_.isUndefined(this.proxyAllowance[tokenAddress]) ||
_.isUndefined(this.proxyAllowance[tokenAddress][userAddress])) {
const methodOpts = {
- defaultBlock: BlockParamLiteral.Pending,
+ defaultBlock: this.defaultBlock,
};
const proxyAllowance = await this.token.getProxyAllowanceAsync(tokenAddress, userAddress, methodOpts);
this.setProxyAllowance(tokenAddress, userAddress, proxyAllowance);
diff --git a/packages/0x.js/src/utils/exchange_transfer_simulator.ts b/packages/0x.js/src/utils/exchange_transfer_simulator.ts
index 308ef06db..eeb6081cb 100644
--- a/packages/0x.js/src/utils/exchange_transfer_simulator.ts
+++ b/packages/0x.js/src/utils/exchange_transfer_simulator.ts
@@ -35,8 +35,8 @@ const ERR_MSG_MAPPING = {
export class ExchangeTransferSimulator {
private store: BalanceAndProxyAllowanceLazyStore;
private UNLIMITED_ALLOWANCE_IN_BASE_UNITS: BigNumber;
- constructor(token: TokenWrapper) {
- this.store = new BalanceAndProxyAllowanceLazyStore(token);
+ constructor(token: TokenWrapper, defaultBlock: BlockParamLiteral) {
+ this.store = new BalanceAndProxyAllowanceLazyStore(token, defaultBlock);
this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS = token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
}
/**