Files

102 lines
2.8 KiB
Go
Raw Permalink Normal View History

2025-12-26 10:57:37 +08:00
package main
2025-12-26 11:34:45 +08:00
import (
"context"
"errors"
"fmt"
2026-01-05 12:45:32 +08:00
"log/slog"
2025-12-26 11:34:45 +08:00
"os"
"os/signal"
"syscall"
2026-01-05 12:45:32 +08:00
"github.com/gagliardetto/solana-go/rpc"
2026-01-28 14:11:34 +08:00
"github.com/samlior/libsam/v2/pkg/shreder"
2025-12-26 11:34:45 +08:00
)
2025-12-26 10:57:37 +08:00
func main() {
2025-12-26 11:34:45 +08:00
url := os.Getenv("URL")
if url == "" {
panic("URL is not set")
}
2026-01-05 12:45:32 +08:00
rpcUrl := os.Getenv("RPC_URL")
if rpcUrl == "" {
panic("RPC_URL is not set")
}
rpcClient := rpc.New(rpcUrl)
shreder.SetLogLevel(slog.LevelDebug)
2026-01-30 11:45:57 +08:00
//handlers := shreder.GetRegisteredHandlers()
2025-12-26 11:34:45 +08:00
shrederClient, cleanup, err := shreder.NewShrederClient(
url,
2026-01-05 12:45:32 +08:00
rpcClient,
2025-12-30 11:03:11 +08:00
map[string]*shreder.SubscribeRequestFilterTransactions{
2025-12-26 11:34:45 +08:00
"pumpfunamm": {
2026-01-05 12:45:32 +08:00
//AccountRequired: []string{
// "pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA",
//},
AccountInclude: []string{
2025-12-26 11:34:45 +08:00
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA",
2026-01-05 12:45:32 +08:00
"GS4CU59F31iL7aR2Q8zVS8DRrcRnXX1yjQ66TqNVQnaR", //Event Authority
"5PHirr8joyTMp9JMm6nW7hNDVyEYdkzDqazxPD7RaTjx", // Fee Config
2026-01-06 16:42:07 +08:00
"pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ", // pump fee program
2025-12-26 11:34:45 +08:00
},
},
"photon": {
AccountRequired: []string{
"BSfD6SHZigAfDWSjzD5Q41jw8LmKwtmjskPH9XW1mrRW",
},
},
2026-01-06 16:42:07 +08:00
"jupiterV6": {
AccountRequired: []string{
"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",
},
},
2026-01-07 15:39:32 +08:00
"okxdexroutev2": {
AccountRequired: []string{
"proVF4pMXVaYqmy4NjniPh4pqKNfMmsihgd4wdkCX3u",
},
},
2026-01-30 11:45:57 +08:00
2025-12-26 11:34:45 +08:00
// TODO: axiom, gmgn, etc.
2026-01-30 11:45:57 +08:00
},
//shreder.WithCustomParsers(map[solana.PublicKey]shreder.Handler{
// solana.MustPublicKeyFromBase58("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"): handlers[solana.MustPublicKeyFromBase58("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4")],
// solana.MustPublicKeyFromBase58("proVF4pMXVaYqmy4NjniPh4pqKNfMmsihgd4wdkCX3u"): handlers[solana.MustPublicKeyFromBase58("proVF4pMXVaYqmy4NjniPh4pqKNfMmsihgd4wdkCX3u")],
//}),
shreder.BlocksStats(false), shreder.LogParsedStats(true), shreder.ShowTableLoaded(false))
2025-12-26 11:34:45 +08:00
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()
}()
// async read from shreder
2026-01-28 14:11:34 +08:00
txCh := make(chan shreder.TxSignal, 1000)
2025-12-26 11:34:45 +08:00
go func() {
2026-01-28 14:11:34 +08:00
err := shrederClient.ReadEntriesSync(ctx, txCh)
2025-12-26 11:34:45 +08:00
if err != nil {
if !errors.Is(err, context.Canceled) {
panic(err)
}
}
}()
for {
select {
case <-ctx.Done():
return
2026-01-28 14:11:34 +08:00
case tx := <-txCh:
2026-02-02 15:39:05 +08:00
if tx.Label == "dbot" || tx.Label == "okxdexroutev2" {
2026-02-05 14:32:24 +08:00
fmt.Println("===============", tx.TxHash, tx.Label, tx.Program, tx.Event, tx.Token0Address, tx.Token1Address, "token0amount:", tx.Token0Amount, "token1amount:", tx.Token1Amount, "parse time:", tx.ParseEnd.Sub(tx.ParseStart), "cu price:", tx.CUPrice, "swqos agent:", tx.SWQoSAgent, "swqos tips:", tx.SWQoSTips)
2026-01-06 16:42:07 +08:00
}
2025-12-26 11:34:45 +08:00
}
}
2025-12-26 10:57:37 +08:00
}