krishishah / 0xygen-relay Goto Github PK
View Code? Open in Web Editor NEW0xygen Monorepo- Decentralised Ethereum Token Relay
0xygen Monorepo- Decentralised Ethereum Token Relay
Add POST endpoint to enable clients to let relayers know that a user is attempting to fill/cancel a series of orders. This will aid the relayer's order pruning functionality
Add GET endpoint to provide clients with a history of valid orders (those which have not been entirely filled/ canceled or expired) as well as invalid orders (filled/ canceled/expired orders).
The fund validation receives orders from a message queue, and communicates with an Ethereum node to validate that:
It should also take into consideration whether the order has been partially filled or canceled, based on the values set in the Fill Updater service.
If validation fails, response should be in the following format:
Error response will be sent with a non-2xx HTTP status code
{
"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 ECDSA or Hash
1006 - Unsupported option
Retrieves a list of orders given query parameters. This endpoint should be paginated. For querying an entire orderbook snapshot, the orderbook endpoint is recommended.
All parameters are optional.
If both makerTokenAddress and takerTokenAddress 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.
[
{
"exchangeContractAddress": "0x12459c951127e0c374ff9105dda097662a027093",
"maker": "0x9e56625509c2f60af937f23b7b532600390e8c8b",
"taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32",
"makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d",
"takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990",
"feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da",
"makerTokenAmount": "10000000000000000",
"takerTokenAmount": "20000000000000000",
"makerFee": "100000000000000",
"takerFee": "200000000000000",
"expirationUnixTimestampSec": "42",
"salt": "67006738228878699843088602623665307406148487219438534730168799356281242528500",
"ecSignature": {
"v": 27,
"r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33",
"s": "0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254"
}
},
...
]
Retrieves the orderbook for a given token pair.
{
"bids": [
{
"exchangeContractAddress": "0x12459c951127e0c374ff9105dda097662a027093",
"maker": "0x9e56625509c2f60af937f23b7b532600390e8c8b",
"taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32",
"makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d",
"takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990",
"feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da",
"makerTokenAmount": "10000000000000000",
"takerTokenAmount": "20000000000000000",
"makerFee": "100000000000000",
"takerFee": "200000000000000",
"expirationUnixTimestampSec": "42",
"salt": "67006738228878699843088602623665307406148487219438534730168799356281242528500",
"ecSignature": {
"v": 27,
"r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33",
"s": "0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254"
}
},
...
],
"asks": [
{
"exchangeContractAddress": "0x12459c951127e0c374ff9105dda097662a027093",
"maker": "0x9e56625509c2f60af937f23b7b532600390e8c8b",
"taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32",
"makerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990",
"takerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d",
"feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da",
"makerTokenAmount": "22000000000000000",
"takerTokenAmount": "10000000000000000",
"makerFee": "100000000000000",
"takerFee": "200000000000000",
"expirationUnixTimestampSec": "632",
"salt": "54515451557974875123697849345751275676157243756715784155226239582178",
"ecSignature": {
"v": 27,
"r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33",
"s": "0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254"
}
},
...
]
}
bids
- array of signed orders where takerTokenAddress
is equal to baseTokenAddress
asks
- array of signed orders where makerTokenAddress
is equal to baseTokenAddress
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 first by total fees, then by expiration in ascending order.
{
"type": "subscribe",
"channel": "orderbook",
"requestId": 1,
"payload": {
"baseTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d",
"quoteTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990",
"snapshot": true,
"limit": 100
}
}
requestId
- an integer that will be sent back by the server in response messages so the client can appropriately respond when multiple subscriptions are madebaseTokenAddress
- address of token designated as the baseToken in the currency pair calculation of price (required)quoteTokenAddress
- address of token designated as the quoteToken in the currency pair calculation of price (required)snapshot
- if true
, a snapshot of the orderbook will be sent before any updates to the orderbooklimit
- maximum number of bids and asks in orderbook snapshot{
"type": "snapshot",
"channel": "orderbook",
"requestId": 1,
"payload": {
"bids": [
{
"exchangeContractAddress": "0x12459c951127e0c374ff9105dda097662a027093",
"maker": "0x9e56625509c2f60af937f23b7b532600390e8c8b",
"taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32",
"makerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990",
"takerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d",
"feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da",
"makerTokenAmount": "22000000000000000",
"takerTokenAmount": "10000000000000000",
"makerFee": "100000000000000",
"takerFee": "200000000000000",
"expirationUnixTimestampSec": "632",
"salt": "54515451557974875123697849345751275676157243756715784155226239582178",
"ecSignature": {
"v": 27,
"r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33",
"s": "0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254"
}
},
...
],
"asks": [
{
"exchangeContractAddress": "0x12459c951127e0c374ff9105dda097662a027093",
"maker": "0x9e56625509c2f60af937f23b7b532600390e8c8b",
"taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32",
"makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d",
"takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990",
"feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da",
"makerTokenAmount": "10000000000000000",
"takerTokenAmount": "20000000000000000",
"makerFee": "100000000000000",
"takerFee": "200000000000000",
"expirationUnixTimestampSec": "42",
"salt": "67006738228878699843088602623665307406148487219438534730168799356281242528500",
"ecSignature": {
"v": 27,
"r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33",
"s": "0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254"
}
},
...
]
}
}
requestId
- an integer that corresponds to the requestId sent by the client in the subscribe
messagebids
- array of signed orders where takerTokenAddress
is equal to baseTokenAddress
asks
- array of signed orders where makerTokenAddress
is equal to baseTokenAddress
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 first by total fees, then by expiration in ascending order.
{
"type": "update",
"channel": "orderbook",
"requestId": 1,
"payload": {
"exchangeContractAddress": "0x12459c951127e0c374ff9105dda097662a027093",
"maker": "0x9e56625509c2f60af937f23b7b532600390e8c8b",
"taker": "0xa2b31dacf30a9c50ca473337c01d8a201ae33e32",
"makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d",
"takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990",
"feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da",
"makerTokenAmount": "10000000000000000",
"takerTokenAmount": "20000000000000000",
"makerFee": "100000000000000",
"takerFee": "200000000000000",
"expirationUnixTimestampSec": "42",
"salt": "67006738228878699843088602623665307406148487219438534730168799356281242528500",
"ecSignature": {
"v": 27,
"r": "0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33",
"s": "0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254"
}
}
}
requestId
- an integer that corresponds to the requestId sent by the client in the subscribe
messageThis will help isolate testing and development environments from production and maintain privacy. Examples include 0x.js config, database config, webserver config
Given an unsigned order without the fee-related properties, returns the required feeRecipient
, makerFee
, and takerFee
of that order.
{
"exchangeContractAddress": "0x12459c951127e0c374ff9105dda097662a027093",
"maker": "0x9e56625509c2f60af937f23b7b532600390e8c8b",
"taker": "0x0000000000000000000000000000000000000000",
"makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d",
"takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990",
"makerTokenAmount": "10000000000000000",
"takerTokenAmount": "20000000000000000",
"expirationUnixTimestampSec": "42",
"salt": "67006738228878699843088602623665307406148487219438534730168799356281242528500"
}
{
"feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da",
"makerFee": "100000000000000",
"takerFee": "200000000000000"
}
In order to run 0x.js methods that interact with the Ethereum blockchain (i.e filling an order, checking a balance or setting an allowance) a Web3 Provider needs to interact with an Ethereum node.
This involves setting up a TestRPC either locally or remotely. TestRPC is a Node.js based Ethereum client for testing and development. It uses ethereumjs to simulate full client behavior (not a real chain) and make developing Ethereum applications much faster. It also includes all pTopular RPC functions and features (like events) and can be run deterministically to make development a breeze.
Two possible solutions:
The ZeroEx class is the single entry-point into the 0x.js library. It contains all of the library's functionality and all calls to the library should be made through a ZeroEx instance. The constructor of the ZeroEx class takes in the following parameters:
new ZeroEx(provider: Web3Provider, config: ZeroExConfig): ZeroEx
Web3Providers are required in order to interface the dApp with an Ethereum Node. More details can be found at: https://0xproject.com/wiki#Web3-Provider-Explained
This involves implementing the following interface:
Interface ZeroExConfig
{
exchangeContractAddress: undefined|string,
gasPrice: BigNumber,
networkId: number,
orderWatcherConfig: OrderStateWatcherConfig,
tokenRegistryContractAddress: undefined|string,
tokenTransferProxyContractAddress: undefined|string,
zrxContractAddress: undefined|string,
}
More info can be found about 0x specific config here: https://0xproject.com/docs/0xjs#types-ZeroExConfig
Retrieves a list of available token pairs and the information required to trade them. This endpoint should be paginated.
[
{
"tokenA": {
"address": "0x323b5d4c32345ced77393b3530b1eed0f346429d",
"minAmount": "0",
"maxAmount": "10000000000000000000",
"precision": 5
},
"tokenB": {
"address": "0xef7fff64389b814a946f3e92105513705ca6b990",
"minAmount": "0",
"maxAmount": "50000000000000000000",
"precision": 5
}
},
...
]
address
- address of the tokenminAmount
- the minimum trade amount the relayer will acceptmaxAmount
- the maximum trade amount the relayer will acceptprecision
- the desired price precision a relayer would like to support within their orderbookA declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.