aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/order-utils')
-rw-r--r--packages/order-utils/CHANGELOG.json25
-rw-r--r--packages/order-utils/CHANGELOG.md4
-rw-r--r--packages/order-utils/package.json28
-rw-r--r--packages/order-utils/src/abstract/abstract_order_filled_cancelled_lazy_store.ts12
-rw-r--r--packages/order-utils/src/asset_data_utils.ts2
-rw-r--r--packages/order-utils/src/crypto.ts2
-rw-r--r--packages/order-utils/src/index.ts1
-rw-r--r--packages/order-utils/src/store/balance_and_proxy_allowance_lazy_store.ts16
-rw-r--r--packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts65
9 files changed, 138 insertions, 17 deletions
diff --git a/packages/order-utils/CHANGELOG.json b/packages/order-utils/CHANGELOG.json
index 715d58a43..b1f962e9f 100644
--- a/packages/order-utils/CHANGELOG.json
+++ b/packages/order-utils/CHANGELOG.json
@@ -1,6 +1,16 @@
[
{
- "version": "1.0.0",
+ "version": "1.0.0-rc.2",
+ "changes": [
+ {
+ "note":
+ "Upgrade ethereumjs-abi dep including a fix so that addresses starting with 0 are properly decoded by `decodeERC20AssetData`"
+ }
+ ]
+ },
+ {
+ "timestamp": 1532043000,
+ "version": "1.0.0-rc.1",
"changes": [
{
"note": "Refactor to work with V2 of 0x protocol",
@@ -9,6 +19,19 @@
{
"note": "Export parseECSignature method",
"pr": 684
+ },
+ {
+ "note": "Handle Typed Arrays when hashing data",
+ "pr": 894
+ }
+ ]
+ },
+ {
+ "timestamp": 1531919263,
+ "version": "0.0.9",
+ "changes": [
+ {
+ "note": "Dependencies updated"
}
]
},
diff --git a/packages/order-utils/CHANGELOG.md b/packages/order-utils/CHANGELOG.md
index 672affc19..17464a966 100644
--- a/packages/order-utils/CHANGELOG.md
+++ b/packages/order-utils/CHANGELOG.md
@@ -5,6 +5,10 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
+## v0.0.9 - _July 18, 2018_
+
+ * Dependencies updated
+
## v0.0.8 - _July 9, 2018_
* Dependencies updated
diff --git a/packages/order-utils/package.json b/packages/order-utils/package.json
index cdacf58d0..0df8a3f6c 100644
--- a/packages/order-utils/package.json
+++ b/packages/order-utils/package.json
@@ -1,6 +1,6 @@
{
"name": "@0xproject/order-utils",
- "version": "1.0.0",
+ "version": "1.0.0-rc.1",
"engines": {
"node": ">=6.12"
},
@@ -51,9 +51,9 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/order-utils/README.md",
"devDependencies": {
- "@0xproject/dev-utils": "^0.4.5",
- "@0xproject/monorepo-scripts": "^0.2.2",
- "@0xproject/tslint-config": "^0.4.21",
+ "@0xproject/dev-utils": "^1.0.0",
+ "@0xproject/monorepo-scripts": "^1.0.0",
+ "@0xproject/tslint-config": "^1.0.0",
"@types/bn.js": "^4.11.0",
"@types/lodash": "4.14.104",
"chai": "^4.0.1",
@@ -71,18 +71,18 @@
"typescript": "2.7.1"
},
"dependencies": {
- "@0xproject/assert": "^0.3.0",
- "@0xproject/base-contract": "^0.3.5",
- "@0xproject/json-schemas": "1.0.0",
- "@0xproject/sol-compiler": "^0.5.3",
- "@0xproject/types": "^1.0.0",
- "@0xproject/typescript-typings": "^0.4.2",
- "@0xproject/utils": "^0.7.2",
- "@0xproject/web3-wrapper": "^0.7.2",
+ "@0xproject/assert": "^1.0.0",
+ "@0xproject/base-contract": "^1.0.0",
+ "@0xproject/json-schemas": "^1.0.0-rc.1",
+ "@0xproject/sol-compiler": "^1.0.0",
+ "@0xproject/types": "^1.0.0-rc.1",
+ "@0xproject/typescript-typings": "^1.0.0",
+ "@0xproject/utils": "^1.0.0",
+ "@0xproject/web3-wrapper": "^1.0.0",
"@types/node": "^8.0.53",
"bn.js": "^4.11.8",
- "ethereum-types": "^0.0.2",
- "ethereumjs-abi": "^0.6.4",
+ "ethereum-types": "^1.0.0",
+ "ethereumjs-abi": "0.6.5",
"ethereumjs-util": "^5.1.1",
"ethers": "3.0.22",
"lodash": "^4.17.4"
diff --git a/packages/order-utils/src/abstract/abstract_order_filled_cancelled_lazy_store.ts b/packages/order-utils/src/abstract/abstract_order_filled_cancelled_lazy_store.ts
new file mode 100644
index 000000000..617bcb224
--- /dev/null
+++ b/packages/order-utils/src/abstract/abstract_order_filled_cancelled_lazy_store.ts
@@ -0,0 +1,12 @@
+import { BigNumber } from '@0xproject/utils';
+
+export abstract class AbstractOrderFilledCancelledLazyStore {
+ public abstract async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber>;
+ public abstract async getIsCancelledAsync(orderHash: string): Promise<boolean>;
+ public abstract setFilledTakerAmount(orderHash: string, balance: BigNumber): void;
+ public abstract deleteFilledTakerAmount(orderHash: string): void;
+ public abstract setIsCancelled(orderHash: string, isCancelled: boolean): void;
+ public abstract deleteIsCancelled(orderHash: string): void;
+ public abstract deleteAll(): void;
+ public abstract getZRXAssetData(): string;
+}
diff --git a/packages/order-utils/src/asset_data_utils.ts b/packages/order-utils/src/asset_data_utils.ts
index d39c3c774..0c0b59548 100644
--- a/packages/order-utils/src/asset_data_utils.ts
+++ b/packages/order-utils/src/asset_data_utils.ts
@@ -112,7 +112,7 @@ export const assetDataUtils = {
* @param assetData Hex encoded assetData string to decode
* @return Either a ERC20 or ERC721 assetData object
*/
- decodeAssetData(assetData: string): ERC20AssetData | ERC721AssetData {
+ decodeAssetDataOrThrow(assetData: string): ERC20AssetData | ERC721AssetData {
const assetProxyId = assetDataUtils.decodeAssetProxyId(assetData);
switch (assetProxyId) {
case AssetProxyId.ERC20:
diff --git a/packages/order-utils/src/crypto.ts b/packages/order-utils/src/crypto.ts
index 517ca2840..0f1504a72 100644
--- a/packages/order-utils/src/crypto.ts
+++ b/packages/order-utils/src/crypto.ts
@@ -32,7 +32,7 @@ export const crypto = {
argTypes.push('address');
} else if (_.isString(arg)) {
argTypes.push('string');
- } else if (_.isBuffer(arg)) {
+ } else if (_.isBuffer(arg) || _.isTypedArray(arg)) {
argTypes.push('bytes');
} else if (_.isBoolean(arg)) {
argTypes.push('bool');
diff --git a/packages/order-utils/src/index.ts b/packages/order-utils/src/index.ts
index 8d748a2dc..76be63bb8 100644
--- a/packages/order-utils/src/index.ts
+++ b/packages/order-utils/src/index.ts
@@ -17,6 +17,7 @@ export { OrderError, MessagePrefixType, MessagePrefixOpts, EIP712Parameter, EIP7
export { AbstractBalanceAndProxyAllowanceFetcher } from './abstract/abstract_balance_and_proxy_allowance_fetcher';
export { AbstractOrderFilledCancelledFetcher } from './abstract/abstract_order_filled_cancelled_fetcher';
export { BalanceAndProxyAllowanceLazyStore } from './store/balance_and_proxy_allowance_lazy_store';
+export { OrderFilledCancelledLazyStore } from './store/order_filled_cancelled_lazy_store';
export { RemainingFillableCalculator } from './remaining_fillable_calculator';
export { OrderStateUtils } from './order_state_utils';
export { assetDataUtils } from './asset_data_utils';
diff --git a/packages/order-utils/src/store/balance_and_proxy_allowance_lazy_store.ts b/packages/order-utils/src/store/balance_and_proxy_allowance_lazy_store.ts
index 6d5a02adf..5a2c1d7ff 100644
--- a/packages/order-utils/src/store/balance_and_proxy_allowance_lazy_store.ts
+++ b/packages/order-utils/src/store/balance_and_proxy_allowance_lazy_store.ts
@@ -1,8 +1,10 @@
+import { AssetProxyId } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import { AbstractBalanceAndProxyAllowanceFetcher } from '../abstract/abstract_balance_and_proxy_allowance_fetcher';
import { AbstractBalanceAndProxyAllowanceLazyStore } from '../abstract/abstract_balance_and_proxy_allowance_lazy_store';
+import { assetDataUtils } from '../asset_data_utils';
/**
* Copy on read store for balances/proxyAllowances of tokens/accounts
@@ -74,6 +76,20 @@ export class BalanceAndProxyAllowanceLazyStore implements AbstractBalanceAndProx
}
}
}
+ public deleteAllERC721ProxyAllowance(tokenAddress: string, userAddress: string): void {
+ for (const assetData in this._proxyAllowance) {
+ if (this._proxyAllowance.hasOwnProperty(assetData)) {
+ const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData);
+ if (
+ decodedAssetData.assetProxyId === AssetProxyId.ERC721 &&
+ decodedAssetData.tokenAddress === tokenAddress &&
+ !_.isUndefined(this._proxyAllowance[assetData][userAddress])
+ ) {
+ delete this._proxyAllowance[assetData][userAddress];
+ }
+ }
+ }
+ }
public deleteAll(): void {
this._balance = {};
this._proxyAllowance = {};
diff --git a/packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts b/packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts
new file mode 100644
index 000000000..336c6d0ba
--- /dev/null
+++ b/packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts
@@ -0,0 +1,65 @@
+import { BigNumber } from '@0xproject/utils';
+import * as _ from 'lodash';
+
+import { AbstractOrderFilledCancelledFetcher } from '../abstract/abstract_order_filled_cancelled_fetcher';
+import { AbstractOrderFilledCancelledLazyStore } from '../abstract/abstract_order_filled_cancelled_lazy_store';
+
+/**
+ * Copy on read store for balances/proxyAllowances of tokens/accounts
+ */
+export class OrderFilledCancelledLazyStore implements AbstractOrderFilledCancelledLazyStore {
+ private readonly _orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher;
+ private _filledTakerAmount: {
+ [orderHash: string]: BigNumber;
+ };
+ private _isCancelled: {
+ [orderHash: string]: boolean;
+ };
+ constructor(orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher) {
+ this._orderFilledCancelledFetcher = orderFilledCancelledFetcher;
+ this._filledTakerAmount = {};
+ this._isCancelled = {};
+ }
+ public async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber> {
+ if (_.isUndefined(this._filledTakerAmount[orderHash])) {
+ const filledTakerAmount = await this._orderFilledCancelledFetcher.getFilledTakerAmountAsync(orderHash);
+ this.setFilledTakerAmount(orderHash, filledTakerAmount);
+ }
+ const cachedFilledTakerAmount = this._filledTakerAmount[orderHash];
+ return cachedFilledTakerAmount;
+ }
+ public setFilledTakerAmount(orderHash: string, filledTakerAmount: BigNumber): void {
+ this._filledTakerAmount[orderHash] = filledTakerAmount;
+ }
+ public deleteFilledTakerAmount(orderHash: string): void {
+ delete this._filledTakerAmount[orderHash];
+ }
+ public async getIsCancelledAsync(orderHash: string): Promise<boolean> {
+ if (_.isUndefined(this._isCancelled[orderHash])) {
+ const isCancelled = await this._orderFilledCancelledFetcher.isOrderCancelledAsync(orderHash);
+ this.setIsCancelled(orderHash, isCancelled);
+ }
+ const cachedIsCancelled = this._isCancelled[orderHash]; // tslint:disable-line:boolean-naming
+ return cachedIsCancelled;
+ }
+ public setIsCancelled(orderHash: string, isCancelled: boolean): void {
+ this._isCancelled[orderHash] = isCancelled;
+ }
+ public deleteIsCancelled(orderHash: string): void {
+ delete this._isCancelled[orderHash];
+ }
+ public deleteAll(): void {
+ this.deleteAllFilled();
+ this.deleteAllIsCancelled();
+ }
+ public deleteAllIsCancelled(): void {
+ this._isCancelled = {};
+ }
+ public deleteAllFilled(): void {
+ this._filledTakerAmount = {};
+ }
+ public getZRXAssetData(): string {
+ const zrxAssetData = this._orderFilledCancelledFetcher.getZRXAssetData();
+ return zrxAssetData;
+ }
+}