juptierv6
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
type AddressTables struct {
|
||||
rpcClient *rpc.Client
|
||||
mux sync.RWMutex
|
||||
loadMux sync.Mutex
|
||||
tables *lru.Cache[solana.PublicKey, []solana.PublicKey]
|
||||
loading map[solana.PublicKey]struct{}
|
||||
|
||||
@@ -60,32 +61,34 @@ func (at *AddressTables) GetAddressTable(tablePubkey solana.PublicKey, idx []uin
|
||||
if !ok {
|
||||
at.mux.RUnlock()
|
||||
_ = at.pool.Submit(func() {
|
||||
at.mux.RLock()
|
||||
at.loadMux.Lock()
|
||||
_, loading := at.loading[tablePubkey]
|
||||
if loading {
|
||||
at.mux.RUnlock()
|
||||
at.loadMux.Unlock()
|
||||
return
|
||||
}
|
||||
at.mux.RUnlock()
|
||||
at.mux.Lock()
|
||||
at.loading[tablePubkey] = struct{}{}
|
||||
at.mux.Unlock()
|
||||
at.loadMux.Unlock()
|
||||
|
||||
table, err := at.loadAddressTable(tablePubkey)
|
||||
if err != nil {
|
||||
logger.Error("loadAddressTable failed", "err", err, "table", tablePubkey)
|
||||
at.mux.Lock()
|
||||
at.loadMux.Lock()
|
||||
delete(at.loading, tablePubkey)
|
||||
at.mux.Unlock()
|
||||
at.loadMux.Unlock()
|
||||
return
|
||||
}
|
||||
at.loadMux.Lock()
|
||||
delete(at.loading, tablePubkey)
|
||||
at.loadMux.Unlock()
|
||||
|
||||
at.mux.Lock()
|
||||
at.tables.Add(tablePubkey, table)
|
||||
total := at.tables.Len()
|
||||
delete(at.loading, tablePubkey)
|
||||
at.mux.Unlock()
|
||||
logger.Info("loadAddressTable", "table", tablePubkey.String(), "table count:", total)
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
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))
|
||||
for _, i := range idx {
|
||||
if int(i) >= len(addresses) {
|
||||
logger.Error("over loadAddressTable failed", "idx", i, "table", tablePubkey)
|
||||
//todo... update table?
|
||||
continue
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
func pumpSwapSellAtIdx0(amount uint64, plan []RoutePlanStep) uint64 {
|
||||
var ret uint64
|
||||
func pumpSwapSellAtIdx0(amount uint64, plan []RoutePlanStep) (uint64, int) {
|
||||
var (
|
||||
ret uint64
|
||||
i int
|
||||
)
|
||||
for _, step := range plan {
|
||||
if step.InputIdx == 0 &&
|
||||
(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
|
||||
}
|
||||
}
|
||||
return ret
|
||||
return ret, i
|
||||
}
|
||||
|
||||
func pumpSwapSellAtIdx0V2(amount uint64, plan []RoutePlanStepV2) uint64 {
|
||||
var ret uint64
|
||||
func pumpSwapSellAtIdx0V2(amount uint64, plan []RoutePlanStepV2) (uint64, int) {
|
||||
var (
|
||||
ret uint64
|
||||
i int
|
||||
)
|
||||
for _, step := range plan {
|
||||
if step.InputIdx == 0 &&
|
||||
(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
|
||||
}
|
||||
}
|
||||
return ret
|
||||
return ret, i
|
||||
}
|
||||
|
||||
// only decodes inputIdx = 0 container pumpSwap instructions for now
|
||||
@@ -861,6 +878,7 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
||||
var (
|
||||
sourceMint solana.PublicKey
|
||||
inputAmount uint64
|
||||
planCount int
|
||||
err error
|
||||
)
|
||||
|
||||
@@ -872,34 +890,34 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
inputAmount = pumpSwapSellAtIdx0V2(args.In, args.Plan)
|
||||
|
||||
inputAmount, planCount = pumpSwapSellAtIdx0V2(args.In, args.Plan)
|
||||
case bytes.Equal(disc, jupiterSharedAccountsRouteV2):
|
||||
args, err := decodeJupiterV6SharedAccountsRouteV2Arg(instruction.Data[8:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
inputAmount = pumpSwapSellAtIdx0V2(args.In, args.RoutePlan)
|
||||
|
||||
inputAmount, planCount = pumpSwapSellAtIdx0V2(args.In, args.RoutePlan)
|
||||
case bytes.Equal(disc, jupiterRoute):
|
||||
args, err := decodeJupiterV6RouteArg(instruction.Data[8:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = args
|
||||
inputAmount = pumpSwapSellAtIdx0(args.In, args.Plan)
|
||||
|
||||
inputAmount, planCount = pumpSwapSellAtIdx0(args.In, args.Plan)
|
||||
case bytes.Equal(disc, jupiterSharedAccountsRoute):
|
||||
args, err := decodeJupiterV6SharedAccountsRouteArg(instruction.Data[8:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = args
|
||||
inputAmount = pumpSwapSellAtIdx0(args.In, args.Plan)
|
||||
|
||||
inputAmount, planCount = pumpSwapSellAtIdx0(args.In, args.Plan)
|
||||
default:
|
||||
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 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -913,6 +931,40 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
||||
if err != nil {
|
||||
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) {
|
||||
if len(instruction.Accounts) < 12 {
|
||||
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 {
|
||||
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 {
|
||||
if len(instruction.Accounts) < 10 {
|
||||
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 {
|
||||
if i <= 9 {
|
||||
if i < 9 {
|
||||
continue
|
||||
}
|
||||
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||
@@ -949,11 +1033,12 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
||||
if err != nil {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
if !distMint.Equals(solana.WrappedSol) {
|
||||
if !quoteMint.Equals(solana.WrappedSol) {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/mr-tron/base58"
|
||||
@@ -238,6 +239,7 @@ func ParseTransaction(update *SubscribeUpdateTransaction, loader *AddressTables)
|
||||
staticKeys = append(staticKeys, accounts...)
|
||||
}
|
||||
}
|
||||
versioned.Message.StaticAccountKeys = staticKeys
|
||||
}
|
||||
|
||||
var parsed []*TxSignal
|
||||
@@ -280,9 +282,9 @@ func ParseTransaction(update *SubscribeUpdateTransaction, loader *AddressTables)
|
||||
case terminalProgramID:
|
||||
txRes, err := parseTermInstruction(versioned, i)
|
||||
parsed = appendParsed(parsed, txRes, err, txHash, "terminal")
|
||||
//case jupiterV6ProgramID:
|
||||
// txRes, err := parseJupiterV6Instruction(versioned, i)
|
||||
// parsed = appendParsed(parsed, txRes, err, txHash, "jupiterv6")
|
||||
case jupiterV6ProgramID:
|
||||
txRes, err := parseJupiterV6Instruction(versioned, i)
|
||||
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 {
|
||||
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[:]))
|
||||
}
|
||||
return list
|
||||
}
|
||||
if parsed != nil {
|
||||
|
||||
Reference in New Issue
Block a user