chore: support raydium launch lab and add test
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/gagliardetto/solana-go/programs/address-lookup-table"
|
||||
addresslookuptable "github.com/gagliardetto/solana-go/programs/address-lookup-table"
|
||||
"github.com/gagliardetto/solana-go/rpc"
|
||||
|
||||
"github.com/samlior/libsam/v2/pkg/shreder"
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
const (
|
||||
rpcURL = "https://staked.helius-rpc.com?api-key=5adcf1f9-5719-43d1-bf3f-c2d4e1e5f94d"
|
||||
txSignature = "4gzWkLRWNLbkBdvyCqg2M4unWA7yg4DdMg8dGTnapw2USsefd9TjXVArhv22qJE9gtex46NwXC4xp1FtNZ1TmjAM"
|
||||
txSignature = "2erxUsE92LdrxhWy6HryUJpvBpVUociu2UY6AGoX7E6orrqm6AYxDzhmub3J9PDPa5CPNwWZBG8rCxKCdquVo2Lc"
|
||||
labelFilter = ""
|
||||
)
|
||||
|
||||
|
||||
147
pkg/shreder/program_raydiumlaunchlab.go
Normal file
147
pkg/shreder/program_raydiumlaunchlab.go
Normal file
@@ -0,0 +1,147 @@
|
||||
package shreder
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
)
|
||||
|
||||
var raydiumLaunchLabProgramID = solana.MustPublicKeyFromBase58("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj")
|
||||
var (
|
||||
raydiumLaunchLabSellExactInDiscriminator = []byte{0x95, 0x27, 0xde, 0x9b, 0xd3, 0x7c, 0x98, 0x1a}
|
||||
raydiumLaunchLabSellExactOutDiscriminator = []byte{0x5f, 0xc8, 0x47, 0x22, 0x08, 0x09, 0x0b, 0xa6}
|
||||
raydiumLaunchLabBuyExactInDiscriminator = []byte{0xfa, 0xea, 0x0d, 0x7b, 0xd5, 0x9c, 0x13, 0xec}
|
||||
raydiumLaunchLabBuyExactOutDiscriminator = []byte{0x18, 0xd3, 0x74, 0x28, 0x69, 0x03, 0x99, 0x38}
|
||||
)
|
||||
|
||||
func parseRaydiumLaunchLabInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||||
if instructionIndex >= len(tx.Instructions) {
|
||||
return nil, fmt.Errorf("instruction index out of bounds")
|
||||
}
|
||||
|
||||
instruction := tx.Instructions[instructionIndex]
|
||||
if len(instruction.Data) == 0 {
|
||||
return nil, fmt.Errorf("data is empty")
|
||||
}
|
||||
if len(instruction.Data) < 8 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
txSignal *TxSignal
|
||||
)
|
||||
if matchMethod(instruction.Data, raydiumLaunchLabBuyExactInDiscriminator) {
|
||||
txSignal, err = parseRaydiumLaunchLabSwap(tx, instruction, true, true)
|
||||
} else if matchMethod(instruction.Data, raydiumLaunchLabBuyExactOutDiscriminator) {
|
||||
txSignal, err = parseRaydiumLaunchLabSwap(tx, instruction, true, false)
|
||||
} else if matchMethod(instruction.Data, raydiumLaunchLabSellExactInDiscriminator) {
|
||||
txSignal, err = parseRaydiumLaunchLabSwap(tx, instruction, false, true)
|
||||
} else if matchMethod(instruction.Data, raydiumLaunchLabSellExactOutDiscriminator) {
|
||||
txSignal, err = parseRaydiumLaunchLabSwap(tx, instruction, false, false)
|
||||
}
|
||||
if txSignal != nil {
|
||||
return TxSignalBatch{txSignal}, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func parseRaydiumLaunchLabSwap(tx VersionedTransaction, instruction Instructions, isBuy bool, exactIn bool) (*TxSignal, error) {
|
||||
if len(instruction.Accounts) < 10 {
|
||||
return nil, fmt.Errorf("accounts too short")
|
||||
}
|
||||
if len(instruction.Data) < 24 {
|
||||
return nil, fmt.Errorf("data too short for raydium launch lab swap args, len=%d", len(instruction.Data))
|
||||
}
|
||||
|
||||
mint, err := tx.GetAccount(int(instruction.Accounts[9]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := tx.GetAccount(int(instruction.Accounts[0]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
amountA := binary.LittleEndian.Uint64(instruction.Data[8:16])
|
||||
amountB := binary.LittleEndian.Uint64(instruction.Data[16:24])
|
||||
|
||||
if isBuy {
|
||||
if exactIn {
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "raydiumlaunchlab",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(amountB),
|
||||
Token1Amount: formatSolAmount(amountA),
|
||||
Program: "RaydiumLaunchLab",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: true,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: amountB,
|
||||
Token1AmountUint64: amountA,
|
||||
}, nil
|
||||
} else {
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "raydiumlaunchlab",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(amountA),
|
||||
Token1Amount: formatSolAmount(amountB),
|
||||
Program: "RaydiumLaunchLab",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: amountA,
|
||||
Token1AmountUint64: amountB,
|
||||
}, nil
|
||||
}
|
||||
} else {
|
||||
if exactIn {
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "raydiumlaunchlab",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(amountA),
|
||||
Token1Amount: formatSolAmount(amountB),
|
||||
Program: "RaydiumLaunchLab",
|
||||
Event: "sell",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: amountA,
|
||||
Token1AmountUint64: amountB,
|
||||
}, nil
|
||||
} else {
|
||||
return &TxSignal{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Label: "raydiumlaunchlab",
|
||||
Maker: user.String(),
|
||||
Token0Address: mint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token0Amount: formatTokenAmount(amountB),
|
||||
Token1Amount: formatSolAmount(amountA),
|
||||
Program: "RaydiumLaunchLab",
|
||||
Event: "sell",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: true,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: amountB,
|
||||
Token1AmountUint64: amountA,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,27 +56,28 @@ var (
|
||||
defaultFilterAccount []solana.PublicKey
|
||||
|
||||
registered = map[solana.PublicKey]Handler{
|
||||
pumpProgramID: {parsePumpInstruction, "pump"},
|
||||
azczProgramID: {parseAzczInstruction, "azcz"},
|
||||
f5tfProgramID: {parseF5tfInstruction, "f5tf"},
|
||||
flasProgramID: {parseFlasInstruction, "flas"},
|
||||
photonProgramID: {parsePhotonInstruction, "photon"},
|
||||
pumpAmmProgramID: {parsePumpAmmInstruction, "pumpamm"},
|
||||
binanceWalletProgramID: {parseBinanceWalletInstruction, "binancewallet"},
|
||||
boboProgramID: {parseBoboInstruction, "bobo"},
|
||||
qtkvProgramID: {parseQtkvInstruction, "qtkv"},
|
||||
fjszProgramID: {parseFjszInstruction, "fjsz"},
|
||||
terminalProgramID: {parseTermInstruction, "terminal"},
|
||||
jupiterV6ProgramID: {parseJupiterV6Instruction, "jupiterv6"},
|
||||
okxDexRouteV2ProgramID: {parseOkxDexRouteV2Instruction, "okxdexroutev2"},
|
||||
dflowProgramID: {parseDFlowInstruction, "dflow"},
|
||||
gmgnProgramID: {parseGMGNInstruction, "gmgn"},
|
||||
bonkProgramID: {parseBonkInstruction, "bonk"},
|
||||
bloomRouterProgramID: {parseBloomRouterInstruction, "bloomrouter"},
|
||||
dlmmProgramID: {parseDlmmInstruction, "dlmm"},
|
||||
dbotProgramID: {parseDbotInstruction, "dbot"},
|
||||
tradewizProgramID: {parseTradewizInstruction, "tradewiz"},
|
||||
maestroProgramId: {parseMaestroInstruction, "maestro"},
|
||||
pumpProgramID: {parsePumpInstruction, "pump"},
|
||||
azczProgramID: {parseAzczInstruction, "azcz"},
|
||||
f5tfProgramID: {parseF5tfInstruction, "f5tf"},
|
||||
flasProgramID: {parseFlasInstruction, "flas"},
|
||||
photonProgramID: {parsePhotonInstruction, "photon"},
|
||||
pumpAmmProgramID: {parsePumpAmmInstruction, "pumpamm"},
|
||||
binanceWalletProgramID: {parseBinanceWalletInstruction, "binancewallet"},
|
||||
boboProgramID: {parseBoboInstruction, "bobo"},
|
||||
qtkvProgramID: {parseQtkvInstruction, "qtkv"},
|
||||
fjszProgramID: {parseFjszInstruction, "fjsz"},
|
||||
terminalProgramID: {parseTermInstruction, "terminal"},
|
||||
jupiterV6ProgramID: {parseJupiterV6Instruction, "jupiterv6"},
|
||||
okxDexRouteV2ProgramID: {parseOkxDexRouteV2Instruction, "okxdexroutev2"},
|
||||
dflowProgramID: {parseDFlowInstruction, "dflow"},
|
||||
gmgnProgramID: {parseGMGNInstruction, "gmgn"},
|
||||
bonkProgramID: {parseBonkInstruction, "bonk"},
|
||||
bloomRouterProgramID: {parseBloomRouterInstruction, "bloomrouter"},
|
||||
dlmmProgramID: {parseDlmmInstruction, "dlmm"},
|
||||
dbotProgramID: {parseDbotInstruction, "dbot"},
|
||||
tradewizProgramID: {parseTradewizInstruction, "tradewiz"},
|
||||
maestroProgramId: {parseMaestroInstruction, "maestro"},
|
||||
raydiumLaunchLabProgramID: {parseRaydiumLaunchLabInstruction, "raydiumlaunchlab"},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package shreder
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -160,6 +161,10 @@ func TestParseTermBuy(t *testing.T) {
|
||||
closed,
|
||||
)
|
||||
}()
|
||||
go func() {
|
||||
<-closed
|
||||
close(ch)
|
||||
}()
|
||||
signals := make([]TxSignal, 0)
|
||||
for signal := range ch {
|
||||
signals = append(signals, signal)
|
||||
@@ -208,6 +213,10 @@ func TestParseBonkBuy(t *testing.T) {
|
||||
closed,
|
||||
)
|
||||
}()
|
||||
go func() {
|
||||
<-closed
|
||||
close(ch)
|
||||
}()
|
||||
signals := make([]TxSignal, 0)
|
||||
for signal := range ch {
|
||||
signals = append(signals, signal)
|
||||
@@ -256,6 +265,10 @@ func TestParseBonkSell(t *testing.T) {
|
||||
closed,
|
||||
)
|
||||
}()
|
||||
go func() {
|
||||
<-closed
|
||||
close(ch)
|
||||
}()
|
||||
signals := make([]TxSignal, 0)
|
||||
for signal := range ch {
|
||||
signals = append(signals, signal)
|
||||
@@ -305,6 +318,10 @@ func TestParsePhotonBuy(t *testing.T) {
|
||||
closed,
|
||||
)
|
||||
}()
|
||||
go func() {
|
||||
<-closed
|
||||
close(ch)
|
||||
}()
|
||||
signals := make([]TxSignal, 0)
|
||||
for signal := range ch {
|
||||
signals = append(signals, signal)
|
||||
@@ -353,6 +370,10 @@ func TestParseJupiterV6PumpFunBuy(t *testing.T) {
|
||||
closed,
|
||||
)
|
||||
}()
|
||||
go func() {
|
||||
<-closed
|
||||
close(ch)
|
||||
}()
|
||||
signals := make([]TxSignal, 0)
|
||||
for signal := range ch {
|
||||
signals = append(signals, signal)
|
||||
@@ -404,6 +425,10 @@ func TestParseJupiterV6PumpFunSell(t *testing.T) {
|
||||
closed,
|
||||
)
|
||||
}()
|
||||
go func() {
|
||||
<-closed
|
||||
close(ch)
|
||||
}()
|
||||
signals := make([]TxSignal, 0)
|
||||
for signal := range ch {
|
||||
signals = append(signals, signal)
|
||||
@@ -435,3 +460,59 @@ func TestParseJupiterV6PumpFunSell(t *testing.T) {
|
||||
t.Fatalf("expected ExactSOL false, got true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRaydiumLaunchLabBuyExactIn(t *testing.T) {
|
||||
rpcUrl := os.Getenv("SOL_RPC_URL")
|
||||
if rpcUrl == "" {
|
||||
t.Fatalf("SOL_RPC_URL is not set")
|
||||
}
|
||||
|
||||
client := rpc.New(rpcUrl)
|
||||
ch := make(chan TxSignal)
|
||||
closed := make(chan struct{})
|
||||
go func() {
|
||||
ParseTransactionForSubscribe(
|
||||
context.Background(),
|
||||
getTransaction(t, client, "2erxUsE92LdrxhWy6HryUJpvBpVUociu2UY6AGoX7E6orrqm6AYxDzhmub3J9PDPa5CPNwWZBG8rCxKCdquVo2Lc"),
|
||||
nil,
|
||||
ch,
|
||||
closed,
|
||||
)
|
||||
}()
|
||||
go func() {
|
||||
<-closed
|
||||
close(ch)
|
||||
}()
|
||||
fmt.Println("Parsing Raydium Launch Lab Buy Exact In")
|
||||
signals := make([]TxSignal, 0)
|
||||
for signal := range ch {
|
||||
signals = append(signals, signal)
|
||||
}
|
||||
|
||||
if len(signals) != 1 {
|
||||
t.Fatalf("expected 1 signal, got %d", len(signals))
|
||||
}
|
||||
|
||||
signal := signals[0]
|
||||
if signal.Label != "raydiumlaunchlab" {
|
||||
t.Fatalf("expected raydiumlaunchlab signal, got %s", signal.Label)
|
||||
}
|
||||
if signal.Event != "buy" {
|
||||
t.Fatalf("expected buy event, got %s", signal.Event)
|
||||
}
|
||||
if signal.Maker != "56JZV81H3XJedVWcV8RTXrn5YD6WW2k2LTGVDGCUwyYb" {
|
||||
t.Fatalf("expected maker 56JZV81H3XJedVWcV8RTXrn5YD6WW2k2LTGVDGCUwyYb, got %s", signal.Maker)
|
||||
}
|
||||
if signal.Token0Address != "676zr3qFwy3XUXwVkQVdV9cidSaxcS6SrHga8cK4kKej" {
|
||||
t.Fatalf("expected token0 address 676zr3qFwy3XUXwVkQVdV9cidSaxcS6SrHga8cK4kKej, got %s", signal.Token0Address)
|
||||
}
|
||||
if signal.Token0AmountUint64 != 15336821188103 {
|
||||
t.Fatalf("expected token0 amount 15336821188103, got %d", signal.Token0AmountUint64)
|
||||
}
|
||||
if signal.Token1AmountUint64 != 1000000000 {
|
||||
t.Fatalf("expected token1 amount 1000000000, got %d", signal.Token1AmountUint64)
|
||||
}
|
||||
if !signal.ExactSOL {
|
||||
t.Fatalf("expected ExactSOL true, got false")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user