Giter Site home page Giter Site logo

0xygen-relay's People

Contributors

krishishah avatar

Stargazers

 avatar  avatar

Watchers

 avatar

0xygen-relay's Issues

Extend relayer API with endpoints not included within 0x Protocol

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).

Perform fund validation

Fund Validation

The fund validation receives orders from a message queue, and communicates with an Ethereum node to validate that:

  • The maker of the order has adequate funds to complete the order (both the maker token and the fee token).
  • The maker of the order has set allowances for the token transfer proxy to complete the order.

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

Error response will be sent with a non-2xx HTTP status code

See error response schema

{
    "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

Implement GET /v0/orders - 0x Relayer 0x Relayer API Endpoint

GET /v0/orders

Retrieves a list of orders given query parameters. This endpoint should be paginated. For querying an entire orderbook snapshot, the orderbook endpoint is recommended.

Parameters

  • exchangeContractAddress [string]: returns orders created for this exchange address
  • tokenAddress [string]: returns orders where makerTokenAddress or takerTokenAddress is token address
  • makerTokenAddress [string]: returns orders with specified makerTokenAddress
  • takerTokenAddress [string]: returns orders with specified makerTokenAddress
  • maker [string]: returns orders where maker is maker address
  • taker [string]: returns orders where taker is taker address
  • trader [string]: returns orders where maker or taker is trader address
  • feeRecipient [string]: returns orders where feeRecipient is feeRecipient address

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.

Response

See response schema

[
    {
        "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"
        }
    },
    ...
]

Implement GET /v0/orderbook - 0x Relayer API Endpoint

GET /v0/orderbook

Retrieves the orderbook for a given token pair.

Parameters

  • baseTokenAddress [string]: address of token designated as the baseToken in the currency pair calculation of price (required)
  • quoteTokenAddress [string]: address of token designated as the quoteToken in the currency pair calculation of price (required)

Response

See response schema

{
    "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.

Implement 0x Web Socket API

Websocket API

Orderbook Channel

Request messages

Subscribe

See payload schema

{
    "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 made
  • baseTokenAddress - 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 orderbook
  • limit - maximum number of bids and asks in orderbook snapshot

Response messages

Snapshot

See payload schema

{
    "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 message
  • 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.

Update

See payload schema

{
    "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 message

Implement POST /v0/fees - 0x Relayer API Endpoint

POST /v0/fees

Given an unsigned order without the fee-related properties, returns the required feeRecipient, makerFee, and takerFee of that order.

Payload

See payload schema

{
    "exchangeContractAddress": "0x12459c951127e0c374ff9105dda097662a027093",
    "maker": "0x9e56625509c2f60af937f23b7b532600390e8c8b",
    "taker": "0x0000000000000000000000000000000000000000",
    "makerTokenAddress": "0x323b5d4c32345ced77393b3530b1eed0f346429d",
    "takerTokenAddress": "0xef7fff64389b814a946f3e92105513705ca6b990",
    "makerTokenAmount": "10000000000000000",
    "takerTokenAmount": "20000000000000000",
    "expirationUnixTimestampSec": "42",
    "salt": "67006738228878699843088602623665307406148487219438534730168799356281242528500"
}

Response

See response schema

{
    "feeRecipient": "0xb046140686d052fff581f63f8136cce132e857da",
    "makerFee": "100000000000000",
    "takerFee": "200000000000000"
}

Set up TestRPC

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:

  1. Infura - Remote TestRPC (https://blog.infura.io/getting-started-with-infura-28e41844cc89)
  2. Truffle - Local TestRPC (http://truffleframework.com/tutorials/ethereum-devops-truffle-testrpc-vsts)

Set up 0x & Web3Provider config

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

Implement GET /v0/token_pairs - 0x Relayer API Endpoint

GET /v0/token_pairs

Retrieves a list of available token pairs and the information required to trade them. This endpoint should be paginated.

Parameters

  • tokenA=&tokenB [string]: these are token addresses. returns token pairs that contain tokenA and tokenB (in any order). Setting only tokenA or tokenB returns pairs filtered by that token only (optional)

Response

See response schema

[
    {
        "tokenA": {
            "address": "0x323b5d4c32345ced77393b3530b1eed0f346429d",
            "minAmount": "0",
            "maxAmount": "10000000000000000000",
            "precision": 5
        },
        "tokenB": {
            "address": "0xef7fff64389b814a946f3e92105513705ca6b990",
            "minAmount": "0",
            "maxAmount": "50000000000000000000",
            "precision": 5
        }
    },
    ...
]
  • address - address of the token
  • minAmount - the minimum trade amount the relayer will accept
  • maxAmount - the maximum trade amount the relayer will accept
  • precision - the desired price precision a relayer would like to support within their orderbook

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.