diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-03-30 02:08:52 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-04-21 04:56:17 +0800 |
commit | 75f77f3e8675c468d88456aec02561732c7646fb (patch) | |
tree | 6cbc55dca9fda65c7872e078ff134cf86107356c /packages/contracts/src/utils/formatters.ts | |
parent | 7a66da5a51603d4d87d644f3635f8c7f1d00bb36 (diff) | |
download | dexon-0x-contracts-75f77f3e8675c468d88456aec02561732c7646fb.tar dexon-0x-contracts-75f77f3e8675c468d88456aec02561732c7646fb.tar.gz dexon-0x-contracts-75f77f3e8675c468d88456aec02561732c7646fb.tar.bz2 dexon-0x-contracts-75f77f3e8675c468d88456aec02561732c7646fb.tar.lz dexon-0x-contracts-75f77f3e8675c468d88456aec02561732c7646fb.tar.xz dexon-0x-contracts-75f77f3e8675c468d88456aec02561732c7646fb.tar.zst dexon-0x-contracts-75f77f3e8675c468d88456aec02561732c7646fb.zip |
Add marketBuyOrders, rename variables, and fx old tests
Diffstat (limited to 'packages/contracts/src/utils/formatters.ts')
-rw-r--r-- | packages/contracts/src/utils/formatters.ts | 79 |
1 files changed, 30 insertions, 49 deletions
diff --git a/packages/contracts/src/utils/formatters.ts b/packages/contracts/src/utils/formatters.ts index 2b261f967..d70c03cb8 100644 --- a/packages/contracts/src/utils/formatters.ts +++ b/packages/contracts/src/utils/formatters.ts @@ -1,78 +1,59 @@ import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; -import { BatchCancelOrders, BatchFillOrders, MarketFillOrders, SignedOrder } from './types'; +import { orderUtils } from './order_utils'; +import { BatchCancelOrders, BatchFillOrders, MarketBuyOrders, MarketSellOrders, SignedOrder } from './types'; export const formatters = { - createBatchFill(signedOrders: SignedOrder[], takerTokenFillAmounts: BigNumber[] = []) { + createBatchFill(signedOrders: SignedOrder[], takerSellAmounts: BigNumber[] = []) { const batchFill: BatchFillOrders = { orders: [], signatures: [], - takerTokenFillAmounts, + takerSellAmounts, }; _.forEach(signedOrders, signedOrder => { - batchFill.orders.push({ - makerAddress: signedOrder.makerAddress, - takerAddress: signedOrder.takerAddress, - makerTokenAddress: signedOrder.makerTokenAddress, - takerTokenAddress: signedOrder.takerTokenAddress, - feeRecipientAddress: signedOrder.feeRecipientAddress, - makerTokenAmount: signedOrder.makerTokenAmount, - takerTokenAmount: signedOrder.takerTokenAmount, - makerFeeAmount: signedOrder.makerFeeAmount, - takerFeeAmount: signedOrder.takerFeeAmount, - expirationTimeSeconds: signedOrder.expirationTimeSeconds, - salt: signedOrder.salt, - }); + const orderStruct = orderUtils.getOrderStruct(signedOrder); + batchFill.orders.push(orderStruct); batchFill.signatures.push(signedOrder.signature); - if (takerTokenFillAmounts.length < signedOrders.length) { - batchFill.takerTokenFillAmounts.push(signedOrder.takerTokenAmount); + if (takerSellAmounts.length < signedOrders.length) { + batchFill.takerSellAmounts.push(signedOrder.makerBuyAmount); } }); return batchFill; }, - createMarketFillOrders(signedOrders: SignedOrder[], takerTokenFillAmount: BigNumber) { - const marketFillOrders: MarketFillOrders = { + createMarketSellOrders(signedOrders: SignedOrder[], takerSellAmount: BigNumber) { + const marketSellOrders: MarketSellOrders = { orders: [], signatures: [], - takerTokenFillAmount, + takerSellAmount, }; _.forEach(signedOrders, signedOrder => { - marketFillOrders.orders.push({ - makerAddress: signedOrder.makerAddress, - takerAddress: signedOrder.takerAddress, - makerTokenAddress: signedOrder.makerTokenAddress, - takerTokenAddress: signedOrder.takerTokenAddress, - feeRecipientAddress: signedOrder.feeRecipientAddress, - makerTokenAmount: signedOrder.makerTokenAmount, - takerTokenAmount: signedOrder.takerTokenAmount, - makerFeeAmount: signedOrder.makerFeeAmount, - takerFeeAmount: signedOrder.takerFeeAmount, - expirationTimeSeconds: signedOrder.expirationTimeSeconds, - salt: signedOrder.salt, - }); - marketFillOrders.signatures.push(signedOrder.signature); + const orderStruct = orderUtils.getOrderStruct(signedOrder); + marketSellOrders.orders.push(orderStruct); + marketSellOrders.signatures.push(signedOrder.signature); }); - return marketFillOrders; + return marketSellOrders; + }, + createMarketBuyOrders(signedOrders: SignedOrder[], takerBuyAmount: BigNumber) { + const marketBuyOrders: MarketBuyOrders = { + orders: [], + signatures: [], + takerBuyAmount, + }; + _.forEach(signedOrders, signedOrder => { + const orderStruct = orderUtils.getOrderStruct(signedOrder); + marketBuyOrders.orders.push(orderStruct); + marketBuyOrders.signatures.push(signedOrder.signature); + }); + return marketBuyOrders; }, createBatchCancel(signedOrders: SignedOrder[]) { const batchCancel: BatchCancelOrders = { orders: [], }; _.forEach(signedOrders, signedOrder => { - batchCancel.orders.push({ - makerAddress: signedOrder.makerAddress, - takerAddress: signedOrder.takerAddress, - makerTokenAddress: signedOrder.makerTokenAddress, - takerTokenAddress: signedOrder.takerTokenAddress, - feeRecipientAddress: signedOrder.feeRecipientAddress, - makerTokenAmount: signedOrder.makerTokenAmount, - takerTokenAmount: signedOrder.takerTokenAmount, - makerFeeAmount: signedOrder.makerFeeAmount, - takerFeeAmount: signedOrder.takerFeeAmount, - expirationTimeSeconds: signedOrder.expirationTimeSeconds, - salt: signedOrder.salt, - }); + const orderStruct = orderUtils.getOrderStruct(signedOrder); + batchCancel.orders.push(orderStruct); }); return batchCancel; }, |