An open source, high performance limit order book for the Seaport smart contracts. Implemented in Rust using ethers-rs, this offers a turnkey option for digital asset marketplaces.

Overview

Quay

Quay is an open source, high performance backend for the Seaport smart contracts. The project is implemented in Rust, using Postgres as a storage backend, with the aim of allowing a proliferation of signature based trading platforms for ERC-721s and ERC-1155s based on the Seaport smart contract interface.

Project structure

Web application

main.rs contains the main function, which is called when the crate's binary is executed. That in turn calls startup.rs. That creates the application, attaches the services, routes, database connection pool, and rpc connection context used by the endpoints.

Routes/Services

Routes and services are defined in /routes using actix-web macros.

Telemetry

telemetry.rs and startup.rs set up a tracing framework that provides rich logs for runtime telemetry and development debugging. These tracing logs are then extended via macros on routes.

Example:

#[post("/offers")]
#[tracing::instrument(
name = "Adding a new offer",
skip(offer, pool, seaport),
fields(
offerer = %offer.parameters.offerer,
)
)]
async fn create_offer(
    offer: web::Json<Order>,
    pool: web::Data<PgPool>,
    seaport: web::Data<Seaport<Provider<ethers::providers::Http>>>,
) -> HttpResponse {
    if insert_offer(&pool, &offer, &seaport).await.is_err() {
        return HttpResponse::InternalServerError().finish();
    }
    HttpResponse::Ok().finish()
}

SIWE Authentication

This project supports EIP-4361 (Sign in with Ethereum) authentication. See src/routes/sessions.rs for implementation details.

Redis

Redis is used for SIWE session storage.

Database

The database schema and queries are written in SQL and managed with sqlx. The schemas live in migrations/, and the database queries are inline where used on the objects (SQL speaking objects). The database connection is handled in a connection pool at application startup.

Generating queries for macros

When new queries are added, run DATABASE_URL=postgres://postgres:password@localhost:5432/quay cargo sqlx prepare -- --lib to generate new query definitions for the macro expansion used by sqlx.

Migrations

Database schema migrations are performed out of band with sqlx-cli. All database migrations should be tested locally, and applied in a non-breaking fashion. What this means, ideally, is that there is a migration to add new functionality, then a rollout of the new backend version, then another migration to delete any legacy schema after roll out.

How to run migration using sqlx-cli
  1. sqlx migrate add '<MIGRATION_NAME>';
  2. Write all necesarry queries in migrations/<MIGRATION_NAME>;
  3. Apply for local db (if it's required for testing): sqlx migrate run;

Smart contract interactions and data structures

Blockchain interactions happen via RPC using the ethers-rs library. This project contains type safe bindings for the seaport (seaport.rs) and conduit controller (conduit_controller.rs) contracts, which have been extended with other functionality, and will eventually include functions for serializing to and from postgres. The rpc connection is handled by a wrapped reference counter at application startup.

Local development environment

Developers will need rust and docker to work on this project. Docker is used to host a local instance of the postgres database to execute tests against. To set up a local database, run: ./scripts/init_db.sh and ./scripts/init_redis.sh

Building the project

Run cargo build to build the project. indexer.dockerfile and api.dockerfile are useful for generating docker images for use in production or testing.

Tests

Tests live in the /tests folder.

Running the tests

Run cargo test any time after setting up your development environment.

CI/CD

CI/CD is implemented using GitHub actions, the scripting is in .github/workflows. There are certain actions which run on open pull requests, and deploy actions, which run only after passing tests on master.

Continuous Integration

This project uses clippy, tarpaulin, and a number of other crates to provide end-to-end tests, unit tests, formatting, linting, and static analysis to enforce code quality. These tests are then run in an automated fashion using GitHub actions.

Continuous Deployment

This project supports deployment to Digital Ocean via spec.yaml

You might also like...
A template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it.

CosmWasm Starter Pack This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it. To understan

Create your personal token with rust smart contracts

Solana Rust Token 💰 This application written Rust using Anchor ⚓

Rust library for build smart contracts on Internet Computer, by the Spinner.Cash team.

Spinner Rust library for building smart contracts on the Internet Computer. More specifically it is used by Spinner.Cash, a decentralized layer-2 prot

Rust implementation for Thippy -- a Substrate parachain for smart contracts.

Thippy ‒- A Smart Contracts Parachain This is a node implementation of Thippy, a Substrate parachain for smart contracts. Developing Smart Contracts f

🖨 Template for Rust applications & smart contracts @okp4.

Rust Template Template for Rust projects @okp4. Purpose & Philosophy This repository holds the template for building Rust projects with a consistent s

Unofficial Rust SDK library for Uniswap smart contracts.

uniswap-rs Unofficial Rust SDK library for Uniswap smart contracts. Quickstart Add this to your Cargo.toml: [dependencies] uniswap-rs = { git = "https

zink! is a library for developing ink! smart contracts with useful Rust macros that extend functionality and reduce boilerplate code.
zink! is a library for developing ink! smart contracts with useful Rust macros that extend functionality and reduce boilerplate code.

zink! Smart Contract Macros This is a helper library for developing ink! smart contracts. It contains useful Rust macros that extend functionality and

Unofficial Rust SDK library for Uniswap smart contracts.

uniswap-rs Unofficial Rust SDK library for Uniswap smart contracts. Quickstart Add this to your Cargo.toml: [dependencies] uniswap-rs = { git = "https

Smart contracts for Ref Finance

Ref Finance Contracts This mono repo contains the source code for the smart contracts of Ref Finance on NEAR. Contracts Contract Reference Description

Comments
  • Migrate Quay to Axum

    Migrate Quay to Axum

    Migrating from actix -> axum is in line with getting everything running on the tokio runtime, as well as the ability to support a hybrid server for gRPC and http on the same port.

    opened by 0xAlcibiades 2
  • initial database schema for seaport

    initial database schema for seaport

    A cleanroom rewrite of a database schema to underlay these models: https://docs.opensea.io/v2.0/reference/model-reference

    Changed a bit of the casing to be more consistent, and the types to more closely correlate with the data types coming in and out of the contract.

    opened by 0xAlcibiades 1
  • Docs

    Docs

    Note: Includes the session branch as it had the most recent message structures/updates to Sequence Markdown

    Updated the docs.

    Trader => Taker. Updated to include function calls for on-chain interaction with Settlement Engine. Updated to include message structures of important note. Updated to include gRP for Taker.

    opened by dbelv 0
  • Error in  'quay/docs/SequenceDiagrams.md'.

    Error in 'quay/docs/SequenceDiagrams.md'.

    In, last sequence diagram ( https://github.com/Alcibiades-Capital/quay/raw/master/docs/diagrams/mm_offer_trader_execute.png ) It should be "Case: market make offer, trader executes", but it shows "Case: market make offer, trader doesn't execute".

    opened by madenmud 0
Releases(v0.1.0)
Owner
Valorem Labs Inc.
A team of EVM hackers, MEV searchers, and Rustaceans. Research and developing decentralized derivatives.
Valorem Labs Inc.
Minimal Substrate node configured for smart contracts via pallet-contracts.

substrate-contracts-node This repository contains Substrate's node-template configured to include Substrate's pallet-contracts ‒ a smart contract modu

Parity Technologies 73 Dec 30, 2022
An open source Rust high performance cryptocurrency trading API with support for multiple exchanges and language wrappers. written in rust(🦀) with ❤️

Les.rs - Rust Cryptocurrency Exchange Library An open source Rust high performance cryptocurrency trading API with support for multiple exchanges and

Crabby AI 4 Jan 9, 2023
This monorepository contains the source code for the smart contracts implementing bAsset Protocol on the Terra blockchain.

Crll bAsset Contracts This monorepository contains the source code for the smart contracts implementing bAsset Protocol on the Terra blockchain. You c

null 3 Mar 29, 2024
A PoC backbone for NFT Marketplaces on NEAR Protocol

NFT Market Reference Implementation A PoC backbone for NFT Marketplaces on NEAR Protocol. Reference Changelog Changelog Progress: basic purchase of NF

null 9 May 26, 2022
Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.

Building 1. Install rustc, cargo and rustfmt. $ curl https://sh.rustup.rs -sSf | sh $ source $HOME/.cargo/env $ rustup component add rustfmt When buil

Solana Foundation 9.8k Jan 3, 2023
ethers-rs signer using GCP KMS

ethers-gcp-kms-signer Installation Cargo cargo add ethers-gcp-kms-signer Usage Signer use ethers::prelude::*; use ethers_gcp_kms_signer::{GcpKeyRingRe

null 12 Apr 16, 2023
evm2near compiles Solidity contracts into NEAR WebAssembly contracts.

EVM → NEAR evm2near is a project for compiling EVM bytecode into wasm bytecode, with the particular goal of having that wasm artifact be executable on

Aurora 125 Dec 3, 2022
Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin.

dlctix Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin. This project is part of the Backdrop Build

null 7 Feb 29, 2024
Rust project for working with ETH - Ethereum transactions with Rust on Ganache and also deploy smart contracts :)

Just a test project to work with Ethereum but using Rust. I'm using plain Rust here, not Foundry. In future we will use Foundry. Hope you're already f

Akhil Sharma 2 Dec 20, 2022
Rust client to Opensea's APIs and Ethereum smart contracts

opensea.rs Rust bindings & CLI to the Opensea API and Contracts CLI Usage Run cargo r -- --help to get the top level help menu: opensea-cli 0.1.0 Choo

Georgios Konstantopoulos 226 Dec 27, 2022