73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
|
|
package shreder
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"github.com/gagliardetto/solana-go"
|
||
|
|
"github.com/near/borsh-go"
|
||
|
|
)
|
||
|
|
|
||
|
|
// only buy function with pump program
|
||
|
|
var f5tfProgramID = solana.MustPublicKeyFromBase58("F5tfvbLog9VdGUPqBDTT8rgXvTTcq7e5UiGnupL1zvBq")
|
||
|
|
var (
|
||
|
|
f5tfBuyTokensIX = []byte{0}
|
||
|
|
)
|
||
|
|
|
||
|
|
type f5tfBuyArgs struct {
|
||
|
|
SolAmount uint64
|
||
|
|
TokenAmount uint64
|
||
|
|
}
|
||
|
|
|
||
|
|
func parseF5tfInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
||
|
|
if instructionIndex >= len(tx.Instructions) {
|
||
|
|
return nil, fmt.Errorf("instruction index out of bounds")
|
||
|
|
}
|
||
|
|
|
||
|
|
instruction := tx.Instructions[instructionIndex]
|
||
|
|
if len(instruction.Data) == 0 {
|
||
|
|
return nil, fmt.Errorf("data is empty")
|
||
|
|
}
|
||
|
|
if !matchMethod(instruction.Data, f5tfBuyTokensIX) {
|
||
|
|
return nil, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
if len(instruction.Accounts) < 7 {
|
||
|
|
return nil, fmt.Errorf("accounts too short")
|
||
|
|
}
|
||
|
|
|
||
|
|
mint, err := tx.GetAccount(int(instruction.Accounts[2]))
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
user, err := tx.GetAccount(int(instruction.Accounts[6]))
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
if len(instruction.Data) < 2 {
|
||
|
|
return nil, fmt.Errorf("data too short for f5tf buy args len=%d", len(instruction.Data))
|
||
|
|
}
|
||
|
|
|
||
|
|
var args f5tfBuyArgs
|
||
|
|
if err := borsh.Deserialize(&args, instruction.Data[1:]); err != nil {
|
||
|
|
return nil, fmt.Errorf("failed to parse buy tokens args: %w", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
return TxSignalBatch{&TxSignal{
|
||
|
|
TxHash: tx.Signatures[0].String(),
|
||
|
|
Label: "f5tf",
|
||
|
|
Maker: user.String(),
|
||
|
|
Token0Address: mint.String(),
|
||
|
|
Token1Address: wsolMint,
|
||
|
|
Token0Amount: formatTokenAmount(args.TokenAmount),
|
||
|
|
Token1Amount: formatSolAmount(args.SolAmount),
|
||
|
|
Program: "Pump",
|
||
|
|
Event: "buy",
|
||
|
|
IsToken2022: false,
|
||
|
|
IsMayhemMode: false,
|
||
|
|
Block: tx.Block,
|
||
|
|
Token0AmountUint64: args.TokenAmount,
|
||
|
|
Token1AmountUint64: args.SolAmount,
|
||
|
|
}}, nil
|
||
|
|
}
|