Go SDK

The Go SDK provides a WebSocket JSON-RPC 2.0 client for interacting with the YoorQuezt MEV engine. It supports concurrent calls, atomic request IDs, and subscription channels for real-time event streaming.

Installation

go get github.com/yoorquezt-labs/yoorquezt-sdk-mev-go

Features

  • WebSocket JSON-RPC 2.0 -- persistent connection with concurrent call support
  • Atomic request IDs -- thread-safe ID generation for parallel requests
  • Subscriptions -- channel-based subscription system for real-time events
  • Automatic reconnection -- configurable reconnect with exponential backoff
  • Context support -- all methods accept context.Context for cancellation and timeouts

Available Methods

The client exposes the following JSON-RPC methods via the gateway:

Bundle Operations:

  • mev_sendBundle -- submit a bundle for MEV extraction
  • mev_getBundle -- query bundle status by ID
  • mev_simulateBundle -- simulate a bundle without submitting
  • mev_simulateTx -- simulate a single transaction
  • mev_listBundles -- list stored bundles

Protected Transactions:

  • mev_protectTx -- submit a transaction with MEV protection
  • mev_getProtectStatus -- query protection status
  • mev_getProtectRebates -- query accumulated rebates

Auction:

  • mev_getAuction -- query current auction state

Intent Operations:

  • mev_submitIntent -- submit an intent
  • mev_getIntent -- query intent by ID
  • mev_submitSolution -- submit a solver solution
  • mev_getSolutions -- list solutions for an intent
  • mev_registerSolver -- register as a solver
  • mev_listSolvers -- list registered solvers

Relay Operations:

  • mev_relayRegister -- register a relay
  • mev_relayList -- list connected relays
  • mev_relayStats -- relay marketplace statistics
  • mev_relayGet -- get relay by ID

Query / System:

  • mev_listBlocks -- list recent blocks
  • mev_getBlock -- get block by ID
  • mev_health -- health check
  • mev_authStats -- authentication statistics
  • mev_simCacheStats -- simulation cache statistics
  • mev_orderflowSummary -- orderflow summary

Aliases (yq_ prefix):

  • yq_getProtectionStatus -- alias for mev_getProtectStatus
  • yq_getRebateHistory -- alias for mev_getProtectRebates
  • yq_getStats -- OFA statistics

Subscription Topics

TopicDescription
auctionReal-time auction events: new bids, auction results, winning bundles
protectProtection events: MEV detected, mitigated, rebates accumulated
blocksNew block events with included bundles and MEV statistics
mempoolMempool activity: new transactions, pending bundles
intentsIntent lifecycle events: submitted, solving, filled, expired

Subscribe via mev_subscribe / mev_unsubscribe (or yq_subscribe / yq_unsubscribe).

Code Example

package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/yoorquezt-labs/yoorquezt-sdk-mev-go"
	
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()

	// Connect to the gateway
	c, err := yqmev.Dial(ctx, "ws://localhost:9099/ws", client.Options{
		APIKey:           "YOUR_API_KEY",
		ReconnectBackoff: 2 * time.Second,
		MaxReconnects:    5,
	})
	if err != nil {
		log.Fatalf("failed to connect: %v", err)
	}
	defer c.Close()

	// Submit a protected transaction
	var txStatus jsonrpc.TransactionStatus
	err = c.Call(ctx, "mev_protectTx", &txStatus, jsonrpc.ProtectedTxParams{
		RawTx:   "0x02f8...",
		ChainID: 1,
	})
	if err != nil {
		log.Fatalf("send protected tx failed: %v", err)
	}
	fmt.Printf("Transaction: %s, Protected: %v\n", txStatus.TxHash, txStatus.Protected)

	// Submit a bundle
	var bundleResult jsonrpc.BundleResult
	err = c.Call(ctx, "mev_sendBundle", &bundleResult, jsonrpc.BundleParams{
		Txs:         []string{"0x02f8...", "0x02f8..."},
		BlockNumber: "0x10a3b2c",
		MinTimestamp: 0,
		MaxTimestamp: 0,
	})
	if err != nil {
		log.Fatalf("send bundle failed: %v", err)
	}
	fmt.Printf("Bundle ID: %s\n", bundleResult.BundleID)

	// Subscribe to auction events
	auctionCh, subID, err := c.Subscribe(ctx, "auction")
	if err != nil {
		log.Fatalf("subscribe failed: %v", err)
	}
	defer c.Unsubscribe(ctx, subID)

	fmt.Println("Listening for auction events...")
	for {
		select {
		case event := <-auctionCh:
			fmt.Printf("Auction event: %s\n", event.Method)
		case <-ctx.Done():
			fmt.Println("Context cancelled, shutting down")
			return
		}
	}
}

Querying Rebates

// Check accumulated rebates
var rebates jsonrpc.RebateResponse
err = c.Call(ctx, "mev_getProtectRebates", &rebates, map[string]string{
	"originator_id": "0xYourAddress",
})
if err != nil {
	log.Fatalf("get rebates failed: %v", err)
}
fmt.Printf("Rebate balance: %s ETH\n", rebates.TotalRebate)
Edit this page