Merge pull request #916 from 0xProject/feature/sra/add-sra-package

Add the sra-api package (OpenAPI Spec)
This commit is contained in:
Francesco Agosti
2018-08-09 17:02:43 -07:00
committed by GitHub
81 changed files with 2751 additions and 1001 deletions

View File

@@ -10028,4 +10028,4 @@
"constructorArgs": "[]"
}
}
}
}

View File

@@ -5,11 +5,11 @@ export const contractWrappersPrivateNetworkConfigSchema = {
type: 'number',
minimum: 1,
},
gasPrice: { $ref: '/Number' },
zrxContractAddress: { $ref: '/Address' },
exchangeContractAddress: { $ref: '/Address' },
erc20ProxyContractAddress: { $ref: '/Address' },
erc721ProxyContractAddress: { $ref: '/Address' },
gasPrice: { $ref: '/numberSchema' },
zrxContractAddress: { $ref: '/addressSchema' },
exchangeContractAddress: { $ref: '/addressSchema' },
erc20ProxyContractAddress: { $ref: '/addressSchema' },
erc721ProxyContractAddress: { $ref: '/addressSchema' },
blockPollingIntervalMs: { type: 'number' },
orderWatcherConfig: {
type: 'object',

View File

@@ -19,11 +19,11 @@ export const contractWrappersPublicNetworkConfigSchema = {
networkNameToId.ganache,
],
},
gasPrice: { $ref: '/Number' },
zrxContractAddress: { $ref: '/Address' },
exchangeContractAddress: { $ref: '/Address' },
erc20ProxyContractAddress: { $ref: '/Address' },
erc721ProxyContractAddress: { $ref: '/Address' },
gasPrice: { $ref: '/numberSchema' },
zrxContractAddress: { $ref: '/addressSchema' },
exchangeContractAddress: { $ref: '/addressSchema' },
erc20ProxyContractAddress: { $ref: '/addressSchema' },
erc721ProxyContractAddress: { $ref: '/addressSchema' },
blockPollingIntervalMs: { type: 'number' },
orderWatcherConfig: {
type: 'object',

View File

@@ -1,7 +1,7 @@
export const methodOptsSchema = {
id: '/MethodOpts',
properties: {
defaultBlock: { $ref: '/BlockParam' },
defaultBlock: { $ref: '/blockParamSchema' },
},
type: 'object',
};

View File

@@ -1,7 +1,7 @@
export const txOptsSchema = {
id: '/TxOpts',
properties: {
gasPrice: { $ref: '/Number' },
gasPrice: { $ref: '/numberSchema' },
gasLimit: { type: 'number' },
},
type: 'object',

View File

@@ -5,6 +5,10 @@
{
"note": "Change hexSchema to match `0x`",
"pr": 937
},
{
"note": "Upgrade Relayer API schemas for relayer API V2",
"pr": 916
}
]
},

View File

@@ -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+)?$',
};

View File

@@ -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',
};

View File

@@ -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',

View File

@@ -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',

View File

@@ -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',
};

View File

@@ -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',

View File

@@ -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',

View File

@@ -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',

View File

@@ -1,5 +1,5 @@
export const orderHashSchema = {
id: '/OrderHashSchema',
id: '/orderHashSchema',
type: 'string',
pattern: '^0x[0-9a-fA-F]{64}$',
};

View File

@@ -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'],
},

View File

@@ -1,5 +1,5 @@
export const ordersSchema = {
id: '/ordersSchema',
type: 'array',
items: { $ref: '/Order' },
items: { $ref: '/orderSchema' },
};

View File

@@ -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'],
};

View File

@@ -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'],
};

View File

@@ -1,8 +1,8 @@
export const relayerApiErrorResponseSchema = {
id: '/RelayerApiErrorResponse',
id: '/relayerApiErrorResponseSchema',
type: 'object',
properties: {
code: { type: 'number' },
code: { type: 'integer', 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: 'integer', minimum: 1000, maximum: 1006 },
reason: { type: 'string' },
},
required: ['field', 'code', 'reason'],

View File

@@ -0,0 +1,13 @@
export const relayerApiFeeRecipientsResponseSchema = {
id: '/relayerApiFeeRecipientsResponseSchema',
type: 'object',
allOf: [
{ $ref: '/paginatedCollectionSchema' },
{
properties: {
records: { $ref: '/addressSchema' },
},
required: ['records'],
},
],
};

View File

@@ -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',
],
};

View File

@@ -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'],
};

View File

@@ -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'],
};

View File

@@ -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',
],
};

View File

@@ -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'],
};

View File

@@ -0,0 +1,9 @@
export const relayerApiOrderSchema = {
id: '/relayerApiOrderSchema',
type: 'object',
properties: {
order: { $ref: '/orderSchema' },
metaData: { type: 'object' },
},
required: ['order', 'metaData'],
};

View File

@@ -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'],
};

View File

@@ -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'],
};

View File

@@ -1,9 +1,9 @@
export const relayerApiOrderBookResponseSchema = {
id: '/RelayerApiOrderBookResponse',
export const relayerApiOrderbookResponseSchema = {
id: '/relayerApiOrderbookResponseSchema',
type: 'object',
properties: {
bids: { $ref: '/signedOrdersSchema' },
asks: { $ref: '/signedOrdersSchema' },
bids: { $ref: '/relayerApiOrdersResponseSchema' },
asks: { $ref: '/relayerApiOrdersResponseSchema' },
},
required: ['bids', 'asks'],
};

View File

@@ -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' },
},
};

View File

@@ -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'],
};

View File

@@ -0,0 +1,13 @@
export const relayerApiOrdersResponseSchema = {
id: '/relayerApiOrdersResponseSchema',
type: 'object',
allOf: [
{ $ref: '/paginatedCollectionSchema' },
{
properties: {
records: { $ref: '/relayerApiOrdersSchema' },
},
required: ['records'],
},
],
};

View File

@@ -0,0 +1,5 @@
export const relayerApiOrdersSchema = {
id: '/relayerApiOrdersSchema',
type: 'array',
items: { $ref: '/relayerApiOrderSchema' },
};

View File

@@ -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'],
};

View File

@@ -1,5 +1,5 @@
export const signedOrdersSchema = {
id: '/signedOrdersSchema',
type: 'array',
items: { $ref: '/SignedOrder' },
items: { $ref: '/signedOrderSchema' },
};

View File

@@ -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',

View File

@@ -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',

View File

@@ -9,23 +9,25 @@ 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 { paginatedCollectionSchema } from '../schemas/paginated_collection_schema';
import {
relayerApiAssetDataPairsResponseSchema,
relayerApiAssetDataPairsSchema,
relayerApiAssetDataTradeInfoSchema,
} from '../schemas/relayer_api_asset_pairs_response_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 { relayerApiFeeRecipientsResponseSchema } from '../schemas/relayer_api_fee_recipients_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 {
relayerApiOrderbookChannelSubscribePayload,
relayerApiOrderbookChannelSubscribeSchema,
} from '../schemas/relayer_api_orberbook_channel_subscribe_schema';
import {
relayerApiOrderbookChannelSnapshotPayload,
relayerApiOrderbookChannelSnapshotSchema,
} from '../schemas/relayer_api_orderbook_channel_snapshot_schema';
import { relayerApiOrderbookChannelUpdateSchema } from '../schemas/relayer_api_orderbook_channel_update_response_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 +53,19 @@ export const schemas = {
tokenSchema,
jsNumber,
txDataSchema,
paginatedCollectionSchema,
relayerApiErrorResponseSchema,
relayerApiFeesPayloadSchema,
relayerApiFeesResponseSchema,
relayerApiOrderBookResponseSchema,
relayerApiTokenPairsResponseSchema,
relayerApiTokenTradeInfoSchema,
relayerApiOrderbookChannelSubscribeSchema,
relayerApiOrderbookChannelSubscribePayload,
relayerApiOrderbookChannelUpdateSchema,
relayerApiOrderbookChannelSnapshotSchema,
relayerApiOrderbookChannelSnapshotPayload,
relayerApiFeeRecipientsResponseSchema,
relayerApiOrderSchema,
relayerApiOrdersSchema,
relayerApiOrderConfigPayloadSchema,
relayerApiOrderConfigResponseSchema,
relayerApiOrderbookResponseSchema,
relayerApiAssetDataPairsResponseSchema,
relayerApiAssetDataTradeInfoSchema,
relayerApiOrdersChannelSubscribeSchema,
relayerApiOrdersChannelSubscribePayload,
relayerApiOrdersChannelUpdateSchema,
relayerApiOrdersResponseSchema,
relayerApiAssetDataPairsSchema,
};

File diff suppressed because it is too large Load Diff

View File

@@ -44468,5 +44468,11 @@
}
}
},
"networks": {}
"networks": {
"50": {
"address": "0x34d402f14d58e001d8efbe6585051bf9706aa064",
"links": {},
"constructorArgs": "[[\"0x5409ed021d9299bf6814279a6a1411a7e866a631\",\"0x6ecbe1db9ef729cbe972c83fb886247691fb6beb\"],[\"0x1dc4c1cefef38a777b15aa20260a54e584b16c48\",\"0x1d7022f5b17d2f8b695918fb48fa1089c9f85401\"],\"2\",\"0\"]"
}
}
}

View File

@@ -252,5 +252,11 @@
}
}
},
"networks": {}
"networks": {
"50": {
"address": "0x1dc4c1cefef38a777b15aa20260a54e584b16c48",
"links": {},
"constructorArgs": "[]"
}
}
}

View File

@@ -252,5 +252,11 @@
}
}
},
"networks": {}
"networks": {
"50": {
"address": "0x1d7022f5b17d2f8b695918fb48fa1089c9f85401",
"links": {},
"constructorArgs": "[]"
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -326,5 +326,11 @@
}
}
},
"networks": {}
"networks": {
"50": {
"address": "0x0b1ba0af832d7c05fd64161e0db78e85978e8082",
"links": {},
"constructorArgs": "[]"
}
}
}

View File

@@ -10028,4 +10028,4 @@
"constructorArgs": "[]"
}
}
}
}

View File

@@ -1,7 +1,7 @@
export const orderWatcherPartialConfigSchema = {
id: '/OrderWatcherPartialConfigSchema',
properties: {
stateLayer: { $ref: '/BlockParam' },
stateLayer: { $ref: '/blockParamSchema' },
orderExpirationCheckingIntervalMs: { type: 'number' },
eventPollingIntervalMs: { type: 'number' },
expirationMarginMs: { type: 'number' },

View File

@@ -0,0 +1,13 @@
{
"domain": "sra-api",
"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
}

View File

@@ -0,0 +1,8 @@
.*
yarn-error.log
/src/
/schemas/
test/
tsconfig.json
/lib/src/monorepo_scripts/
/public/

View File

@@ -0,0 +1,11 @@
[
{
"version": "1.0.1-rc.4",
"changes": [
{
"note": "Add inital spec for SRA v2",
"pr": 916
}
]
}
]

View File

@@ -0,0 +1,99 @@
## @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.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.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
```
**NOTE: On deploying the site, it will say the site is available at a non-existent URL. Please ignore and use the (now updated) URL above.**
### Clean
```bash
yarn clean
```
### Lint
```bash
yarn lint
```
### Run Tests
```bash
yarn test
```

View File

@@ -0,0 +1,6 @@
import { writeFileSync } from 'fs';
import { api } from '../src';
const apiJson = JSON.stringify(api);
writeFileSync('lib/api.json', apiJson);

View File

@@ -0,0 +1,61 @@
{
"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": "swagger-cli validate lib/api.json",
"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",
"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 build_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",
"redoc-cli": "^0.6.1",
"shx": "^0.2.2",
"swagger-cli": "^2.1.1",
"ts-node": "^7.0.0",
"tslint": "5.11.0",
"typescript": "2.7.1"
},
"publishConfig": {
"access": "public"
}
}

301
packages/sra-api/src/api.ts Normal file
View File

@@ -0,0 +1,301 @@
import { OpenApiSpec } from '@loopback/openapi-v3-types';
import { examples } from './examples';
import { schemas } from './json-schemas';
import { md } from './md';
import { generateParameters } from './parameters';
import { generateResponses } from './responses';
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.relayerApiAssetDataPairsResponse,
`Returns a collection of available asset pairs with some meta info`,
),
},
},
'/v2/orders': {
get: {
description:
'Retrieves a list of orders given query parameters. This endpoint should be [paginated](#section/Pagination). For querying an entire orderbook snapshot, the [orderbook endpoint](#operation/getOrderbook) is recommended. If both makerAssetData and takerAssetData are specified, returned orders will be sorted by price determined by (takerTokenAmount/makerTokenAmount) in ascending order. By default, orders returned by this endpoint are unsorted.',
operationId: 'getOrders',
parameters: generateParameters(
[
{
name: 'makerAssetProxyId',
in: 'query',
description: `The maker [asset proxy id](https://0xproject.com/docs/0x.js#types-AssetProxyId) (example: "0xf47261b0" for ERC20, "0x02571792" for ERC721).`,
example: '0xf47261b0',
schema: {
$ref: '#/components/schemas/hexSchema',
},
},
{
name: 'takerAssetProxyId',
in: 'query',
description: `The taker asset [asset proxy id](https://0xproject.com/docs/0x.js#types-AssetProxyId) (example: "0xf47261b0" for ERC20, "0x02571792" for ERC721).`,
example: '0x02571792',
schema: {
$ref: '#/components/schemas/hexSchema',
},
},
{
name: 'makerAssetAddress',
in: 'query',
description: `The contract address for the maker asset.`,
example: '0xe41d2489571d322189246dafa5ebde1f4699f498',
schema: {
$ref: '#/components/schemas/addressSchema',
},
},
{
name: 'takerAssetAddress',
in: 'query',
description: `The contract address for the taker asset.`,
example: '0xe41d2489571d322189246dafa5ebde1f4699f498',
schema: {
$ref: '#/components/schemas/addressSchema',
},
},
{
name: 'exchangeAddress',
in: 'query',
description: `Same as exchangeAddress in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`,
example: '0xe41d2489571d322189246dafa5ebde1f4699f498',
schema: {
$ref: '#/components/schemas/addressSchema',
},
},
{
name: 'senderAddress',
in: 'query',
description: `Same as senderAddress in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`,
example: '0xe41d2489571d322189246dafa5ebde1f4699f498',
schema: {
$ref: '#/components/schemas/addressSchema',
},
},
{
name: 'makerAssetData',
in: 'query',
description: `Same as makerAssetData in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`,
example: '0xe41d2489571d322189246dafa5ebde1f4699f498',
schema: {
$ref: '#/components/schemas/hexSchema',
},
},
{
name: 'takerAssetData',
in: 'query',
description: `Same as takerAssetData in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`,
example: '0xe41d2489571d322189246dafa5ebde1f4699f498',
schema: {
$ref: '#/components/schemas/hexSchema',
},
},
{
name: 'traderAssetData',
in: 'query',
description: `Same as traderAssetData in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`,
example: '0xe41d2489571d322189246dafa5ebde1f4699f498',
schema: {
$ref: '#/components/schemas/hexSchema',
},
},
{
name: 'makerAddress',
in: 'query',
description: `Same as makerAddress in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`,
example: '0xe41d2489571d322189246dafa5ebde1f4699f498',
schema: {
$ref: '#/components/schemas/addressSchema',
},
},
{
name: 'traderAddress',
in: 'query',
description: `Same as traderAddress in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`,
example: '0xe41d2489571d322189246dafa5ebde1f4699f498',
schema: {
$ref: '#/components/schemas/addressSchema',
},
},
{
name: 'feeRecipientAddress',
in: 'query',
description: `Same as feeRecipientAddress in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`,
example: '0xe41d2489571d322189246dafa5ebde1f4699f498',
schema: {
$ref: '#/components/schemas/addressSchema',
},
},
],
true,
),
responses: generateResponses(
'relayerApiOrdersResponseSchema',
examples.relayerApiOrdersResponse,
`A collection of 0x orders with meta-data as specified by query params`,
),
},
},
'/v2/order/{orderHash}': {
get: {
description: 'Retrieves the 0x order with meta info that is associated with the hash.',
operationId: 'getOrder',
parameters: generateParameters(
[
{
name: 'orderHash',
in: 'path',
description: 'The hash of the desired 0x order.',
example: '0xd4b103c42d2512eef3fee775e097f044291615d25f5d71e0ac70dbd49d223591',
schema: {
$ref: '#/components/schemas/orderHashSchema',
},
},
],
false,
),
responses: generateResponses(
'relayerApiOrderSchema',
examples.relayerApiOrder,
`The order and meta info associated with the orderHash`,
),
},
},
'/v2/orderbook': {
get: {
description: `Retrieves the orderbook for a given asset pair. This endpoint should be [paginated](#section/Pagination). Bids will be sorted in descending order by price, and asks will be sorted in ascending order by price. Within the price sorted orders, the orders are further sorted by _taker fee price_ which is defined as the **takerFee** divided by **takerTokenAmount**. After _taker fee price_, orders are to be sorted by expiration in ascending order. The way pagination works for this endpoint is that the **page** and **per_page** query params apply to both \`bids\` and \`asks\` collections, and if \`page\` * \`per_page\` > \`total\` for a certain collection, the \`records\` for that collection should just be empty. `,
operationId: 'getOrderbook',
parameters: generateParameters(
[
{
name: 'baseAssetData',
in: 'query',
description: `assetData (makerAssetData or takerAssetData) designated as the base currency in the [currency pair calculation](https://en.wikipedia.org/wiki/Currency_pair) of price.`,
required: true,
example: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
schema: {
$ref: '#/components/schemas/hexSchema',
},
},
{
name: 'quoteAssetData',
in: 'query',
description: `assetData (makerAssetData or takerAssetData) designated as the quote currency in the currency pair calculation of price (required).`,
required: true,
example: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
schema: {
$ref: '#/components/schemas/hexSchema',
},
},
],
true,
),
responses: generateResponses(
'relayerApiOrderbookResponseSchema',
examples.relayerApiOrderbookResponse,
`The sorted order book for the specified asset pair.`,
),
},
},
'/v2/order_config': {
get: {
description: `Relayers have full discretion over the orders that they are willing to host on their orderbooks (e.g what fees they charge, etc...). In order for traders to discover their requirements programmatically, they can send an incomplete order to this endpoint and receive the missing fields, specifc to that order. This gives relayers a large amount of flexibility to tailor fees to unique traders, trading pairs and volume amounts. Submit a partial order and receive information required to complete the order: \`senderAddress\`, \`feeRecipientAddress\`, \`makerFee\`, \`takerFee\`. `,
operationId: 'getOrderConfig',
parameters: generateParameters([], false),
requestBody: {
description:
'The fields of a 0x order the relayer may want to decide what configuration to send back.',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/relayerApiOrderConfigPayloadSchema',
},
example: examples.relayerApiOrderConfigPayload,
},
},
},
responses: generateResponses(
'relayerApiOrderConfigResponseSchema',
examples.relayerApiOrderConfigResponse,
`The additional fields necessary in order to submit an order to the relayer.`,
),
},
},
'/v2/fee_recipients': {
get: {
description: `Retrieves a collection of all fee recipient addresses for a relayer. This endpoint should be [paginated](#section/Pagination).`,
operationId: 'getFeeRecipients',
parameters: generateParameters([], true),
responses: generateResponses(
'relayerApiFeeRecipientsResponseSchema',
examples.relayerApiFeeRecipientsResponse,
`A collection of all used fee recipient addresses.`,
),
},
},
'/v2/order': {
post: {
description: `Submit a signed order to the relayer.`,
operationId: 'postOrder',
parameters: generateParameters([], false),
requestBody: {
description: 'A valid signed 0x order based on the schema.',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/signedOrderSchema',
},
example: examples.signedOrder,
},
},
},
responses: generateResponses(),
},
},
},
components: {
schemas,
},
};

View File

@@ -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.',
},
};

View File

@@ -0,0 +1,11 @@
export const validationError = {
code: 100,
reason: 'Validation failed',
validationErrors: [
{
field: 'networkId',
code: 1006,
reason: 'Network id 42 is not supported',
},
],
};

View File

@@ -0,0 +1,21 @@
import { validationError } from './errors';
import { relayerApiAssetDataPairsResponse } from './relayerApiAssetDataPairsResponse';
import { relayerApiFeeRecipientsResponse } from './relayerApiFeeRecipientsResponse';
import { relayerApiOrder } from './relayerApiOrder';
import { relayerApiOrderbookResponse } from './relayerApiOrderbookResponse';
import { relayerApiOrderConfigPayload } from './relayerApiOrderConfigPayload';
import { relayerApiOrderConfigResponse } from './relayerApiOrderConfigResponse';
import { relayerApiOrdersResponse } from './relayerApiOrdersResponse';
import { signedOrder } from './signedOrder';
export const examples = {
validationError,
relayerApiAssetDataPairsResponse,
relayerApiFeeRecipientsResponse,
relayerApiOrder,
relayerApiOrderbookResponse,
relayerApiOrderConfigPayload,
relayerApiOrderConfigResponse,
relayerApiOrdersResponse,
signedOrder,
};

View File

@@ -0,0 +1,21 @@
export const relayerApiAssetDataPairsResponse = {
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',
},
},
],
};

View File

@@ -0,0 +1,10 @@
export const relayerApiFeeRecipientsResponse = {
total: 3,
page: 1,
perPage: 10,
records: [
'0x6eC92694ea172ebC430C30fa31De87620967A082',
'0x9e56625509c2f60af937f23b7b532600390e8c8b',
'0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
],
};

View File

@@ -0,0 +1,19 @@
export const relayerApiOrder = {
order: {
makerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b',
takerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
feeRecipientAddress: '0xb046140686d052fff581f63f8136cce132e857da',
senderAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
makerAssetAmount: '10000000000000000',
takerAssetAmount: '20000000000000000',
makerFee: '100000000000000',
takerFee: '200000000000000',
expirationTimeSeconds: '1532560590',
salt: '1532559225',
makerAssetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
takerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990',
exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093',
signature: '0x012761a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
},
metaData: {},
};

View File

@@ -0,0 +1,10 @@
export const relayerApiOrderConfigPayload = {
makerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b',
takerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
makerAssetAmount: '10000000000000000',
takerAssetAmount: '20000000000000000',
makerAssetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
takerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990',
exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093',
expirationTimeSeconds: '1532560590',
};

View File

@@ -0,0 +1,6 @@
export const relayerApiOrderConfigResponse = {
senderAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
feeRecipientAddress: '0xb046140686d052fff581f63f8136cce132e857da',
makerFee: '100000000000000',
takerFee: '200000000000000',
};

View File

@@ -0,0 +1,54 @@
export const relayerApiOrderbookResponse = {
bids: {
total: 325,
page: 2,
perPage: 100,
records: [
{
order: {
makerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b',
takerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
feeRecipientAddress: '0xb046140686d052fff581f63f8136cce132e857da',
senderAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
makerAssetAmount: '10000000000000000',
takerAssetAmount: '20000000000000000',
makerFee: '100000000000000',
takerFee: '200000000000000',
expirationTimeSeconds: '1532560590',
salt: '1532559225',
makerAssetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
takerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990',
exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093',
signature: '0x012761a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
},
metaData: {},
},
],
},
asks: {
total: 500,
page: 2,
perPage: 100,
records: [
{
order: {
makerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
takerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b',
feeRecipientAddress: '0xb046140686d052fff581f63f8136cce132e857da',
senderAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
makerAssetAmount: '20000000000000000',
takerAssetAmount: '10000000000000000',
makerFee: '200000000000000',
takerFee: '100000000000000',
expirationTimeSeconds: '1532560590',
salt: '1532559225',
makerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990',
takerAssetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093',
signature: '0x013842a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b3518891',
},
metaData: {},
},
],
},
};

View File

@@ -0,0 +1,26 @@
export const relayerApiOrdersResponse = {
total: 984,
page: 1,
perPage: 100,
records: [
{
order: {
makerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b',
takerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
feeRecipientAddress: '0xb046140686d052fff581f63f8136cce132e857da',
senderAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
makerAssetAmount: '10000000000000000',
takerAssetAmount: '20000000000000000',
makerFee: '100000000000000',
takerFee: '200000000000000',
expirationTimeSeconds: '1532560590',
salt: '1532559225',
makerAssetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
takerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990',
exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093',
signature: '0x012761a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
},
metaData: {},
},
],
};

View File

@@ -0,0 +1,16 @@
export const signedOrder = {
makerAddress: '0x9e56625509c2f60af937f23b7b532600390e8c8b',
takerAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
feeRecipientAddress: '0xb046140686d052fff581f63f8136cce132e857da',
senderAddress: '0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
makerAssetAmount: '10000000000000000',
takerAssetAmount: '20000000000000000',
makerFee: '100000000000000',
takerFee: '200000000000000',
expirationTimeSeconds: '1532560590',
salt: '1532559225',
makerAssetData: '0xf47261b04c32345ced77393b3530b1eed0f346429d',
takerAssetData: '0x0257179264389b814a946f3e92105513705ca6b990',
exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093',
signature: '0x012761a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
};

View File

@@ -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',
},
},
};

View File

@@ -0,0 +1 @@
export { api } from './api';

View File

@@ -0,0 +1,63 @@
import { schemas as jsonSchemas } from '@0xproject/json-schemas';
// Only include schemas we actually need
const {
numberSchema,
addressSchema,
hexSchema,
orderHashSchema,
orderSchema,
signedOrderSchema,
signedOrdersSchema,
ordersSchema,
paginatedCollectionSchema,
relayerApiErrorResponseSchema,
relayerApiFeeRecipientsResponseSchema,
relayerApiOrderSchema,
relayerApiOrdersSchema,
relayerApiOrderConfigPayloadSchema,
relayerApiOrderConfigResponseSchema,
relayerApiOrderbookResponseSchema,
relayerApiAssetDataPairsResponseSchema,
relayerApiAssetDataTradeInfoSchema,
relayerApiOrdersChannelSubscribeSchema,
relayerApiOrdersChannelSubscribePayload,
relayerApiOrdersChannelUpdateSchema,
relayerApiOrdersResponseSchema,
relayerApiAssetDataPairsSchema,
} = jsonSchemas;
const usedSchemas = {
numberSchema,
addressSchema,
hexSchema,
orderHashSchema,
orderSchema,
signedOrderSchema,
signedOrdersSchema,
ordersSchema,
paginatedCollectionSchema,
relayerApiErrorResponseSchema,
relayerApiFeeRecipientsResponseSchema,
relayerApiOrderSchema,
relayerApiOrdersSchema,
relayerApiOrderConfigPayloadSchema,
relayerApiOrderConfigResponseSchema,
relayerApiOrderbookResponseSchema,
relayerApiAssetDataPairsResponseSchema,
relayerApiAssetDataTradeInfoSchema,
relayerApiOrdersChannelSubscribeSchema,
relayerApiOrdersChannelSubscribePayload,
relayerApiOrdersChannelUpdateSchema,
relayerApiOrdersResponseSchema,
relayerApiAssetDataPairsSchema,
};
// We need to replace the `$ref`s to be OpenAPI compliant.
const openApiSchemas = JSON.parse(
JSON.stringify(usedSchemas).replace(/(\/\w+)/g, match => `#/components/schemas${match}`),
);
// The json schema used by OpenAPI does not accept ids
Object.keys(openApiSchemas).forEach(key => delete openApiSchemas[key].id);
export const schemas = openApiSchemas;

View File

@@ -0,0 +1,5 @@
import { readFileSync } from 'fs';
export const md = {
introduction: readFileSync('src/md/introduction.md').toString(),
};

View File

@@ -0,0 +1,214 @@
# Testing
Use the [sra-report](https://github.com/0xProject/0x-monorepo/tree/development/packages/sra-report) command line tool to test your API for SRA compliance.
# Schemas
The [JSON schemas](http://json-schema.org/) for the API payloads and responses can be found in [@0xproject/json-schemas](https://github.com/0xProject/0x.js/tree/development/packages/json-schemas). Examples of each payload and response can be found in the library's [test suite](https://github.com/0xProject/0x.js/blob/development/packages/json-schemas/test/schema_test.ts#L1).
```
npm install @0xproject/json-schemas --save
```
You can easily validate your API's payloads and responses using the [@0xproject/json-schemas](https://github.com/0xProject/0x.js/tree/development/packages/json-schemas) package:
```
import {SchemaValidator, ValidatorResult, schemas} from '@0xproject/json-schemas';
const {relayerApiTokenPairsResponseSchema} = schemas;
const validator = new SchemaValidator();
const tokenPairsResponse = {
...
};
const validatorResult: ValidatorResult = validator.validate(tokenPairsResponse, relayerApiTokenPairsResponseSchema);
```
# 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/asset_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](#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](#section/Misc.) about formatting `snake_case` vs. `lowerCamelCase`.
These requests include the [`/v2/asset_pairs`](#operation/getAssetPairs), [`/v2/orders`](#operation/getOrders), [`/v2/fee_recipients`](#operation/getFeeRecipients) and [`/v2/orderbook`](#operation/getOrderbook) 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/asset_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](#section/Errors) 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/asset_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/asset_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`.

View File

@@ -0,0 +1,36 @@
import { 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: ParameterObject = {
name: 'network_id',
in: 'query',
description: 'The id of the Ethereum network',
example: 42,
schema: {
type: 'number',
},
};
export const generateParameters = (parameters: ParameterObject[], isPaginated: boolean = false): ParameterObject[] => {
const optionalParameters = isPaginated ? paginationParameters : [];
return [networkdIdParameter, ...optionalParameters, ...parameters];
};

View File

@@ -0,0 +1,24 @@
import { ResponsesObject } from '@loopback/openapi-v3-types';
import { errorResponses } from './errors';
import { headers } from './headers';
export const generateResponses = (schemaName?: string, example?: any, description: string = 'OK'): ResponsesObject => {
const responses = {
'200': {
headers,
description,
content: {},
},
...errorResponses,
};
if (schemaName) {
responses['200'].content = {
'application/json': {
schema: { $ref: `#/components/schemas/${schemaName}` },
example,
},
};
}
return responses;
};

View File

@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib"
},
"include": ["./src/**/*", "./test/*"]
}

View File

@@ -0,0 +1,3 @@
{
"extends": ["@0xproject/tslint-config"]
}

View File

@@ -0,0 +1 @@
declare module 'openapi-schema-validation';

771
yarn.lock

File diff suppressed because it is too large Load Diff