aboutsummaryrefslogtreecommitdiffstats
path: root/test/utils/order_factory.ts
blob: ec16df22d99a44ee74870c327b1095490cda7da6 (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
import assign from 'lodash/assign';
import isUndefined from 'lodash/isUndefined';
import * as BigNumber from 'bignumber.js';
import {ZeroEx, SignedOrder} from '../../src';

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