aboutsummaryrefslogtreecommitdiffstats
path: root/packages/forwarder-helper/src/utils/order_utils.ts
blob: d14c6a6d7d0013ad068a6b295cc74fc6d639d888 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';

export const orderUtils = {
    isOrderExpired(order: SignedOrder): boolean {
        const millisecondsInSecond = 1000;
        const currentUnixTimestampSec = new BigNumber(Date.now() / millisecondsInSecond).round();
        return order.expirationTimeSeconds.lessThan(currentUnixTimestampSec);
    },
    calculateRemainingMakerAssetAmount(order: SignedOrder, remainingTakerAssetAmount: BigNumber): BigNumber {
        const result = remainingTakerAssetAmount.eq(0)
            ? new BigNumber(0)
            : remainingTakerAssetAmount.times(order.makerAssetAmount).dividedToIntegerBy(order.takerAssetAmount);
        return result;
    },
};