chore: add parse swqos logic

This commit is contained in:
2026-02-05 14:32:24 +08:00
parent 77c8c0aad3
commit db9e2b33cb
5 changed files with 300 additions and 6 deletions

View File

@@ -45,6 +45,8 @@ type TxSignal struct {
IsToken2022 bool `json:"is_token2022"`
IsMayhemMode bool `json:"is_mayhem_mode"`
CUPrice decimal.Decimal `json:"cu_price"`
SWQoSAgent string `json:"swqos_agent"`
SWQoSTips decimal.Decimal `json:"swqos_tips"`
ExactSOL bool `json:"exact_in"`
@@ -55,7 +57,6 @@ type TxSignal struct {
MaxPriceImpactBps uint16 `json:"max_price_impact_bps"`
// parsed values
CUPriceUint64 uint64 `json:"-"`
Token0AmountUint64 uint64 `json:"-"`
Token1AmountUint64 uint64 `json:"-"`

View File

@@ -11,6 +11,7 @@ import (
"strings"
"github.com/gagliardetto/solana-go"
"github.com/samlior/libsam/v2/pkg/consts"
"github.com/shopspring/decimal"
)
@@ -200,7 +201,8 @@ func ParseTransactionWithHandler(ctx context.Context, versioned VersionedTransac
}
cuPrice := decimal.Zero
cuPriceUint64 := uint64(0)
swqosAgent := ""
swqosTips := decimal.Zero
for _, instruction := range versioned.Instructions {
program, err := versioned.GetAccount(int(instruction.ProgramIDIndex))
if err != nil {
@@ -209,9 +211,27 @@ func ParseTransactionWithHandler(ctx context.Context, versioned VersionedTransac
if program.Equals(ComputeBudgetProgram) &&
len(instruction.Data) == 9 &&
instruction.Data[0] == 0x03 {
cuPriceUint64 = binary.LittleEndian.Uint64(instruction.Data[1:9])
cuPriceUint64 := binary.LittleEndian.Uint64(instruction.Data[1:9])
cuPrice = formatCUPrice(cuPriceUint64)
break
}
if program.Equals(solana.SystemProgramID) &&
len(instruction.Data) == 12 &&
instruction.Data[0] == 0x02 &&
instruction.Data[1] == 0x00 &&
instruction.Data[2] == 0x00 &&
instruction.Data[3] == 0x00 &&
len(instruction.Accounts) >= 2 {
destination, err := versioned.GetAccount(int(instruction.Accounts[1]))
if err != nil {
continue
}
var ok bool
swqosAgent, ok = consts.SWQoSFeeAddresses2Pubkeys[destination]
if !ok {
continue
}
swqosTipsUint64 := binary.LittleEndian.Uint64(instruction.Data[4:12])
swqosTips = formatSolAmount(swqosTipsUint64)
}
}
@@ -240,7 +260,8 @@ func ParseTransactionWithHandler(ctx context.Context, versioned VersionedTransac
one.Label = handler.Label
one.Block = versioned.Block
one.CUPrice = cuPrice
one.CUPriceUint64 = cuPriceUint64
one.SWQoSAgent = swqosAgent
one.SWQoSTips = swqosTips
select {
case <-ctx.Done():
return