aboutsummaryrefslogblamecommitdiffstats
path: root/test/utils/token_utils.ts
blob: 14788b299273d547844e7e456c9af0d2fc6a54fc (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                                                              
                                                                   



                                            
                                                                  

                                                          
                                 

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