Files

86 lines
3.2 KiB
Go
Raw Permalink Normal View History

2025-11-20 17:56:45 +08:00
package main
import (
"context"
"fmt"
"time"
2026-02-26 16:11:34 +08:00
"github.com/gagliardetto/solana-go"
"github.com/shopspring/decimal"
2025-11-20 17:56:45 +08:00
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
)
2026-02-26 16:11:34 +08:00
var (
pumpProgram = solana.MustPublicKeyFromBase58("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P")
pumpAmmProgram = solana.MustPublicKeyFromBase58("pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA")
)
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)
2026-05-18 11:46:49 +08:00
go example.RunLoopWithReConnect(context.Background(), "ams.rpc.orbitflare.com:10000", "ORBIT-EPUZGQ-177605-508881", 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-26 16:11:34 +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
// 处理交易
2026-04-20 12:31:30 +08:00
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())
}
}
2026-04-20 15:09:42 +08:00
if len(ptx.Swaps) > 0 {
_, err := parser.EncodeTxBinary(ptx)
if err != nil {
fmt.Printf("success tx : %s, , block: %d, tx: %s, err: %s \n", time.Now().Format("2006-01-02 15:04:05"), ptx.Block, ptx.GetTxHash(), err.Error())
}
}
2026-04-20 12:31:30 +08:00
2025-11-20 17:56:45 +08:00
}
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)
// }
//}
}
}