aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src/utils.ts
blob: 64195dbedb97ce5400e0ccecc48724492c32d06a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { BigNumber } from '@0x/utils';

export const utils = {
    getSignatureTypeIndexIfExists(signature: string): number {
        // tslint:disable-next-line:custom-no-magic-numbers
        const signatureTypeHex = signature.slice(-2);
        const base = 16;
        const signatureTypeInt = parseInt(signatureTypeHex, base);
        return signatureTypeInt;
    },
    getCurrentUnixTimestampSec(): BigNumber {
        const milisecondsInSecond = 1000;
        return new BigNumber(Date.now() / milisecondsInSecond).integerValue();
    },
    getPartialAmountFloor(numerator: BigNumber, denominator: BigNumber, target: BigNumber): BigNumber {
        const fillMakerTokenAmount = numerator
            .multipliedBy(target)
            .div(denominator)
            .integerValue(0);
        return fillMakerTokenAmount;
    },
};