@@ -22,7 +22,8 @@ import * as _ from 'lodash';
22
22
import * as Web3 from 'web3' ;
23
23
24
24
import { constants } from './constants' ;
25
- import { paddedBufferForPrimitive , bufferObjectWithProperties } from './encoding' ;
25
+ import { bufferObjectWithProperties } from './encoding' ;
26
+ import { generateTakerWalletOrdersBuffer } from './takerWallet' ;
26
27
import { Address , Bytes32 , Exchanges , IssuanceOrder , SolidityTypes , TakerWalletOrder } from './types' ;
27
28
28
29
export function generateTimestamp ( minutes : number ) : BigNumber {
@@ -91,67 +92,11 @@ export function generateSerializedOrders(
91
92
} ) ;
92
93
// Loop through all exchange orders and create buffers
93
94
_ . forEach ( exchanges , ( exchangeOrders , key ) => {
94
- const exchangeKey : number = constants . EXCHANGES [ key ] ;
95
- if ( exchangeKey === 1 ) {
96
- // Handle Zero Ex
97
- } else if ( exchangeKey === 2 ) {
98
- // Handle Kyber Network
99
- } else if ( exchangeKey === 3 ) {
95
+ if ( key === 'ZERO_EX' ) {
96
+ } else if ( key === 'KYBER' ) {
97
+ } else if ( key === 'TAKER_WALLET' ) {
100
98
orderBuffer . push ( generateTakerWalletOrdersBuffer ( makerTokenAddress , exchangeOrders , web3 ) ) ;
101
99
}
102
100
} ) ;
103
101
return ethUtil . bufferToHex ( Buffer . concat ( orderBuffer ) ) ;
104
102
}
105
-
106
- /* ============ Taker Wallet Order Functions ============ */
107
-
108
- /**
109
- * Takes a taker wallet order object and turns it into a buffer.
110
- *
111
- * @param takerTokenAddress Address of the token the taker will fill in the taker wallet order
112
- * @param takerTokenAmount Amount of tokens the taker will fill in the order
113
- * @param web3 web3 instance instantiated with `new Web3(provider);`
114
- * @return Taker wallet order as a buffer
115
- */
116
-
117
- export function takerWalletOrderToBuffer (
118
- takerTokenAddress : Address ,
119
- takerTokenAmount : BigNumber ,
120
- web3 : Web3 ,
121
- ) : Buffer {
122
- const takerWalletOrder : Buffer [ ] = [ ] ;
123
- takerWalletOrder . push ( paddedBufferForPrimitive ( takerTokenAddress ) ) ;
124
- takerWalletOrder . push ( paddedBufferForPrimitive ( web3 . toHex ( takerTokenAmount ) ) ) ;
125
- return Buffer . concat ( takerWalletOrder ) ;
126
- }
127
-
128
- /**
129
- * Takes taker wallet orders and generates a buffer representing all orders the
130
- * taker can fill directly from their wallet.
131
- *
132
- * @param makerTokenAddress Address of the token used to pay for the order
133
- * @param orders Array of TakerWalletOrders
134
- * @param web3 web3 instance instantiated with `new Web3(provider);`
135
- * @return Entire taker wallet orders data as a buffer
136
- */
137
-
138
- export function generateTakerWalletOrdersBuffer (
139
- makerTokenAddress : Address ,
140
- orders : TakerWalletOrder [ ] ,
141
- web3 : Web3 ,
142
- ) : Buffer {
143
- // Generate header for taker wallet order
144
- const takerOrderHeader : Buffer [ ] = [
145
- paddedBufferForPrimitive ( constants . EXCHANGES . KYBER ) ,
146
- paddedBufferForPrimitive ( orders . length ) , // Include the number of orders as part of header
147
- paddedBufferForPrimitive ( makerTokenAddress ) ,
148
- paddedBufferForPrimitive ( 0 ) , // Taker wallet orders do not take any maker token to execute
149
- ] ;
150
- // Turn all taker wallet orders to buffers
151
- const takerOrderBody : Buffer [ ] = _ . map ( orders , ( { takerTokenAddress, takerTokenAmount} ) =>
152
- takerWalletOrderToBuffer ( takerTokenAddress , takerTokenAmount , web3 ) ) ;
153
- return Buffer . concat ( [
154
- Buffer . concat ( takerOrderHeader ) ,
155
- Buffer . concat ( takerOrderBody ) ,
156
- ] ) ;
157
- }
0 commit comments