51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package shreder
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
|
|
"github.com/gagliardetto/solana-go"
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
var tradewizProgramID = solana.MustPublicKeyFromBase58("B3jytJa6Tzpn4Ly7GNnDm3dMGqUin5aMRm5aPsJGU5G7")
|
|
|
|
func parseTradewizInstruction(tx VersionedTransaction, instructionIndex int) (TxSignalBatch, error) {
|
|
if instructionIndex >= len(tx.Instructions) {
|
|
return nil, fmt.Errorf("instruction index out of bounds")
|
|
}
|
|
ix := tx.Instructions[instructionIndex]
|
|
if len(ix.Data) < 9 {
|
|
return nil, fmt.Errorf("data too short for tradewiz buy args, len=%d", len(ix.Data))
|
|
}
|
|
if len(ix.Accounts) < 3 {
|
|
return nil, fmt.Errorf("accounts too short")
|
|
}
|
|
|
|
// data format: 0x00 + u64(wsol amount) + u64(...)
|
|
wsolAmount := binary.LittleEndian.Uint64(ix.Data[1:9])
|
|
|
|
mint, err := tx.GetAccount(int(ix.Accounts[2]))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return TxSignalBatch{&TxSignal{
|
|
TxHash: tx.Signatures[0].String(),
|
|
Label: "tradewiz",
|
|
Maker: tx.StaticAccountKeys[0].String(),
|
|
Token0Address: mint.String(),
|
|
Token1Address: wsolMint,
|
|
Token0Amount: decimal.Zero,
|
|
Token1Amount: formatSolAmount(wsolAmount),
|
|
Program: "Pump",
|
|
Event: "buy",
|
|
IsToken2022: false,
|
|
IsMayhemMode: false,
|
|
ExactSOL: true,
|
|
Block: tx.Block,
|
|
Token0AmountUint64: 0,
|
|
Token1AmountUint64: wsolAmount,
|
|
}}, nil
|
|
}
|