Files
pump-parser/internal/example/cmd/main.go

98 lines
3.6 KiB
Go
Raw Normal View History

2025-11-20 17:56:45 +08:00
package main
import (
"context"
"fmt"
"time"
parser "github.com/thloyi/pump-parser"
2025-12-22 17:56:40 +08:00
example "github.com/thloyi/pump-parser/internal/example"
2025-11-20 17:56:45 +08:00
)
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
2025-12-22 17:56:40 +08:00
ch := make(chan example.SubscriptionMessage, 1)
go example.RunLoopWithReConnect(context.Background(), "127.0.0.1:10001", parser.SolProgramPump, ch)
2025-11-20 17:56:45 +08:00
// var tokenTxs = make(map[string]*types.Tx)
2025-11-24 17:47:56 +08:00
// currentBlock := uint64(0)
2025-11-20 17:56:45 +08:00
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
2026-02-12 10:11:29 +08:00
fmt.Println("consume", ptx.ComputeUnitsConsumed, "limit", ptx.CuLimit, "hash", ptx.GetTxHash())
2025-11-20 17:56:45 +08:00
//data, _ := json.Marshal(tx)
//fmt.Println(string(data))
//continue
//if tx.Token0Address != "HRHLDjqFBhNeyTXUuZQE9gTy5z2112qeQBS9U79NHyyp" {
// continue
//}
2025-11-24 17:47:56 +08:00
//if currentBlock == ptx.Block {
// continue
//}
2025-11-20 17:56:45 +08:00
// 处理交易
2025-12-22 17:56:40 +08:00
txErr, ok := ptx.Err.(*parser.TransactionError)
2025-11-20 17:56:45 +08:00
var customerErrCode uint32
var instructorErrIndex uint8
if ok {
instructorErrIndex, customerErrCode, _ = txErr.GetCustomErrorCode()
fmt.Printf("now: %s, block: %d, tx: %s, errInstr Code: %d, errInstrIndex: %d, err: %v\n", time.Now().Format("2006-01-02 15:04:05"), ptx.Block, ptx.GetTxHash(), customerErrCode, instructorErrIndex, ptx.Err)
} else {
2025-11-21 12:01:44 +08:00
txs := example.FromTx(ptx)
2025-11-20 17:56:45 +08:00
if len(txs) == 0 {
fmt.Printf("tx is empty, block: %d, tx %s \n", ptx.Block, ptx.GetTxHash())
continue
}
2025-12-31 16:53:39 +08:00
// printed := false
2025-11-20 17:56:45 +08:00
for _, tx := range txs {
2025-12-31 16:53:39 +08:00
if tx.Program != parser.SolProgramPumpAMM {
continue
}
if tx.EntryContract == "" || tx.EntryContract == parser.SolProgramPumpAMM || tx.EntryContract == parser.EntryContractOKXDexRouterV2 || tx.EntryContract == "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr" {
continue
}
2025-12-22 17:56:40 +08:00
//if tx.Token1Amount.GreaterThanOrEqual(decimal.NewFromFloat(0.1)) || tx.Event != "buy" {
// continue
//}
2025-12-31 16:53:39 +08:00
// printed = true
fmt.Printf("t: %s, block: %d, hash: %s, maker: %s, program: %s, event: %s, token0: %s, entryContract: %s, token balance: %s, EntryContract: %s\n",
2025-11-20 17:56:45 +08:00
time.Now().Format(time.RFC3339Nano),
2025-12-31 16:53:39 +08:00
tx.Block, tx.GetTxHash(), tx.Maker, tx.Program, tx.Event, tx.Token0Amount, tx.EntryContract, tx.AfterSignerToken0Balance, tx.EntryContract)
2025-11-24 17:47:56 +08:00
//break
2025-11-20 17:56:45 +08:00
}
2025-12-31 16:53:39 +08:00
//if !printed {
// continue
//}
2025-11-20 17:56:45 +08:00
//fmt.Printf("t: %s, block: %d, hash: %s, signer: %s, program: %s, event: %s, token0: %s, token1: %s, signer before sol :%s, after sol: %s, after token: %s, tokencreator: %s, tokenprogram: %s, mayhem: %t\n",
// time.Now().Format(time.RFC3339Nano),
// tx.Block, tx.GetTxHash(), tx.Maker, tx.Program, tx.Event, tx.Token0Amount.String(), tx.Token1Amount.String(),
// tx.BeforeSolBalance, tx.AfterSOLBalance, tx.AfterSignerToken0Balance, tx.TokenCreator, tx.Token0Program, tx.Mayhem)
}
2025-11-24 17:47:56 +08:00
// currentBlock = ptx.Block
2025-11-20 17:56:45 +08:00
//
//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)
// }
//}
}
}