Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d3f46ebbf |
@@ -14,6 +14,7 @@ import (
|
|||||||
type AddressTables struct {
|
type AddressTables struct {
|
||||||
rpcClient *rpc.Client
|
rpcClient *rpc.Client
|
||||||
mux sync.RWMutex
|
mux sync.RWMutex
|
||||||
|
loadMux sync.Mutex
|
||||||
tables *lru.Cache[solana.PublicKey, []solana.PublicKey]
|
tables *lru.Cache[solana.PublicKey, []solana.PublicKey]
|
||||||
loading map[solana.PublicKey]struct{}
|
loading map[solana.PublicKey]struct{}
|
||||||
|
|
||||||
@@ -60,32 +61,34 @@ func (at *AddressTables) GetAddressTable(tablePubkey solana.PublicKey, idx []uin
|
|||||||
if !ok {
|
if !ok {
|
||||||
at.mux.RUnlock()
|
at.mux.RUnlock()
|
||||||
_ = at.pool.Submit(func() {
|
_ = at.pool.Submit(func() {
|
||||||
at.mux.RLock()
|
at.loadMux.Lock()
|
||||||
_, loading := at.loading[tablePubkey]
|
_, loading := at.loading[tablePubkey]
|
||||||
if loading {
|
if loading {
|
||||||
at.mux.RUnlock()
|
at.loadMux.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
at.mux.RUnlock()
|
|
||||||
at.mux.Lock()
|
|
||||||
at.loading[tablePubkey] = struct{}{}
|
at.loading[tablePubkey] = struct{}{}
|
||||||
at.mux.Unlock()
|
at.loadMux.Unlock()
|
||||||
|
|
||||||
table, err := at.loadAddressTable(tablePubkey)
|
table, err := at.loadAddressTable(tablePubkey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("loadAddressTable failed", "err", err, "table", tablePubkey)
|
logger.Error("loadAddressTable failed", "err", err, "table", tablePubkey)
|
||||||
at.mux.Lock()
|
at.loadMux.Lock()
|
||||||
delete(at.loading, tablePubkey)
|
delete(at.loading, tablePubkey)
|
||||||
at.mux.Unlock()
|
at.loadMux.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
at.loadMux.Lock()
|
||||||
|
delete(at.loading, tablePubkey)
|
||||||
|
at.loadMux.Unlock()
|
||||||
|
|
||||||
at.mux.Lock()
|
at.mux.Lock()
|
||||||
at.tables.Add(tablePubkey, table)
|
at.tables.Add(tablePubkey, table)
|
||||||
total := at.tables.Len()
|
total := at.tables.Len()
|
||||||
delete(at.loading, tablePubkey)
|
|
||||||
at.mux.Unlock()
|
at.mux.Unlock()
|
||||||
logger.Info("loadAddressTable", "table", tablePubkey.String(), "table count:", total)
|
logger.Info("loadAddressTable", "table", tablePubkey.String(), "table count:", total)
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
at.mux.RUnlock()
|
at.mux.RUnlock()
|
||||||
@@ -93,6 +96,8 @@ func (at *AddressTables) GetAddressTable(tablePubkey solana.PublicKey, idx []uin
|
|||||||
var result solana.PublicKeySlice = make([]solana.PublicKey, 0, len(idx))
|
var result solana.PublicKeySlice = make([]solana.PublicKey, 0, len(idx))
|
||||||
for _, i := range idx {
|
for _, i := range idx {
|
||||||
if int(i) >= len(addresses) {
|
if int(i) >= len(addresses) {
|
||||||
|
logger.Error("over loadAddressTable failed", "idx", i, "table", tablePubkey)
|
||||||
|
//todo... update table?
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result = append(result, addresses[i])
|
result = append(result, addresses[i])
|
||||||
|
|||||||
@@ -819,26 +819,43 @@ func decodeJupiterV6SharedAccountsRouteV2Arg(data []byte) (*JupiterV6SharedAccou
|
|||||||
return &JupiterV6SharedAccountsRouteV2Arg{ID: id, In: inAmt, QuotedOut: quotedOut, Slippage: slippage, PlatFee: pf, PosSlip: pos, RoutePlan: plan}, nil
|
return &JupiterV6SharedAccountsRouteV2Arg{ID: id, In: inAmt, QuotedOut: quotedOut, Slippage: slippage, PlatFee: pf, PosSlip: pos, RoutePlan: plan}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func pumpSwapSellAtIdx0(amount uint64, plan []RoutePlanStep) uint64 {
|
func pumpSwapSellAtIdx0(amount uint64, plan []RoutePlanStep) (uint64, int) {
|
||||||
var ret uint64
|
var (
|
||||||
|
ret uint64
|
||||||
|
i int
|
||||||
|
)
|
||||||
for _, step := range plan {
|
for _, step := range plan {
|
||||||
if step.InputIdx == 0 &&
|
if step.InputIdx == 0 &&
|
||||||
(step.Swap.Kind == PumpSwapSell || step.Swap.Kind == PumpSwapSellV2 || step.Swap.Kind == PumpSwapSellV3) {
|
(step.Swap.Kind == PumpSwapSell || step.Swap.Kind == PumpSwapSellV2 || step.Swap.Kind == PumpSwapSellV3) {
|
||||||
|
i++
|
||||||
|
if ret > 0 {
|
||||||
|
// multiple pumpSwapSell at inputIdx=0? should not happen
|
||||||
|
return 0, i
|
||||||
|
}
|
||||||
ret += amount * uint64(step.Percent) / 100
|
ret += amount * uint64(step.Percent) / 100
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret
|
return ret, i
|
||||||
}
|
}
|
||||||
|
|
||||||
func pumpSwapSellAtIdx0V2(amount uint64, plan []RoutePlanStepV2) uint64 {
|
func pumpSwapSellAtIdx0V2(amount uint64, plan []RoutePlanStepV2) (uint64, int) {
|
||||||
var ret uint64
|
var (
|
||||||
|
ret uint64
|
||||||
|
i int
|
||||||
|
)
|
||||||
for _, step := range plan {
|
for _, step := range plan {
|
||||||
if step.InputIdx == 0 &&
|
if step.InputIdx == 0 &&
|
||||||
(step.Swap.Kind == PumpSwapSell || step.Swap.Kind == PumpSwapSellV2 || step.Swap.Kind == PumpSwapSellV3) {
|
(step.Swap.Kind == PumpSwapSell || step.Swap.Kind == PumpSwapSellV2 || step.Swap.Kind == PumpSwapSellV3) {
|
||||||
|
i++
|
||||||
|
if ret > 0 {
|
||||||
|
// multiple pumpSwapSell at inputIdx=0? should not happen
|
||||||
|
|
||||||
|
return 0, i
|
||||||
|
}
|
||||||
ret += amount * uint64(step.Bps) / 10000
|
ret += amount * uint64(step.Bps) / 10000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret
|
return ret, i
|
||||||
}
|
}
|
||||||
|
|
||||||
// only decodes inputIdx = 0 container pumpSwap instructions for now
|
// only decodes inputIdx = 0 container pumpSwap instructions for now
|
||||||
@@ -861,6 +878,7 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
var (
|
var (
|
||||||
sourceMint solana.PublicKey
|
sourceMint solana.PublicKey
|
||||||
inputAmount uint64
|
inputAmount uint64
|
||||||
|
planCount int
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -872,34 +890,34 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
inputAmount = pumpSwapSellAtIdx0V2(args.In, args.Plan)
|
inputAmount, planCount = pumpSwapSellAtIdx0V2(args.In, args.Plan)
|
||||||
|
|
||||||
case bytes.Equal(disc, jupiterSharedAccountsRouteV2):
|
case bytes.Equal(disc, jupiterSharedAccountsRouteV2):
|
||||||
args, err := decodeJupiterV6SharedAccountsRouteV2Arg(instruction.Data[8:])
|
args, err := decodeJupiterV6SharedAccountsRouteV2Arg(instruction.Data[8:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
inputAmount = pumpSwapSellAtIdx0V2(args.In, args.RoutePlan)
|
inputAmount, planCount = pumpSwapSellAtIdx0V2(args.In, args.RoutePlan)
|
||||||
|
|
||||||
case bytes.Equal(disc, jupiterRoute):
|
case bytes.Equal(disc, jupiterRoute):
|
||||||
args, err := decodeJupiterV6RouteArg(instruction.Data[8:])
|
args, err := decodeJupiterV6RouteArg(instruction.Data[8:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
_ = args
|
_ = args
|
||||||
inputAmount = pumpSwapSellAtIdx0(args.In, args.Plan)
|
inputAmount, planCount = pumpSwapSellAtIdx0(args.In, args.Plan)
|
||||||
|
|
||||||
case bytes.Equal(disc, jupiterSharedAccountsRoute):
|
case bytes.Equal(disc, jupiterSharedAccountsRoute):
|
||||||
args, err := decodeJupiterV6SharedAccountsRouteArg(instruction.Data[8:])
|
args, err := decodeJupiterV6SharedAccountsRouteArg(instruction.Data[8:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
_ = args
|
_ = args
|
||||||
inputAmount = pumpSwapSellAtIdx0(args.In, args.Plan)
|
inputAmount, planCount = pumpSwapSellAtIdx0(args.In, args.Plan)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
if planCount > 1 {
|
||||||
|
// multiple pumpSwapSell at inputIdx=0? should not happen
|
||||||
|
logger.Warn("pumpSwapSell at inputIdx=0: multiple instances found", "tx", tx.Signatures[0].String(), "planCount", planCount)
|
||||||
|
}
|
||||||
if inputAmount == 0 {
|
if inputAmount == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -913,6 +931,40 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
srcIdx uint8
|
||||||
|
)
|
||||||
|
for i, acctIdx := range instruction.Accounts {
|
||||||
|
if i < 9 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if key.Equals(pumpAmmProgramID) {
|
||||||
|
srcIdx = uint8(i + 4)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if srcIdx == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceMint, err = getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx+1]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !quoteMint.Equals(solana.WrappedSol) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
} else if bytes.Equal(disc, jupiterSharedAccountsRoute) {
|
} else if bytes.Equal(disc, jupiterSharedAccountsRoute) {
|
||||||
if len(instruction.Accounts) < 12 {
|
if len(instruction.Accounts) < 12 {
|
||||||
return nil, fmt.Errorf("not enough accounts for jupiter v6 jupiterSharedAccountsRoute instruction")
|
return nil, fmt.Errorf("not enough accounts for jupiter v6 jupiterSharedAccountsRoute instruction")
|
||||||
@@ -921,6 +973,38 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
var (
|
||||||
|
srcIdx uint8
|
||||||
|
)
|
||||||
|
for i, acctIdx := range instruction.Accounts {
|
||||||
|
if i < 12 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if key.Equals(pumpAmmProgramID) {
|
||||||
|
srcIdx = uint8(i + 4)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if srcIdx == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceMint, err = getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx+1]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !quoteMint.Equals(solana.WrappedSol) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(instruction.Accounts) < 10 {
|
if len(instruction.Accounts) < 10 {
|
||||||
return nil, fmt.Errorf("not enough accounts for jupiter v6 jupiterRoute instruction")
|
return nil, fmt.Errorf("not enough accounts for jupiter v6 jupiterRoute instruction")
|
||||||
@@ -930,7 +1014,7 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
)
|
)
|
||||||
|
|
||||||
for i, acctIdx := range instruction.Accounts {
|
for i, acctIdx := range instruction.Accounts {
|
||||||
if i <= 9 {
|
if i < 9 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||||
@@ -949,11 +1033,12 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
distMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx+1]))
|
|
||||||
|
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx+1]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !distMint.Equals(solana.WrappedSol) {
|
if !quoteMint.Equals(solana.WrappedSol) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gagliardetto/solana-go"
|
"github.com/gagliardetto/solana-go"
|
||||||
"github.com/mr-tron/base58"
|
"github.com/mr-tron/base58"
|
||||||
@@ -238,6 +239,7 @@ func ParseTransaction(update *SubscribeUpdateTransaction, loader *AddressTables)
|
|||||||
staticKeys = append(staticKeys, accounts...)
|
staticKeys = append(staticKeys, accounts...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
versioned.Message.StaticAccountKeys = staticKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
var parsed []*TxSignal
|
var parsed []*TxSignal
|
||||||
@@ -280,9 +282,9 @@ func ParseTransaction(update *SubscribeUpdateTransaction, loader *AddressTables)
|
|||||||
case terminalProgramID:
|
case terminalProgramID:
|
||||||
txRes, err := parseTermInstruction(versioned, i)
|
txRes, err := parseTermInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "terminal")
|
parsed = appendParsed(parsed, txRes, err, txHash, "terminal")
|
||||||
//case jupiterV6ProgramID:
|
case jupiterV6ProgramID:
|
||||||
// txRes, err := parseJupiterV6Instruction(versioned, i)
|
txRes, err := parseJupiterV6Instruction(versioned, i)
|
||||||
// parsed = appendParsed(parsed, txRes, err, txHash, "jupiterv6")
|
parsed = appendParsed(parsed, txRes, err, txHash, "jupiterv6")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,10 +293,9 @@ func ParseTransaction(update *SubscribeUpdateTransaction, loader *AddressTables)
|
|||||||
|
|
||||||
func appendParsed(list []*TxSignal, parsed *TxSignal, err error, txHash [64]byte, label string) []*TxSignal {
|
func appendParsed(list []*TxSignal, parsed *TxSignal, err error, txHash [64]byte, label string) []*TxSignal {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//if errors.Is(err, &AccountNotFoundError{}) {
|
if !strings.HasPrefix(err.Error(), "account index") {
|
||||||
//
|
logger.Debug("txparser: failed to parse", "label", label, "instruction", err, "tx_hash", base58.Encode(txHash[:]))
|
||||||
//}
|
}
|
||||||
logger.Debug("txparser: failed to parse", "label", label, "instruction", err, "tx_hash", base58.Encode(txHash[:]))
|
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
if parsed != nil {
|
if parsed != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user