Remove chainId from json-schemas and connect
This commit is contained in:
parent
3b9d84fa58
commit
403ceebff9
@ -379,19 +379,6 @@ ___
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Interface: RequestOpts
|
|
||||||
|
|
||||||
|
|
||||||
## Properties
|
|
||||||
|
|
||||||
### `Optional` chainId
|
|
||||||
|
|
||||||
• **chainId**? : *undefined | number*
|
|
||||||
|
|
||||||
*Defined in [types/src/index.ts:487](https://github.com/0xProject/0x-monorepo/blob/c93b02d55/packages/types/src/index.ts#L487)*
|
|
||||||
|
|
||||||
<hr />
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Interface: SignedOrder
|
# Interface: SignedOrder
|
||||||
|
@ -12,7 +12,6 @@ import {
|
|||||||
OrdersRequestOpts,
|
OrdersRequestOpts,
|
||||||
OrdersResponse,
|
OrdersResponse,
|
||||||
PagedRequestOpts,
|
PagedRequestOpts,
|
||||||
RequestOpts,
|
|
||||||
SignedOrder,
|
SignedOrder,
|
||||||
} from '@0x/types';
|
} from '@0x/types';
|
||||||
import { fetchAsync } from '@0x/utils';
|
import { fetchAsync } from '@0x/utils';
|
||||||
@ -53,16 +52,15 @@ export class HttpClient {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Retrieve assetData pair info from the API
|
* Retrieve assetData pair info from the API
|
||||||
* @param requestOpts Options specifying assetData information to retrieve, page information, and chain id.
|
* @param requestOpts Options specifying assetData information to retrieve, page information.
|
||||||
* @return The resulting AssetPairsResponse that match the request
|
* @return The resulting AssetPairsResponse that match the request
|
||||||
*/
|
*/
|
||||||
public async getAssetPairsAsync(
|
public async getAssetPairsAsync(
|
||||||
requestOpts?: RequestOpts & AssetPairsRequestOpts & PagedRequestOpts,
|
requestOpts?: AssetPairsRequestOpts & PagedRequestOpts,
|
||||||
): Promise<AssetPairsResponse> {
|
): Promise<AssetPairsResponse> {
|
||||||
if (requestOpts !== undefined) {
|
if (requestOpts !== undefined) {
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, schemas.assetPairsRequestOptsSchema);
|
assert.doesConformToSchema('requestOpts', requestOpts, schemas.assetPairsRequestOptsSchema);
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema);
|
assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema);
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema);
|
|
||||||
}
|
}
|
||||||
const httpRequestOpts = {
|
const httpRequestOpts = {
|
||||||
params: requestOpts,
|
params: requestOpts,
|
||||||
@ -73,16 +71,15 @@ export class HttpClient {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Retrieve orders from the API
|
* Retrieve orders from the API
|
||||||
* @param requestOpts Options specifying orders to retrieve and page information, page information, and chain id.
|
* @param requestOpts Options specifying orders to retrieve and page information, page information.
|
||||||
* @return The resulting OrdersResponse that match the request
|
* @return The resulting OrdersResponse that match the request
|
||||||
*/
|
*/
|
||||||
public async getOrdersAsync(
|
public async getOrdersAsync(
|
||||||
requestOpts?: RequestOpts & OrdersRequestOpts & PagedRequestOpts,
|
requestOpts?: OrdersRequestOpts & PagedRequestOpts,
|
||||||
): Promise<OrdersResponse> {
|
): Promise<OrdersResponse> {
|
||||||
if (requestOpts !== undefined) {
|
if (requestOpts !== undefined) {
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, schemas.ordersRequestOptsSchema);
|
assert.doesConformToSchema('requestOpts', requestOpts, schemas.ordersRequestOptsSchema);
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema);
|
assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema);
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema);
|
|
||||||
}
|
}
|
||||||
const httpRequestOpts = {
|
const httpRequestOpts = {
|
||||||
params: requestOpts,
|
params: requestOpts,
|
||||||
@ -96,32 +93,25 @@ export class HttpClient {
|
|||||||
* @param orderHash An orderHash generated from the desired order
|
* @param orderHash An orderHash generated from the desired order
|
||||||
* @return The APIOrder that matches the supplied orderHash
|
* @return The APIOrder that matches the supplied orderHash
|
||||||
*/
|
*/
|
||||||
public async getOrderAsync(orderHash: string, requestOpts?: RequestOpts): Promise<APIOrder> {
|
public async getOrderAsync(orderHash: string): Promise<APIOrder> {
|
||||||
if (requestOpts !== undefined) {
|
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema);
|
|
||||||
}
|
|
||||||
assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
|
assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
|
||||||
const httpRequestOpts = {
|
const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get);
|
||||||
params: requestOpts,
|
|
||||||
};
|
|
||||||
const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get, httpRequestOpts);
|
|
||||||
const order = relayerResponseJsonParsers.parseAPIOrderJson(responseJson);
|
const order = relayerResponseJsonParsers.parseAPIOrderJson(responseJson);
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Retrieve an orderbook from the API
|
* Retrieve an orderbook from the API
|
||||||
* @param request An OrderbookRequest instance describing the specific orderbook to retrieve
|
* @param request An OrderbookRequest instance describing the specific orderbook to retrieve
|
||||||
* @param requestOpts Options specifying page information, and chain id.
|
* @param requestOpts Options specifying page information.
|
||||||
* @return The resulting OrderbookResponse that matches the request
|
* @return The resulting OrderbookResponse that matches the request
|
||||||
*/
|
*/
|
||||||
public async getOrderbookAsync(
|
public async getOrderbookAsync(
|
||||||
request: OrderbookRequest,
|
request: OrderbookRequest,
|
||||||
requestOpts?: RequestOpts & PagedRequestOpts,
|
requestOpts?: PagedRequestOpts,
|
||||||
): Promise<OrderbookResponse> {
|
): Promise<OrderbookResponse> {
|
||||||
assert.doesConformToSchema('request', request, schemas.orderBookRequestSchema);
|
assert.doesConformToSchema('request', request, schemas.orderBookRequestSchema);
|
||||||
if (requestOpts !== undefined) {
|
if (requestOpts !== undefined) {
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema);
|
assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema);
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema);
|
|
||||||
}
|
}
|
||||||
const httpRequestOpts = {
|
const httpRequestOpts = {
|
||||||
params: _.defaults({}, request, requestOpts),
|
params: _.defaults({}, request, requestOpts),
|
||||||
@ -133,19 +123,13 @@ export class HttpClient {
|
|||||||
/**
|
/**
|
||||||
* Retrieve fee information from the API
|
* Retrieve fee information from the API
|
||||||
* @param request A OrderConfigRequest instance describing the specific fees to retrieve
|
* @param request A OrderConfigRequest instance describing the specific fees to retrieve
|
||||||
* @param requestOpts Options specifying chain id.
|
|
||||||
* @return The resulting OrderConfigResponse that matches the request
|
* @return The resulting OrderConfigResponse that matches the request
|
||||||
*/
|
*/
|
||||||
public async getOrderConfigAsync(
|
public async getOrderConfigAsync(
|
||||||
request: OrderConfigRequest,
|
request: OrderConfigRequest,
|
||||||
requestOpts?: RequestOpts,
|
|
||||||
): Promise<OrderConfigResponse> {
|
): Promise<OrderConfigResponse> {
|
||||||
if (requestOpts !== undefined) {
|
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema);
|
|
||||||
}
|
|
||||||
assert.doesConformToSchema('request', request, schemas.orderConfigRequestSchema);
|
assert.doesConformToSchema('request', request, schemas.orderConfigRequestSchema);
|
||||||
const httpRequestOpts = {
|
const httpRequestOpts = {
|
||||||
params: requestOpts,
|
|
||||||
payload: request,
|
payload: request,
|
||||||
};
|
};
|
||||||
const responseJson = await this._requestAsync('/order_config', HttpRequestType.Post, httpRequestOpts);
|
const responseJson = await this._requestAsync('/order_config', HttpRequestType.Post, httpRequestOpts);
|
||||||
@ -154,13 +138,12 @@ export class HttpClient {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Retrieve the list of fee recipient addresses used by the relayer.
|
* Retrieve the list of fee recipient addresses used by the relayer.
|
||||||
* @param requestOpts Options specifying page information, and chain id.
|
* @param requestOpts Options specifying page information.
|
||||||
* @return The resulting FeeRecipientsResponse
|
* @return The resulting FeeRecipientsResponse
|
||||||
*/
|
*/
|
||||||
public async getFeeRecipientsAsync(requestOpts?: RequestOpts & PagedRequestOpts): Promise<FeeRecipientsResponse> {
|
public async getFeeRecipientsAsync(requestOpts?: PagedRequestOpts): Promise<FeeRecipientsResponse> {
|
||||||
if (requestOpts !== undefined) {
|
if (requestOpts !== undefined) {
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema);
|
assert.doesConformToSchema('requestOpts', requestOpts, schemas.pagedRequestOptsSchema);
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, schemas.requestOptsSchema);
|
|
||||||
}
|
}
|
||||||
const httpRequestOpts = {
|
const httpRequestOpts = {
|
||||||
params: requestOpts,
|
params: requestOpts,
|
||||||
@ -172,12 +155,10 @@ export class HttpClient {
|
|||||||
/**
|
/**
|
||||||
* Submit a signed order to the API
|
* Submit a signed order to the API
|
||||||
* @param signedOrder A SignedOrder instance to submit
|
* @param signedOrder A SignedOrder instance to submit
|
||||||
* @param requestOpts Options specifying chain id.
|
|
||||||
*/
|
*/
|
||||||
public async submitOrderAsync(signedOrder: SignedOrder, requestOpts?: RequestOpts): Promise<void> {
|
public async submitOrderAsync(signedOrder: SignedOrder): Promise<void> {
|
||||||
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
|
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
|
||||||
const httpRequestOpts = {
|
const httpRequestOpts = {
|
||||||
params: requestOpts,
|
|
||||||
payload: signedOrder,
|
payload: signedOrder,
|
||||||
};
|
};
|
||||||
await this._requestAsync('/order', HttpRequestType.Post, httpRequestOpts);
|
await this._requestAsync('/order', HttpRequestType.Post, httpRequestOpts);
|
||||||
|
@ -15,6 +15,5 @@ export {
|
|||||||
OrdersResponse,
|
OrdersResponse,
|
||||||
PagedRequestOpts,
|
PagedRequestOpts,
|
||||||
PaginatedCollection,
|
PaginatedCollection,
|
||||||
RequestOpts,
|
|
||||||
SignedOrder,
|
SignedOrder,
|
||||||
} from '@0x/types';
|
} from '@0x/types';
|
||||||
|
@ -53,9 +53,8 @@ describe('HttpClient', () => {
|
|||||||
assetDataA: assetData,
|
assetDataA: assetData,
|
||||||
page: 3,
|
page: 3,
|
||||||
perPage: 50,
|
perPage: 50,
|
||||||
chainId: 42,
|
|
||||||
};
|
};
|
||||||
const urlWithQuery = `${url}?assetDataA=${assetData}&chainId=42&page=3&perPage=50`;
|
const urlWithQuery = `${url}?assetDataA=${assetData}&page=3&perPage=50`;
|
||||||
fetchMock.get(urlWithQuery, assetDataPairsResponseJSON);
|
fetchMock.get(urlWithQuery, assetDataPairsResponseJSON);
|
||||||
const assetDataPairs = await relayerClient.getAssetPairsAsync(assetPairsRequestOpts);
|
const assetDataPairs = await relayerClient.getAssetPairsAsync(assetPairsRequestOpts);
|
||||||
expect(assetDataPairs).to.be.deep.equal(assetDataPairsResponse);
|
expect(assetDataPairs).to.be.deep.equal(assetDataPairsResponse);
|
||||||
@ -78,9 +77,8 @@ describe('HttpClient', () => {
|
|||||||
assetDataAddress,
|
assetDataAddress,
|
||||||
page: 3,
|
page: 3,
|
||||||
perPage: 50,
|
perPage: 50,
|
||||||
chainId: 42,
|
|
||||||
};
|
};
|
||||||
const urlWithQuery = `${url}?assetDataAddress=${assetDataAddress}&chainId=42&page=3&perPage=50`;
|
const urlWithQuery = `${url}?assetDataAddress=${assetDataAddress}&page=3&perPage=50`;
|
||||||
fetchMock.get(urlWithQuery, ordersResponseJSON);
|
fetchMock.get(urlWithQuery, ordersResponseJSON);
|
||||||
const orders = await relayerClient.getOrdersAsync(ordersRequest);
|
const orders = await relayerClient.getOrdersAsync(ordersRequest);
|
||||||
expect(orders).to.be.deep.equal(ordersResponse);
|
expect(orders).to.be.deep.equal(ordersResponse);
|
||||||
@ -112,7 +110,7 @@ describe('HttpClient', () => {
|
|||||||
it('gets orderbook with default page options when none are provided', async () => {
|
it('gets orderbook with default page options when none are provided', async () => {
|
||||||
const urlWithQuery = `${url}?baseAssetData=${request.baseAssetData}"eAssetData=${
|
const urlWithQuery = `${url}?baseAssetData=${request.baseAssetData}"eAssetData=${
|
||||||
request.quoteAssetData
|
request.quoteAssetData
|
||||||
}`;
|
}`;
|
||||||
fetchMock.get(urlWithQuery, orderbookJSON);
|
fetchMock.get(urlWithQuery, orderbookJSON);
|
||||||
const orderbook = await relayerClient.getOrderbookAsync(request);
|
const orderbook = await relayerClient.getOrderbookAsync(request);
|
||||||
expect(orderbook).to.be.deep.equal(orderbookResponse);
|
expect(orderbook).to.be.deep.equal(orderbookResponse);
|
||||||
@ -120,12 +118,11 @@ describe('HttpClient', () => {
|
|||||||
it('gets orderbook with specified page options', async () => {
|
it('gets orderbook with specified page options', async () => {
|
||||||
const urlWithQuery = `${url}?baseAssetData=${
|
const urlWithQuery = `${url}?baseAssetData=${
|
||||||
request.baseAssetData
|
request.baseAssetData
|
||||||
}&chainId=42&page=3&perPage=50"eAssetData=${request.quoteAssetData}`;
|
}&page=3&perPage=50"eAssetData=${request.quoteAssetData}`;
|
||||||
fetchMock.get(urlWithQuery, orderbookJSON);
|
fetchMock.get(urlWithQuery, orderbookJSON);
|
||||||
const pagedRequestOptions = {
|
const pagedRequestOptions = {
|
||||||
page: 3,
|
page: 3,
|
||||||
perPage: 50,
|
perPage: 50,
|
||||||
chainId: 42,
|
|
||||||
};
|
};
|
||||||
const orderbook = await relayerClient.getOrderbookAsync(request, pagedRequestOptions);
|
const orderbook = await relayerClient.getOrderbookAsync(request, pagedRequestOptions);
|
||||||
expect(orderbook).to.be.deep.equal(orderbookResponse);
|
expect(orderbook).to.be.deep.equal(orderbookResponse);
|
||||||
@ -175,12 +172,11 @@ describe('HttpClient', () => {
|
|||||||
expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse);
|
expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse);
|
||||||
});
|
});
|
||||||
it('gets fee recipient with specified page options', async () => {
|
it('gets fee recipient with specified page options', async () => {
|
||||||
const urlWithQuery = `${url}?chainId=42&page=3&perPage=50`;
|
const urlWithQuery = `${url}?page=3&perPage=50`;
|
||||||
fetchMock.get(urlWithQuery, feeRecipientsResponseJSON);
|
fetchMock.get(urlWithQuery, feeRecipientsResponseJSON);
|
||||||
const pagedRequestOptions = {
|
const pagedRequestOptions = {
|
||||||
page: 3,
|
page: 3,
|
||||||
perPage: 50,
|
perPage: 50,
|
||||||
chainId: 42,
|
|
||||||
};
|
};
|
||||||
const feeRecipients = await relayerClient.getFeeRecipientsAsync(pagedRequestOptions);
|
const feeRecipients = await relayerClient.getFeeRecipientsAsync(pagedRequestOptions);
|
||||||
expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse);
|
expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse);
|
||||||
|
@ -2,13 +2,26 @@
|
|||||||
"id": "/relayerApiOrdersChannelSubscribePayloadSchema",
|
"id": "/relayerApiOrdersChannelSubscribePayloadSchema",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"makerAssetProxyId": { "$ref": "/hexSchema" },
|
"makerAssetProxyId": {
|
||||||
"takerAssetProxyId": { "$ref": "/hexSchema" },
|
"$ref": "/hexSchema"
|
||||||
"chainId": { "type": "number" },
|
},
|
||||||
"makerAssetAddress": { "$ref": "/addressSchema" },
|
"takerAssetProxyId": {
|
||||||
"takerAssetAddress": { "$ref": "/addressSchema" },
|
"$ref": "/hexSchema"
|
||||||
"makerAssetData": { "$ref": "/hexSchema" },
|
},
|
||||||
"takerAssetData": { "$ref": "/hexSchema" },
|
"makerAssetAddress": {
|
||||||
"traderAssetData": { "$ref": "/hexSchema" }
|
"$ref": "/addressSchema"
|
||||||
|
},
|
||||||
|
"takerAssetAddress": {
|
||||||
|
"$ref": "/addressSchema"
|
||||||
|
},
|
||||||
|
"makerAssetData": {
|
||||||
|
"$ref": "/hexSchema"
|
||||||
|
},
|
||||||
|
"takerAssetData": {
|
||||||
|
"$ref": "/hexSchema"
|
||||||
|
},
|
||||||
|
"traderAssetData": {
|
||||||
|
"$ref": "/hexSchema"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "/RequestOptsSchema",
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"chainId": { "type": "number" }
|
|
||||||
}
|
|
||||||
}
|
|
@ -34,40 +34,6 @@ All endpoints that are paginated should return a `total`, `page`, `perPage` and
|
|||||||
|
|
||||||
These requests include the [`/v3/asset_pairs`](#operation/getAssetPairs), [`/v3/orders`](#operation/getOrders), [`/v3/fee_recipients`](#operation/getFeeRecipients) and [`/v3/orderbook`](#operation/getOrderbook) endpoints.
|
These requests include the [`/v3/asset_pairs`](#operation/getAssetPairs), [`/v3/orders`](#operation/getOrders), [`/v3/fee_recipients`](#operation/getFeeRecipients) and [`/v3/orderbook`](#operation/getOrderbook) endpoints.
|
||||||
|
|
||||||
# Chain Id
|
|
||||||
|
|
||||||
All requests should be able to specify a **?chainId** query param for all supported chains. For example:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ curl https://api.example-relayer.com/v3/asset_pairs?chainId=1
|
|
||||||
```
|
|
||||||
|
|
||||||
If the query param is not provided, it should default to **1** (mainnet).
|
|
||||||
|
|
||||||
Chains and their Ids:
|
|
||||||
|
|
||||||
| Chain Id | Chain Name |
|
|
||||||
| -------- | ---------- |
|
|
||||||
| 1 | Mainnet |
|
|
||||||
| 42 | Kovan |
|
|
||||||
| 3 | Ropsten |
|
|
||||||
| 4 | Rinkeby |
|
|
||||||
|
|
||||||
If a certain chain is not supported, the response should **400** as specified in the [error response](#section/Errors) section. For example:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"code": 100,
|
|
||||||
"reason": "Validation failed",
|
|
||||||
"validationErrors": [
|
|
||||||
{
|
|
||||||
"field": "chainId",
|
|
||||||
"code": 1006,
|
|
||||||
"reason": "Chain id 42 is not supported"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
# Link Header
|
# Link Header
|
||||||
|
|
||||||
|
@ -22,18 +22,8 @@ export const paginationParameters: ParameterObject[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const chainIdParameter: ParameterObject = {
|
|
||||||
name: 'chainId',
|
|
||||||
in: 'query',
|
|
||||||
description: 'The id of the Ethereum chain',
|
|
||||||
example: 42,
|
|
||||||
schema: {
|
|
||||||
type: 'number',
|
|
||||||
default: 1,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const generateParameters = (parameters: ParameterObject[], isPaginated: boolean = false): ParameterObject[] => {
|
export const generateParameters = (parameters: ParameterObject[], isPaginated: boolean = false): ParameterObject[] => {
|
||||||
const optionalParameters = isPaginated ? paginationParameters : [];
|
const optionalParameters = isPaginated ? paginationParameters : [];
|
||||||
return [...parameters, chainIdParameter, ...optionalParameters];
|
return [...parameters, ...optionalParameters];
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user