Skip to content

Commit

Permalink
Merge branch 'main' into ECO-484
Browse files Browse the repository at this point in the history
  • Loading branch information
CRBl69 committed Oct 7, 2023
2 parents e753d39 + 3310d3e commit 188537c
Show file tree
Hide file tree
Showing 20 changed files with 262 additions and 238 deletions.
2 changes: 1 addition & 1 deletion doc/doc-site/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ Econia's docs are built using [Docusaurus].

1. Make your changes to the database migrations.
2. Run the local end-to-end docker compose according to instructions in `/src/docker/README.md`
3. Visit `localhost:3001` and copy the JSON it returns.
3. Visit `localhost:3000` and copy the JSON it returns.
4. Paste the JSON into `/doc/doc-site/openapi.json`
5. Done!
14 changes: 8 additions & 6 deletions doc/doc-site/docs/off-chain/dss/data-service-stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ This page will show you how to run the DSS locally.
The DSS exposes a REST API and a WebSocket server.

The WebSocket server mainly provides notifications of any events emitted by the Econia Move package.
It can be addressed at `ws://0.0.0.0:3001` in the default local configuration of docker compose.

The REST API also provides all the events emitted by the Econia Move package., as well as aggregated data like order history and order book state.
It can be addressed at `http://0.0.0.0:3000` in the default local configuration of docker compose.

In order to access the WebSocket server, connect to the following URL: `ws://your-host/[JWT]` where `[JWT]` is a JSON Web Token (JWT).
To get a JWT, query the REST API at `http://your-host/rpc/jwt` with the HTTP method `POST` and `{"channels": […]}` as a payload, where `[…]` is a list of the names of the channels you want to receive notifications for.
Expand Down Expand Up @@ -109,15 +111,15 @@ When switching chains, don't forget to prune the Docker database volume (`docker

### Verifying the DSS

Verify that the database is accessible by navigating your browser to `http://0.0.0.0:3001`.
Verify that the database is accessible by navigating your browser to `http://0.0.0.0:3000`.

Once the processor has parsed all transactions up until the chain tip, then check that individual tables are visible/contain data by navigating to:

- `http://0.0.0.0:3001/market_registration_events`
- `http://0.0.0.0:3001/cancel_order_events`
- `http://0.0.0.0:3001/fill_events`
- `http://0.0.0.0:3001/place_limit_order_events`
- `http://0.0.0.0:3001/balance_updates`
- `http://0.0.0.0:3000/market_registration_events`
- `http://0.0.0.0:3000/cancel_order_events`
- `http://0.0.0.0:3000/fill_events`
- `http://0.0.0.0:3000/place_limit_order_events`
- `http://0.0.0.0:3000/balance_updates`

:::tip

Expand Down
39 changes: 38 additions & 1 deletion doc/doc-site/docs/off-chain/dss/websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Channels include:
- `cancel_order_event`

For each channel, the payload format is identical to the corresponding event format returned by the [DSS REST API](./rest-api.md).
For example, the payload of an event from the `fill_event` channel is identical to the event format returned by a REST API query for `localhost:3001/fill_events` (note that channel names have no `s` at the end but REST API endpoints do), except that WebSocket events are received one by one instead of in an array.
For example, the payload of an event from the `fill_event` channel is identical to the event format returned by a REST API query for `localhost:3000/fill_events` (note that channel names have no `s` at the end but REST API endpoints do), except that WebSocket events are received one by one instead of in an array.

Hence the format of an event payload from the `fill_event` channel:

Expand Down Expand Up @@ -82,3 +82,40 @@ In contrast, the response of a REST API query for the `/fill_events` endpoint (a
```

Note the `[` and the `]`, constituting an array.

## Example

The Econia repository contains a Docker compose environment for running a DSS against a local testnet.
This compose environment is designed for end-to-end testing, and can be used for monitoring WebSockets notifications via the [`event.py`](https://github.com/econia-labs/econia/blob/main/src/python/sdk/examples/event.py) example script.
In order to run the example script, you'll need to install [Poetry](https://python-poetry.org/docs/).

If you'd like to run the example script against the end-to-end Docker compose environment, first initialize the environment according to the steps [here](https://github.com/econia-labs/econia/blob/main/src/docker/README.md).
Then once the compose environment is running, open up a new terminal and run the following:

```sh
# From Econia repo root
cd src/python/sdk
poetry install
poetry run event
```

Enter nothing for all of the prompts to use the default local configuration.

Now you can perform actions on the locally-deployed exchange to trigger events, or run the `trade.py` script:

```sh
# From Econia repo root, new terminal
cd src/python/sdk
poetry run trade
```

The script will have a few prompts, respond to each of them as follows:

| Prompt | Value |
| -------------- | -------------------------------------------------------------------- |
| Econia address | `0xeeee0dd966cd4fc739f76006591239b32527edbb7c303c431f8c691bda150b40` |
| Faucet address | `0xffff094ef8ccfa9137adcb13a2fae2587e83c348b32c63f811cc19fcc9fc5878` |
| Node URL | http://0.0.0.0:8080/v1 |
| Faucet URL | http://0.0.0.0:8081 |

As you run through the assorted sections in the trading script, you should see fill events coming in over the WebSockets channel.
23 changes: 6 additions & 17 deletions src/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ While the local testnet is running, you can look up on-chain Move resources usin
Note that the Aptos faucet API may take longer to start up than the node REST API:

```sh
# From Econia repo root
ECONIA_ADDRESS=0xeeee0dd966cd4fc739f76006591239b32527edbb7c303c431f8c691bda150b40
FAUCET_ADDRESS=0xffff094ef8ccfa9137adcb13a2fae2587e83c348b32c63f811cc19fcc9fc5878
aptos account list --account $FAUCET_ADDRESS --url http://0.0.0.0:8080
Expand All @@ -54,17 +53,7 @@ Both of the last two commands should spit out a bunch of resources deployed to t

There is a script available that performs most (but not all) of the eventful and/or interesting operations on the exchange.
By running it against the local end-to-end deployment, it's possible to verify things like processor operation, database connectivity and data accessibility.
You'll need to install [Poetry](https://python-poetry.org/docs/):

```sh
brew install poetry
```

Alternatively, if your platform doesn't support `brew`:

```sh
curl -sSL https://install.python-poetry.org | python3 -
```
To run the script you'll need to install [Poetry](https://python-poetry.org/docs/).

Next run the following:

Expand All @@ -86,12 +75,12 @@ The script will have a few prompts, respond to each of them as follows:

Next, the script will step through various operations such as order creation, cancellation and fulfillment; press `ENTER` to advance each step.
The script should execute to completion (it says `THE END!`) if everything is working.
Verify that the database is accessible by navigating to `http://0.0.0.0:3001`, and that necessary tables are visible/contain data by navigating to:
Verify that the database is accessible by navigating to `http://0.0.0.0:3000`, and that necessary tables are visible/contain data by navigating to:

- `http://0.0.0.0:3001/market_registration_events`
- `http://0.0.0.0:3001/cancel_order_events`
- `http://0.0.0.0:3001/fill_events`
- `http://0.0.0.0:3001/place_limit_order_events`
- `http://0.0.0.0:3000/market_registration_events`
- `http://0.0.0.0:3000/cancel_order_events`
- `http://0.0.0.0:3000/fill_events`
- `http://0.0.0.0:3000/place_limit_order_events`

If each of these tables is visible and containing data then that means the processor, database and PostgREST are all working together!

Expand Down
47 changes: 41 additions & 6 deletions src/docker/api/Dockerfile.ws
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
FROM debian:stable-slim
FROM haskell:9.4.7-slim as builder

ARG POSTGRES_WEBSOCKETS_VERSION
# Postgres-websockets repo metadata
ARG GIT_REPO=https://github.com/diogob/postgres-websockets.git
ARG GIT_TAG=0.11.2.1

# Install System Dependencies
RUN apt-get update \
&& apt-get install -y libpq-dev wget \
&& apt-get install -y \
libpq-dev \
wget \
git \
build-essential \
libffi-dev \
libgmp-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

RUN wget https://github.com/diogob/postgres-websockets/releases/download/$POSTGRES_WEBSOCKETS_VERSION/postgres-websockets
# Clone the Repository
WORKDIR /app
RUN git clone \
$GIT_REPO \
--branch $GIT_TAG \
--depth 1

RUN chmod u+x ./postgres-websockets
# Build the Project from source using the resolver it specifies
# https://github.com/diogob/postgres-websockets/tree/master#building-from-source
# https://github.com/diogob/postgres-websockets/blob/master/stack.yaml
WORKDIR /app/postgres-websockets
RUN stack setup
RUN stack install --resolver lts-21.14

ENTRYPOINT ["./postgres-websockets"]
# Lightweight Final Image
FROM debian:bullseye-slim

# Install Runtime Dependencies
RUN apt-get update \
&& apt-get install -y \
libpq-dev \
libgmp-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

# Copy the Binary from the Builder
COPY --from=builder /root/.local/bin/postgres-websockets /usr/local/bin/postgres-websockets

# Set the Entry Point
ENTRYPOINT ["postgres-websockets"]
4 changes: 0 additions & 4 deletions src/docker/cargo-chef/Dockerfile

This file was deleted.

106 changes: 0 additions & 106 deletions src/docker/chain/Dockerfile

This file was deleted.

1 change: 0 additions & 1 deletion src/docker/chain/accounts/econia.address

This file was deleted.

1 change: 0 additions & 1 deletion src/docker/chain/accounts/econia.key

This file was deleted.

1 change: 0 additions & 1 deletion src/docker/chain/accounts/faucet.address

This file was deleted.

1 change: 0 additions & 1 deletion src/docker/chain/accounts/faucet.key

This file was deleted.

4 changes: 2 additions & 2 deletions src/docker/compose.dss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
PGRST_DB_SCHEMA: api
image: postgrest/postgrest
ports:
- "3001:3000"
- "3000:3000"

ws:
build:
Expand All @@ -42,4 +42,4 @@ services:
- PGWS_CHECK_LISTENER_INTERVAL=1000
- PGWS_LISTEN_CHANNEL=econiaws
ports:
- 3000:3000
- 3001:3000
8 changes: 6 additions & 2 deletions src/docker/database/Dockerfile.postgres
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
FROM postgres:14-bookworm

# pgjwt repo metadata
ARG GIT_REPO=https://github.com/michelp/pgjwt.git
ARG GIT_COMMIT=f3d82fd30151e754e19ce5d6a06c71c20689ce3d

RUN apt-get update -y \
&& apt-get install -y git make \
&& rm -rf /var/lib/apt/lists/*

RUN git clone https://github.com/michelp/pgjwt

RUN git clone $GIT_REPO
WORKDIR ./pgjwt
RUN git checkout $GIT_COMMIT

RUN make install

Expand Down
Loading

0 comments on commit 188537c

Please sign in to comment.