/usage-socket

🔌 Plug in to the FOMO

Primary LanguageTypeScriptMIT LicenseMIT

GET Protocol Usage Socket

Horizontally scalable websocket server offering a real-time feed of all protocol usage and events.

The GET Protocol Usage Socket (affectionately known as the FOMO Socket) is used to broadcast all usage events on the protocol. This covers all ticket interactions and event registration. This will offer a real-time feed of usage and GET token.

The following contract events and usage types are handled:

  • PrimarySaleMint => { type: "MINT" }
  • TicketInvalidated => { type: "INVALIDATE" }
  • SecondarySale => { type: "RESALE" }
  • TicketScanned => { type: "SCAN" }
  • NftClaimed => { type: "CLAIM" }
  • newEventRegistered => { type: "NEW_EVENT" }

Relation to Subgraph UsageEvent

The UsageEvents generated by usage-socket attempt to maintain type consistency with the UsageEvent entity in the GET Protocol Subgraph. There are a number of key differences to the UsageEvents between each project:

  • usage-socket is stateless and will not hold a history of the UsageEvents and will always track the latest contract events. The subgraph is designed to store a historical record of these events so will contain a full version history of contract ABIs.
  • The GraphQL interface of the subgraph allows for nested entites, which are not supported here. Instead the associations have bee flattened to their respective IDs. relayer { id } becomes relayerId and event { id } becomes eventId.

Otherwise the keys and values should be identical. See index.d.ts for the UsageEvent type definition.

Setup

You will first need a Polygon WebSocket RPC endpoint to listen to blockhain events. Infura or Moralis (Speedy Nodes) provide enough capacity on their free-tiers.

Note; the application does not handle loading environment variables onto your environment. You can try to use dotenv-cli or do this directly within your shell.

  1. cp .env.example .env
  2. yarn install
  3. yarn start

Or if you prefer to use docker:

  1. docker build -t usage-socket .
  2. docker run --env-file ./.env -p 8080:8080 -it usage-socket

The websocket can be can be found at ws://localhost:8080/ and connected to with Websocat using websocat ws://127.0.0.1:8080.

Contributing

Contributions are welcome, please feel free to let us know about any issues or create a PR. By contributing, you agree to release your modifications under the MIT license (see the file LICENSE).

Conventions

Where possible we stick to some sensible defaults in particular @typescript-eslint, and Prettier. Husky has been configured to automatically lint and format upon commit.