aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/util/signed_order_utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/util/signed_order_utils.ts')
-rw-r--r--packages/contracts/util/signed_order_utils.ts49
1 files changed, 49 insertions, 0 deletions
diff --git a/packages/contracts/util/signed_order_utils.ts b/packages/contracts/util/signed_order_utils.ts
new file mode 100644
index 000000000..fc2f800cd
--- /dev/null
+++ b/packages/contracts/util/signed_order_utils.ts
@@ -0,0 +1,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,
+ ],
+ };
+ },
+};