• Stars
    star
    362
  • Rank 117,671 (Top 3 %)
  • Language
    TypeScript
  • License
    Other
  • Created about 5 years ago
  • Updated 9 months ago

Reviews

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

Repository Details

An HTTP Interface to 0x liquidity and tooling

Version Docs Chat with us on Discord Twitter Continuous Integration No Maintenance Intended

⚠️ DEPRECATION NOTICE ⚠️

This repository is no longer maintained by the 0x team. It will remain available for download and use, but we will not be providing any further support. For more information please see our blog post.

If you are looking to access Swap API, please contact the 0x team via the contact form in 0x.org.


alt text

Table of contents

Introduction

The 0x API is a collection of services and endpoints that can be run together or separately. In aggregate, the APIs provide interfaces to 0x liquidity. Everything can be run monolithically via yarn start and docker-compose up as described in Getting Started.

Services

The API contains different services that serve a collection of HTTP or websocket endpoints and keep your order states in sync with the Ethereum state.

HTTP Services

These are services that handle HTTP requests and responses.

Name Path Run Command Requires Ethereum JSON RPC Provider? Requires Relational Database?
All HTTP Services /* yarn start:service:http Yes Yes
Swap /swap yarn start:service:swap_http Yes Yes
Orderbook /orderbook yarn start:service:sra_http No Yes
Meta Transaction Service /meta_transaction yarn start:service:meta_transaction_http Yes Yes

Data Services

The transaction watcher ensures that the data being served is present and up-to-date by keeping the database in sync with Ethereum. The endpoints above run without it, but would be providing degraded or non-functional service.

Name Run Command Requires Ethereum JSON RPC Provider? Requires Relational Database?
Transaction Watcher (monitor and broadcast meta transactions) yarn start:service:transaction_watcher Yes Yes

Getting started

Pre-requirements

Developing

To get a local development version of 0x-api running:

  1. Clone the repo.

  2. Create an .env file and copy the content from the .env_example file. Defaults are defined in config.ts/config.js. The bash environment takes precedence over the .env file. If you run source .env, changes to the .env file will have no effect until you unset the colliding variables.

Environment Variable Default Description
CHAIN_ID Required. No default. The chain id you'd like your API to run on (e.g: 1 -> mainnet, 137 -> Polygon). Defaults to 42 in the API, but required for docker-compose up.
ETHEREUM_RPC_URL Required. No default. The URL used to issue JSON RPC requests. Use http://localhost:8545 to use the local ganache instance.
ZERO_EX_GAS_API_URL Optional. Default: 'https://gas.api.0x.org/source/median' The URL used to fetch gas prices. It should be changed to a matching endpoint based on CHAIN_ID.
POSTGRES_URI Required. Default for dev: postgresql://api:api@localhost/api A URI of a running postgres instance. By default, the API will create all necessary tables. A default instance is spun up in docker-compose up
POSTGRES_READ_REPLICA_URIS Optional. No default A comma separated list of URIs of running postgres read replica instances.
FEE_RECIPIENT_ADDRESS 0x0000000000000000000000000000000000000000 The Ethereum address which should be specified as the fee recipient in orders your API accepts.
TAKER_FEE_ASSET_DATA 0x The taker fee token asset data for created 0x orders.
TAKER_FEE_UNIT_AMOUNT 0 The flat taker fee amount you'd like to receive for filled orders hosted by you.
WHITELIST_ALL_TOKENS false A boolean determining whether all tokens should be allowed to be posted.
SWAP_IGNORED_ADDRESSES [] A comma separated list of addresses to ignore. These addresses are persisted but not used in any /swap/* endpoints
META_TXN_SUBMIT_WHITELISTED_API_KEYS [] A comma separated list of whitelisted 0x API keys that can use the meta-txn /submit endpoint.
META_TXN_RELAY_PRIVATE_KEYS [] A comma separated list of meta-txn relay sender private keys managed by the TransactionWatcherSignerService.
META_TXN_SIGNING_ENABLED true A boolean determining whether the meta-txn signs and submits transactions .
META_TXN_MAX_GAS_PRICE_GWEI 50 The maximum gas price (in gwei) the meta-txn service will submit a transaction at. If the gas price of the network exceeds this value then the meta-txn service will be disabled.
META_TXN_RELAY_EXPECTED_MINED_SEC Default: 120 The expected time for a meta-txn to be included in a block.
ENABLE_PROMETHEUS_METRICS Default: false A boolean determining whether to enable prometheus monitoring.
PROMETHEUS_PORT Default: 8080 The port from which prometheus metrics should be served.
KAFKA_BROKERS Optional. No default. A comma separated list of Kafka broker servers
KAFKA_TOPIC_QUOTE_REPORT Optional. No default The name of the Kafka topic to publish quote reports on. Setting this and KAFKA_BROKERS enable publishing.
  1. Install the dependencies:

    yarn
  2. Build the project:

    yarn build
  3. Run docker-compose up to run the other dependencies required for the API. This uses the local docker-compose.yml file.

  4. Run the database migrations:

yarn db:migrate
  1. Start the API

    yarn start

    For development:

    yarn dev

Adding a new contract

NOTE: This repo is undergoing a tooling change.

To add a new contract, you will need to add it to compiler.json.

You can generate the entire list by running the following:

find . -type f -name "*.sol" | grep -v foundry | grep -v "contracts/lib" | grep -v "node_modules"

Developing on Ganache

To use ganache, use the .env file below:

CHAIN_ID=1337
ETHEREUM_RPC_URL=http://localhost:8545

Then run

$ docker-compose up
$ yarn dev

Developing on Foundry

Install Foundry if needed.

Initialize git submodule:

git submodule update --init --recursive

Compile using forge

cd contracts
forge build

Testing

Run yarn test. It's really that easy :)

Tip: Test suites set up and teardown sandboxed environments, so using .only on it and describe statements will save lots of development time.

Commands

  • yarn build - Build the code
  • yarn test - Test the code
  • yarn lint - Lint the code
  • yarn start - Starts the API
  • yarn dev - Starts the API in dev-mode
  • yarn watch - Watch the source code and rebuild on change
  • yarn prettier - Auto-format the code
  • yarn release - Release a new version of the 0x-api

Deployment

A Docker image is built and hosted by Dockerhub every time a change to the master branch occurs. A Docker image is built, pushed and tagged when a new version is released as well. Running this image will run 0x API as a monolith, with all its dependencies. You can run any of the services separately by overriding the Docker command with the service-specific command when running the container.

When versioning the API, we freeze the old version in a separate branch so that we can deploy patches, and continue to support the old version until it's officially deprecated. Be aware when contributing fixes that you may want to apply the fix to an older version too.

This is a list of endpoints supported by different versions of the API. If an endpoint is not on this list, it is by default pointed to the master branch.

Endpoint(s) API version branch @0x/asset-swapper branch
/swap/v0/, /meta_transaction/v0 https://github.com/0xProject/0x-api/tree/freeze/swap-v0 https://github.com/0xProject/0x-monorepo/tree/v0-asset-swapper
/sra/v3 https://github.com/0xProject/0x-api/tree/freeze/sra-v3 N/A

Release

Releases are triggered automatically by the release GitHub action. They can also be triggered manually by using yarn release, which requires a GITHUB_TOKEN environment variable.

Database

This project uses TypeORM. It makes it easier for anyone to switch out the backing database used by this project. By default, this project uses a PostgreSQL database.

To add a migration, you may use the following command:

yarn db:migration:create -n myMigration

Legal Disclaimer

The laws and regulations applicable to the use and exchange of digital assets and blockchain-native tokens, including through any software developed using the licensed work created by ZeroEx Intl. as described here (the β€œWork”), vary by jurisdiction. As set forth in the Apache License, Version 2.0 applicable to the Work, developers are β€œsolely responsible for determining the appropriateness of using or redistributing the Work,” which includes responsibility for ensuring compliance with any such applicable laws and regulations. See the Apache License, Version 2.0 for the specific language governing all applicable permissions and limitations: http://www.apache.org/licenses/LICENSE-2.0

More Repositories

1

0x-monorepo

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

OpenZKP

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

0x-launch-kit

Start an exchange in under a minute
JavaScript
380
star
4

protocol

TypeScript
362
star
5

0x-mesh

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

0x-starter-project

A project showcasing how to get started with 0x.js
TypeScript
200
star
7

0x-launch-kit-backend

Launch a 0x relayer in under a minute [DEPRECATED]
TypeScript
173
star
8

standard-relayer-api

Standard specifications for 0x relayer public APIs
164
star
9

0x-protocol-specification

Specification for 0x protocol
148
star
10

0x-launch-kit-frontend

TypeScript
112
star
11

tools

TypeScript
96
star
12

ZEIPs

0x Improvement Proposals
91
star
13

swap-demo-tutorial

JavaScript
67
star
14

website

0x.org website
TypeScript
54
star
15

0x-nextjs-demo-app

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

rpc-gateway

A failover proxy for node providers
Go
47
star
17

0x-relayer-registry

A collection of relayers using 0x
TypeScript
43
star
18

whitepaper

Technical document that specifies 0x protocol.
TeX
33
star
19

0x-parser

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

web3-typescript-typings

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

dev-tools-truffle-example

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

fast-abi

ABI encoding, fast
Rust
27
star
23

0x-event-pipeline

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

0x-examples

A collection of 0x API code examples
TypeScript
19
star
25

VDF

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

0x-sdk

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

0x-codesandbox

0x Codesandbox
TypeScript
14
star
28

0x-debug

TypeScript
14
star
29

quote-server

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

0x-settler

0x settlement contracts using Permit2
Solidity
11
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

connect-starter-project

A tutorial for interacting with a relayer that conforms to the standard relayer API
TypeScript
10
star
34

0x-coordinator-server

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

sutro

Eye of Sutro: Ethereum State Watcher
Rust
7
star
36

pm

6
star
37

branding

Logos and other media
5
star
38

p2p_incentives

Python
5
star
39

node-anvil

Nodejs bindings to Foundry Anvil
Rust
5
star
40

zrx-buyer

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

0x-subgraph

TypeScript
4
star
42

mesh-viz

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

matcha-flagged-tokens

4
star
44

0x-exchange-proxy-subgraph

TypeScript
4
star
45

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
46

proxy

Simple Go Proxy
Go
3
star
47

mesh-mock-graphql-api

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

setup-helm

Github Action for Helm installation
TypeScript
3
star
49

mesh-workshop-demo

TypeScript
3
star
50

exchange-v3

TypeScript
2
star
51

0x-mesh-demo-client-javascript

[DEPRECATED] A demo 0x Mesh WebSocket client written in Javascript
TypeScript
2
star
52

ts-doc-gen

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

setup-govulncheck

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

setup-foundry

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

mesh-rs

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

matcha-unsupported-tokens

1
star
57

permit2-matcha

A headless prototype of how the Matcha API works with permit2 smart contracts.
TypeScript
1
star