Files
libsam/cmd/shreder/main.go
2026-01-07 21:15:54 +08:00

105 lines
2.3 KiB
Go

package main
import (
"context"
"errors"
"fmt"
"log/slog"
"os"
"os/signal"
"syscall"
"github.com/gagliardetto/solana-go/rpc"
"github.com/samlior/libsam/pkg/shreder"
)
func main() {
url := os.Getenv("URL")
if url == "" {
panic("URL is not set")
}
rpcUrl := os.Getenv("RPC_URL")
if rpcUrl == "" {
panic("RPC_URL is not set")
}
rpcClient := rpc.New(rpcUrl)
shreder.SetLogLevel(slog.LevelDebug)
shrederClient, cleanup, err := shreder.NewShrederClient(
url,
rpcClient,
map[string]*shreder.SubscribeRequestFilterTransactions{
"pumpfunamm": {
//AccountRequired: []string{
// "pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA",
//},
AccountInclude: []string{
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA",
"GS4CU59F31iL7aR2Q8zVS8DRrcRnXX1yjQ66TqNVQnaR", //Event Authority
"5PHirr8joyTMp9JMm6nW7hNDVyEYdkzDqazxPD7RaTjx", // Fee Config
"pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ", // pump fee program
},
},
"photon": {
AccountRequired: []string{
"BSfD6SHZigAfDWSjzD5Q41jw8LmKwtmjskPH9XW1mrRW",
},
},
"jupiterV6": {
AccountRequired: []string{
"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",
},
},
"okxdexroutev2": {
AccountRequired: []string{
"proVF4pMXVaYqmy4NjniPh4pqKNfMmsihgd4wdkCX3u",
},
},
"dflow": {
AccountRequired: []string{
"DF1ow4tspfHX9JwWJsAb9epbkA8hmpSEAtxXy1V27QBH",
},
},
// TODO: axiom, gmgn, etc.
})
if err != nil {
panic(err)
}
defer cleanup()
exitSignal := make(chan os.Signal, 1)
ctx, cancel := context.WithCancel(context.Background())
signal.Notify(exitSignal, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-exitSignal
cancel()
}()
shrederClient.EnableClientStats = true
// async read from shreder
txCh := make(chan shreder.TxSignalBatch, 1000)
go func() {
err := shrederClient.ReadSync(ctx, txCh)
if err != nil {
if !errors.Is(err, context.Canceled) {
panic(err)
}
}
}()
for {
select {
case <-ctx.Done():
return
case txBatch := <-txCh:
//jsonData, _ := json.MarshalIndent(txBatch, "", " ")
for _, tx := range txBatch {
if tx.Label == "okxdexroutev2" {
fmt.Println("===============", tx.TxHash, tx.Label, tx.Event, tx.Token0Address, "token:", tx.Token0Amount, "parse time:", tx.ParseEnd.Sub(tx.ParseStart))
}
}
//fmt.Println(txBatch[0].TxHash)
}
}
}