aboutsummaryrefslogblamecommitdiffstats
path: root/packages/0x.js/test/utils/order_factory.ts
blob: 08f2081a4097f54f043f3466a8a40ca9c32e567a (plain) (tree)
1
2
3
4
5
6
7
8
                                             

                            
                                                
 

                                                 
                             




































                                                                                                                  
  
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';

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

const SHOULD_ADD_PERSONAL_MESSAGE_PREFIX = false;

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, SHOULD_ADD_PERSONAL_MESSAGE_PREFIX);
        const signedOrder: SignedOrder = _.assign(order, { ecSignature });
        return signedOrder;
    },
};