[Work in progress, PR/Contributions welcome! Testing on Kovan test network]
ZeroEx Open Source Relayer using the Open Orderbook strategy.
Follows ZeroEx Standard Relayer API V0 Draft specification.
- Tested on ubuntu 16.04 LTS
- Install/upgrade to Nodejs: v10.11.0
- Install yarn:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
- Install redis-server:
sudo apt-get install redis-server
- then run command to confirm that everything ok:
sudo service redis-server status
- Install docker-compose:
sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
- Test connection to db port and other:
netstat -p tcp | grep 5432 6379
lsof -nP -iTCP:$PORT | grep LISTEN
lsof -nP -i:$PORT | grep LISTEN
- Install docker:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- Add the Docker repository to APT sources:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- Next, update the package database with the Docker packages from the newly added repo:
sudo apt-get update
apt-cache policy docker-ce
- Finally, install Docker:
sudo apt-get install -y docker-ce
- Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it's running:
sudo systemctl status docker
sudo docker-compose
- Install docker-machine
curl -L https://github.com/docker/machine/releases/download/v0.15.0/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine &&
chmod +x /tmp/docker-machine &&
sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
- verify install:
docker-machine -v
- current status:
yarn start
yarn run v1.9.4
$ node dist/index
2018-09-12T09:03:49.390Z - info: Conduit starting...
2018-09-12T09:03:49.421Z - verbose: Connected to Web3 Provider Engine
2018-09-12T09:03:49.550Z - verbose: ZeroEx client set up
2018-09-12T09:03:49.562Z - verbose: Redis Publisher setup
2018-09-12T09:03:49.568Z - verbose: Redis Subscriber setup
2018-09-12T09:03:49.568Z - debug: Connected to Redis instance
2018-09-12T09:03:49.744Z - debug: Connected to Postgres database
2018-09-12T09:03:49.747Z - debug: Connected to Relay client
2018-09-12T09:03:49.751Z - verbose: OrderWatcher subscribing to ORDER_ADDED message channel
2018-09-12T09:03:49.754Z - debug: Received a redis subscription request for ORDER_ADDED. Subscribing...
2018-09-12T09:03:49.759Z - verbose: OrderWatcher subscribed to ORDER_ADDED message channel
2018-09-12T09:03:49.765Z - verbose: OrderWatcher initialized ZeroEx OrderStateWatcher subscription
2018-09-12T09:03:49.765Z - debug: Connected to OrderWatcher
2018-09-12T09:03:49.802Z - error: Error starting app error: relation "orders" does not exist
yarn dev
$ ts-node src/index
2018-09-25T22:00:47.690Z - info: Conduit starting...
2018-09-25T22:00:47.708Z - verbose: Connected to Web3 Provider Engine
2018-09-25T22:00:47.823Z - verbose: ZeroEx client set up
2018-09-25T22:00:47.834Z - verbose: Redis Publisher setup
2018-09-25T22:00:47.835Z - verbose: Redis Subscriber setup
2018-09-25T22:00:47.835Z - debug: Connected to Redis instance
2018-09-25T22:00:47.915Z - error: Error connecting to Postgres error: password authentication failed for user "johnjohnson"
To start the local dev server:
yarn install
yarn start
-
The server is hosted at
http://localhost:3000
-
To make sure it is working, make a GET request to
http://localhost:3000/api/v0/token_pairs
- change feerecipient (kovan): 0x13cF20B0a6053bA53855e5574AD049323109B0C4
┌─────────────────────────────┐
│amis-erc20.github.io/smartdex│
│ Amis │
│ SmartDex │
│ Client │
│ │
└─────────────────────────────┘
▲ ▲
┌───────┘ └───────┐
│ ▼
┌─────────────┐ ┌─────────────┐
│ │ │ │
│ WebSocket │ │ HTTP API │
│ │ │ │
└─────────────┘ └─────────────┘
▲ ▲
│ emits │
└─events┐ ┌──────┘
│ │
│ ▼
┌──────────────────┐ ┌──────────────┐ ┌──────────────┐
│ Relevant event │ │ │ │◦◦◦◦◦◦◦◦◦◦◦◦◦◦│
│ streams │─────▶│ App Engine │◀─────▶│◦◦◦◦0x.js◦◦◦◦◦│
│ (includes 0x.js) │ │ │ │◦◦◦◦◦◦◦◦◦◦◦◦◦◦│
└──────────────────┘ └──────────────┘ └──────────────┘
▲
│
▼
┌──────────────┐
│ │
│ Orderbook │
│ │
└──────────────┘
▲
│
▼
┌──────────────┐
│ │
│ Data store │
│ │
└──────────────┘
I'll be adding support for Matching as soon as this proposal is implemented. I personally think the matching strategy will lead to a better UX (atomic, no race conditions, faster relay feedback), but currently requires large upfront capital. Matching engine will use sorted sets on top of red-black trees and will be configured as a separate strategy.
1/ Search the orderbook for a specific WETH pair:
- A GET https://conduit-relay.herokuapp.com/api/v0/orderbook?baseTokenAddress=0xd0a1e359811322d97991e03f863a0c30c2cf029c&page=1&per_page=100"eTokenAddress=0x6ff6c0ff1d68b964901f986d4c9fa3ac68346570 request returns:
bids
0
exchangeContractAddress "0x90fe2af704b34e0224bf2299c838e04d4dcf1364"
maker "0xceebbcf600e3643be7fbd639b64ad609ff2abf71"
taker "0x0000000000000000000000000000000000000000"
makerTokenAddress "0xd0a1e359811322d97991e03f863a0c30c2cf029c"
takerTokenAddress "0x6ff6c0ff1d68b964901f986d4c9fa3ac68346570"
feeRecipient "0x0000000000000000000000000000000000000000"
makerTokenAmount "2900000000000000"
takerTokenAmount "1000000000000000000"
makerFee "0"
takerFee "0"
expirationUnixTimestampSec "1537912800"
salt "19963472023720220868290022542873803929730847471346145544791072525302447061067"
ecSignature
v 28
r "0xc1a04e5c3a15a8db8dd2514b6b2d54325d53c212079a20aece3dcaa71817b16b"
s "0x513f08faa7ad101875ac2825b532b106bfa883b2c8314c17d86fcce70d25415e"
1 {…}
2 {…}
3 {…}
4 {…}
5 {…}
6 {…}
asks
0
exchangeContractAddress "0x90fe2af704b34e0224bf2299c838e04d4dcf1364"
maker "0xceebbcf600e3643be7fbd639b64ad609ff2abf71"
taker "0x0000000000000000000000000000000000000000"
makerTokenAddress "0x6ff6c0ff1d68b964901f986d4c9fa3ac68346570"
takerTokenAddress "0xd0a1e359811322d97991e03f863a0c30c2cf029c"
feeRecipient "0x0000000000000000000000000000000000000000"
makerTokenAmount "1000000000000000"
takerTokenAmount "100000000000000"
makerFee "0"
takerFee "0"
expirationUnixTimestampSec "1538172000"
salt "1882906118882121786560959423584494093735683627214136122858370408972300359305"
ecSignature
v 28
r "0x0f729c231a156f0f7a9852bc74cf2e476eb994401ddb9df8818a125eabd45e9b"
s "0x0ece49da2b2bb2e9dc36560141132b991cd8bd51cde3728dd91ba929a7ebf6a8"
2/ GET request to retrieve the orders list:
- https://conduit-relay.herokuapp.com/api/v0/orders returns all the orders from all tokens listed
3/ GET request to retrieve the token_pairs
- docker ps -a
- docker-compose stop # stop your containers, but it won’t remove them
- docker-compose down # stop your containers, but it also removes the stopped containers as well as any networks that were created
- docker image ls
- docker container ls -a
- docker container stop b74fcbfc7313
- docker container rm b74fcbfc7313
- docker logs pg
- docker run --name pg -p 5432:5432 -e POSTGRES_PASSWORD=passwrd -e POSTGRES_USER=root -e POSTGRES_DB=zeroex -d postgres
- docker inspect pg
- docker exec -ti pg /bin/bash
- psql -U postgres -d zeroex -h 172.17.0.2 -W