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", }, }, // 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() }() // 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 == "flas" { if tx.Event == "buy" { fmt.Println("===============", tx.TxHash, tx.Program, tx.Event, tx.Token0Address, "token:", tx.Token0Amount, "sol:", tx.Token1Amount) } else if tx.Event == "sell" { fmt.Println("===============", tx.TxHash, tx.Program, tx.Event, tx.Token0Address, "token:", tx.Token0Amount) } } } //fmt.Println(txBatch[0].TxHash) } } }