• Stars
    star
    164
  • Rank 221,933 (Top 5 %)
  • Language
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Standard specifications for 0x relayer public APIs

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.

More Repositories

1

0x-monorepo

0x protocol monorepo - includes our smart contracts and many developer tools
TypeScript
1,407
star
2

OpenZKP

OpenZKP - pure Rust implementations of Zero-Knowledge Proof systems.
Rust
616
star
3

0x-launch-kit

Start an exchange in under a minute
JavaScript
375
star
4

0x-api

An HTTP Interface to 0x liquidity and tooling
TypeScript
356
star
5

protocol

TypeScript
343
star
6

0x-mesh

A peer-to-peer network for sharing 0x orders
Go
258
star
7

0x-starter-project

A project showcasing how to get started with 0x.js
TypeScript
202
star
8

0x-launch-kit-backend

Launch a 0x relayer in under a minute [DEPRECATED]
TypeScript
172
star
9

0x-protocol-specification

Specification for 0x protocol
147
star
10

0x-launch-kit-frontend

TypeScript
113
star
11

ZEIPs

0x Improvement Proposals
91
star
12

tools

TypeScript
90
star
13

website

0x.org website
TypeScript
53
star
14

swap-demo-tutorial

JavaScript
48
star
15

rpc-gateway

A failover proxy for node providers
Go
46
star
16

0x-relayer-registry

A collection of relayers using 0x
TypeScript
43
star
17

whitepaper

Technical document that specifies 0x protocol.
TeX
34
star
18

0x-nextjs-demo-app

Example ERC20 swapping app made with 0x Swap API, Next.js, and ConnectKit
TypeScript
31
star
19

web3-typescript-typings

[DEPRECATED] A preliminary Web3 v0.x typescript type definition
30
star
20

dev-tools-truffle-example

An example Truffle project showing how to use the 0x Dev Tools with the Truffle framework
JavaScript
28
star
21

fast-abi

ABI encoding, fast
Rust
26
star
22

0x-event-pipeline

A node.js app for pulling 0x event info to inform things like staking.
TypeScript
24
star
23

0x-parser

🧾 A library that parses 0x transactions from EVM blockchains into a format that is user-friendly and easy to understand.
TypeScript
23
star
24

VDF

A Solidity implementation of a VDF verifier contract
Solidity
16
star
25

0x-sdk

TypeScript SDK for building exchange functionality on Ethereum and EVM-compatible chains πŸ› .
TypeScript
15
star
26

0x-codesandbox

0x Codesandbox
TypeScript
14
star
27

0x-debug

TypeScript
14
star
28

quote-server

An RFQ quote server that can be used to provide quotes via 0x API
TypeScript
14
star
29

connect-starter-project

A tutorial for interacting with a relayer that conforms to the standard relayer API
TypeScript
11
star
30

0x-coordinator-server

A reference implementation of a 0x coordinator server (soft-cancel variant)
TypeScript
10
star
31

0x-instant

JavaScript
10
star
32

0x-staking-pool-registry

A collection of metadata about staking pools on 0x - https://0x.org/
TypeScript
10
star
33

sutro

Eye of Sutro: Ethereum State Watcher
Rust
7
star
34

pm

6
star
35

branding

Logos and other media
5
star
36

p2p_incentives

Python
5
star
37

0x-examples

A collection of 0x API code examples
TypeScript
5
star
38

node-anvil

Nodejs bindings to Foundry Anvil
Rust
5
star
39

mesh-viz

https://mesh-viz.0x.org/
TypeScript
4
star
40

zrx-buyer

A demonstration of using asset-buyer to buy ZRX
TypeScript
4
star
41

0x-subgraph

TypeScript
4
star
42

matcha-flagged-tokens

4
star
43

0x-exchange-proxy-subgraph

TypeScript
4
star
44

0x-api-forked-testnet-example

A basic example for how you can test 0x API using a private for of Ethereum mainnet
TypeScript
4
star
45

proxy

Simple Go Proxy
Go
3
star
46

mesh-workshop-demo

TypeScript
3
star
47

mesh-mock-graphql-api

Demo of the new Mesh GraphQL API using mock data
TypeScript
3
star
48

0x-mesh-demo-client-javascript

[DEPRECATED] A demo 0x Mesh WebSocket client written in Javascript
TypeScript
3
star
49

setup-helm

Github Action for Helm installation
TypeScript
3
star
50

exchange-v3

TypeScript
2
star
51

setup-foundry

Install foundry-rs/foundry in your Github Action workflow
TypeScript
2
star
52

setup-govulncheck

Setup govulncheck: https://go.dev/security/vuln/
TypeScript
2
star
53

ts-doc-gen

A CLI for generating a single MD reference doc file for a TS project
TypeScript
2
star
54

mesh-rs

Rust implementation of the 0x Mesh protocol
Rust
1
star
55

matcha-unsupported-tokens

1
star