Connecting to devnet

Introduction

This guide is intended for participants of our Dexterity Devnet alpha to connect to the market and start trading. Note that participation to our alpha program is by invitation only. Please get in touch on Discord if you are interested in joining the program.

Connectivity

While we eventually plan to host or provided self hosted REST/Websocket access to the market, currently the only provided mechanisms via which to connect are a Python & a Rust SDK. Since these require access to the dexterity repository which is not yet open sourced, seats are generally limited to our liquidity partners but get in touch with us and we can discuss access.

Some technical bits

You can find a much more in-depth technical description in the dexterity whitepaper, for the purposes of connecting it's important to understand two fundamental concepts in dexterity, that of the market product group and trader risk group. The market product group (MPG) represents a selection of actively traded products where cross-margining can take place. Products are dynamic in the sense that some products in a group will expire and new ones will get created, obviously some like a perpetual future can exist in perpetuity. The MPG is generally created and maintained by the network. The trader risk group (TRG) represents the trader's deposits, orders, positions and overall risk in the instruments of a specific MPG. This should be created by the trader as it will be linked to the trader's wallet.

Creating a TRG and accessing the market

We have attempted to keep the Python & Rust SDK in sync so the instructions below should apply to both but it's possible that some small discrepancies exist.

Discovery steps

  • Find out the program ids being used in the deployment from the HXRO team. The programs you will need the ids of are:
    • DEX
    • AGNOSTIC_ORDERBOOK
    • RISK_ENGINE
    • FEES
    • INSTRUMENTS
  • Then also find out what the current MPG being used for testing is.

Install Rust & the Solana CLI

  • Install Rust using rustup
  • Dexterity requires rust nightly, we recommend version nightly-2022-03-14
  • Install the Solana CLI
  • Run solana-keygen generate to generate you default private key
  • Run solana config set --url devnet to ensure you are pointing to devnet

TRG Creation steps (Python only)

  • Install poetry if you haven't already
  • Navigate to the client folder and run poetry install to create the virtual environment and install the dependencies
  • Set environment variables for the program ids as listed above
  • Run the new_connect.py script passing in the MPG, so for example poetry run dexteritysdk/bots/new_connect.py --market_product_group 2W35pvsJn7LWym5ADmSWkQJwEv4hRPfEvjx3Fb9TQnty.Note this will transfer lamports from your default key to a newly generate trader keypair. The script will print out the trader's private key, the generated TRG and a "vault" token associated token account (ATA).
  • Request an airdrop for the vault token from the HXRO team quoting the ATA. The command is spl-token mint --mint-authority <authority keypair> <token mint> <amount> -- <receiver ata>

Market interaction steps (Python & Rust)

  • Set PRIVATE_KEY for Python or PAYER for Rust to wallet owning the TRG
  • Create an SDKContext, using SDKContext::connect for Rust or SDKContext.connect for Python
  • Create an SDKTrader, using SDKTrader::connect for Rust or SDKTrader.connect for Python
  • Make a deposit using the deposit method on the SDKTrader object, this will deposit vault tokens from the trader's ATA to the MPG's vault and serves as your collateral
  • Proceed to try and create and cancel orders using the methods on SDKTrader
  • For some examples see maker-bot/src/main.rs for Rust or client/dexterity/bots/quoter_bot.py for Python

Notes / Known limitations

  • As Solana instructions cannot officially return return values, it is challenging to e.g. get hold of new order ids etc. In python, the client makes it easier to parse the logs and extract the ids from there, this is implemented currently but is somewhat fragile. For Rust it's still work in progress and therefore the example maker-bot does a cancel_all instead.