Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6bab10866b | |||
| 83aa772710 | |||
| da51b19b50 | |||
| f39b89b497 | |||
| 26e07ec52e | |||
| 35c57c3c7a | |||
| 3e58b62e1f | |||
|
|
4c0abc5c34 | ||
|
|
d9aea3e8d7 |
@@ -61,7 +61,7 @@ func main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
// TODO: axiom, gmgn, etc.
|
// TODO: axiom, gmgn, etc.
|
||||||
})
|
}, shreder.BlocksStats(false), shreder.LogParsedStats(true), shreder.ShowTableLoaded(false))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,6 @@ func main() {
|
|||||||
<-exitSignal
|
<-exitSignal
|
||||||
cancel()
|
cancel()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// async read from shreder
|
// async read from shreder
|
||||||
txCh := make(chan shreder.TxSignalBatch, 1000)
|
txCh := make(chan shreder.TxSignalBatch, 1000)
|
||||||
go func() {
|
go func() {
|
||||||
@@ -94,8 +93,8 @@ func main() {
|
|||||||
case txBatch := <-txCh:
|
case txBatch := <-txCh:
|
||||||
//jsonData, _ := json.MarshalIndent(txBatch, "", " ")
|
//jsonData, _ := json.MarshalIndent(txBatch, "", " ")
|
||||||
for _, tx := range txBatch {
|
for _, tx := range txBatch {
|
||||||
if tx.Label == "dflow" {
|
if tx.Label == "okxdexroutev2" || tx.Label == "jupiterv6" || tx.Label == "dflow" {
|
||||||
fmt.Println("===============", tx.TxHash, tx.Event, tx.Token0Address, "token:", tx.Token0Amount)
|
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)
|
//fmt.Println(txBatch[0].TxHash)
|
||||||
|
|||||||
@@ -11,24 +11,33 @@ import (
|
|||||||
"github.com/panjf2000/ants/v2"
|
"github.com/panjf2000/ants/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type TableInfo struct {
|
||||||
|
overErrCount int
|
||||||
|
|
||||||
|
addresses []solana.PublicKey
|
||||||
|
}
|
||||||
|
|
||||||
type AddressTables struct {
|
type AddressTables struct {
|
||||||
|
showTableLoaded bool
|
||||||
|
|
||||||
rpcClient *rpc.Client
|
rpcClient *rpc.Client
|
||||||
mux sync.RWMutex
|
|
||||||
loadMux sync.Mutex
|
loadMux sync.Mutex
|
||||||
tables *lru.Cache[solana.PublicKey, []solana.PublicKey]
|
tables *lru.Cache[solana.PublicKey, *TableInfo]
|
||||||
loading map[solana.PublicKey]struct{}
|
loading map[solana.PublicKey]struct{}
|
||||||
|
|
||||||
pool *ants.Pool
|
pool *ants.Pool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAddressTables(rpcClient *rpc.Client) *AddressTables {
|
func NewAddressTables(rpcClient *rpc.Client, showTableLoaded bool) *AddressTables {
|
||||||
pool, _ := ants.NewPool(5, ants.WithPreAlloc(true), ants.WithNonblocking(true))
|
pool, _ := ants.NewPool(5, ants.WithPreAlloc(true), ants.WithNonblocking(true))
|
||||||
cache, _ := lru.New[solana.PublicKey, []solana.PublicKey](10000)
|
cache, _ := lru.New[solana.PublicKey, *TableInfo](10000)
|
||||||
return &AddressTables{
|
return &AddressTables{
|
||||||
rpcClient: rpcClient,
|
rpcClient: rpcClient,
|
||||||
tables: cache,
|
tables: cache,
|
||||||
loading: make(map[solana.PublicKey]struct{}),
|
loading: make(map[solana.PublicKey]struct{}),
|
||||||
pool: pool,
|
pool: pool,
|
||||||
|
|
||||||
|
showTableLoaded: showTableLoaded,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,12 +63,7 @@ func (at *AddressTables) loadAddressTable(tablePubkey solana.PublicKey) ([]solan
|
|||||||
return addresses, nil
|
return addresses, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
func (at *AddressTables) load(tablePubkey solana.PublicKey) {
|
||||||
func (at *AddressTables) GetAddressTable(tablePubkey solana.PublicKey, idx []uint8) []solana.PublicKey {
|
|
||||||
at.mux.RLock()
|
|
||||||
addresses, ok := at.tables.Get(tablePubkey)
|
|
||||||
if !ok {
|
|
||||||
at.mux.RUnlock()
|
|
||||||
_ = at.pool.Submit(func() {
|
_ = at.pool.Submit(func() {
|
||||||
at.loadMux.Lock()
|
at.loadMux.Lock()
|
||||||
_, loading := at.loading[tablePubkey]
|
_, loading := at.loading[tablePubkey]
|
||||||
@@ -82,25 +86,55 @@ func (at *AddressTables) GetAddressTable(tablePubkey solana.PublicKey, idx []uin
|
|||||||
delete(at.loading, tablePubkey)
|
delete(at.loading, tablePubkey)
|
||||||
at.loadMux.Unlock()
|
at.loadMux.Unlock()
|
||||||
|
|
||||||
at.mux.Lock()
|
at.tables.Add(tablePubkey, &TableInfo{
|
||||||
at.tables.Add(tablePubkey, table)
|
addresses: table,
|
||||||
total := at.tables.Len()
|
|
||||||
at.mux.Unlock()
|
|
||||||
logger.Info("loadAddressTable", "table", tablePubkey.String(), "table count:", total)
|
|
||||||
})
|
})
|
||||||
|
if at.showTableLoaded {
|
||||||
|
total := at.tables.Len()
|
||||||
|
logger.Info("loadAddressTable", "table", tablePubkey.String(), "table count:", total)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (at *AddressTables) FillToTx(tx *versionedTransaction, tablePubkey solana.PublicKey, idx []uint8) bool {
|
||||||
|
addresses, ok := at.tables.Get(tablePubkey)
|
||||||
|
if !ok {
|
||||||
|
at.load(tablePubkey)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, i := range idx {
|
||||||
|
if int(i) >= len(addresses.addresses) {
|
||||||
|
logger.Error("over loadAddressTable failed", "idx", i, "table", tablePubkey)
|
||||||
|
addresses.overErrCount++
|
||||||
|
if addresses.overErrCount > 10 {
|
||||||
|
at.load(tablePubkey)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
tx.Message.StaticAccountKeys = append(tx.Message.StaticAccountKeys, addresses.addresses[i])
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (at *AddressTables) GetAddressTable(tablePubkey solana.PublicKey, idx []uint8) []solana.PublicKey {
|
||||||
|
addresses, ok := at.tables.Get(tablePubkey)
|
||||||
|
if !ok {
|
||||||
|
at.load(tablePubkey)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
at.mux.RUnlock()
|
|
||||||
|
|
||||||
var result solana.PublicKeySlice = make([]solana.PublicKey, 0, len(idx))
|
var result solana.PublicKeySlice = make([]solana.PublicKey, 0, len(idx))
|
||||||
for _, i := range idx {
|
for _, i := range idx {
|
||||||
if int(i) >= len(addresses) {
|
if int(i) >= len(addresses.addresses) {
|
||||||
logger.Error("over loadAddressTable failed", "idx", i, "table", tablePubkey)
|
logger.Error("over loadAddressTable failed", "idx", i, "table", tablePubkey)
|
||||||
//todo... update table?
|
addresses.overErrCount++
|
||||||
continue
|
if addresses.overErrCount > 10 {
|
||||||
|
at.load(tablePubkey)
|
||||||
}
|
}
|
||||||
result = append(result, addresses[i])
|
break
|
||||||
|
}
|
||||||
|
result = append(result, addresses.addresses[i])
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,23 +3,61 @@ package shreder
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gagliardetto/solana-go/rpc"
|
"github.com/gagliardetto/solana-go/rpc"
|
||||||
|
"github.com/panjf2000/ants/v2"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
enableBlockStats bool
|
||||||
|
enableParseStats bool
|
||||||
|
|
||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
client ShrederServiceClient
|
client ShrederServiceClient
|
||||||
tableLoader *AddressTables
|
tableLoader *AddressTables
|
||||||
subscription map[string]*SubscribeRequestFilterTransactions
|
subscription map[string]*SubscribeRequestFilterTransactions
|
||||||
|
|
||||||
|
pool *ants.Pool
|
||||||
|
|
||||||
|
lastSlot uint64
|
||||||
|
lastSlotTime time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
type ClientOpts struct {
|
||||||
|
blockStats bool
|
||||||
|
showTableLoaded bool
|
||||||
|
logParseStats bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type ClientOption func(*ClientOpts)
|
||||||
|
|
||||||
|
func ShowTableLoaded(enable bool) ClientOption {
|
||||||
|
return func(opts *ClientOpts) {
|
||||||
|
opts.showTableLoaded = enable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BlocksStats(enable bool) ClientOption {
|
||||||
|
return func(opts *ClientOpts) {
|
||||||
|
opts.blockStats = enable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func LogParsedStats(enable bool) ClientOption {
|
||||||
|
return func(opts *ClientOpts) {
|
||||||
|
opts.logParseStats = enable
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewShrederClient(
|
func NewShrederClient(
|
||||||
url string,
|
url string,
|
||||||
rpcClient *rpc.Client,
|
rpcClient *rpc.Client,
|
||||||
subscription map[string]*SubscribeRequestFilterTransactions,
|
subscription map[string]*SubscribeRequestFilterTransactions,
|
||||||
|
options ...ClientOption,
|
||||||
) (*Client, func(), error) {
|
) (*Client, func(), error) {
|
||||||
if rpcClient == nil {
|
if rpcClient == nil {
|
||||||
return nil, func() {}, fmt.Errorf("rpc client is nil")
|
return nil, func() {}, fmt.Errorf("rpc client is nil")
|
||||||
@@ -30,11 +68,29 @@ func NewShrederClient(
|
|||||||
return nil, func() {}, err
|
return nil, func() {}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
poolSize := runtime.NumCPU()*2 + 2
|
||||||
|
logger.Info("creating shreder client", "url", url, "pool_size", poolSize)
|
||||||
|
pool, err := ants.NewPool(poolSize, ants.WithNonblocking(false))
|
||||||
|
if err != nil {
|
||||||
|
return nil, func() {}, err
|
||||||
|
}
|
||||||
|
o := &ClientOpts{
|
||||||
|
blockStats: false,
|
||||||
|
showTableLoaded: true,
|
||||||
|
logParseStats: false,
|
||||||
|
}
|
||||||
|
for _, option := range options {
|
||||||
|
option(o)
|
||||||
|
}
|
||||||
s := &Client{
|
s := &Client{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
client: NewShrederServiceClient(conn),
|
client: NewShrederServiceClient(conn),
|
||||||
subscription: subscription,
|
subscription: subscription,
|
||||||
tableLoader: NewAddressTables(rpcClient),
|
tableLoader: NewAddressTables(rpcClient, o.showTableLoaded),
|
||||||
|
pool: pool,
|
||||||
|
|
||||||
|
enableBlockStats: o.blockStats,
|
||||||
|
enableParseStats: o.logParseStats,
|
||||||
}
|
}
|
||||||
|
|
||||||
return s, func() {
|
return s, func() {
|
||||||
@@ -45,6 +101,10 @@ func NewShrederClient(
|
|||||||
func (c *Client) Wait() {
|
func (c *Client) Wait() {
|
||||||
logger.Debug("waiting for shreder client to stop")
|
logger.Debug("waiting for shreder client to stop")
|
||||||
|
|
||||||
|
if c.pool != nil {
|
||||||
|
c.pool.Release()
|
||||||
|
}
|
||||||
|
|
||||||
err := c.conn.Close()
|
err := c.conn.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("failed to close connection: ", "err", err)
|
logger.Error("failed to close connection: ", "err", err)
|
||||||
@@ -59,6 +119,8 @@ func (c *Client) ReadSync(ctx context.Context, txCh chan<- TxSignalBatch) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Debug("subscribing to transactions")
|
||||||
|
|
||||||
err = stream.Send(&SubscribeTransactionsRequest{
|
err = stream.Send(&SubscribeTransactionsRequest{
|
||||||
Transactions: c.subscription,
|
Transactions: c.subscription,
|
||||||
})
|
})
|
||||||
@@ -72,20 +134,38 @@ func (c *Client) ReadSync(ctx context.Context, txCh chan<- TxSignalBatch) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
txBatch := ParseTransaction(response.Transaction, c.tableLoader)
|
if c.enableBlockStats {
|
||||||
if len(txBatch) == 0 {
|
slot := response.Transaction.Slot
|
||||||
continue
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
txData := response.Transaction
|
||||||
|
|
||||||
|
err = c.pool.Submit(func() {
|
||||||
|
txBatch := ParseTransaction(txData, c.tableLoader, c.enableParseStats)
|
||||||
|
if len(txBatch) == 0 {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// set fixed source for tx signals
|
|
||||||
for _, tx := range txBatch {
|
for _, tx := range txBatch {
|
||||||
tx.Source = "shreder"
|
tx.Source = "shreder"
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return ctx.Err()
|
return
|
||||||
case txCh <- txBatch:
|
case txCh <- txBatch:
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
dflowProgramID = solana.MustPublicKeyFromBase58("DF1ow4tspfHX9JwWJsAb9epbkA8hmpSEAtxXy1V27QBH")
|
dflowProgramID = solana.MustPublicKeyFromBase58("DF1ow4tspfHX9JwWJsAb9epbkA8hmpSEAtxXy1V27QBH")
|
||||||
|
dflowProgramString = dflowProgramID.String()
|
||||||
|
|
||||||
dflowSwapDisc = []byte{248, 198, 158, 145, 225, 117, 135, 200}
|
dflowSwapDisc = []byte{248, 198, 158, 145, 225, 117, 135, 200}
|
||||||
dflowSwap2Disc = []byte{65, 75, 63, 76, 235, 91, 91, 136}
|
dflowSwap2Disc = []byte{65, 75, 63, 76, 235, 91, 91, 136}
|
||||||
@@ -276,10 +277,11 @@ func parseDFlowInstruction(tx *versionedTransaction, instructionIndex int) (*TxS
|
|||||||
var (
|
var (
|
||||||
srcIdx uint8
|
srcIdx uint8
|
||||||
)
|
)
|
||||||
for i, acctIdx := range ix.Accounts {
|
if len(ix.Accounts) <= 6 {
|
||||||
if i < 6 {
|
return nil, nil
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
accounts := ix.Accounts[5:]
|
||||||
|
for i, acctIdx := range accounts {
|
||||||
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -289,15 +291,15 @@ func parseDFlowInstruction(tx *versionedTransaction, instructionIndex int) (*TxS
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if srcIdx == 0 || srcIdx+1 >= uint8(len(ix.Accounts)) {
|
if srcIdx == 0 || srcIdx+1 >= uint8(len(accounts)) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
baseMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(ix.Accounts[srcIdx]))
|
baseMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(ix.Accounts[srcIdx+1]))
|
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx+1]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -307,7 +309,6 @@ func parseDFlowInstruction(tx *versionedTransaction, instructionIndex int) (*TxS
|
|||||||
|
|
||||||
// Build TxSignal
|
// Build TxSignal
|
||||||
sig := &TxSignal{
|
sig := &TxSignal{
|
||||||
Label: "dflow",
|
|
||||||
TxHash: tx.Signatures[0].String(),
|
TxHash: tx.Signatures[0].String(),
|
||||||
Maker: tx.Message.StaticAccountKeys[0].String(),
|
Maker: tx.Message.StaticAccountKeys[0].String(),
|
||||||
Program: "PumpAMM",
|
Program: "PumpAMM",
|
||||||
|
|||||||
@@ -935,10 +935,11 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
var (
|
var (
|
||||||
srcIdx uint8
|
srcIdx uint8
|
||||||
)
|
)
|
||||||
for i, acctIdx := range instruction.Accounts {
|
if len(instruction.Accounts) <= 9 {
|
||||||
if i < 9 {
|
return nil, nil
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
accounts := instruction.Accounts[8:]
|
||||||
|
for i, acctIdx := range accounts {
|
||||||
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -948,18 +949,18 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if srcIdx == 0 || srcIdx+1 >= uint8(len(instruction.Accounts)) {
|
if srcIdx == 0 || srcIdx+1 >= uint8(len(accounts)) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
baseMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx]))
|
baseMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !sourceMint.Equals(baseMint) {
|
if !sourceMint.Equals(baseMint) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx+1]))
|
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx+1]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -978,10 +979,11 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
var (
|
var (
|
||||||
srcIdx uint8
|
srcIdx uint8
|
||||||
)
|
)
|
||||||
for i, acctIdx := range instruction.Accounts {
|
if len(instruction.Accounts) <= 12 {
|
||||||
if i < 12 {
|
return nil, nil
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
accounts := instruction.Accounts[11:]
|
||||||
|
for i, acctIdx := range accounts {
|
||||||
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -991,11 +993,11 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if srcIdx == 0 || srcIdx+1 >= uint8(len(instruction.Accounts)) {
|
if srcIdx == 0 || srcIdx+1 >= uint8(len(accounts)) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
baseMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx]))
|
baseMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1003,7 +1005,7 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx+1]))
|
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx+1]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1018,10 +1020,8 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
srcIdx uint8
|
srcIdx uint8
|
||||||
)
|
)
|
||||||
|
|
||||||
for i, acctIdx := range instruction.Accounts {
|
accounts := instruction.Accounts[9:]
|
||||||
if i < 9 {
|
for i, acctIdx := range accounts {
|
||||||
continue
|
|
||||||
}
|
|
||||||
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1031,15 +1031,15 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if srcIdx == 0 || srcIdx+1 >= uint8(len(instruction.Accounts)) {
|
if srcIdx == 0 || srcIdx+1 >= uint8(len(accounts)) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
sourceMint, err = getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx]))
|
sourceMint, err = getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx+1]))
|
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx+1]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1049,7 +1049,6 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
signal := &TxSignal{
|
signal := &TxSignal{
|
||||||
Label: "jupiterV6",
|
|
||||||
TxHash: tx.Signatures[0].String(),
|
TxHash: tx.Signatures[0].String(),
|
||||||
Maker: tx.Message.StaticAccountKeys[0].String(),
|
Maker: tx.Message.StaticAccountKeys[0].String(),
|
||||||
Token0Address: sourceMint.String(),
|
Token0Address: sourceMint.String(),
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
okxDexRouteV2ProgramID = solana.MustPublicKeyFromBase58("proVF4pMXVaYqmy4NjniPh4pqKNfMmsihgd4wdkCX3u")
|
okxDexRouteV2ProgramID = solana.MustPublicKeyFromBase58("proVF4pMXVaYqmy4NjniPh4pqKNfMmsihgd4wdkCX3u")
|
||||||
|
okxDexRouteV2ProgramIDString = okxDexRouteV2ProgramID.String()
|
||||||
|
|
||||||
okxSwapTobDisc = []byte{170, 41, 85, 177, 132, 80, 31, 53}
|
okxSwapTobDisc = []byte{170, 41, 85, 177, 132, 80, 31, 53}
|
||||||
okxSwapTobWithReceiverDisc = []byte{223, 170, 216, 234, 204, 6, 241, 25}
|
okxSwapTobWithReceiverDisc = []byte{223, 170, 216, 234, 204, 6, 241, 25}
|
||||||
@@ -314,10 +315,11 @@ func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex in
|
|||||||
var (
|
var (
|
||||||
srcIdx uint8
|
srcIdx uint8
|
||||||
)
|
)
|
||||||
for i, acctIdx := range ix.Accounts {
|
if len(ix.Accounts) <= 15 {
|
||||||
if i < 15 {
|
return nil, nil
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
accounts := ix.Accounts[14:]
|
||||||
|
for i, acctIdx := range accounts {
|
||||||
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -327,11 +329,11 @@ func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex in
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if srcIdx == 0 || int(srcIdx+1) >= len(ix.Accounts) {
|
if srcIdx == 0 || int(srcIdx+1) >= len(accounts) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
baseMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(ix.Accounts[srcIdx]))
|
baseMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -339,7 +341,7 @@ func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex in
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(ix.Accounts[srcIdx+1]))
|
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx+1]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -348,7 +350,6 @@ func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex in
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &TxSignal{
|
return &TxSignal{
|
||||||
Label: "okxdexroutev2",
|
|
||||||
TxHash: tx.Signatures[0].String(),
|
TxHash: tx.Signatures[0].String(),
|
||||||
Maker: tx.Message.StaticAccountKeys[0].String(),
|
Maker: tx.Message.StaticAccountKeys[0].String(),
|
||||||
Token0Address: baseMint.String(),
|
Token0Address: baseMint.String(),
|
||||||
|
|||||||
@@ -45,13 +45,15 @@ type TxSignal struct {
|
|||||||
IsToken2022 bool `json:"is_token2022"`
|
IsToken2022 bool `json:"is_token2022"`
|
||||||
IsMayhemMode bool `json:"is_mayhem_mode"`
|
IsMayhemMode bool `json:"is_mayhem_mode"`
|
||||||
TxFee decimal.Decimal `json:"tx_fee"`
|
TxFee decimal.Decimal `json:"tx_fee"`
|
||||||
EntryContract string `json:"entry_contract"`
|
|
||||||
|
|
||||||
ExactSOL bool `json:"exact_in"`
|
ExactSOL bool `json:"exact_in"`
|
||||||
|
|
||||||
// parsed values
|
// parsed values
|
||||||
Token0AmountUint64 uint64 `json:"-"`
|
Token0AmountUint64 uint64 `json:"-"`
|
||||||
Token1AmountUint64 uint64 `json:"-"`
|
Token1AmountUint64 uint64 `json:"-"`
|
||||||
|
|
||||||
|
ParseStart time.Time `json:"parse_start"`
|
||||||
|
ParseEnd time.Time `json:"parse_end"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TxSignal) Parse() *TxSignal {
|
func (t *TxSignal) Parse() *TxSignal {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gagliardetto/solana-go"
|
"github.com/gagliardetto/solana-go"
|
||||||
"github.com/mr-tron/base58"
|
"github.com/mr-tron/base58"
|
||||||
@@ -21,13 +23,11 @@ const (
|
|||||||
// program ids
|
// program ids
|
||||||
var (
|
var (
|
||||||
pumpProgramID = solana.MustPublicKeyFromBase58("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P")
|
pumpProgramID = solana.MustPublicKeyFromBase58("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P")
|
||||||
|
|
||||||
// has no sell function with pump and pump.amm program
|
// has no sell function with pump and pump.amm program
|
||||||
azczProgramID = solana.MustPublicKeyFromBase58("AzcZqCRUQgKEg5FTAgY7JacATABEYCEfMbjXEzspLYFB")
|
azczProgramID = solana.MustPublicKeyFromBase58("AzcZqCRUQgKEg5FTAgY7JacATABEYCEfMbjXEzspLYFB")
|
||||||
|
|
||||||
// only buy function with pump program
|
// only buy function with pump program
|
||||||
f5tfProgramID = solana.MustPublicKeyFromBase58("F5tfvbLog9VdGUPqBDTT8rgXvTTcq7e5UiGnupL1zvBq")
|
f5tfProgramID = solana.MustPublicKeyFromBase58("F5tfvbLog9VdGUPqBDTT8rgXvTTcq7e5UiGnupL1zvBq")
|
||||||
|
|
||||||
// only pump.fun function
|
// only pump.fun function
|
||||||
photonProgramID = solana.MustPublicKeyFromBase58("BSfD6SHZigAfDWSjzD5Q41jw8LmKwtmjskPH9XW1mrRW")
|
photonProgramID = solana.MustPublicKeyFromBase58("BSfD6SHZigAfDWSjzD5Q41jw8LmKwtmjskPH9XW1mrRW")
|
||||||
|
|
||||||
@@ -45,6 +45,10 @@ var (
|
|||||||
terminalProgramID = solana.MustPublicKeyFromBase58("term9YPb9mzAsABaqN71A4xdbxHmpBNZavpBiQKZzN3")
|
terminalProgramID = solana.MustPublicKeyFromBase58("term9YPb9mzAsABaqN71A4xdbxHmpBNZavpBiQKZzN3")
|
||||||
|
|
||||||
jupiterV6ProgramID = solana.MustPublicKeyFromBase58("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4")
|
jupiterV6ProgramID = solana.MustPublicKeyFromBase58("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4")
|
||||||
|
|
||||||
|
gmgnProgramID = solana.MustPublicKeyFromBase58("GMgnVFR8Jb39LoXsEVzb3DvBy3ywCmdmJquHUy1Lrkqb")
|
||||||
|
|
||||||
|
bonkProgramID = solana.MustPublicKeyFromBase58("BBRouter1cVunVXvkcqeKkZQcBK7ruan37PPm3xzWaXD")
|
||||||
)
|
)
|
||||||
|
|
||||||
type AccountNotFoundError struct {
|
type AccountNotFoundError struct {
|
||||||
@@ -94,6 +98,10 @@ var (
|
|||||||
terminalBuyTokensIX = []byte{0xa6, 0x54, 0x14, 0x96, 0x9f, 0x77, 0x59, 0xca}
|
terminalBuyTokensIX = []byte{0xa6, 0x54, 0x14, 0x96, 0x9f, 0x77, 0x59, 0xca}
|
||||||
terminalSellTokensIX = []byte{0xbe, 0x84, 0xa2, 0x96, 0x93, 0x7c, 0xf8, 0x6b}
|
terminalSellTokensIX = []byte{0xbe, 0x84, 0xa2, 0x96, 0x93, 0x7c, 0xf8, 0x6b}
|
||||||
terminalAmmSellTokensIX = []byte{0x40, 0x64, 0x97, 0xb9, 0x16, 0xfa, 0xec, 0xb1}
|
terminalAmmSellTokensIX = []byte{0x40, 0x64, 0x97, 0xb9, 0x16, 0xfa, 0xec, 0xb1}
|
||||||
|
|
||||||
|
gmgnBuyTokensIX = []byte{0x66, 0x06, 0x3d, 0x12, 0x01, 0xda, 0xeb, 0xea}
|
||||||
|
|
||||||
|
bonkBuyAndSellTokensIX = []byte{0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a}
|
||||||
)
|
)
|
||||||
|
|
||||||
type compiledInstruction struct {
|
type compiledInstruction struct {
|
||||||
@@ -118,6 +126,7 @@ type versionedTransaction struct {
|
|||||||
Signatures []solana.Signature
|
Signatures []solana.Signature
|
||||||
Message versionedMessage
|
Message versionedMessage
|
||||||
Block uint64
|
Block uint64
|
||||||
|
Time time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type pumpExtendedSellArgs struct {
|
type pumpExtendedSellArgs struct {
|
||||||
@@ -192,15 +201,72 @@ type fjszBuyArgs struct {
|
|||||||
TokenAmount uint64
|
TokenAmount uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
versionedPool = sync.Pool{}
|
||||||
|
|
||||||
|
accIdxPool = sync.Pool{}
|
||||||
|
)
|
||||||
|
|
||||||
|
func requireAccIdxSlice() []uint8 {
|
||||||
|
v := accIdxPool.Get()
|
||||||
|
if v == nil {
|
||||||
|
return make([]uint8, 0, 16)
|
||||||
|
}
|
||||||
|
return v.([]uint8)
|
||||||
|
}
|
||||||
|
|
||||||
|
func releaseAccIdxSlice(s []uint8) {
|
||||||
|
if s == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s = s[:0]
|
||||||
|
accIdxPool.Put(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func requireVersionedPool() *versionedTransaction {
|
||||||
|
v := versionedPool.Get()
|
||||||
|
if v == nil {
|
||||||
|
return &versionedTransaction{
|
||||||
|
Signatures: make([]solana.Signature, 0, 10),
|
||||||
|
Message: versionedMessage{
|
||||||
|
StaticAccountKeys: make([]solana.PublicKey, 0, 256),
|
||||||
|
Instructions: make([]compiledInstruction, 0, 16),
|
||||||
|
AddressTableLookups: make([]addressTableLookup, 0, 10),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return v.(*versionedTransaction)
|
||||||
|
}
|
||||||
|
|
||||||
|
func releaseVersionedPool(v *versionedTransaction) {
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for i := range v.Message.Instructions {
|
||||||
|
releaseAccIdxSlice(v.Message.Instructions[i].Accounts)
|
||||||
|
}
|
||||||
|
for i := range v.Message.AddressTableLookups {
|
||||||
|
releaseAccIdxSlice(v.Message.AddressTableLookups[i].WritableIndexes)
|
||||||
|
releaseAccIdxSlice(v.Message.AddressTableLookups[i].ReadonlyIndexes)
|
||||||
|
}
|
||||||
|
versionedPool.Put(v)
|
||||||
|
}
|
||||||
|
|
||||||
// ParseTransaction mirrors the Rust parse_transaction entry point.
|
// ParseTransaction mirrors the Rust parse_transaction entry point.
|
||||||
func ParseTransaction(update *SubscribeUpdateTransaction, loader *AddressTables) []*TxSignal {
|
func ParseTransaction(update *SubscribeUpdateTransaction, loader *AddressTables, stats bool) []*TxSignal {
|
||||||
|
var now time.Time
|
||||||
|
if stats {
|
||||||
|
now = time.Now()
|
||||||
|
}
|
||||||
versioned, err := toVersionedTransaction(update)
|
versioned, err := toVersionedTransaction(update)
|
||||||
if err != nil || versioned == nil || len(versioned.Signatures) == 0 {
|
if err != nil || versioned == nil || len(versioned.Signatures) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
releaseVersionedPool(versioned)
|
||||||
|
}()
|
||||||
txHash := versioned.Signatures[0]
|
txHash := versioned.Signatures[0]
|
||||||
staticKeys := versioned.Message.StaticAccountKeys
|
// staticKeys := versioned.Message.StaticAccountKeys
|
||||||
instructions := versioned.Message.Instructions
|
instructions := versioned.Message.Instructions
|
||||||
|
|
||||||
if loader != nil && len(versioned.Message.AddressTableLookups) > 0 {
|
if loader != nil && len(versioned.Message.AddressTableLookups) > 0 {
|
||||||
@@ -209,85 +275,87 @@ func ParseTransaction(update *SubscribeUpdateTransaction, loader *AddressTables)
|
|||||||
if len(lookup.WritableIndexes) == 0 {
|
if len(lookup.WritableIndexes) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
accounts := loader.GetAddressTable(lookup.AccountKey, lookup.WritableIndexes)
|
lookupTableOk = loader.FillToTx(versioned, lookup.AccountKey, lookup.WritableIndexes)
|
||||||
if len(accounts) != len(lookup.WritableIndexes) {
|
if !lookupTableOk {
|
||||||
lookupTableOk = false
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
staticKeys = append(staticKeys, accounts...)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if lookupTableOk {
|
if lookupTableOk {
|
||||||
for _, lookup := range versioned.Message.AddressTableLookups {
|
for _, lookup := range versioned.Message.AddressTableLookups {
|
||||||
if len(lookup.ReadonlyIndexes) == 0 {
|
if len(lookup.ReadonlyIndexes) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
accounts := loader.GetAddressTable(lookup.AccountKey, lookup.ReadonlyIndexes)
|
lookupTableOk = loader.FillToTx(versioned, lookup.AccountKey, lookup.ReadonlyIndexes)
|
||||||
if len(accounts) != len(lookup.ReadonlyIndexes) {
|
if !lookupTableOk {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
staticKeys = append(staticKeys, accounts...)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
versioned.Message.StaticAccountKeys = staticKeys
|
// versioned.Message.StaticAccountKeys = staticKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
var parsed []*TxSignal
|
var parsed []*TxSignal = make([]*TxSignal, 0, 3)
|
||||||
|
|
||||||
for i := range instructions {
|
for i := range instructions {
|
||||||
inst := instructions[i]
|
inst := instructions[i]
|
||||||
if int(inst.ProgramIDIndex) >= len(staticKeys) {
|
if int(inst.ProgramIDIndex) >= len(versioned.Message.StaticAccountKeys) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
programID := staticKeys[inst.ProgramIDIndex]
|
programID := versioned.Message.StaticAccountKeys[inst.ProgramIDIndex]
|
||||||
switch programID {
|
switch programID {
|
||||||
case pumpProgramID:
|
case pumpProgramID:
|
||||||
txRes, err := parsePumpInstruction(versioned, i)
|
txRes, err := parsePumpInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "pump", pumpProgramID.String())
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "pump")
|
||||||
case azczProgramID:
|
case azczProgramID:
|
||||||
txRes, err := parseAzczInstruction(versioned, i)
|
txRes, err := parseAzczInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "azcz", azczProgramID.String())
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "azcz")
|
||||||
case f5tfProgramID:
|
case f5tfProgramID:
|
||||||
txRes, err := parseF5tfInstruction(versioned, i)
|
txRes, err := parseF5tfInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "f5tf", f5tfProgramID.String())
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "f5tf")
|
||||||
case flasProgramID:
|
case flasProgramID:
|
||||||
txRes, err := parseFlasInstruction(versioned, i)
|
txRes, err := parseFlasInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "flas", flasProgramID.String())
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "flas")
|
||||||
case photonProgramID:
|
case photonProgramID:
|
||||||
txRes, err := parsePhotonInstruction(versioned, i)
|
txRes, err := parsePhotonInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "photon", photonProgramID.String())
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "photon")
|
||||||
case pumpAmmProgramID:
|
case pumpAmmProgramID:
|
||||||
txRes, err := parsePumpAmmInstruction(versioned, i)
|
txRes, err := parsePumpAmmInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "pumpamm", pumpAmmProgramID.String())
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "pumpamm")
|
||||||
case boboProgramID:
|
case boboProgramID:
|
||||||
txRes, err := parseBoboInstruction(versioned, i)
|
txRes, err := parseBoboInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "bobo", boboProgramID.String())
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "bobo")
|
||||||
case qtkvProgramID:
|
case qtkvProgramID:
|
||||||
txRes, err := parseQtkvInstruction(versioned, i)
|
txRes, err := parseQtkvInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "qtkv", qtkvProgramID.String())
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "qtkv")
|
||||||
case fjszProgramID:
|
case fjszProgramID:
|
||||||
txRes, err := parseFjszInstruction(versioned, i)
|
txRes, err := parseFjszInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "fjsz", fjszProgramID.String())
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "fjsz")
|
||||||
case terminalProgramID:
|
case terminalProgramID:
|
||||||
txRes, err := parseTermInstruction(versioned, i)
|
txRes, err := parseTermInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "terminal", terminalProgramID.String())
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "terminal")
|
||||||
case jupiterV6ProgramID:
|
case jupiterV6ProgramID:
|
||||||
txRes, err := parseJupiterV6Instruction(versioned, i)
|
txRes, err := parseJupiterV6Instruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "jupiterv6", jupiterV6ProgramID.String())
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "jupiterv6")
|
||||||
case okxDexRouteV2ProgramID:
|
case okxDexRouteV2ProgramID:
|
||||||
txRes, err := parseOkxDexRouteV2Instruction(versioned, i)
|
txRes, err := parseOkxDexRouteV2Instruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "okxdexroutev2", okxDexRouteV2ProgramID.String())
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "okxdexroutev2")
|
||||||
case dflowProgramID:
|
case dflowProgramID:
|
||||||
txRes, err := parseDFlowInstruction(versioned, i)
|
txRes, err := parseDFlowInstruction(versioned, i)
|
||||||
parsed = appendParsed(parsed, txRes, err, txHash, "dflow", dflowProgramID.String())
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "dflow")
|
||||||
|
case gmgnProgramID:
|
||||||
|
txRes, err := parseGMGNInstruction(versioned, i)
|
||||||
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "gmgn")
|
||||||
|
case bonkProgramID:
|
||||||
|
txRes, err := parseBonkInstruction(versioned, i)
|
||||||
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "bonk")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsed
|
return parsed
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendParsed(list []*TxSignal, parsed *TxSignal, err error, txHash [64]byte, label string, entryContract string) []*TxSignal {
|
func appendParsed(start time.Time, list []*TxSignal, parsed *TxSignal, err error, txHash [64]byte, label string) []*TxSignal {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !strings.HasPrefix(err.Error(), "account index") {
|
if !strings.HasPrefix(err.Error(), "account index") {
|
||||||
logger.Debug("txparser: failed to parse", "label", label, "instruction", err, "tx_hash", base58.Encode(txHash[:]))
|
logger.Debug("txparser: failed to parse", "label", label, "instruction", err, "tx_hash", base58.Encode(txHash[:]))
|
||||||
@@ -295,7 +363,11 @@ func appendParsed(list []*TxSignal, parsed *TxSignal, err error, txHash [64]byte
|
|||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
if parsed != nil {
|
if parsed != nil {
|
||||||
parsed.EntryContract = entryContract
|
parsed.Label = label
|
||||||
|
if !start.IsZero() {
|
||||||
|
parsed.ParseEnd = time.Now()
|
||||||
|
parsed.ParseStart = start
|
||||||
|
}
|
||||||
list = append(list, parsed)
|
list = append(list, parsed)
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
@@ -308,47 +380,42 @@ func toVersionedTransaction(update *SubscribeUpdateTransaction) (*versionedTrans
|
|||||||
|
|
||||||
protoTx := update.Transaction
|
protoTx := update.Transaction
|
||||||
msg := protoTx.Message
|
msg := protoTx.Message
|
||||||
|
versioned := requireVersionedPool()
|
||||||
signatures := make([]solana.Signature, len(protoTx.Signatures))
|
versioned.Signatures = versioned.Signatures[:0]
|
||||||
for i, rawSig := range protoTx.Signatures {
|
for _, rawSig := range protoTx.Signatures {
|
||||||
signatures[i] = solana.SignatureFromBytes(rawSig)
|
versioned.Signatures = append(versioned.Signatures, solana.SignatureFromBytes(rawSig))
|
||||||
}
|
}
|
||||||
|
versioned.Message.StaticAccountKeys = versioned.Message.StaticAccountKeys[:0]
|
||||||
staticKeys := make([]solana.PublicKey, len(msg.AccountKeys))
|
for _, key := range msg.AccountKeys {
|
||||||
for i, key := range msg.AccountKeys {
|
versioned.Message.StaticAccountKeys = append(versioned.Message.StaticAccountKeys, solana.PublicKeyFromBytes(key))
|
||||||
staticKeys[i] = solana.PublicKeyFromBytes(key)
|
|
||||||
}
|
}
|
||||||
|
versioned.Message.Instructions = versioned.Message.Instructions[:0]
|
||||||
instructions := make([]compiledInstruction, len(msg.Instructions))
|
for _, instr := range msg.Instructions {
|
||||||
for i, instr := range msg.Instructions {
|
accounts := requireAccIdxSlice()
|
||||||
accounts := append([]uint8(nil), instr.Accounts...)
|
accounts = append(accounts, instr.Accounts...)
|
||||||
instructions[i] = compiledInstruction{
|
versioned.Message.Instructions = append(versioned.Message.Instructions,
|
||||||
|
compiledInstruction{
|
||||||
ProgramIDIndex: uint8(instr.ProgramIdIndex),
|
ProgramIDIndex: uint8(instr.ProgramIdIndex),
|
||||||
Accounts: accounts,
|
Accounts: accounts,
|
||||||
Data: instr.Data,
|
Data: instr.Data,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
lookups := make([]addressTableLookup, len(msg.AddressTableLookups))
|
versioned.Message.AddressTableLookups = versioned.Message.AddressTableLookups[:0]
|
||||||
for i, lookup := range msg.AddressTableLookups {
|
for _, lookup := range msg.AddressTableLookups {
|
||||||
writable := append([]uint8(nil), lookup.WritableIndexes...)
|
writable := requireAccIdxSlice()
|
||||||
readonly := append([]uint8(nil), lookup.ReadonlyIndexes...)
|
writable = append(writable, lookup.WritableIndexes...)
|
||||||
lookups[i] = addressTableLookup{
|
readonly := requireAccIdxSlice()
|
||||||
|
readonly = append(readonly, lookup.ReadonlyIndexes...)
|
||||||
|
versioned.Message.AddressTableLookups = append(versioned.Message.AddressTableLookups, addressTableLookup{
|
||||||
AccountKey: solana.PublicKeyFromBytes(lookup.AccountKey),
|
AccountKey: solana.PublicKeyFromBytes(lookup.AccountKey),
|
||||||
WritableIndexes: writable,
|
WritableIndexes: writable,
|
||||||
ReadonlyIndexes: readonly,
|
ReadonlyIndexes: readonly,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return &versionedTransaction{
|
versioned.Block = update.GetSlot()
|
||||||
Signatures: signatures,
|
return versioned, nil
|
||||||
Message: versionedMessage{
|
|
||||||
StaticAccountKeys: staticKeys,
|
|
||||||
Instructions: instructions,
|
|
||||||
AddressTableLookups: lookups,
|
|
||||||
},
|
|
||||||
Block: update.GetSlot(),
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatTokenAmount(amount uint64) decimal.Decimal {
|
func formatTokenAmount(amount uint64) decimal.Decimal {
|
||||||
@@ -939,6 +1006,66 @@ func parseFlasBuy(tx *versionedTransaction, instructionIndex int) (*TxSignal, er
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseGMGNInstruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||||
|
msg := tx.Message
|
||||||
|
if instructionIndex >= len(msg.Instructions) {
|
||||||
|
return nil, fmt.Errorf("instruction index out of bounds")
|
||||||
|
}
|
||||||
|
|
||||||
|
instruction := msg.Instructions[instructionIndex]
|
||||||
|
if len(instruction.Data) == 0 {
|
||||||
|
return nil, fmt.Errorf("data is empty")
|
||||||
|
}
|
||||||
|
if len(instruction.Data) < 8 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if matchMethod(instruction.Data, gmgnBuyTokensIX) {
|
||||||
|
return parseGMGNBuy(tx, &instruction)
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseGMGNBuy(tx *versionedTransaction, instruction *compiledInstruction) (*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))
|
||||||
|
}
|
||||||
|
|
||||||
|
staticKeys := tx.Message.StaticAccountKeys
|
||||||
|
mint, err := getStaticKey(staticKeys, int(instruction.Accounts[2]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
user, err := getStaticKey(staticKeys, 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
|
||||||
|
}
|
||||||
|
|
||||||
func parsePhotonInstruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
|
func parsePhotonInstruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||||
msg := tx.Message
|
msg := tx.Message
|
||||||
if instructionIndex >= len(msg.Instructions) {
|
if instructionIndex >= len(msg.Instructions) {
|
||||||
@@ -999,6 +1126,7 @@ func parsePhotonBuy(tx *versionedTransaction, instruction *compiledInstruction)
|
|||||||
Event: "buy",
|
Event: "buy",
|
||||||
IsToken2022: false,
|
IsToken2022: false,
|
||||||
IsMayhemMode: false,
|
IsMayhemMode: false,
|
||||||
|
ExactSOL: true,
|
||||||
Block: tx.Block,
|
Block: tx.Block,
|
||||||
Token0AmountUint64: args.TokenAmount,
|
Token0AmountUint64: args.TokenAmount,
|
||||||
Token1AmountUint64: solAmount,
|
Token1AmountUint64: solAmount,
|
||||||
@@ -1173,6 +1301,7 @@ func parseTermBuy(tx *versionedTransaction, instruction *compiledInstruction) (*
|
|||||||
Event: "buy",
|
Event: "buy",
|
||||||
IsToken2022: false,
|
IsToken2022: false,
|
||||||
IsMayhemMode: false,
|
IsMayhemMode: false,
|
||||||
|
ExactSOL: true,
|
||||||
Block: tx.Block,
|
Block: tx.Block,
|
||||||
Token0AmountUint64: tokenAmount,
|
Token0AmountUint64: tokenAmount,
|
||||||
Token1AmountUint64: solAmount,
|
Token1AmountUint64: solAmount,
|
||||||
@@ -1208,6 +1337,7 @@ func parseTermSell(tx *versionedTransaction, instruction *compiledInstruction) (
|
|||||||
Event: "buy",
|
Event: "buy",
|
||||||
IsToken2022: false,
|
IsToken2022: false,
|
||||||
IsMayhemMode: false,
|
IsMayhemMode: false,
|
||||||
|
ExactSOL: false,
|
||||||
Block: tx.Block,
|
Block: tx.Block,
|
||||||
Token0AmountUint64: tokenAmount,
|
Token0AmountUint64: tokenAmount,
|
||||||
Token1AmountUint64: solAmount,
|
Token1AmountUint64: solAmount,
|
||||||
@@ -1580,7 +1710,7 @@ func parseFjszInstruction(tx *versionedTransaction, instructionIndex int) (*TxSi
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTerminalInstruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
|
func parseBonkInstruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||||
msg := tx.Message
|
msg := tx.Message
|
||||||
if instructionIndex >= len(msg.Instructions) {
|
if instructionIndex >= len(msg.Instructions) {
|
||||||
return nil, fmt.Errorf("instruction index out of bounds")
|
return nil, fmt.Errorf("instruction index out of bounds")
|
||||||
@@ -1590,24 +1720,87 @@ func parseTerminalInstruction(tx *versionedTransaction, instructionIndex int) (*
|
|||||||
if len(instruction.Data) == 0 {
|
if len(instruction.Data) == 0 {
|
||||||
return nil, fmt.Errorf("data is empty")
|
return nil, fmt.Errorf("data is empty")
|
||||||
}
|
}
|
||||||
if matchMethod(instruction.Data, terminalBuyTokensIX) {
|
|
||||||
return parseTermBuy(tx, &instruction)
|
if matchMethod(instruction.Data, bonkBuyAndSellTokensIX) {
|
||||||
} else if matchMethod(instruction.Data, terminalSellTokensIX) {
|
return parseBonkBuyAndSell(tx, &instruction)
|
||||||
return parseTermSell(tx, &instruction)
|
|
||||||
} else if matchMethod(instruction.Data, terminalAmmSellTokensIX) {
|
|
||||||
return parseTermAmmSell(tx, &instruction)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func indexOf(haystack []uint8, needle uint8) int {
|
func parseBonkBuyAndSell(tx *versionedTransaction, instruction *compiledInstruction) (*TxSignal, error) {
|
||||||
for i, v := range haystack {
|
if len(instruction.Accounts) < 8 {
|
||||||
if v == needle {
|
return nil, fmt.Errorf("accounts too short")
|
||||||
return i
|
|
||||||
}
|
}
|
||||||
|
staticKeys := tx.Message.StaticAccountKeys
|
||||||
|
programId, err := getStaticKey(staticKeys, int(instruction.Accounts[7]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if programId != pumpProgramID {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err := getStaticKey(staticKeys, int(instruction.Accounts[0]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
flagAccount, err := getStaticKey(staticKeys, 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 := getStaticKey(staticKeys, 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 := getStaticKey(staticKeys, 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
|
||||||
}
|
}
|
||||||
return -1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func matchMethod(data []byte, methods []byte) bool {
|
func matchMethod(data []byte, methods []byte) bool {
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
package shreder
|
package shreder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gagliardetto/solana-go"
|
||||||
|
"github.com/gagliardetto/solana-go/rpc"
|
||||||
"github.com/near/borsh-go"
|
"github.com/near/borsh-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -54,3 +58,234 @@ func TestDecodeAxiomArgs(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toUpdata(slot uint64, tx *solana.Transaction) *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([]*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] = &CompiledInstruction{
|
||||||
|
ProgramIdIndex: uint32(instr.ProgramIDIndex),
|
||||||
|
Accounts: accounts,
|
||||||
|
Data: instr.Data[:],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addressTableLookups := make([]*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] = &MessageAddressTableLookup{
|
||||||
|
AccountKey: lookup.AccountKey[:],
|
||||||
|
WritableIndexes: writable,
|
||||||
|
ReadonlyIndexes: readonly,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &SubscribeUpdateTransaction{
|
||||||
|
Transaction: &Transaction{
|
||||||
|
Signatures: signatures,
|
||||||
|
Message: &Message{
|
||||||
|
Header: &MessageHeader{
|
||||||
|
NumRequiredSignatures: uint32(tx.Message.Header.NumRequiredSignatures),
|
||||||
|
NumReadonlySignedAccounts: uint32(tx.Message.Header.NumReadonlySignedAccounts),
|
||||||
|
NumReadonlyUnsignedAccounts: uint32(tx.Message.Header.NumReadonlyUnsignedAccounts),
|
||||||
|
},
|
||||||
|
AccountKeys: accountKeys,
|
||||||
|
RecentBlockhash: nil, // TODO
|
||||||
|
Instructions: instructions,
|
||||||
|
Versioned: false, // TODO
|
||||||
|
AddressTableLookups: addressTableLookups,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Slot: slot,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTransaction(t *testing.T, client *rpc.Client, signature string) *SubscribeUpdateTransaction {
|
||||||
|
version := uint64(0)
|
||||||
|
tx, err := client.GetTransaction(
|
||||||
|
context.Background(),
|
||||||
|
solana.MustSignatureFromBase58(signature),
|
||||||
|
&rpc.GetTransactionOpts{
|
||||||
|
Commitment: rpc.CommitmentFinalized,
|
||||||
|
MaxSupportedTransactionVersion: &version,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to get transaction: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_tx, err := tx.Transaction.GetTransaction()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to get transaction: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return toUpdata(tx.Slot, _tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseTermBuy(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, "5Gz1fa4Qhb35bkg9QCMXpxCX5uuNr7WcjcmrwajGZA7kXsvNS9pDnYe12ggWeSqf1nwZbVPob6DkX6fcwbE9ofBR"),
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
if len(signals) != 1 {
|
||||||
|
t.Fatalf("expected 1 signal, got %d", len(signals))
|
||||||
|
}
|
||||||
|
|
||||||
|
signal := signals[0]
|
||||||
|
if signal.Label != "terminal" {
|
||||||
|
t.Fatalf("expected terminal signal, got %s", signal.Label)
|
||||||
|
}
|
||||||
|
if signal.Event != "buy" {
|
||||||
|
t.Fatalf("expected buy event, got %s", signal.Event)
|
||||||
|
}
|
||||||
|
if signal.Maker != "BaLxyjXzATAnfm7cc5AFhWBpiwnsb71THcnofDLTWAPK" {
|
||||||
|
t.Fatalf("expected maker BaLxyjXzATAnfm7cc5AFhWBpiwnsb71THcnofDLTWAPK, got %s", signal.Maker)
|
||||||
|
}
|
||||||
|
if signal.Token0Address != "5Wgv54peXRKDHYHapAELzgNKEPEh9E5Bf3hUR3sTpump" {
|
||||||
|
t.Fatalf("expected token0 address 5Wgv54peXRKDHYHapAELzgNKEPEh9E5Bf3hUR3sTpump, got %s", signal.Token0Address)
|
||||||
|
}
|
||||||
|
if signal.Token0AmountUint64 != 6952026214256 {
|
||||||
|
t.Fatalf("expected token0 amount 6952026214256, got %d", signal.Token0AmountUint64)
|
||||||
|
}
|
||||||
|
if signal.Token1AmountUint64 != 653333333 {
|
||||||
|
t.Fatalf("expected token1 amount 653333333, got %d", signal.Token1AmountUint64)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseBonkBuy(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, "3gHF3TA2aA8rpjdmoEs2vA89vrq9J9NnTTUSXHfE6uXcaYP9cJgLtEUjCmsK9EWAyHEg7cEiepehQf4GFv1272jW"),
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
if len(signals) != 1 {
|
||||||
|
t.Fatalf("expected 1 signal, got %d", len(signals))
|
||||||
|
}
|
||||||
|
|
||||||
|
signal := signals[0]
|
||||||
|
if signal.Label != "bonk" {
|
||||||
|
t.Fatalf("expected bonk signal, got %s", signal.Label)
|
||||||
|
}
|
||||||
|
if signal.Event != "buy" {
|
||||||
|
t.Fatalf("expected buy event, got %s", signal.Event)
|
||||||
|
}
|
||||||
|
if signal.Maker != "BFobdhAbdBteBuDvHUdBthsQqJyMuWnG9SGUheW1Ni2C" {
|
||||||
|
t.Fatalf("expected maker BFobdhAbdBteBuDvHUdBthsQqJyMuWnG9SGUheW1Ni2C, got %s", signal.Maker)
|
||||||
|
}
|
||||||
|
if signal.Token0Address != "Awupo9Jxe1fsc7eEtCEcN9D3PoyReQhc9WEuEAHXpump" {
|
||||||
|
t.Fatalf("expected token0 address Awupo9Jxe1fsc7eEtCEcN9D3PoyReQhc9WEuEAHXpump, got %s", signal.Token0Address)
|
||||||
|
}
|
||||||
|
if signal.Token0AmountUint64 != 8616799656436 {
|
||||||
|
t.Fatalf("expected token0 amount 8616799656436, got %d", signal.Token0AmountUint64)
|
||||||
|
}
|
||||||
|
if signal.Token1AmountUint64 != 495000000 {
|
||||||
|
t.Fatalf("expected token1 amount 495000000, got %d", signal.Token1AmountUint64)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseBonkSell(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, "3XNi6b3j69SSStqLLRQVH5BNGVfEoFxGCzmpdd5FvrY4kmC8T644WGdEhCH9fAdrxWuR2Mtzgywq8K7qetu5MGyb"),
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
if len(signals) != 1 {
|
||||||
|
t.Fatalf("expected 1 signal, got %d", len(signals))
|
||||||
|
}
|
||||||
|
|
||||||
|
signal := signals[0]
|
||||||
|
if signal.Label != "bonk" {
|
||||||
|
t.Fatalf("expected bonk signal, got %s", signal.Label)
|
||||||
|
}
|
||||||
|
if signal.Event != "sell" {
|
||||||
|
t.Fatalf("expected sell event, got %s", signal.Event)
|
||||||
|
}
|
||||||
|
if signal.Maker != "2xTT7XXCEYSCrRb3G4Egc4ZwpCe78qq6r7w6ChZhbTXc" {
|
||||||
|
t.Fatalf("expected maker 2xTT7XXCEYSCrRb3G4Egc4ZwpCe78qq6r7w6ChZhbTXc, got %s", signal.Maker)
|
||||||
|
}
|
||||||
|
if signal.Token0Address != "8pgpJDYuojYXvb8KE4Hv7DCty12FrkqpKChgfHzspump" {
|
||||||
|
t.Fatalf("expected token0 address 8pgpJDYuojYXvb8KE4Hv7DCty12FrkqpKChgfHzspump, got %s", signal.Token0Address)
|
||||||
|
}
|
||||||
|
if signal.Token0AmountUint64 != 6235736929390 {
|
||||||
|
t.Fatalf("expected token0 amount 6235736929390, got %d", signal.Token0AmountUint64)
|
||||||
|
}
|
||||||
|
if signal.Token1AmountUint64 != 1379707703 {
|
||||||
|
t.Fatalf("expected token1 amount 1379707703, got %d", signal.Token1AmountUint64)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParsePhotonBuy(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, "4DCEcXAWBxagXoUNGhWsJ7qfxq5SuE5BG2cBDBqAY7sCHkBopaMJu33ZnXnFHqzPMmWxVxq6666KRF4hMHVB33Ux"),
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
if len(signals) != 1 {
|
||||||
|
t.Fatalf("expected 1 signal, got %d", len(signals))
|
||||||
|
}
|
||||||
|
|
||||||
|
signal := signals[0]
|
||||||
|
if signal.Label != "photon" {
|
||||||
|
t.Fatalf("expected terminal signal, got %s", signal.Label)
|
||||||
|
}
|
||||||
|
if signal.Event != "buy" {
|
||||||
|
t.Fatalf("expected buy event, got %s", signal.Event)
|
||||||
|
}
|
||||||
|
if signal.Maker != "8sUm7sLf3Steu6oVyVQqoA9GpFcMRz6YhrAidd4x7g7a" {
|
||||||
|
t.Fatalf("expected maker 8sUm7sLf3Steu6oVyVQqoA9GpFcMRz6YhrAidd4x7g7a, got %s", signal.Maker)
|
||||||
|
}
|
||||||
|
if signal.Token0Address != "jx4PF2MwC7AK9S8dTeYm29hM3vAN8Rtfs2VX4Vz5UVj" {
|
||||||
|
t.Fatalf("expected token0 address jx4PF2MwC7AK9S8dTeYm29hM3vAN8Rtfs2VX4Vz5UVj, got %s", signal.Token0Address)
|
||||||
|
}
|
||||||
|
if signal.Token0AmountUint64 != 1796593710706 {
|
||||||
|
t.Fatalf("expected token0 amount 1796593710706, got %d", signal.Token0AmountUint64)
|
||||||
|
}
|
||||||
|
if signal.Token1AmountUint64 != 1955555553 {
|
||||||
|
t.Fatalf("expected token1 amount 1955555553, got %d", signal.Token1AmountUint64)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user