GithubHelp home page GithubHelp logo

charles-chenzz / jito-go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from weeaa/jito-go

0.0 1.0 0.0 313 KB

๐Ÿช™ Jito Go SDK [unnoficial]

Home Page: https://www.jito.wtf

License: Apache License 2.0

Shell 0.76% Go 98.33% Batchfile 0.91%

jito-go's Introduction

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 1.21 or higher

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/gagliardetto/solana-go"
  "github.com/gagliardetto/solana-go/programs/system"
  "github.com/gagliardetto/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/gagliardetto/solana-go"
    "github.com/gagliardetto/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/gagliardetto/solana-go"
    "github.com/gagliardetto/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.

jito-go's People

Contributors

weeaa avatar kidknot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.