chore: add cu price

This commit is contained in:
2026-02-03 17:36:59 +08:00
parent a0e46ec83e
commit 77c8c0aad3
3 changed files with 31 additions and 3 deletions

View File

@@ -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)
}
}
}

View File

@@ -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:"-"`

View File

@@ -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))