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
45
46
47
48
49
|
import { SignedOrder } from '0x.js';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash';
import { crypto } from './crypto';
export const signedOrderUtils = {
createFill: (
signedOrder: SignedOrder,
shouldThrowOnInsufficientBalanceOrAllowance?: boolean,
fillTakerTokenAmount?: BigNumber,
) => {
const fill = {
...signedOrderUtils.getOrderAddressesAndValues(signedOrder),
fillTakerTokenAmount: fillTakerTokenAmount || signedOrder.takerTokenAmount,
shouldThrowOnInsufficientBalanceOrAllowance: !!shouldThrowOnInsufficientBalanceOrAllowance,
...signedOrder.ecSignature,
};
return fill;
},
createCancel(signedOrder: SignedOrder, cancelTakerTokenAmount?: BigNumber) {
const cancel = {
...signedOrderUtils.getOrderAddressesAndValues(signedOrder),
cancelTakerTokenAmount: cancelTakerTokenAmount || signedOrder.takerTokenAmount,
};
return cancel;
},
getOrderAddressesAndValues(signedOrder: SignedOrder) {
return {
orderAddresses: [
signedOrder.maker,
signedOrder.taker,
signedOrder.makerTokenAddress,
signedOrder.takerTokenAddress,
signedOrder.feeRecipient,
],
orderValues: [
signedOrder.makerTokenAmount,
signedOrder.takerTokenAmount,
signedOrder.makerFee,
signedOrder.takerFee,
signedOrder.expirationUnixTimestampSec,
signedOrder.salt,
],
};
},
};
|