From 77c8c0aad31cc57c3bd7737d2daf6d9cb9c13c1a Mon Sep 17 00:00:00 2001 From: samlior Date: Tue, 3 Feb 2026 17:36:59 +0800 Subject: [PATCH] chore: add cu price --- cmd/shreder/main.go | 2 +- pkg/shreder/tx.go | 3 ++- pkg/shreder/txparser.go | 29 ++++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/cmd/shreder/main.go b/cmd/shreder/main.go index 3f6d169..7387f63 100644 --- a/cmd/shreder/main.go +++ b/cmd/shreder/main.go @@ -94,7 +94,7 @@ func main() { return case tx := <-txCh: if tx.Label == "dbot" || tx.Label == "okxdexroutev2" { - fmt.Println("===============", tx.TxHash, tx.Label,tx.Program ,tx.Event, tx.Token0Address, tx.Token1Address,"token0amount:", tx.Token0Amount, "token1amount:",tx.Token1Amount ,"parse time:", tx.ParseEnd.Sub(tx.ParseStart)) + fmt.Println("===============", tx.TxHash, tx.Label, tx.Program, tx.Event, tx.Token0Address, tx.Token1Address, "token0amount:", tx.Token0Amount, "token1amount:", tx.Token1Amount, "parse time:", tx.ParseEnd.Sub(tx.ParseStart), "cu price:", tx.CUPrice, "cu price uint64:", tx.CUPriceUint64) } } } diff --git a/pkg/shreder/tx.go b/pkg/shreder/tx.go index 571eb58..a1eec65 100644 --- a/pkg/shreder/tx.go +++ b/pkg/shreder/tx.go @@ -44,7 +44,7 @@ type TxSignal struct { IsProcessed bool `json:"is_processed"` IsToken2022 bool `json:"is_token2022"` IsMayhemMode bool `json:"is_mayhem_mode"` - TxFee decimal.Decimal `json:"tx_fee"` + CUPrice decimal.Decimal `json:"cu_price"` ExactSOL bool `json:"exact_in"` @@ -55,6 +55,7 @@ type TxSignal struct { MaxPriceImpactBps uint16 `json:"max_price_impact_bps"` // parsed values + CUPriceUint64 uint64 `json:"-"` Token0AmountUint64 uint64 `json:"-"` Token1AmountUint64 uint64 `json:"-"` diff --git a/pkg/shreder/txparser.go b/pkg/shreder/txparser.go index f98440c..bd56386 100644 --- a/pkg/shreder/txparser.go +++ b/pkg/shreder/txparser.go @@ -3,6 +3,7 @@ package shreder import ( "bytes" "context" + "encoding/binary" "fmt" "io" "math/big" @@ -92,7 +93,10 @@ func ParseTransactionForSubscribe(ctx context.Context, update *SubscribeUpdateTr } } -var VoteProgram = solana.MustPublicKeyFromBase58("Vote111111111111111111111111111111111111111") +var ( + ComputeBudgetProgram = solana.MustPublicKeyFromBase58("ComputeBudget111111111111111111111111111111") + VoteProgram = solana.MustPublicKeyFromBase58("Vote111111111111111111111111111111111111111") +) func FilterTransactionForEntries(versioned VersionedTransaction) bool { if len(versioned.Instructions) >= 1 { @@ -195,6 +199,22 @@ func ParseTransactionWithHandler(ctx context.Context, versioned VersionedTransac } } + cuPrice := decimal.Zero + cuPriceUint64 := uint64(0) + for _, instruction := range versioned.Instructions { + program, err := versioned.GetAccount(int(instruction.ProgramIDIndex)) + if err != nil { + continue + } + if program.Equals(ComputeBudgetProgram) && + len(instruction.Data) == 9 && + instruction.Data[0] == 0x03 { + cuPriceUint64 = binary.LittleEndian.Uint64(instruction.Data[1:9]) + cuPrice = formatCUPrice(cuPriceUint64) + break + } + } + for i, instruction := range versioned.Instructions { //load from address table program, err := versioned.GetAccount(int(instruction.ProgramIDIndex)) @@ -219,6 +239,8 @@ func ParseTransactionWithHandler(ctx context.Context, versioned VersionedTransac } one.Label = handler.Label one.Block = versioned.Block + one.CUPrice = cuPrice + one.CUPriceUint64 = cuPriceUint64 select { case <-ctx.Done(): return @@ -288,6 +310,11 @@ func toVersionedTransaction(update *SubscribeUpdateTransaction) (VersionedTransa return versioned, nil } +func formatCUPrice(cuPrice uint64) decimal.Decimal { + val := decimal.NewFromBigInt(new(big.Int).SetUint64(cuPrice), 0) + return val.Div(decimal.NewFromInt(1_000_000)) +} + func formatTokenAmount(amount uint64) decimal.Decimal { val := decimal.NewFromBigInt(new(big.Int).SetUint64(amount), 0) return val.Div(decimal.NewFromInt(1_000_000))