An tiny web API for @QuarryProtocol

Overview

Warlock

warlock_gif

Warlock is a tiny web API layer around Quarry Protocol and has endpoints to deserialize Quarry accounts like quarries, miners, and rewarders to JSON.

Running Warlock locally

Clone the repo, get into the project root and run the following.

cargo build
touch .env && echo "PORT=3000" > .env
cargo run

Request/Response schemas

Before you read the req/res schemas, it's useful to know about some custom types that they use and how they're expected to be passed in from a client.

Network config

The network config object allows you to specify to an endpoint, a Network that you want it to interact with while performing it's logic. It is implemented in rust like so:

#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum Network {
    Mainnet,
    Devnet,
    Localnet,
}

/// Network config object for requests to use
#[derive(Debug, Serialize, Deserialize)]
pub struct NetworkConfig {
    pub variant: Network,
}

In JSON, this would be:

{
    "variant": SOME_VARIANT_HERE
}

The value for variant can be either "Mainnet", "Devnet" or "Localnet", with the parantheses since they're strings. If you want to specify custom RPC endpoints for those networks, feel free to edit the src/utils/network_utils.rs file locally. By default, it uses the standard Solana public RPC urls.

Pubkey config

The pubkey config object allows you to specify to an endpoint, a Pubkey that you want it to interact with while performing it's logic. It is implemented in rust like so:

#[derive(Serialize, Deserialize)]
pub struct PubkeyConfig {
    pub pubkey: Pubkey,
}

In JSON, this would be:

{
    "pubkey": [...] // Pubkey array
}

The value for pubkey should be the byte-array representation of the public key you're passing in which should be an array of 32 unsigned 8-bit integers. If you're using this from a rust client and need to grab the bytes from a pubkey string, you can use the following:

use solana_program::pubkey::Pubkey;

pub fn pubkey_string_to_bytes(addr: &str) -> [u8; 32] {
    let x = Pubkey::from_str(addr).unwrap();
    x.to_bytes()
}

/quarry, /miner, /rewarder

The request and response schemas for these endpoints are similar enough such that we can group the documentation together. All 3 endpoints are meant to be called using GET requests and they all use the exact same request format expected to be passed in as JSON in the request body, implemented in Rust as follows:

#[derive(Serialize, Deserialize)]
pub struct FetchAccountRequest {
    pub network_config: NetworkConfig,
    pub pubkey_config: PubkeyConfig,
}

Crafting the request body in JSON from a client looks like this:

{
    "network_config": {
         "variant": "Mainnet"
     },
     "pubkey_config": {
         "pubkey": [...] // Pubkey array
     }
 }

The "pubkey" would, once again, be an array of 32 unsigned 8-bit integers, or in other words, the byte-array representation of the pubkey of the quarry, miner, or rewarder you're trying to fetch.

The response schemas for these endpoints are mostly the same with a minor difference, implemented in Rust as follows:

// getMiner response
#[derive(Serialize, Deserialize)]
pub struct FetchMinerResponse {
    pub network_config: NetworkConfig,
    pub miner: MinerWrapper,
}

// getQuarry response
#[derive(Serialize, Deserialize)]
pub struct FetchQuarryResponse {
    pub network_config: NetworkConfig,
    pub quarry: QuarryWrapper,
}

// getRewarder response
#[derive(Serialize, Deserialize)]
pub struct FetchRewarderResponse {
    pub network_config: NetworkConfig,
    pub rewarder: RewarderWrapper,
}

The wrapper accounts (MinerWrapper, QuarryWrapper, RewarderWrapper) have the exact same format as the base accounts from the Quarry Protocol, I just had to reimplement them for reasons that nobody reading this should care about. There are no missing or additional fields in them.

The actual JSON returned from the endpoints would look like this:

    // Response for an example getRewarder request. You can imagine what the other two look like based off this :)

    {
    "network_config": {
        "variant": "Mainnet"
    },
    "rewarder": {
        "base": [...], // Pubkey array
        "bump": 255,
        "authority": [...], // Pubkey array
        "pending_authority": [...], // Pubkey array
        "num_quarries": 57,
        "annual_rewards_rate": 511000000000000,
        "total_rewards_shares": 6738,
        "mint_wrapper": [...], // Pubkey array
        "rewards_token_mint": [...], // Pubkey array
        "claim_fee_token_account": [...], // Pubkey array
        "max_claim_fee_kbps": 1000,
        "pause_authority": [...], // Pubkey array
        "is_paused": false
    }
}

Each endpoint returns back the network config passed into it and a JSON representation of the onchain account it was called to fetch. The only important thing to note is that for any field where the value is a public key, the value is represented as a byte-array.

You might also like...
REST API server that abstracts the need to write CRUD methods by exposing a standardized API to interact with a Postgres database
REST API server that abstracts the need to write CRUD methods by exposing a standardized API to interact with a Postgres database

Basiliq Exposing a Postgres database via a REST API that follows the JSON:API specs. All in all, a tasty API. What is Basiliq Quickstart Ready to use

A secure and efficient gateway for interacting with OpenAI's API, featuring load balancing, user request handling without individual API keys, and global access control.

OpenAI Hub OpenAI Hub is a comprehensive and robust tool designed to streamline and enhance your interaction with OpenAI's API. It features an innovat

A Rust web framework

cargonauts - a Rust web framework Documentation cargonauts is a Rust web framework intended for building maintainable, well-factored web apps. This pr

A Rust library to extract useful data from HTML documents, suitable for web scraping.

select.rs A library to extract useful data from HTML documents, suitable for web scraping. NOTE: The following example only works in the upcoming rele

A Google-like web search engine that provides the user with the most relevant websites in accordance to his/her query, using crawled and indexed textual data and PageRank.
A Google-like web search engine that provides the user with the most relevant websites in accordance to his/her query, using crawled and indexed textual data and PageRank.

Mini Google Course project for the Architecture of Computer Systems course. Overview: Architecture: We are working on multiple components of the web c

A rust web framework with safety and speed in mind.

darpi A web api framework with speed and safety in mind. One of the big goals is to catch all errors at compile time, if possible. The framework uses

A web framework for Rust.

Rocket Rocket is an async web framework for Rust with a focus on usability, security, extensibility, and speed. #[macro_use] extern crate rocket; #[g

Rust / Wasm framework for building client web apps
Rust / Wasm framework for building client web apps

Yew Rust / Wasm client web app framework Documentation (stable) | Documentation (latest) | Examples | Changelog | Roadmap | 简体中文文档 | 繁體中文文檔 | ドキュメント A

A super-easy, composable, web server framework for warp speeds.

warp A super-easy, composable, web server framework for warp speeds. The fundamental building block of warp is the Filter: they can be combined and co

Owner
Rohan Kapur
building some stuff ig
Rohan Kapur
Sauron is an html web framework for building web-apps. It is heavily inspired by elm.

sauron Guide Sauron is an web framework for creating fast and interactive client side web application, as well as server-side rendering for back-end w

Jovansonlee Cesar 1.7k Dec 26, 2022
Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.

Actix 16.2k Jan 2, 2023
Hot reload static web server for deploying mutiple static web site with version control.

SPA-SERVER It is to provide a static web http server with cache and hot reload. 中文 README Feature Built with Hyper and Warp, fast and small! SSL with

null 7 Dec 18, 2022
Code template for a production Web Application using Axum: The AwesomeApp Blueprint for Professional Web Development.

AwesomeApp rust-web-app More info at: https://awesomeapp.dev/rust-web-app/ rust-web-app YouTube episodes: Episode 01 - Rust Web App - Course to Produc

null 45 Sep 6, 2023
A highly customizable, full scale web backend for web-rwkv, built on axum with websocket protocol.

web-rwkv-axum A axum web backend for web-rwkv, built on websocket. Supports BNF-constrained grammar, CFG sampling, etc., all streamed over network. St

Li Junyu 12 Sep 25, 2023
Rust implementation of the `URLPattern` web API

urlpattern This crate implements the URLPattern web API in Rust. We aim to follow the specification as closely as possible. Contributing We appreciate

Deno Land 40 Dec 14, 2022
A pure Rust implementation of the Web Local Storage API, for use in non-browser contexts

Rust Web Local Storage API A Rust implementation of the Web LocalStorage API, for use in non-browser contexts About the Web Local Storage API MDN docs

RICHΛRD ΛNΛYΛ 10 Nov 28, 2022
Implementation of the RealWorld backend API spec in Actix, Rust's powerful actor system and most fun web framework.

Actix codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API. ❗ (2021/05/13) This cod

Allen 475 Jan 2, 2023
RESTful Todo API with Actix-web and SeaORM. Documented by swagger-ui

RESTful Todo RESTful Todo API with Actix and SeaORM. Documented by swagger-ui Prerequisites Rust Usage Clone the repository and run the following comm

Awiteb 4 Dec 27, 2022
An API project using Rust, Actix Web and JWT. *WIP*

Actix-web REST API with JWT (WIP) A simple CRUD backend app using Actix-web, Diesel and JWT Require Rust Stable Postgres Or using Docker How to run Ma

Akhil Sharma 4 Sep 21, 2023