CKS-Systems / manifest

The Unlimited Orderbook
https://www.manifest.trade
GNU General Public License v3.0
32 stars 17 forks source link
defi orderbook solana

Logo

MANIFEST

The Unlimited Orderbook

codecov Code Review - Rust Code Review - Typescript Build Docs Benchmarking Formal Verification

Manifest is the next generation liquidity primitive on Solana. No more permissioned markets. No more trading fees. No more expensive rent to start a market. Capital efficiency built-in. Maximal freedom to exchange risk. Trade everything for nothing.

Whitepaper

Read The Orderbook Manifesto

Comparison

Openbook Phoenix Manifest
Crankless No Yes Yes
Feeless No No Yes
Atomic lot sizes No No Yes
Anchor Yes No No
Creation Rent 2 SOL 3+ SOL .004 SOL
License GPL Business GPL
Read optimized Yes No Yes
Swap accounts 16 8 7
CU :white_check_mark: :white_check_mark: :white_check_mark: :white_check_mark:
Token 22 No No Yes
Composable wrapper No No Yes
Capital Efficient No No Yes

Details:

Design Overview

Data Structure

The innovation that allows this next leap in onchain trading is the hypertree. All data in the market account fits into graph nodes of the same size (80 bytes), which lets independent data structures grow without being fully initialized from the start by interleaving

The market account holds all relevant information. It begins with a header that stores all of the fixed information for the market like BaseMint, QuoteMint. All variable data (RestingOrders and ClaimedSeats) are in the dynamic byte array after the header. There are 3 RedBlack trees for Bids, Asks, ClaimedSeats and 1 LinkedList for FreeListNodes, overlapping across each other. All are graphs where each vertex along with adjacency list fits in 80 bytes, allowing them to use the same blocks.

--------------------------------------------------------------------------------------------------------
|                   Header                    |                               Dynamic                   |
--------------------------------------------------------------------------------------------------------
| BaseMint, QuoteMint, BidsRootIndex, ...     | Bid | Ask | FreeListNode | Seat | Seat | Bid | Bid | Ask|
--------------------------------------------------------------------------------------------------------

Core vs Wrapper

Manifest implements the orderbook as an infrastructure layer primitive and creates the purest form of risk exchange possible. Other orderbooks get bogged down by special feature requests from trading teams that ultimately make the program bloated and confusing. Manifest strives to only include features that are absolutely necessary to be in the base layer. Anything that can be handled at layers above on the stack will not be done in manifest. This simplification makes formal verification of the program feasible.

Manifest should be interacted with though a wrapper program. Features like ClientOrderId, FillOrKill, PostOnlySlide, adjusting orders for insufficient funds, can and should be in a separate program that does a CPI into Manifest. A reference implementation and deployment of a wrapper are provided, showing what can be done outside the core of an orderbook without needing to be in the orderbook itself.

Global Orders

Global orders are a new type of order for trading on Solana. When resting orders across many markets, cost of capital can be expensive. This is the problem that global orders look to address. A global order is an order that does not lock the tokens to support the order on the market. The same tokens that would have supported an order on one market, can now support orders across many markets, with the tokens moved just in time as there is a fill.

Building

cargo build-sbf

Open Questions

Testing

Program Test

cargo test-sbf

Typescript client test

sh local-validator-test.sh

Resources

Version

Currently deployed version 1.0.0 release

Client SDK

NPM Package

Audit

View Report

Formal Verification

Instructions for how to run formal verification are in Certora_README

From a high level, 4 sets of properties were formally verified

Verification is rerun against head every day using the certora prover. The rules mostly lie within the certora directory. There are some parts of the code that are only enabled with the certora feature, but that is so the verification can go beyond proving invariants at the end and do it on intermediate steps.

Tip Jar

B6dmr2UAn2wgjdm3T4N1Vjd8oPYRRTguByW7AEngkeL6

Debugging

A fork of solana explorer with insruction decoding and fill log parsing has been made in this repo which is hosted at explorer.manifest.trade. Due to the lack of updates from anchor and hacky changes to get the explorer to handle parsing a non-anchor program, we are not currently going to try to backport our changes.