Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35c5c83f4b | ||
|
|
5f97972194 | ||
|
|
741d333e1b | ||
|
|
594c46a1d2 | ||
|
|
45107aa8c3 | ||
|
|
36db4729d4 | ||
| 23f37cff2c | |||
| 6bab10866b | |||
| 83aa772710 | |||
| da51b19b50 | |||
| f39b89b497 | |||
| 26e07ec52e | |||
| 35c57c3c7a | |||
| 3e58b62e1f | |||
|
|
4c0abc5c34 | ||
|
|
d9aea3e8d7 | ||
|
|
b82b7d9b0e | ||
| d9bc106eb1 | |||
| 871dac8bd3 | |||
|
|
156fd9b0bf | ||
|
|
2504636fb0 |
187
README.md
187
README.md
@@ -15,6 +15,8 @@ go get github.com/samlior/libsam
|
|||||||
| fra | fra1.shreder.xyz:9991 |
|
| fra | fra1.shreder.xyz:9991 |
|
||||||
| ams | ams1.shreder.xyz:9991 |
|
| ams | ams1.shreder.xyz:9991 |
|
||||||
| ewr | ny1.shreder.xyz:9991 |
|
| ewr | ny1.shreder.xyz:9991 |
|
||||||
|
| uk | lon.shreder.xyz:9991 |
|
||||||
|
| jp | tyo.shreder.xyz:9991 |
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
@@ -105,6 +107,13 @@ See [example](./cmd/shreder/main.go).
|
|||||||
"keepAliveUrl": "http://germany.solana.dex.blxrbdn.com/ping",
|
"keepAliveUrl": "http://germany.solana.dex.blxrbdn.com/ping",
|
||||||
"tips": "0.001",
|
"tips": "0.001",
|
||||||
"rateLimit": 0
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "soyas",
|
||||||
|
"sendTxUrl": "fra.landing.soyas.xyz:9000",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -191,6 +200,13 @@ See [example](./cmd/shreder/main.go).
|
|||||||
"keepAliveUrl": "http://amsterdam.solana.dex.blxrbdn.com/api/v2/ping",
|
"keepAliveUrl": "http://amsterdam.solana.dex.blxrbdn.com/api/v2/ping",
|
||||||
"tips": "0.001",
|
"tips": "0.001",
|
||||||
"rateLimit": 0
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "soyas",
|
||||||
|
"sendTxUrl": "ams.landing.soyas.xyz:9000",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -278,6 +294,177 @@ See [example](./cmd/shreder/main.go).
|
|||||||
"keepAliveUrl": "http://ny.solana.dex.blxrbdn.com/api/v2/ping",
|
"keepAliveUrl": "http://ny.solana.dex.blxrbdn.com/api/v2/ping",
|
||||||
"tips": "0.001",
|
"tips": "0.001",
|
||||||
"rateLimit": 0
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "soyas",
|
||||||
|
"sendTxUrl": "nyc.landing.soyas.xyz:9000",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details><summary> London </summary>
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name": "helius",
|
||||||
|
"sendTxUrl": "http://lon-sender.helius-rpc.com/fast",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"keepAliveUrl": "http://lon-sender.helius-rpc.com/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "blockrazor",
|
||||||
|
"sendTxUrl": "london.solana-grpc.blockrazor.xyz:80",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "node1",
|
||||||
|
"sendTxUrl": "http://lon.node1.me",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"keepAliveUrl": "http://lon.node1.me/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nextblock",
|
||||||
|
"sendTxUrl": "http://london.nextblock.io/api/v2/submit",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"keepAliveUrl": "http://london.nextblock.io/api/v2/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "flashBlock",
|
||||||
|
"sendTxUrl": "http://london.flashblock.trade/api/v2/submit-batch",
|
||||||
|
"sendBundleUrl": "http://london.flashblock.trade/api/v2/submit-batch",
|
||||||
|
"keepAliveUrl": "http://london.flashblock.trade/api/v2/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stellium",
|
||||||
|
"sendTxUrl": "http://lhr1.flashrpc.com/be95e80d-afc2-4a48-b017-db021fc4c19e",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"keepAliveUrl": "http://lhr1.flashrpc.com/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "blocxroute",
|
||||||
|
"sendTxUrl": "http://uk.solana.dex.blxrbdn.com/api/v2/submit",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"keepAliveUrl": "http://uk.solana.dex.blxrbdn.com/api/v2/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "soyas",
|
||||||
|
"sendTxUrl": "lon.landing.soyas.xyz:9000",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
|
||||||
|
<details><summary> Japan </summary>
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name": "helius",
|
||||||
|
"sendTxUrl": "http://tyo-sender.helius-rpc.com/fast",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"keepAliveUrl": "http://tyo-sender.helius-rpc.com/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "0slot",
|
||||||
|
"sendTxUrl": "http://jp1.0slot.trade?api-key=3fec78a0d361418a8eff95be9ed85cc3&anti-mev=true",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"keepAliveUrl": "http://jp1.0slot.trade/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "blockrazor",
|
||||||
|
"sendTxUrl": "tokyo.solana-grpc.blockrazor.xyz:80",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "node1",
|
||||||
|
"sendTxUrl": "http://tk.node1.me",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"keepAliveUrl": "http://tk.node1.me/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nextblock",
|
||||||
|
"sendTxUrl": "http://tokyo.nextblock.io/api/v2/submit",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"keepAliveUrl": "http://tokyo.nextblock.io/api/v2/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "flashBlock",
|
||||||
|
"sendTxUrl": "http://tokyo.flashblock.trade/api/v2/submit-batch",
|
||||||
|
"sendBundleUrl": "http://tokyo.flashblock.trade/api/v2/submit-batch",
|
||||||
|
"keepAliveUrl": "http://tokyo.flashblock.trade/api/v2/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "astralane",
|
||||||
|
"sendTxUrl": "http://jp.gateway.astralane.io/iris?api-key=zhaozNc5OIadLPI3r9nUVVPpCZcQAUjngO6Tgr5XUJcmBrIisFaaZF81Ijn01Ytn",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"keepAliveUrl": "http://jp.gateway.astralane.io/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nozomi",
|
||||||
|
"sendTxUrl": "http://tyo1.nozomi.temporal.xyz/?c=34cff37e-f1a5-446a-98bb-66aa1b62cb74",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"keepAliveUrl": "http://tyo1.nozomi.temporal.xyz/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stellium",
|
||||||
|
"sendTxUrl": "http://tyo1.flashrpc.com/be95e80d-afc2-4a48-b017-db021fc4c19e",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"keepAliveUrl": "http://tyo1.flashrpc.com/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "blocxroute",
|
||||||
|
"sendTxUrl": "http://tokyo.solana.dex.blxrbdn.com/api/v2/submit",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"keepAliveUrl": "http://tokyo.solana.dex.blxrbdn.com/api/v2/ping",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "soyas",
|
||||||
|
"sendTxUrl": "tyo.landing.soyas.xyz:9000",
|
||||||
|
"sendBundleUrl": "",
|
||||||
|
"tips": "0.001",
|
||||||
|
"rateLimit": 0
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -50,8 +50,18 @@ func main() {
|
|||||||
"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",
|
"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"okxdexroutev2": {
|
||||||
|
AccountRequired: []string{
|
||||||
|
"proVF4pMXVaYqmy4NjniPh4pqKNfMmsihgd4wdkCX3u",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"dflow": {
|
||||||
|
AccountRequired: []string{
|
||||||
|
"DF1ow4tspfHX9JwWJsAb9epbkA8hmpSEAtxXy1V27QBH",
|
||||||
|
},
|
||||||
|
},
|
||||||
// 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)
|
||||||
}
|
}
|
||||||
@@ -65,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() {
|
||||||
@@ -84,13 +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 == "flas" {
|
if tx.Label == "okxdexroutev2" || tx.Label == "jupiterv6" || tx.Label == "dflow" {
|
||||||
if tx.Event == "buy" {
|
fmt.Println("===============", tx.TxHash, tx.Label, tx.Event, tx.Token0Address, "token:", tx.Token0Amount, "parse time:", tx.ParseEnd.Sub(tx.ParseStart))
|
||||||
fmt.Println("===============", tx.TxHash, tx.Program, tx.Event, tx.Token0Address, "token:", tx.Token0Amount, "sol:", tx.Token1Amount)
|
|
||||||
} else if tx.Event == "sell" {
|
|
||||||
fmt.Println("===============", tx.TxHash, tx.Program, tx.Event, tx.Token0Address, "token:", tx.Token0Amount)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//fmt.Println(txBatch[0].TxHash)
|
//fmt.Println(txBatch[0].TxHash)
|
||||||
|
|||||||
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
5
go.mod
5
go.mod
@@ -4,10 +4,13 @@ go 1.25.1
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BlockRazorinc/solana-trader-client-go v0.0.0-20250722092120-44561cb37455
|
github.com/BlockRazorinc/solana-trader-client-go v0.0.0-20250722092120-44561cb37455
|
||||||
|
github.com/gagliardetto/binary v0.8.0
|
||||||
github.com/gagliardetto/solana-go v1.12.0
|
github.com/gagliardetto/solana-go v1.12.0
|
||||||
|
github.com/hashicorp/golang-lru/v2 v2.0.7
|
||||||
github.com/mr-tron/base58 v1.2.0
|
github.com/mr-tron/base58 v1.2.0
|
||||||
github.com/near/borsh-go v0.3.2-0.20220516180422-1ff87d108454
|
github.com/near/borsh-go v0.3.2-0.20220516180422-1ff87d108454
|
||||||
github.com/panjf2000/ants/v2 v2.11.4
|
github.com/panjf2000/ants/v2 v2.11.4
|
||||||
|
github.com/quic-go/quic-go v0.58.0
|
||||||
github.com/shopspring/decimal v1.4.0
|
github.com/shopspring/decimal v1.4.0
|
||||||
google.golang.org/grpc v1.75.0
|
google.golang.org/grpc v1.75.0
|
||||||
google.golang.org/protobuf v1.36.10
|
google.golang.org/protobuf v1.36.10
|
||||||
@@ -19,10 +22,8 @@ require (
|
|||||||
github.com/blendle/zapdriver v1.3.1 // indirect
|
github.com/blendle/zapdriver v1.3.1 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/fatih/color v1.9.0 // indirect
|
github.com/fatih/color v1.9.0 // indirect
|
||||||
github.com/gagliardetto/binary v0.8.0 // indirect
|
|
||||||
github.com/gagliardetto/treeout v0.1.4 // indirect
|
github.com/gagliardetto/treeout v0.1.4 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/compress v1.13.6 // indirect
|
github.com/klauspost/compress v1.13.6 // indirect
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
||||||
|
|||||||
8
go.sum
8
go.sum
@@ -77,6 +77,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
|||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/quic-go/quic-go v0.58.0 h1:ggY2pvZaVdB9EyojxL1p+5mptkuHyX5MOSv4dgWF4Ug=
|
||||||
|
github.com/quic-go/quic-go v0.58.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU=
|
||||||
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||||
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
|
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
|
||||||
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
|
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
|
||||||
@@ -86,8 +88,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
|||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE=
|
github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE=
|
||||||
github.com/test-go/testify v1.1.4/go.mod h1:rH7cfJo/47vWGdi4GPj16x3/t1xGOj2YxzmNQzk2ghU=
|
github.com/test-go/testify v1.1.4/go.mod h1:rH7cfJo/47vWGdi4GPj16x3/t1xGOj2YxzmNQzk2ghU=
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||||
@@ -115,6 +117,8 @@ go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
|||||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||||
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
||||||
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||||
|
go.uber.org/mock v0.5.2 h1:LbtPTcP8A5k9WPXj54PPPbjcI4Y6lhyOZXn+VS7wNko=
|
||||||
|
go.uber.org/mock v0.5.2/go.mod h1:wLlUxC2vVTPTaE3UD51E0BGOAElKrILxhVSDYQLld5o=
|
||||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||||
|
|||||||
@@ -121,4 +121,5 @@ var SWQoSFeeAddresses = map[string]string{
|
|||||||
"ste11p5x8tJ53H1NbNQsRBg1YNRd4GcVpxtDw8PBpmb": enum.SWQoSAgentStellium,
|
"ste11p5x8tJ53H1NbNQsRBg1YNRd4GcVpxtDw8PBpmb": enum.SWQoSAgentStellium,
|
||||||
"ste11p7e2KLYou5bwtt35H7BM6uMdo4pvioGjJXKFcN": enum.SWQoSAgentStellium,
|
"ste11p7e2KLYou5bwtt35H7BM6uMdo4pvioGjJXKFcN": enum.SWQoSAgentStellium,
|
||||||
"ste11TMV68LMi1BguM4RQujtbNCZvf1sjsASpqgAvSX": enum.SWQoSAgentStellium,
|
"ste11TMV68LMi1BguM4RQujtbNCZvf1sjsASpqgAvSX": enum.SWQoSAgentStellium,
|
||||||
|
"soyas4s6L8KWZ8rsSk1mF3d1mQScoTGGAgjk98bF8nP": enum.SWQoSAgentSoyas,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,4 +12,5 @@ const (
|
|||||||
SWQoSAgentBlockRazor = "blockrazor"
|
SWQoSAgentBlockRazor = "blockrazor"
|
||||||
SWQoSAgentAstralane = "astralane"
|
SWQoSAgentAstralane = "astralane"
|
||||||
SWQoSAgentStellium = "stellium"
|
SWQoSAgentStellium = "stellium"
|
||||||
|
SWQoSAgentSoyas = "soyas"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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,
|
||||||
})
|
})
|
||||||
@@ -66,26 +128,53 @@ func (c *Client) ReadSync(ctx context.Context, txCh chan<- TxSignalBatch) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reboot the pool
|
||||||
|
c.pool.Reboot()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
response, err := stream.Recv()
|
var response *SubscribeTransactionsResponse
|
||||||
|
response, err = stream.Recv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
txBatch := ParseTransaction(response.Transaction, c.tableLoader)
|
if c.enableBlockStats {
|
||||||
|
slot := response.Transaction.Slot
|
||||||
|
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 {
|
if len(txBatch) == 0 {
|
||||||
continue
|
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 {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sync waiting for all tasks to complete
|
||||||
|
c.pool.Release()
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
409
pkg/shreder/dflow.go
Normal file
409
pkg/shreder/dflow.go
Normal file
@@ -0,0 +1,409 @@
|
|||||||
|
package shreder
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
bin "github.com/gagliardetto/binary"
|
||||||
|
"github.com/gagliardetto/solana-go"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
dflowProgramID = solana.MustPublicKeyFromBase58("DF1ow4tspfHX9JwWJsAb9epbkA8hmpSEAtxXy1V27QBH")
|
||||||
|
dflowProgramString = dflowProgramID.String()
|
||||||
|
|
||||||
|
dflowSwapDisc = []byte{248, 198, 158, 145, 225, 117, 135, 200}
|
||||||
|
dflowSwap2Disc = []byte{65, 75, 63, 76, 235, 91, 91, 136}
|
||||||
|
dflowSwapWithDestinationDisc = []byte{168, 172, 24, 77, 197, 156, 135, 101}
|
||||||
|
dflowSwapWithDestinationNative = []byte{205, 77, 127, 108, 241, 32, 196, 195}
|
||||||
|
dflowSwap2WithDestinationDisc = []byte{95, 123, 213, 246, 122, 1, 86, 231}
|
||||||
|
dflowSwap2WithDestinationNative = []byte{222, 100, 184, 146, 186, 196, 105, 165}
|
||||||
|
|
||||||
|
wrappedSOL = solana.MustPublicKeyFromBase58("So11111111111111111111111111111111111111112")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Action enum tags (0-based, per dflow_idl Action variants)
|
||||||
|
const (
|
||||||
|
ActWhirlpoolsSwap uint8 = iota
|
||||||
|
ActClearpoolsSwap
|
||||||
|
ActRaydiumAmmSwap
|
||||||
|
ActLifinityV2Swap
|
||||||
|
ActMeteoraDlmmSwap
|
||||||
|
ActRaydiumClmmSwap
|
||||||
|
ActRaydiumClmmSwapV2
|
||||||
|
ActPhoenixSwap
|
||||||
|
ActPumpFunBuy
|
||||||
|
ActPumpFunSell
|
||||||
|
ActGammaSwap
|
||||||
|
ActObricV2Swap
|
||||||
|
ActPumpFunAmmBuy
|
||||||
|
ActPumpFunAmmSell
|
||||||
|
ActSolFiSwap
|
||||||
|
ActRubiconSwap
|
||||||
|
ActMeteoraDammV1Swap
|
||||||
|
ActRaydiumCpSwap
|
||||||
|
ActStabbleStableSwap
|
||||||
|
ActTesseraVSwap
|
||||||
|
ActMeteoraDammV2Swap
|
||||||
|
ActRaydiumLaunchlabSwap
|
||||||
|
ActMeteoraDbcSwap
|
||||||
|
ActHumidiFiSwap
|
||||||
|
ActWhirlpoolsSwapV2
|
||||||
|
ActMeteoraDlmmSwapV2
|
||||||
|
ActZeroFiSwap
|
||||||
|
ActAlphaQSwap
|
||||||
|
ActTokenSwap
|
||||||
|
ActSolFiV2Swap
|
||||||
|
ActMozartSwap
|
||||||
|
ActDFlowDynamicRouteV1
|
||||||
|
ActHeavenSwap
|
||||||
|
ActNexusSwap
|
||||||
|
ActSarosDlmmSwap
|
||||||
|
ActTransferFee
|
||||||
|
ActTransferFeeWithMint
|
||||||
|
ActRecordId
|
||||||
|
ActRecordId2
|
||||||
|
ActManifestSwap
|
||||||
|
ActBisonFiSwap
|
||||||
|
ActSanctumInfinitySwap
|
||||||
|
ActSanctumInfinityLiquidity
|
||||||
|
ActOpenPredictionsOrder
|
||||||
|
ActScorchSwap
|
||||||
|
ActIncludeAccount
|
||||||
|
)
|
||||||
|
|
||||||
|
// DynamicRouteV1CandidateAction tags
|
||||||
|
const (
|
||||||
|
drv1SolFi uint8 = iota
|
||||||
|
drv1Rubicon
|
||||||
|
drv1TesseraV
|
||||||
|
drv1HumidiFi
|
||||||
|
drv1SolFiV2
|
||||||
|
drv1Mozart
|
||||||
|
drv1ObricV2
|
||||||
|
drv1Nexus
|
||||||
|
)
|
||||||
|
|
||||||
|
// PumpFun*Options { amount: u64, orchestrator_flags: OrchestratorFlags{flags u8} }
|
||||||
|
type pumpFunAction struct {
|
||||||
|
Amount uint64
|
||||||
|
Flags uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
type dflowAction struct {
|
||||||
|
Tag uint8
|
||||||
|
Pump *pumpFunAction
|
||||||
|
}
|
||||||
|
|
||||||
|
type dflowSwapParams struct {
|
||||||
|
Actions []dflowAction
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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, ActObricV2Swap,
|
||||||
|
ActSolFiSwap, ActRubiconSwap, ActMeteoraDammV1Swap, ActRaydiumCpSwap,
|
||||||
|
ActStabbleStableSwap, ActTesseraVSwap, ActMeteoraDammV2Swap, ActRaydiumLaunchlabSwap,
|
||||||
|
ActZeroFiSwap, ActAlphaQSwap, ActTokenSwap, ActSolFiV2Swap, ActMozartSwap, ActHeavenSwap,
|
||||||
|
ActNexusSwap, ActSarosDlmmSwap, ActManifestSwap, ActBisonFiSwap:
|
||||||
|
// amount u64 + orchestrator_flags u8
|
||||||
|
return nil, dec.SkipBytes(8 + 1)
|
||||||
|
case ActMeteoraDlmmSwap, ActRaydiumClmmSwap, ActRaydiumClmmSwapV2, ActMeteoraDlmmSwapV2:
|
||||||
|
// amount u64 + u8 + orchestrator_flags u8
|
||||||
|
return nil, dec.SkipBytes(8 + 1 + 1)
|
||||||
|
case ActPhoenixSwap:
|
||||||
|
// amount u64 + side u8 + orchestrator_flags u8
|
||||||
|
return nil, dec.SkipBytes(8 + 1 + 1)
|
||||||
|
case ActGammaSwap:
|
||||||
|
// amount u64 + endorsed bool + orchestrator_flags u8
|
||||||
|
return nil, dec.SkipBytes(8 + 1 + 1)
|
||||||
|
case ActPumpFunAmmSell, ActPumpFunAmmBuy, ActPumpFunBuy, ActPumpFunSell:
|
||||||
|
amt, err := dec.ReadUint64(binary.LittleEndian)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
flg, err := dec.ReadUint8()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
case ActHumidiFiSwap:
|
||||||
|
// amount u64 + swap_id u64 + orchestrator_flags u8
|
||||||
|
return nil, dec.SkipBytes(8 + 8 + 1)
|
||||||
|
case ActDFlowDynamicRouteV1:
|
||||||
|
// candidate_actions Vec<DynamicRouteV1CandidateAction> + amount u64 + orchestrator_flags u8
|
||||||
|
ln, err := dec.ReadUint32(binary.LittleEndian)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for j := uint32(0); j < ln; j++ {
|
||||||
|
t, err := dec.ReadUint8()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if t == drv1HumidiFi {
|
||||||
|
if err := dec.SkipBytes(8); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// other variants carry no payload
|
||||||
|
}
|
||||||
|
if err := dec.SkipBytes(8); err != nil { // amount
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return nil, dec.SkipBytes(1) // orchestrator_flags
|
||||||
|
case ActTransferFee, ActTransferFeeWithMint:
|
||||||
|
return nil, dec.SkipBytes(8)
|
||||||
|
case ActRecordId:
|
||||||
|
return nil, dec.SkipBytes(76)
|
||||||
|
case ActRecordId2:
|
||||||
|
return nil, dec.SkipBytes(4)
|
||||||
|
case ActSanctumInfinitySwap:
|
||||||
|
// amount u64 + src_lst_value_calc_accs u8 + dst_lst_value_calc_accs u8 + src_lst_index u32 + dst_lst_index u32 + orchestrator_flags u8
|
||||||
|
return nil, dec.SkipBytes(8 + 1 + 1 + 4 + 4 + 1)
|
||||||
|
case ActSanctumInfinityLiquidity:
|
||||||
|
// amount u64 + lst_value_calc_accs u8 + lst_index u32 + orchestrator_flags u8
|
||||||
|
return nil, dec.SkipBytes(8 + 1 + 4 + 1)
|
||||||
|
case ActOpenPredictionsOrder:
|
||||||
|
// nonce u64 + order_outcome u8 + quoted_out_amount u64 + slippage_bps u16 + platform_fee_recipient_vault pubkey(32) + platform_fee_scale u16
|
||||||
|
return nil, dec.SkipBytes(8 + 1 + 8 + 2 + 32 + 2)
|
||||||
|
case ActScorchSwap:
|
||||||
|
// amount u64 + id u128 + orchestrator_flags u8
|
||||||
|
return nil, dec.SkipBytes(8 + 16 + 1)
|
||||||
|
case ActIncludeAccount:
|
||||||
|
return nil, nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported action tag %d", tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SwapParams: actions Vec<Action>, quoted_out_amount u64, slippage_bps u16, platform_fee_bps u16
|
||||||
|
func decodeSwapParams(data []byte) (*dflowSwapParams, error) {
|
||||||
|
dec := bin.NewBorshDecoder(data)
|
||||||
|
out := &dflowSwapParams{}
|
||||||
|
ln, err := dec.ReadUint32(binary.LittleEndian)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out.Actions = make([]dflowAction, 0, ln)
|
||||||
|
for i := uint32(0); i < ln; i++ {
|
||||||
|
tag, err := dec.ReadUint8()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("actions[%d] tag: %w", i, err)
|
||||||
|
}
|
||||||
|
pump, err := skipDflowAction(dec, tag)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("actions[%d]: %w", i, err)
|
||||||
|
}
|
||||||
|
out.Actions = append(out.Actions, dflowAction{Tag: tag, Pump: pump})
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swap2Params: actions Vec<Action>, quoted_out_amount u64, slippage_bps u16, platform_fee_bps u16, positive_slippage_fee_limit_pct u8
|
||||||
|
func decodeSwap2Params(data []byte) (*dflowSwapParams, error) {
|
||||||
|
dec := bin.NewBorshDecoder(data)
|
||||||
|
out := &dflowSwapParams{}
|
||||||
|
ln, err := dec.ReadUint32(binary.LittleEndian)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out.Actions = make([]dflowAction, 0, ln)
|
||||||
|
for i := uint32(0); i < ln; i++ {
|
||||||
|
tag, err := dec.ReadUint8()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("actions[%d] tag: %w", i, err)
|
||||||
|
}
|
||||||
|
pump, err := skipDflowAction(dec, tag)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("actions[%d]: %w", i, err)
|
||||||
|
}
|
||||||
|
out.Actions = append(out.Actions, dflowAction{Tag: tag, Pump: pump})
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func findDflowPumpAmmMints(staticKeys []solana.PublicKey, accounts []uint8) (solana.PublicKey, solana.PublicKey, bool, error) {
|
||||||
|
for i, acctIdx := range accounts {
|
||||||
|
key, err := getStaticKey(staticKeys, 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 := getStaticKey(staticKeys, int(accounts[baseIdx]))
|
||||||
|
if err != nil {
|
||||||
|
return solana.PublicKey{}, solana.PublicKey{}, false, err
|
||||||
|
}
|
||||||
|
quoteMint, err := getStaticKey(staticKeys, 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) {
|
||||||
|
msg := tx.Message
|
||||||
|
if instructionIndex >= len(msg.Instructions) {
|
||||||
|
return nil, fmt.Errorf("instruction index out of bounds")
|
||||||
|
}
|
||||||
|
ix := msg.Instructions[instructionIndex]
|
||||||
|
if len(ix.Data) < 8 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
disc := ix.Data[:8]
|
||||||
|
payload := ix.Data[8:]
|
||||||
|
|
||||||
|
var params *dflowSwapParams
|
||||||
|
switch {
|
||||||
|
case bytes.Equal(disc, dflowSwapDisc), bytes.Equal(disc, dflowSwapWithDestinationDisc), bytes.Equal(disc, dflowSwapWithDestinationNative):
|
||||||
|
params, err = decodeSwapParams(payload)
|
||||||
|
case bytes.Equal(disc, dflowSwap2Disc), bytes.Equal(disc, dflowSwap2WithDestinationDisc), bytes.Equal(disc, dflowSwap2WithDestinationNative):
|
||||||
|
params, err = decodeSwap2Params(payload)
|
||||||
|
default:
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if params == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
pumpAmmBuy *pumpFunAction
|
||||||
|
pumpAmmSell *pumpFunAction
|
||||||
|
pumpBuy *pumpFunAction
|
||||||
|
pumpSell *pumpFunAction
|
||||||
|
)
|
||||||
|
for _, act := range params.Actions {
|
||||||
|
if act.Pump == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch act.Tag {
|
||||||
|
case ActPumpFunAmmSell:
|
||||||
|
pumpAmmSell = act.Pump
|
||||||
|
case ActPumpFunAmmBuy:
|
||||||
|
pumpAmmBuy = act.Pump
|
||||||
|
case ActPumpFunBuy:
|
||||||
|
pumpBuy = act.Pump
|
||||||
|
case ActPumpFunSell:
|
||||||
|
pumpSell = act.Pump
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.Message.StaticAccountKeys, ix.Accounts)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
out = append(out, &TxSignal{
|
||||||
|
TxHash: tx.Signatures[0].String(),
|
||||||
|
Maker: tx.Message.StaticAccountKeys[0].String(),
|
||||||
|
Program: "PumpAMM",
|
||||||
|
Event: event,
|
||||||
|
Token0Address: baseMint.String(),
|
||||||
|
Token1Address: wsolMint,
|
||||||
|
Token0Amount: token0Amount,
|
||||||
|
Token1Amount: token1Amount,
|
||||||
|
ExactSOL: exactSol,
|
||||||
|
Token0AmountUint64: token0AmountUint64,
|
||||||
|
Token1AmountUint64: token1AmountUint64,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.Message.StaticAccountKeys, 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.Message.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
|
||||||
|
}
|
||||||
1989
pkg/shreder/dflow_idl.json
Normal file
1989
pkg/shreder/dflow_idl.json
Normal file
File diff suppressed because it is too large
Load Diff
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
@@ -22,6 +22,10 @@ var (
|
|||||||
|
|
||||||
jupiterSharedAccountsExactOutRouteV2 = []byte{53, 96, 229, 202, 216, 187, 250, 24}
|
jupiterSharedAccountsExactOutRouteV2 = []byte{53, 96, 229, 202, 216, 187, 250, 24}
|
||||||
jupiterSharedAccountsRouteV2 = []byte{209, 152, 83, 147, 124, 254, 216, 233}
|
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
|
type Side uint8
|
||||||
@@ -819,14 +823,37 @@ func decodeJupiterV6SharedAccountsRouteV2Arg(data []byte) (*JupiterV6SharedAccou
|
|||||||
return &JupiterV6SharedAccountsRouteV2Arg{ID: id, In: inAmt, QuotedOut: quotedOut, Slippage: slippage, PlatFee: pf, PosSlip: pos, RoutePlan: plan}, nil
|
return &JupiterV6SharedAccountsRouteV2Arg{ID: id, In: inAmt, QuotedOut: quotedOut, Slippage: slippage, PlatFee: pf, PosSlip: pos, RoutePlan: plan}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func 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) {
|
func pumpSwapSellAtIdx0(amount uint64, plan []RoutePlanStep) (uint64, int) {
|
||||||
var (
|
var (
|
||||||
ret uint64
|
ret uint64
|
||||||
i int
|
i int
|
||||||
)
|
)
|
||||||
for _, step := range plan {
|
for _, step := range plan {
|
||||||
if step.InputIdx == 0 &&
|
if !isInputIdx0(step.InputIdx) || !isPumpSwapSellKind(step.Swap.Kind) {
|
||||||
(step.Swap.Kind == PumpSwapSell || step.Swap.Kind == PumpSwapSellV2 || step.Swap.Kind == PumpSwapSellV3) {
|
continue
|
||||||
|
}
|
||||||
i++
|
i++
|
||||||
if ret > 0 {
|
if ret > 0 {
|
||||||
// multiple pumpSwapSell at inputIdx=0? should not happen
|
// multiple pumpSwapSell at inputIdx=0? should not happen
|
||||||
@@ -834,7 +861,6 @@ func pumpSwapSellAtIdx0(amount uint64, plan []RoutePlanStep) (uint64, int) {
|
|||||||
}
|
}
|
||||||
ret += amount * uint64(step.Percent) / 100
|
ret += amount * uint64(step.Percent) / 100
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return ret, i
|
return ret, i
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -844,20 +870,382 @@ func pumpSwapSellAtIdx0V2(amount uint64, plan []RoutePlanStepV2) (uint64, int) {
|
|||||||
i int
|
i int
|
||||||
)
|
)
|
||||||
for _, step := range plan {
|
for _, step := range plan {
|
||||||
if step.InputIdx == 0 &&
|
if !isInputIdx0(step.InputIdx) || !isPumpSwapSellKind(step.Swap.Kind) {
|
||||||
(step.Swap.Kind == PumpSwapSell || step.Swap.Kind == PumpSwapSellV2 || step.Swap.Kind == PumpSwapSellV3) {
|
continue
|
||||||
|
}
|
||||||
i++
|
i++
|
||||||
if ret > 0 {
|
if ret > 0 {
|
||||||
// multiple pumpSwapSell at inputIdx=0? should not happen
|
// multiple pumpSwapSell at inputIdx=0? should not happen
|
||||||
|
|
||||||
return 0, i
|
return 0, i
|
||||||
}
|
}
|
||||||
ret += amount * uint64(step.Bps) / 10000
|
ret += amount * uint64(step.Bps) / 10000
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return ret, i
|
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 compiledInstruction, 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 := getStaticKey(tx.Message.StaticAccountKeys, 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.Message.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 := getStaticKey(tx.Message.StaticAccountKeys, 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.Message.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(staticKeys []solana.PublicKey, accounts []uint8) (solana.PublicKey, bool, error) {
|
||||||
|
for i, acctIdx := range accounts {
|
||||||
|
key, err := getStaticKey(staticKeys, 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 := getStaticKey(staticKeys, int(accounts[i+3]))
|
||||||
|
if err != nil {
|
||||||
|
return solana.PublicKey{}, false, err
|
||||||
|
}
|
||||||
|
return mint, true, nil
|
||||||
|
}
|
||||||
|
return solana.PublicKey{}, false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func jupiterV6SourceDestMints(msg versionedMessage, instruction compiledInstruction, 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 := getStaticKey(msg.StaticAccountKeys, int(instruction.Accounts[3]))
|
||||||
|
if err != nil {
|
||||||
|
return solana.PublicKey{}, solana.PublicKey{}, false, err
|
||||||
|
}
|
||||||
|
dst, err := getStaticKey(msg.StaticAccountKeys, 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 := getStaticKey(msg.StaticAccountKeys, int(instruction.Accounts[7]))
|
||||||
|
if err != nil {
|
||||||
|
return solana.PublicKey{}, solana.PublicKey{}, false, err
|
||||||
|
}
|
||||||
|
dst, err := getStaticKey(msg.StaticAccountKeys, 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
|
// only decodes inputIdx = 0 container pumpSwap instructions for now
|
||||||
func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
|
func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||||
msg := tx.Message
|
msg := tx.Message
|
||||||
@@ -878,7 +1266,16 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
var (
|
var (
|
||||||
sourceMint solana.PublicKey
|
sourceMint solana.PublicKey
|
||||||
inputAmount uint64
|
inputAmount uint64
|
||||||
|
routeIn uint64
|
||||||
|
routeOut uint64
|
||||||
planCount int
|
planCount int
|
||||||
|
buySwap pumpSwapBuyMatch
|
||||||
|
buySwapCnt int
|
||||||
|
wrapped pumpWrappedMatch
|
||||||
|
wrappedCnt int
|
||||||
|
wrappedAny pumpWrappedMatch
|
||||||
|
wrappedAnyC int
|
||||||
|
exactOut bool
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -890,40 +1287,334 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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):
|
case bytes.Equal(disc, jupiterSharedAccountsRouteV2):
|
||||||
args, err := decodeJupiterV6SharedAccountsRouteV2Arg(instruction.Data[8:])
|
args, err := decodeJupiterV6SharedAccountsRouteV2Arg(instruction.Data[8:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
inputAmount, 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):
|
case bytes.Equal(disc, jupiterRoute):
|
||||||
args, err := decodeJupiterV6RouteArg(instruction.Data[8:])
|
args, err := decodeJupiterV6RouteArg(instruction.Data[8:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
_ = args
|
sig, handled, err := parseJupiterPumpAmmRoute(tx, instruction, args.In, args.QuotedOut, args.Plan)
|
||||||
inputAmount, planCount = pumpSwapSellAtIdx0(args.In, args.Plan)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if handled {
|
||||||
|
return 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):
|
case bytes.Equal(disc, jupiterSharedAccountsRoute):
|
||||||
args, err := decodeJupiterV6SharedAccountsRouteArg(instruction.Data[8:])
|
args, err := decodeJupiterV6SharedAccountsRouteArg(instruction.Data[8:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
_ = args
|
_ = args
|
||||||
inputAmount, 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:
|
default:
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
if bytes.Equal(disc, jupiterRoute) {
|
||||||
|
if len(instruction.Accounts) < 13 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
destMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[5]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if isToken1Mint(destMint) {
|
||||||
|
pumpKey, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[9]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !pumpKey.Equals(pumpProgramID) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
token0Mint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[12]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
token0Amount := decimal.Zero
|
||||||
|
if routeIn > 0 {
|
||||||
|
token0Amount = formatTokenAmount(routeIn)
|
||||||
|
}
|
||||||
|
return &TxSignal{
|
||||||
|
TxHash: tx.Signatures[0].String(),
|
||||||
|
Maker: tx.Message.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 &TxSignal{
|
||||||
|
TxHash: tx.Signatures[0].String(),
|
||||||
|
Maker: tx.Message.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.Message.StaticAccountKeys, instruction.Accounts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
token1Mint := solana.WrappedSol
|
||||||
|
token1IsStable := false
|
||||||
|
srcMint, dstMint, ok, err := jupiterV6SourceDestMints(tx.Message, 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 &TxSignal{
|
||||||
|
TxHash: tx.Signatures[0].String(),
|
||||||
|
Maker: tx.Message.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.Message.StaticAccountKeys, instruction.Accounts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
token1Mint := solana.WrappedSol
|
||||||
|
token1IsStable := false
|
||||||
|
srcMint, dstMint, ok, err := jupiterV6SourceDestMints(tx.Message, 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 &TxSignal{
|
||||||
|
TxHash: tx.Signatures[0].String(),
|
||||||
|
Maker: tx.Message.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 {
|
if planCount > 1 {
|
||||||
// multiple pumpSwapSell at inputIdx=0? should not happen
|
// multiple pumpSwapSell at inputIdx=0? should not happen
|
||||||
logger.Warn("pumpSwapSell at inputIdx=0: multiple instances found", "tx", tx.Signatures[0].String(), "planCount", planCount)
|
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
|
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.
|
// 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 {
|
if len(instruction.Accounts) < 6 {
|
||||||
return nil, fmt.Errorf("not enough accounts for jupiter v6 v2 instruction")
|
return nil, fmt.Errorf("not enough accounts for jupiter v6 v2 instruction")
|
||||||
}
|
}
|
||||||
@@ -931,14 +1622,21 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
destMint, err = getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[4]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
destMintOK = true
|
||||||
|
sourceMintOK = true
|
||||||
|
|
||||||
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,16 +1646,15 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if srcIdx == 0 {
|
if srcIdx == 0 || srcIdx+1 >= uint8(len(accounts)) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceMint, 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
|
||||||
}
|
}
|
||||||
|
quoteMint, err = getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx+1]))
|
||||||
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx+1]))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -965,7 +1662,7 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if bytes.Equal(disc, jupiterSharedAccountsRoute) {
|
} else if bytes.Equal(disc, jupiterSharedAccountsRoute) || bytes.Equal(disc, jupiterSharedAccountsExactOutRoute) {
|
||||||
if len(instruction.Accounts) < 12 {
|
if len(instruction.Accounts) < 12 {
|
||||||
return nil, fmt.Errorf("not enough accounts for jupiter v6 jupiterSharedAccountsRoute instruction")
|
return nil, fmt.Errorf("not enough accounts for jupiter v6 jupiterSharedAccountsRoute instruction")
|
||||||
}
|
}
|
||||||
@@ -973,13 +1670,20 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
destMint, err = getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[8]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
destMintOK = true
|
||||||
|
sourceMintOK = true
|
||||||
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
|
||||||
@@ -989,16 +1693,16 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if srcIdx == 0 {
|
if srcIdx == 0 || srcIdx+1 >= uint8(len(accounts)) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceMint, 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
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
@@ -1013,10 +1717,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
|
||||||
@@ -1026,39 +1728,75 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if srcIdx == 0 {
|
if srcIdx == 0 || srcIdx+1 >= uint8(len(accounts)) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
sourceMint, 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
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
if !quoteMint.Equals(solana.WrappedSol) {
|
if !quoteMint.Equals(solana.WrappedSol) {
|
||||||
return nil, nil
|
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{
|
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: baseMint.String(),
|
||||||
Token1Address: wsolMint,
|
Token1Address: wsolMint,
|
||||||
Token0Amount: formatTokenAmount(inputAmount),
|
Token0Amount: token0Amount,
|
||||||
Token1Amount: decimal.Zero,
|
Token1Amount: token1Amount,
|
||||||
Program: "PumpAMM",
|
Program: "PumpAMM",
|
||||||
Event: "sell",
|
Event: event,
|
||||||
IsToken2022: false,
|
IsToken2022: false,
|
||||||
IsMayhemMode: false,
|
IsMayhemMode: false,
|
||||||
ExactSOL: false,
|
ExactSOL: exactSol,
|
||||||
Block: tx.Block,
|
Block: tx.Block,
|
||||||
Token0AmountUint64: inputAmount,
|
Token0AmountUint64: token0AmountUint64,
|
||||||
Token1AmountUint64: 0,
|
Token1AmountUint64: token1AmountUint64,
|
||||||
}
|
}
|
||||||
|
|
||||||
return signal, nil
|
return signal, nil
|
||||||
|
|||||||
@@ -1,5 +1,368 @@
|
|||||||
package shreder
|
package shreder
|
||||||
|
|
||||||
//func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
|
import (
|
||||||
//
|
"bytes"
|
||||||
//}
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
bin "github.com/gagliardetto/binary"
|
||||||
|
"github.com/gagliardetto/solana-go"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
okxDexRouteV2ProgramID = solana.MustPublicKeyFromBase58("proVF4pMXVaYqmy4NjniPh4pqKNfMmsihgd4wdkCX3u")
|
||||||
|
okxDexRouteV2ProgramIDString = okxDexRouteV2ProgramID.String()
|
||||||
|
|
||||||
|
okxSwapTobDisc = []byte{170, 41, 85, 177, 132, 80, 31, 53}
|
||||||
|
okxSwapTobWithReceiverDisc = []byte{223, 170, 216, 234, 204, 6, 241, 25}
|
||||||
|
okxSwapTocDisc = []byte{187, 201, 212, 51, 16, 155, 236, 60}
|
||||||
|
okxSwapTocV2Disc = []byte{127, 214, 107, 189, 23, 90, 47, 104}
|
||||||
|
)
|
||||||
|
|
||||||
|
// IDL: SwapArgs { order_id:u64, amount_in:u64, expect_amount_out:u64, slippage:u16, routes: Vec<Route> }
|
||||||
|
// IDL: Route { dex: Dex(enum), weight:u16, index:u8 }
|
||||||
|
|
||||||
|
type OkxV2Route struct {
|
||||||
|
Dex OkxV2SwapKind
|
||||||
|
Weight uint16
|
||||||
|
Index uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
type OkxV2SwapArgs struct {
|
||||||
|
OrderID uint64
|
||||||
|
AmountIn uint64
|
||||||
|
ExpectAmountOut uint64
|
||||||
|
Slippage uint16
|
||||||
|
Routes []OkxV2Route
|
||||||
|
}
|
||||||
|
|
||||||
|
type OkxV2SwapKind uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
OKCV2_SplTokenSwap OkxV2SwapKind = iota
|
||||||
|
OKCV2_StableSwap
|
||||||
|
OKCV2_Whirlpool
|
||||||
|
OKCV2_MeteoraDynamicpool
|
||||||
|
OKCV2_RaydiumSwap
|
||||||
|
OKCV2_RaydiumStableSwap
|
||||||
|
OKCV2_RaydiumClmmSwap
|
||||||
|
OKCV2_AldrinExchangeV1
|
||||||
|
OKCV2_AldrinExchangeV2
|
||||||
|
OKCV2_LifinityV1
|
||||||
|
OKCV2_LifinityV2
|
||||||
|
OKCV2_RaydiumClmmSwapV2
|
||||||
|
OKCV2_FluxBeam
|
||||||
|
OKCV2_MeteoraDlmm
|
||||||
|
OKCV2_RaydiumCpmmSwap
|
||||||
|
OKCV2_OpenBookV2
|
||||||
|
OKCV2_WhirlpoolV2
|
||||||
|
OKCV2_Phoenix
|
||||||
|
OKCV2_ObricV2
|
||||||
|
OKCV2_SanctumAddLiq
|
||||||
|
OKCV2_SanctumRemoveLiq
|
||||||
|
OKCV2_SanctumNonWsolSwap
|
||||||
|
OKCV2_SanctumWsolSwap
|
||||||
|
OKCV2_PumpfunBuy
|
||||||
|
OKCV2_PumpfunSell
|
||||||
|
OKCV2_StabbleSwap
|
||||||
|
OKCV2_SanctumRouter
|
||||||
|
OKCV2_MeteoraVaultDeposit
|
||||||
|
OKCV2_MeteoraVaultWithdraw
|
||||||
|
OKCV2_Saros
|
||||||
|
OKCV2_MeteoraLst
|
||||||
|
OKCV2_Solfi
|
||||||
|
OKCV2_QualiaSwap
|
||||||
|
OKCV2_Zerofi
|
||||||
|
OKCV2_PumpfunammBuy
|
||||||
|
OKCV2_PumpfunammSell
|
||||||
|
OKCV2_Virtuals
|
||||||
|
OKCV2_VertigoBuy
|
||||||
|
OKCV2_VertigoSell
|
||||||
|
OKCV2_PerpetualsAddLiq
|
||||||
|
OKCV2_PerpetualsRemoveLiq
|
||||||
|
OKCV2_PerpetualsSwap
|
||||||
|
OKCV2_RaydiumLaunchpad
|
||||||
|
OKCV2_LetsBonkFun
|
||||||
|
OKCV2_Woofi
|
||||||
|
OKCV2_MeteoraDbc
|
||||||
|
OKCV2_MeteoraDlmmSwap2
|
||||||
|
OKCV2_MeteoraDAMMV2
|
||||||
|
OKCV2_Gavel
|
||||||
|
OKCV2_BoopfunBuy
|
||||||
|
OKCV2_BoopfunSell
|
||||||
|
OKCV2_MeteoraDbc2
|
||||||
|
OKCV2_GooseFX
|
||||||
|
OKCV2_Dooar
|
||||||
|
OKCV2_Numeraire
|
||||||
|
OKCV2_SaberDecimalWrapperDeposit
|
||||||
|
OKCV2_SaberDecimalWrapperWithdraw
|
||||||
|
OKCV2_SarosDlmm
|
||||||
|
OKCV2_OneDexSwap
|
||||||
|
OKCV2_Manifest
|
||||||
|
OKCV2_ByrealClmm
|
||||||
|
OKCV2_PancakeSwapV3Swap
|
||||||
|
OKCV2_PancakeSwapV3SwapV2
|
||||||
|
OKCV2_Tessera
|
||||||
|
OKCV2_SolRfq
|
||||||
|
OKCV2_Humidifi
|
||||||
|
OKCV2_HeavenBuy
|
||||||
|
OKCV2_HeavenSell
|
||||||
|
OKCV2_SolfiV2
|
||||||
|
OKCV2_Goonfi
|
||||||
|
OKCV2_MoonitBuy
|
||||||
|
OKCV2_MoonitSell
|
||||||
|
OKCV2_RaydiumSwapV2
|
||||||
|
OKCV2_Whalestreet
|
||||||
|
OKCV2_SugarMoneyBuy
|
||||||
|
OKCV2_SugarMoneySell
|
||||||
|
OKCV2_MeteoraDAMMV2Swap2
|
||||||
|
OKCV2_AlphaQ
|
||||||
|
OKCV2_FutarchyAmm
|
||||||
|
OKCV2_PumpfunBuy2
|
||||||
|
OKCV2_PumpfunSell2
|
||||||
|
OKCV2_HumidifiSwap2
|
||||||
|
OKCV2_Scorch
|
||||||
|
OKCV2_JupiterLendDeposit
|
||||||
|
OKCV2_JupiterLendRedeem
|
||||||
|
OKCV2_TokkaAmm
|
||||||
|
)
|
||||||
|
|
||||||
|
func decodeOkxSwapTobSwapArgs(data []byte) (*OkxV2SwapArgs, error) {
|
||||||
|
dec := bin.NewBorshDecoder(data)
|
||||||
|
return decodeOkxV2SwapArgs(dec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeOkxSwapTobWithReceiverSwapArgs(data []byte) (*OkxV2SwapArgs, error) {
|
||||||
|
dec := bin.NewBorshDecoder(data)
|
||||||
|
return decodeOkxV2SwapArgs(dec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeOkxSwapTocSwapArgs(data []byte) (*OkxV2SwapArgs, error) {
|
||||||
|
dec := bin.NewBorshDecoder(data)
|
||||||
|
return decodeOkxV2SwapArgs(dec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeOkxSwapTocV2SwapArgs(data []byte) (*OkxV2SwapArgs, error) {
|
||||||
|
dec := bin.NewBorshDecoder(data)
|
||||||
|
return decodeOkxV2SwapArgs(dec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func skipOkxV2DexPayload(dec *bin.Decoder, dex OkxV2SwapKind) error {
|
||||||
|
// IMPORTANT: In IDL, Dex is an enum. Most variants have no fields, but some carry payload.
|
||||||
|
// We only need to keep decoding aligned for SwapArgs.routes.
|
||||||
|
switch dex {
|
||||||
|
case OKCV2_SolRfq:
|
||||||
|
// fields: 6*u64 + 2*bool
|
||||||
|
// rfq_id, expected_maker_amount, expected_taker_amount, maker_send_amount,
|
||||||
|
// taker_send_amount, expiry, maker_use_native_sol, taker_use_native_sol
|
||||||
|
if err := dec.SkipBytes(8 * 6); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return dec.SkipBytes(2)
|
||||||
|
case OKCV2_SugarMoneyBuy, OKCV2_SugarMoneySell:
|
||||||
|
// fields: u8 + u8
|
||||||
|
return dec.SkipBytes(2)
|
||||||
|
case OKCV2_HumidifiSwap2:
|
||||||
|
// fields: u64
|
||||||
|
return dec.SkipBytes(8)
|
||||||
|
case OKCV2_Scorch:
|
||||||
|
// fields: u128 => 16 bytes
|
||||||
|
return dec.SkipBytes(16)
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeOkxV2SwapArgs(dec *bin.Decoder) (*OkxV2SwapArgs, error) {
|
||||||
|
out := &OkxV2SwapArgs{}
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if out.OrderID, err = dec.ReadUint64(binary.LittleEndian); err != nil {
|
||||||
|
return nil, fmt.Errorf("read order_id: %w", err)
|
||||||
|
}
|
||||||
|
if out.AmountIn, err = dec.ReadUint64(binary.LittleEndian); err != nil {
|
||||||
|
return nil, fmt.Errorf("read amount_in: %w", err)
|
||||||
|
}
|
||||||
|
if out.ExpectAmountOut, err = dec.ReadUint64(binary.LittleEndian); err != nil {
|
||||||
|
return nil, fmt.Errorf("read expect_amount_out: %w", err)
|
||||||
|
}
|
||||||
|
if out.Slippage, err = dec.ReadUint16(binary.LittleEndian); err != nil {
|
||||||
|
return nil, fmt.Errorf("read slippage: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// routes: Vec<Route>
|
||||||
|
routesLen, err := dec.ReadUint32(binary.LittleEndian)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("read routes len: %w", err)
|
||||||
|
}
|
||||||
|
out.Routes = make([]OkxV2Route, 0, routesLen)
|
||||||
|
for i := uint32(0); i < routesLen; i++ {
|
||||||
|
// Route { dex: Dex(enum tag u8 [+ payload]), weight: u16, index: u8 }
|
||||||
|
tag, err := dec.ReadUint8()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("read routes[%d].dex: %w", i, err)
|
||||||
|
}
|
||||||
|
dex := OkxV2SwapKind(tag)
|
||||||
|
if err := skipOkxV2DexPayload(dec, dex); err != nil {
|
||||||
|
return nil, fmt.Errorf("skip routes[%d].dex payload (%d): %w", i, tag, err)
|
||||||
|
}
|
||||||
|
weight, err := dec.ReadUint16(binary.LittleEndian)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("read routes[%d].weight: %w", i, err)
|
||||||
|
}
|
||||||
|
idx, err := dec.ReadUint8()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("read routes[%d].index: %w", i, err)
|
||||||
|
}
|
||||||
|
out.Routes = append(out.Routes, OkxV2Route{Dex: dex, Weight: weight, Index: idx})
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type OkxV2SwapSolRfq struct {
|
||||||
|
RfqId uint64
|
||||||
|
expectedMakerAmount uint64
|
||||||
|
expectedTakerAmount uint64
|
||||||
|
makerSendAmount uint64
|
||||||
|
takerSendAmount uint64
|
||||||
|
expiry uint64
|
||||||
|
makerUseNativeSol bool
|
||||||
|
takerUseNativeSol bool
|
||||||
|
}
|
||||||
|
type OkxV2SwapSugarMoney struct {
|
||||||
|
BondingCurveBump uint8
|
||||||
|
|
||||||
|
BondingCurveSolAssociatedAccountBump uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
type OkxV2SwapHumidifiSwap2 struct {
|
||||||
|
SwapId uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
type OkxV2SwapScorch struct {
|
||||||
|
Id [16]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseOkxDexRouteV2Instruction(tx *versionedTransaction, instructionIndex int) (*TxSignal, error) {
|
||||||
|
msg := tx.Message
|
||||||
|
if instructionIndex >= len(msg.Instructions) {
|
||||||
|
return nil, fmt.Errorf("instruction index out of bounds")
|
||||||
|
}
|
||||||
|
ix := msg.Instructions[instructionIndex]
|
||||||
|
if len(ix.Data) < 8 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
disc := ix.Data[:8]
|
||||||
|
data := ix.Data[8:]
|
||||||
|
|
||||||
|
var (
|
||||||
|
args *OkxV2SwapArgs
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
switch {
|
||||||
|
case bytes.Equal(disc, okxSwapTobDisc):
|
||||||
|
args, err = decodeOkxSwapTobSwapArgs(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("decode swap_tob args: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
case bytes.Equal(disc, okxSwapTobWithReceiverDisc):
|
||||||
|
args, err = decodeOkxSwapTobWithReceiverSwapArgs(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("decode swap_tob_with_receiver args: %w", err)
|
||||||
|
}
|
||||||
|
case bytes.Equal(disc, okxSwapTocDisc):
|
||||||
|
args, err = decodeOkxSwapTocSwapArgs(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("decode swap_toc args: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
case bytes.Equal(disc, okxSwapTocV2Disc):
|
||||||
|
args, err = decodeOkxSwapTocV2SwapArgs(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("decode swap_toc_v2 args: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
if len(ix.Accounts) < 15 {
|
||||||
|
return nil, fmt.Errorf("invalid account count: %d", len(ix.Accounts))
|
||||||
|
}
|
||||||
|
var (
|
||||||
|
inputAmount uint64
|
||||||
|
routeCount int
|
||||||
|
)
|
||||||
|
for _, route := range args.Routes {
|
||||||
|
if route.Index == 1 && (route.Dex == OKCV2_PumpfunammSell ||
|
||||||
|
route.Dex == OKCV2_PumpfunSell2) {
|
||||||
|
routeCount++
|
||||||
|
inputAmount = args.AmountIn * uint64(route.Weight) / 10000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if routeCount > 1 {
|
||||||
|
logger.Warn("pumpSwapSell at inputIdx=0: multiple instances found", "tx", tx.Signatures[0].String(), "routeCount", routeCount)
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
if inputAmount == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
srcMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(ix.Accounts[3]))
|
||||||
|
|
||||||
|
var (
|
||||||
|
srcIdx uint8
|
||||||
|
)
|
||||||
|
if len(ix.Accounts) <= 15 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
accounts := ix.Accounts[14:]
|
||||||
|
for i, acctIdx := range accounts {
|
||||||
|
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if key.Equals(pumpAmmProgramID) {
|
||||||
|
srcIdx = uint8(i + 6)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if srcIdx == 0 || int(srcIdx+1) >= len(accounts) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
baseMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !baseMint.Equals(srcMint) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(accounts[srcIdx+1]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !quoteMint.Equals(solana.WrappedSol) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &TxSignal{
|
||||||
|
TxHash: tx.Signatures[0].String(),
|
||||||
|
Maker: tx.Message.StaticAccountKeys[0].String(),
|
||||||
|
Token0Address: baseMint.String(),
|
||||||
|
Token1Address: wsolMint,
|
||||||
|
Token0Amount: formatTokenAmount(inputAmount),
|
||||||
|
Token1Amount: decimal.Zero,
|
||||||
|
Event: "sell",
|
||||||
|
Program: "PumpAMM",
|
||||||
|
IsProcessed: false,
|
||||||
|
IsToken2022: false,
|
||||||
|
IsMayhemMode: false,
|
||||||
|
ExactSOL: false,
|
||||||
|
Token0AmountUint64: inputAmount,
|
||||||
|
Token1AmountUint64: 0,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,13 +45,22 @@ 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"`
|
||||||
|
|
||||||
|
|
||||||
|
//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
|
// 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,15 @@ 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")
|
||||||
|
|
||||||
|
bloomRouterProgramID = solana.MustPublicKeyFromBase58("b1oomGGqPKGD6errbyfbVMBuzSC8WtAAYo8MwNafWW1")
|
||||||
|
|
||||||
|
// For Metaora dlmm
|
||||||
|
dlmmProgramID = solana.MustPublicKeyFromBase58("LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo")
|
||||||
)
|
)
|
||||||
|
|
||||||
type AccountNotFoundError struct {
|
type AccountNotFoundError struct {
|
||||||
@@ -94,6 +103,17 @@ 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}
|
||||||
|
|
||||||
|
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 compiledInstruction struct {
|
type compiledInstruction struct {
|
||||||
@@ -118,6 +138,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 {
|
||||||
@@ -166,6 +187,12 @@ type photonSwapPumpAmmArgs struct {
|
|||||||
ToAmount uint64
|
ToAmount uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type bloomRouterArgs struct {
|
||||||
|
Side uint16
|
||||||
|
SolAmount uint64
|
||||||
|
TokenAmount uint64
|
||||||
|
}
|
||||||
|
|
||||||
type pumpAmmBuyArgs struct {
|
type pumpAmmBuyArgs struct {
|
||||||
Amount uint64
|
Amount uint64
|
||||||
MaxSolCost uint64
|
MaxSolCost uint64
|
||||||
@@ -192,15 +219,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,79 +293,93 @@ 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:
|
||||||
|
txRes, err := parseOkxDexRouteV2Instruction(versioned, i)
|
||||||
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "okxdexroutev2")
|
||||||
|
case dflowProgramID:
|
||||||
|
txRes, err := parseDFlowInstruction(versioned, i)
|
||||||
|
parsed = appendParsedBatch(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")
|
||||||
|
case bloomRouterProgramID:
|
||||||
|
txRes, err := parseBloomRouterInstruction(versioned, i)
|
||||||
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "bloomrouter")
|
||||||
|
case dlmmProgramID:
|
||||||
|
txRes, err := parseDlmmInstruction(versioned, i)
|
||||||
|
parsed = appendParsed(now, parsed, txRes, err, txHash, "dlmm")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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[:]))
|
||||||
@@ -289,12 +387,44 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func appendParsedBatch(start time.Time, list []*TxSignal, parsed []*TxSignal, err error, txHash [64]byte, label string) []*TxSignal {
|
||||||
|
if err != nil {
|
||||||
|
if !strings.HasPrefix(err.Error(), "account index") {
|
||||||
|
logger.Debug("txparser: failed to parse", "label", label, "instruction", err, "tx_hash", base58.Encode(txHash[:]))
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
if len(parsed) == 0 {
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
var end time.Time
|
||||||
|
if !start.IsZero() {
|
||||||
|
end = time.Now()
|
||||||
|
}
|
||||||
|
for _, sig := range parsed {
|
||||||
|
if sig == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sig.Label = label
|
||||||
|
if !start.IsZero() {
|
||||||
|
sig.ParseEnd = end
|
||||||
|
sig.ParseStart = start
|
||||||
|
}
|
||||||
|
list = append(list, sig)
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
func toVersionedTransaction(update *SubscribeUpdateTransaction) (*versionedTransaction, error) {
|
func toVersionedTransaction(update *SubscribeUpdateTransaction) (*versionedTransaction, error) {
|
||||||
if update == nil || update.Transaction == nil || update.Transaction.Message == nil {
|
if update == nil || update.Transaction == nil || update.Transaction.Message == nil {
|
||||||
return nil, fmt.Errorf("transaction is nil")
|
return nil, fmt.Errorf("transaction is nil")
|
||||||
@@ -302,47 +432,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 {
|
||||||
@@ -799,7 +924,7 @@ func parseFlasAmmSell(tx *versionedTransaction, instructionIndex int) (*TxSignal
|
|||||||
Maker: user.String(),
|
Maker: user.String(),
|
||||||
Token0Address: mint.String(),
|
Token0Address: mint.String(),
|
||||||
Token1Address: wsolMint,
|
Token1Address: wsolMint,
|
||||||
Token0Amount: formatSolAmount(args.Amount1),
|
Token0Amount: formatTokenAmount(args.Amount1),
|
||||||
Token1Amount: formatSolAmount(args.Amount2),
|
Token1Amount: formatSolAmount(args.Amount2),
|
||||||
Program: "PumpAMM",
|
Program: "PumpAMM",
|
||||||
Event: "sell",
|
Event: "sell",
|
||||||
@@ -933,6 +1058,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) {
|
||||||
@@ -993,6 +1178,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,
|
||||||
@@ -1167,6 +1353,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,
|
||||||
@@ -1202,12 +1389,229 @@ 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,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 findAssociatedTokenAddressWithTokenProgram(wallet, mint, tokenProgram solana.PublicKey) (solana.PublicKey, uint8, error) {
|
||||||
|
return solana.FindProgramAddress([][]byte{
|
||||||
|
wallet[:],
|
||||||
|
tokenProgram[:],
|
||||||
|
mint[:],
|
||||||
|
}, solana.SPLAssociatedTokenAccountProgramID)
|
||||||
|
}
|
||||||
|
|
||||||
|
type dlmmParsedArgs struct {
|
||||||
|
AmountIn uint64
|
||||||
|
AmountOut uint64
|
||||||
|
ExactIn bool
|
||||||
|
ExactOut bool
|
||||||
|
ActiveBin int32
|
||||||
|
MaxPriceImpactBps uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
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) (*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) < 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
|
||||||
|
}
|
||||||
|
|
||||||
|
staticKeys := tx.Message.StaticAccountKeys
|
||||||
|
userTokenIn, err := getStaticKey(staticKeys, int(instruction.Accounts[4]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
userTokenOut, err := getStaticKey(staticKeys, int(instruction.Accounts[5]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
tokenX, err := getStaticKey(staticKeys, int(instruction.Accounts[6]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
tokenY, err := getStaticKey(staticKeys, int(instruction.Accounts[7]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
user, err := getStaticKey(staticKeys, int(instruction.Accounts[10]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
tokenXProgram, err := getStaticKey(staticKeys, int(instruction.Accounts[11]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
tokenYProgram, err := getStaticKey(staticKeys, 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 &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
|
||||||
|
}
|
||||||
|
|
||||||
func decodePumpAmmBuyArgs(data []byte) (uint64, uint64, error) {
|
func decodePumpAmmBuyArgs(data []byte) (uint64, uint64, error) {
|
||||||
if len(data) < 9 {
|
if len(data) < 9 {
|
||||||
return 0, 0, fmt.Errorf("data too short for pump amm buy args, len=%d", len(data))
|
return 0, 0, fmt.Errorf("data too short for pump amm buy args, len=%d", len(data))
|
||||||
@@ -1574,7 +1978,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")
|
||||||
@@ -1584,24 +1988,182 @@ 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 parseBloomRouterInstruction(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) < 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 := getStaticKey(msg.StaticAccountKeys, int(instruction.Accounts[0]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
mint solana.PublicKey
|
||||||
|
ok bool
|
||||||
|
)
|
||||||
|
for _, acctIdx := range instruction.Accounts {
|
||||||
|
key, err := getStaticKey(msg.StaticAccountKeys, 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 &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
|
||||||
}
|
}
|
||||||
|
|
||||||
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,314 @@ 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
205
pkg/swqos/clients/soyas_client.go
Normal file
205
pkg/swqos/clients/soyas_client.go
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
package clients
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/ed25519"
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/tls"
|
||||||
|
"crypto/x509"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"math/big"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gagliardetto/solana-go"
|
||||||
|
|
||||||
|
"github.com/mr-tron/base58"
|
||||||
|
"github.com/quic-go/quic-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
alpnTPUProtocolID = "solana-tpu"
|
||||||
|
defaultServerName = "soyas-landing"
|
||||||
|
defaultKeepAlive = 25 * time.Second
|
||||||
|
defaultIdleTimeout = 5 * time.Minute
|
||||||
|
)
|
||||||
|
|
||||||
|
type SoyasClient struct {
|
||||||
|
endpointAddr string
|
||||||
|
tlsConfig *tls.Config
|
||||||
|
quicConfig *quic.Config
|
||||||
|
|
||||||
|
connMu sync.RWMutex
|
||||||
|
conn *quic.Conn
|
||||||
|
reconnectMu sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect creates a client using the whitelisted Solana keypair (base58-encoded secret key) as the mutual-TLS client identity.
|
||||||
|
func NewSoyasClient(ctx context.Context, url string) *SoyasClient {
|
||||||
|
cert, err := x509CertificateFromSolanaBase58Key("2ketcrBU1kBvr68sPVYdBdn5ztgg3VBKZP1xa1o5B8w47wemBXH73ZALdmj3ukcGzkxh6DhzLq3myu45XUwW1eNC")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tlsConfig := &tls.Config{
|
||||||
|
Certificates: []tls.Certificate{cert},
|
||||||
|
ServerName: defaultServerName,
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
NextProtos: []string{alpnTPUProtocolID},
|
||||||
|
MinVersion: tls.VersionTLS13,
|
||||||
|
}
|
||||||
|
|
||||||
|
quicConfig := &quic.Config{
|
||||||
|
KeepAlivePeriod: defaultKeepAlive,
|
||||||
|
MaxIdleTimeout: defaultIdleTimeout,
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &SoyasClient{
|
||||||
|
endpointAddr: url,
|
||||||
|
tlsConfig: tlsConfig,
|
||||||
|
quicConfig: quicConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = client.reconnect(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close closes the underlying QUIC connection (if any). Safe to call multiple times.
|
||||||
|
func (c *SoyasClient) Close() error {
|
||||||
|
c.reconnectMu.Lock()
|
||||||
|
defer c.reconnectMu.Unlock()
|
||||||
|
|
||||||
|
c.connMu.Lock()
|
||||||
|
conn := c.conn
|
||||||
|
c.conn = nil
|
||||||
|
c.connMu.Unlock()
|
||||||
|
|
||||||
|
if conn == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return conn.CloseWithError(0, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendTransaction sends a signed Solana transaction payload to Soyas.
|
||||||
|
// The payload should be the raw wire bytes (for example, from solana-go's tx.MarshalBinary()).
|
||||||
|
// If sending fails, it reconnects once and retries.
|
||||||
|
func (c *SoyasClient) SendTransaction(ctx context.Context, tx *solana.Transaction) error {
|
||||||
|
if c.endpointAddr == "" {
|
||||||
|
return fmt.Errorf("send tx url is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
raw, err := tx.MarshalBinary()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
conn := c.getConn()
|
||||||
|
if conn != nil {
|
||||||
|
if err := trySendBytes(ctx, conn, raw); err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.reconnect(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
conn = c.getConn()
|
||||||
|
if conn == nil {
|
||||||
|
return errors.New("missing QUIC connection")
|
||||||
|
}
|
||||||
|
return trySendBytes(ctx, conn, raw)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SoyasClient) SendBundle(ctx context.Context, txs []*solana.Transaction) error {
|
||||||
|
return fmt.Errorf("soyas client not support send bundle")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SoyasClient) getConn() *quic.Conn {
|
||||||
|
c.connMu.RLock()
|
||||||
|
defer c.connMu.RUnlock()
|
||||||
|
return c.conn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SoyasClient) reconnect(ctx context.Context) error {
|
||||||
|
c.reconnectMu.Lock()
|
||||||
|
defer c.reconnectMu.Unlock()
|
||||||
|
|
||||||
|
if existing := c.getConn(); existing != nil && existing.Context().Err() == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := quic.DialAddr(ctx, c.endpointAddr, c.tlsConfig, c.quicConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.connMu.Lock()
|
||||||
|
old := c.conn
|
||||||
|
c.conn = conn
|
||||||
|
c.connMu.Unlock()
|
||||||
|
|
||||||
|
if old != nil {
|
||||||
|
_ = old.CloseWithError(0, "")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func trySendBytes(ctx context.Context, conn *quic.Conn, payload []byte) error {
|
||||||
|
stream, err := conn.OpenUniStreamSync(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := stream.Write(payload); err != nil {
|
||||||
|
_ = stream.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return stream.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// x509CertificateFromSolanaBase58Key creates a short-lived self-signed X.509
|
||||||
|
// certificate whose public key is derived from the provided Solana Ed25519 key.
|
||||||
|
// The Soyas ingress extracts this public key to identify/allowlist the client.
|
||||||
|
func x509CertificateFromSolanaBase58Key(apiKeyBase58 string) (tls.Certificate, error) {
|
||||||
|
raw, err := base58.Decode(apiKeyBase58)
|
||||||
|
if err != nil {
|
||||||
|
return tls.Certificate{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var seed []byte
|
||||||
|
switch len(raw) {
|
||||||
|
case ed25519.SeedSize:
|
||||||
|
seed = raw
|
||||||
|
case ed25519.PrivateKeySize:
|
||||||
|
seed = raw[:ed25519.SeedSize]
|
||||||
|
default:
|
||||||
|
return tls.Certificate{}, errors.New("api key must decode to 32 (seed) or 64 (secret) bytes")
|
||||||
|
}
|
||||||
|
|
||||||
|
priv := ed25519.NewKeyFromSeed(seed)
|
||||||
|
pub := priv.Public().(ed25519.PublicKey)
|
||||||
|
|
||||||
|
serial, err := rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128))
|
||||||
|
if err != nil {
|
||||||
|
return tls.Certificate{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
template := &x509.Certificate{
|
||||||
|
SerialNumber: serial,
|
||||||
|
NotBefore: time.Now().Add(-5 * time.Minute),
|
||||||
|
NotAfter: time.Now().Add(365 * 24 * time.Hour),
|
||||||
|
KeyUsage: x509.KeyUsageDigitalSignature,
|
||||||
|
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth},
|
||||||
|
}
|
||||||
|
|
||||||
|
der, err := x509.CreateCertificate(rand.Reader, template, template, pub, priv)
|
||||||
|
if err != nil {
|
||||||
|
return tls.Certificate{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return tls.Certificate{
|
||||||
|
Certificate: [][]byte{der},
|
||||||
|
PrivateKey: priv,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -24,6 +24,8 @@ func NewSWQoSClient(ctx context.Context, config *SWQoSClientConfig) (SWQoSClient
|
|||||||
client = clients.NewAstralaneClient(config.SendTxUrl)
|
client = clients.NewAstralaneClient(config.SendTxUrl)
|
||||||
case enum.SWQoSAgentBlocxRoute:
|
case enum.SWQoSAgentBlocxRoute:
|
||||||
client = clients.NewBloxrouteClient(config.SendTxUrl)
|
client = clients.NewBloxrouteClient(config.SendTxUrl)
|
||||||
|
case enum.SWQoSAgentSoyas:
|
||||||
|
client = clients.NewSoyasClient(ctx, config.SendTxUrl)
|
||||||
case enum.SWQoSAgent0slot, enum.SWQoSAgentJito, enum.SWQoSAgentHelius, enum.SWQoSAgentNozomi, enum.SWQoSAgentStellium:
|
case enum.SWQoSAgent0slot, enum.SWQoSAgentJito, enum.SWQoSAgentHelius, enum.SWQoSAgentNozomi, enum.SWQoSAgentStellium:
|
||||||
client = clients.NewHttpClient(config.SendTxUrl, config.SendBundleUrl)
|
client = clients.NewHttpClient(config.SendTxUrl, config.SendBundleUrl)
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user