diff options
author | Ara Kevonian <ara@dextroid.io> | 2018-04-10 18:46:43 +0800 |
---|---|---|
committer | Ara Kevonian <ara@dextroid.io> | 2018-04-10 18:46:43 +0800 |
commit | bf0ef055fbd4f5f798ea56868ad0beddf1111e7f (patch) | |
tree | 9d91f4ccc25e5c93638d8432c9851f293665b0bd /packages | |
parent | c80b42712a9fc73c05c32cd3d3396a6a02a7969f (diff) | |
download | dexon-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')
-rw-r--r-- | packages/0x.js/CHANGELOG.json | 4 | ||||
-rw-r--r-- | packages/0x.js/CHANGELOG.md | 4 | ||||
-rw-r--r-- | packages/0x.js/package.json | 25 | ||||
-rw-r--r-- | packages/0x.js/src/fetchers/balance_and_allowance_fetcher.ts | 6 | ||||
-rw-r--r-- | packages/0x.js/src/fetchers/order_filled_cancelled_fetcher.ts | 6 | ||||
-rw-r--r-- | packages/0x.js/src/stores/balance_proxy_allowance_lazy_store.ts | 3 | ||||
-rw-r--r-- | packages/0x.js/src/stores/order_filled_cancelled_lazy_store.ts | 3 | ||||
-rw-r--r-- | packages/0x.js/src/utils/order_state_utils.ts | 30 |
8 files changed, 50 insertions, 31 deletions
diff --git a/packages/0x.js/CHANGELOG.json b/packages/0x.js/CHANGELOG.json index 6d5dc0dd2..91bd75f65 100644 --- a/packages/0x.js/CHANGELOG.json +++ b/packages/0x.js/CHANGELOG.json @@ -5,6 +5,10 @@ { "note": "Moved Web3.Provider to `@0xproject/types:Provider`", "pr": 501 + }, + { + "note": "Add `zeroEx.exchange.getOrderStateAsync` to allow obtaining current OrderState for a signedOrder", + "pr": 510 } ] }, diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 76f82d93e..c18915417 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -5,10 +5,6 @@ Edit the package's CHANGELOG.json file only. CHANGELOG -## v0.36.0 - TBD - - * Add `zeroEx.exchange.getOrderStateAsync` to allow obtaining current OrderState for a signedOrder - ## v0.35.0 - _April 2, 2018_ * Removed `ZeroExError.TransactionMiningTimeout` and moved it to '@0xproject/web3_wrapper' `Web3WrapperErrors.TransactionMiningTimeout` (#485) diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index e62f948b4..882b40733 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -2,38 +2,43 @@ "name": "0x.js", "version": "0.35.0", "description": "A javascript library for interacting with the 0x protocol", - "keywords": ["0x.js", "0xproject", "ethereum", "tokens", "exchange"], + "keywords": [ + "0x.js", + "0xproject", + "ethereum", + "tokens", + "exchange" + ], "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "scripts": { "build:watch": "tsc -w", "prebuild": "run-s clean generate_contract_wrappers", "build": "run-p build:umd:prod build:commonjs; exit 0;", - "generate_contract_wrappers": - "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'", + "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'", "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", "test:circleci": "run-s test:coverage", "test": "run-s clean test:commonjs", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", - "update_contracts": - "for i in ${npm_package_config_artifacts}; do copyfiles -u 4 ../contracts/build/contracts/$i.json ../0x.js/src/artifacts; done;", + "update_contracts": "for i in ${npm_package_config_artifacts}; do copyfiles -u 4 ../contracts/build/contracts/$i.json ../0x.js/src/artifacts; done;", "clean": "shx rm -rf _bundles lib test_temp scripts", "build:umd:prod": "NODE_ENV=production webpack", - "build:commonjs": - "tsc && copyfiles -u 2 './src/artifacts/**/*.json' ./lib/src/artifacts && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", + "build:commonjs": "tsc && copyfiles -u 2 './src/artifacts/**/*.json' ./lib/src/artifacts && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "test:commonjs": "run-s build:commonjs run_mocha", "run_mocha": "mocha lib/test/**/*_test.js --timeout 10000 --bail --exit", "manual:postpublish": "yarn build; node ./scripts/postpublish.js", "docs:stage": "yarn build && node ./scripts/stage_docs.js", "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES", - "upload_docs_json": - "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json" + "upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json" }, "config": { "artifacts": "TokenTransferProxy Exchange TokenRegistry Token EtherToken", "postpublish": { - "assets": ["packages/0x.js/_bundles/index.js", "packages/0x.js/_bundles/index.min.js"], + "assets": [ + "packages/0x.js/_bundles/index.js", + "packages/0x.js/_bundles/index.min.js" + ], "docPublishConfigs": { "extraFileIncludes": [ "../types/src/index.ts", 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); |