package main import ( "context" "fmt" "time" "github.com/gagliardetto/solana-go" "github.com/shopspring/decimal" parser "github.com/thloyi/pump-parser" example "github.com/thloyi/pump-parser/internal/example" ) var ( pumpProgram = solana.MustPublicKeyFromBase58("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P") pumpAmmProgram = solana.MustPublicKeyFromBase58("pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA") ) func main() { //pool, err := ants.NewPool(100, ants.WithPreAlloc(true), ants.WithNonblocking(true)) //if err != nil { // panic(err) //} //xt := tracker.NewTwitterTracker(nil) // Initialize Twitter tracker if needed // laserstream-mainnet-slc.helius-rpc.com:80 ch := make(chan example.SubscriptionMessage, 1) go example.RunLoopWithReConnect(context.Background(), "", "", parser.SolProgramPump, ch) // var tokenTxs = make(map[string]*types.Tx) // currentBlock := uint64(0) for msg := range ch { if msg.Tx == nil { block := msg.Block if block.Slot%100 == 0 { fmt.Printf("slot: %d, hash: %s, time: %s, height: %d, estimate delay second: %d\n", block.Slot, block.BlockHash, time.Unix(block.BlockTime, 0).Format("2006-01-02 15:04:05"), block.Height, msg.EstimateDelaySecond) } continue } ptx := msg.Tx // fmt.Println("consume", ptx.ComputeUnitsConsumed, "limit", ptx.CuLimit, "hash", ptx.GetTxHash()) //data, _ := json.Marshal(tx) //fmt.Println(string(data)) //continue //if tx.Token0Address != "HRHLDjqFBhNeyTXUuZQE9gTy5z2112qeQBS9U79NHyyp" { // continue //} //if currentBlock == ptx.Block { // continue //} // 处理交易 if len(ptx.Swaps) > 0 { for _, swap := range ptx.Swaps { if swap.SlippageBps.LessThan(decimal.Zero) || swap.SlippageBps.GreaterThan(decimal.NewFromInt(10000)) { fmt.Printf("success tx : %s, program: %s, event: %s, block: %d, tx: %s, base: %s, quote: %s \n", time.Now().Format("2006-01-02 15:04:05"), swap.Program, swap.Event, ptx.Block, ptx.GetTxHash(), swap.BaseAmount.Div(decimal.NewFromInt(1e6)), swap.QuoteAmount.Div(decimal.NewFromInt(1e9))) } if swap.SlippageBps.Equal(decimal.Zero) && (swap.Event == "buy" || swap.Event == "sell") { fmt.Printf("zero success tx : %s, program: %s, event: %s, block: %d, tx: %s, base: %s, quote: %s, fix: %s, limit: %s, \n", time.Now().Format("2006-01-02 15:04:05"), swap.Program, swap.Event, ptx.Block, ptx.GetTxHash(), swap.BaseAmount.Div(decimal.NewFromInt(1e6)), swap.QuoteAmount.Div(decimal.NewFromInt(1e9)), swap.FixedAmount.String(), swap.LimitAmount.String()) } } } // currentBlock = ptx.Block // //if tx.Event == "create" { // if err := pool.Submit(func() { // now := time.Now() // xt.AddToken(tx.Token) // log.Printf("Add token %s, cost: %s %s %v %v", tx.Token.Address, time.Since(now), tx.Token.Twitter, xt.DuplicateCount(tx.Token.Address), xt.HasTwitter(tx.Token.Address)) // }); err != nil { // fmt.Println(err) // } //} } }