aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/src
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-08-15 05:40:52 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-08-15 05:40:52 +0800
commitce88086e080e05ed71c1ef4e31f2d0ce530af67f (patch)
treef2022bb7bc42c9bc85cbef19c684b666e2d7f66f /packages/connect/src
parentc1cc92a46f9ebfa4408a5dc515f1e100fe3a7054 (diff)
downloaddexon-0x-contracts-ce88086e080e05ed71c1ef4e31f2d0ce530af67f.tar.gz
dexon-0x-contracts-ce88086e080e05ed71c1ef4e31f2d0ce530af67f.tar.zst
dexon-0x-contracts-ce88086e080e05ed71c1ef4e31f2d0ce530af67f.zip
Update types to reflect v2
Diffstat (limited to 'packages/connect/src')
-rw-r--r--packages/connect/src/http_client.ts22
-rw-r--r--packages/connect/src/index.ts6
-rw-r--r--packages/connect/src/schemas/fees_request_schema.ts18
-rw-r--r--packages/connect/src/schemas/orderbook_request_schema.ts6
-rw-r--r--packages/connect/src/schemas/orders_request_opts_schema.ts6
-rw-r--r--packages/connect/src/schemas/token_pairs_request_opts_schema.ts4
-rw-r--r--packages/connect/src/types.ts91
-rw-r--r--packages/connect/src/utils/orderbook_channel_message_parser.ts10
-rw-r--r--packages/connect/src/utils/relayer_response_json_parsers.ts20
-rw-r--r--packages/connect/src/utils/type_converters.ts6
-rw-r--r--packages/connect/src/ws_orderbook_channel.ts8
11 files changed, 95 insertions, 102 deletions
diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts
index 1b51ee429..b2e15775e 100644
--- a/packages/connect/src/http_client.ts
+++ b/packages/connect/src/http_client.ts
@@ -9,8 +9,8 @@ import { schemas as clientSchemas } from './schemas/schemas';
import {
AssetPairsRequestOpts,
Client,
- FeesRequest,
- FeesResponse,
+ OrderConfigRequest,
+ OrderConfigResponse,
HttpRequestOptions,
HttpRequestType,
OrderbookRequest,
@@ -65,8 +65,8 @@ export class HttpClient implements Client {
this._apiEndpointUrl = url.replace(TRAILING_SLASHES_REGEX, ''); // remove trailing slashes
}
/**
- * Retrieve token pair info from the API
- * @param requestOpts Options specifying token information to retrieve and page information, defaults to { page: 1, perPage: 100 }
+ * Retrieve assetData pair info from the API
+ * @param requestOpts Options specifying assetData information to retrieve and page information, defaults to { page: 1, perPage: 100 }
* @return The resulting TokenPairsItems that match the request
*/
public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise<TokenPairsItem[]> {
@@ -77,9 +77,9 @@ export class HttpClient implements Client {
const httpRequestOpts = {
params: _.defaults({}, requestOpts, DEFAULT_PAGED_REQUEST_OPTS),
};
- const responseJson = await this._requestAsync('/token_pairs', HttpRequestType.Get, httpRequestOpts);
- const tokenPairs = relayerResponseJsonParsers.parseTokenPairsJson(responseJson);
- return tokenPairs;
+ const responseJson = await this._requestAsync('/assetData_pairs', HttpRequestType.Get, httpRequestOpts);
+ const assetDataPairs = relayerResponseJsonParsers.parseTokenPairsJson(responseJson);
+ return assetDataPairs;
}
/**
* Retrieve orders from the API
@@ -132,16 +132,16 @@ export class HttpClient implements Client {
}
/**
* Retrieve fee information from the API
- * @param request A FeesRequest instance describing the specific fees to retrieve
- * @return The resulting FeesResponse that matches the request
+ * @param request A OrderConfigRequest instance describing the specific fees to retrieve
+ * @return The resulting OrderConfigResponse that matches the request
*/
- public async getOrderConfigAsync(request: FeesRequest): Promise<FeesResponse> {
+ public async getOrderConfigAsync(request: OrderConfigRequest): Promise<OrderConfigResponse> {
assert.doesConformToSchema('request', request, clientSchemas.feesRequestSchema);
const httpRequestOpts = {
payload: request,
};
const responseJson = await this._requestAsync('/fees', HttpRequestType.Post, httpRequestOpts);
- const fees = relayerResponseJsonParsers.parseFeesResponseJson(responseJson);
+ const fees = relayerResponseJsonParsers.parseOrderConfigResponseJson(responseJson);
return fees;
}
/**
diff --git a/packages/connect/src/index.ts b/packages/connect/src/index.ts
index a4fc39425..e57967714 100644
--- a/packages/connect/src/index.ts
+++ b/packages/connect/src/index.ts
@@ -2,8 +2,8 @@ export { HttpClient } from './http_client';
export { orderbookChannelFactory } from './orderbook_channel_factory';
export {
Client,
- FeesRequest,
- FeesResponse,
+ OrderConfigRequest,
+ OrderConfigResponse,
OrderbookChannel,
OrderbookChannelHandler,
OrderbookChannelSubscriptionOpts,
@@ -13,7 +13,7 @@ export {
PagedRequestOpts,
TokenPairsItem,
AssetPairsRequestOpts,
- TokenTradeInfo,
+ Asset,
} from './types';
export { Order, SignedOrder } from '@0xproject/types';
diff --git a/packages/connect/src/schemas/fees_request_schema.ts b/packages/connect/src/schemas/fees_request_schema.ts
index ff3d7b9d3..e41e49e09 100644
--- a/packages/connect/src/schemas/fees_request_schema.ts
+++ b/packages/connect/src/schemas/fees_request_schema.ts
@@ -1,26 +1,26 @@
export const feesRequestSchema = {
- id: '/FeesRequest',
+ id: '/OrderConfigRequest',
type: 'object',
properties: {
- exchangeContractAddress: { $ref: '/Address' },
+ exchangeAddress: { $ref: '/Address' },
maker: { $ref: '/Address' },
taker: { $ref: '/Address' },
makerTokenAddress: { $ref: '/Address' },
takerTokenAddress: { $ref: '/Address' },
- makerTokenAmount: { $ref: '/Number' },
- takerTokenAmount: { $ref: '/Number' },
- expirationUnixTimestampSec: { $ref: '/Number' },
+ makerAssetAmount: { $ref: '/Number' },
+ takerAssetAmount: { $ref: '/Number' },
+ expirationTimeSeconds: { $ref: '/Number' },
salt: { $ref: '/Number' },
},
required: [
- 'exchangeContractAddress',
+ 'exchangeAddress',
'maker',
'taker',
'makerTokenAddress',
'takerTokenAddress',
- 'makerTokenAmount',
- 'takerTokenAmount',
- 'expirationUnixTimestampSec',
+ 'makerAssetAmount',
+ 'takerAssetAmount',
+ 'expirationTimeSeconds',
'salt',
],
};
diff --git a/packages/connect/src/schemas/orderbook_request_schema.ts b/packages/connect/src/schemas/orderbook_request_schema.ts
index 5f3463242..cc75ada5c 100644
--- a/packages/connect/src/schemas/orderbook_request_schema.ts
+++ b/packages/connect/src/schemas/orderbook_request_schema.ts
@@ -2,8 +2,8 @@ export const orderBookRequestSchema = {
id: '/OrderBookRequest',
type: 'object',
properties: {
- baseTokenAddress: { $ref: '/Address' },
- quoteTokenAddress: { $ref: '/Address' },
+ baseAssetData: { $ref: '/Address' },
+ quoteAssetData: { $ref: '/Address' },
},
- required: ['baseTokenAddress', 'quoteTokenAddress'],
+ required: ['baseAssetData', 'quoteAssetData'],
};
diff --git a/packages/connect/src/schemas/orders_request_opts_schema.ts b/packages/connect/src/schemas/orders_request_opts_schema.ts
index 5facbc959..1a9f74f7f 100644
--- a/packages/connect/src/schemas/orders_request_opts_schema.ts
+++ b/packages/connect/src/schemas/orders_request_opts_schema.ts
@@ -2,12 +2,12 @@ export const ordersRequestOptsSchema = {
id: '/OrdersRequestOpts',
type: 'object',
properties: {
- exchangeContractAddress: { $ref: '/Address' },
+ exchangeAddress: { $ref: '/Address' },
tokenAddress: { $ref: '/Address' },
makerTokenAddress: { $ref: '/Address' },
takerTokenAddress: { $ref: '/Address' },
- tokenA: { $ref: '/Address' },
- tokenB: { $ref: '/Address' },
+ assetDataA: { $ref: '/Address' },
+ assetDataB: { $ref: '/Address' },
maker: { $ref: '/Address' },
taker: { $ref: '/Address' },
trader: { $ref: '/Address' },
diff --git a/packages/connect/src/schemas/token_pairs_request_opts_schema.ts b/packages/connect/src/schemas/token_pairs_request_opts_schema.ts
index dffd063d0..bf1caa20d 100644
--- a/packages/connect/src/schemas/token_pairs_request_opts_schema.ts
+++ b/packages/connect/src/schemas/token_pairs_request_opts_schema.ts
@@ -2,7 +2,7 @@ export const AssetPairsRequestOptsSchema = {
id: '/AssetPairsRequestOpts',
type: 'object',
properties: {
- tokenA: { $ref: '/Address' },
- tokenB: { $ref: '/Address' },
+ assetDataA: { $ref: '/Address' },
+ assetDataB: { $ref: '/Address' },
},
};
diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts
index ca56d251b..0f2242329 100644
--- a/packages/connect/src/types.ts
+++ b/packages/connect/src/types.ts
@@ -2,11 +2,12 @@ import { SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
export interface Client {
- getAssetPairsAsync: (requestOpts?: AssetPairsRequestOpts & PagedRequestOpts) => Promise<TokenPairsItem[]>;
- getOrdersAsync: (requestOpts?: OrdersRequestOpts & PagedRequestOpts) => Promise<SignedOrder[]>;
- getOrderAsync: (orderHash: string) => Promise<SignedOrder>;
+ getAssetPairsAsync: (requestOpts?: AssetPairsRequestOpts & PagedRequestOpts) => Promise<PaginatedCollection<TokenPairsItem>>;
+ getOrdersAsync: (requestOpts?: OrdersRequestOpts & PagedRequestOpts) => Promise<PaginatedCollection<APIOrder>>;
+ getOrderAsync: (orderHash: string) => Promise<APIOrder>;
getOrderbookAsync: (request: OrderbookRequest, requestOpts?: PagedRequestOpts) => Promise<OrderbookResponse>;
- getOrderConfigAsync: (request: FeesRequest) => Promise<FeesResponse>;
+ getOrderConfigAsync: (request: OrderConfigRequest) => Promise<OrderConfigResponse>;
+ getFeeRecipients: () => Promise<PaginatedCollection<string>>;
submitOrderAsync: (signedOrder: SignedOrder) => Promise<void>;
}
@@ -16,58 +17,45 @@ export interface OrderbookChannel {
}
/**
- * baseTokenAddress: The address of token designated as the baseToken in the currency pair calculation of price
- * quoteTokenAddress: The address of token designated as the quoteToken in the currency pair calculation of price
+ * baseAssetData: The address of assetData designated as the baseToken in the currency pair calculation of price
+ * quoteAssetData: The address of assetData designated as the quoteToken in the currency pair calculation of price
* snapshot: If true, a snapshot of the orderbook will be sent before the updates to the orderbook
* limit: Maximum number of bids and asks in orderbook snapshot
*/
export interface OrderbookChannelSubscriptionOpts {
- baseTokenAddress: string;
- quoteTokenAddress: string;
+ baseAssetData: string;
+ quoteAssetData: string;
snapshot: boolean;
limit: number;
}
export interface OrderbookChannelHandler {
- onSnapshot: (
- channel: OrderbookChannel,
- subscriptionOpts: OrderbookChannelSubscriptionOpts,
- snapshot: OrderbookResponse,
- ) => void;
onUpdate: (
channel: OrderbookChannel,
subscriptionOpts: OrderbookChannelSubscriptionOpts,
- order: SignedOrder,
+ order: APIOrder,
) => void;
onError: (channel: OrderbookChannel, err: Error, subscriptionOpts?: OrderbookChannelSubscriptionOpts) => void;
onClose: (channel: OrderbookChannel) => void;
}
-export type OrderbookChannelMessage =
- | SnapshotOrderbookChannelMessage
- | UpdateOrderbookChannelMessage
- | UnknownOrderbookChannelMessage;
+export type OrdersChannelMessage =
+ | UpdateOrdersChannelMessage
+ | UnknownOrdersChannelMessage;
-export enum OrderbookChannelMessageTypes {
- Snapshot = 'snapshot',
+export enum OrdersChannelMessageTypes {
Update = 'update',
Unknown = 'unknown',
}
-export interface SnapshotOrderbookChannelMessage {
- type: OrderbookChannelMessageTypes.Snapshot;
- requestId: number;
- payload: OrderbookResponse;
-}
-
-export interface UpdateOrderbookChannelMessage {
- type: OrderbookChannelMessageTypes.Update;
+export interface UpdateOrdersChannelMessage {
+ type: OrdersChannelMessageTypes.Update;
requestId: number;
- payload: SignedOrder;
+ payload: APIOrder;
}
-export interface UnknownOrderbookChannelMessage {
- type: OrderbookChannelMessageTypes.Unknown;
+export interface UnknownOrdersChannelMessage {
+ type: OrdersChannelMessageTypes.Unknown;
requestId: number;
payload: undefined;
}
@@ -83,25 +71,30 @@ export enum WebsocketClientEventType {
ConnectFailed = 'connectFailed',
}
+export interface APIOrder {
+ order: SignedOrder;
+ metaData: object;
+}
+
export interface AssetPairsRequestOpts {
- tokenA?: string;
- tokenB?: string;
+ assetDataA?: string;
+ assetDataB?: string;
}
export interface TokenPairsItem {
- tokenA: TokenTradeInfo;
- tokenB: TokenTradeInfo;
+ assetDataA: Asset;
+ assetDataB: Asset;
}
-export interface TokenTradeInfo {
- address: string;
+export interface Asset {
+ assetData: string;
minAmount: BigNumber;
maxAmount: BigNumber;
precision: number;
}
export interface OrdersRequestOpts {
- exchangeContractAddress?: string;
+ exchangeAddress?: string;
tokenAddress?: string;
makerTokenAddress?: string;
takerTokenAddress?: string;
@@ -112,35 +105,35 @@ export interface OrdersRequestOpts {
}
export interface OrderbookRequest {
- baseTokenAddress: string;
- quoteTokenAddress: string;
+ baseAssetData: string;
+ quoteAssetData: string;
}
export interface OrderbookResponse {
- bids: SignedOrder[];
- asks: SignedOrder[];
+ bids: PaginatedCollection<APIOrder>;
+ asks: PaginatedCollection<APIOrder>;
}
-export interface PaginatedCollectionResponse<T> {
+export interface PaginatedCollection<T> {
total: number;
page: number;
perPage: number;
records: T[];
}
-export interface FeesRequest {
- exchangeContractAddress: string;
+export interface OrderConfigRequest {
+ exchangeAddress: string;
maker: string;
taker: string;
makerTokenAddress: string;
takerTokenAddress: string;
- makerTokenAmount: BigNumber;
- takerTokenAmount: BigNumber;
- expirationUnixTimestampSec: BigNumber;
+ makerAssetAmount: BigNumber;
+ takerAssetAmount: BigNumber;
+ expirationTimeSeconds: BigNumber;
salt: BigNumber;
}
-export interface FeesResponse {
+export interface OrderConfigResponse {
feeRecipient: string;
makerFee: BigNumber;
takerFee: BigNumber;
diff --git a/packages/connect/src/utils/orderbook_channel_message_parser.ts b/packages/connect/src/utils/orderbook_channel_message_parser.ts
index 593288078..ca739e587 100644
--- a/packages/connect/src/utils/orderbook_channel_message_parser.ts
+++ b/packages/connect/src/utils/orderbook_channel_message_parser.ts
@@ -2,12 +2,12 @@ import { assert } from '@0xproject/assert';
import { schemas } from '@0xproject/json-schemas';
import * as _ from 'lodash';
-import { OrderbookChannelMessage, OrderbookChannelMessageTypes } from '../types';
+import { OrdersChannelMessage, OrdersChannelMessageTypes } from '../types';
import { relayerResponseJsonParsers } from './relayer_response_json_parsers';
export const orderbookChannelMessageParser = {
- parse(utf8Data: string): OrderbookChannelMessage {
+ parse(utf8Data: string): OrdersChannelMessage {
// parse the message
const messageObj = JSON.parse(utf8Data);
// ensure we have a type parameter to switch on
@@ -19,13 +19,13 @@ export const orderbookChannelMessageParser = {
assert.assert(!_.isUndefined(requestId), `Message is missing a requestId parameter: ${utf8Data}`);
assert.isNumber('requestId', requestId);
switch (type) {
- case OrderbookChannelMessageTypes.Snapshot: {
+ case OrdersChannelMessageTypes.Snapshot: {
assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrderbookChannelSnapshotSchema);
const orderbookJson = messageObj.payload;
const orderbook = relayerResponseJsonParsers.parseOrderbookResponseJson(orderbookJson);
return _.assign(messageObj, { payload: orderbook });
}
- case OrderbookChannelMessageTypes.Update: {
+ case OrdersChannelMessageTypes.Update: {
assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrderbookChannelUpdateSchema);
const orderJson = messageObj.payload;
const order = relayerResponseJsonParsers.parseOrderJson(orderJson);
@@ -33,7 +33,7 @@ export const orderbookChannelMessageParser = {
}
default: {
return {
- type: OrderbookChannelMessageTypes.Unknown,
+ type: OrdersChannelMessageTypes.Unknown,
requestId,
payload: undefined,
};
diff --git a/packages/connect/src/utils/relayer_response_json_parsers.ts b/packages/connect/src/utils/relayer_response_json_parsers.ts
index ccae8b115..55f787820 100644
--- a/packages/connect/src/utils/relayer_response_json_parsers.ts
+++ b/packages/connect/src/utils/relayer_response_json_parsers.ts
@@ -2,19 +2,19 @@ import { assert } from '@0xproject/assert';
import { schemas } from '@0xproject/json-schemas';
import { SignedOrder } from '@0xproject/types';
-import { FeesResponse, OrderbookResponse, TokenPairsItem } from '../types';
+import { OrderConfigResponse, OrderbookResponse, TokenPairsItem } from '../types';
import { typeConverters } from './type_converters';
export const relayerResponseJsonParsers = {
parseTokenPairsJson(json: any): TokenPairsItem[] {
- assert.doesConformToSchema('tokenPairs', json, schemas.relayerApiTokenPairsResponseSchema);
- return json.map((tokenPair: any) => {
- return typeConverters.convertStringsFieldsToBigNumbers(tokenPair, [
- 'tokenA.minAmount',
- 'tokenA.maxAmount',
- 'tokenB.minAmount',
- 'tokenB.maxAmount',
+ assert.doesConformToSchema('assetDataPairs', json, schemas.relayerApiTokenPairsResponseSchema);
+ return json.map((assetDataPair: any) => {
+ return typeConverters.convertStringsFieldsToBigNumbers(assetDataPair, [
+ 'assetDataA.minAmount',
+ 'assetDataA.maxAmount',
+ 'assetDataB.minAmount',
+ 'assetDataB.maxAmount',
]);
});
},
@@ -30,8 +30,8 @@ export const relayerResponseJsonParsers = {
assert.doesConformToSchema('orderBook', json, schemas.relayerApiOrderBookResponseSchema);
return typeConverters.convertOrderbookStringFieldsToBigNumber(json);
},
- parseFeesResponseJson(json: any): FeesResponse {
- assert.doesConformToSchema('fees', json, schemas.relayerApiFeesResponseSchema);
+ parseOrderConfigResponseJson(json: any): OrderConfigResponse {
+ assert.doesConformToSchema('fees', json, schemas.relayerApiOrderConfigResponseSchema);
return typeConverters.convertStringsFieldsToBigNumbers(json, ['makerFee', 'takerFee']);
},
};
diff --git a/packages/connect/src/utils/type_converters.ts b/packages/connect/src/utils/type_converters.ts
index 210d452b9..513f9b39f 100644
--- a/packages/connect/src/utils/type_converters.ts
+++ b/packages/connect/src/utils/type_converters.ts
@@ -12,11 +12,11 @@ export const typeConverters = {
},
convertOrderStringFieldsToBigNumber(order: any): any {
return typeConverters.convertStringsFieldsToBigNumbers(order, [
- 'makerTokenAmount',
- 'takerTokenAmount',
+ 'makerAssetAmount',
+ 'takerAssetAmount',
'makerFee',
'takerFee',
- 'expirationUnixTimestampSec',
+ 'expirationTimeSeconds',
'salt',
]);
},
diff --git a/packages/connect/src/ws_orderbook_channel.ts b/packages/connect/src/ws_orderbook_channel.ts
index fa9f5e37f..d09fd375d 100644
--- a/packages/connect/src/ws_orderbook_channel.ts
+++ b/packages/connect/src/ws_orderbook_channel.ts
@@ -4,8 +4,8 @@ import * as WebSocket from 'websocket';
import {
OrderbookChannel,
OrderbookChannelHandler,
- OrderbookChannelMessageTypes,
OrderbookChannelSubscriptionOpts,
+ OrdersChannelMessageTypes,
} from './types';
import { assert } from './utils/assert';
import { orderbookChannelMessageParser } from './utils/orderbook_channel_message_parser';
@@ -44,7 +44,7 @@ export class WebSocketOrderbookChannel implements OrderbookChannel {
/**
* Subscribe to orderbook snapshots and updates from the websocket
* @param subscriptionOpts An OrderbookChannelSubscriptionOpts instance describing which
- * token pair to subscribe to
+ * assetData pair to subscribe to
*/
public subscribe(subscriptionOpts: OrderbookChannelSubscriptionOpts): void {
assert.isOrderbookChannelSubscriptionOpts('subscriptionOpts', subscriptionOpts);
@@ -82,11 +82,11 @@ export class WebSocketOrderbookChannel implements OrderbookChannel {
return;
}
switch (parserResult.type) {
- case OrderbookChannelMessageTypes.Snapshot: {
+ case OrdersChannelMessageTypes.Snapshot: {
this._handler.onSnapshot(this, subscriptionOpts, parserResult.payload);
break;
}
- case OrderbookChannelMessageTypes.Update: {
+ case OrdersChannelMessageTypes.Update: {
this._handler.onUpdate(this, subscriptionOpts, parserResult.payload);
break;
}