Waverider is a Solana Geyser Plugin streaming account Data to a PostgREST Server
At a high level, Waverider allows you to specify a set of programs, from which you want the accounts (PDA's) to be streamed to your Postgres database.
Waverider is divided into two plugins, one called "default" and the other "atlantic". The difference between the two is that atlantic is also built to stream deserialized data to the database, while the default one only contains the raw data buffer.
- Speed: Making a SQL Query to a Postgres database can be up to 10 times faster than using gPa (getProgramAccounts) calls.
- Realtime: We can benefit from Supabase's realtime infrastructure to stream Realtime account updates to dApp frontends.
- Filtering: With the atlantic plugin, we can directly filter on chain data with a SQL Query, instead of having to use gPa Filters.
Walktrough of Waverider streaming deserialized account data to a Supabase instance.
WaveriderDEMO.mp4
git clone https://github.com/nautilus-project/waverider.git
cd waverider
- Build the Plugin
yarn build-default
- Set up your database
This plugin works with every PostgREST Server, although i recommend you set up a Supabase instance. They have a generous free tier, but can also be self hosted for completely free.
Take the SQL Script at config/default.sql and run it in your database, either via the CLI or a GUI(Supabase web GUI).
If you are using Supabase, also make sure to turn off Row Level Security for the accounts table, you can do this via the UI.
- Fill the configuration file
If you are a mac user, open config/config.default.mac.json
. If you are on Windows or Linux, open config/config.default.json
.
Fill out these fields:
{
// Your supabase REST API URL (starting with https//). Don't forget the /rest/v1 at the end
"supabase_url": "<url>/rest/v1",
// Your Supabase Annon Key
"supabase_key": "<key>",
// The programs you want to index accounts from
"programs": ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"]
}
- Launch your validator with the plugin
We'll use a local validator for this example, but this can be attached to a main/test/devnet validator.
For mac users, run: solana-test-validator --geyser-plugin-config config/config.default.mac.json
.
For Linux/Windows users, run: solana-test-validator --geyser-plugin-config config/config.default.json
.
If you want deserialized data to be streamed to your accounts, it's going to take a little glass chewing.
First, you'll have to define your structs in the plugin.rs
file. Then, get your accounts discriminators and add them as if statements into the code. The if statements should be like: if the first 8 bytes of the Geyser plugin Interface account data are equal to your structs discriminator, run YourStruct::deserialize. Then specify the table name where you want this data to be written to.
Keep in mind that you will have to create the SQL schema yourself based on your Account Structs.
I'm going to specify more documentation to this topic soon. Feel free to contribute any ideas on how to make this process easier.