From 9f5eeed30930eea59e9922569a15cb5d689f3eeb Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 10 Dec 2018 14:37:48 -0800 Subject: Rename core package to protocol --- .../utils/simple_order_filled_cancelled_fetcher.ts | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 contracts/protocol/test/utils/simple_order_filled_cancelled_fetcher.ts (limited to 'contracts/protocol/test/utils/simple_order_filled_cancelled_fetcher.ts') diff --git a/contracts/protocol/test/utils/simple_order_filled_cancelled_fetcher.ts b/contracts/protocol/test/utils/simple_order_filled_cancelled_fetcher.ts new file mode 100644 index 000000000..af959e00e --- /dev/null +++ b/contracts/protocol/test/utils/simple_order_filled_cancelled_fetcher.ts @@ -0,0 +1,31 @@ +import { AbstractOrderFilledCancelledFetcher, orderHashUtils } from '@0x/order-utils'; +import { SignedOrder } from '@0x/types'; +import { BigNumber } from '@0x/utils'; + +import { ExchangeWrapper } from './exchange_wrapper'; + +export class SimpleOrderFilledCancelledFetcher implements AbstractOrderFilledCancelledFetcher { + private readonly _exchangeWrapper: ExchangeWrapper; + private readonly _zrxAssetData: string; + constructor(exchange: ExchangeWrapper, zrxAssetData: string) { + this._exchangeWrapper = exchange; + this._zrxAssetData = zrxAssetData; + } + public async getFilledTakerAmountAsync(orderHash: string): Promise { + const filledTakerAmount = new BigNumber(await this._exchangeWrapper.getTakerAssetFilledAmountAsync(orderHash)); + return filledTakerAmount; + } + public async isOrderCancelledAsync(signedOrder: SignedOrder): Promise { + const orderHash = orderHashUtils.getOrderHashHex(signedOrder); + const isCancelled = await this._exchangeWrapper.isCancelledAsync(orderHash); + const orderEpoch = await this._exchangeWrapper.getOrderEpochAsync( + signedOrder.makerAddress, + signedOrder.senderAddress, + ); + const isCancelledByOrderEpoch = orderEpoch > signedOrder.salt; + return isCancelled || isCancelledByOrderEpoch; + } + public getZRXAssetData(): string { + return this._zrxAssetData; + } +} -- cgit v1.2.3