Skip to content

17535250630/jito_cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages