multi-market crank for serum-dex

Overview

serum-crank

A performance and cost optimized serum-dex crank that allows combining multiple market cranking instructions into a single transaction, while concurrently generating the crank instructions allowing for increased throughput.

Overview

This works by taking a list of markets which need to be cranked, and checking each market concurrently with the rest. Any markets which can be cranked during the given work loop iteration will be combined into a single transaction. If no markets are ready to be cranked, the work loop exits, otherwise it will crank all available markets.

Transaction Size Limits

Depending on your configured settings, you may be able to crank up to 6 markets in a single transaction.

Compiler Optimizations

The rustc compiler settings have been set to as optimized as they can be, so build times will generally be slower than normal.

Global Allocator

The global allocator has been replaced with jemalloc, allowing the usage of jemalloc over the default which usually ends up being malloc.

Docker

A docker image and compose file is included, which can be built locally providing you meet the following requirements:

  • buildkit supported by your docker daemon to enable build caching
  • Experimental features enabled in your docker daemon.
  • optional - pigz to compress the exported docker image

To build the docker image run

$> make build-docker

After it is built and you have the configuration file filled out, you can run:

$> docker-compose up -d

If it is your first time building the docker image it will take awhile. On an i7-9750H w/ 32GB of memory first time builds take around 400 -> 600 seconds. Subsequent builds will usually take 50% of this time, so typically anywhere from 200 -> 300 seconds.

CLI

To use the docker image requires a configuration file which is the primary use of the CLI. Although it can be used to run the crank service as well. To build the CLI run

$> make build-cli
$> ./crank --help
serum-crank 0.0.1
Solfarm
a performance optimized serum crank service

USAGE:
    crank [OPTIONS] [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -c, --config <FILE>    sets the config file

SUBCOMMANDS:
    config    configuration management commands
    help      Prints this message or the help of the given subcommand(s)
    run       runs the serum crank

Configuration

With the CLI built you can generate a config file located in the current working directory named config.yaml with the config commands:

---
http_rpc_url: "https://api.devnet.solana.com"
ws_rpc_url: "ws://api.devnet.solana.com"
key_path: ~/.config/solana/id.json
log_file: liquidator.log
debug_log: false
crank:
  # used to configure the markets to crank
  markets:
    # name of the market to crank
    - name: TULIP-USDC
      # the market account public key
      market_account: somekey
      # random coin wallet,doesnt really matter what you pick
      # we use an ATA account
      coin_wallet: somewallet
      # random pc wallet, as as above
      pc_wallet: some_pc_wallet
  # the serum dex program
  dex_program: 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin
  # the amount of time in seconds to wait in between crank runs
  max_wait_for_events_delay: 60
  # the max number of accounts to include in a single crank
  # if you want to get up to 6 markets per tx, you will want to set this to 5
  num_accounts: 32
  # max events processed per worker
  events_per_worker: 5
  # max number of markets to crank in a single tx
  # if there are more markets to crank than this number
  # we chunk the markets to crank into groups of this number
  max_markets_per_tx: 6

Log Analysis

To enable quick analysis of the serum crank log file, scripts/check_logs.sh can be used to dump the logs of the running crank docker container, which will show a warning if any errors were detected. When no errors have been detected the output looks similar to:

$ ./check_logs.sh 
found records of 320 cranks, with highest markets in tx 5
5 most recent crank transactions
2s6Uxd....bfB9TkPKeV
4trQ1n....DRaMZ3hcDS
5A3RT2....MRcVRCSyK4
23jksg....rdLSVPQ2pd
3U4jTe....kMuQgZKMvW

Results

With the following configuration the highest amount of markets cranked in a single transaction so far has been 7.

max_wait_for_events_delay: 60
num_accounts: 5
events_per_worker: 5
max_markets_per_tx: 9

License

Based on code from Serum, so for their click here

You might also like...
Two-party and multi-party ECDSA protocols based on class group with Rust

CG-MPC-ECDSA This project aims to implement two-party and multi-party ECDSA protocols based on class group with Rust. It currently includes schemes de

Cryptle: a secure multi-party Wordle clone with Enarx

Cryptle: a secure multi-party Wordle clone with Enarx Wordle is a popular web-based game, where a single player has to guess a five-letter word in six

User-friendly secure computation engine based on secure multi-party computation
User-friendly secure computation engine based on secure multi-party computation

CipherCore If you have any questions, or, more generally, would like to discuss CipherCore, please join the Slack community. See a vastly extended ver

Ethereum JSON-RPC multi-transport client. Rust implementation of web3 library

Ethereum JSON-RPC multi-transport client. Rust implementation of web3 library. ENS address: rust-web3.eth

A basic contract to facilitate multi-hop FIN swaps

Fin Multi A basic contract designed to support consolidation of staking "dust" into a single asset, via FIN Market Swaps. ExecuteMsg requires a VecVe

CosmWasm multi-contract testing framework

Multi Test: Test helpers for multi-contract interactions Warning: Alpha Software Designed for internal use only. This is used for testing cw-plus cont

Freelance payment protocol written in Rust.. (with multi-sig signing for dispute settling)

Freelance Escrow payment protocol 📝 About The freelance protocol is a protocol built on decentralized and open systems such as blockchain and decentr

Multi-tenant Nix Binary Cache

Attic Attic is a self-hostable Nix Binary Cache server backed by an S3-compatible storage provider. It has support for global deduplication and garbag

Template for multi-contract CosmWasm projects

CosmWasm Template Template for multi-contract CosmWasm projects How to Use Install cargo-make: cargo install --force cargo-make Run formatter: cargo m

Comments
  • "Found Instructions For X" Doesnt Display Correct Amount

    The found instructions for X marktets log no longer shows the correct amount of markets cranked as of https://github.com/sol-farm/serum-crank/commit/deaca30c4b1c9ff93c5222017b2c9fb9edfd555e

    bug 
    opened by bonedaddy 1
  • Multi-Crank And Misc Optimizations

    Multi-Crank And Misc Optimizations

    Overview

    Removes all functionality not related to crank turning, and allows combining crank instructions for a configurable max number of markets per transaction. This allows you to speed up crank times, and reduce crank costs.

    opened by bonedaddy 0
  • Crank Optimizations

    Crank Optimizations

    • Dont read_keypair_file for each iteration of consume_events_wrapper. Read it once at startup and wrap in Arc and then use Arc::clone
    • Do not opts.client() for each iteration of consume_events_wrapper. Do so once at startup and wrap in Arc and then use Arc::clone
    • Combine multiple crank operations in one transaction. Should be able to fit at least 2, potentially 4 -> 5.
    • Add signal handling for graceful exits
    opened by bonedaddy 0
  • Migrating To OpenDex

    Migrating To OpenDex

    To migrate from the existing serum dex to the new opendex, all you need to do is replace the pre-existing dex program id with srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX

    opened by bonedaddy 0
Releases(v0.0.8)
Owner
SolFarm
The Efficient Solana Yield Aggregator
SolFarm
Project Serum Rust Monorepo

serum-dex Project Serum Rust Monorepo Website | Discord | Awesome | DEX | TypeScript Program Deployments Program Devnet Mainnet Beta DEX DESVgJVGajEgK

Project Serum 564 Dec 31, 2022
Making composability with the Zeta DEX a breeze, FuZe provides CPI interfaces and sample implementations for on-chain program integration.

Zeta FuZe ?? Zeta FuZe FuZe is Zeta's cross-program integration ecosystem. This repository contains the Zeta Cross Program Invocation (CPI) interface

Zeta 39 Aug 27, 2022
A tutorial for an NFT Market Place Built with Near Protocol and React.js

nft-marketplace-part-1 A tutorial for an NFT Market Place built using Near Protocol and React.js. Preview To run this app locally, follow below steps:

Kohwo Orien 5 Jun 29, 2022
A collection of libraries to be implemented for Automated Market Makers built in Sway.

?? ?? Executor AMM ?? ?? The Executor AMM is a reference implementation of Concentrated Liquidity in Sway. To run on the FuelVM many modifications had

Sway Libraries 54 Dec 21, 2022
A fast and secure multi protocol honeypot.

Medusa A fast and secure multi protocol honeypot that can mimic realistic devices running ssh, telnet, http, https or any other tcp and udp servers. W

Simone Margaritelli 268 Dec 26, 2022
An encrypted multi client messaging system written in pure Rust

?? Preamble This is a pure Rust multi-client encrypted messaging system, also known as Edode's Secured Messaging System. It is an end-to-end(s) commun

Edode 3 Sep 16, 2022
Eternally liquid. Forward compatible. Nested, conditional, & Multi-resourced NFTs.

RMRK Substrate Rust Setup First, complete the basic Rust setup instructions. Run Use Rust's native cargo command to build and launch the template node

RMRK Team 67 Dec 25, 2022
Multi Party Key Management System (KMS) for Secp256k1 Elliptic curve based digital signatures.

Key Management System (KMS) for curve Secp256k1 Multi Party Key Management System (KMS) for Secp256k1 Elliptic curve based digital signatures. Introdu

[ZenGo X] 61 Dec 28, 2022
Rust implementation of multi-party Schnorr signatures over elliptic curves.

Multi Party Schnorr Signatures This library contains several Rust implementations of multi-signature Schnorr schemes. Generally speaking, these scheme

[ZenGo X] 148 Dec 15, 2022
A standalone Aleo prover build upon snarkOS and snarkVM, with multi-threading optimization

Aleo Light Prover Introduction A standalone Aleo prover build upon snarkOS and snarkVM, with multi-threading optimization. It's called "light" because

Haruka Ma 91 Dec 29, 2022