aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src/order_factory.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-05-30 07:58:30 +0800
committerFabio Berger <me@fabioberger.com>2018-05-30 07:58:30 +0800
commit4874d55d03918b47967024777194d88a5f2bc1fc (patch)
tree4a53834e9424a8b33aa7d0edaf13de11f2e807a3 /packages/order-utils/src/order_factory.ts
parent10faa474950a902af943b3c51f3703491afa6520 (diff)
downloaddexon-0x-contracts-4874d55d03918b47967024777194d88a5f2bc1fc.tar.gz
dexon-0x-contracts-4874d55d03918b47967024777194d88a5f2bc1fc.tar.zst
dexon-0x-contracts-4874d55d03918b47967024777194d88a5f2bc1fc.zip
Initial refactor of order-utils. Move many utils from contracts into this package.
Diffstat (limited to 'packages/order-utils/src/order_factory.ts')
-rw-r--r--packages/order-utils/src/order_factory.ts58
1 files changed, 33 insertions, 25 deletions
diff --git a/packages/order-utils/src/order_factory.ts b/packages/order-utils/src/order_factory.ts
index 2759aac81..fe341b845 100644
--- a/packages/order-utils/src/order_factory.ts
+++ b/packages/order-utils/src/order_factory.ts
@@ -2,48 +2,56 @@ import { Provider, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
-import { getOrderHashHex } from './order_hash';
+import { orderHashUtils } from './order_hash';
import { generatePseudoRandomSalt } from './salt';
-import { signOrderHashAsync } from './signature_utils';
+import { ecSignOrderHashAsync, getVRSHexString } from './signature_utils';
const SHOULD_ADD_PERSONAL_MESSAGE_PREFIX = false;
export const orderFactory = {
async createSignedOrderAsync(
provider: Provider,
- maker: string,
- taker: string,
+ makerAddress: string,
+ takerAddress: string,
+ senderAddress: string,
makerFee: BigNumber,
takerFee: BigNumber,
- makerTokenAmount: BigNumber,
- makerTokenAddress: string,
- takerTokenAmount: BigNumber,
- takerTokenAddress: string,
- exchangeContractAddress: string,
- feeRecipient: string,
- expirationUnixTimestampSecIfExists?: BigNumber,
+ makerAssetAmount: BigNumber,
+ makerAssetData: string,
+ takerAssetAmount: BigNumber,
+ takerAssetData: string,
+ exchangeAddress: string,
+ feeRecipientAddress: string,
+ expirationTimeSecondsIfExists?: BigNumber,
): Promise<SignedOrder> {
const defaultExpirationUnixTimestampSec = new BigNumber(2524604400); // Close to infinite
- const expirationUnixTimestampSec = _.isUndefined(expirationUnixTimestampSecIfExists)
+ const expirationTimeSeconds = _.isUndefined(expirationTimeSecondsIfExists)
? defaultExpirationUnixTimestampSec
- : expirationUnixTimestampSecIfExists;
+ : expirationTimeSecondsIfExists;
const order = {
- maker,
- taker,
+ makerAddress,
+ takerAddress,
+ senderAddress,
makerFee,
takerFee,
- makerTokenAmount,
- takerTokenAmount,
- makerTokenAddress,
- takerTokenAddress,
+ makerAssetAmount,
+ takerAssetAmount,
+ makerAssetData,
+ takerAssetData,
salt: generatePseudoRandomSalt(),
- exchangeContractAddress,
- feeRecipient,
- expirationUnixTimestampSec,
+ exchangeAddress,
+ feeRecipientAddress,
+ expirationTimeSeconds,
};
- const orderHash = getOrderHashHex(order);
- const ecSignature = await signOrderHashAsync(provider, orderHash, maker, SHOULD_ADD_PERSONAL_MESSAGE_PREFIX);
- const signedOrder: SignedOrder = _.assign(order, { ecSignature });
+ const orderHash = orderHashUtils.getOrderHashHex(order);
+ const ecSignature = await ecSignOrderHashAsync(
+ provider,
+ orderHash,
+ makerAddress,
+ SHOULD_ADD_PERSONAL_MESSAGE_PREFIX,
+ );
+ const signature = getVRSHexString(ecSignature);
+ const signedOrder: SignedOrder = _.assign(order, { signature });
return signedOrder;
},
};