jito_go

package module
v0.0.0-...-5aa976a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

README

Jito Go SDK

GoDoc Go Report Card License

This library contains tooling to interact with Jito Labs MEV software. ⚠️ Work in progress. ⚠️

PRs and contributions are welcome.

jitolabs

❇️ Contents

✨ Features

  • Searcher
  • Block Engine
  • Relayer
  • ShredStream (WIP, help welcome 😊)
  • Geyser

📡 RPC Methods

🤡* methods which are disabled by Jito due to malicious use

  • Searcher
    • SubscribeMempoolAccounts 🤡
    • SubscribeMempoolPrograms 🤡
    • GetNextScheduledLeader
    • GetRegions
    • GetConnectedLeaders
    • GetConnectedLeadersRegioned
    • GetTipAccounts
    • SimulateBundle
    • SendBundle
    • SendBundleWithConfirmation
    • SubscribeBundleResults
  • Block Engine
    • Validator
      • SubscribePackets
      • SubscribeBundles
      • GetBlockBuilderFeeInfo
    • Relayer
      • SubscribeAccountsOfInterest
      • SubscribeProgramsOfInterest
      • StartExpiringPacketStream
  • Geyser
    • SubscribePartialAccountUpdates
    • SubscribeBlockUpdates
    • SubscribeAccountUpdates
    • SubscribeProgramUpdates
    • SubscribeTransactionUpdates
    • SubscribeSlotUpdates
  • ShredStream
  • Others (pkg/util.go)
    • SubscribeTipStream

💾 Installing

go get github.com/weeaa/jito-go@latest

If you want to run tests:

  1. Install Task.
  2. Initialize your .env file by running task install:<os> (darwin/linux/windows).
  3. Run tests with task test.

🔑 Keypair Authentication

To access Jito MEV functionalities, you'll need a whitelisted Public Key obtained from a fresh KeyPair; submit your Public Key here. In order to generate a new KeyPair, you can use the following function GenerateKeypair() from the /pkg package.

💻 Examples

Send Bundle
package main

import (
  "context"
  "github.com/17535250630/solana-go"
  "github.com/17535250630/solana-go/programs/system"
  "github.com/17535250630/solana-go/rpc"
  "github.com/weeaa/jito-go"
  "github.com/weeaa/jito-go/clients/searcher_client"
  "log"
  "os"
)

func main() {
  client, err := searcher_client.NewSearcherClient(
    jito_go.NewYork.BlockEngineURL,
    rpc.New(rpc.MainNetBeta_RPC),
    solana.MustPrivateKeyFromBase58(os.Getenv("PRIVATE_KEY")),
	nil,
  )
  if err != nil {
    log.Fatal(err)
  }

  // max per bundle is 5 transactions
  txns := make([]*solana.Transaction, 0, 5)

  block, err := client.RpcConn.GetRecentBlockhash(context.TODO(), rpc.CommitmentFinalized)
  if err != nil {
    log.Fatal(err)
  }

  from := solana.MustPrivateKeyFromBase58("Tq5gFBU4QG6b6aUYAwi87CUx64iy5tZT1J6nuphN4FXov3UZahMYGSbxLGhb8a9UZ1VvxWB4NzDavSzTorqKCio")
  to := solana.MustPublicKeyFromBase58("BLrQPbKruZgFkNhpdGGrJcZdt1HnfrBLojLYYgnrwNrz")

  tx, err := solana.NewTransaction(
    []solana.Instruction{
      system.NewTransferInstruction(
        10000,
        from.PublicKey(),
        to,
      ).Build(),
    },
    block.Value.Blockhash,
    solana.TransactionPayer(from.PublicKey()),
  )
  if err != nil {
    log.Fatal(err)
  }

  if _, err = tx.Sign(
    func(key solana.PublicKey) *solana.PrivateKey {
      if from.PublicKey().Equals(key) {
        return &from
      }
      return nil
    },
  ); err != nil {
    log.Fatal(err)
  }

  txns = append(txns, tx)

  resp, err := client.BroadcastBundleWithConfirmation(txns, 100)
  if err != nil {
    log.Fatal(err)
  }

  log.Println(resp)
}
Subscribe to MemPool Transactions [Accounts]
package main

import (
	"context"
    "github.com/17535250630/solana-go"
    "github.com/17535250630/solana-go/rpc"
    "github.com/weeaa/jito-go"
    "github.com/weeaa/jito-go/clients/searcher_client"
    "log"
    "os"
)

func main() {
  client, err := searcher_client.NewSearcherClient(
    jito_go.NewYork.BlockEngineURL,
    rpc.New(rpc.MainNetBeta_RPC),
    solana.MustPrivateKeyFromBase58(os.Getenv("PRIVATE_KEY")),
    nil,
  )
  if err != nil {
    log.Fatal(err)
  }

  txSub := make(chan *solana.Transaction)
  regions := []string{jito_go.NewYork.Region}
  accounts := []string{
    "GuHvDyajPfQpHrg2oCWmArYHrZn2ynxAkSxAPFn9ht1g",
    "4EKP9SRfykwQxDvrPq7jUwdkkc93Wd4JGCbBgwapeJhs",
    "Hn98nGFGfZwJPjd4bk3uAX5pYHJe5VqtrtMhU54LNNhe",
    "MuUEAu5tFfEMhaFGoz66jYTFBUHZrwfn3KWimXLNft2",
    "CSGeQFoSuN56QZqf9WLqEEkWhRFt6QksTjMDLm68PZKA",
  }

  payload := &searcher_client.SubscribeAccountsMempoolTransactionsPayload{
    Ctx:      context.TODO(),
    Accounts: accounts,
    Regions:  regions,
    TxCh:     make(chan *solana.Transaction),
    ErrCh:    make(chan error),
  }
  
  if err = client.SubscribeAccountsMempoolTransactions(payload); err != nil {
    log.Fatal(err)
  }

  for tx := range txSub {
    log.Println(tx)
  }
}
Get Regions
package main

import (
    "github.com/17535250630/solana-go"
    "github.com/17535250630/solana-go/rpc"
    "github.com/weeaa/jito-go"
    "github.com/weeaa/jito-go/clients/searcher_client"
    "log"
    "os"
)

func main() {
  client, err := searcher_client.NewSearcherClient(
    jito_go.NewYork.BlockEngineURL,
    rpc.New(rpc.MainNetBeta_RPC),
    solana.MustPrivateKeyFromBase58(os.Getenv("PRIVATE_KEY")),
	nil,
  )
  if err != nil {
    log.Fatal(err)
  }

  resp, err := client.GetRegions()
  if err != nil {
    log.Fatal(err)
  }

  log.Println(resp)
}
Subscribe Block Updates [Geyser]
package main

import (
	"context"
	"github.com/weeaa/jito-go/clients/geyser_client"
	"github.com/weeaa/jito-go/proto"
	"log"
)

func main() {
	rpcAddr := "myGeyserRpcNodeURL"
	
	// establish conn to geyser node...
	client, err := geyser_client.NewGeyserClient(context.Background(), rpcAddr, nil)
	if err != nil {
		log.Fatal(err)
	}
	
	// create block update sub
	sub, err := client.SubscribeBlockUpdates()
	if err != nil {
		log.Fatal(err)
	}
	// create chan to receive block updates
	ch := make(chan *proto.BlockUpdate)
	// feed the chan with block updates 
	client.OnBlockUpdates(context.Background(), sub, ch)
	
	// loop to read new block updates from chan
	for {
		block := <-ch
		log.Println(block)
	}
}

🚨 Disclaimer

This library is not affiliated with Jito Labs. It is a community project and is not officially supported by Jito Labs. Use at your own risk.

🛟 Support

If my work has been useful in building your for-profit services/infra/bots/etc, consider donating at EcrHvqa5Vh4NhR3bitRZVrdcUGr1Z3o6bXHz7xgBU2FB (SOL).

📃 License

Apache-2.0 License.

Documentation

Index

Constants

View Source
const JitoMainnet = "mainnet.rpc.jito.wtf"

Variables

View Source
var Amsterdam = JitoEndpoints["AMS"]
View Source
var Frankfurt = JitoEndpoints["FFM"]
View Source
var JitoEndpoints = map[string]JitoEndpointInfo{
	"AMS": {
		Region:            "amsterdam",
		BlockEngineURL:    "amsterdam.mainnet.block-engine.jito.wtf:443",
		RelayerURL:        "http://amsterdam.mainnet.relayer.jito.wtf:8100",
		ShredReceiverAddr: "74.118.140.240:1002",
		Ntp:               "ntp.amsterdam.jito.wtf",
	},
	"FFM": {
		Region:            "frankfurt",
		BlockEngineURL:    "frankfurt.mainnet.block-engine.jito.wtf:443",
		RelayerURL:        "http://frankfurt.mainnet.relayer.jito.wtf:8100",
		ShredReceiverAddr: "145.40.93.84:1002",
		Ntp:               "ntp.frankfurt.jito.wtf",
	},
	"NY": {
		Region:            "ny",
		BlockEngineURL:    "ny.mainnet.block-engine.jito.wtf:443",
		RelayerURL:        "http://ny.mainnet.relayer.jito.wtf:8100",
		ShredReceiverAddr: "141.98.216.96:1002",
		Ntp:               "ntp.dallas.jito.wtf",
	},
	"TKY": {
		Region:            "tokyo",
		BlockEngineURL:    "tokyo.mainnet.block-engine.jito.wtf:443",
		RelayerURL:        "http://tokyo.mainnet.relayer.jito.wtf:8100",
		ShredReceiverAddr: "202.8.9.160:1002",
		Ntp:               "ntp.tokyo.jito.wtf",
	},
	"BigD-TESTNET": {
		BlockEngineURL:    "dallas.testnet.block-engine.jito.wtf:443",
		RelayerURL:        "http://dallas.testnet.relayer.jito.wtf:8100",
		ShredReceiverAddr: "147.28.154.132:1002",
		Ntp:               "ntp.dallas.jito.wtf",
	},
	"NY-TESTNET": {
		BlockEngineURL:    "ny.testnet.block-engine.jito.wtf:443",
		RelayerURL:        "http://nyc.testnet.relayer.jito.wtf:8100",
		ShredReceiverAddr: "141.98.216.97:1002",
		Ntp:               "ntp.dallas.jito.wtf",
	},
}
View Source
var MainnetMerkleUploadAuthorityProgram = solana.MustPublicKeyFromBase58("GZctHpWXmsZC1YHACTGGcHhYxjdRqQvTpYkb9LMvxDib")
View Source
var MainnetTipAccounts = []solana.PublicKey{
	solana.MustPublicKeyFromBase58("96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5"),
	solana.MustPublicKeyFromBase58("HFqU5x63VTqvQss8hp11i4wVV8bD44PvwucfZ2bU7gRe"),
	solana.MustPublicKeyFromBase58("Cw8CFyM9FkoMi7K7Crf6HNQqf4uEMzpKw6QNghXLvLkY"),
	solana.MustPublicKeyFromBase58("ADaUMid9yfUytqMBgopwjb2DTLSokTSzL1zt6iGPaS49"),
	solana.MustPublicKeyFromBase58("DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh"),
	solana.MustPublicKeyFromBase58("ADuUkR4vqLUMWXxW9gh6D6L8pMSawimctcNZ5pGwDcEt"),
	solana.MustPublicKeyFromBase58("DttWaMuVvTiduZRnguLF7jNxTgiMBZ1hyAumKUiL2KRL"),
	solana.MustPublicKeyFromBase58("3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT"),
}
View Source
var MainnetTipDistributionProgram = solana.MustPublicKeyFromBase58("4R3gSG8BpU4t19KYj8CfnbtRpnT8gtk4dvTHxVRwc2r7")
View Source
var MainnetTipPaymentProgram = solana.MustPublicKeyFromBase58("T1pyyaTNZsKv2WcRAB8oVnk93mLJw2XzjtVYqCsaHqt")
View Source
var NewYork = JitoEndpoints["NY"]
View Source
var TestnetDallas = JitoEndpoints["BigD-TESTNET"]
View Source
var TestnetMerkleUploadAuthorityProgram = solana.MustPublicKeyFromBase58("GZctHpWXmsZC1YHACTGGcHhYxjdRqQvTpYkb9LMvxDib")
View Source
var TestnetNewYork = JitoEndpoints["NY-TESTNET"]
View Source
var TestnetTipAccounts = []solana.PublicKey{
	solana.MustPublicKeyFromBase58("B1mrQSpdeMU9gCvkJ6VsXVVoYjRGkNA7TtjMyqxrhecH"),
	solana.MustPublicKeyFromBase58("aTtUk2DHgLhKZRDjePq6eiHRKC1XXFMBiSUfQ2JNDbN"),
	solana.MustPublicKeyFromBase58("E2eSqe33tuhAHKTrwky5uEjaVqnb2T9ns6nHHUrN8588"),
	solana.MustPublicKeyFromBase58("4xgEmT58RwTNsF5xm2RMYCnR1EVukdK8a1i2qFjnJFu3"),
	solana.MustPublicKeyFromBase58("EoW3SUQap7ZeynXQ2QJ847aerhxbPVr843uMeTfc9dxM"),
	solana.MustPublicKeyFromBase58("ARTtviJkLLt6cHGQDydfo1Wyk6M4VGZdKZ2ZhdnJL336"),
	solana.MustPublicKeyFromBase58("9n3d1K5YD2vECAbRFhFFGYNNjiXtHXJWn9F31t89vsAV"),
	solana.MustPublicKeyFromBase58("9ttgPBBhRYFuQccdR1DSnb7hydsWANoDsV3P9kaGMCEh"),
}
View Source
var TestnetTipDistributionProgram = solana.MustPublicKeyFromBase58("F2Zu7QZiTYUhPd7u9ukRVwxh7B71oA3NMJcHuCHc29P2")
View Source
var TestnetTipPaymentProgram = solana.MustPublicKeyFromBase58("DCN82qDxJAQuSqHhv2BJuAgi41SPeKZB5ioBCTMNDrCC")
View Source
var Tokyo = JitoEndpoints["TKY"]

Functions

This section is empty.

Types

type JitoEndpointInfo

type JitoEndpointInfo struct {
	Region            string
	BlockEngineURL    string
	RelayerURL        string
	ShredReceiverAddr string
	Ntp               string
}

Directories

Path Synopsis
clients

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL