aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers/src/fetchers/order_filled_cancelled_fetcher.ts
blob: 5d350916cf7d9510cf5be2746d2c39f8c0b50599 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// tslint:disable:no-unnecessary-type-assertion
import { AbstractOrderFilledCancelledFetcher, orderHashUtils } from '@0x/order-utils';
import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { BlockParamLiteral } from 'ethereum-types';

import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper';

export class OrderFilledCancelledFetcher implements AbstractOrderFilledCancelledFetcher {
    private readonly _exchange: ExchangeWrapper;
    private readonly _stateLayer: BlockParamLiteral;
    constructor(exchange: ExchangeWrapper, stateLayer: BlockParamLiteral) {
        this._exchange = exchange;
        this._stateLayer = stateLayer;
    }
    public async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber> {
        const filledTakerAmount = this._exchange.getFilledTakerAssetAmountAsync(orderHash, {
            defaultBlock: this._stateLayer,
        });
        return filledTakerAmount;
    }
    public async isOrderCancelledAsync(signedOrder: SignedOrder): Promise<boolean> {
        const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
        const isCancelled = await this._exchange.isCancelledAsync(orderHash);
        const orderEpoch = await this._exchange.getOrderEpochAsync(
            signedOrder.makerAddress,
            signedOrder.senderAddress,
            {
                defaultBlock: this._stateLayer,
            },
        );
        const isCancelledByOrderEpoch = orderEpoch > signedOrder.salt;
        return isCancelled || isCancelledByOrderEpoch;
    }
    public getZRXAssetData(): string {
        const zrxAssetData = this._exchange.getZRXAssetData();
        return zrxAssetData;
    }
}