Skip to main content

Running a Genius Yield Smart Order Router with Maestro

Genius Yield offers a truly decentralized DEX experience on Cardano and combines various innovative features such as:

  • A pure order-book architecture - A similar model found in traditional finance and centralized crypto exchanges.
  • Smart Order Routers - No centralized batchers, but community run arbitrage bots.
  • Market Making Bots - No more impermanent loss, LPs can execute advanced market making strategies.

Under the hood, Genius Yield is powered by Maestro’s blockchain infrastructure platform. Get to know more here!

The Smart Order Routers opportunity

Genius Yield Smart Order Routers are a key component of the Genius Yield innovative way of running a DEX on Cardano.

Unlinke with the centralized batchers approach, in Genius Yield orders will be matched and put forward to the blockchain by community-run arbitrage bots - Smart Order Routers.

On a high level, these bots will monitor the Genius Yield order books in search of matchable buy and sell orders. The default SOR strategy will only match and submit orders that are beneficial to the bot itself. This presents a risk-free way to contribute to the DEX's working by running an SOR.

This guide will illustrate the simplest way one can leverage Maestro to run a Genius Yield SOR.

Getting a Maestro Account and API key

To interact with the Cardano blockchain, a Maestro Account, Project and API key will be required. Please follow the instructions detailed here.

This maestro api-key is the value that will be assigned to MAESTRO_API_KEY when running the SOR via Docker.

Installing Docker and cardano-cli

Follow the official instructions to install Docker on your system.

The simplest way to get cardano-cli running will be to use Docker and get the Blink Labs cardano-node image by running:

// Pull the image
docker pull ghcr.io/blinklabs-io/cardano-node

// Testing that it runs
docker run --rm -ti ghcr.io/blinklabs-io/cardano-node cli --help

Generating bot wallet keys

An important initial step is the creation of the bot wallet keys.

For running in preprod, replace --mainnet with --testnet-magic 1

// Generate bot wallet keys in current working directory
docker run --rm -ti -w /tmp -v `pwd`:/tmp ghcr.io/blinklabs-io/cardano-node \
cli address key-gen --verification-key-file bot.vkey --signing-key-file bot.skey

// Generate bot wallet address in current working directory
docker run --rm -ti -w /tmp -v `pwd`:/tmp ghcr.io/blinklabs-io/cardano-node \
cli address build --mainnet --payment-verification-key bot.vkey --out-file bot.addr

This will create the files bot.skey, bot.vkey, and bot.addr: the private signing key, the verification key, and the wallet address on the preprod testnet.

Read the cbor hex for the private signing key using the following command:

cat bot.skey | jq -r '.cborHex'

This private signing key is the value that will be assigned to PAYMENT_SIGNING_KEY_CBOR_HEX when running the SOR via Docker.

caution
  • This private signing key grants access to moving the funds sent to or accrued on the wallet.
  • There is no way to regenerate the same keys, therefore please store this data with the utmost safety and security in mind.
  • Know more about Cardano Wallets here.

Preparing a collateral UTxO

It is recommended to provision the bot wallet with 5 ADA to be used as collateral.

The address for the bot wallet generated above can be obtained with:

cat bot.addr

Compose and submit a transaction sending 5 ADA to this address.

The reference for the resulting UTxO can be seen using Maestro Indexer endpoint UTxOs at an address.

curl -L -X GET 'https://mainnet.gomaestro-api.org/v1/addresses/<SOR-bot-wallet-address>/utxos' \
-H 'Accept: application/json' \
-H 'api-key: <maestro api-key>'

By putting together the response's tx_hash and index, a UTxO reference can be obtained.

E.g. b24743fb4b5381971ee8b3d02a3fd5e783acdb5a21cd2d22d192ec84e7e279fc#0 where the ending in #0 would signify an index of 0.

This collateral UTxO reference is the value that will be assigned to COLLATERAL_UTXO_REF when running the SOR via Docker.

Running the GY SOR using Maestro+Docker

The following bash snippet will use the elements gathered above to define environment variables and use them to run a Docker version of a Genius Yield Smart Order Router.

For running on the preprod network, replace --mainnet with --preprod.

# Define environment variables
# Replace <> fields with actual values (removing the <>)
PAYMENT_SIGNING_KEY_CBOR_HEX=<private signing key>
COLLATERAL_UTXO_REF=<collateral UTxO reference>
MAESTRO_API_KEY=<maestro api-key>
CARDANO_NETWORK=mainnet

# Run the Docker version of the Genius Yield Smart Order Router
# Will automatically download Docker images on first run
# use --pull=always so that, when restarting your SOR, Docker will look for the latest image by Genius Yield
docker run -it --pull=always\
-e BOTC_SKEY="{\"cborHex\": \"$PAYMENT_SIGNING_KEY_CBOR_HEX\", \"type\": \"PaymentSigningKeyShelley_ed25519\", \"description\": \"Payment Signing Key\"}" \
-e BOTC_COLLATERAL="$COLLATERAL_UTXO_REF" \
-e BOTC_CONFIG="{ \"coreProvider\": { \"maestroToken\": \"$MAESTRO_API_KEY\" }, \"networkId\": \"$CARDANO_NETWORK\", \"logging\": [{ \"type\": { \"tag\": \"stderr\" }, \"severity\": \"Info\", \"verbosity\": \"V2\" }],\"utxoCacheEnable\": false }" \
ghcr.io/geniusyield/smart-order-router:latest
tip
Where to next?