Skip to content

Commit a02bab9

Browse files
committed
Cleanup: Clean up constants
1 parent dafa3f0 commit a02bab9

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { BigNumber } from 'bignumber.js';
22

3+
import { Constants } from './types';
34

4-
export const constants = {
5+
export const constants: Constants = {
56
EXCHANGES: {
67
ZERO_EX: 1,
78
KYBER: 2,

src/orders.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ import * as Web3 from 'web3';
2323

2424
import { constants } from './constants';
2525
import { paddedBufferForPrimitive, bufferObjectWithProperties } from './encoding';
26-
import { Address, Bytes32, IssuanceOrder, SolidityTypes, TakerWalletOrder } from './types';
27-
28-
interface Exchanges {
29-
[exchangeId: string]: TakerWalletOrder[];
30-
}
26+
import { Address, Bytes32, Exchanges, IssuanceOrder, SolidityTypes, TakerWalletOrder } from './types';
3127

3228
export function generateTimestamp(minutes: number): BigNumber {
3329
const timeToExpiration = minutes * 60 * 1000;
@@ -84,22 +80,23 @@ export function generateSerializedOrders(
8480
const orderBuffer: Buffer[] = [];
8581
// Sort exchange orders by exchange
8682
const exchanges: Exchanges = {
87-
'1': [],
88-
'2': [],
89-
'3': [],
83+
'ZERO_EX': [],
84+
'KYBER': [],
85+
'TAKER_WALLET': [],
9086
};
9187
_.forEach(orders, (order: TakerWalletOrder) => {
9288
const { exchange } = order;
93-
const exchangeOrders: object[] = exchanges[exchange];
89+
const exchangeOrders: TakerWalletOrder[] = exchanges[exchange];
9490
exchangeOrders.push(order);
9591
});
9692
// Loop through all exchange orders and create buffers
9793
_.forEach(exchanges, (exchangeOrders, key) => {
98-
if (key === '1') { // Todo: Replace with set-protocol-contracts constants
94+
const exchangeKey: number = constants.EXCHANGES[key];
95+
if (exchangeKey === 1) {
9996
// Handle Zero Ex
100-
} else if (key === '2') {
97+
} else if (exchangeKey === 2) {
10198
// Handle Kyber Network
102-
} else if (key === '3') {
99+
} else if (exchangeKey === 3) {
103100
orderBuffer.push(generateTakerWalletOrdersBuffer(makerTokenAddress, exchangeOrders, web3));
104101
}
105102
});
@@ -145,7 +142,7 @@ export function generateTakerWalletOrdersBuffer(
145142
): Buffer {
146143
// Generate header for taker wallet order
147144
const takerOrderHeader: Buffer[] = [
148-
paddedBufferForPrimitive(3), // Todo: Replace with set-protocol-contracts constants
145+
paddedBufferForPrimitive(constants.EXCHANGES.KYBER),
149146
paddedBufferForPrimitive(orders.length), // Include the number of orders as part of header
150147
paddedBufferForPrimitive(makerTokenAddress),
151148
paddedBufferForPrimitive(0), // Taker wallet orders do not take any maker token to execute

src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ export type Bytes32 = string;
66
export type Bytes = string;
77
export type UInt = number | BigNumber;
88

9+
export interface Constants {
10+
[constantId: string]: any;
11+
}
12+
913
export interface ECSig {
1014
v: UInt;
1115
r: string;
1216
s: string;
1317
}
1418

19+
export interface Exchanges {
20+
[exchangeId: string]: TakerWalletOrder[];
21+
}
22+
1523
export interface IssuanceOrder {
1624
setAddress: Address;
1725
makerAddress: Address;

0 commit comments

Comments
 (0)