chore: add parse swqos logic
This commit is contained in:
@@ -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:"-"`
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user