aboutsummaryrefslogtreecommitdiffstats
path: root/packages/deployer/src/utils/encoder.ts
blob: 806efbbca974465a939a733a6d5f54276a1d6203 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { AbiDefinition, AbiType, ContractAbi, DataItem } from '@0xproject/types';
import * as _ from 'lodash';
import * as web3Abi from 'web3-eth-abi';

export const encoder = {
    encodeConstructorArgsFromAbi(args: any[], abi: ContractAbi): string {
        const constructorTypes: string[] = [];
        _.each(abi, (element: AbiDefinition) => {
            if (element.type === AbiType.Constructor) {
                _.each(element.inputs, (input: DataItem) => {
                    constructorTypes.push(input.type);
                });
            }
        });
        const encodedParameters = web3Abi.encodeParameters(constructorTypes, args);
        return encodedParameters;
    },
};