aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/test/utils/token_utils.ts
blob: fe4886ba4ad397557070ab5c492f16204f965a06 (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
import { Token } from '@0xproject/types';
import * as _ from 'lodash';

import { InternalZeroExError } from '../../src/types';

const PROTOCOL_TOKEN_SYMBOL = 'ZRX';
const WETH_TOKEN_SYMBOL = 'WETH';

export class TokenUtils {
    private _tokens: Token[];
    constructor(tokens: Token[]) {
        this._tokens = tokens;
    }
    public getProtocolTokenOrThrow(): Token {
        const zrxToken = _.find(this._tokens, { symbol: PROTOCOL_TOKEN_SYMBOL });
        if (_.isUndefined(zrxToken)) {
            throw new Error(InternalZeroExError.ZrxNotInTokenRegistry);
        }
        return zrxToken;
    }
    public getWethTokenOrThrow(): Token {
        const wethToken = _.find(this._tokens, { symbol: WETH_TOKEN_SYMBOL });
        if (_.isUndefined(wethToken)) {
            throw new Error(InternalZeroExError.WethNotInTokenRegistry);
        }
        return wethToken;
    }
    public getDummyTokens(): Token[] {
        const dummyTokens = _.filter(this._tokens, token => {
            return !_.includes([PROTOCOL_TOKEN_SYMBOL, WETH_TOKEN_SYMBOL], token.symbol);
        });
        return dummyTokens;
    }
}