aboutsummaryrefslogtreecommitdiffstats
path: root/test/utils/token_utils.ts
blob: 11d334619c324f3f277dc4cf93539a9d3dec807f (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
import * as _ from 'lodash';
import {Token, ZeroExError} from '../../src/types';

const PROTOCOL_TOKEN_SYMBOL = 'ZRX';

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(ZeroExError.CONTRACT_NOT_DEPLOYED_ON_NETWORK);
        }
        return zrxToken;
    }
    public getNonProtocolTokens(): Token[] {
        return _.filter(this.tokens, token => {
            return token.symbol !== PROTOCOL_TOKEN_SYMBOL;
        });
    }
}