aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/json-schemas/CHANGELOG.json4
-rw-r--r--packages/json-schemas/schemas/basic_type_schemas.ts6
-rw-r--r--packages/json-schemas/schemas/block_range_schema.ts8
-rw-r--r--packages/json-schemas/schemas/call_data_schema.ts12
-rw-r--r--packages/json-schemas/schemas/ec_signature_schema.ts6
-rw-r--r--packages/json-schemas/schemas/index_filter_values_schema.ts4
-rw-r--r--packages/json-schemas/schemas/order_cancel_schema.ts6
-rw-r--r--packages/json-schemas/schemas/order_fill_or_kill_requests_schema.ts6
-rw-r--r--packages/json-schemas/schemas/order_fill_requests_schema.ts6
-rw-r--r--packages/json-schemas/schemas/order_hash_schema.ts2
-rw-r--r--packages/json-schemas/schemas/order_schemas.ts34
-rw-r--r--packages/json-schemas/schemas/orders_schema.ts2
-rw-r--r--packages/json-schemas/schemas/paginated_collection_schema.ts10
-rw-r--r--packages/json-schemas/schemas/relayer_api_asset_pairs_response_schema.ts38
-rw-r--r--packages/json-schemas/schemas/relayer_api_error_response_schema.ts6
-rw-r--r--packages/json-schemas/schemas/relayer_api_fees_payload_schema.ts24
-rw-r--r--packages/json-schemas/schemas/relayer_api_fees_response_schema.ts10
-rw-r--r--packages/json-schemas/schemas/relayer_api_orberbook_channel_subscribe_schema.ts23
-rw-r--r--packages/json-schemas/schemas/relayer_api_order_config_payload_schema.ts24
-rw-r--r--packages/json-schemas/schemas/relayer_api_order_config_response_schema.ts11
-rw-r--r--packages/json-schemas/schemas/relayer_api_order_schema.ts9
-rw-r--r--packages/json-schemas/schemas/relayer_api_orderbook_channel_snapshot_schema.ts21
-rw-r--r--packages/json-schemas/schemas/relayer_api_orderbook_channel_update_response_schema.ts11
-rw-r--r--packages/json-schemas/schemas/relayer_api_orderbook_response_schema.ts6
-rw-r--r--packages/json-schemas/schemas/relayer_api_orders_channel_subscribe_schema.ts26
-rw-r--r--packages/json-schemas/schemas/relayer_api_orders_channel_update_response_schema.ts11
-rw-r--r--packages/json-schemas/schemas/relayer_api_orders_response_schema.ts13
-rw-r--r--packages/json-schemas/schemas/relayer_api_orders_schema.ts5
-rw-r--r--packages/json-schemas/schemas/relayer_api_token_pairs_response_schema.ts24
-rw-r--r--packages/json-schemas/schemas/signed_orders_schema.ts2
-rw-r--r--packages/json-schemas/schemas/token_schema.ts4
-rw-r--r--packages/json-schemas/schemas/tx_data_schema.ts14
-rw-r--r--packages/json-schemas/src/schemas.ts50
-rw-r--r--packages/json-schemas/test/schema_test.ts951
-rw-r--r--packages/sra-api/.discharge.json13
-rw-r--r--packages/sra-api/.npmignore8
-rw-r--r--packages/sra-api/CHANGELOG.json1
-rw-r--r--packages/sra-api/README.md97
-rw-r--r--packages/sra-api/package.json62
-rw-r--r--packages/sra-api/src/api.ts61
-rw-r--r--packages/sra-api/src/errors.ts24
-rw-r--r--packages/sra-api/src/examples/errors.ts11
-rw-r--r--packages/sra-api/src/examples/index.ts7
-rw-r--r--packages/sra-api/src/examples/relayerApiAssetDataPairsResponseSchema.ts21
-rw-r--r--packages/sra-api/src/headers.ts20
-rw-r--r--packages/sra-api/src/index.ts1
-rw-r--r--packages/sra-api/src/md/index.ts5
-rw-r--r--packages/sra-api/src/md/introduction.md180
-rw-r--r--packages/sra-api/src/parameters.ts37
-rw-r--r--packages/sra-api/src/responses.ts17
-rw-r--r--packages/sra-api/test/api_test.ts15
-rw-r--r--packages/sra-api/tsconfig.json7
-rw-r--r--packages/sra-api/tslint.json3
-rw-r--r--packages/typescript-typings/types/openapi-schema-validation/index.d.ts1
54 files changed, 1295 insertions, 685 deletions
diff --git a/packages/json-schemas/CHANGELOG.json b/packages/json-schemas/CHANGELOG.json
index 33cf126e3..6017b2f2b 100644
--- a/packages/json-schemas/CHANGELOG.json
+++ b/packages/json-schemas/CHANGELOG.json
@@ -5,6 +5,10 @@
{
"note": "Change hexSchema to match `0x`",
"pr": 937
+ },
+ {
+ "note": "Upgrade Relayer API schemas for relayer API V2",
+ "pr": 916
}
]
},
diff --git a/packages/json-schemas/schemas/basic_type_schemas.ts b/packages/json-schemas/schemas/basic_type_schemas.ts
index 301f9ec73..a59afaef8 100644
--- a/packages/json-schemas/schemas/basic_type_schemas.ts
+++ b/packages/json-schemas/schemas/basic_type_schemas.ts
@@ -1,17 +1,17 @@
export const addressSchema = {
- id: '/Address',
+ id: '/addressSchema',
type: 'string',
pattern: '^0x[0-9a-f]{40}$',
};
export const hexSchema = {
- id: '/Hex',
+ id: '/hexSchema',
type: 'string',
pattern: '^0x(([0-9a-f][0-9a-f])+)?$',
};
export const numberSchema = {
- id: '/Number',
+ id: '/numberSchema',
type: 'string',
pattern: '^\\d+(\\.\\d+)?$',
};
diff --git a/packages/json-schemas/schemas/block_range_schema.ts b/packages/json-schemas/schemas/block_range_schema.ts
index 1f6a63151..9eb242fc6 100644
--- a/packages/json-schemas/schemas/block_range_schema.ts
+++ b/packages/json-schemas/schemas/block_range_schema.ts
@@ -1,5 +1,5 @@
export const blockParamSchema = {
- id: '/BlockParam',
+ id: '/blockParamSchema',
oneOf: [
{
type: 'number',
@@ -11,10 +11,10 @@ export const blockParamSchema = {
};
export const blockRangeSchema = {
- id: '/BlockRange',
+ id: '/blockRangeSchema',
properties: {
- fromBlock: { $ref: '/BlockParam' },
- toBlock: { $ref: '/BlockParam' },
+ fromBlock: { $ref: '/blockParamSchema' },
+ toBlock: { $ref: '/blockParamSchema' },
},
type: 'object',
};
diff --git a/packages/json-schemas/schemas/call_data_schema.ts b/packages/json-schemas/schemas/call_data_schema.ts
index b9d00ad2a..4c77d9f9d 100644
--- a/packages/json-schemas/schemas/call_data_schema.ts
+++ b/packages/json-schemas/schemas/call_data_schema.ts
@@ -1,16 +1,16 @@
export const callDataSchema = {
- id: '/CallData',
+ id: '/callDataSchema',
properties: {
- from: { $ref: '/Address' },
- to: { $ref: '/Address' },
+ from: { $ref: '/addressSchema' },
+ to: { $ref: '/addressSchema' },
value: {
- oneOf: [{ $ref: '/Number' }, { $ref: '/JsNumber' }],
+ oneOf: [{ $ref: '/numberSchema' }, { $ref: '/jsNumber' }],
},
gas: {
- oneOf: [{ $ref: '/Number' }, { $ref: '/JsNumber' }],
+ oneOf: [{ $ref: '/numberSchema' }, { $ref: '/jsNumber' }],
},
gasPrice: {
- oneOf: [{ $ref: '/Number' }, { $ref: '/JsNumber' }],
+ oneOf: [{ $ref: '/numberSchema' }, { $ref: '/jsNumber' }],
},
data: {
type: 'string',
diff --git a/packages/json-schemas/schemas/ec_signature_schema.ts b/packages/json-schemas/schemas/ec_signature_schema.ts
index 71b840dd8..c59532f09 100644
--- a/packages/json-schemas/schemas/ec_signature_schema.ts
+++ b/packages/json-schemas/schemas/ec_signature_schema.ts
@@ -1,5 +1,5 @@
export const ecSignatureParameterSchema = {
- id: '/ECSignatureParameter',
+ id: '/ecSignatureParameterSchema',
type: 'string',
pattern: '^0[xX][0-9A-Fa-f]{64}$',
};
@@ -12,8 +12,8 @@ export const ecSignatureSchema = {
minimum: 27,
maximum: 28,
},
- r: { $ref: '/ECSignatureParameter' },
- s: { $ref: '/ECSignatureParameter' },
+ r: { $ref: '/ecSignatureParameterSchema' },
+ s: { $ref: '/ecSignatureParameterSchema' },
},
required: ['v', 'r', 's'],
type: 'object',
diff --git a/packages/json-schemas/schemas/index_filter_values_schema.ts b/packages/json-schemas/schemas/index_filter_values_schema.ts
index 3374d63e0..f3c8cef68 100644
--- a/packages/json-schemas/schemas/index_filter_values_schema.ts
+++ b/packages/json-schemas/schemas/index_filter_values_schema.ts
@@ -1,7 +1,7 @@
export const indexFilterValuesSchema = {
- id: '/IndexFilterValues',
+ id: '/indexFilterValuesSchema',
additionalProperties: {
- oneOf: [{ $ref: '/Number' }, { $ref: '/Address' }, { $ref: '/OrderHashSchema' }],
+ oneOf: [{ $ref: '/numberSchema' }, { $ref: '/addressSchema' }, { $ref: '/orderHashSchema' }],
},
type: 'object',
};
diff --git a/packages/json-schemas/schemas/order_cancel_schema.ts b/packages/json-schemas/schemas/order_cancel_schema.ts
index ad23d01cc..e4edfbca9 100644
--- a/packages/json-schemas/schemas/order_cancel_schema.ts
+++ b/packages/json-schemas/schemas/order_cancel_schema.ts
@@ -1,10 +1,10 @@
export const orderCancellationRequestsSchema = {
- id: '/OrderCancellationRequests',
+ id: '/orderCancellationRequestsSchema',
type: 'array',
items: {
properties: {
- order: { $ref: '/Order' },
- takerTokenCancelAmount: { $ref: '/Number' },
+ order: { $ref: '/orderSchema' },
+ takerTokenCancelAmount: { $ref: '/numberSchema' },
},
required: ['order', 'takerTokenCancelAmount'],
type: 'object',
diff --git a/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.ts b/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.ts
index 61f2c8849..e2c18ef0a 100644
--- a/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.ts
+++ b/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.ts
@@ -1,10 +1,10 @@
export const orderFillOrKillRequestsSchema = {
- id: '/OrderFillOrKillRequests',
+ id: '/orderFillOrKillRequestsSchema',
type: 'array',
items: {
properties: {
- signedOrder: { $ref: '/SignedOrder' },
- fillTakerAmount: { $ref: '/Number' },
+ signedOrder: { $ref: '/signedOrderSchema' },
+ fillTakerAmount: { $ref: '/numberSchema' },
},
required: ['signedOrder', 'fillTakerAmount'],
type: 'object',
diff --git a/packages/json-schemas/schemas/order_fill_requests_schema.ts b/packages/json-schemas/schemas/order_fill_requests_schema.ts
index 419d0670f..ea8b35e54 100644
--- a/packages/json-schemas/schemas/order_fill_requests_schema.ts
+++ b/packages/json-schemas/schemas/order_fill_requests_schema.ts
@@ -1,10 +1,10 @@
export const orderFillRequestsSchema = {
- id: '/OrderFillRequests',
+ id: '/orderFillRequestsSchema',
type: 'array',
items: {
properties: {
- signedOrder: { $ref: '/SignedOrder' },
- takerTokenFillAmount: { $ref: '/Number' },
+ signedOrder: { $ref: '/signedOrderSchema' },
+ takerTokenFillAmount: { $ref: '/numberSchema' },
},
required: ['signedOrder', 'takerTokenFillAmount'],
type: 'object',
diff --git a/packages/json-schemas/schemas/order_hash_schema.ts b/packages/json-schemas/schemas/order_hash_schema.ts
index 6af06927f..9773a88f9 100644
--- a/packages/json-schemas/schemas/order_hash_schema.ts
+++ b/packages/json-schemas/schemas/order_hash_schema.ts
@@ -1,5 +1,5 @@
export const orderHashSchema = {
- id: '/OrderHashSchema',
+ id: '/orderHashSchema',
type: 'string',
pattern: '^0x[0-9a-fA-F]{64}$',
};
diff --git a/packages/json-schemas/schemas/order_schemas.ts b/packages/json-schemas/schemas/order_schemas.ts
index dcbfde6e0..eb7fdaf5a 100644
--- a/packages/json-schemas/schemas/order_schemas.ts
+++ b/packages/json-schemas/schemas/order_schemas.ts
@@ -1,19 +1,19 @@
export const orderSchema = {
- id: '/Order',
+ id: '/orderSchema',
properties: {
- makerAddress: { $ref: '/Address' },
- takerAddress: { $ref: '/Address' },
- makerFee: { $ref: '/Number' },
- takerFee: { $ref: '/Number' },
- senderAddress: { $ref: '/Address' },
- makerAssetAmount: { $ref: '/Number' },
- takerAssetAmount: { $ref: '/Number' },
- makerAssetData: { $ref: '/Hex' },
- takerAssetData: { $ref: '/Hex' },
- salt: { $ref: '/Number' },
- exchangeAddress: { $ref: '/Address' },
- feeRecipientAddress: { $ref: '/Address' },
- expirationTimeSeconds: { $ref: '/Number' },
+ makerAddress: { $ref: '/addressSchema' },
+ takerAddress: { $ref: '/addressSchema' },
+ makerFee: { $ref: '/numberSchema' },
+ takerFee: { $ref: '/numberSchema' },
+ senderAddress: { $ref: '/addressSchema' },
+ makerAssetAmount: { $ref: '/numberSchema' },
+ takerAssetAmount: { $ref: '/numberSchema' },
+ makerAssetData: { $ref: '/hexSchema' },
+ takerAssetData: { $ref: '/hexSchema' },
+ salt: { $ref: '/numberSchema' },
+ exchangeAddress: { $ref: '/addressSchema' },
+ feeRecipientAddress: { $ref: '/addressSchema' },
+ expirationTimeSeconds: { $ref: '/numberSchema' },
},
required: [
'makerAddress',
@@ -34,12 +34,12 @@ export const orderSchema = {
};
export const signedOrderSchema = {
- id: '/SignedOrder',
+ id: '/signedOrderSchema',
allOf: [
- { $ref: '/Order' },
+ { $ref: '/orderSchema' },
{
properties: {
- signature: { $ref: '/Hex' },
+ signature: { $ref: '/hexSchema' },
},
required: ['signature'],
},
diff --git a/packages/json-schemas/schemas/orders_schema.ts b/packages/json-schemas/schemas/orders_schema.ts
index 3ba3291a2..de0abcf00 100644
--- a/packages/json-schemas/schemas/orders_schema.ts
+++ b/packages/json-schemas/schemas/orders_schema.ts
@@ -1,5 +1,5 @@
export const ordersSchema = {
id: '/ordersSchema',
type: 'array',
- items: { $ref: '/Order' },
+ items: { $ref: '/orderSchema' },
};
diff --git a/packages/json-schemas/schemas/paginated_collection_schema.ts b/packages/json-schemas/schemas/paginated_collection_schema.ts
new file mode 100644
index 000000000..16044c70a
--- /dev/null
+++ b/packages/json-schemas/schemas/paginated_collection_schema.ts
@@ -0,0 +1,10 @@
+export const paginatedCollectionSchema = {
+ id: '/paginatedCollectionSchema',
+ type: 'object',
+ properties: {
+ total: { type: 'number' },
+ perPage: { type: 'number' },
+ page: { type: 'number' },
+ },
+ required: ['total', 'perPage', 'page'],
+};
diff --git a/packages/json-schemas/schemas/relayer_api_asset_pairs_response_schema.ts b/packages/json-schemas/schemas/relayer_api_asset_pairs_response_schema.ts
new file mode 100644
index 000000000..c13396d29
--- /dev/null
+++ b/packages/json-schemas/schemas/relayer_api_asset_pairs_response_schema.ts
@@ -0,0 +1,38 @@
+export const relayerApiAssetDataPairsResponseSchema = {
+ id: '/relayerApiAssetDataPairsResponseSchema',
+ type: 'object',
+ allOf: [
+ { $ref: '/paginatedCollectionSchema' },
+ {
+ properties: {
+ records: { $ref: '/relayerApiAssetDataPairsSchema' },
+ },
+ required: ['records'],
+ },
+ ],
+};
+
+export const relayerApiAssetDataPairsSchema = {
+ id: '/relayerApiAssetDataPairsSchema',
+ type: 'array',
+ items: {
+ properties: {
+ assetDataA: { $ref: '/relayerApiAssetDataTradeInfoSchema' },
+ assetDataB: { $ref: '/relayerApiAssetDataTradeInfoSchema' },
+ },
+ required: ['assetDataA', 'assetDataB'],
+ type: 'object',
+ },
+};
+
+export const relayerApiAssetDataTradeInfoSchema = {
+ id: '/relayerApiAssetDataTradeInfoSchema',
+ type: 'object',
+ properties: {
+ assetData: { $ref: '/hexSchema' },
+ minAmount: { $ref: '/numberSchema' },
+ maxAmount: { $ref: '/numberSchema' },
+ precision: { type: 'number' },
+ },
+ required: ['assetData'],
+};
diff --git a/packages/json-schemas/schemas/relayer_api_error_response_schema.ts b/packages/json-schemas/schemas/relayer_api_error_response_schema.ts
index 27fdb166f..05740aa54 100644
--- a/packages/json-schemas/schemas/relayer_api_error_response_schema.ts
+++ b/packages/json-schemas/schemas/relayer_api_error_response_schema.ts
@@ -1,8 +1,8 @@
export const relayerApiErrorResponseSchema = {
- id: '/RelayerApiErrorResponse',
+ id: '/relayerApiErrorResponseSchema',
type: 'object',
properties: {
- code: { type: 'number' },
+ code: { type: 'number', minimum: 100, maximum: 103 },
reason: { type: 'string' },
validationErrors: {
type: 'array',
@@ -10,7 +10,7 @@ export const relayerApiErrorResponseSchema = {
type: 'object',
properties: {
field: { type: 'string' },
- code: { type: 'number' },
+ code: { type: 'number', minimum: 1000, maximum: 1006 },
reason: { type: 'string' },
},
required: ['field', 'code', 'reason'],
diff --git a/packages/json-schemas/schemas/relayer_api_fees_payload_schema.ts b/packages/json-schemas/schemas/relayer_api_fees_payload_schema.ts
deleted file mode 100644
index eaaf777a1..000000000
--- a/packages/json-schemas/schemas/relayer_api_fees_payload_schema.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-export const relayerApiFeesPayloadSchema = {
- id: '/RelayerApiFeesPayload',
- type: 'object',
- properties: {
- exchangeContractAddress: { $ref: '/Address' },
- maker: { $ref: '/Address' },
- taker: { $ref: '/Address' },
- makerTokenAddress: { $ref: '/Address' },
- takerTokenAddress: { $ref: '/Address' },
- makerTokenAmount: { $ref: '/Number' },
- takerTokenAmount: { $ref: '/Number' },
- expirationUnixTimestampSec: { $ref: '/Number' },
- salt: { $ref: '/Number' },
- },
- required: [
- 'exchangeContractAddress',
- 'maker',
- 'taker',
- 'makerTokenAddress',
- 'takerTokenAddress',
- 'expirationUnixTimestampSec',
- 'salt',
- ],
-};
diff --git a/packages/json-schemas/schemas/relayer_api_fees_response_schema.ts b/packages/json-schemas/schemas/relayer_api_fees_response_schema.ts
deleted file mode 100644
index e7440613f..000000000
--- a/packages/json-schemas/schemas/relayer_api_fees_response_schema.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-export const relayerApiFeesResponseSchema = {
- id: '/RelayerApiFeesResponse',
- type: 'object',
- properties: {
- makerFee: { $ref: '/Number' },
- takerFee: { $ref: '/Number' },
- feeRecipient: { $ref: '/Address' },
- },
- required: ['makerFee', 'takerFee', 'feeRecipient'],
-};
diff --git a/packages/json-schemas/schemas/relayer_api_orberbook_channel_subscribe_schema.ts b/packages/json-schemas/schemas/relayer_api_orberbook_channel_subscribe_schema.ts
deleted file mode 100644
index d93fa73d6..000000000
--- a/packages/json-schemas/schemas/relayer_api_orberbook_channel_subscribe_schema.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-export const relayerApiOrderbookChannelSubscribeSchema = {
- id: '/RelayerApiOrderbookChannelSubscribe',
- type: 'object',
- properties: {
- type: { enum: ['subscribe'] },
- channel: { enum: ['orderbook'] },
- requestId: { type: 'number' },
- payload: { $ref: '/RelayerApiOrderbookChannelSubscribePayload' },
- },
- required: ['type', 'channel', 'requestId', 'payload'],
-};
-
-export const relayerApiOrderbookChannelSubscribePayload = {
- id: '/RelayerApiOrderbookChannelSubscribePayload',
- type: 'object',
- properties: {
- baseTokenAddress: { $ref: '/Address' },
- quoteTokenAddress: { $ref: '/Address' },
- snapshot: { type: 'boolean' },
- limit: { type: 'number' },
- },
- required: ['baseTokenAddress', 'quoteTokenAddress'],
-};
diff --git a/packages/json-schemas/schemas/relayer_api_order_config_payload_schema.ts b/packages/json-schemas/schemas/relayer_api_order_config_payload_schema.ts
new file mode 100644
index 000000000..8d1d408d6
--- /dev/null
+++ b/packages/json-schemas/schemas/relayer_api_order_config_payload_schema.ts
@@ -0,0 +1,24 @@
+export const relayerApiOrderConfigPayloadSchema = {
+ id: '/relayerApiOrderConfigPayloadSchema',
+ type: 'object',
+ properties: {
+ makerAddress: { $ref: '/addressSchema' },
+ takerAddress: { $ref: '/addressSchema' },
+ makerAssetAmount: { $ref: '/numberSchema' },
+ takerAssetAmount: { $ref: '/numberSchema' },
+ makerAssetData: { $ref: '/hexSchema' },
+ takerAssetData: { $ref: '/hexSchema' },
+ exchangeAddress: { $ref: '/addressSchema' },
+ expirationTimeSeconds: { $ref: '/numberSchema' },
+ },
+ required: [
+ 'makerAddress',
+ 'takerAddress',
+ 'makerAssetAmount',
+ 'takerAssetAmount',
+ 'makerAssetData',
+ 'takerAssetData',
+ 'exchangeAddress',
+ 'expirationTimeSeconds',
+ ],
+};
diff --git a/packages/json-schemas/schemas/relayer_api_order_config_response_schema.ts b/packages/json-schemas/schemas/relayer_api_order_config_response_schema.ts
new file mode 100644
index 000000000..390d0b262
--- /dev/null
+++ b/packages/json-schemas/schemas/relayer_api_order_config_response_schema.ts
@@ -0,0 +1,11 @@
+export const relayerApiOrderConfigResponseSchema = {
+ id: '/relayerApiOrderConfigResponseSchema',
+ type: 'object',
+ properties: {
+ makerFee: { $ref: '/numberSchema' },
+ takerFee: { $ref: '/numberSchema' },
+ feeRecipientAddress: { $ref: '/addressSchema' },
+ senderAddress: { $ref: '/addressSchema' },
+ },
+ required: ['makerFee', 'takerFee', 'feeRecipientAddress', 'senderAddress'],
+};
diff --git a/packages/json-schemas/schemas/relayer_api_order_schema.ts b/packages/json-schemas/schemas/relayer_api_order_schema.ts
new file mode 100644
index 000000000..17fa146c4
--- /dev/null
+++ b/packages/json-schemas/schemas/relayer_api_order_schema.ts
@@ -0,0 +1,9 @@
+export const relayerApiOrderSchema = {
+ id: '/relayerApiOrderSchema',
+ type: 'object',
+ properties: {
+ order: { $ref: '/orderSchema' },
+ remainingFillableAmount: { $ref: '/numberSchema' },
+ },
+ required: ['order', 'remainingFillableAmount'],
+};
diff --git a/packages/json-schemas/schemas/relayer_api_orderbook_channel_snapshot_schema.ts b/packages/json-schemas/schemas/relayer_api_orderbook_channel_snapshot_schema.ts
deleted file mode 100644
index fe1510d5b..000000000
--- a/packages/json-schemas/schemas/relayer_api_orderbook_channel_snapshot_schema.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-export const relayerApiOrderbookChannelSnapshotSchema = {
- id: '/RelayerApiOrderbookChannelSnapshot',
- type: 'object',
- properties: {
- type: { enum: ['snapshot'] },
- channel: { enum: ['orderbook'] },
- requestId: { type: 'number' },
- payload: { $ref: '/RelayerApiOrderbookChannelSnapshotPayload' },
- },
- required: ['type', 'channel', 'requestId', 'payload'],
-};
-
-export const relayerApiOrderbookChannelSnapshotPayload = {
- id: '/RelayerApiOrderbookChannelSnapshotPayload',
- type: 'object',
- properties: {
- bids: { $ref: '/signedOrdersSchema' },
- asks: { $ref: '/signedOrdersSchema' },
- },
- required: ['bids', 'asks'],
-};
diff --git a/packages/json-schemas/schemas/relayer_api_orderbook_channel_update_response_schema.ts b/packages/json-schemas/schemas/relayer_api_orderbook_channel_update_response_schema.ts
deleted file mode 100644
index 9a6d83d4c..000000000
--- a/packages/json-schemas/schemas/relayer_api_orderbook_channel_update_response_schema.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-export const relayerApiOrderbookChannelUpdateSchema = {
- id: '/RelayerApiOrderbookChannelUpdate',
- type: 'object',
- properties: {
- type: { enum: ['update'] },
- channel: { enum: ['orderbook'] },
- requestId: { type: 'number' },
- payload: { $ref: '/SignedOrder' },
- },
- required: ['type', 'channel', 'requestId', 'payload'],
-};
diff --git a/packages/json-schemas/schemas/relayer_api_orderbook_response_schema.ts b/packages/json-schemas/schemas/relayer_api_orderbook_response_schema.ts
index 5c409c807..2e5b0c6f2 100644
--- a/packages/json-schemas/schemas/relayer_api_orderbook_response_schema.ts
+++ b/packages/json-schemas/schemas/relayer_api_orderbook_response_schema.ts
@@ -1,9 +1,9 @@
export const relayerApiOrderBookResponseSchema = {
- id: '/RelayerApiOrderBookResponse',
+ id: '/relayerApiOrderBookResponseSchema',
type: 'object',
properties: {
- bids: { $ref: '/signedOrdersSchema' },
- asks: { $ref: '/signedOrdersSchema' },
+ bids: { $ref: '/relayerApiOrdersResponseSchema' },
+ asks: { $ref: '/relayerApiOrdersResponseSchema' },
},
required: ['bids', 'asks'],
};
diff --git a/packages/json-schemas/schemas/relayer_api_orders_channel_subscribe_schema.ts b/packages/json-schemas/schemas/relayer_api_orders_channel_subscribe_schema.ts
new file mode 100644
index 000000000..a3b9b6d95
--- /dev/null
+++ b/packages/json-schemas/schemas/relayer_api_orders_channel_subscribe_schema.ts
@@ -0,0 +1,26 @@
+export const relayerApiOrdersChannelSubscribeSchema = {
+ id: '/relayerApiOrdersChannelSubscribeSchema',
+ type: 'object',
+ properties: {
+ type: { enum: ['subscribe'] },
+ channel: { enum: ['orders'] },
+ requestId: { type: 'string' },
+ payload: { $ref: '/relayerApiOrdersChannelSubscribePayload' },
+ },
+ required: ['type', 'channel', 'requestId'],
+};
+
+export const relayerApiOrdersChannelSubscribePayload = {
+ id: '/relayerApiOrdersChannelSubscribePayload',
+ type: 'object',
+ properties: {
+ makerAssetProxyId: { $ref: '/hexSchema' },
+ takerAssetProxyId: { $ref: '/hexSchema' },
+ networkId: { type: 'number' },
+ makerAssetAddress: { $ref: '/addressSchema' },
+ takerAssetAddress: { $ref: '/addressSchema' },
+ makerAssetData: { $ref: '/hexSchema' },
+ takerAssetData: { $ref: '/hexSchema' },
+ traderAssetData: { $ref: '/hexSchema' },
+ },
+};
diff --git a/packages/json-schemas/schemas/relayer_api_orders_channel_update_response_schema.ts b/packages/json-schemas/schemas/relayer_api_orders_channel_update_response_schema.ts
new file mode 100644
index 000000000..800b818e2
--- /dev/null
+++ b/packages/json-schemas/schemas/relayer_api_orders_channel_update_response_schema.ts
@@ -0,0 +1,11 @@
+export const relayerApiOrdersChannelUpdateSchema = {
+ id: '/relayerApiOrdersChannelUpdateSchema',
+ type: 'object',
+ properties: {
+ type: { enum: ['update'] },
+ channel: { enum: ['orders'] },
+ requestId: { type: 'string' },
+ payload: { $ref: '/relayerApiOrdersSchema' },
+ },
+ required: ['type', 'channel', 'requestId'],
+};
diff --git a/packages/json-schemas/schemas/relayer_api_orders_response_schema.ts b/packages/json-schemas/schemas/relayer_api_orders_response_schema.ts
new file mode 100644
index 000000000..c10d64ca9
--- /dev/null
+++ b/packages/json-schemas/schemas/relayer_api_orders_response_schema.ts
@@ -0,0 +1,13 @@
+export const relayerApiOrdersResponseSchema = {
+ id: '/relayerApiOrdersResponseSchema',
+ type: 'object',
+ allOf: [
+ { $ref: '/paginatedCollectionSchema' },
+ {
+ properties: {
+ records: { $ref: '/relayerApiOrdersSchema' },
+ },
+ required: ['records'],
+ },
+ ],
+};
diff --git a/packages/json-schemas/schemas/relayer_api_orders_schema.ts b/packages/json-schemas/schemas/relayer_api_orders_schema.ts
new file mode 100644
index 000000000..ba8ce4722
--- /dev/null
+++ b/packages/json-schemas/schemas/relayer_api_orders_schema.ts
@@ -0,0 +1,5 @@
+export const relayerApiOrdersSchema = {
+ id: '/relayerApiOrdersSchema',
+ type: 'array',
+ items: { $ref: '/relayerApiOrderSchema' },
+};
diff --git a/packages/json-schemas/schemas/relayer_api_token_pairs_response_schema.ts b/packages/json-schemas/schemas/relayer_api_token_pairs_response_schema.ts
deleted file mode 100644
index 5009c7955..000000000
--- a/packages/json-schemas/schemas/relayer_api_token_pairs_response_schema.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-export const relayerApiTokenPairsResponseSchema = {
- id: '/RelayerApiTokenPairsResponse',
- type: 'array',
- items: {
- properties: {
- tokenA: { $ref: '/RelayerApiTokenTradeInfo' },
- tokenB: { $ref: '/RelayerApiTokenTradeInfo' },
- },
- required: ['tokenA', 'tokenB'],
- type: 'object',
- },
-};
-
-export const relayerApiTokenTradeInfoSchema = {
- id: '/RelayerApiTokenTradeInfo',
- type: 'object',
- properties: {
- address: { $ref: '/Address' },
- minAmount: { $ref: '/Number' },
- maxAmount: { $ref: '/Number' },
- precision: { type: 'number' },
- },
- required: ['address'],
-};
diff --git a/packages/json-schemas/schemas/signed_orders_schema.ts b/packages/json-schemas/schemas/signed_orders_schema.ts
index 34d956836..e2a5aeb56 100644
--- a/packages/json-schemas/schemas/signed_orders_schema.ts
+++ b/packages/json-schemas/schemas/signed_orders_schema.ts
@@ -1,5 +1,5 @@
export const signedOrdersSchema = {
id: '/signedOrdersSchema',
type: 'array',
- items: { $ref: '/SignedOrder' },
+ items: { $ref: '/signedOrderSchema' },
};
diff --git a/packages/json-schemas/schemas/token_schema.ts b/packages/json-schemas/schemas/token_schema.ts
index e64565c8b..a0b1ae27f 100644
--- a/packages/json-schemas/schemas/token_schema.ts
+++ b/packages/json-schemas/schemas/token_schema.ts
@@ -1,10 +1,10 @@
export const tokenSchema = {
- id: '/Token',
+ id: '/tokenSchema',
properties: {
name: { type: 'string' },
symbol: { type: 'string' },
decimals: { type: 'number' },
- address: { $ref: '/Address' },
+ address: { $ref: '/addressSchema' },
},
required: ['name', 'symbol', 'decimals', 'address'],
type: 'object',
diff --git a/packages/json-schemas/schemas/tx_data_schema.ts b/packages/json-schemas/schemas/tx_data_schema.ts
index 4274c553f..41a5c708a 100644
--- a/packages/json-schemas/schemas/tx_data_schema.ts
+++ b/packages/json-schemas/schemas/tx_data_schema.ts
@@ -1,22 +1,22 @@
export const jsNumber = {
- id: '/JsNumber',
+ id: '/jsNumber',
type: 'number',
minimum: 0,
};
export const txDataSchema = {
- id: '/TxData',
+ id: '/txDataSchema',
properties: {
- from: { $ref: '/Address' },
- to: { $ref: '/Address' },
+ from: { $ref: '/addressSchema' },
+ to: { $ref: '/addressSchema' },
value: {
- oneOf: [{ $ref: '/Number' }, { $ref: '/JsNumber' }],
+ oneOf: [{ $ref: '/numberSchema' }, { $ref: '/jsNumber' }],
},
gas: {
- oneOf: [{ $ref: '/Number' }, { $ref: '/JsNumber' }],
+ oneOf: [{ $ref: '/numberSchema' }, { $ref: '/jsNumber' }],
},
gasPrice: {
- oneOf: [{ $ref: '/Number' }, { $ref: '/JsNumber' }],
+ oneOf: [{ $ref: '/numberSchema' }, { $ref: '/jsNumber' }],
},
data: {
type: 'string',
diff --git a/packages/json-schemas/src/schemas.ts b/packages/json-schemas/src/schemas.ts
index 8b7c538ed..61614ebde 100644
--- a/packages/json-schemas/src/schemas.ts
+++ b/packages/json-schemas/src/schemas.ts
@@ -9,23 +9,24 @@ import { orderFillRequestsSchema } from '../schemas/order_fill_requests_schema';
import { orderHashSchema } from '../schemas/order_hash_schema';
import { orderSchema, signedOrderSchema } from '../schemas/order_schemas';
import { ordersSchema } from '../schemas/orders_schema';
-import { relayerApiErrorResponseSchema } from '../schemas/relayer_api_error_response_schema';
-import { relayerApiFeesPayloadSchema } from '../schemas/relayer_api_fees_payload_schema';
-import { relayerApiFeesResponseSchema } from '../schemas/relayer_api_fees_response_schema';
-import {
- relayerApiOrderbookChannelSubscribePayload,
- relayerApiOrderbookChannelSubscribeSchema,
-} from '../schemas/relayer_api_orberbook_channel_subscribe_schema';
+import { paginatedCollectionSchema } from '../schemas/paginated_collection_schema';
import {
- relayerApiOrderbookChannelSnapshotPayload,
- relayerApiOrderbookChannelSnapshotSchema,
-} from '../schemas/relayer_api_orderbook_channel_snapshot_schema';
-import { relayerApiOrderbookChannelUpdateSchema } from '../schemas/relayer_api_orderbook_channel_update_response_schema';
+ relayerApiAssetDataPairsResponseSchema,
+ relayerApiAssetDataPairsSchema,
+ relayerApiAssetDataTradeInfoSchema,
+} from '../schemas/relayer_api_asset_pairs_response_schema';
+import { relayerApiErrorResponseSchema } from '../schemas/relayer_api_error_response_schema';
+import { relayerApiOrderConfigPayloadSchema } from '../schemas/relayer_api_order_config_payload_schema';
+import { relayerApiOrderConfigResponseSchema } from '../schemas/relayer_api_order_config_response_schema';
+import { relayerApiOrderSchema } from '../schemas/relayer_api_order_schema';
import { relayerApiOrderBookResponseSchema } from '../schemas/relayer_api_orderbook_response_schema';
import {
- relayerApiTokenPairsResponseSchema,
- relayerApiTokenTradeInfoSchema,
-} from '../schemas/relayer_api_token_pairs_response_schema';
+ relayerApiOrdersChannelSubscribePayload,
+ relayerApiOrdersChannelSubscribeSchema,
+} from '../schemas/relayer_api_orders_channel_subscribe_schema';
+import { relayerApiOrdersChannelUpdateSchema } from '../schemas/relayer_api_orders_channel_update_response_schema';
+import { relayerApiOrdersResponseSchema } from '../schemas/relayer_api_orders_response_schema';
+import { relayerApiOrdersSchema } from '../schemas/relayer_api_orders_schema';
import { signedOrdersSchema } from '../schemas/signed_orders_schema';
import { tokenSchema } from '../schemas/token_schema';
import { jsNumber, txDataSchema } from '../schemas/tx_data_schema';
@@ -51,15 +52,18 @@ export const schemas = {
tokenSchema,
jsNumber,
txDataSchema,
+ paginatedCollectionSchema,
relayerApiErrorResponseSchema,
- relayerApiFeesPayloadSchema,
- relayerApiFeesResponseSchema,
+ relayerApiOrderSchema,
+ relayerApiOrdersSchema,
+ relayerApiOrderConfigPayloadSchema,
+ relayerApiOrderConfigResponseSchema,
relayerApiOrderBookResponseSchema,
- relayerApiTokenPairsResponseSchema,
- relayerApiTokenTradeInfoSchema,
- relayerApiOrderbookChannelSubscribeSchema,
- relayerApiOrderbookChannelSubscribePayload,
- relayerApiOrderbookChannelUpdateSchema,
- relayerApiOrderbookChannelSnapshotSchema,
- relayerApiOrderbookChannelSnapshotPayload,
+ relayerApiAssetDataPairsResponseSchema,
+ relayerApiAssetDataTradeInfoSchema,
+ relayerApiOrdersChannelSubscribeSchema,
+ relayerApiOrdersChannelSubscribePayload,
+ relayerApiOrdersChannelUpdateSchema,
+ relayerApiOrdersResponseSchema,
+ relayerApiAssetDataPairsSchema,
};
diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts
index f84553df1..01fa53045 100644
--- a/packages/json-schemas/test/schema_test.ts
+++ b/packages/json-schemas/test/schema_test.ts
@@ -26,14 +26,16 @@ const {
tokenSchema,
jsNumber,
txDataSchema,
+ paginatedCollectionSchema,
relayerApiErrorResponseSchema,
relayerApiOrderBookResponseSchema,
- relayerApiTokenPairsResponseSchema,
- relayerApiFeesPayloadSchema,
- relayerApiFeesResponseSchema,
- relayerApiOrderbookChannelSubscribeSchema,
- relayerApiOrderbookChannelUpdateSchema,
- relayerApiOrderbookChannelSnapshotSchema,
+ relayerApiAssetDataPairsResponseSchema,
+ relayerApiOrderConfigPayloadSchema,
+ relayerApiOrderConfigResponseSchema,
+ relayerApiOrdersChannelSubscribeSchema,
+ relayerApiOrdersChannelUpdateSchema,
+ relayerApiOrdersResponseSchema,
+ relayerApiOrderSchema,
} = schemas;
describe('Schema', () => {
@@ -55,6 +57,11 @@ describe('Schema', () => {
}
});
};
+ const paginatedResponse = {
+ total: 100,
+ perPage: 10,
+ page: 3,
+ };
describe('#numberSchema', () => {
it('should validate valid numbers', () => {
const testCases = ['42', '0', '1.3', '0.2', '00.00'];
@@ -166,6 +173,29 @@ describe('Schema', () => {
validateAgainstSchema(testCases, tokenSchema, shouldFail);
});
});
+ describe('#paginatedCollectionSchema', () => {
+ it('should validate valid paginated collections', () => {
+ const testCases = [paginatedResponse];
+ validateAgainstSchema(testCases, paginatedCollectionSchema);
+ });
+ it('should fail for invalid paginated collections', () => {
+ const paginatedCollectionNoTotal = {
+ page: 10,
+ perPage: 2,
+ };
+ const paginatedCollectionNoPerPage = {
+ page: 10,
+ total: 100,
+ };
+ const paginatedCollectionNoPage = {
+ total: 10,
+ perPage: 20,
+ };
+ const testCases = [{}, paginatedCollectionNoPage, paginatedCollectionNoPerPage, paginatedCollectionNoTotal];
+ const shouldFail = true;
+ validateAgainstSchema(testCases, paginatedCollectionSchema, shouldFail);
+ });
+ });
describe('order including schemas', () => {
const order = {
makerAddress: NULL_ADDRESS,
@@ -182,6 +212,14 @@ describe('Schema', () => {
exchangeAddress: NULL_ADDRESS,
expirationTimeSeconds: '42',
};
+ const relayerApiOrder = {
+ order,
+ remainingFillableAmount: '50000000000000',
+ };
+ const relayerApiOrdersResponse = {
+ ...paginatedResponse,
+ records: [relayerApiOrder, relayerApiOrder],
+ };
describe('#orderSchema', () => {
it('should validate valid order', () => {
const testCases = [order];
@@ -308,303 +346,453 @@ describe('Schema', () => {
validateAgainstSchema(testCases, orderFillRequestsSchema, shouldFail);
});
});
- describe('#relayerApiOrderBookResponseSchema', () => {
- it('should validate valid order book responses', () => {
- const testCases = [
- {
- bids: [],
- asks: [],
- },
- {
- bids: [signedOrder, signedOrder],
- asks: [],
- },
- {
- bids: [],
- asks: [signedOrder, signedOrder],
- },
- {
- bids: [signedOrder],
- asks: [signedOrder, signedOrder],
- },
- ];
- validateAgainstSchema(testCases, relayerApiOrderBookResponseSchema);
+ describe('standard relayer api schemas', () => {
+ describe('#relayerApiOrderSchema', () => {
+ it('should validate valid relayer api order', () => {
+ const testCases = [relayerApiOrder];
+ validateAgainstSchema(testCases, relayerApiOrderSchema);
+ });
+ it('should fail for invalid relayer api orders', () => {
+ const testCases = [{}, order, { order }, { order, remainingFillableAmount: 5 }];
+ const shouldFail = true;
+ validateAgainstSchema(testCases, relayerApiOrderSchema, shouldFail);
+ });
});
- it('should fail for invalid order fill requests', () => {
- const testCases = [
- {},
- {
- bids: [signedOrder, signedOrder],
- },
- {
- asks: [signedOrder, signedOrder],
- },
- {
- bids: signedOrder,
- asks: [signedOrder, signedOrder],
- },
- {
- bids: [signedOrder],
- asks: signedOrder,
- },
- ];
- const shouldFail = true;
- validateAgainstSchema(testCases, relayerApiOrderBookResponseSchema, shouldFail);
+ describe('#relayerApiErrorResponseSchema', () => {
+ it('should validate valid errorResponse', () => {
+ const testCases = [
+ {
+ code: 102,
+ reason: 'Order submission disabled',
+ },
+ {
+ code: 101,
+ reason: 'Validation failed',
+ validationErrors: [
+ {
+ field: 'maker',
+ code: 1002,
+ reason: 'Invalid address',
+ },
+ ],
+ },
+ ];
+ validateAgainstSchema(testCases, relayerApiErrorResponseSchema);
+ });
+ it('should fail for invalid error responses', () => {
+ const testCases = [
+ {},
+ {
+ code: 102,
+ },
+ {
+ code: '102',
+ reason: 'Order submission disabled',
+ },
+ {
+ reason: 'Order submission disabled',
+ },
+ {
+ code: 101,
+ reason: 'Validation failed',
+ validationErrors: [
+ {
+ field: 'maker',
+ reason: 'Invalid address',
+ },
+ ],
+ },
+ {
+ code: 101,
+ reason: 'Validation failed',
+ validationErrors: [
+ {
+ field: 'maker',
+ code: '1002',
+ reason: 'Invalid address',
+ },
+ ],
+ },
+ ];
+ const shouldFail = true;
+ validateAgainstSchema(testCases, relayerApiErrorResponseSchema, shouldFail);
+ });
});
- });
- describe('#relayerApiOrderbookChannelSubscribeSchema', () => {
- it('should validate valid orderbook channel websocket subscribe message', () => {
- const testCases = [
- {
- type: 'subscribe',
- channel: 'orderbook',
- requestId: 1,
- payload: {
- baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- snapshot: true,
- limit: 100,
+ describe('#relayerApiOrderConfigPayloadSchema', () => {
+ it('should validate valid fees payloads', () => {
+ const testCases = [
+ {
+ exchangeAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ makerAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ takerAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ makerAssetData: NULL_ADDRESS,
+ takerAssetData: NULL_ADDRESS,
+ makerAssetAmount: '10000000000000000000',
+ takerAssetAmount: '30000000000000000000',
+ expirationTimeSeconds: '42',
},
- },
- {
- type: 'subscribe',
- channel: 'orderbook',
- requestId: 1,
- payload: {
- baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ ];
+ validateAgainstSchema(testCases, relayerApiOrderConfigPayloadSchema);
+ });
+ it('should fail for invalid fees payloads', () => {
+ const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32';
+ const testCases = [
+ {},
+ {
+ makerAssetAmount: '10000000000000000000',
+ takerAssetAmount: '30000000000000000000',
+ makerAssetData: NULL_ADDRESS,
+ takerAssetData: NULL_ADDRESS,
},
- },
- ];
- validateAgainstSchema(testCases, relayerApiOrderbookChannelSubscribeSchema);
+ {
+ takerAddress: checksummedAddress,
+ makerAssetAmount: '10000000000000000000',
+ takerAssetAmount: '30000000000000000000',
+ },
+ {
+ makerAssetAmount: 10000000000000000000,
+ takerAssetAmount: 30000000000000000000,
+ },
+ ];
+ const shouldFail = true;
+ validateAgainstSchema(testCases, relayerApiOrderConfigPayloadSchema, shouldFail);
+ });
});
- it('should fail for invalid orderbook channel websocket subscribe message', () => {
- const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32';
- const testCases = [
- {
- type: 'subscribe',
- channel: 'orderbook',
- payload: {
- baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- snapshot: true,
- limit: 100,
+ describe('#relayerApiOrderConfigResponseSchema', () => {
+ it('should validate valid fees responses', () => {
+ const testCases = [
+ {
+ makerFee: '10000000000000000',
+ takerFee: '30000000000000000',
+ feeRecipientAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ senderAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
},
- },
- {
- type: 'foo',
- channel: 'orderbook',
- requestId: 1,
- payload: {
- baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ ];
+ validateAgainstSchema(testCases, relayerApiOrderConfigResponseSchema);
+ });
+ it('should fail for invalid fees responses', () => {
+ const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32';
+ const testCases = [
+ {},
+ {
+ makerFee: 10000000000000000,
+ takerFee: 30000000000000000,
},
- },
- {
- type: 'subscribe',
- channel: 'bar',
- requestId: 1,
- payload: {
- baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ {
+ feeRecipient: checksummedAddress,
+ takerToSpecify: checksummedAddress,
+ makerFee: '10000000000000000',
+ takerFee: '30000000000000000',
},
- },
- {
- type: 'subscribe',
- channel: 'orderbook',
- requestId: 1,
- payload: {
- baseTokenAddress: checksummedAddress,
- quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ ];
+ const shouldFail = true;
+ validateAgainstSchema(testCases, relayerApiOrderConfigResponseSchema, shouldFail);
+ });
+ });
+ describe('#relayerAssetDataPairsResponseSchema', () => {
+ it('should validate valid assetPairs response', () => {
+ const testCases = [
+ {
+ ...paginatedResponse,
+ records: [],
},
- },
- {
- type: 'subscribe',
- channel: 'orderbook',
- requestId: 1,
- payload: {
- baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- quoteTokenAddress: checksummedAddress,
+ {
+ ...paginatedResponse,
+ records: [
+ {
+ assetDataA: {
+ assetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ minAmount: '0',
+ maxAmount: '10000000000000000000',
+ precision: 5,
+ },
+ assetDataB: {
+ assetData: '0xef7fff64389b814a946f3e92105513705ca6b990',
+ minAmount: '0',
+ maxAmount: '50000000000000000000',
+ precision: 5,
+ },
+ },
+ ],
},
- },
- {
- type: 'subscribe',
- channel: 'orderbook',
- requestId: 1,
- payload: {
- quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ {
+ ...paginatedResponse,
+ records: [
+ {
+ assetDataA: {
+ assetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ },
+ assetDataB: {
+ assetData: '0xef7fff64389b814a946f3e92105513705ca6b990',
+ },
+ },
+ ],
},
- },
- {
- type: 'subscribe',
- channel: 'orderbook',
- requestId: 1,
- payload: {
- baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ ];
+ validateAgainstSchema(testCases, relayerApiAssetDataPairsResponseSchema);
+ });
+ it('should fail for invalid assetPairs responses', () => {
+ const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32';
+ const testCases = [
+ {
+ ...paginatedResponse,
+ records: [
+ {
+ assetDataA: {
+ assetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ minAmount: '0',
+ maxAmount: '10000000000000000000',
+ precision: 5,
+ },
+ assetDataC: {
+ assetData: '0xef7fff64389b814a946f3e92105513705ca6b990',
+ minAmount: '0',
+ maxAmount: '50000000000000000000',
+ precision: 5,
+ },
+ },
+ ],
},
- },
- {
- type: 'subscribe',
- channel: 'orderbook',
- requestId: 1,
- payload: {
- baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- snapshot: 'true',
- limit: 100,
+ {
+ records: [
+ {
+ assetDataA: {
+ assetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
+ minAmount: '0',
+ maxAmount: '10000000000000000000',
+ precision: 5,
+ },
+ assetDataB: {
+ assetData: '0xef7fff64389b814a946f3e92105513705ca6b990',
+ minAmount: '0',
+ maxAmount: '50000000000000000000',
+ precision: 5,
+ },
+ },
+ ],
},
- },
- {
- type: 'subscribe',
- channel: 'orderbook',
- requestId: 1,
- payload: {
- baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- snapshot: true,
- limit: '100',
+ {
+ ...paginatedResponse,
+ records: [
+ {
+ assetDataA: {
+ minAmount: '0',
+ maxAmount: '10000000000000000000',
+ precision: 5,
+ },
+ assetDataB: {
+ minAmount: '0',
+ maxAmount: '50000000000000000000',
+ precision: 5,
+ },
+ },
+ ],
},
- },
- ];
- const shouldFail = true;
- validateAgainstSchema(testCases, relayerApiOrderbookChannelSubscribeSchema, shouldFail);
+ ];
+ const shouldFail = true;
+ validateAgainstSchema(testCases, relayerApiAssetDataPairsResponseSchema, shouldFail);
+ });
});
- });
- describe('#relayerApiOrderbookChannelSnapshotSchema', () => {
- it('should validate valid orderbook channel websocket snapshot message', () => {
- const testCases = [
- {
- type: 'snapshot',
- channel: 'orderbook',
- requestId: 2,
- payload: {
- bids: [],
- asks: [],
+ describe('#relayerApiOrdersResponseSchema', () => {
+ it('should validate valid orders responses', () => {
+ const testCases = [
+ relayerApiOrdersResponse,
+ {
+ ...paginatedResponse,
+ records: [],
},
- },
- {
- type: 'snapshot',
- channel: 'orderbook',
- requestId: 2,
- payload: {
- bids: [signedOrder],
- asks: [signedOrder],
+ ];
+ validateAgainstSchema(testCases, relayerApiOrdersResponseSchema);
+ });
+ it('should fail for invalid orders responses', () => {
+ const testCases = [
+ {
+ records: [relayerApiOrder, relayerApiOrder],
},
- },
- ];
- validateAgainstSchema(testCases, relayerApiOrderbookChannelSnapshotSchema);
- });
- it('should fail for invalid orderbook channel websocket snapshot message', () => {
- const testCases = [
- {
- type: 'foo',
- channel: 'orderbook',
- requestId: 2,
- payload: {
- bids: [signedOrder],
- asks: [signedOrder],
+ {
+ ...paginatedResponse,
},
- },
- {
- type: 'snapshot',
- channel: 'bar',
- requestId: 2,
- payload: {
- bids: [signedOrder],
- asks: [signedOrder],
+ {
+ ...paginatedResponse,
+ records: [{}, relayerApiOrder],
},
- },
- {
- type: 'snapshot',
- channel: 'orderbook',
- payload: {
- bids: [signedOrder],
- asks: [signedOrder],
+ ];
+ const shouldFail = true;
+ validateAgainstSchema(testCases, relayerApiOrdersResponseSchema, shouldFail);
+ });
+ });
+ describe('#relayerApiOrderBookResponseSchema', () => {
+ it('should validate valid order book responses', () => {
+ const testCases = [
+ {
+ bids: {
+ ...paginatedResponse,
+ records: [relayerApiOrder],
+ },
+ asks: {
+ ...paginatedResponse,
+ records: [],
+ },
},
- },
- {
- type: 'snapshot',
- channel: 'orderbook',
- requestId: '2',
- payload: {
- bids: [signedOrder],
- asks: [signedOrder],
+ {
+ bids: {
+ ...paginatedResponse,
+ records: [relayerApiOrder, relayerApiOrder],
+ },
+ asks: {
+ ...paginatedResponse,
+ records: [relayerApiOrder, relayerApiOrder],
+ },
},
- },
- {
- type: 'snapshot',
- channel: 'orderbook',
- requestId: 2,
- payload: {
- bids: [signedOrder],
+ {
+ bids: {
+ ...paginatedResponse,
+ records: [],
+ },
+ asks: {
+ ...paginatedResponse,
+ records: [relayerApiOrder, relayerApiOrder],
+ },
},
- },
- {
- type: 'snapshot',
- channel: 'orderbook',
- requestId: 2,
- payload: {
- asks: [signedOrder],
+ ];
+ validateAgainstSchema(testCases, relayerApiOrderBookResponseSchema);
+ });
+ it('should fail for invalid order fill requests', () => {
+ const testCases = [
+ {},
+ {
+ bids: {
+ records: [relayerApiOrder],
+ },
+ asks: {
+ ...paginatedResponse,
+ records: [],
+ },
},
- },
- {
- type: 'snapshot',
- channel: 'orderbook',
- requestId: 2,
- payload: {
- bids: [signedOrder],
- asks: [{}],
+ {
+ bids: {
+ ...paginatedResponse,
+ records: [relayerApiOrder, relayerApiOrder],
+ },
+ asks: {},
},
- },
- {
- type: 'snapshot',
- channel: 'orderbook',
- requestId: 2,
- payload: {
- bids: [{}],
- asks: [signedOrder],
+ {
+ bids: {
+ ...paginatedResponse,
+ },
+ asks: {
+ ...paginatedResponse,
+ records: [relayerApiOrder, relayerApiOrder],
+ },
},
- },
- ];
- const shouldFail = true;
- validateAgainstSchema(testCases, relayerApiOrderbookChannelSnapshotSchema, shouldFail);
+ ];
+ const shouldFail = true;
+ validateAgainstSchema(testCases, relayerApiOrdersResponseSchema, shouldFail);
+ });
});
- });
- describe('#relayerApiOrderbookChannelUpdateSchema', () => {
- it('should validate valid orderbook channel websocket update message', () => {
- const testCases = [
- {
- type: 'update',
- channel: 'orderbook',
- requestId: 2,
- payload: signedOrder,
- },
- ];
- validateAgainstSchema(testCases, relayerApiOrderbookChannelUpdateSchema);
+ describe('#relayerApiOrdersChannelSubscribeSchema', () => {
+ it('should validate valid orders channel websocket subscribe message', () => {
+ const testCases = [
+ {
+ type: 'subscribe',
+ channel: 'orders',
+ requestId: 'randomId',
+ },
+ {
+ type: 'subscribe',
+ channel: 'orders',
+ requestId: 'randomId',
+ payload: {
+ makerAssetProxyId: '0x02571792',
+ takerAssetProxyId: '0xf47261b0',
+ },
+ },
+ {
+ type: 'subscribe',
+ channel: 'orders',
+ requestId: 'randomId',
+ payload: {},
+ },
+ ];
+ validateAgainstSchema(testCases, relayerApiOrdersChannelSubscribeSchema);
+ });
+ it('should fail for invalid orders channel websocket subscribe message', () => {
+ const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32';
+ const testCases = [
+ {
+ type: 'subscribe',
+ channel: 'orders',
+ },
+ {
+ type: 'subscribe',
+ channel: 'orders',
+ requestId: 'randomId',
+ payload: {
+ makerAssetProxyId: '0x02571792',
+ takerAssetProxyId: '0xf47261b0',
+ makerAssetAddress: checksummedAddress,
+ },
+ },
+ {
+ type: 'subscribe',
+ channel: 'orders',
+ requestId: 'randomId',
+ payload: {
+ makerAssetProxyId: 'invalidId',
+ },
+ },
+ ];
+ const shouldFail = true;
+ validateAgainstSchema(testCases, relayerApiOrdersChannelSubscribeSchema, shouldFail);
+ });
});
- it('should fail for invalid orderbook channel websocket update message', () => {
- const testCases = [
- {
- type: 'foo',
- channel: 'orderbook',
- requestId: 2,
- payload: signedOrder,
- },
- {
- type: 'update',
- channel: 'bar',
- requestId: 2,
- payload: signedOrder,
- },
- {
- type: 'update',
- channel: 'orderbook',
- requestId: 2,
- payload: {},
- },
- ];
- const shouldFail = true;
- validateAgainstSchema(testCases, relayerApiOrderbookChannelUpdateSchema, shouldFail);
+ describe('#relayerApiOrdersChannelUpdateSchema', () => {
+ it('should validate valid orders channel websocket update message', () => {
+ const testCases = [
+ {
+ type: 'update',
+ channel: 'orders',
+ requestId: 'randomId',
+ payload: [relayerApiOrder],
+ },
+ {
+ type: 'update',
+ channel: 'orders',
+ requestId: 'randomId',
+ payload: [],
+ },
+ ];
+ validateAgainstSchema(testCases, relayerApiOrdersChannelUpdateSchema);
+ });
+ it('should fail for invalid orders channel websocket update message', () => {
+ const testCases = [
+ {
+ type: 'foo',
+ channel: 'orders',
+ requestId: 'randomId',
+ },
+ {
+ type: 'update',
+ channel: 'bar',
+ requestId: 2,
+ payload: [relayerApiOrder],
+ },
+ {
+ type: 'update',
+ channel: 'orders',
+ requestId: 'randomId',
+ payload: {},
+ },
+ {
+ type: 'update',
+ channel: 'orders',
+ requestId: 'randomId',
+ payload: relayerApiErrorResponseSchema,
+ },
+ ];
+ const shouldFail = true;
+ validateAgainstSchema(testCases, relayerApiOrdersChannelUpdateSchema, shouldFail);
+ });
});
});
});
@@ -624,217 +812,6 @@ describe('Schema', () => {
});
});
});
- describe('#relayerApiErrorResponseSchema', () => {
- it('should validate valid errorResponse', () => {
- const testCases = [
- {
- code: 102,
- reason: 'Order submission disabled',
- },
- {
- code: 101,
- reason: 'Validation failed',
- validationErrors: [
- {
- field: 'maker',
- code: 1002,
- reason: 'Invalid address',
- },
- ],
- },
- ];
- validateAgainstSchema(testCases, relayerApiErrorResponseSchema);
- });
- it('should fail for invalid error responses', () => {
- const testCases = [
- {},
- {
- code: 102,
- },
- {
- code: '102',
- reason: 'Order submission disabled',
- },
- {
- reason: 'Order submission disabled',
- },
- {
- code: 101,
- reason: 'Validation failed',
- validationErrors: [
- {
- field: 'maker',
- reason: 'Invalid address',
- },
- ],
- },
- {
- code: 101,
- reason: 'Validation failed',
- validationErrors: [
- {
- field: 'maker',
- code: '1002',
- reason: 'Invalid address',
- },
- ],
- },
- ];
- const shouldFail = true;
- validateAgainstSchema(testCases, relayerApiErrorResponseSchema, shouldFail);
- });
- });
- describe('#relayerApiFeesPayloadSchema', () => {
- it('should validate valid fees payloads', () => {
- const testCases = [
- {
- exchangeContractAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- maker: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- taker: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990',
- makerTokenAmount: '10000000000000000000',
- takerTokenAmount: '30000000000000000000',
- expirationUnixTimestampSec: '42',
- salt: '67006738228878699843088602623665307406148487219438534730168799356281242528500',
- },
- ];
- validateAgainstSchema(testCases, relayerApiFeesPayloadSchema);
- });
- it('should fail for invalid fees payloads', () => {
- const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32';
- const testCases = [
- {},
- {
- takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990',
- makerTokenAmount: '10000000000000000000',
- takerTokenAmount: '30000000000000000000',
- },
- {
- taker: checksummedAddress,
- makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990',
- makerTokenAmount: '10000000000000000000',
- takerTokenAmount: '30000000000000000000',
- },
- {
- makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990',
- makerTokenAmount: 10000000000000000000,
- takerTokenAmount: 30000000000000000000,
- },
- ];
- const shouldFail = true;
- validateAgainstSchema(testCases, relayerApiFeesPayloadSchema, shouldFail);
- });
- });
- describe('#relayerApiFeesResponseSchema', () => {
- it('should validate valid fees responses', () => {
- const testCases = [
- {
- makerFee: '10000000000000000',
- takerFee: '30000000000000000',
- feeRecipient: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- },
- ];
- validateAgainstSchema(testCases, relayerApiFeesResponseSchema);
- });
- it('should fail for invalid fees responses', () => {
- const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32';
- const testCases = [
- {},
- {
- makerFee: 10000000000000000,
- takerFee: 30000000000000000,
- },
- {
- feeRecipient: checksummedAddress,
- takerToSpecify: checksummedAddress,
- makerFee: '10000000000000000',
- takerFee: '30000000000000000',
- },
- ];
- const shouldFail = true;
- validateAgainstSchema(testCases, relayerApiFeesResponseSchema, shouldFail);
- });
- });
- describe('#relayerApiTokenPairsResponseSchema', () => {
- it('should validate valid tokenPairs response', () => {
- const testCases = [
- [],
- [
- {
- tokenA: {
- address: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- minAmount: '0',
- maxAmount: '10000000000000000000',
- precision: 5,
- },
- tokenB: {
- address: '0xef7fff64389b814a946f3e92105513705ca6b990',
- minAmount: '0',
- maxAmount: '50000000000000000000',
- precision: 5,
- },
- },
- ],
- [
- {
- tokenA: {
- address: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- },
- tokenB: {
- address: '0xef7fff64389b814a946f3e92105513705ca6b990',
- },
- },
- ],
- ];
- validateAgainstSchema(testCases, relayerApiTokenPairsResponseSchema);
- });
- it('should fail for invalid tokenPairs responses', () => {
- const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32';
- const testCases = [
- [
- {
- tokenA: {
- address: checksummedAddress,
- },
- tokenB: {
- address: checksummedAddress,
- },
- },
- ],
- [
- {
- tokenA: {
- address: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- minAmount: 0,
- maxAmount: 10000000000000000000,
- },
- tokenB: {
- address: '0xef7fff64389b814a946f3e92105513705ca6b990',
- minAmount: 0,
- maxAmount: 50000000000000000000,
- },
- },
- ],
- [
- {
- tokenA: {
- address: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
- precision: '5',
- },
- tokenB: {
- address: '0xef7fff64389b814a946f3e92105513705ca6b990',
- precision: '5',
- },
- },
- ],
- ];
- const shouldFail = true;
- validateAgainstSchema(testCases, relayerApiTokenPairsResponseSchema, shouldFail);
- });
- });
describe('#jsNumberSchema', () => {
it('should validate valid js number', () => {
// tslint:disable-next-line:custom-no-magic-numbers
diff --git a/packages/sra-api/.discharge.json b/packages/sra-api/.discharge.json
new file mode 100644
index 000000000..ddb76d50d
--- /dev/null
+++ b/packages/sra-api/.discharge.json
@@ -0,0 +1,13 @@
+{
+ "domain": "sra-api.com",
+ "build_command": "yarn build-site",
+ "upload_directory": "public",
+ "index_key": "index.html",
+ "error_key": "index.html",
+ "trailing_slashes": true,
+ "cache": 3600,
+ "aws_profile": "default",
+ "aws_region": "us-east-1",
+ "cdn": false,
+ "dns_configured": true
+}
diff --git a/packages/sra-api/.npmignore b/packages/sra-api/.npmignore
new file mode 100644
index 000000000..e610180ad
--- /dev/null
+++ b/packages/sra-api/.npmignore
@@ -0,0 +1,8 @@
+.*
+yarn-error.log
+/src/
+/schemas/
+test/
+tsconfig.json
+/lib/src/monorepo_scripts/
+/public/ \ No newline at end of file
diff --git a/packages/sra-api/CHANGELOG.json b/packages/sra-api/CHANGELOG.json
new file mode 100644
index 000000000..fe51488c7
--- /dev/null
+++ b/packages/sra-api/CHANGELOG.json
@@ -0,0 +1 @@
+[]
diff --git a/packages/sra-api/README.md b/packages/sra-api/README.md
new file mode 100644
index 000000000..23eefe7d8
--- /dev/null
+++ b/packages/sra-api/README.md
@@ -0,0 +1,97 @@
+## @0xproject/sra-api
+
+Contains the Standard Relayer API [OpenAPI Spec](https://github.com/OAI/OpenAPI-Specification).
+
+The package distributes both a javascript object version and a json version.
+
+A deployed [ReDoc](https://github.com/Rebilly/ReDoc) static site with the API can be found here http://sra-api.com.s3-website-us-east-1.amazonaws.com/.
+
+## Usage
+
+```
+import { api } from '@0xproject/sra-api';
+```
+
+## Installation
+
+```
+yarn install
+```
+
+## Development
+
+You can start a development server that will serve a [ReDoc](https://github.com/Rebilly/ReDoc) documentation instance. It uses the `api.json` file from `lib/` (you must have built at least once with `yarn build` or `yarn build-json`) that is based on the `api` object exported from `src`.
+
+```
+yarn watch_without_deps
+```
+
+The process will watch for changes, but will not hot-reload so you must refresh the page to see the changes.
+
+## Contributing
+
+We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository.
+
+Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
+
+### Install dependencies
+
+If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
+
+```bash
+yarn config set workspaces-experimental true
+```
+
+Then install dependencies
+
+```bash
+yarn install
+```
+
+### Build
+
+To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory:
+
+```bash
+PKG=@0xproject/sra-api yarn build
+```
+
+Or continuously rebuild on change:
+
+```bash
+PKG=@0xproject/sra-api yarn watch
+```
+
+### Static Site
+
+We also [host a static HTML version of the docs on S3](http://sra-api.com.s3-website-us-east-1.amazonaws.com/) for easy sharing.
+
+To build the website run
+
+```
+yarn build-site
+```
+
+To build and deploy the site run
+
+```
+yarn deploy-site
+```
+
+### Clean
+
+```bash
+yarn clean
+```
+
+### Lint
+
+```bash
+yarn lint
+```
+
+### Run Tests
+
+```bash
+yarn test
+```
diff --git a/packages/sra-api/package.json b/packages/sra-api/package.json
new file mode 100644
index 000000000..4e0fb1637
--- /dev/null
+++ b/packages/sra-api/package.json
@@ -0,0 +1,62 @@
+{
+ "name": "@0xproject/sra-api",
+ "version": "0.0.1",
+ "engines": {
+ "node": ">=6.12"
+ },
+ "description": "Standard Relayer API Open API Spec",
+ "main": "lib/src/index.js",
+ "types": "lib/src/index.d.ts",
+ "scripts": {
+ "serve": "redoc-cli serve lib/api.json --watch",
+ "watch_without_deps": "run-p build-json:watch serve",
+ "lint": "tslint --project .",
+ "test": "yarn run_mocha",
+ "rebuild_and_test": "run-s clean build test",
+ "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
+ "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
+ "test:circleci": "yarn test:coverage",
+ "run_mocha": "mocha lib/test/**/*_test.js --exit",
+ "clean": "shx rm -rf lib",
+ "build": "tsc && yarn build-json",
+ "build-site": "yarn build && redoc-cli bundle lib/api.json --output public/index.html",
+ "build-json": "ts-node scripts/buildJson.ts",
+ "build-json:watch": "chokidar 'src/**/*' -c 'yarn build-json' ",
+ "deploy-site": "discharge deploy"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/0xProject/0x-monorepo.git"
+ },
+ "author": "Francesco Agosti",
+ "license": "Apache-2.0",
+ "bugs": {
+ "url": "https://github.com/0xProject/0x-monorepo/issues"
+ },
+ "homepage": "https://github.com/0xProject/0x-monorepo/packages/sra-api/README.md",
+ "dependencies": {
+ "@0xproject/json-schemas": "1.0.1-rc.3"
+ },
+ "devDependencies": {
+ "@0xproject/tslint-config": "^1.0.4",
+ "@loopback/openapi-v3-types": "^0.8.2",
+ "@types/mocha": "^2.2.42",
+ "@types/node": "^10.5.3",
+ "chai": "^4.0.1",
+ "chokidar-cli": "^1.2.0",
+ "dirty-chai": "^2.0.1",
+ "discharge": "^0.7.1",
+ "mocha": "^4.0.1",
+ "npm-run-all": "^4.1.3",
+ "nyc": "^11.0.1",
+ "openapi-schema-validation": "^0.4.1",
+ "redoc-cli": "^0.6.1",
+ "shx": "^0.2.2",
+ "ts-node": "^7.0.0",
+ "tslint": "5.11.0",
+ "typescript": "2.7.1"
+ },
+ "publishConfig": {
+ "access": "public"
+ }
+}
diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts
new file mode 100644
index 000000000..762d3f4d6
--- /dev/null
+++ b/packages/sra-api/src/api.ts
@@ -0,0 +1,61 @@
+import { schemas } from '@0xproject/json-schemas';
+import { OpenApiSpec } from '@loopback/openapi-v3-types';
+
+import { examples } from './examples';
+import { md } from './md';
+import { generateParameters } from './parameters';
+import { generateResponses } from './responses';
+// We need to replace the `$ref`s to be openAPI compliant.
+const openApiSchemas = JSON.parse(JSON.stringify(schemas).replace(/(\/\w+)/g, match => `#/components/schemas${match}`));
+
+export const api: OpenApiSpec = {
+ openapi: '3.0.0',
+ info: {
+ version: '2.0.0',
+ title: 'Standard Relayer REST API',
+ description: md.introduction,
+ license: {
+ name: 'Apache 2.0',
+ url: 'https://www.apache.org/licenses/LICENSE-2.0.html',
+ },
+ },
+ paths: {
+ '/v2/asset_pairs': {
+ get: {
+ description:
+ 'Retrieves a list of available asset pairs and the information required to trade them (in any order). Setting only `asset_data_a` or `asset_data_b` returns pairs filtered by that asset only.',
+ operationId: 'getAssetPairs',
+ parameters: generateParameters(
+ [
+ {
+ name: 'asset_data_a',
+ in: 'query',
+ description: 'The assetData value for the first asset in the pair.',
+ example: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
+ schema: {
+ $ref: '#/components/schemas/hexSchema',
+ },
+ },
+ {
+ name: 'asset_data_b',
+ in: 'query',
+ description: 'The assetData value for the second asset in the pair.',
+ example: '0x0257179264389b814a946f3e92105513705ca6b990',
+ schema: {
+ $ref: '#/components/schemas/hexSchema',
+ },
+ },
+ ],
+ true,
+ ),
+ responses: generateResponses(
+ 'relayerApiAssetDataPairsResponseSchema',
+ examples.relayerApiAssetDataPairsResponseSchema,
+ ),
+ },
+ },
+ },
+ components: {
+ schemas: openApiSchemas,
+ },
+};
diff --git a/packages/sra-api/src/errors.ts b/packages/sra-api/src/errors.ts
new file mode 100644
index 000000000..20c35514f
--- /dev/null
+++ b/packages/sra-api/src/errors.ts
@@ -0,0 +1,24 @@
+import { examples } from './examples';
+export const errorResponses = {
+ '400': {
+ description: 'Validation error',
+ content: {
+ 'application/json': {
+ schema: { $ref: '#/components/schemas/relayerApiErrorResponseSchema' },
+ example: examples.validationError,
+ },
+ },
+ },
+ '404': {
+ description: 'Not found',
+ },
+ '429': {
+ description: 'Too many requests - Rate limit exceeded',
+ },
+ '500': {
+ description: 'Internal Server Error',
+ },
+ '501': {
+ description: 'Not implemented.',
+ },
+};
diff --git a/packages/sra-api/src/examples/errors.ts b/packages/sra-api/src/examples/errors.ts
new file mode 100644
index 000000000..81f29d81c
--- /dev/null
+++ b/packages/sra-api/src/examples/errors.ts
@@ -0,0 +1,11 @@
+export const validationError = {
+ code: 100,
+ reason: 'Validation failed',
+ validationErrors: [
+ {
+ field: 'networkId',
+ code: 1006,
+ reason: 'Network id 42 is not supported',
+ },
+ ],
+};
diff --git a/packages/sra-api/src/examples/index.ts b/packages/sra-api/src/examples/index.ts
new file mode 100644
index 000000000..eeeb353b3
--- /dev/null
+++ b/packages/sra-api/src/examples/index.ts
@@ -0,0 +1,7 @@
+import { validationError } from './errors';
+import { relayerApiAssetDataPairsResponseSchema } from './relayerApiAssetDataPairsResponseSchema';
+
+export const examples = {
+ validationError,
+ relayerApiAssetDataPairsResponseSchema,
+};
diff --git a/packages/sra-api/src/examples/relayerApiAssetDataPairsResponseSchema.ts b/packages/sra-api/src/examples/relayerApiAssetDataPairsResponseSchema.ts
new file mode 100644
index 000000000..89a0c82fb
--- /dev/null
+++ b/packages/sra-api/src/examples/relayerApiAssetDataPairsResponseSchema.ts
@@ -0,0 +1,21 @@
+export const relayerApiAssetDataPairsResponseSchema = {
+ total: 43,
+ page: 1,
+ perPage: 100,
+ records: [
+ {
+ assetDataA: {
+ minAmount: '0',
+ maxAmount: '10000000000000000000',
+ precision: 5,
+ assetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
+ },
+ assetDataB: {
+ minAmount: '0',
+ maxAmount: '50000000000000000000',
+ precision: 5,
+ assetData: '0x0257179264389b814a946f3e92105513705ca6b990',
+ },
+ },
+ ],
+};
diff --git a/packages/sra-api/src/headers.ts b/packages/sra-api/src/headers.ts
new file mode 100644
index 000000000..152254c9f
--- /dev/null
+++ b/packages/sra-api/src/headers.ts
@@ -0,0 +1,20 @@
+export const headers = {
+ 'X-Rate-Limit-Limit': {
+ description: `The maximum number of requests you're permitted to make per hour.`,
+ schema: {
+ type: 'integer',
+ },
+ },
+ 'X-Rate-Limit-Remaining': {
+ description: 'The number of requests remaining in the current rate limit window.',
+ schema: {
+ type: 'integer',
+ },
+ },
+ 'X-Rate-Limit-Reset': {
+ description: 'The time at which the current rate limit window resets in UTC epoch seconds.',
+ schema: {
+ type: 'integer',
+ },
+ },
+};
diff --git a/packages/sra-api/src/index.ts b/packages/sra-api/src/index.ts
new file mode 100644
index 000000000..4d73f3cd3
--- /dev/null
+++ b/packages/sra-api/src/index.ts
@@ -0,0 +1 @@
+export { api } from './api';
diff --git a/packages/sra-api/src/md/index.ts b/packages/sra-api/src/md/index.ts
new file mode 100644
index 000000000..076c3c45c
--- /dev/null
+++ b/packages/sra-api/src/md/index.ts
@@ -0,0 +1,5 @@
+import { readFileSync } from 'fs';
+
+export const md = {
+ introduction: readFileSync('src/md/introduction.md').toString(),
+};
diff --git a/packages/sra-api/src/md/introduction.md b/packages/sra-api/src/md/introduction.md
new file mode 100644
index 000000000..c3aa4d4da
--- /dev/null
+++ b/packages/sra-api/src/md/introduction.md
@@ -0,0 +1,180 @@
+# Pagination
+
+Requests that return potentially large collections should respond to the **?page** and **?per_page** parameters. For example:
+
+```
+curl https://api.example-relayer.com/v2/token_pairs?page=3&per_page=20
+```
+
+Page numbering should be 1-indexed, not 0-indexed. If a query provides an unreasonable (ie. too high) **per_page** value, the response can return a validation error as specified in the [errors section](#errors). If the query specifies a **page** that does not exist (ie. there are not enough **records**), the response should just return an empty **records** array.
+
+All endpoints that are paginated should return a **total**, **page**, **perPage** and a **records** value in the top level of the collection. The value of **total** should be the total number of records for a given query, whereas **records** should be an array representing the response to the query for that page. **page** and **perPage**, are the same values that were specified in the request. See the note in [miscellaneous](#misc) about formatting `snake_case` vs. `lowerCamelCase`.
+
+These requests include the [`asset_pairs`](#get-v2-asset-pairs), [`orders`](#get-v2-orders), and [`orderbook`](#get-v2-orderbook) endpoints.
+
+# Network Id
+All requests should be able to specify a **?networkId** query param for all supported networks. For example:
+```
+curl https://api.example-relayer.com/v2/token_pairs?networkId=1
+```
+If the query param is not provided, it should default to **1** (mainnet).
+
+Networks and their Ids:
+
+| Network Id | Network Name |
+| ---------- | ------------ |
+| 1 | Mainnet |
+| 42 | Kovan |
+| 3 | Ropsten |
+| 4 | Rinkeby |
+
+ If a certain network is not supported, the response should **400** as specified in the [error response](#error-response) section. For example:
+
+```
+{
+ "code": 100,
+ "reason": "Validation failed",
+ "validationErrors": [
+ {
+ "field": "networkId",
+ "code": 1006,
+ "reason": "Network id 42 is not supported",
+ }
+ ]
+}
+```
+
+# Link Header
+
+A [Link Header](https://tools.ietf.org/html/rfc5988) can be included in a response to provide clients with more context about paging
+For example:
+
+```
+Link: <https://api.example-relayer.com/v2/token_pairs?page=3&per_page=20>; rel="next",
+<https://api.github.com/user/repos?page=10&per_page=20>; rel="last"
+```
+
+This `Link` response header contains one or more Hypermedia link relations.
+
+The possible `rel` values are:
+
+| Name | Description |
+| ----- | ------------------------------------------------------------- |
+| next | The link relation for the immediate next page of results. |
+| last | The link relation for the last page of results. |
+| first | The link relation for the first page of results. |
+| prev | The link relation for the immediate previous page of results. |
+
+# Rate Limits
+
+Rate limit guidance for clients can be optionally returned in the response headers:
+
+| Header Name | Description |
+| --------------------- | ---------------------------------------------------------------------------- |
+| X-RateLimit-Limit | The maximum number of requests you're permitted to make per hour. |
+| X-RateLimit-Remaining | The number of requests remaining in the current rate limit window. |
+| X-RateLimit-Reset | The time at which the current rate limit window resets in UTC epoch seconds. |
+
+For example:
+
+```
+curl -i https://api.example-relayer.com/v2/token_pairs
+HTTP/1.1 200 OK
+Date: Mon, 20 Oct 2017 12:30:06 GMT
+Status: 200 OK
+X-RateLimit-Limit: 60
+X-RateLimit-Remaining: 56
+X-RateLimit-Reset: 1372700873
+```
+When a rate limit is exceeded, a status of **429 Too Many Requests** should be returned.
+
+# Errors
+
+Unless the spec defines otherwise, errors to bad requests should respond with HTTP 4xx or status codes.
+
+## Common error codes
+
+| Code | Reason |
+| ---- | --------------------------------------- |
+| 400 | Bad Request – Invalid request format |
+| 404 | Not found |
+| 429 | Too many requests - Rate limit exceeded |
+| 500 | Internal Server Error |
+| 501 | Not Implemented |
+
+## Error reporting format
+For all **400** responses, see the [error response schema](https://github.com/0xProject/0x-monorepo/blob/development/packages/json-schemas/schemas/relayer_api_error_response_schema.ts#L1).
+
+```
+{
+ "code": 101,
+ "reason": "Validation failed",
+ "validationErrors": [
+ {
+ "field": "maker",
+ "code": 1002,
+ "reason": "Invalid address"
+ }
+ ]
+}
+```
+
+General error codes:
+
+```
+100 - Validation Failed
+101 - Malformed JSON
+102 - Order submission disabled
+103 - Throttled
+```
+
+Validation error codes:
+
+```
+1000 - Required field
+1001 - Incorrect format
+1002 - Invalid address
+1003 - Address not supported
+1004 - Value out of range
+1005 - Invalid signature or hash
+1006 - Unsupported option
+```
+
+# Asset Data Encoding
+
+As we now support multiple [token transfer proxies](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#assetproxy), the identifier of which proxy to use for the token transfer must be encoded, along with the token information. Each proxy in 0x v2 has a unique identifier. If you're using 0x.js there will be helper methods for this [encoding](https://0xproject.com/docs/0x.js#zeroEx-encodeERC20AssetData) and [decoding](https://0xproject.com/docs/0x.js#zeroEx-decodeAssetProxyId).
+
+The identifier for the Proxy uses a similar scheme to [ABI function selectors](https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI#function-selector).
+```
+// ERC20 Proxy ID 0xf47261b0
+bytes4(keccak256("ERC20Token(address)"))
+// ERC721 Proxy ID 0x08e937fa
+bytes4(keccak256("ERC721Token(address,uint256)"))
+```
+
+Asset data is encoded using [ABI encoding](https://solidity.readthedocs.io/en/develop/abi-spec.html).
+
+For example, encoding the ERC20 token contract (address: 0x1dc4c1cefef38a777b15aa20260a54e584b16c48) using the ERC20 Transfer Proxy (id: 0xf47261b0) would be:
+```
+0xf47261b00000000000000000000000001dc4c1cefef38a777b15aa20260a54e584b16c48
+```
+
+Encoding the ERC721 token contract (address: `0x371b13d97f4bf77d724e78c16b7dc74099f40e84`), token id (id: `99`, which hex encoded is `0x63`) and the ERC721 Transfer Proxy (id: 0x08e937fa) would be:
+```
+0x08e937fa000000000000000000000000371b13d97f4bf77d724e78c16b7dc74099f40e840000000000000000000000000000000000000000000000000000000000000063
+```
+
+For more information see [the Asset Proxy](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#erc20proxy) section of the v2 spec and the [Ethereum ABI Spec](https://solidity.readthedocs.io/en/develop/abi-spec.html).
+
+# Meta Data in Order Responses
+
+In v2 of the standard relayer API we added the `metaData` field. It is meant to provide a standard place for relayers to put optional, custom or non-standard fields that may of interest to the consumer of the API.
+
+A good example of such a field is `remainingTakerAssetAmount`, which is a convenience field that communicates how much of a 0x order is potentially left to be filled. Unlike the other fields in a 0x order, it is not guaranteed to be correct as it is derived from whatever mechanism the implementer (ie. the relayer) is using. While convenient for prototyping and low stakes situations, we recommend validating the value of the field by checking the state of the blockchain yourself, such as by using [Order Watcher](https://0xproject.com/wiki#0x-OrderWatcher).
+
+# Misc.
+
+* All requests and responses should be of **application/json** content type
+* All token amounts are sent in amounts of the smallest level of precision (base units). (e.g if a token has 18 decimal places, selling 1 token would show up as selling `'1000000000000000000'` units by this API).
+* All addresses are sent as lower-case (non-checksummed) Ethereum addresses with the `0x` prefix.
+* All URL query parameters are to be written in `snake_case` and all queries and responses specified in JSON should use `lowerCamelCase`.
diff --git a/packages/sra-api/src/parameters.ts b/packages/sra-api/src/parameters.ts
new file mode 100644
index 000000000..dac898931
--- /dev/null
+++ b/packages/sra-api/src/parameters.ts
@@ -0,0 +1,37 @@
+import { ParameterLocation, ParameterObject } from '@loopback/openapi-v3-types';
+export const paginationParameters: ParameterObject[] = [
+ {
+ name: 'page',
+ in: 'query',
+ description: 'The number of the page to request in the collection.',
+ example: 3,
+ schema: {
+ type: 'number',
+ },
+ },
+ {
+ name: 'per_page',
+ in: 'query',
+ description: 'The number of records to return per page.',
+ example: 10,
+ schema: {
+ type: 'number',
+ },
+ },
+];
+
+export const networkdIdParameter = {
+ name: 'network_id',
+ in: 'query',
+ description: 'The id of the Ethereum network',
+ example: 42,
+ default: 1,
+ schema: {
+ type: 'number',
+ },
+};
+
+export const generateParameters = (parameters: ParameterObject[], isPaginated: boolean = false): ParameterObject[] => {
+ const optionalParameters = isPaginated ? paginationParameters : [];
+ return [...optionalParameters, ...parameters];
+};
diff --git a/packages/sra-api/src/responses.ts b/packages/sra-api/src/responses.ts
new file mode 100644
index 000000000..59c679b9c
--- /dev/null
+++ b/packages/sra-api/src/responses.ts
@@ -0,0 +1,17 @@
+import { ResponsesObject } from '@loopback/openapi-v3-types';
+
+import { errorResponses } from './errors';
+import { headers } from './headers';
+
+export const generateResponses = (schemaName: string, example: any): ResponsesObject => ({
+ '200': {
+ headers,
+ description: 'OK',
+ content: {
+ 'application/json': {
+ schema: { $ref: `#/components/schemas/${schemaName}` },
+ },
+ },
+ },
+ ...errorResponses,
+});
diff --git a/packages/sra-api/test/api_test.ts b/packages/sra-api/test/api_test.ts
new file mode 100644
index 000000000..47353ca80
--- /dev/null
+++ b/packages/sra-api/test/api_test.ts
@@ -0,0 +1,15 @@
+import * as chai from 'chai';
+import * as dirtyChai from 'dirty-chai';
+import { validate } from 'openapi-schema-validation';
+
+import { api } from '../src/index';
+
+chai.config.includeStack = true;
+chai.use(dirtyChai);
+
+describe('SRA OpenAPI Schema', () => {
+ it('should be a valid OpenAPI schema', () => {
+ const result = validate(api, 3);
+ chai.expect(result.errors).to.have.length(0);
+ });
+});
diff --git a/packages/sra-api/tsconfig.json b/packages/sra-api/tsconfig.json
new file mode 100644
index 000000000..c56d255d5
--- /dev/null
+++ b/packages/sra-api/tsconfig.json
@@ -0,0 +1,7 @@
+{
+ "extends": "../../tsconfig",
+ "compilerOptions": {
+ "outDir": "lib"
+ },
+ "include": ["./src/**/*"]
+}
diff --git a/packages/sra-api/tslint.json b/packages/sra-api/tslint.json
new file mode 100644
index 000000000..ffaefe83a
--- /dev/null
+++ b/packages/sra-api/tslint.json
@@ -0,0 +1,3 @@
+{
+ "extends": ["@0xproject/tslint-config"]
+}
diff --git a/packages/typescript-typings/types/openapi-schema-validation/index.d.ts b/packages/typescript-typings/types/openapi-schema-validation/index.d.ts
new file mode 100644
index 000000000..123a6bdb7
--- /dev/null
+++ b/packages/typescript-typings/types/openapi-schema-validation/index.d.ts
@@ -0,0 +1 @@
+declare module 'openapi-schema-validation';