Files
libsam/cmd/shreder/main.go

113 lines
3.0 KiB
Go
Raw 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-23 17:58:59 +08:00
"time"
2025-12-26 11:34:45 +08:00
2026-01-05 12:45:32 +08:00
"github.com/gagliardetto/solana-go/rpc"
2026-01-23 17:58:59 +08:00
"github.com/shopspring/decimal"
2026-01-05 12:45:32 +08:00
2025-12-26 11:34:45 +08:00
"github.com/samlior/libsam/pkg/shreder"
)
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)
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-07 18:02:45 +08:00
"dflow": {
AccountRequired: []string{
"DF1ow4tspfHX9JwWJsAb9epbkA8hmpSEAtxXy1V27QBH",
},
},
2025-12-26 11:34:45 +08:00
// TODO: axiom, gmgn, etc.
2026-01-08 11:57:57 +08:00
}, 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-23 17:58:59 +08:00
txCh := make(chan shreder.TxSignal, 1000)
2025-12-26 11:34:45 +08:00
go func() {
2026-01-23 17:58:59 +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-23 17:58:59 +08:00
case tx := <-txCh:
2026-01-05 12:45:32 +08:00
//jsonData, _ := json.MarshalIndent(txBatch, "", " ")
2026-01-23 17:58:59 +08:00
if tx.Token0Amount.GreaterThan(decimal.NewFromInt(100)) && (tx.Label == "okxdexroutev2" || tx.Label == "jupiterv6" || tx.Label == "dflow") {
fmt.Println(time.Now(), "===============", tx.TxHash,
"parse time:", tx.Stats.Done.Sub(tx.Stats.Filter),
"decode time:", tx.Stats.Decoded.Sub(tx.Stats.FEC),
"filter time:", tx.Stats.Filter.Sub(tx.Stats.Decoded),
"dataLen", tx.Stats.DataLen, "txCount", tx.Stats.TxCount, "txOffset", tx.Stats.TxOffset, tx.Label, tx.Event, "token:", tx.Token0Amount)
2026-01-06 16:42:07 +08:00
}
2026-01-23 17:58:59 +08:00
//if tx.Token0Amount.GreaterThan(decimal.NewFromInt(100)) && (tx.Label == "okxdexroutev2" || tx.Label == "jupiterv6" || tx.Label == "dflow") {
// fmt.Println(time.Now(), "===============", tx.TxHash,
// tx.Label, tx.Event, "token:", tx.Token0Amount)
//}
2026-01-06 16:42:07 +08:00
//fmt.Println(txBatch[0].TxHash)
2025-12-26 11:34:45 +08:00
}
}
2025-12-26 10:57:37 +08:00
}