Compare commits
7 Commits
23f37cff2c
...
dab77c0b61
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dab77c0b61 | ||
|
|
35c5c83f4b | ||
|
|
5f97972194 | ||
|
|
741d333e1b | ||
|
|
594c46a1d2 | ||
|
|
45107aa8c3 | ||
|
|
36db4729d4 |
@@ -76,7 +76,7 @@ func main() {
|
||||
cancel()
|
||||
}()
|
||||
// async read from shreder
|
||||
txCh := make(chan shreder.TxSignalBatch, 1000)
|
||||
txCh := make(chan shreder.TxSignal, 1000)
|
||||
go func() {
|
||||
err := shrederClient.ReadSync(ctx, txCh)
|
||||
if err != nil {
|
||||
@@ -90,14 +90,10 @@ func main() {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case txBatch := <-txCh:
|
||||
//jsonData, _ := json.MarshalIndent(txBatch, "", " ")
|
||||
for _, tx := range txBatch {
|
||||
case tx := <-txCh:
|
||||
if tx.Label == "okxdexroutev2" || tx.Label == "jupiterv6" || tx.Label == "dflow" {
|
||||
fmt.Println("===============", tx.TxHash, tx.Label, tx.Event, tx.Token0Address, "token:", tx.Token0Amount, "parse time:", tx.ParseEnd.Sub(tx.ParseStart))
|
||||
}
|
||||
}
|
||||
//fmt.Println(txBatch[0].TxHash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
180
cmd/txparse/main.go
Normal file
180
cmd/txparse/main.go
Normal file
@@ -0,0 +1,180 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/gagliardetto/solana-go/programs/address-lookup-table"
|
||||
"github.com/gagliardetto/solana-go/rpc"
|
||||
|
||||
"github.com/samlior/libsam/pkg/shreder"
|
||||
)
|
||||
|
||||
const (
|
||||
rpcURL = "https://staked.helius-rpc.com?api-key=5adcf1f9-5719-43d1-bf3f-c2d4e1e5f94d"
|
||||
txSignature = "4YUQzsQcHxt5jA6qKPVBWCgw8VRuE6bZqAoXeiwptbdLwta3QnDbWHzjwP3mY8hJPPerSf1yGbpdL2SdyWZTJ9e1"
|
||||
labelFilter = ""
|
||||
enableStats = true
|
||||
)
|
||||
|
||||
func main() {
|
||||
if rpcURL == "" || rpcURL == "REPLACE_WITH_RPC_URL" {
|
||||
log.Fatal("rpcURL is not set in cmd/dlmmparse/main.go")
|
||||
}
|
||||
if txSignature == "" || txSignature == "REPLACE_WITH_TX_SIGNATURE" {
|
||||
log.Fatal("txSignature is not set in cmd/dlmmparse/main.go")
|
||||
}
|
||||
|
||||
client := rpc.New(rpcURL)
|
||||
sig, err := solana.SignatureFromBase58(txSignature)
|
||||
if err != nil {
|
||||
log.Fatalf("invalid txSignature: %v", err)
|
||||
}
|
||||
version := uint64(0)
|
||||
tx, err := client.GetTransaction(
|
||||
context.Background(),
|
||||
sig,
|
||||
&rpc.GetTransactionOpts{
|
||||
Commitment: rpc.CommitmentFinalized,
|
||||
MaxSupportedTransactionVersion: &version,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("getTransaction failed: %v", err)
|
||||
}
|
||||
if tx == nil || tx.Transaction == nil {
|
||||
log.Fatal("transaction is empty")
|
||||
}
|
||||
|
||||
rawTx, err := tx.Transaction.GetTransaction()
|
||||
if err != nil {
|
||||
log.Fatalf("decode transaction failed: %v", err)
|
||||
}
|
||||
if rawTx == nil {
|
||||
log.Fatal("decoded transaction is nil")
|
||||
}
|
||||
|
||||
if len(rawTx.Message.AddressTableLookups) > 0 {
|
||||
tables := make(map[solana.PublicKey]solana.PublicKeySlice, len(rawTx.Message.AddressTableLookups))
|
||||
for _, lookup := range rawTx.Message.AddressTableLookups {
|
||||
state, err := addresslookuptable.GetAddressLookupTable(context.Background(), client, lookup.AccountKey)
|
||||
if err != nil {
|
||||
log.Fatalf("load address table %s failed: %v", lookup.AccountKey, err)
|
||||
}
|
||||
tables[lookup.AccountKey] = state.Addresses
|
||||
}
|
||||
if err := rawTx.Message.SetAddressTables(tables); err != nil {
|
||||
log.Fatalf("set address tables failed: %v", err)
|
||||
}
|
||||
if err := rawTx.Message.ResolveLookups(); err != nil {
|
||||
log.Fatalf("resolve address lookups failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
update := toSubscribeUpdate(tx.Slot, rawTx)
|
||||
signals := shreder.ParseTransaction(update, nil, enableStats)
|
||||
if len(signals) == 0 {
|
||||
fmt.Println("no signals parsed")
|
||||
return
|
||||
}
|
||||
|
||||
printed := false
|
||||
for _, signal := range signals {
|
||||
if signal == nil {
|
||||
continue
|
||||
}
|
||||
if labelFilter != "" && signal.Label != labelFilter {
|
||||
continue
|
||||
}
|
||||
printed = true
|
||||
output, err := json.MarshalIndent(signal, "", " ")
|
||||
if err != nil {
|
||||
log.Fatalf("marshal signal failed: %v", err)
|
||||
}
|
||||
fmt.Println(string(output))
|
||||
}
|
||||
|
||||
if printed {
|
||||
return
|
||||
}
|
||||
|
||||
if labelFilter != "" {
|
||||
fmt.Printf("no %s signal parsed, dump all signals:\n", labelFilter)
|
||||
} else {
|
||||
fmt.Println("no matching signal parsed, dump all signals:")
|
||||
}
|
||||
for _, signal := range signals {
|
||||
if signal == nil {
|
||||
continue
|
||||
}
|
||||
output, err := json.MarshalIndent(signal, "", " ")
|
||||
if err != nil {
|
||||
log.Fatalf("marshal signal failed: %v", err)
|
||||
}
|
||||
fmt.Println(string(output))
|
||||
}
|
||||
}
|
||||
|
||||
func toSubscribeUpdate(slot uint64, tx *solana.Transaction) *shreder.SubscribeUpdateTransaction {
|
||||
signatures := make([][]byte, len(tx.Signatures))
|
||||
for i, sig := range tx.Signatures {
|
||||
signatures[i] = sig[:]
|
||||
}
|
||||
|
||||
accountKeys := make([][]byte, len(tx.Message.AccountKeys))
|
||||
for i, key := range tx.Message.AccountKeys {
|
||||
accountKeys[i] = key[:]
|
||||
}
|
||||
|
||||
instructions := make([]*shreder.CompiledInstruction, len(tx.Message.Instructions))
|
||||
for i, instr := range tx.Message.Instructions {
|
||||
accounts := make([]byte, len(instr.Accounts))
|
||||
for j, acc := range instr.Accounts {
|
||||
accounts[j] = byte(acc)
|
||||
}
|
||||
instructions[i] = &shreder.CompiledInstruction{
|
||||
ProgramIdIndex: uint32(instr.ProgramIDIndex),
|
||||
Accounts: accounts,
|
||||
Data: instr.Data[:],
|
||||
}
|
||||
}
|
||||
|
||||
addressTableLookups := make([]*shreder.MessageAddressTableLookup, len(tx.Message.AddressTableLookups))
|
||||
for i, lookup := range tx.Message.AddressTableLookups {
|
||||
writable := make([]byte, len(lookup.WritableIndexes))
|
||||
for j, idx := range lookup.WritableIndexes {
|
||||
writable[j] = byte(idx)
|
||||
}
|
||||
readonly := make([]byte, len(lookup.ReadonlyIndexes))
|
||||
for j, idx := range lookup.ReadonlyIndexes {
|
||||
readonly[j] = byte(idx)
|
||||
}
|
||||
addressTableLookups[i] = &shreder.MessageAddressTableLookup{
|
||||
AccountKey: lookup.AccountKey[:],
|
||||
WritableIndexes: writable,
|
||||
ReadonlyIndexes: readonly,
|
||||
}
|
||||
}
|
||||
|
||||
return &shreder.SubscribeUpdateTransaction{
|
||||
Transaction: &shreder.Transaction{
|
||||
Signatures: signatures,
|
||||
Message: &shreder.Message{
|
||||
Header: &shreder.MessageHeader{
|
||||
NumRequiredSignatures: uint32(tx.Message.Header.NumRequiredSignatures),
|
||||
NumReadonlySignedAccounts: uint32(tx.Message.Header.NumReadonlySignedAccounts),
|
||||
NumReadonlyUnsignedAccounts: uint32(tx.Message.Header.NumReadonlyUnsignedAccounts),
|
||||
},
|
||||
AccountKeys: accountKeys,
|
||||
RecentBlockhash: nil,
|
||||
Instructions: instructions,
|
||||
Versioned: false,
|
||||
AddressTableLookups: addressTableLookups,
|
||||
},
|
||||
},
|
||||
Slot: slot,
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@ type TableInfo struct {
|
||||
addresses []solana.PublicKey
|
||||
}
|
||||
|
||||
const MaxOverErrCount = 10
|
||||
|
||||
type AddressTables struct {
|
||||
showTableLoaded bool
|
||||
|
||||
@@ -96,7 +98,7 @@ func (at *AddressTables) load(tablePubkey solana.PublicKey) {
|
||||
})
|
||||
}
|
||||
|
||||
func (at *AddressTables) FillToTx(tx *versionedTransaction, tablePubkey solana.PublicKey, idx []uint8) bool {
|
||||
func (at *AddressTables) FillToTx(tx *VersionedTransaction, tablePubkey solana.PublicKey, idx []uint8) bool {
|
||||
addresses, ok := at.tables.Get(tablePubkey)
|
||||
if !ok {
|
||||
at.load(tablePubkey)
|
||||
@@ -112,7 +114,7 @@ func (at *AddressTables) FillToTx(tx *versionedTransaction, tablePubkey solana.P
|
||||
}
|
||||
return false
|
||||
}
|
||||
tx.Message.StaticAccountKeys = append(tx.Message.StaticAccountKeys, addresses.addresses[i])
|
||||
tx.StaticAccountKeys = append(tx.StaticAccountKeys, addresses.addresses[i])
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -129,7 +131,7 @@ func (at *AddressTables) GetAddressTable(tablePubkey solana.PublicKey, idx []uin
|
||||
if int(i) >= len(addresses.addresses) {
|
||||
logger.Error("over loadAddressTable failed", "idx", i, "table", tablePubkey)
|
||||
addresses.overErrCount++
|
||||
if addresses.overErrCount > 10 {
|
||||
if addresses.overErrCount > MaxOverErrCount {
|
||||
at.load(tablePubkey)
|
||||
}
|
||||
break
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
@@ -47,6 +49,8 @@ func BlocksStats(enable bool) ClientOption {
|
||||
}
|
||||
}
|
||||
|
||||
// LogParsedStats enables logging of parsed transaction statistics.
|
||||
// Deprecated: do not use.
|
||||
func LogParsedStats(enable bool) ClientOption {
|
||||
return func(opts *ClientOpts) {
|
||||
opts.logParseStats = enable
|
||||
@@ -113,7 +117,42 @@ func (c *Client) Wait() {
|
||||
logger.Debug("shreder client stopped")
|
||||
}
|
||||
|
||||
func (c *Client) ReadSync(ctx context.Context, txCh chan<- TxSignalBatch) error {
|
||||
func (c *Client) ReadEntriesSync(ctx context.Context, txCh chan<- TxSignal) error {
|
||||
stream, err := c.client.SubscribeEntries(ctx, &SubscribeEntriesRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Debug("reading entries from shreder client")
|
||||
for {
|
||||
response, err := stream.Recv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
slot := response.Slot
|
||||
if c.enableBlockStats {
|
||||
now := time.Now()
|
||||
if c.lastSlotTime.IsZero() || slot > c.lastSlot {
|
||||
if !c.lastSlotTime.IsZero() {
|
||||
logger.Info("block processed", "running", c.pool.Running(), "slot", slot, "prev_slot", c.lastSlot, "delta_ms", now.Sub(c.lastSlotTime).Milliseconds())
|
||||
}
|
||||
c.lastSlot = slot
|
||||
c.lastSlotTime = now
|
||||
}
|
||||
}
|
||||
|
||||
entries := response.Entries
|
||||
|
||||
err = c.pool.Submit(func() {
|
||||
ParseTransactionForEntries(ctx, slot, bytes.NewReader(entries), c.tableLoader, txCh)
|
||||
})
|
||||
if err != nil && errors.Is(err, ants.ErrPoolOverload) {
|
||||
logger.Warn("task pool is full")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) ReadSync(ctx context.Context, txCh chan<- TxSignal) error {
|
||||
stream, err := c.client.SubscribeTransactions(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -152,24 +191,11 @@ func (c *Client) ReadSync(ctx context.Context, txCh chan<- TxSignalBatch) error
|
||||
|
||||
txData := response.Transaction
|
||||
|
||||
err = c.pool.Submit(func() {
|
||||
txBatch := ParseTransaction(txData, c.tableLoader, c.enableParseStats)
|
||||
if len(txBatch) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, tx := range txBatch {
|
||||
tx.Source = "shreder"
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case txCh <- txBatch:
|
||||
}
|
||||
err := c.pool.Submit(func() {
|
||||
ParseTransactionForSubscribe(ctx, txData, c.tableLoader, txCh)
|
||||
})
|
||||
if err != nil {
|
||||
break
|
||||
if err != nil && errors.Is(err, ants.ErrPoolOverload) {
|
||||
logger.Warn("task pool is full")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
8471
pkg/shreder/dlmm_idl.json
Normal file
8471
pkg/shreder/dlmm_idl.json
Normal file
File diff suppressed because it is too large
Load Diff
273
pkg/shreder/entry.go
Normal file
273
pkg/shreder/entry.go
Normal file
@@ -0,0 +1,273 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
type wrapperReader struct {
|
||||
io.Reader
|
||||
}
|
||||
|
||||
func (wr *wrapperReader) ReadU64() (uint64, error) {
|
||||
var buf [8]byte
|
||||
_, err := io.ReadFull(wr, buf[:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint64(buf[0]) | uint64(buf[1])<<8 | uint64(buf[2])<<16 | uint64(buf[3])<<24 |
|
||||
uint64(buf[4])<<32 | uint64(buf[5])<<40 | uint64(buf[6])<<48 | uint64(buf[7])<<56, nil
|
||||
}
|
||||
|
||||
func (wr *wrapperReader) Skip(n int) error {
|
||||
_, err := io.CopyN(io.Discard, wr, int64(n))
|
||||
return err
|
||||
}
|
||||
|
||||
func (wr *wrapperReader) ReadCompactU16() (uint16, error) {
|
||||
ln := 0
|
||||
size := 0
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
var buf [1]byte
|
||||
_, err := io.ReadFull(wr, buf[:])
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("unable to decode compact u16 at %d: %w", i, err)
|
||||
}
|
||||
elem := int(buf[0])
|
||||
if elem == 0 && i != 0 {
|
||||
return 0, fmt.Errorf("alias")
|
||||
}
|
||||
if i == 2 && (elem&0x80) != 0 {
|
||||
return 0, fmt.Errorf("byte three continues")
|
||||
}
|
||||
ln |= (elem & 0x7f) << (size * 7)
|
||||
size++
|
||||
if (elem & 0x80) == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
return uint16(ln), nil
|
||||
}
|
||||
|
||||
func (wr *wrapperReader) ReadByte() (uint8, error) {
|
||||
var buf [1]byte
|
||||
_, err := io.ReadFull(wr, buf[:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return buf[0], nil
|
||||
}
|
||||
|
||||
func ResizeSlice[T any](slice []T, newSize int) {
|
||||
if cap(slice) < newSize {
|
||||
slice = append(slice, make([]T, newSize-len(slice))...)
|
||||
}
|
||||
slice = slice[:newSize]
|
||||
}
|
||||
|
||||
// entriesToVersionedTransaction converts raw entry bytes to versioned transactions.
|
||||
func entriesToVersionedTransaction(slot uint64, data io.Reader, callback func(tx VersionedTransaction)) error {
|
||||
b := &wrapperReader{data}
|
||||
var entriesNumBuf [8]byte
|
||||
n, err := io.ReadFull(b, entriesNumBuf[:])
|
||||
if err != nil {
|
||||
if err == io.EOF && n == 0 {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unable to read entries num: %w", err)
|
||||
}
|
||||
entriesNum := binary.LittleEndian.Uint64(entriesNumBuf[:])
|
||||
//if entriesNum == 0 {
|
||||
// return nil, nil
|
||||
//}
|
||||
if entriesNum > 2048 {
|
||||
return fmt.Errorf("entries num is too large: %d > %d", entriesNum, 1024)
|
||||
}
|
||||
|
||||
for i := uint64(0); i < entriesNum; i++ {
|
||||
err = b.Skip(40)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to skip num_hashes + hash of entry %d: %w", i, err)
|
||||
}
|
||||
numTx, err := b.ReadU64()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read num_transactions of entry %d: %w", i, err)
|
||||
}
|
||||
for j := 0; j < int(numTx); j++ {
|
||||
numSignatures, err := b.ReadCompactU16()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read numSignatures in entry %d, txn %d: %w", i, j, err)
|
||||
}
|
||||
|
||||
// enforce a maximum number of signatures to prevent OOM
|
||||
if numSignatures > 32 {
|
||||
return fmt.Errorf("numSignatures %d exceeds maximum in entry %d, txn %d", numSignatures, i, j)
|
||||
}
|
||||
if numSignatures == 0 {
|
||||
return fmt.Errorf("numSignatures is zero in entry %d, txn %d", i, j)
|
||||
}
|
||||
|
||||
versioned := VersionedTransaction{}
|
||||
versioned.Block = slot
|
||||
versioned.Time = time.Now()
|
||||
ResizeSlice(versioned.Signatures, int(numSignatures))
|
||||
for k := 0; k < int(numSignatures); k++ {
|
||||
_, err = io.ReadFull(b, versioned.Signatures[k][:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read signature in entry %d, txn %d, sig: %d, %w", i, j, k, err)
|
||||
}
|
||||
}
|
||||
|
||||
msgVersion, err := b.ReadByte()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read message version in entry %d, txn %d: %w", i, j, err)
|
||||
}
|
||||
msgVersion = (msgVersion & 0x80) >> 7 // mask to get only the version bits
|
||||
legacy := msgVersion == 0
|
||||
headerSkip := 2
|
||||
if !legacy {
|
||||
headerSkip = 3
|
||||
}
|
||||
// skip msg version, mx.Header+3
|
||||
|
||||
err = b.Skip(headerSkip)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to skip message header in entry %d, txn %d: %w", i, j, err)
|
||||
}
|
||||
|
||||
// read mx.AccountKeys
|
||||
// _, err = r.Read(u16[:])
|
||||
|
||||
numAccountKeys, err := b.ReadCompactU16()
|
||||
// logger.Info("tx", "hash", versioned.Signatures[0].String(), "version", msgVersion)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode numAccountKeys in entry %d, txn %d: %w", i, j, err)
|
||||
}
|
||||
// enforce a maximum number of account keys to prevent OOM
|
||||
if numAccountKeys > 255 {
|
||||
return fmt.Errorf("numAccountKeys %d exceeds maximum in entry %d, txn %d", numAccountKeys, i, j)
|
||||
}
|
||||
|
||||
ResizeSlice(versioned.StaticAccountKeys, int(numAccountKeys))
|
||||
|
||||
for k := 0; k < int(numAccountKeys); k++ {
|
||||
_, err = io.ReadFull(b, versioned.StaticAccountKeys[k][:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read accountKey[%d] in entry %d, txn %d: %w", k, i, j, err)
|
||||
}
|
||||
}
|
||||
|
||||
//skip solana hash
|
||||
err = b.Skip(32)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to skip recentBlockhash in entry %d, txn %d: %w", i, j, err)
|
||||
}
|
||||
|
||||
// read mx.Instructions
|
||||
numInstructions, err := b.ReadCompactU16()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode numInstructions in entry %d, txn %d: %w", i, j, err)
|
||||
}
|
||||
|
||||
// enforce a maximum number of instructions to prevent OOM
|
||||
if numInstructions >= 256 {
|
||||
return fmt.Errorf("numInstructions %d exceeds maximum in entry %d, txn %d, txHash: %s", numInstructions, i, j, versioned.GetSignature())
|
||||
}
|
||||
ResizeSlice(versioned.Instructions, int(numInstructions))
|
||||
for k := 0; k < int(numInstructions); k++ {
|
||||
versioned.Instructions[k].ProgramIDIndex, err = b.ReadByte()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read mx.Instructions[%d].ProgramIDIndex in entry %d, txn %d: %w", k, i, j, err)
|
||||
}
|
||||
numAccounts, err := b.ReadCompactU16()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode numAccounts for ix[%d] in entry %d, txn %d: %w", k, i, j, err)
|
||||
}
|
||||
|
||||
// enforce a maximum number of accounts to prevent OOM
|
||||
if numAccounts >= 256 {
|
||||
return fmt.Errorf("numAccounts %d exceeds maximum for ix[%d] in entry %d, txn %d", numAccounts, k, i, j)
|
||||
}
|
||||
ResizeSlice(versioned.Instructions[k].Accounts, int(numAccounts))
|
||||
|
||||
//.AccountsLen = int(numAccounts)
|
||||
if numAccounts != 0 {
|
||||
_, err = io.ReadFull(b, versioned.Instructions[k].Accounts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read mx.Instructions[%d].Accounts in entry %d, txn %d: %w", k, i, j, err)
|
||||
}
|
||||
}
|
||||
dataLen, err := b.ReadCompactU16()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode mx.Instructions[%d].Data length in entry %d, txn %d: %w", k, i, j, err)
|
||||
}
|
||||
// enforce a maximum data length to prevent OOM
|
||||
if dataLen > 2048 {
|
||||
return fmt.Errorf("mx.Instructions[%d].Data length %d exceeds maximum in entry %d, txn %d, txHash: %s", k, dataLen, i, j, versioned.GetSignature())
|
||||
}
|
||||
ResizeSlice(versioned.Instructions[k].Accounts, int(numAccounts))
|
||||
if dataLen > 0 {
|
||||
_, err = io.ReadFull(b, versioned.Instructions[k].Data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read mx.Instructions[%d].Data in entry %d, txn %d: %w", k, i, j, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !legacy {
|
||||
// read mx.AddressTableLookups
|
||||
numLookups, err := b.ReadByte()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read numAddressTableLookups in entry %d, txn %d: %w", i, j, err)
|
||||
}
|
||||
if numLookups >= 32 {
|
||||
return fmt.Errorf("numLookups %d exceeds maximum in entry %d, txn %d", numLookups, i, j)
|
||||
}
|
||||
ResizeSlice(versioned.AddressTableLookups, int(numLookups))
|
||||
for k := uint8(0); k < numLookups; k++ {
|
||||
_, err = io.ReadFull(b, versioned.AddressTableLookups[k].AccountKey[:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read address table account key for lookup[%d] in entry %d, txn %d: %w", k, i, j, err)
|
||||
}
|
||||
numWritable, err := b.ReadCompactU16()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode numWritableIndexes for lookup[%d] in entry %d, txn %d: %w", k, i, j, err)
|
||||
}
|
||||
// enforce a maximum number of writable indexes to prevent OOM
|
||||
if numWritable >= 256 {
|
||||
return fmt.Errorf("numWritableIndexes %d exceeds maximum for lookup[%d] in entry %d, txn %d", numWritable, k, i, j)
|
||||
}
|
||||
ResizeSlice(versioned.AddressTableLookups[k].WritableIndexes, int(numWritable))
|
||||
if numWritable > 0 {
|
||||
_, err = io.ReadFull(b, versioned.AddressTableLookups[k].WritableIndexes)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read writableIndexes for lookup[%d] in entry %d, txn %d: %w", k, i, j, err)
|
||||
}
|
||||
}
|
||||
|
||||
numReadonly, err := b.ReadCompactU16()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode numReadonlyIndexes for lookup[%d] in entry %d, txn %d: %w", k, i, j, err)
|
||||
}
|
||||
// enforce a maximum number of readonly indexes to prevent OOM
|
||||
if numReadonly > 256 {
|
||||
return fmt.Errorf("numReadonlyIndexes %d exceeds maximum for lookup[%d] in entry %d, txn %d", numReadonly, k, i, j)
|
||||
}
|
||||
ResizeSlice(versioned.AddressTableLookups[k].ReadonlyIndexes, int(numReadonly))
|
||||
if numReadonly > 0 {
|
||||
_, err = io.ReadFull(b, versioned.AddressTableLookups[k].ReadonlyIndexes)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read readonlyIndexes for lookup[%d] in entry %d, txn %d: %w", k, i, j, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
callback(versioned)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
129
pkg/shreder/program_azcz.go
Normal file
129
pkg/shreder/program_azcz.go
Normal file
@@ -0,0 +1,129 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/near/borsh-go"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// has no sell function with pump and pump.amm program
|
||||
var azczProgramID = solana.MustPublicKeyFromBase58("AzcZqCRUQgKEg5FTAgY7JacATABEYCEfMbjXEzspLYFB")
|
||||
var (
|
||||
azczBuyTokensIX = []byte{11}
|
||||
azczAmmBuyTokensIX = []byte{0xf}
|
||||
)
|
||||
|
||||
type azczBuyArgs struct {
|
||||
SolAmount uint64
|
||||
TokenAmount uint64
|
||||
}
|
||||
|
||||
func parseAzczInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) == 0 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
txSignal *TxSignal
|
||||
)
|
||||
if matchMethod(instruction.Data, azczBuyTokensIX) {
|
||||
txSignal, err = parseAzczBuy(tx, instructionIndex)
|
||||
} else if matchMethod(instruction.Data, azczAmmBuyTokensIX) {
|
||||
txSignal, err = parseAzczAmmBuy(tx, instructionIndex)
|
||||
}
|
||||
if txSignal != nil {
|
||||
return TxSignalBatch{txSignal}, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func parseAzczAmmBuy(tx VersionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Accounts) < 8 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[3]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(instruction.Data) < 17 {
|
||||
return nil, fmt.Errorf("data too short for azcz amm buy args, len=%d", len(instruction.Data))
|
||||
}
|
||||
|
||||
solAmount := binary.LittleEndian.Uint64(instruction.Data[1:9])
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "azcz",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: decimal.Zero,
|
||||
Token1Amount: formatSolAmount(solAmount),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: true,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: 0,
|
||||
Token1AmountUint64: solAmount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parseAzczBuy(tx VersionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Accounts) < 8 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[3]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[7]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(instruction.Data) < 2 {
|
||||
return nil, fmt.Errorf("data too short for azcz buy args len=%d", len(instruction.Data))
|
||||
}
|
||||
|
||||
var args azczBuyArgs
|
||||
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "azcz",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(args.TokenAmount),
|
||||
Token1Amount: formatSolAmount(args.SolAmount),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: args.TokenAmount,
|
||||
Token1AmountUint64: args.SolAmount,
|
||||
}, nil
|
||||
}
|
||||
111
pkg/shreder/program_bloomrouter.go
Normal file
111
pkg/shreder/program_bloomrouter.go
Normal file
@@ -0,0 +1,111 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
)
|
||||
|
||||
var bloomRouterProgramID = solana.MustPublicKeyFromBase58("b1oomGGqPKGD6errbyfbVMBuzSC8WtAAYo8MwNafWW1")
|
||||
|
||||
type bloomRouterArgs struct {
|
||||
Side uint16
|
||||
SolAmount uint64
|
||||
TokenAmount uint64
|
||||
}
|
||||
|
||||
func parseBloomRouterInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) < 26 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var (
|
||||
amount uint64
|
||||
sol uint64
|
||||
exactIn bool
|
||||
event string
|
||||
)
|
||||
|
||||
args, err := decodeBloomRouterArgs(instruction.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch args.Side {
|
||||
case 0:
|
||||
event = "buy"
|
||||
exactIn = true
|
||||
case 1:
|
||||
event = "sell"
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
if args.SolAmount > ^uint64(0)/100 {
|
||||
return nil, fmt.Errorf("bloomrouter sol amount overflow")
|
||||
}
|
||||
// bloomrouter SOL amount has 2 fewer decimals than lamports.
|
||||
sol = args.SolAmount * 100
|
||||
amount = args.TokenAmount
|
||||
|
||||
if len(instruction.Accounts) == 0 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
maker, err := tx.GetAccount(int(instruction.Accounts[0]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var (
|
||||
mint solana.PublicKey
|
||||
ok bool
|
||||
)
|
||||
for _, acctIdx := range instruction.Accounts {
|
||||
key, err := tx.GetAccount(int(acctIdx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if strings.HasSuffix(key.String(), "pump") {
|
||||
mint = key
|
||||
ok = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return TxSignalBatch{&TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "bloomrouter",
|
||||
Maker: maker.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(amount),
|
||||
Token1Amount: formatSolAmount(sol),
|
||||
Program: "Pump",
|
||||
Event: event,
|
||||
ExactSOL: exactIn,
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: amount,
|
||||
Token1AmountUint64: sol,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func decodeBloomRouterArgs(data []byte) (bloomRouterArgs, error) {
|
||||
if len(data) < 26 {
|
||||
return bloomRouterArgs{}, fmt.Errorf("data too short for bloomrouter args, len=%d", len(data))
|
||||
}
|
||||
return bloomRouterArgs{
|
||||
Side: binary.BigEndian.Uint16(data[8:10]),
|
||||
SolAmount: binary.LittleEndian.Uint64(data[10:18]),
|
||||
TokenAmount: binary.LittleEndian.Uint64(data[18:26]),
|
||||
}, nil
|
||||
}
|
||||
77
pkg/shreder/program_bobo.go
Normal file
77
pkg/shreder/program_bobo.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/near/borsh-go"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
var boboProgramID = solana.MustPublicKeyFromBase58("BobogA5N2KN2GG4XN3E3rNNRw3L8H1QPXp7QLxGrNHGM")
|
||||
var (
|
||||
boboBuyPumpTokensIX = []byte{0xff, 0xe7, 0x11, 0x53, 0x15, 0xc5, 0xc3, 0xdf}
|
||||
)
|
||||
|
||||
type boboBuyArgs struct {
|
||||
Placeholder1 uint64
|
||||
Placeholder2 uint64
|
||||
SolAmount uint64
|
||||
Placeholder3 uint64
|
||||
Placeholder4 uint64
|
||||
Placeholder5 uint64
|
||||
Placeholder6 uint64
|
||||
}
|
||||
|
||||
func parseBoboInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) == 0 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
if len(instruction.Data) < 8 || !bytes.Equal(instruction.Data[:8], boboBuyPumpTokensIX) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if len(instruction.Accounts) < 8 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
if len(instruction.Data) < 16 {
|
||||
return nil, fmt.Errorf("data too short for bobo buy args, len=%d", len(instruction.Data))
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[2]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[6]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var args boboBuyArgs
|
||||
if err := borsh.Deserialize(&args, instruction.Data[8:]); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||
}
|
||||
|
||||
return TxSignalBatch{&TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "bobo",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: decimal.NewFromInt(1),
|
||||
Token1Amount: formatSolAmount(args.SolAmount),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: 1,
|
||||
Token1AmountUint64: args.SolAmount,
|
||||
}}, nil
|
||||
}
|
||||
111
pkg/shreder/program_bonk.go
Normal file
111
pkg/shreder/program_bonk.go
Normal file
@@ -0,0 +1,111 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
)
|
||||
|
||||
var bonkProgramID = solana.MustPublicKeyFromBase58("BBRouter1cVunVXvkcqeKkZQcBK7ruan37PPm3xzWaXD")
|
||||
var (
|
||||
bonkBuyAndSellTokensIX = []byte{0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a}
|
||||
)
|
||||
|
||||
func parseBonkInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) == 0 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
txSignal *TxSignal
|
||||
)
|
||||
if matchMethod(instruction.Data, bonkBuyAndSellTokensIX) {
|
||||
txSignal, err = parseBonkBuyAndSell(tx, instruction)
|
||||
}
|
||||
if txSignal != nil {
|
||||
return TxSignalBatch{txSignal}, err
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func parseBonkBuyAndSell(tx VersionedTransaction, instruction Instructions) (*TxSignal, error) {
|
||||
if len(instruction.Accounts) < 8 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
programId, err := tx.GetAccount(int(instruction.Accounts[7]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if programId != pumpProgramID {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[0]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
flagAccount, err := tx.GetAccount(int(instruction.Accounts[4]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
amount1 := binary.LittleEndian.Uint64(instruction.Data[17:25])
|
||||
amount2 := binary.LittleEndian.Uint64(instruction.Data[25:33])
|
||||
|
||||
if user == flagAccount {
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[6]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "bonk",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(amount2),
|
||||
Token1Amount: formatSolAmount(amount1),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: true,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: amount2,
|
||||
Token1AmountUint64: amount1,
|
||||
}, nil
|
||||
} else {
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[5]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "bonk",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(amount1),
|
||||
Token1Amount: formatSolAmount(amount2),
|
||||
Program: "Pump",
|
||||
Event: "sell",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: amount1,
|
||||
Token1AmountUint64: amount2,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
@@ -86,28 +86,28 @@ const (
|
||||
drv1Nexus
|
||||
)
|
||||
|
||||
// PumpFunAmmSellOptions { amount: u64, orchestrator_flags: OrchestratorFlags{flags u8} }
|
||||
type pumpFunAmm struct {
|
||||
// PumpFun*Options { amount: u64, orchestrator_flags: OrchestratorFlags{flags u8} }
|
||||
type pumpFunAction struct {
|
||||
Amount uint64
|
||||
Flags uint8
|
||||
}
|
||||
|
||||
type dflowAction struct {
|
||||
Tag uint8
|
||||
Pump *pumpFunAmm
|
||||
Pump *pumpFunAction
|
||||
}
|
||||
|
||||
type dflowSwapParams struct {
|
||||
Actions []dflowAction
|
||||
}
|
||||
|
||||
// bytes to skip for Action variants before/after PumpFunAmmSell; only PumpFunAmmSell is decoded.
|
||||
func skipDflowAction(dec *bin.Decoder, tag uint8) (*pumpFunAmm, error) {
|
||||
// bytes to skip for Action variants; only PumpFun* actions are decoded.
|
||||
func skipDflowAction(dec *bin.Decoder, tag uint8) (*pumpFunAction, error) {
|
||||
switch tag {
|
||||
case ActWhirlpoolsSwap, ActClearpoolsSwap, ActWhirlpoolsSwapV2:
|
||||
// amount u64 + bool + orchestrator_flags u8
|
||||
return nil, dec.SkipBytes(8 + 1 + 1)
|
||||
case ActRaydiumAmmSwap, ActLifinityV2Swap, ActPumpFunBuy, ActPumpFunSell, ActObricV2Swap,
|
||||
case ActRaydiumAmmSwap, ActLifinityV2Swap, ActObricV2Swap,
|
||||
ActSolFiSwap, ActRubiconSwap, ActMeteoraDammV1Swap, ActRaydiumCpSwap,
|
||||
ActStabbleStableSwap, ActTesseraVSwap, ActMeteoraDammV2Swap, ActRaydiumLaunchlabSwap,
|
||||
ActZeroFiSwap, ActAlphaQSwap, ActTokenSwap, ActSolFiV2Swap, ActMozartSwap, ActHeavenSwap,
|
||||
@@ -123,7 +123,7 @@ func skipDflowAction(dec *bin.Decoder, tag uint8) (*pumpFunAmm, error) {
|
||||
case ActGammaSwap:
|
||||
// amount u64 + endorsed bool + orchestrator_flags u8
|
||||
return nil, dec.SkipBytes(8 + 1 + 1)
|
||||
case ActPumpFunAmmSell, ActPumpFunAmmBuy:
|
||||
case ActPumpFunAmmSell, ActPumpFunAmmBuy, ActPumpFunBuy, ActPumpFunSell:
|
||||
amt, err := dec.ReadUint64(binary.LittleEndian)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -132,7 +132,7 @@ func skipDflowAction(dec *bin.Decoder, tag uint8) (*pumpFunAmm, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pumpFunAmm{Amount: amt, Flags: flg}, nil
|
||||
return &pumpFunAction{Amount: amt, Flags: flg}, nil
|
||||
case ActMeteoraDbcSwap:
|
||||
// amount u64 + is_rate_limiter_applied bool + orchestrator_flags u8
|
||||
return nil, dec.SkipBytes(8 + 1 + 1)
|
||||
@@ -232,12 +232,38 @@ func decodeSwap2Params(data []byte) (*dflowSwapParams, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func parseDFlowInstruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||
msg := tx.Message
|
||||
if instructionIndex >= len(msg.Instructions) {
|
||||
func findDflowPumpAmmMints(tx VersionedTransaction, accounts []uint8) (solana.PublicKey, solana.PublicKey, bool, error) {
|
||||
for i, acctIdx := range accounts {
|
||||
key, err := tx.GetAccount(int(acctIdx))
|
||||
if err != nil {
|
||||
return solana.PublicKey{}, solana.PublicKey{}, false, err
|
||||
}
|
||||
if !key.Equals(pumpAmmProgramID) {
|
||||
continue
|
||||
}
|
||||
baseIdx := i + 4
|
||||
quoteIdx := i + 5
|
||||
if baseIdx >= len(accounts) || quoteIdx >= len(accounts) {
|
||||
return solana.PublicKey{}, solana.PublicKey{}, false, nil
|
||||
}
|
||||
baseMint, err := tx.GetAccount(int(accounts[baseIdx]))
|
||||
if err != nil {
|
||||
return solana.PublicKey{}, solana.PublicKey{}, false, err
|
||||
}
|
||||
quoteMint, err := tx.GetAccount(int(accounts[quoteIdx]))
|
||||
if err != nil {
|
||||
return solana.PublicKey{}, solana.PublicKey{}, false, err
|
||||
}
|
||||
return baseMint, quoteMint, true, nil
|
||||
}
|
||||
return solana.PublicKey{}, solana.PublicKey{}, false, nil
|
||||
}
|
||||
|
||||
func parseDFlowInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
ix := msg.Instructions[instructionIndex]
|
||||
ix := tx.Instructions[instructionIndex]
|
||||
if len(ix.Data) < 8 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -262,63 +288,121 @@ func parseDFlowInstruction(tx *versionedTransaction, instructionIndex int) (*TxS
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var pump *pumpFunAmm
|
||||
for _, act := range params.Actions {
|
||||
if act.Tag == ActPumpFunAmmSell && act.Pump != nil {
|
||||
pump = act.Pump
|
||||
break
|
||||
}
|
||||
}
|
||||
if pump == nil {
|
||||
return nil, nil // only care about PumpFunAmmSell
|
||||
}
|
||||
|
||||
// Require WSOL pair when destination mint is provided.
|
||||
var (
|
||||
srcIdx uint8
|
||||
pumpAmmBuy *pumpFunAction
|
||||
pumpAmmSell *pumpFunAction
|
||||
pumpBuy *pumpFunAction
|
||||
pumpSell *pumpFunAction
|
||||
)
|
||||
if len(ix.Accounts) <= 6 {
|
||||
return nil, nil
|
||||
for _, act := range params.Actions {
|
||||
if act.Pump == nil {
|
||||
continue
|
||||
}
|
||||
accounts := ix.Accounts[5:]
|
||||
for i, acctIdx := range accounts {
|
||||
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
switch act.Tag {
|
||||
case ActPumpFunAmmSell:
|
||||
pumpAmmSell = act.Pump
|
||||
case ActPumpFunAmmBuy:
|
||||
pumpAmmBuy = act.Pump
|
||||
case ActPumpFunBuy:
|
||||
pumpBuy = act.Pump
|
||||
case ActPumpFunSell:
|
||||
pumpSell = act.Pump
|
||||
}
|
||||
if key.Equals(pumpAmmProgramID) {
|
||||
srcIdx = uint8(i + 4)
|
||||
break
|
||||
}
|
||||
}
|
||||
if srcIdx == 0 || srcIdx+1 >= uint8(len(accounts)) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
baseMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx]))
|
||||
out := make(TxSignalBatch, 0, 2)
|
||||
if pumpAmmSell != nil || pumpAmmBuy != nil {
|
||||
event := "sell"
|
||||
amt := pumpAmmSell
|
||||
isBuy := false
|
||||
if amt == nil {
|
||||
event = "buy"
|
||||
isBuy = true
|
||||
amt = pumpAmmBuy
|
||||
}
|
||||
baseMint, quoteMint, ok, err := findDflowPumpAmmMints(tx, ix.Accounts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx+1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if ok && quoteMint.Equals(solana.WrappedSol) {
|
||||
var (
|
||||
token0Amount decimal.Decimal
|
||||
token1Amount decimal.Decimal
|
||||
token0AmountUint64 uint64
|
||||
token1AmountUint64 uint64
|
||||
exactSol bool
|
||||
)
|
||||
if isBuy {
|
||||
exactSol = true
|
||||
token1Amount = formatSolAmount(amt.Amount)
|
||||
token1AmountUint64 = amt.Amount
|
||||
} else {
|
||||
token0Amount = formatTokenAmount(amt.Amount)
|
||||
token0AmountUint64 = amt.Amount
|
||||
}
|
||||
if !quoteMint.Equals(solana.WrappedSol) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Build TxSignal
|
||||
sig := &TxSignal{
|
||||
out = append(out, &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Maker: tx.Message.StaticAccountKeys[0].String(),
|
||||
Maker: tx.StaticAccountKeys[0].String(),
|
||||
Program: "PumpAMM",
|
||||
Event: "sell",
|
||||
Event: event,
|
||||
Token0Address: baseMint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(pump.Amount),
|
||||
Token1Amount: decimal.Zero,
|
||||
Token0AmountUint64: uint64(pump.Amount),
|
||||
Token1AmountUint64: 0,
|
||||
Token0Amount: token0Amount,
|
||||
Token1Amount: token1Amount,
|
||||
ExactSOL: exactSol,
|
||||
Token0AmountUint64: token0AmountUint64,
|
||||
Token1AmountUint64: token1AmountUint64,
|
||||
})
|
||||
}
|
||||
return sig, nil
|
||||
}
|
||||
|
||||
if pumpSell != nil || pumpBuy != nil {
|
||||
event := "sell"
|
||||
amt := pumpSell
|
||||
isBuy := false
|
||||
if amt == nil {
|
||||
event = "buy"
|
||||
isBuy = true
|
||||
amt = pumpBuy
|
||||
}
|
||||
mint, ok, err := findPumpFunMint(tx, ix.Accounts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ok {
|
||||
var (
|
||||
token0Amount decimal.Decimal
|
||||
token1Amount decimal.Decimal
|
||||
token0AmountUint64 uint64
|
||||
token1AmountUint64 uint64
|
||||
exactSol bool
|
||||
)
|
||||
if isBuy {
|
||||
exactSol = true
|
||||
token1Amount = formatSolAmount(amt.Amount)
|
||||
token1AmountUint64 = amt.Amount
|
||||
} else {
|
||||
token0Amount = formatTokenAmount(amt.Amount)
|
||||
token0AmountUint64 = amt.Amount
|
||||
}
|
||||
out = append(out, &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Maker: tx.StaticAccountKeys[0].String(),
|
||||
Program: "Pump",
|
||||
Event: event,
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: token0Amount,
|
||||
Token1Amount: token1Amount,
|
||||
ExactSOL: exactSol,
|
||||
Token0AmountUint64: token0AmountUint64,
|
||||
Token1AmountUint64: token1AmountUint64,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if len(out) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
227
pkg/shreder/program_dlmm.go
Normal file
227
pkg/shreder/program_dlmm.go
Normal file
@@ -0,0 +1,227 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// For Metaora dlmm
|
||||
var dlmmProgramID = solana.MustPublicKeyFromBase58("LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo")
|
||||
var (
|
||||
dlmmSwapIX = []byte{248, 198, 158, 145, 225, 117, 135, 200}
|
||||
dlmmSwap2IX = []byte{65, 75, 63, 76, 235, 91, 91, 136}
|
||||
dlmmSwapExactOutIX = []byte{250, 73, 101, 33, 38, 207, 75, 184}
|
||||
dlmmSwapExactOut2IX = []byte{43, 215, 247, 132, 137, 60, 243, 81}
|
||||
dlmmSwapPriceImpactIX = []byte{56, 173, 230, 208, 173, 228, 156, 205}
|
||||
dlmmSwapPriceImpact2IX = []byte{74, 98, 192, 214, 177, 51, 75, 51}
|
||||
)
|
||||
|
||||
type dlmmParsedArgs struct {
|
||||
AmountIn uint64
|
||||
AmountOut uint64
|
||||
ExactIn bool
|
||||
ExactOut bool
|
||||
ActiveBin int32
|
||||
MaxPriceImpactBps uint16
|
||||
}
|
||||
|
||||
func dlmmTokenOrder(tokenX, tokenY solana.PublicKey) (solana.PublicKey, solana.PublicKey) {
|
||||
switch {
|
||||
case tokenX.Equals(solana.WrappedSol):
|
||||
return tokenY, tokenX
|
||||
case tokenY.Equals(solana.WrappedSol):
|
||||
return tokenX, tokenY
|
||||
default:
|
||||
return tokenX, tokenY
|
||||
}
|
||||
}
|
||||
|
||||
func parseDlmmSwapArgs(disc []byte, payload []byte) (*dlmmParsedArgs, error) {
|
||||
switch {
|
||||
case bytes.Equal(disc, dlmmSwapIX), bytes.Equal(disc, dlmmSwap2IX):
|
||||
if len(payload) < 16 {
|
||||
return nil, fmt.Errorf("data too short for dlmm swap args, len=%d", len(payload))
|
||||
}
|
||||
return &dlmmParsedArgs{
|
||||
AmountIn: binary.LittleEndian.Uint64(payload[0:8]),
|
||||
AmountOut: binary.LittleEndian.Uint64(payload[8:16]),
|
||||
ExactIn: true,
|
||||
}, nil
|
||||
case bytes.Equal(disc, dlmmSwapExactOutIX), bytes.Equal(disc, dlmmSwapExactOut2IX):
|
||||
if len(payload) < 16 {
|
||||
return nil, fmt.Errorf("data too short for dlmm swap exact out args, len=%d", len(payload))
|
||||
}
|
||||
return &dlmmParsedArgs{
|
||||
AmountIn: binary.LittleEndian.Uint64(payload[0:8]),
|
||||
AmountOut: binary.LittleEndian.Uint64(payload[8:16]),
|
||||
ExactOut: true,
|
||||
}, nil
|
||||
case bytes.Equal(disc, dlmmSwapPriceImpactIX), bytes.Equal(disc, dlmmSwapPriceImpact2IX):
|
||||
if len(payload) < 11 {
|
||||
return nil, fmt.Errorf("data too short for dlmm swap with price impact args, len=%d", len(payload))
|
||||
}
|
||||
amountIn := binary.LittleEndian.Uint64(payload[0:8])
|
||||
idx := 8
|
||||
if len(payload) < idx+1 {
|
||||
return nil, fmt.Errorf("data too short for dlmm swap with price impact args, len=%d", len(payload))
|
||||
}
|
||||
activeBinTag := payload[idx]
|
||||
idx++
|
||||
var activeBin int32
|
||||
if activeBinTag == 1 {
|
||||
if len(payload) < idx+4 {
|
||||
return nil, fmt.Errorf("data too short for dlmm swap with price impact args, len=%d", len(payload))
|
||||
}
|
||||
activeBin = int32(binary.LittleEndian.Uint32(payload[idx : idx+4]))
|
||||
idx += 4
|
||||
} else if activeBinTag != 0 {
|
||||
return nil, fmt.Errorf("invalid active_id tag %d", activeBinTag)
|
||||
}
|
||||
if len(payload) < idx+2 {
|
||||
return nil, fmt.Errorf("data too short for dlmm swap with price impact args, len=%d", len(payload))
|
||||
}
|
||||
return &dlmmParsedArgs{
|
||||
AmountIn: amountIn,
|
||||
ExactIn: true,
|
||||
ActiveBin: activeBin,
|
||||
MaxPriceImpactBps: binary.LittleEndian.Uint16(payload[idx : idx+2]),
|
||||
}, nil
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
func parseDlmmInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) < 8 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
if len(instruction.Accounts) < 13 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
disc := instruction.Data[:8]
|
||||
payload := instruction.Data[8:]
|
||||
|
||||
args, err := parseDlmmSwapArgs(disc, payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if args == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
userTokenIn, err := tx.GetAccount(int(instruction.Accounts[4]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
userTokenOut, err := tx.GetAccount(int(instruction.Accounts[5]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tokenX, err := tx.GetAccount(int(instruction.Accounts[6]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tokenY, err := tx.GetAccount(int(instruction.Accounts[7]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[10]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tokenXProgram, err := tx.GetAccount(int(instruction.Accounts[11]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tokenYProgram, err := tx.GetAccount(int(instruction.Accounts[12]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
token0Mint, token1Mint := dlmmTokenOrder(tokenX, tokenY)
|
||||
var (
|
||||
token0AmountUint64 uint64
|
||||
token1AmountUint64 uint64
|
||||
)
|
||||
if !tokenX.Equals(solana.WrappedSol) && !tokenY.Equals(solana.WrappedSol) {
|
||||
return nil, nil
|
||||
}
|
||||
wsolProgram := tokenXProgram
|
||||
if tokenY.Equals(solana.WrappedSol) {
|
||||
wsolProgram = tokenYProgram
|
||||
}
|
||||
wsolAta, _, err := findAssociatedTokenAddressWithTokenProgram(user, solana.WrappedSol, wsolProgram)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
wsolIn := userTokenIn.Equals(wsolAta)
|
||||
wsolOut := userTokenOut.Equals(wsolAta)
|
||||
if !wsolIn && !wsolOut {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
event := "sell"
|
||||
if wsolIn {
|
||||
event = "buy"
|
||||
}
|
||||
exactSol := (args.ExactIn && wsolIn) || (args.ExactOut && wsolOut)
|
||||
|
||||
if wsolIn {
|
||||
if args.ExactIn {
|
||||
token1AmountUint64 = args.AmountIn
|
||||
}
|
||||
if args.ExactOut {
|
||||
token0AmountUint64 = args.AmountOut
|
||||
}
|
||||
} else {
|
||||
if args.ExactOut {
|
||||
token1AmountUint64 = args.AmountOut
|
||||
}
|
||||
if args.ExactIn {
|
||||
token0AmountUint64 = args.AmountIn
|
||||
}
|
||||
}
|
||||
|
||||
token0Amount := formatTokenAmount(token0AmountUint64)
|
||||
if token0Mint.Equals(solana.WrappedSol) {
|
||||
token0Amount = formatSolAmount(token0AmountUint64)
|
||||
}
|
||||
token1Amount := decimal.Zero
|
||||
if token1AmountUint64 > 0 {
|
||||
if token1Mint.Equals(solana.WrappedSol) {
|
||||
token1Amount = formatSolAmount(token1AmountUint64)
|
||||
} else {
|
||||
token1Amount = formatTokenAmount(token1AmountUint64)
|
||||
}
|
||||
}
|
||||
|
||||
return TxSignalBatch{&TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "dlmm",
|
||||
Maker: user.String(),
|
||||
Token0Address: token0Mint.String(),
|
||||
Token1Address: token1Mint.String(),
|
||||
Token0Amount: token0Amount,
|
||||
Token1Amount: token1Amount,
|
||||
Program: "MeteoraDLMM",
|
||||
Event: event,
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: exactSol,
|
||||
ActiveBin: args.ActiveBin,
|
||||
MaxPriceImpactBps: args.MaxPriceImpactBps,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: token0AmountUint64,
|
||||
Token1AmountUint64: token1AmountUint64,
|
||||
}}, nil
|
||||
}
|
||||
72
pkg/shreder/program_f5tf.go
Normal file
72
pkg/shreder/program_f5tf.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/near/borsh-go"
|
||||
)
|
||||
|
||||
// only buy function with pump program
|
||||
var f5tfProgramID = solana.MustPublicKeyFromBase58("F5tfvbLog9VdGUPqBDTT8rgXvTTcq7e5UiGnupL1zvBq")
|
||||
var (
|
||||
f5tfBuyTokensIX = []byte{0}
|
||||
)
|
||||
|
||||
type f5tfBuyArgs struct {
|
||||
SolAmount uint64
|
||||
TokenAmount uint64
|
||||
}
|
||||
|
||||
func parseF5tfInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) == 0 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
if !matchMethod(instruction.Data, f5tfBuyTokensIX) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if len(instruction.Accounts) < 7 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[2]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[6]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(instruction.Data) < 2 {
|
||||
return nil, fmt.Errorf("data too short for f5tf buy args len=%d", len(instruction.Data))
|
||||
}
|
||||
|
||||
var args f5tfBuyArgs
|
||||
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||
}
|
||||
|
||||
return TxSignalBatch{&TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "f5tf",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(args.TokenAmount),
|
||||
Token1Amount: formatSolAmount(args.SolAmount),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: args.TokenAmount,
|
||||
Token1AmountUint64: args.SolAmount,
|
||||
}}, nil
|
||||
}
|
||||
71
pkg/shreder/program_fjsz.go
Normal file
71
pkg/shreder/program_fjsz.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/near/borsh-go"
|
||||
)
|
||||
|
||||
// only buy function with pump program
|
||||
var fjszProgramID = solana.MustPublicKeyFromBase58("FJsZbftBqRLfF7uqUKpm4s2goDr6xsQ5Q3mN7AFJB6hK")
|
||||
var (
|
||||
fjszBuyTokensIX = []byte{0xe7, 0x3f, 0x99, 0x83, 0xf3, 0xed, 0xe3, 0x3c}
|
||||
)
|
||||
|
||||
type fjszBuyArgs struct {
|
||||
SolAmount uint64
|
||||
TokenAmount uint64
|
||||
}
|
||||
|
||||
func parseFjszInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) == 0 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
|
||||
if !matchMethod(instruction.Data, fjszBuyTokensIX) {
|
||||
return nil, nil
|
||||
}
|
||||
if len(instruction.Accounts) < 7 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
if len(instruction.Data) < 16 {
|
||||
return nil, fmt.Errorf("data too short for fjzs buy args, len=%d", len(instruction.Data))
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[2]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[6]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var args fjszBuyArgs
|
||||
if err := borsh.Deserialize(&args, instruction.Data[8:]); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||
}
|
||||
|
||||
return TxSignalBatch{&TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "fjsz",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(args.TokenAmount),
|
||||
Token1Amount: formatSolAmount(args.SolAmount),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: args.TokenAmount,
|
||||
Token1AmountUint64: args.SolAmount,
|
||||
}}, nil
|
||||
}
|
||||
218
pkg/shreder/program_flas.go
Normal file
218
pkg/shreder/program_flas.go
Normal file
@@ -0,0 +1,218 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/near/borsh-go"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
var flasProgramID = solana.MustPublicKeyFromBase58("FLASHX8DrLbgeR8FcfNV1F5krxYcYMUdBkrP1EPBtxB9")
|
||||
var (
|
||||
flasBuyTokensIX = []byte{0x00, 0x1, 0x4}
|
||||
flasSellTokensIX = []byte{0x01, 0x1, 0x3}
|
||||
flasAmmBuyTokensIX = []byte{0x00, 0x2, 0x2}
|
||||
flasAmmSellTokensIX = []byte{0x01, 0x2, 0x2}
|
||||
)
|
||||
|
||||
type flasArgs struct {
|
||||
Amount1 uint64
|
||||
Amount2 uint64
|
||||
Placeholder [3]uint8
|
||||
}
|
||||
|
||||
func parseFlasInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) == 0 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
if len(instruction.Data) == 10 && instruction.Data[0] == 1 {
|
||||
return nil, nil
|
||||
}
|
||||
if len(instruction.Data) < 20 {
|
||||
return nil, fmt.Errorf("data too short for args flas instruction, len: %d", len(instruction.Data))
|
||||
}
|
||||
methodData := instruction.Data[17:20]
|
||||
//if !matchMethod(methodData, flasBuyTokensIX) {
|
||||
// return nil, nil
|
||||
//}
|
||||
var (
|
||||
err error
|
||||
txSignal *TxSignal
|
||||
)
|
||||
if matchMethod(methodData, flasBuyTokensIX) {
|
||||
txSignal, err = parseFlasBuy(tx, instructionIndex)
|
||||
} else if matchMethod(methodData, flasSellTokensIX) {
|
||||
txSignal, err = parseFlasSell(tx, instructionIndex)
|
||||
} else if matchMethod(methodData, flasAmmBuyTokensIX) {
|
||||
txSignal, err = parseFlasAmmBuy(tx, instructionIndex)
|
||||
} else if matchMethod(methodData, flasAmmSellTokensIX) {
|
||||
txSignal, err = parseFlasAmmSell(tx, instructionIndex)
|
||||
}
|
||||
if txSignal != nil {
|
||||
return TxSignalBatch{txSignal}, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func parseFlasAmmSell(tx VersionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Accounts) < 10 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[9]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var args flasArgs
|
||||
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "flas",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(args.Amount1),
|
||||
Token1Amount: formatSolAmount(args.Amount2),
|
||||
Program: "PumpAMM",
|
||||
Event: "sell",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: args.Amount1,
|
||||
Token1AmountUint64: args.Amount2,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parseFlasAmmBuy(tx VersionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Accounts) < 10 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[9]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var args flasArgs
|
||||
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "flas",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: decimal.Zero,
|
||||
Token1Amount: formatSolAmount(args.Amount1),
|
||||
Program: "PumpAMM",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: true,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: 0,
|
||||
Token1AmountUint64: args.Amount1,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parseFlasSell(tx VersionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Accounts) < 9 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[8]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var args flasArgs
|
||||
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "flas",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(args.Amount1),
|
||||
Token1Amount: formatSolAmount(args.Amount2),
|
||||
Program: "Pump",
|
||||
Event: "sell",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: args.Amount1,
|
||||
Token1AmountUint64: args.Amount2,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parseFlasBuy(tx VersionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Accounts) < 9 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[8]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[0]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(instruction.Data) > 20 {
|
||||
instruction.Data = instruction.Data[:20]
|
||||
}
|
||||
var args flasArgs
|
||||
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "flas",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(args.Amount2),
|
||||
Token1Amount: formatSolAmount(args.Amount1),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: true,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: args.Amount2,
|
||||
Token1AmountUint64: args.Amount1,
|
||||
}, nil
|
||||
}
|
||||
78
pkg/shreder/program_gmgn.go
Normal file
78
pkg/shreder/program_gmgn.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
)
|
||||
|
||||
var gmgnProgramID = solana.MustPublicKeyFromBase58("GMgnVFR8Jb39LoXsEVzb3DvBy3ywCmdmJquHUy1Lrkqb")
|
||||
var (
|
||||
gmgnBuyTokensIX = []byte{0x66, 0x06, 0x3d, 0x12, 0x01, 0xda, 0xeb, 0xea}
|
||||
)
|
||||
|
||||
func parseGMGNInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) == 0 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
if len(instruction.Data) < 8 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
txSignal *TxSignal
|
||||
)
|
||||
if matchMethod(instruction.Data, gmgnBuyTokensIX) {
|
||||
txSignal, err = parseGMGNBuy(tx, instruction)
|
||||
}
|
||||
if txSignal != nil {
|
||||
return TxSignalBatch{txSignal}, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func parseGMGNBuy(tx VersionedTransaction, instruction Instructions) (*TxSignal, error) {
|
||||
if len(instruction.Accounts) < 8 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
if len(instruction.Data) < 24 {
|
||||
return nil, fmt.Errorf("data too short for gmgn buy args, len=%d", len(instruction.Data))
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[2]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[6]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
solAmount := binary.LittleEndian.Uint64(instruction.Data[8:16])
|
||||
tokenAmount := binary.LittleEndian.Uint64(instruction.Data[16:24])
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "gmgn",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(tokenAmount),
|
||||
Token1Amount: formatSolAmount(solAmount),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: true,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: tokenAmount,
|
||||
Token1AmountUint64: solAmount,
|
||||
}, nil
|
||||
}
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
jupiterV6ProgramID = solana.MustPublicKeyFromBase58("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4")
|
||||
|
||||
jupiterRouteV2 = []byte{187, 100, 250, 204, 49, 196, 175, 20}
|
||||
jupiterExactOutRouteV2 = []byte{157, 138, 184, 82, 21, 244, 243, 36}
|
||||
|
||||
@@ -22,6 +24,10 @@ var (
|
||||
|
||||
jupiterSharedAccountsExactOutRouteV2 = []byte{53, 96, 229, 202, 216, 187, 250, 24}
|
||||
jupiterSharedAccountsRouteV2 = []byte{209, 152, 83, 147, 124, 254, 216, 233}
|
||||
|
||||
usdcMint = solana.MustPublicKeyFromBase58("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")
|
||||
usd1Mint = solana.MustPublicKeyFromBase58("USD1ttGY1N17NEEHLmELoaybftRBUSErhqYiQzvEmuB")
|
||||
usdtMint = solana.MustPublicKeyFromBase58("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB")
|
||||
)
|
||||
|
||||
type Side uint8
|
||||
@@ -819,14 +825,37 @@ func decodeJupiterV6SharedAccountsRouteV2Arg(data []byte) (*JupiterV6SharedAccou
|
||||
return &JupiterV6SharedAccountsRouteV2Arg{ID: id, In: inAmt, QuotedOut: quotedOut, Slippage: slippage, PlatFee: pf, PosSlip: pos, RoutePlan: plan}, nil
|
||||
}
|
||||
|
||||
func isInputIdx0(idx uint8) bool {
|
||||
return idx == 0
|
||||
}
|
||||
|
||||
func isPumpSwapSellKind(kind SwapKind) bool {
|
||||
switch kind {
|
||||
case PumpSwapSell, PumpSwapSellV2, PumpSwapSellV3:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func isPumpSwapBuyKind(kind SwapKind) bool {
|
||||
switch kind {
|
||||
case PumpSwapBuy, PumpSwapBuyV2, PumpSwapBuyV3:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
if !isInputIdx0(step.InputIdx) || !isPumpSwapSellKind(step.Swap.Kind) {
|
||||
continue
|
||||
}
|
||||
i++
|
||||
if ret > 0 {
|
||||
// multiple pumpSwapSell at inputIdx=0? should not happen
|
||||
@@ -834,7 +863,6 @@ func pumpSwapSellAtIdx0(amount uint64, plan []RoutePlanStep) (uint64, int) {
|
||||
}
|
||||
ret += amount * uint64(step.Percent) / 100
|
||||
}
|
||||
}
|
||||
return ret, i
|
||||
}
|
||||
|
||||
@@ -844,28 +872,389 @@ func pumpSwapSellAtIdx0V2(amount uint64, plan []RoutePlanStepV2) (uint64, int) {
|
||||
i int
|
||||
)
|
||||
for _, step := range plan {
|
||||
if step.InputIdx == 0 &&
|
||||
(step.Swap.Kind == PumpSwapSell || step.Swap.Kind == PumpSwapSellV2 || step.Swap.Kind == PumpSwapSellV3) {
|
||||
if !isInputIdx0(step.InputIdx) || !isPumpSwapSellKind(step.Swap.Kind) {
|
||||
continue
|
||||
}
|
||||
i++
|
||||
if ret > 0 {
|
||||
// multiple pumpSwapSell at inputIdx=0? should not happen
|
||||
|
||||
return 0, i
|
||||
}
|
||||
ret += amount * uint64(step.Bps) / 10000
|
||||
}
|
||||
}
|
||||
return ret, i
|
||||
}
|
||||
|
||||
type pumpSwapBuyMatch struct {
|
||||
InAmount uint64
|
||||
OutAmount uint64
|
||||
}
|
||||
|
||||
func pumpSwapBuyAtIdx0(in uint64, out uint64, plan []RoutePlanStep) (pumpSwapBuyMatch, int) {
|
||||
var (
|
||||
ret pumpSwapBuyMatch
|
||||
count int
|
||||
)
|
||||
for _, step := range plan {
|
||||
if !isInputIdx0(step.InputIdx) || !isPumpSwapBuyKind(step.Swap.Kind) {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
if count > 1 {
|
||||
return pumpSwapBuyMatch{}, count
|
||||
}
|
||||
ret.InAmount = in * uint64(step.Percent) / 100
|
||||
if step.Percent == 100 {
|
||||
ret.OutAmount = out
|
||||
}
|
||||
}
|
||||
return ret, count
|
||||
}
|
||||
|
||||
func pumpSwapBuyAtIdx0V2(in uint64, out uint64, plan []RoutePlanStepV2) (pumpSwapBuyMatch, int) {
|
||||
var (
|
||||
ret pumpSwapBuyMatch
|
||||
count int
|
||||
)
|
||||
for _, step := range plan {
|
||||
if !isInputIdx0(step.InputIdx) || !isPumpSwapBuyKind(step.Swap.Kind) {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
if count > 1 {
|
||||
return pumpSwapBuyMatch{}, count
|
||||
}
|
||||
ret.InAmount = in * uint64(step.Bps) / 10000
|
||||
if step.Bps == 10000 {
|
||||
ret.OutAmount = out
|
||||
}
|
||||
}
|
||||
return ret, count
|
||||
}
|
||||
|
||||
type pumpWrappedMatch struct {
|
||||
IsBuy bool
|
||||
InAmount uint64
|
||||
OutAmount uint64
|
||||
}
|
||||
|
||||
func isPumpWrappedBuy(kind SwapKind) bool {
|
||||
switch kind {
|
||||
case PumpWrappedBuy, PumpWrappedBuyV2, PumpWrappedBuyV3, PumpWrappedBuyV4:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func isPumpWrappedSell(kind SwapKind) bool {
|
||||
switch kind {
|
||||
case PumpWrappedSell, PumpWrappedSellV2, PumpWrappedSellV3, PumpWrappedSellV4:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func isPumpWrappedKind(kind SwapKind) bool {
|
||||
return isPumpWrappedBuy(kind) || isPumpWrappedSell(kind)
|
||||
}
|
||||
|
||||
func isStableMint(mint solana.PublicKey) bool {
|
||||
if mint.Equals(usdcMint) {
|
||||
return true
|
||||
}
|
||||
if mint.Equals(usd1Mint) {
|
||||
return true
|
||||
}
|
||||
if mint.Equals(usdtMint) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isToken1Mint(mint solana.PublicKey) bool {
|
||||
return mint.Equals(solana.WrappedSol) || mint.Equals(solana.SystemProgramID) || isStableMint(mint)
|
||||
}
|
||||
|
||||
func isJupiterV6Token1RequiredDisc(disc []byte) bool {
|
||||
return bytes.Equal(disc, jupiterRouteV2) ||
|
||||
bytes.Equal(disc, jupiterSharedAccountsRouteV2) ||
|
||||
bytes.Equal(disc, jupiterExactOutRouteV2) ||
|
||||
bytes.Equal(disc, jupiterSharedAccountsExactOutRouteV2) ||
|
||||
bytes.Equal(disc, jupiterSharedAccountsRoute) ||
|
||||
bytes.Equal(disc, jupiterSharedAccountsExactOutRoute)
|
||||
}
|
||||
|
||||
func pumpWrappedAtIdx0(in uint64, out uint64, plan []RoutePlanStep) (pumpWrappedMatch, int) {
|
||||
var (
|
||||
ret pumpWrappedMatch
|
||||
count int
|
||||
)
|
||||
for _, step := range plan {
|
||||
if !isInputIdx0(step.InputIdx) {
|
||||
continue
|
||||
}
|
||||
if !isPumpWrappedKind(step.Swap.Kind) {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
if count > 1 {
|
||||
return pumpWrappedMatch{}, count
|
||||
}
|
||||
ret.IsBuy = isPumpWrappedBuy(step.Swap.Kind)
|
||||
ret.InAmount = in * uint64(step.Percent) / 100
|
||||
if step.Percent == 100 {
|
||||
ret.OutAmount = out
|
||||
}
|
||||
}
|
||||
return ret, count
|
||||
}
|
||||
|
||||
func pumpWrappedAtIdx0V2(in uint64, out uint64, plan []RoutePlanStepV2) (pumpWrappedMatch, int) {
|
||||
var (
|
||||
ret pumpWrappedMatch
|
||||
count int
|
||||
)
|
||||
for _, step := range plan {
|
||||
if !isInputIdx0(step.InputIdx) {
|
||||
continue
|
||||
}
|
||||
if !isPumpWrappedKind(step.Swap.Kind) {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
if count > 1 {
|
||||
return pumpWrappedMatch{}, count
|
||||
}
|
||||
ret.IsBuy = isPumpWrappedBuy(step.Swap.Kind)
|
||||
ret.InAmount = in * uint64(step.Bps) / 10000
|
||||
if step.Bps == 10000 {
|
||||
ret.OutAmount = out
|
||||
}
|
||||
}
|
||||
return ret, count
|
||||
}
|
||||
|
||||
func pumpWrappedAny(plan []RoutePlanStep) (pumpWrappedMatch, int) {
|
||||
var (
|
||||
ret pumpWrappedMatch
|
||||
count int
|
||||
)
|
||||
for _, step := range plan {
|
||||
if !isPumpWrappedKind(step.Swap.Kind) {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
if count > 1 {
|
||||
return pumpWrappedMatch{}, count
|
||||
}
|
||||
ret.IsBuy = isPumpWrappedBuy(step.Swap.Kind)
|
||||
}
|
||||
return ret, count
|
||||
}
|
||||
|
||||
func pumpWrappedAnyV2(plan []RoutePlanStepV2) (pumpWrappedMatch, int) {
|
||||
var (
|
||||
ret pumpWrappedMatch
|
||||
count int
|
||||
)
|
||||
for _, step := range plan {
|
||||
if !isPumpWrappedKind(step.Swap.Kind) {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
if count > 1 {
|
||||
return pumpWrappedMatch{}, count
|
||||
}
|
||||
ret.IsBuy = isPumpWrappedBuy(step.Swap.Kind)
|
||||
}
|
||||
return ret, count
|
||||
}
|
||||
|
||||
func pumpRoutePlanStats(in uint64, out uint64, plan []RoutePlanStep, includeInput bool) (uint64, int, pumpSwapBuyMatch, int, pumpWrappedMatch, int, pumpWrappedMatch, int) {
|
||||
var (
|
||||
inputAmount uint64
|
||||
planCount int
|
||||
)
|
||||
if includeInput {
|
||||
inputAmount, planCount = pumpSwapSellAtIdx0(in, plan)
|
||||
}
|
||||
buySwap, buySwapCnt := pumpSwapBuyAtIdx0(in, out, plan)
|
||||
wrapped, wrappedCnt := pumpWrappedAtIdx0(in, out, plan)
|
||||
wrappedAny, wrappedAnyC := pumpWrappedAny(plan)
|
||||
return inputAmount, planCount, buySwap, buySwapCnt, wrapped, wrappedCnt, wrappedAny, wrappedAnyC
|
||||
}
|
||||
|
||||
func pumpRoutePlanStatsV2(in uint64, out uint64, plan []RoutePlanStepV2, includeInput bool) (uint64, int, pumpSwapBuyMatch, int, pumpWrappedMatch, int, pumpWrappedMatch, int) {
|
||||
var (
|
||||
inputAmount uint64
|
||||
planCount int
|
||||
)
|
||||
if includeInput {
|
||||
inputAmount, planCount = pumpSwapSellAtIdx0V2(in, plan)
|
||||
}
|
||||
buySwap, buySwapCnt := pumpSwapBuyAtIdx0V2(in, out, plan)
|
||||
wrapped, wrappedCnt := pumpWrappedAtIdx0V2(in, out, plan)
|
||||
wrappedAny, wrappedAnyC := pumpWrappedAnyV2(plan)
|
||||
return inputAmount, planCount, buySwap, buySwapCnt, wrapped, wrappedCnt, wrappedAny, wrappedAnyC
|
||||
}
|
||||
|
||||
func parseJupiterPumpAmmRoute(tx VersionedTransaction, instruction Instructions, in uint64, out uint64, plan []RoutePlanStep) (*TxSignal, bool, error) {
|
||||
var (
|
||||
isBuy bool
|
||||
isSell bool
|
||||
count int
|
||||
)
|
||||
for _, step := range plan {
|
||||
if !isInputIdx0(step.InputIdx) {
|
||||
continue
|
||||
}
|
||||
if isPumpSwapSellKind(step.Swap.Kind) {
|
||||
isSell = true
|
||||
count++
|
||||
} else if isPumpSwapBuyKind(step.Swap.Kind) {
|
||||
isBuy = true
|
||||
count++
|
||||
}
|
||||
}
|
||||
if count == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
if count > 1 || (isBuy && isSell) {
|
||||
logger.Warn("pumpamm route at inputIdx=0: multiple instances found", "tx", tx.Signatures[0].String(), "planCount", count)
|
||||
return nil, true, nil
|
||||
}
|
||||
if len(instruction.Accounts) < 14 {
|
||||
return nil, true, nil
|
||||
}
|
||||
token0Key, err := tx.GetAccount(int(instruction.Accounts[13]))
|
||||
if err != nil {
|
||||
return nil, true, err
|
||||
}
|
||||
if isSell {
|
||||
token0Amount := decimal.Zero
|
||||
if in > 0 {
|
||||
token0Amount = formatTokenAmount(in)
|
||||
}
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Maker: tx.StaticAccountKeys[0].String(),
|
||||
Token0Address: token0Key.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: token0Amount,
|
||||
Token1Amount: decimal.Zero,
|
||||
Program: "PumpAMM",
|
||||
Event: "sell",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: in,
|
||||
Token1AmountUint64: 0,
|
||||
}, true, nil
|
||||
}
|
||||
if len(instruction.Accounts) < 15 {
|
||||
return nil, true, nil
|
||||
}
|
||||
wsolKey, err := tx.GetAccount(int(instruction.Accounts[14]))
|
||||
if err != nil {
|
||||
return nil, true, err
|
||||
}
|
||||
if !wsolKey.Equals(solana.WrappedSol) {
|
||||
return nil, true, nil
|
||||
}
|
||||
token0Amount := decimal.Zero
|
||||
if out > 0 {
|
||||
token0Amount = formatTokenAmount(out)
|
||||
}
|
||||
token1Amount := decimal.Zero
|
||||
if in > 0 {
|
||||
token1Amount = formatSolAmount(in)
|
||||
}
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Maker: tx.StaticAccountKeys[0].String(),
|
||||
Token0Address: token0Key.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: token0Amount,
|
||||
Token1Amount: token1Amount,
|
||||
Program: "PumpAMM",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: true,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: out,
|
||||
Token1AmountUint64: in,
|
||||
}, true, nil
|
||||
}
|
||||
|
||||
func findPumpFunMint(tx VersionedTransaction, accounts []uint8) (solana.PublicKey, bool, error) {
|
||||
for i, acctIdx := range accounts {
|
||||
key, err := tx.GetAccount(int(acctIdx))
|
||||
if err != nil {
|
||||
return solana.PublicKey{}, false, err
|
||||
}
|
||||
if !key.Equals(pumpProgramID) {
|
||||
continue
|
||||
}
|
||||
if i+3 >= len(accounts) {
|
||||
return solana.PublicKey{}, false, nil
|
||||
}
|
||||
mint, err := tx.GetAccount(int(accounts[i+3]))
|
||||
if err != nil {
|
||||
return solana.PublicKey{}, false, err
|
||||
}
|
||||
return mint, true, nil
|
||||
}
|
||||
return solana.PublicKey{}, false, nil
|
||||
}
|
||||
|
||||
func jupiterV6SourceDestMints(msg VersionedTransaction, instruction Instructions, disc []byte) (solana.PublicKey, solana.PublicKey, bool, error) {
|
||||
switch {
|
||||
case bytes.Equal(disc, jupiterRouteV2),
|
||||
bytes.Equal(disc, jupiterSharedAccountsRouteV2),
|
||||
bytes.Equal(disc, jupiterExactOutRouteV2),
|
||||
bytes.Equal(disc, jupiterSharedAccountsExactOutRouteV2):
|
||||
if len(instruction.Accounts) < 5 {
|
||||
return solana.PublicKey{}, solana.PublicKey{}, false, fmt.Errorf("not enough accounts for jupiter v6 v2 instruction")
|
||||
}
|
||||
src, err := msg.GetAccount(int(instruction.Accounts[3]))
|
||||
if err != nil {
|
||||
return solana.PublicKey{}, solana.PublicKey{}, false, err
|
||||
}
|
||||
dst, err := msg.GetAccount(int(instruction.Accounts[4]))
|
||||
if err != nil {
|
||||
return solana.PublicKey{}, solana.PublicKey{}, false, err
|
||||
}
|
||||
return src, dst, true, nil
|
||||
case bytes.Equal(disc, jupiterSharedAccountsRoute),
|
||||
bytes.Equal(disc, jupiterSharedAccountsExactOutRoute):
|
||||
if len(instruction.Accounts) < 9 {
|
||||
return solana.PublicKey{}, solana.PublicKey{}, false, fmt.Errorf("not enough accounts for jupiter v6 shared accounts instruction")
|
||||
}
|
||||
src, err := msg.GetAccount(int(instruction.Accounts[7]))
|
||||
if err != nil {
|
||||
return solana.PublicKey{}, solana.PublicKey{}, false, err
|
||||
}
|
||||
dst, err := msg.GetAccount(int(instruction.Accounts[8]))
|
||||
if err != nil {
|
||||
return solana.PublicKey{}, solana.PublicKey{}, false, err
|
||||
}
|
||||
return src, dst, true, nil
|
||||
default:
|
||||
return solana.PublicKey{}, solana.PublicKey{}, false, nil
|
||||
}
|
||||
}
|
||||
|
||||
// only decodes inputIdx = 0 container pumpSwap instructions for now
|
||||
func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||
msg := tx.Message
|
||||
if instructionIndex >= len(msg.Instructions) {
|
||||
func parseJupiterV6Instruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := msg.Instructions[instructionIndex]
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) == 0 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
@@ -878,7 +1267,16 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
||||
var (
|
||||
sourceMint solana.PublicKey
|
||||
inputAmount uint64
|
||||
routeIn uint64
|
||||
routeOut uint64
|
||||
planCount int
|
||||
buySwap pumpSwapBuyMatch
|
||||
buySwapCnt int
|
||||
wrapped pumpWrappedMatch
|
||||
wrappedCnt int
|
||||
wrappedAny pumpWrappedMatch
|
||||
wrappedAnyC int
|
||||
exactOut bool
|
||||
err error
|
||||
)
|
||||
|
||||
@@ -890,47 +1288,347 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
inputAmount, planCount = pumpSwapSellAtIdx0V2(args.In, args.Plan)
|
||||
inputAmount, planCount, buySwap, buySwapCnt, wrapped, wrappedCnt, wrappedAny, wrappedAnyC = pumpRoutePlanStatsV2(args.In, args.Out, args.Plan, true)
|
||||
routeIn = args.In
|
||||
routeOut = args.Out
|
||||
case bytes.Equal(disc, jupiterSharedAccountsRouteV2):
|
||||
args, err := decodeJupiterV6SharedAccountsRouteV2Arg(instruction.Data[8:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
inputAmount, planCount = pumpSwapSellAtIdx0V2(args.In, args.RoutePlan)
|
||||
inputAmount, planCount, buySwap, buySwapCnt, wrapped, wrappedCnt, wrappedAny, wrappedAnyC = pumpRoutePlanStatsV2(args.In, args.QuotedOut, args.RoutePlan, true)
|
||||
routeIn = args.In
|
||||
routeOut = args.QuotedOut
|
||||
case bytes.Equal(disc, jupiterExactOutRouteV2):
|
||||
args, err := decodeJupiterV6ExactOutRouteV2Arg(instruction.Data[8:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exactOut = true
|
||||
inputAmount, planCount, buySwap, buySwapCnt, wrapped, wrappedCnt, wrappedAny, wrappedAnyC = pumpRoutePlanStatsV2(args.QuotedIn, args.Out, args.RoutePlan, false)
|
||||
routeIn = args.QuotedIn
|
||||
routeOut = args.Out
|
||||
case bytes.Equal(disc, jupiterSharedAccountsExactOutRouteV2):
|
||||
args, err := decodeJupiterV6SharedAccountsExactOutRouteV2Arg(instruction.Data[8:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exactOut = true
|
||||
inputAmount, planCount, buySwap, buySwapCnt, wrapped, wrappedCnt, wrappedAny, wrappedAnyC = pumpRoutePlanStatsV2(args.QuotedIn, args.Out, args.RoutePlan, false)
|
||||
routeIn = args.QuotedIn
|
||||
routeOut = args.Out
|
||||
case bytes.Equal(disc, jupiterRoute):
|
||||
args, err := decodeJupiterV6RouteArg(instruction.Data[8:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = args
|
||||
inputAmount, planCount = pumpSwapSellAtIdx0(args.In, args.Plan)
|
||||
sig, handled, err := parseJupiterPumpAmmRoute(tx, instruction, args.In, args.QuotedOut, args.Plan)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if handled {
|
||||
return TxSignalBatch{sig}, nil
|
||||
}
|
||||
inputAmount, planCount, buySwap, buySwapCnt, wrapped, wrappedCnt, wrappedAny, wrappedAnyC = pumpRoutePlanStats(args.In, args.QuotedOut, args.Plan, true)
|
||||
routeIn = args.In
|
||||
routeOut = args.QuotedOut
|
||||
case bytes.Equal(disc, jupiterSharedAccountsExactOutRoute):
|
||||
args, err := decodeJupiterV6SharedAccountsExactOutRouteArg(instruction.Data[8:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exactOut = true
|
||||
inputAmount, planCount, buySwap, buySwapCnt, wrapped, wrappedCnt, wrappedAny, wrappedAnyC = pumpRoutePlanStats(args.QuotedIn, args.Out, args.Plan, false)
|
||||
routeIn = args.QuotedIn
|
||||
routeOut = args.Out
|
||||
case bytes.Equal(disc, jupiterSharedAccountsRoute):
|
||||
args, err := decodeJupiterV6SharedAccountsRouteArg(instruction.Data[8:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = args
|
||||
inputAmount, planCount = pumpSwapSellAtIdx0(args.In, args.Plan)
|
||||
inputAmount, planCount, buySwap, buySwapCnt, wrapped, wrappedCnt, wrappedAny, wrappedAnyC = pumpRoutePlanStats(args.In, args.QuotedOut, args.Plan, true)
|
||||
routeIn = args.In
|
||||
routeOut = args.QuotedOut
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
if bytes.Equal(disc, jupiterRoute) {
|
||||
if len(instruction.Accounts) < 13 {
|
||||
return nil, nil
|
||||
}
|
||||
destMint, err := tx.GetAccount(int(instruction.Accounts[5]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isToken1Mint(destMint) {
|
||||
pumpKey, err := tx.GetAccount(int(instruction.Accounts[9]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !pumpKey.Equals(pumpProgramID) {
|
||||
return nil, nil
|
||||
}
|
||||
token0Mint, err := tx.GetAccount(int(instruction.Accounts[12]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
token0Amount := decimal.Zero
|
||||
if routeIn > 0 {
|
||||
token0Amount = formatTokenAmount(routeIn)
|
||||
}
|
||||
return TxSignalBatch{&TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Maker: tx.StaticAccountKeys[0].String(),
|
||||
Token0Address: token0Mint.String(),
|
||||
Token1Address: destMint.String(),
|
||||
Token0Amount: token0Amount,
|
||||
Token1Amount: decimal.Zero,
|
||||
Program: "Pump",
|
||||
Event: "sell",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: routeIn,
|
||||
Token1AmountUint64: 0,
|
||||
}}, nil
|
||||
}
|
||||
token0Amount := decimal.Zero
|
||||
if routeOut > 0 {
|
||||
token0Amount = formatTokenAmount(routeOut)
|
||||
}
|
||||
return TxSignalBatch{&TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Maker: tx.StaticAccountKeys[0].String(),
|
||||
Token0Address: destMint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: token0Amount,
|
||||
Token1Amount: decimal.Zero,
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: routeOut,
|
||||
Token1AmountUint64: 0,
|
||||
}}, nil
|
||||
}
|
||||
if wrappedCnt > 1 {
|
||||
logger.Warn("pumpWrapped at inputIdx=0: multiple instances found", "tx", tx.Signatures[0].String(), "planCount", wrappedCnt)
|
||||
}
|
||||
if wrapped.InAmount > 0 {
|
||||
mint, ok, err := findPumpFunMint(tx, instruction.Accounts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
token1Mint := solana.WrappedSol
|
||||
token1IsStable := false
|
||||
srcMint, dstMint, ok, err := jupiterV6SourceDestMints(tx, instruction, disc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isJupiterV6Token1RequiredDisc(disc) {
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
if !isToken1Mint(srcMint) && !isToken1Mint(dstMint) {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
if ok {
|
||||
if srcMint.Equals(solana.WrappedSol) || dstMint.Equals(solana.WrappedSol) {
|
||||
token1Mint = solana.WrappedSol
|
||||
} else if isStableMint(srcMint) {
|
||||
token1Mint = srcMint
|
||||
token1IsStable = true
|
||||
} else if isStableMint(dstMint) {
|
||||
token1Mint = dstMint
|
||||
token1IsStable = true
|
||||
}
|
||||
}
|
||||
event := "sell"
|
||||
exactSol := false
|
||||
var (
|
||||
token0AmountUint64 uint64
|
||||
token1AmountUint64 uint64
|
||||
)
|
||||
if wrapped.IsBuy {
|
||||
event = "buy"
|
||||
exactSol = !exactOut
|
||||
token0AmountUint64 = wrapped.OutAmount
|
||||
token1AmountUint64 = wrapped.InAmount
|
||||
} else {
|
||||
exactSol = exactOut && wrapped.OutAmount > 0
|
||||
token0AmountUint64 = wrapped.InAmount
|
||||
token1AmountUint64 = wrapped.OutAmount
|
||||
}
|
||||
token0Amount := decimal.Zero
|
||||
if token0AmountUint64 > 0 {
|
||||
token0Amount = formatTokenAmount(token0AmountUint64)
|
||||
}
|
||||
token1Amount := decimal.Zero
|
||||
if token1AmountUint64 > 0 {
|
||||
if token1IsStable {
|
||||
token1Amount = formatTokenAmount(token1AmountUint64)
|
||||
} else {
|
||||
token1Amount = formatSolAmount(token1AmountUint64)
|
||||
}
|
||||
}
|
||||
token1Address := wsolMint
|
||||
if token1IsStable {
|
||||
token1Address = token1Mint.String()
|
||||
}
|
||||
return TxSignalBatch{&TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Maker: tx.StaticAccountKeys[0].String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: token1Address,
|
||||
Token0Amount: token0Amount,
|
||||
Token1Amount: token1Amount,
|
||||
Program: "Pump",
|
||||
Event: event,
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: exactSol,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: token0AmountUint64,
|
||||
Token1AmountUint64: token1AmountUint64,
|
||||
}}, nil
|
||||
}
|
||||
if wrappedAnyC > 1 {
|
||||
logger.Warn("pumpWrapped at inputIdx!=0: multiple instances found", "tx", tx.Signatures[0].String(), "planCount", wrappedAnyC)
|
||||
}
|
||||
if wrappedAnyC == 1 && routeIn > 0 && routeOut > 0 {
|
||||
mint, ok, err := findPumpFunMint(tx, instruction.Accounts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
token1Mint := solana.WrappedSol
|
||||
token1IsStable := false
|
||||
srcMint, dstMint, ok, err := jupiterV6SourceDestMints(tx, instruction, disc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isJupiterV6Token1RequiredDisc(disc) {
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
if !isToken1Mint(srcMint) && !isToken1Mint(dstMint) {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
if ok {
|
||||
if srcMint.Equals(solana.WrappedSol) || dstMint.Equals(solana.WrappedSol) {
|
||||
token1Mint = solana.WrappedSol
|
||||
} else if isStableMint(srcMint) {
|
||||
token1Mint = srcMint
|
||||
token1IsStable = true
|
||||
} else if isStableMint(dstMint) {
|
||||
token1Mint = dstMint
|
||||
token1IsStable = true
|
||||
}
|
||||
}
|
||||
event := "sell"
|
||||
exactSol := false
|
||||
var (
|
||||
token0AmountUint64 uint64
|
||||
token1AmountUint64 uint64
|
||||
)
|
||||
if wrappedAny.IsBuy {
|
||||
event = "buy"
|
||||
exactSol = !exactOut
|
||||
token0AmountUint64 = routeOut
|
||||
token1AmountUint64 = routeIn
|
||||
} else {
|
||||
exactSol = exactOut && routeOut > 0
|
||||
token0AmountUint64 = routeIn
|
||||
token1AmountUint64 = routeOut
|
||||
}
|
||||
token0Amount := decimal.Zero
|
||||
if token0AmountUint64 > 0 {
|
||||
token0Amount = formatTokenAmount(token0AmountUint64)
|
||||
}
|
||||
token1Amount := decimal.Zero
|
||||
if token1AmountUint64 > 0 {
|
||||
if token1IsStable {
|
||||
token1Amount = formatTokenAmount(token1AmountUint64)
|
||||
} else {
|
||||
token1Amount = formatSolAmount(token1AmountUint64)
|
||||
}
|
||||
}
|
||||
token1Address := wsolMint
|
||||
if token1IsStable {
|
||||
token1Address = token1Mint.String()
|
||||
}
|
||||
return TxSignalBatch{&TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Maker: tx.StaticAccountKeys[0].String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: token1Address,
|
||||
Token0Amount: token0Amount,
|
||||
Token1Amount: token1Amount,
|
||||
Program: "Pump",
|
||||
Event: event,
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: exactSol,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: token0AmountUint64,
|
||||
Token1AmountUint64: token1AmountUint64,
|
||||
}}, 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 buySwapCnt > 1 {
|
||||
// multiple pumpSwapBuy at inputIdx=0? should not happen
|
||||
logger.Warn("pumpSwapBuy at inputIdx=0: multiple instances found", "tx", tx.Signatures[0].String(), "planCount", buySwapCnt)
|
||||
}
|
||||
hasSell := inputAmount > 0
|
||||
hasBuy := buySwap.InAmount > 0
|
||||
if hasSell && hasBuy {
|
||||
logger.Warn("pumpSwap buy/sell at inputIdx=0: both found", "tx", tx.Signatures[0].String(), "sellCount", planCount, "buyCount", buySwapCnt)
|
||||
return nil, nil
|
||||
}
|
||||
if !hasSell && !hasBuy {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var (
|
||||
baseMint solana.PublicKey
|
||||
quoteMint solana.PublicKey
|
||||
destMint solana.PublicKey
|
||||
destMintOK bool
|
||||
sourceMintOK bool
|
||||
)
|
||||
|
||||
// existing mint extraction logic only valid for route_v2/ exact_out_route_v2. Keep it but guard.
|
||||
if bytes.Equal(disc, jupiterRouteV2) || bytes.Equal(disc, jupiterSharedAccountsRouteV2) {
|
||||
if bytes.Equal(disc, jupiterRouteV2) ||
|
||||
bytes.Equal(disc, jupiterSharedAccountsRouteV2) ||
|
||||
bytes.Equal(disc, jupiterExactOutRouteV2) ||
|
||||
bytes.Equal(disc, jupiterSharedAccountsExactOutRouteV2) {
|
||||
if len(instruction.Accounts) < 6 {
|
||||
return nil, fmt.Errorf("not enough accounts for jupiter v6 v2 instruction")
|
||||
}
|
||||
sourceMint, err = getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[3]))
|
||||
sourceMint, err = tx.GetAccount(int(instruction.Accounts[3]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
destMint, err = tx.GetAccount(int(instruction.Accounts[4]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
destMintOK = true
|
||||
sourceMintOK = true
|
||||
|
||||
var (
|
||||
srcIdx uint8
|
||||
@@ -940,7 +1638,7 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
||||
}
|
||||
accounts := instruction.Accounts[8:]
|
||||
for i, acctIdx := range accounts {
|
||||
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||
key, err := tx.GetAccount(int(acctIdx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -953,14 +1651,11 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
baseMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx]))
|
||||
baseMint, err = tx.GetAccount(int(accounts[srcIdx]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !sourceMint.Equals(baseMint) {
|
||||
return nil, nil
|
||||
}
|
||||
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx+1]))
|
||||
quoteMint, err = tx.GetAccount(int(accounts[srcIdx+1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -968,14 +1663,20 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
} else if bytes.Equal(disc, jupiterSharedAccountsRoute) {
|
||||
} else if bytes.Equal(disc, jupiterSharedAccountsRoute) || bytes.Equal(disc, jupiterSharedAccountsExactOutRoute) {
|
||||
if len(instruction.Accounts) < 12 {
|
||||
return nil, fmt.Errorf("not enough accounts for jupiter v6 jupiterSharedAccountsRoute instruction")
|
||||
}
|
||||
sourceMint, err = getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[7]))
|
||||
sourceMint, err = tx.GetAccount(int(instruction.Accounts[7]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
destMint, err = tx.GetAccount(int(instruction.Accounts[8]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
destMintOK = true
|
||||
sourceMintOK = true
|
||||
var (
|
||||
srcIdx uint8
|
||||
)
|
||||
@@ -984,7 +1685,7 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
||||
}
|
||||
accounts := instruction.Accounts[11:]
|
||||
for i, acctIdx := range accounts {
|
||||
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||
key, err := tx.GetAccount(int(acctIdx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -997,15 +1698,12 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
baseMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx]))
|
||||
baseMint, err = tx.GetAccount(int(accounts[srcIdx]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !sourceMint.Equals(baseMint) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx+1]))
|
||||
quoteMint, err = tx.GetAccount(int(accounts[srcIdx+1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1022,7 +1720,7 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
||||
|
||||
accounts := instruction.Accounts[9:]
|
||||
for i, acctIdx := range accounts {
|
||||
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||
key, err := tx.GetAccount(int(acctIdx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1034,38 +1732,75 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
||||
if srcIdx == 0 || srcIdx+1 >= uint8(len(accounts)) {
|
||||
return nil, nil
|
||||
}
|
||||
sourceMint, err = getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx]))
|
||||
baseMint, err = tx.GetAccount(int(accounts[srcIdx]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx+1]))
|
||||
quoteMint, err = tx.GetAccount(int(accounts[srcIdx+1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !quoteMint.Equals(solana.WrappedSol) {
|
||||
return nil, nil
|
||||
}
|
||||
sourceMint = baseMint
|
||||
}
|
||||
|
||||
if hasSell {
|
||||
if sourceMintOK && !sourceMint.Equals(baseMint) {
|
||||
return nil, nil
|
||||
}
|
||||
} else {
|
||||
if !sourceMintOK {
|
||||
return nil, nil
|
||||
}
|
||||
if !sourceMint.Equals(solana.WrappedSol) && !sourceMint.Equals(solana.SystemProgramID) {
|
||||
return nil, nil
|
||||
}
|
||||
if destMintOK && !destMint.Equals(baseMint) {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
event := "sell"
|
||||
exactSol := false
|
||||
token0AmountUint64 := inputAmount
|
||||
token1AmountUint64 := uint64(0)
|
||||
if hasBuy {
|
||||
event = "buy"
|
||||
exactSol = !exactOut
|
||||
token0AmountUint64 = buySwap.OutAmount
|
||||
token1AmountUint64 = buySwap.InAmount
|
||||
}
|
||||
|
||||
token0Amount := decimal.Zero
|
||||
if token0AmountUint64 > 0 {
|
||||
token0Amount = formatTokenAmount(token0AmountUint64)
|
||||
}
|
||||
token1Amount := decimal.Zero
|
||||
if token1AmountUint64 > 0 {
|
||||
token1Amount = formatSolAmount(token1AmountUint64)
|
||||
}
|
||||
|
||||
signal := &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Maker: tx.Message.StaticAccountKeys[0].String(),
|
||||
Token0Address: sourceMint.String(),
|
||||
Maker: tx.StaticAccountKeys[0].String(),
|
||||
Token0Address: baseMint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(inputAmount),
|
||||
Token1Amount: decimal.Zero,
|
||||
Token0Amount: token0Amount,
|
||||
Token1Amount: token1Amount,
|
||||
Program: "PumpAMM",
|
||||
Event: "sell",
|
||||
Event: event,
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: false,
|
||||
ExactSOL: exactSol,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: inputAmount,
|
||||
Token1AmountUint64: 0,
|
||||
Token0AmountUint64: token0AmountUint64,
|
||||
Token1AmountUint64: token1AmountUint64,
|
||||
}
|
||||
|
||||
return signal, nil
|
||||
return TxSignalBatch{signal}, nil
|
||||
}
|
||||
|
||||
// keep lints happy if solana-go isn't referenced elsewhere in this file for build tags
|
||||
@@ -245,12 +245,11 @@ type OkxV2SwapScorch struct {
|
||||
Id [16]byte
|
||||
}
|
||||
|
||||
func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||
msg := tx.Message
|
||||
if instructionIndex >= len(msg.Instructions) {
|
||||
func parseOkxDexRouteV2Instruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
ix := msg.Instructions[instructionIndex]
|
||||
ix := tx.Instructions[instructionIndex]
|
||||
if len(ix.Data) < 8 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -310,7 +309,7 @@ func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex in
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
srcMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(ix.Accounts[3]))
|
||||
srcMint, err := tx.GetAccount(int(ix.Accounts[3]))
|
||||
|
||||
var (
|
||||
srcIdx uint8
|
||||
@@ -320,7 +319,7 @@ func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex in
|
||||
}
|
||||
accounts := ix.Accounts[14:]
|
||||
for i, acctIdx := range accounts {
|
||||
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||
key, err := tx.GetAccount(int(acctIdx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -333,7 +332,7 @@ func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex in
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
baseMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx]))
|
||||
baseMint, err := tx.GetAccount(int(accounts[srcIdx]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -341,7 +340,7 @@ func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex in
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx+1]))
|
||||
quoteMint, err := tx.GetAccount(int(accounts[srcIdx+1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -349,9 +348,9 @@ func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex in
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
return TxSignalBatch{&TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Maker: tx.Message.StaticAccountKeys[0].String(),
|
||||
Maker: tx.StaticAccountKeys[0].String(),
|
||||
Token0Address: baseMint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(inputAmount),
|
||||
@@ -364,5 +363,5 @@ func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex in
|
||||
ExactSOL: false,
|
||||
Token0AmountUint64: inputAmount,
|
||||
Token1AmountUint64: 0,
|
||||
}, nil
|
||||
}}, nil
|
||||
}
|
||||
156
pkg/shreder/program_photon.go
Normal file
156
pkg/shreder/program_photon.go
Normal file
@@ -0,0 +1,156 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/near/borsh-go"
|
||||
)
|
||||
|
||||
// only pump.fun function
|
||||
var photonProgramID = solana.MustPublicKeyFromBase58("BSfD6SHZigAfDWSjzD5Q41jw8LmKwtmjskPH9XW1mrRW")
|
||||
var (
|
||||
photonBuyPumpTokensIX = []byte{0x52, 0xe1, 0x77, 0xe7, 0x4e, 0x1d, 0x2d, 0x46}
|
||||
photonSwapPumpAmmIX = []byte{0x2c, 0x77, 0xaf, 0xda, 0xc7, 0x4d, 0xc4, 0xeb}
|
||||
)
|
||||
|
||||
type photonBuyPumpArgs struct {
|
||||
Timestamp uint64
|
||||
SolAmount uint64
|
||||
TokenAmount uint64
|
||||
Fee uint64
|
||||
}
|
||||
|
||||
type photonSwapPumpAmmArgs struct {
|
||||
FromAmount uint64
|
||||
ToAmount uint64
|
||||
}
|
||||
|
||||
func parsePhotonInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) == 0 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
if len(instruction.Data) < 8 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
txSignal *TxSignal
|
||||
)
|
||||
switch {
|
||||
case bytes.Equal(instruction.Data[:8], photonBuyPumpTokensIX):
|
||||
txSignal, err = parsePhotonBuy(tx, instruction)
|
||||
case bytes.Equal(instruction.Data[:8], photonSwapPumpAmmIX):
|
||||
txSignal, err = parsePhotonSwap(tx, instruction)
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
if txSignal != nil {
|
||||
return TxSignalBatch{txSignal}, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func parsePhotonBuy(tx VersionedTransaction, instruction Instructions) (*TxSignal, error) {
|
||||
if len(instruction.Accounts) < 8 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
if len(instruction.Data) < 16 {
|
||||
return nil, fmt.Errorf("data too short for photon buy args, len=%d", len(instruction.Data))
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[3]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[7]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var args photonBuyPumpArgs
|
||||
if err := borsh.Deserialize(&args, instruction.Data[8:]); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||
}
|
||||
|
||||
solAmount := args.SolAmount * (100000000 - 1234568) / 100000000
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "photon",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(args.TokenAmount),
|
||||
Token1Amount: formatSolAmount(solAmount),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: true,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: args.TokenAmount,
|
||||
Token1AmountUint64: solAmount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parsePhotonSwap(tx VersionedTransaction, instruction Instructions) (*TxSignal, error) {
|
||||
if len(instruction.Accounts) < 8 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
if len(instruction.Data) < 16 {
|
||||
return nil, fmt.Errorf("data too short for swap args for photon. len=%d", len(instruction.Data))
|
||||
}
|
||||
|
||||
base, err := tx.GetAccount(int(instruction.Accounts[3]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
quote, err := tx.GetAccount(int(instruction.Accounts[4]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !quote.Equals(solana.WrappedSol) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
buyer, err := tx.GetAccount(int(instruction.Accounts[1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var args photonSwapPumpAmmArgs
|
||||
if err := borsh.Deserialize(&args, instruction.Data[8:]); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse swap pump amm tokens args: %w", err)
|
||||
}
|
||||
|
||||
if args.FromAmount > args.ToAmount {
|
||||
// sell; ignore
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
solAmount := args.FromAmount * (100000000 - 1234568) / 100000000
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "photon",
|
||||
Maker: buyer.String(),
|
||||
Token0Address: base.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(args.ToAmount),
|
||||
Token1Amount: formatSolAmount(solAmount),
|
||||
Program: "PumpAMM",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: args.ToAmount,
|
||||
Token1AmountUint64: solAmount,
|
||||
}, nil
|
||||
}
|
||||
256
pkg/shreder/program_pump.go
Normal file
256
pkg/shreder/program_pump.go
Normal file
@@ -0,0 +1,256 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/near/borsh-go"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
var pumpProgramID = solana.MustPublicKeyFromBase58("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P")
|
||||
var (
|
||||
pumpCreateCoinIX = []byte{24, 30, 200, 40, 5, 28, 7, 119}
|
||||
pumpCreateCoinV2IX = []byte{214, 144, 76, 236, 95, 139, 49, 180}
|
||||
pumpExtendedSellIX = []byte{51, 230, 133, 164, 1, 127, 131, 173}
|
||||
pumpBuyTokensIX = []byte{102, 6, 61, 18, 1, 218, 235, 234}
|
||||
pumpBuyV2TokensIX = []byte{56, 252, 116, 8, 158, 223, 205, 95}
|
||||
)
|
||||
|
||||
type pumpExtendedSellArgs struct {
|
||||
Amount uint64
|
||||
MinSolOutput uint64
|
||||
}
|
||||
|
||||
type pumpBuyArgs struct {
|
||||
Amount uint64
|
||||
MaxSolCost uint64
|
||||
}
|
||||
|
||||
type pumpCreateCoinV2Args struct {
|
||||
Name string
|
||||
Symbol string
|
||||
Uri string
|
||||
Creator solana.PublicKey
|
||||
IsMayhemMode bool
|
||||
}
|
||||
|
||||
func parsePumpInstruction(msg VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
|
||||
instruction := msg.Instructions[instructionIndex]
|
||||
if len(instruction.Data) < 8 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
txSignal *TxSignal
|
||||
)
|
||||
if matchMethod(instruction.Data[0:8], pumpBuyV2TokensIX) || matchMethod(instruction.Data[0:8], pumpBuyTokensIX) {
|
||||
txSignal, err = parsePumpBuy(msg, instruction)
|
||||
} else if matchMethod(instruction.Data[0:8], pumpExtendedSellIX) {
|
||||
txSignal, err = parsePumpSell(msg, instruction)
|
||||
} else if matchMethod(instruction.Data[0:8], pumpCreateCoinIX) {
|
||||
txSignal, err = parsePumpCreate(msg, instruction)
|
||||
} else if matchMethod(instruction.Data[0:8], pumpCreateCoinV2IX) {
|
||||
txSignal, err = parsePumpCreateV2(msg, instruction)
|
||||
}
|
||||
if txSignal != nil {
|
||||
return TxSignalBatch{txSignal}, err
|
||||
}
|
||||
return nil, err
|
||||
|
||||
}
|
||||
|
||||
func parsePumpCreate(tx VersionedTransaction, instruction Instructions) (*TxSignal, error) {
|
||||
if len(instruction.Accounts) < 8 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[0]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
creator, err := tx.GetAccount(int(instruction.Accounts[7]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "pump",
|
||||
Maker: creator.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: decimal.Zero,
|
||||
Token1Amount: decimal.Zero,
|
||||
Program: "Pump",
|
||||
Event: "create",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: 0,
|
||||
Token1AmountUint64: 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parsePumpCreateV2(tx VersionedTransaction, instruction Instructions) (*TxSignal, error) {
|
||||
if len(instruction.Accounts) < 8 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
if len(instruction.Data) < 8 {
|
||||
return nil, fmt.Errorf("data too short for pump create v2 args, len=%d", len(instruction.Data))
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[0]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tokenProgramKey, err := tx.GetAccount(int(instruction.Accounts[7]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var args pumpCreateCoinV2Args
|
||||
if err := borsh.Deserialize(&args, instruction.Data[8:]); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse create coin v2 args: %w", err)
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "pump",
|
||||
Maker: args.Creator.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: decimal.Zero,
|
||||
Token1Amount: decimal.Zero,
|
||||
Program: "Pump",
|
||||
Event: "create",
|
||||
IsToken2022: tokenProgramKey.String() != tokenProgram,
|
||||
IsMayhemMode: args.IsMayhemMode,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: 0,
|
||||
Token1AmountUint64: 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func decodePumpBuyArgs(data []byte) (uint64, uint64, error) {
|
||||
if len(data) < 9 {
|
||||
return 0, 0, fmt.Errorf("data too short for pump buy buy args, len=%d", len(data))
|
||||
}
|
||||
|
||||
var args pumpBuyArgs
|
||||
if err := borsh.Deserialize(&args, data[8:]); err == nil {
|
||||
return args.Amount, args.MaxSolCost, nil
|
||||
}
|
||||
|
||||
if len(data) >= 24 {
|
||||
amount := binary.LittleEndian.Uint64(data[8:16])
|
||||
maxSol := binary.LittleEndian.Uint64(data[16:24])
|
||||
return amount, maxSol, nil
|
||||
}
|
||||
|
||||
return 0, 0, fmt.Errorf("failed to parse buy tokens args")
|
||||
}
|
||||
|
||||
func parsePumpBuy(tx VersionedTransaction, instruction Instructions) (*TxSignal, error) {
|
||||
amount, sol, err := decodePumpBuyArgs(instruction.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exactIn := false
|
||||
if matchMethod(instruction.Data, pumpBuyV2TokensIX) {
|
||||
temp := amount
|
||||
amount = sol
|
||||
sol = temp
|
||||
exactIn = true
|
||||
}
|
||||
|
||||
if len(instruction.Accounts) < 7 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[2]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buyer, err := tx.GetAccount(int(instruction.Accounts[6]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "pump",
|
||||
Maker: buyer.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(amount),
|
||||
Token1Amount: formatSolAmount(sol),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
ExactSOL: exactIn,
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: amount,
|
||||
Token1AmountUint64: sol,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func decodePumpSellArgs(data []byte) (uint64, uint64, error) {
|
||||
if len(data) < 9 {
|
||||
return 0, 0, fmt.Errorf("data too short for pump sell sell args, len=%d", len(data))
|
||||
}
|
||||
|
||||
var args pumpExtendedSellArgs
|
||||
if err := borsh.Deserialize(&args, data[8:]); err == nil {
|
||||
return args.Amount, args.MinSolOutput, nil
|
||||
}
|
||||
|
||||
if len(data) >= 24 {
|
||||
amount := binary.LittleEndian.Uint64(data[8:16])
|
||||
minSol := binary.LittleEndian.Uint64(data[16:24])
|
||||
return amount, minSol, nil
|
||||
}
|
||||
|
||||
return 0, 0, fmt.Errorf("failed to parse sell tokens args")
|
||||
}
|
||||
|
||||
func parsePumpSell(tx VersionedTransaction, instruction Instructions) (*TxSignal, error) {
|
||||
amount, minSol, err := decodePumpSellArgs(instruction.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(instruction.Accounts) < 7 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[2]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
seller, err := tx.GetAccount(int(instruction.Accounts[6]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "pump",
|
||||
Maker: seller.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(amount),
|
||||
Token1Amount: formatSolAmount(minSol),
|
||||
Program: "Pump",
|
||||
Event: "sell",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: amount,
|
||||
Token1AmountUint64: minSol,
|
||||
}, nil
|
||||
}
|
||||
166
pkg/shreder/program_pumpamm.go
Normal file
166
pkg/shreder/program_pumpamm.go
Normal file
@@ -0,0 +1,166 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/near/borsh-go"
|
||||
)
|
||||
|
||||
var pumpAmmProgramID = solana.MustPublicKeyFromBase58("pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA")
|
||||
var (
|
||||
pumpAmmBuyTokensV2IX = []byte{198, 46, 21, 82, 180, 217, 232, 112}
|
||||
pumpAmmBuyTokensIX = []byte{102, 6, 61, 18, 1, 218, 235, 234}
|
||||
pumpAmmSellTokensIX = []byte{51, 230, 133, 164, 1, 127, 131, 173}
|
||||
)
|
||||
|
||||
type pumpAmmBuyArgs struct {
|
||||
Amount uint64
|
||||
MaxSolCost uint64
|
||||
}
|
||||
|
||||
func parsePumpAmmInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) == 0 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
txSignal *TxSignal
|
||||
)
|
||||
if matchMethod(instruction.Data, pumpAmmBuyTokensIX) || matchMethod(instruction.Data, pumpAmmBuyTokensV2IX) {
|
||||
txSignal, err = parsePumpAmmBuy(tx, instruction)
|
||||
} else if matchMethod(instruction.Data, pumpAmmSellTokensIX) {
|
||||
txSignal, err = parsePumpAmmSell(tx, instruction)
|
||||
}
|
||||
|
||||
if txSignal != nil {
|
||||
return TxSignalBatch{txSignal}, err
|
||||
}
|
||||
|
||||
return nil, err
|
||||
|
||||
}
|
||||
|
||||
func decodePumpAmmBuyArgs(data []byte) (uint64, uint64, error) {
|
||||
if len(data) < 9 {
|
||||
return 0, 0, fmt.Errorf("data too short for pump amm buy args, len=%d", len(data))
|
||||
}
|
||||
|
||||
var args pumpAmmBuyArgs
|
||||
if err := borsh.Deserialize(&args, data[8:]); err == nil {
|
||||
return args.Amount, args.MaxSolCost, nil
|
||||
}
|
||||
|
||||
if len(data) >= 24 {
|
||||
amount := binary.LittleEndian.Uint64(data[8:16])
|
||||
maxSol := binary.LittleEndian.Uint64(data[16:24])
|
||||
return amount, maxSol, nil
|
||||
}
|
||||
|
||||
return 0, 0, fmt.Errorf("failed to parse buy tokens args")
|
||||
}
|
||||
|
||||
func parsePumpAmmBuy(tx VersionedTransaction, instruction Instructions) (*TxSignal, error) {
|
||||
amount, maxSol, err := decodePumpAmmBuyArgs(instruction.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exactIn := false
|
||||
if matchMethod(instruction.Data, pumpAmmBuyTokensV2IX) {
|
||||
temp := amount
|
||||
amount = maxSol
|
||||
maxSol = temp
|
||||
exactIn = true
|
||||
}
|
||||
|
||||
if len(instruction.Accounts) < 7 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
base, err := tx.GetAccount(int(instruction.Accounts[3]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
quote, err := tx.GetAccount(int(instruction.Accounts[4]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !quote.Equals(solana.WrappedSol) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
buyer, err := tx.GetAccount(int(instruction.Accounts[1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "pumpamm",
|
||||
Maker: buyer.String(),
|
||||
Token0Address: base.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(amount),
|
||||
Token1Amount: formatSolAmount(maxSol),
|
||||
Program: "PumpAMM",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: exactIn,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: amount,
|
||||
Token1AmountUint64: maxSol,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parsePumpAmmSell(tx VersionedTransaction, instruction Instructions) (*TxSignal, error) {
|
||||
amount, minSol, err := decodePumpAmmBuyArgs(instruction.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(instruction.Accounts) < 7 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
base, err := tx.GetAccount(int(instruction.Accounts[3]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
quote, err := tx.GetAccount(int(instruction.Accounts[4]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !quote.Equals(solana.WrappedSol) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
buyer, err := tx.GetAccount(int(instruction.Accounts[1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "pumpamm",
|
||||
Maker: buyer.String(),
|
||||
Token0Address: base.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(amount),
|
||||
Token1Amount: formatSolAmount(minSol),
|
||||
Program: "PumpAMM",
|
||||
Event: "sell",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: amount,
|
||||
Token1AmountUint64: minSol,
|
||||
}, nil
|
||||
}
|
||||
166
pkg/shreder/program_qtkv.go
Normal file
166
pkg/shreder/program_qtkv.go
Normal file
@@ -0,0 +1,166 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/near/borsh-go"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
var qtkvProgramID = solana.MustPublicKeyFromBase58("qtkvapJEvRWWrB7i5K6RaA1kvq5x3qmMKZ98ad71XQ7")
|
||||
var (
|
||||
qtkvBuyTokensIX = []byte{0x02}
|
||||
qtkvSellTokensIX = []byte{0x03}
|
||||
qtkvAmmSellTokensIX = []byte{0x05}
|
||||
)
|
||||
|
||||
type qtkvBuyArgs struct {
|
||||
Placeholder uint64
|
||||
TokenNumber uint64
|
||||
SolAmount uint64
|
||||
}
|
||||
|
||||
func parseQtkvInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) == 0 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
txSignal *TxSignal
|
||||
)
|
||||
if matchMethod(instruction.Data, qtkvBuyTokensIX) {
|
||||
txSignal, err = parseQtkvBuy(tx, instructionIndex)
|
||||
} else if matchMethod(instruction.Data, qtkvAmmSellTokensIX) {
|
||||
txSignal, err = parseQtkvAmmSell(tx, instructionIndex)
|
||||
} else if matchMethod(instruction.Data, qtkvSellTokensIX) {
|
||||
txSignal, err = parseQtkvSell(tx, instructionIndex)
|
||||
}
|
||||
|
||||
if txSignal != nil {
|
||||
return TxSignalBatch{txSignal}, err
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func parseQtkvSell(tx VersionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Accounts) < 11 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
if len(instruction.Data) < 24 {
|
||||
return nil, fmt.Errorf("data too short for qtkv sell args, len=%d", len(instruction.Data))
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[10]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[0]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// in sell, sol amount is not directly provided, so we set it to 0
|
||||
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,
|
||||
Token0Amount: formatTokenAmount(tokenAmount),
|
||||
Token1Amount: decimal.Zero,
|
||||
Program: "Pump",
|
||||
Event: "sell",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: tokenAmount,
|
||||
Token1AmountUint64: 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parseQtkvAmmSell(tx VersionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Accounts) < 11 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
if len(instruction.Data) < 24 {
|
||||
return nil, fmt.Errorf("data too short for qtkv amm sell args, len=%d", len(instruction.Data))
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[10]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[0]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// in sell, sol amount is not directly provided, so we set it to 0
|
||||
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,
|
||||
Token0Amount: formatTokenAmount(tokenAmount),
|
||||
Token1Amount: decimal.Zero,
|
||||
Program: "PumpAMM",
|
||||
Event: "sell",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: tokenAmount,
|
||||
Token1AmountUint64: 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parseQtkvBuy(tx VersionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Accounts) < 8 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[3]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[0]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var args qtkvBuyArgs
|
||||
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||||
}
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "qtkv",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(args.TokenNumber),
|
||||
Token1Amount: formatSolAmount(args.SolAmount),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: args.TokenNumber,
|
||||
Token1AmountUint64: args.SolAmount,
|
||||
}, nil
|
||||
}
|
||||
155
pkg/shreder/program_term.go
Normal file
155
pkg/shreder/program_term.go
Normal file
@@ -0,0 +1,155 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
)
|
||||
|
||||
var terminalProgramID = solana.MustPublicKeyFromBase58("term9YPb9mzAsABaqN71A4xdbxHmpBNZavpBiQKZzN3")
|
||||
var (
|
||||
terminalBuyTokensIX = []byte{0xa6, 0x54, 0x14, 0x96, 0x9f, 0x77, 0x59, 0xca}
|
||||
terminalSellTokensIX = []byte{0xbe, 0x84, 0xa2, 0x96, 0x93, 0x7c, 0xf8, 0x6b}
|
||||
terminalAmmSellTokensIX = []byte{0x40, 0x64, 0x97, 0xb9, 0x16, 0xfa, 0xec, 0xb1}
|
||||
)
|
||||
|
||||
func parseTermInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) == 0 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
if len(instruction.Data) < 24 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
txSignal *TxSignal
|
||||
)
|
||||
switch {
|
||||
case bytes.Equal(instruction.Data[:8], terminalBuyTokensIX):
|
||||
txSignal, err = parseTermBuy(tx, instruction)
|
||||
case bytes.Equal(instruction.Data[:8], terminalSellTokensIX):
|
||||
txSignal, err = parseTermSell(tx, instruction)
|
||||
case bytes.Equal(instruction.Data[:8], terminalAmmSellTokensIX):
|
||||
txSignal, err = parseTermAmmSell(tx, instruction)
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if txSignal != nil {
|
||||
return TxSignalBatch{txSignal}, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func parseTermAmmSell(tx VersionedTransaction, instruction Instructions) (*TxSignal, error) {
|
||||
if len(instruction.Accounts) < 8 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[3]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
solAmount := binary.LittleEndian.Uint64(instruction.Data[8:16])
|
||||
tokenAmount := binary.LittleEndian.Uint64(instruction.Data[16:24])
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "term",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(tokenAmount),
|
||||
Token1Amount: formatSolAmount(solAmount),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: true,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: tokenAmount,
|
||||
Token1AmountUint64: solAmount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parseTermBuy(tx VersionedTransaction, instruction Instructions) (*TxSignal, error) {
|
||||
if len(instruction.Accounts) < 8 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[2]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[6]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
solAmount := binary.LittleEndian.Uint64(instruction.Data[8:16])
|
||||
tokenAmount := binary.LittleEndian.Uint64(instruction.Data[16:24])
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "term",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(tokenAmount),
|
||||
Token1Amount: formatSolAmount(solAmount),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: true,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: tokenAmount,
|
||||
Token1AmountUint64: solAmount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parseTermSell(tx VersionedTransaction, instruction Instructions) (*TxSignal, error) {
|
||||
if len(instruction.Accounts) < 8 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[2]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[6]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tokenAmount := binary.LittleEndian.Uint64(instruction.Data[8:16])
|
||||
solAmount := binary.LittleEndian.Uint64(instruction.Data[16:24])
|
||||
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "term",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(tokenAmount),
|
||||
Token1Amount: formatSolAmount(solAmount),
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: tokenAmount,
|
||||
Token1AmountUint64: solAmount,
|
||||
}, nil
|
||||
}
|
||||
@@ -48,6 +48,12 @@ type TxSignal struct {
|
||||
|
||||
ExactSOL bool `json:"exact_in"`
|
||||
|
||||
//Just for metaora DLMM
|
||||
// ActiveBin is the active bin id provided by swap_with_price_impact(2).
|
||||
ActiveBin int32 `json:"active_bin"`
|
||||
// MaxPriceImpactBps is the price impact guard for swap_with_price_impact(2).
|
||||
MaxPriceImpactBps uint16 `json:"max_price_impact_bps"`
|
||||
|
||||
// parsed values
|
||||
Token0AmountUint64 uint64 `json:"-"`
|
||||
Token1AmountUint64 uint64 `json:"-"`
|
||||
@@ -56,10 +62,4 @@ type TxSignal struct {
|
||||
ParseEnd time.Time `json:"parse_end"`
|
||||
}
|
||||
|
||||
func (t *TxSignal) Parse() *TxSignal {
|
||||
t.Token0AmountUint64 = t.Token0Amount.Mul(decimal.New(1, TokenDecimals)).BigInt().Uint64()
|
||||
t.Token1AmountUint64 = t.Token1Amount.Mul(decimal.New(1, SolDecimals)).BigInt().Uint64()
|
||||
return t
|
||||
}
|
||||
|
||||
type TxSignalBatch = []*TxSignal
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -289,3 +289,83 @@ func TestParsePhotonBuy(t *testing.T) {
|
||||
t.Fatalf("expected token1 amount 1955555553, got %d", signal.Token1AmountUint64)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseJupiterV6PumpFunBuy(t *testing.T) {
|
||||
rpcUrl := os.Getenv("SOL_RPC_URL")
|
||||
if rpcUrl == "" {
|
||||
t.Fatalf("SOL_RPC_URL is not set")
|
||||
}
|
||||
|
||||
client := rpc.New(rpcUrl)
|
||||
signals := ParseTransaction(
|
||||
getTransaction(t, client, "4QF5whXwjx234fMXeH3HrJCy5knFJmKPtgbXys8xKGz1pZypqPvXBr4BoAqXfYn8jLL4HXPY1pcvxCCW1XREFNxd"),
|
||||
nil,
|
||||
false,
|
||||
)
|
||||
if len(signals) != 1 {
|
||||
t.Fatalf("expected 1 signal, got %d", len(signals))
|
||||
}
|
||||
|
||||
signal := signals[0]
|
||||
if signal.Label != "jupiterv6" {
|
||||
t.Fatalf("expected jupiterv6 signal, got %s", signal.Label)
|
||||
}
|
||||
if signal.Event != "buy" {
|
||||
t.Fatalf("expected buy event, got %s", signal.Event)
|
||||
}
|
||||
if signal.Maker != "92ySgsZs3rsrUAq2aeEqYacXQQGmz6e4xHPrRGxLDJXb" {
|
||||
t.Fatalf("expected maker 92ySgsZs3rsrUAq2aeEqYacXQQGmz6e4xHPrRGxLDJXb, got %s", signal.Maker)
|
||||
}
|
||||
if signal.Token0Address != "5kSWidFwDKPZiNf52TfincpVn8ufvkAfEzZ9pk8Dpump" {
|
||||
t.Fatalf("expected token0 address 5kSWidFwDKPZiNf52TfincpVn8ufvkAfEzZ9pk8Dpump, got %s", signal.Token0Address)
|
||||
}
|
||||
if signal.Token0AmountUint64 != 2410530637576 {
|
||||
t.Fatalf("expected token0 amount 2410530637576, got %d", signal.Token0AmountUint64)
|
||||
}
|
||||
if signal.Token1AmountUint64 != 380000000 {
|
||||
t.Fatalf("expected token1 amount 380000000, got %d", signal.Token1AmountUint64)
|
||||
}
|
||||
if !signal.ExactSOL {
|
||||
t.Fatalf("expected ExactSOL true, got false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseJupiterV6PumpFunSell(t *testing.T) {
|
||||
rpcUrl := os.Getenv("SOL_RPC_URL")
|
||||
if rpcUrl == "" {
|
||||
t.Fatalf("SOL_RPC_URL is not set")
|
||||
}
|
||||
|
||||
client := rpc.New(rpcUrl)
|
||||
signals := ParseTransaction(
|
||||
getTransaction(t, client, "yCnE7ZA8dqB5iAZtwpSN2ar5HXh3gBjgaG2xtnwXDPFyHAm5XFU8642uTZTH5A2iPQ6G9hrj5eEPAJiWrfe38gM"),
|
||||
nil,
|
||||
false,
|
||||
)
|
||||
if len(signals) != 1 {
|
||||
t.Fatalf("expected 1 signal, got %d", len(signals))
|
||||
}
|
||||
|
||||
signal := signals[0]
|
||||
if signal.Label != "jupiterv6" {
|
||||
t.Fatalf("expected jupiterv6 signal, got %s", signal.Label)
|
||||
}
|
||||
if signal.Event != "sell" {
|
||||
t.Fatalf("expected sell event, got %s", signal.Event)
|
||||
}
|
||||
if signal.Maker != "CGfWcKKcVQNBCL1vpxXdg6rvfYpQmnS3WkyA22Lk5XnZ" {
|
||||
t.Fatalf("expected maker CGfWcKKcVQNBCL1vpxXdg6rvfYpQmnS3WkyA22Lk5XnZ, got %s", signal.Maker)
|
||||
}
|
||||
if signal.Token0Address != "wp8Mwxy7btAD9hNWsfJyoPNJnjXS9fuNG4mnhQZpump" {
|
||||
t.Fatalf("expected token0 address wp8Mwxy7btAD9hNWsfJyoPNJnjXS9fuNG4mnhQZpump, got %s", signal.Token0Address)
|
||||
}
|
||||
if signal.Token0AmountUint64 != 127531720509990 {
|
||||
t.Fatalf("expected token0 amount 127531720509990, got %d", signal.Token0AmountUint64)
|
||||
}
|
||||
if signal.Token1AmountUint64 != 5296451290 {
|
||||
t.Fatalf("expected token1 amount 5296451290, got %d", signal.Token1AmountUint64)
|
||||
}
|
||||
if signal.ExactSOL {
|
||||
t.Fatalf("expected ExactSOL false, got true")
|
||||
}
|
||||
}
|
||||
|
||||
62
pkg/shreder/versioned.go
Normal file
62
pkg/shreder/versioned.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
type Instructions struct {
|
||||
ProgramIDIndex uint8
|
||||
Accounts []uint8
|
||||
Data []byte
|
||||
}
|
||||
|
||||
type AddressTableLookup struct {
|
||||
AccountKey solana.PublicKey
|
||||
WritableIndexes []uint8
|
||||
ReadonlyIndexes []uint8
|
||||
}
|
||||
|
||||
type VersionedTransaction struct {
|
||||
Signatures []solana.Signature
|
||||
|
||||
StaticAccountKeys []solana.PublicKey
|
||||
Instructions []Instructions
|
||||
AddressTableLookups []AddressTableLookup
|
||||
|
||||
Block uint64
|
||||
Time time.Time
|
||||
}
|
||||
|
||||
func (vt VersionedTransaction) GetSignature() string {
|
||||
if len(vt.Signatures) == 0 {
|
||||
return ""
|
||||
}
|
||||
return vt.Signatures[0].String()
|
||||
}
|
||||
|
||||
func (vtp *VersionedTransaction) FillAccount(account solana.PublicKey) {
|
||||
vtp.StaticAccountKeys = append(vtp.StaticAccountKeys, account)
|
||||
}
|
||||
|
||||
func (vt VersionedTransaction) GetAccount(idx int) (solana.PublicKey, error) {
|
||||
if idx < len(vt.StaticAccountKeys) {
|
||||
return vt.StaticAccountKeys[idx], nil
|
||||
}
|
||||
return solana.PublicKey{}, NewAccountNotFoundError(idx, len(vt.StaticAccountKeys))
|
||||
}
|
||||
Reference in New Issue
Block a user