4 Commits

Author SHA1 Message Date
thloyi
122d474524 juptierv6 fix 2026-01-07 11:57:31 +08:00
thloyi
2d3f46ebbf juptierv6 2026-01-07 11:18:02 +08:00
thloyi
c732bb2b46 fix looptable index 2026-01-06 16:42:07 +08:00
99ff9968bd fix address table lookup 2026-01-05 19:34:35 +08:00
10 changed files with 3889 additions and 24 deletions

62
cmd/debug_jupv6/main.go Normal file
View File

@@ -0,0 +1,62 @@
package main
import (
"encoding/hex"
"fmt"
"os"
)
func main() {
hexData := "bb64facc31c4af14be34e6edcc0000006f03a4df67000000b903320000000300000064342100024b00000000dc0500026310270203"
b, err := hex.DecodeString(hexData)
if err != nil {
panic(err)
}
payload := b[8:]
off := 0
read := func(n int) []byte {
if off+n > len(payload) {
fmt.Printf("OOB read: off=%d n=%d len=%d\n", off, n, len(payload))
os.Exit(1)
}
out := payload[off : off+n]
off += n
return out
}
u8 := func() uint8 { return read(1)[0] }
leU16 := func() uint16 {
b := read(2)
return uint16(b[0]) | uint16(b[1])<<8
}
leU32 := func() uint32 {
b := read(4)
return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
}
leU64 := func() uint64 {
b := read(8)
return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
}
fmt.Printf("payload len=%d\n", len(payload))
amountIn := leU64()
quotedOut := leU64()
slippage := leU16()
platform := leU16()
posSlip := leU16()
fmt.Printf("in=%d out=%d slip=%d plat=%d pos=%d\n", amountIn, quotedOut, slippage, platform, posSlip)
planLen := leU32()
fmt.Printf("planLen=%d\n", planLen)
for i := uint32(0); i < planLen; i++ {
swapTag := u8()
fmt.Printf("step[%d] swapTag=%d (0x%02x) off=%d\n", i, swapTag, swapTag, off)
// payload depends on swapTag; we don't know, so just print next few bytes and stop
bps := leU16()
inIdx := u8()
outIdx := u8()
fmt.Printf(" bps=%d inIdx=%d outIdx=%d off=%d\n", bps, inIdx, outIdx, off)
}
fmt.Printf("done off=%d\n", off)
}

View File

@@ -37,6 +37,7 @@ func main() {
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA",
"GS4CU59F31iL7aR2Q8zVS8DRrcRnXX1yjQ66TqNVQnaR", //Event Authority
"5PHirr8joyTMp9JMm6nW7hNDVyEYdkzDqazxPD7RaTjx", // Fee Config
"pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ", // pump fee program
},
},
"photon": {
@@ -44,6 +45,11 @@ func main() {
"BSfD6SHZigAfDWSjzD5Q41jw8LmKwtmjskPH9XW1mrRW",
},
},
"jupiterV6": {
AccountRequired: []string{
"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",
},
},
// TODO: axiom, gmgn, etc.
})
if err != nil {
@@ -77,7 +83,12 @@ func main() {
return
case txBatch := <-txCh:
//jsonData, _ := json.MarshalIndent(txBatch, "", " ")
fmt.Println(txBatch[0].TxHash)
for _, tx := range txBatch {
if tx.Label == "jupiterV6" {
fmt.Println("===============", tx.TxHash, tx.Token0Address, tx.Token0Amount)
}
}
//fmt.Println(txBatch[0].TxHash)
}
}
}

File diff suppressed because one or more lines are too long

View File

@@ -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{}
@@ -21,7 +22,7 @@ type AddressTables struct {
}
func NewAddressTables(rpcClient *rpc.Client) *AddressTables {
pool, _ := ants.NewPool(10, ants.WithPreAlloc(true), ants.WithNonblocking(true))
pool, _ := ants.NewPool(5, ants.WithPreAlloc(true), ants.WithNonblocking(true))
cache, _ := lru.New[solana.PublicKey, []solana.PublicKey](10000)
return &AddressTables{
rpcClient: rpcClient,
@@ -60,39 +61,43 @@ 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()
var result solana.PublicKeySlice = make([]solana.PublicKey, 0, len(idx))
for i := range idx {
if int(idx[i]) >= len(addresses) {
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])

File diff suppressed because it is too large Load Diff

1068
pkg/shreder/juptierv6.go Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,88 @@
package shreder
import (
"encoding/hex"
"testing"
)
func TestDecodeRouteV2Arg(t *testing.T) {
tests := []struct {
name string
hexData string
}{
{
name: "Jupiter V6 RouteV2Arg Test 0",
hexData: "bb64facc31c4af14809fd500000000002222e8db1800000064000a000000020000005601fe102700016310270102",
},
{
name: "Jupiter V6 RouteV2Arg Test 1",
hexData: "bb64facc31c4af144ff91634b90000004e6c4d05000000002c013200000003000000520000000000000000102700014f102701024310270203",
},
{
name: "Jupiter V6 RouteV2Arg Test 2",
hexData: "bb64facc31c4af14ba2eafa02c1d0000777a9b2200000000f4010a0000000100000052000000000000000010270001",
},
{
name: "Jupiter V6 RouteV2Arg Test 3",
hexData: "bb64facc31c4af144a3521186b07000030508d0e00000000c201320000000300000052000000000000000010270001740110270102590010270203",
},
{
name: "Jupiter V6 RouteV2Arg Test 4",
hexData: "bb64facc31c4af14092d05050000000013701f198c0100008102380100000300000059011027000168001027010251000000000000000010270203",
},
{
name: "Jupiter V6 RouteV2Arg Test 5",
hexData: "bb64facc31c4af1480969800000000006f44ad39bd0000001202320000000200000068001027000151000000000000000010270102",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
instrData, err := hex.DecodeString(tt.hexData)
if err != nil {
t.Fatalf("failed to decode hex string: %v", err)
return
}
t.Logf("raw bytes: %x", instrData[8:])
args, err := decodeJupiterV6RouteV2Arg(instrData[8:])
if err != nil {
t.Fatalf("failed to decode jupiter arguments: %v", err)
return
}
t.Logf("decoded args: %+v", args)
})
}
}
func TestDecodeRouteArg(t *testing.T) {
tests := []struct {
name string
hexData string
}{
{
name: "Jupiter V6 RouteArg Test 0",
hexData: "e517cb977ae3ad2a030000004f6400014f64010251000000000000000064020340420f00000000005c1c81900e000000640000",
},
{
name: "Jupiter V6 RouteArg Test 1",
hexData: "e517cb977ae3ad2a0200000028640001510000000000000000640102c09ee605000000005e1bc48efa000000d00700",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
instrData, err := hex.DecodeString(tt.hexData)
if err != nil {
t.Fatalf("failed to decode hex string: %v", err)
return
}
t.Logf("raw bytes: %x", instrData[8:])
args, err := decodeJupiterV6RouteArg(instrData[8:])
if err != nil {
t.Fatalf("failed to decode jupiter arguments: %v", err)
return
}
t.Logf("decoded args: %+v", args)
})
}
}

View File

@@ -0,0 +1,5 @@
package shreder
//func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
//
//}

View File

@@ -29,6 +29,7 @@ func SetLogLevel(level slog.Level) {
type TxSignal struct {
Source string `json:"source"`
Label string `json:"label"`
TxHash string `json:"tx_hash"`
Maker string `json:"maker"`
Token0Address string `json:"token0_address"`

View File

@@ -5,6 +5,7 @@ import (
"encoding/binary"
"fmt"
"math/big"
"strings"
"github.com/gagliardetto/solana-go"
"github.com/mr-tron/base58"
@@ -42,8 +43,23 @@ var (
flasProgramID = solana.MustPublicKeyFromBase58("FLASHX8DrLbgeR8FcfNV1F5krxYcYMUdBkrP1EPBtxB9")
terminalProgramID = solana.MustPublicKeyFromBase58("term9YPb9mzAsABaqN71A4xdbxHmpBNZavpBiQKZzN3")
jupiterV6ProgramID = solana.MustPublicKeyFromBase58("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4")
)
type AccountNotFoundError struct {
Index int
Len int
}
func NewAccountNotFoundError(i, l int) error {
return &AccountNotFoundError{i, l}
}
func (e AccountNotFoundError) Error() string {
return fmt.Sprintf("account index %d out of range, len=%d", e.Index, e.Len)
}
// instruction discriminators
var (
pumpCreateCoinIX = []byte{24, 30, 200, 40, 5, 28, 7, 119}
@@ -198,19 +214,32 @@ func ParseTransaction(update *SubscribeUpdateTransaction, loader *AddressTables)
instructions := versioned.Message.Instructions
if loader != nil && len(versioned.Message.AddressTableLookups) > 0 {
// currently we only care about photon table lookup
lookupTableOk := true
for _, lookup := range versioned.Message.AddressTableLookups {
if len(lookup.WritableIndexes) == 0 {
continue
}
accounts := loader.GetAddressTable(lookup.AccountKey, lookup.WritableIndexes)
if len(accounts) != len(lookup.WritableIndexes) {
lookupTableOk = false
break
}
staticKeys = append(staticKeys, accounts...)
accounts2 := loader.GetAddressTable(lookup.AccountKey, lookup.ReadonlyIndexes)
if len(accounts2) != len(lookup.ReadonlyIndexes) {
break
}
staticKeys = append(staticKeys, accounts2...)
}
if lookupTableOk {
for _, lookup := range versioned.Message.AddressTableLookups {
if len(lookup.ReadonlyIndexes) == 0 {
continue
}
accounts := loader.GetAddressTable(lookup.AccountKey, lookup.ReadonlyIndexes)
if len(accounts) != len(lookup.ReadonlyIndexes) {
break
}
staticKeys = append(staticKeys, accounts...)
}
}
versioned.Message.StaticAccountKeys = staticKeys
}
var parsed []*TxSignal
@@ -253,6 +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")
}
}
@@ -261,7 +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 {
logger.Debug("txparser: failed to parse", "label", label, "instruction", err, "tx_hash", base58.Encode(txHash[:]))
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 {
@@ -331,11 +365,8 @@ func formatSolAmount(lamports uint64) decimal.Decimal {
}
func getStaticKey(static []solana.PublicKey, index int) (solana.PublicKey, error) {
if index < 0 {
return solana.PublicKey{}, fmt.Errorf("account index %d less then 0", index)
}
if index >= len(static) {
return solana.PublicKey{}, fmt.Errorf("account index %d out of range", index)
if index < 0 || index >= len(static) {
return solana.PublicKey{}, NewAccountNotFoundError(index, len(static))
}
return static[index], nil
}
@@ -381,6 +412,7 @@ func parsePumpCreate(tx *versionedTransaction, instruction *compiledInstruction)
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "pump",
Maker: creator.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -421,6 +453,7 @@ func parsePumpCreateV2(tx *versionedTransaction, instruction *compiledInstructio
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "pump",
Maker: args.Creator.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -484,6 +517,7 @@ func parsePumpBuy(tx *versionedTransaction, instruction *compiledInstruction) (*
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "pump",
Maker: buyer.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -541,6 +575,7 @@ func parsePumpSell(tx *versionedTransaction, instruction *compiledInstruction) (
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "pump",
Maker: seller.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -599,6 +634,7 @@ func parseAzczAmmBuy(tx *versionedTransaction, instructionIndex int) (*TxSignal,
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "azcz",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -642,6 +678,7 @@ func parseAzczBuy(tx *versionedTransaction, instructionIndex int) (*TxSignal, er
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "azcz",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -696,6 +733,7 @@ func parseF5tfInstruction(tx *versionedTransaction, instructionIndex int) (*TxSi
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "f5tf",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -766,6 +804,7 @@ func parseFlasAmmSell(tx *versionedTransaction, instructionIndex int) (*TxSignal
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "flas",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -805,6 +844,7 @@ func parseFlasAmmBuy(tx *versionedTransaction, instructionIndex int) (*TxSignal,
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "flas",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -844,6 +884,7 @@ func parseFlasSell(tx *versionedTransaction, instructionIndex int) (*TxSignal, e
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "flas",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -882,6 +923,7 @@ func parseFlasBuy(tx *versionedTransaction, instructionIndex int) (*TxSignal, er
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "flas",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -948,6 +990,7 @@ func parsePhotonBuy(tx *versionedTransaction, instruction *compiledInstruction)
solAmount := args.SolAmount * (100000000 - 1234568) / 100000000
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "photon",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -1003,6 +1046,7 @@ func parsePhotonSwap(tx *versionedTransaction, instruction *compiledInstruction)
solAmount := args.FromAmount * (100000000 - 1234568) / 100000000
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "photon",
Maker: buyer.String(),
Token0Address: base.String(),
Token1Address: wsolMint,
@@ -1084,6 +1128,7 @@ func parseTermAmmSell(tx *versionedTransaction, instruction *compiledInstruction
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "term",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -1119,6 +1164,7 @@ func parseTermBuy(tx *versionedTransaction, instruction *compiledInstruction) (*
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "term",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -1153,6 +1199,7 @@ func parseTermSell(tx *versionedTransaction, instruction *compiledInstruction) (
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "term",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -1224,6 +1271,7 @@ func parsePumpAmmBuy(tx *versionedTransaction, instruction *compiledInstruction)
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "pumpamm",
Maker: buyer.String(),
Token0Address: base.String(),
Token1Address: wsolMint,
@@ -1270,6 +1318,7 @@ func parsePumpAmmSell(tx *versionedTransaction, instruction *compiledInstruction
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "pumpamm",
Maker: buyer.String(),
Token0Address: base.String(),
Token1Address: wsolMint,
@@ -1323,6 +1372,7 @@ func parseBoboInstruction(tx *versionedTransaction, instructionIndex int) (*TxSi
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "bobo",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -1383,6 +1433,7 @@ func parseQtkvSell(tx *versionedTransaction, instructionIndex int) (*TxSignal, e
tokenAmount := binary.LittleEndian.Uint64(instruction.Data[19:25])
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "qtkv",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -1421,6 +1472,7 @@ func parseQtkvAmmSell(tx *versionedTransaction, instructionIndex int) (*TxSignal
tokenAmount := binary.LittleEndian.Uint64(instruction.Data[19:25])
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "qtkv",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -1459,6 +1511,7 @@ func parseQtkvBuy(tx *versionedTransaction, instructionIndex int) (*TxSignal, er
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "qtkv",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,
@@ -1512,6 +1565,7 @@ func parseFjszInstruction(tx *versionedTransaction, instructionIndex int) (*TxSi
return &TxSignal{
TxHash: tx.Signatures[0].String(),
Label: "fjsz",
Maker: user.String(),
Token0Address: mint.String(),
Token1Address: wsolMint,