GithubHelp home page GithubHelp logo

isabella232 / standard-relayer-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 0xproject/standard-relayer-api

0.0 0.0 0.0 181 KB

Standard specifications for 0x relayer public APIs

License: Apache License 2.0

standard-relayer-api's Introduction

Standard Relayer API

0x Protocol is an open standard. Because of this, we expect many independent applications to be built that will want to use the protocol. In order to make it easier for anyone to source liquidity that conforms to the 0x order format, relayers can opt-in to implementing a set of standard relayer API endpoints. In doing so, they allow clients of the standard relayer API to access the orders on their orderbook.

Specification Versions

SRA v3

Made to match 0x Protocol v3. See changes from v2.

SRA v2

Made to match 0x Protocol v2

SRA v1

Skipped for naming convention and convenience reasons.

SRA v0

Made to match 0x Protocol v1

General Info

Versioning

The URL that specifies the SRA API endpoint should end in the version. Here are some examples:

HTTP: https://api.relayer.com/sra/v0/, https://api.relayer.com/sra/v2/

Websocket: wss://api.relayer.com/sra/v0/, wss://api.relayer.com/sra/v2/

Schemas

The JSON schemas for the API payloads and responses can be found in @0xproject/json-schemas. Examples of each payload and response can be found in the library's test suite.

npm install @0xproject/json-schemas --save

You can easily validate your API's payloads and responses using the @0xproject/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);

Asset Data Encoding

As we now support multiple token transfer proxies, 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 and decoding.

The identifier for the Proxy uses a similar scheme to ABI function selectors.

// ERC20 Proxy ID  0xf47261b0
bytes4(keccak256("ERC20Token(address)"))
// ERC721 Proxy ID 0x02571792
bytes4(keccak256("ERC721Token(address,uint256)"))

Asset data is encoded using ABI encoding.

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: 0x02571792) would be:

0x02571792000000000000000000000000371b13d97f4bf77d724e78c16b7dc74099f40e840000000000000000000000000000000000000000000000000000000000000063

For more information see the Asset Proxy section of the v2 spec and the Ethereum ABI Spec.

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.

standard-relayer-api's People

Contributors

abandeali1 avatar albrow avatar amaurer avatar bmillman19 avatar dekz avatar fabioberger avatar fragosti avatar liamzebedee avatar logvinovleon avatar

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.