pump and pump swap errTx parser

This commit is contained in:
thloyi
2026-02-26 16:11:34 +08:00
parent 972ddc7960
commit b0d4342fa2
12 changed files with 704 additions and 722 deletions

View File

@@ -5,10 +5,17 @@ import (
"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 {
@@ -31,7 +38,7 @@ func main() {
continue
}
ptx := msg.Tx
fmt.Println("consume", ptx.ComputeUnitsConsumed, "limit", ptx.CuLimit, "hash", ptx.GetTxHash())
// fmt.Println("consume", ptx.ComputeUnitsConsumed, "limit", ptx.CuLimit, "hash", ptx.GetTxHash())
//data, _ := json.Marshal(tx)
//fmt.Println(string(data))
//continue
@@ -44,40 +51,9 @@ func main() {
//}
// 处理交易
txErr, ok := ptx.Err.(*parser.TransactionError)
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 {
txs := example.FromTx(ptx)
if len(txs) == 0 {
fmt.Printf("tx is empty, block: %d, tx %s \n", ptx.Block, ptx.GetTxHash())
continue
}
// printed := false
for _, tx := range txs {
if tx.Program != parser.SolProgramPumpAMM {
continue
}
//if tx.Token1Amount.GreaterThanOrEqual(decimal.NewFromFloat(0.1)) || tx.Event != "buy" {
// continue
//}
// printed = true
fmt.Printf("t: %s, block: %d, is cash:%v hash: %s, maker: %s, program: %s, event: %s, token0: %s, entryContract: %s, token balance: %s, EntryContract: %s\n",
time.Now().Format(time.RFC3339Nano),
tx.Block, tx.Cashback, tx.GetTxHash(), tx.Maker, tx.Program, tx.Event, tx.Token0Amount, tx.EntryContract, tx.AfterSignerToken0Balance, tx.EntryContract)
//break
}
//if !printed {
// continue
//}
//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)
if len(ptx.Swaps) > 0 && (ptx.Swaps[0].Program == parser.SolProgramPump || ptx.Swaps[0].Program == parser.SolProgramPumpAMM) {
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"), ptx.Swaps[0].Program, ptx.Swaps[0].Event, ptx.Block, ptx.GetTxHash(),
ptx.Swaps[0].BaseAmount.Div(decimal.NewFromInt(1e6)), ptx.Swaps[0].QuoteAmount.Div(decimal.NewFromInt(1e9)))
}
// currentBlock = ptx.Block
//

View File

@@ -3,7 +3,6 @@ package parser
import (
"fmt"
"github.com/shopspring/decimal"
types "github.com/thloyi/pump-parser"
)
@@ -23,24 +22,14 @@ func NewPumpHandler(cb func(*types.Tx)) *PumpHandler {
func (h *PumpHandler) HandleMessage(rawTx *types.RawTx) {
if rawTx.Meta.Err != nil {
// Notify the channel about the failed transaction
beforeSolBalance := decimal.Zero
afterSolBalance := decimal.Zero
if rawTx.Meta.PreBalances != nil && len(rawTx.Meta.PreBalances) > 0 {
beforeSolBalance = decimal.NewFromUint64(rawTx.Meta.PreBalances[0]).Div(decimal.NewFromInt(1e9))
var parsedTx = &types.Tx{}
parsedTx.SetRawTx(rawTx)
err := parsedTx.Parser()
if err != nil {
fmt.Printf("parser failed tx error: %s, block: %d tx: %s\n", err, rawTx.Slot, rawTx.TxHash())
return
}
if rawTx.Meta.PostBalances != nil && len(rawTx.Meta.PostBalances) > 0 {
afterSolBalance = decimal.NewFromUint64(rawTx.Meta.PostBalances[0]).Div(decimal.NewFromInt(1e9))
}
h.callback(&types.Tx{
TxHash: (*[64]byte)((rawTx.Transaction.Signatures[0][:])),
Err: rawTx.Meta.Err,
Signer: rawTx.GetSigner(),
Block: rawTx.Slot,
BlockIndex: uint64(rawTx.IndexWithinBlock),
BeforeSolBalance: beforeSolBalance,
AfterSOLBalance: afterSolBalance,
})
h.callback(parsedTx)
return
}

View File

@@ -50,19 +50,18 @@ type Client struct {
func NewClientWithPumpSwap(endpoint string, ch chan SubscriptionMessage) *Client {
var subscription pb.SubscribeRequest
var failed = false
//var failed = true
var vote = false
subscription.Transactions = make(map[string]*pb.SubscribeRequestFilterTransactions)
subscription.Transactions["transactions_sub"] = &pb.SubscribeRequestFilterTransactions{
Failed: &failed,
Vote: &vote,
//Failed: &failed,
Vote: &vote,
}
subscription.Transactions["transactions_sub"].AccountInclude = []string{
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA", //Pump AMM
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P", //Pump
}
subscription.BlocksMeta = make(map[string]*pb.SubscribeRequestFilterBlocksMeta)
subscription.BlocksMeta["block_meta"] = &pb.SubscribeRequestFilterBlocksMeta{}
@@ -83,12 +82,12 @@ func NewClientWithPumpSwap(endpoint string, ch chan SubscriptionMessage) *Client
func NewClientWithLaunchLab(endpoint string, ch chan SubscriptionMessage) *Client {
var subscription pb.SubscribeRequest
var failed = false
//var failed = false
var vote = false
subscription.Transactions = make(map[string]*pb.SubscribeRequestFilterTransactions)
subscription.Transactions["transactions_sub"] = &pb.SubscribeRequestFilterTransactions{
Failed: &failed,
Vote: &vote,
//Failed: &failed,
Vote: &vote,
}
subscription.Transactions["transactions_sub"].AccountInclude = []string{