Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2504636fb0 | ||
|
|
c4d35bd3d4 | ||
|
|
214d9e984e | ||
| c30d64fe88 | |||
| 27dde60e93 | |||
|
|
122d474524 | ||
|
|
2d3f46ebbf |
@@ -84,8 +84,13 @@ func main() {
|
|||||||
case txBatch := <-txCh:
|
case txBatch := <-txCh:
|
||||||
//jsonData, _ := json.MarshalIndent(txBatch, "", " ")
|
//jsonData, _ := json.MarshalIndent(txBatch, "", " ")
|
||||||
for _, tx := range txBatch {
|
for _, tx := range txBatch {
|
||||||
if tx.Label == "jupiterV6" {
|
if tx.Label == "flas" {
|
||||||
fmt.Println("===============", tx.TxHash, tx.Token0Address, tx.Token0Amount)
|
if tx.Event == "buy" {
|
||||||
|
fmt.Println("===============", tx.TxHash, tx.Program, tx.Event, tx.Token0Address, "token:", tx.Token0Amount, "sol:", tx.Token1Amount)
|
||||||
|
} else if tx.Event == "sell" {
|
||||||
|
fmt.Println("===============", tx.TxHash, tx.Program, tx.Event, tx.Token0Address, "token:", tx.Token0Amount)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//fmt.Println(txBatch[0].TxHash)
|
//fmt.Println(txBatch[0].TxHash)
|
||||||
|
|||||||
1
pkg/shreder/OnChain_Labs_DexRouterV2-idl.json
Normal file
1
pkg/shreder/OnChain_Labs_DexRouterV2-idl.json
Normal file
File diff suppressed because one or more lines are too long
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -967,7 +1052,7 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
Token0Amount: formatTokenAmount(inputAmount),
|
Token0Amount: formatTokenAmount(inputAmount),
|
||||||
Token1Amount: decimal.Zero,
|
Token1Amount: decimal.Zero,
|
||||||
Program: "PumpAMM",
|
Program: "PumpAMM",
|
||||||
Event: "buy",
|
Event: "sell",
|
||||||
IsToken2022: false,
|
IsToken2022: false,
|
||||||
IsMayhemMode: false,
|
IsMayhemMode: false,
|
||||||
ExactSOL: false,
|
ExactSOL: false,
|
||||||
|
|||||||
@@ -1 +1,5 @@
|
|||||||
package shreder
|
package shreder
|
||||||
|
|
||||||
|
//func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ type TxSignal struct {
|
|||||||
IsToken2022 bool `json:"is_token2022"`
|
IsToken2022 bool `json:"is_token2022"`
|
||||||
IsMayhemMode bool `json:"is_mayhem_mode"`
|
IsMayhemMode bool `json:"is_mayhem_mode"`
|
||||||
TxFee decimal.Decimal `json:"tx_fee"`
|
TxFee decimal.Decimal `json:"tx_fee"`
|
||||||
|
EntryContract string `json:"entry_contract"`
|
||||||
|
|
||||||
ExactSOL bool `json:"exact_in"`
|
ExactSOL bool `json:"exact_in"`
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
||||||
@@ -147,9 +148,9 @@ type f5tfBuyArgs struct {
|
|||||||
TokenAmount uint64
|
TokenAmount uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type flasBuyArgs struct {
|
type flasArgs struct {
|
||||||
SolAmount uint64
|
Amount1 uint64
|
||||||
TokenAmount uint64
|
Amount2 uint64
|
||||||
Placeholder [3]uint8
|
Placeholder [3]uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,16 +171,6 @@ type pumpAmmBuyArgs struct {
|
|||||||
MaxSolCost uint64
|
MaxSolCost uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type _6hb1BuyArgs struct {
|
|
||||||
SolAmount uint64
|
|
||||||
TokenNumber uint64
|
|
||||||
}
|
|
||||||
|
|
||||||
type _8rsrBuyArgs struct {
|
|
||||||
SolIn uint64
|
|
||||||
TokenOut uint64
|
|
||||||
}
|
|
||||||
|
|
||||||
type boboBuyArgs struct {
|
type boboBuyArgs struct {
|
||||||
Placeholder1 uint64
|
Placeholder1 uint64
|
||||||
Placeholder2 uint64
|
Placeholder2 uint64
|
||||||
@@ -238,6 +229,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
|
||||||
@@ -252,52 +244,52 @@ func ParseTransaction(update *SubscribeUpdateTransaction, loader *AddressTables)
|
|||||||
switch programID {
|
switch programID {
|
||||||
case pumpProgramID:
|
case pumpProgramID:
|
||||||
txRes, err := parsePumpInstruction(versioned, i)
|
txRes, err := parsePumpInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "pump")
|
parsed = appendParsed(parsed, txRes, err, txHash, "pump", pumpProgramID.String())
|
||||||
case azczProgramID:
|
case azczProgramID:
|
||||||
txRes, err := parseAzczInstruction(versioned, i)
|
txRes, err := parseAzczInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "azcz")
|
parsed = appendParsed(parsed, txRes, err, txHash, "azcz", azczProgramID.String())
|
||||||
case f5tfProgramID:
|
case f5tfProgramID:
|
||||||
txRes, err := parseF5tfInstruction(versioned, i)
|
txRes, err := parseF5tfInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "f5tf")
|
parsed = appendParsed(parsed, txRes, err, txHash, "f5tf", f5tfProgramID.String())
|
||||||
case flasProgramID:
|
case flasProgramID:
|
||||||
txRes, err := parseFlasInstruction(versioned, i)
|
txRes, err := parseFlasInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "flas")
|
parsed = appendParsed(parsed, txRes, err, txHash, "flas", flasProgramID.String())
|
||||||
case photonProgramID:
|
case photonProgramID:
|
||||||
txRes, err := parsePhotonInstruction(versioned, i)
|
txRes, err := parsePhotonInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "photon")
|
parsed = appendParsed(parsed, txRes, err, txHash, "photon", photonProgramID.String())
|
||||||
case pumpAmmProgramID:
|
case pumpAmmProgramID:
|
||||||
txRes, err := parsePumpAmmInstruction(versioned, i)
|
txRes, err := parsePumpAmmInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "pumpamm")
|
parsed = appendParsed(parsed, txRes, err, txHash, "pumpamm", pumpAmmProgramID.String())
|
||||||
case boboProgramID:
|
case boboProgramID:
|
||||||
txRes, err := parseBoboInstruction(versioned, i)
|
txRes, err := parseBoboInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "bobo")
|
parsed = appendParsed(parsed, txRes, err, txHash, "bobo", boboProgramID.String())
|
||||||
case qtkvProgramID:
|
case qtkvProgramID:
|
||||||
txRes, err := parseQtkvInstruction(versioned, i)
|
txRes, err := parseQtkvInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "qtkv")
|
parsed = appendParsed(parsed, txRes, err, txHash, "qtkv", qtkvProgramID.String())
|
||||||
case fjszProgramID:
|
case fjszProgramID:
|
||||||
txRes, err := parseFjszInstruction(versioned, i)
|
txRes, err := parseFjszInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "fjsz")
|
parsed = appendParsed(parsed, txRes, err, txHash, "fjsz", fjszProgramID.String())
|
||||||
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", terminalProgramID.String())
|
||||||
//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", jupiterV6ProgramID.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsed
|
return parsed
|
||||||
}
|
}
|
||||||
|
|
||||||
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, entryContract 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 {
|
||||||
|
parsed.EntryContract = entryContract
|
||||||
list = append(list, parsed)
|
list = append(list, parsed)
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
@@ -765,10 +757,10 @@ func parseFlasInstruction(tx *versionedTransaction, instructionIndex int) (*TxSi
|
|||||||
return nil, fmt.Errorf("data too short for args flas instruction, len: %d", len(instruction.Data))
|
return nil, fmt.Errorf("data too short for args flas instruction, len: %d", len(instruction.Data))
|
||||||
}
|
}
|
||||||
methodData := instruction.Data[17:20]
|
methodData := instruction.Data[17:20]
|
||||||
if !matchMethod(methodData, flasBuyTokensIX) {
|
//if !matchMethod(methodData, flasBuyTokensIX) {
|
||||||
return nil, nil
|
// return nil, nil
|
||||||
}
|
//}
|
||||||
if matchMethod(methodData, f5tfBuyTokensIX) {
|
if matchMethod(methodData, flasBuyTokensIX) {
|
||||||
return parseFlasBuy(tx, instructionIndex)
|
return parseFlasBuy(tx, instructionIndex)
|
||||||
} else if matchMethod(methodData, flasSellTokensIX) {
|
} else if matchMethod(methodData, flasSellTokensIX) {
|
||||||
return parseFlasSell(tx, instructionIndex)
|
return parseFlasSell(tx, instructionIndex)
|
||||||
@@ -796,7 +788,7 @@ func parseFlasAmmSell(tx *versionedTransaction, instructionIndex int) (*TxSignal
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var args flasBuyArgs
|
var args flasArgs
|
||||||
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||||
}
|
}
|
||||||
@@ -807,16 +799,16 @@ func parseFlasAmmSell(tx *versionedTransaction, instructionIndex int) (*TxSignal
|
|||||||
Maker: user.String(),
|
Maker: user.String(),
|
||||||
Token0Address: mint.String(),
|
Token0Address: mint.String(),
|
||||||
Token1Address: wsolMint,
|
Token1Address: wsolMint,
|
||||||
Token0Amount: decimal.Zero,
|
Token0Amount: formatTokenAmount(args.Amount1),
|
||||||
Token1Amount: formatSolAmount(args.TokenAmount),
|
Token1Amount: formatSolAmount(args.Amount2),
|
||||||
Program: "Pump",
|
Program: "PumpAMM",
|
||||||
Event: "sell",
|
Event: "sell",
|
||||||
IsToken2022: false,
|
IsToken2022: false,
|
||||||
IsMayhemMode: false,
|
IsMayhemMode: false,
|
||||||
ExactSOL: true,
|
ExactSOL: false,
|
||||||
Block: tx.Block,
|
Block: tx.Block,
|
||||||
Token0AmountUint64: 0,
|
Token0AmountUint64: args.Amount1,
|
||||||
Token1AmountUint64: args.TokenAmount,
|
Token1AmountUint64: args.Amount2,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -836,7 +828,7 @@ func parseFlasAmmBuy(tx *versionedTransaction, instructionIndex int) (*TxSignal,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var args flasBuyArgs
|
var args flasArgs
|
||||||
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||||
}
|
}
|
||||||
@@ -848,15 +840,15 @@ func parseFlasAmmBuy(tx *versionedTransaction, instructionIndex int) (*TxSignal,
|
|||||||
Token0Address: mint.String(),
|
Token0Address: mint.String(),
|
||||||
Token1Address: wsolMint,
|
Token1Address: wsolMint,
|
||||||
Token0Amount: decimal.Zero,
|
Token0Amount: decimal.Zero,
|
||||||
Token1Amount: formatSolAmount(args.TokenAmount),
|
Token1Amount: formatSolAmount(args.Amount1),
|
||||||
Program: "Pump",
|
Program: "PumpAMM",
|
||||||
Event: "sell",
|
Event: "buy",
|
||||||
IsToken2022: false,
|
IsToken2022: false,
|
||||||
IsMayhemMode: false,
|
IsMayhemMode: false,
|
||||||
ExactSOL: true,
|
ExactSOL: true,
|
||||||
Block: tx.Block,
|
Block: tx.Block,
|
||||||
Token0AmountUint64: 0,
|
Token0AmountUint64: 0,
|
||||||
Token1AmountUint64: args.TokenAmount,
|
Token1AmountUint64: args.Amount1,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -876,7 +868,7 @@ func parseFlasSell(tx *versionedTransaction, instructionIndex int) (*TxSignal, e
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var args flasBuyArgs
|
var args flasArgs
|
||||||
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||||
}
|
}
|
||||||
@@ -887,15 +879,15 @@ func parseFlasSell(tx *versionedTransaction, instructionIndex int) (*TxSignal, e
|
|||||||
Maker: user.String(),
|
Maker: user.String(),
|
||||||
Token0Address: mint.String(),
|
Token0Address: mint.String(),
|
||||||
Token1Address: wsolMint,
|
Token1Address: wsolMint,
|
||||||
Token0Amount: formatTokenAmount(args.TokenAmount),
|
Token0Amount: formatTokenAmount(args.Amount1),
|
||||||
Token1Amount: formatSolAmount(args.SolAmount),
|
Token1Amount: formatSolAmount(args.Amount2),
|
||||||
Program: "Pump",
|
Program: "Pump",
|
||||||
Event: "sell",
|
Event: "sell",
|
||||||
IsToken2022: false,
|
IsToken2022: false,
|
||||||
IsMayhemMode: false,
|
IsMayhemMode: false,
|
||||||
Block: tx.Block,
|
Block: tx.Block,
|
||||||
Token0AmountUint64: args.TokenAmount,
|
Token0AmountUint64: args.Amount1,
|
||||||
Token1AmountUint64: args.SolAmount,
|
Token1AmountUint64: args.Amount2,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -914,8 +906,10 @@ func parseFlasBuy(tx *versionedTransaction, instructionIndex int) (*TxSignal, er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if len(instruction.Data) > 20 {
|
||||||
var args flasBuyArgs
|
instruction.Data = instruction.Data[:20]
|
||||||
|
}
|
||||||
|
var args flasArgs
|
||||||
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||||
}
|
}
|
||||||
@@ -926,16 +920,16 @@ func parseFlasBuy(tx *versionedTransaction, instructionIndex int) (*TxSignal, er
|
|||||||
Maker: user.String(),
|
Maker: user.String(),
|
||||||
Token0Address: mint.String(),
|
Token0Address: mint.String(),
|
||||||
Token1Address: wsolMint,
|
Token1Address: wsolMint,
|
||||||
Token0Amount: formatTokenAmount(args.TokenAmount),
|
Token0Amount: formatTokenAmount(args.Amount2),
|
||||||
Token1Amount: formatSolAmount(args.SolAmount),
|
Token1Amount: formatSolAmount(args.Amount1),
|
||||||
Program: "Pump",
|
Program: "Pump",
|
||||||
Event: "buy",
|
Event: "buy",
|
||||||
IsToken2022: false,
|
IsToken2022: false,
|
||||||
IsMayhemMode: false,
|
IsMayhemMode: false,
|
||||||
ExactSOL: true,
|
ExactSOL: true,
|
||||||
Block: tx.Block,
|
Block: tx.Block,
|
||||||
Token0AmountUint64: args.TokenAmount,
|
Token0AmountUint64: args.Amount2,
|
||||||
Token1AmountUint64: args.SolAmount,
|
Token1AmountUint64: args.Amount1,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
56
pkg/shreder/txparser_test.go
Normal file
56
pkg/shreder/txparser_test.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package shreder
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/near/borsh-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDecodeAxiomArgs(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
hexData string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "pump amm sell Test 0",
|
||||||
|
hexData: "00686f08bb1b0000007eb4ac020000000001020200183c",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pump amm buy Test 1",
|
||||||
|
hexData: "00c09ee6050000000001c94d882600000000020200323c",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pump buy Test 2",
|
||||||
|
hexData: "00d8d3bc0000000000bb7c53f009000000000104185a",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pump sell Test 3",
|
||||||
|
hexData: "009bbf69ec08080000830bc61200000000010103a000",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pump swap sell Test 4",
|
||||||
|
hexData: "00c98ea7588b0000009adf3b010000000001020200283c",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pump swap sell Test 5",
|
||||||
|
hexData: "00d3727f9301000000f9a50b0100000000010202001e00",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
data, err := hex.DecodeString(tt.hexData)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to decode hex string: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var args flasArgs
|
||||||
|
if err := borsh.Deserialize(&args, data[1:]); err != nil {
|
||||||
|
t.Fatalf("failed to decode Axiom args: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Logf("Decoded Axiom Args: %+v", args)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user