aboutsummaryrefslogtreecommitdiffstats
path: root/packages/asset-buyer/src/utils/assert.ts
blob: 0085ca41e8f8c9151206c3ede6ad7ac9d982bb8f (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
import { assert as sharedAssert } from '@0xproject/assert';
import { schemas } from '@0xproject/json-schemas';
import * as _ from 'lodash';

import { BuyQuote, OrderFetcher, OrderFetcherRequest } from '../types';

export const assert = {
    ...sharedAssert,
    isValidBuyQuote(variableName: string, buyQuote: BuyQuote): void {
        sharedAssert.isHexString(`${variableName}.assetData`, buyQuote.assetData);
        sharedAssert.doesConformToSchema(`${variableName}.orders`, buyQuote.orders, schemas.signedOrdersSchema);
        sharedAssert.doesConformToSchema(`${variableName}.feeOrders`, buyQuote.feeOrders, schemas.signedOrdersSchema);
        sharedAssert.isBigNumber(`${variableName}.minRate`, buyQuote.minRate);
        sharedAssert.isBigNumber(`${variableName}.maxRate`, buyQuote.maxRate);
        sharedAssert.isBigNumber(`${variableName}.assetBuyAmount`, buyQuote.assetBuyAmount);
        if (!_.isUndefined(buyQuote.feePercentage)) {
            sharedAssert.isNumber(`${variableName}.feePercentage`, buyQuote.feePercentage);
        }
    },
    isValidOrderFetcher(variableName: string, orderFetcher: OrderFetcher): void {
        sharedAssert.isFunction(`${variableName}.fetchOrdersAsync`, orderFetcher.fetchOrdersAsync);
    },
    isValidOrderFetcherRequest(variableName: string, orderFetcherRequest: OrderFetcherRequest): void {
        sharedAssert.isHexString(`${variableName}.makerAssetData`, orderFetcherRequest.makerAssetData);
        sharedAssert.isHexString(`${variableName}.takerAssetData`, orderFetcherRequest.takerAssetData);
        sharedAssert.isNumber(`${variableName}.networkId`, orderFetcherRequest.networkId);
    },
};