aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/test/utils/order_factory.ts
blob: 04768af65c4a6c2ccf4a4229fafca329f033be2c (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
35
36
37
38
39
40
41
42
43
44
import BigNumber from 'bignumber.js';
import * as _ from 'lodash';

import { SignedOrder, ZeroEx } from '../../src';

export const orderFactory = {
    async createSignedOrderAsync(
        zeroEx: ZeroEx,
        maker: string,
        taker: string,
        makerFee: BigNumber,
        takerFee: BigNumber,
        makerTokenAmount: BigNumber,
        makerTokenAddress: string,
        takerTokenAmount: BigNumber,
        takerTokenAddress: string,
        exchangeContractAddress: string,
        feeRecipient: string,
        expirationUnixTimestampSecIfExists?: BigNumber,
    ): Promise<SignedOrder> {
        const defaultExpirationUnixTimestampSec = new BigNumber(2524604400); // Close to infinite
        const expirationUnixTimestampSec = _.isUndefined(expirationUnixTimestampSecIfExists)
            ? defaultExpirationUnixTimestampSec
            : expirationUnixTimestampSecIfExists;
        const order = {
            maker,
            taker,
            makerFee,
            takerFee,
            makerTokenAmount,
            takerTokenAmount,
            makerTokenAddress,
            takerTokenAddress,
            salt: ZeroEx.generatePseudoRandomSalt(),
            exchangeContractAddress,
            feeRecipient,
            expirationUnixTimestampSec,
        };
        const orderHash = ZeroEx.getOrderHashHex(order);
        const ecSignature = await zeroEx.signOrderHashAsync(orderHash, maker);
        const signedOrder: SignedOrder = _.assign(order, { ecSignature });
        return signedOrder;
    },
};