134 lines
4.6 KiB
Go
134 lines
4.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/gagliardetto/solana-go"
|
|
"github.com/gagliardetto/solana-go/rpc"
|
|
pump_parser "github.com/thloyi/pump-parser"
|
|
)
|
|
|
|
func main() {
|
|
const rpcURL = "https://staked.helius-rpc.com?api-key=5adcf1f9-5719-43d1-bf3f-c2d4e1e5f94d"
|
|
txHash := os.Getenv("TX_HASH")
|
|
if txHash == "" {
|
|
txHash = "29v7u2ewLr3Se6cWYC2xwN8jszqMWwvVgPz7MqkctTveMo1csWWYDBcUsjuJwb5ciugc5so1jc9QcmR7syJTjEns"
|
|
}
|
|
|
|
if txHash == "" {
|
|
fmt.Fprintln(os.Stderr, "txHash is empty; set it in cmd/rpc_parse/main.go")
|
|
os.Exit(1)
|
|
}
|
|
|
|
sig, err := solana.SignatureFromBase58(txHash)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "invalid txHash: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
client := rpc.New(rpcURL)
|
|
maxSupportedVersion := uint64(0)
|
|
out, err := client.GetTransaction(context.Background(), sig, &rpc.GetTransactionOpts{
|
|
Encoding: solana.EncodingBase64,
|
|
Commitment: rpc.CommitmentConfirmed,
|
|
MaxSupportedTransactionVersion: &maxSupportedVersion,
|
|
})
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "rpc getTransaction error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
if out == nil || out.Transaction == nil || out.Meta == nil {
|
|
fmt.Fprintln(os.Stderr, "rpc getTransaction returned empty response")
|
|
os.Exit(1)
|
|
}
|
|
|
|
rawBinary := out.Transaction.GetBinary()
|
|
if len(rawBinary) == 0 {
|
|
fmt.Fprintln(os.Stderr, "rpc getTransaction returned empty transaction data")
|
|
os.Exit(1)
|
|
}
|
|
|
|
txWithMeta := rpc.TransactionWithMeta{
|
|
Slot: out.Slot,
|
|
BlockTime: out.BlockTime,
|
|
Transaction: rpc.DataBytesOrJSONFromBytes(rawBinary),
|
|
Meta: out.Meta,
|
|
Version: out.Version,
|
|
}
|
|
|
|
var blockTime *uint64
|
|
if out.BlockTime != nil {
|
|
bt := uint64(*out.BlockTime)
|
|
blockTime = &bt
|
|
}
|
|
|
|
rawTx, err := pump_parser.FromRpcTransactionWithMeta(txWithMeta, blockTime, out.Slot, 0)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "convert rpc transaction error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
pump_parser.EnableAllParsers()
|
|
|
|
parsed, err := pump_parser.ParseRawTx(rawTx)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "parse raw tx error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
if len(parsed.Swaps) == 0 {
|
|
fmt.Println("no swaps parsed from tx")
|
|
return
|
|
}
|
|
|
|
for i, swap := range parsed.Swaps {
|
|
fmt.Printf("swap[%d]\n", i)
|
|
fmt.Printf(" program: %s\n", swap.Program)
|
|
fmt.Printf(" event: %s\n", swap.Event)
|
|
fmt.Printf(" pool: %s\n", swap.Pool)
|
|
fmt.Printf(" user: %s\n", swap.User)
|
|
fmt.Printf(" base_mint: %s (decimals=%d)\n", swap.BaseMint, swap.BaseMintDecimals)
|
|
fmt.Printf(" quote_mint: %s (decimals=%d)\n", swap.QuoteMint, swap.QuoteMintDecimals)
|
|
fmt.Printf(" base_amount: %s\n", swap.BaseAmount.String())
|
|
fmt.Printf(" quote_amount: %s\n", swap.QuoteAmount.String())
|
|
if swap.SwapMode != pump_parser.SwapModeUnknown {
|
|
fmt.Printf(" swap_mode: %s\n", swap.SwapMode.String())
|
|
fmt.Printf(" fixed_amount: %s\n", swap.FixedAmount.String())
|
|
fmt.Printf(" fixed_amount_side: %s\n", swap.FixedAmountSide.String())
|
|
fmt.Printf(" fixed_mint: %s\n", swap.FixedMint)
|
|
fmt.Printf(" limit_amount_type: %s\n", swap.LimitAmountType.String())
|
|
fmt.Printf(" limit_amount: %s\n", swap.LimitAmount.String())
|
|
fmt.Printf(" limit_amount_side: %s\n", swap.LimitAmountSide.String())
|
|
fmt.Printf(" limit_mint: %s\n", swap.LimitMint)
|
|
fmt.Printf(" actual_limit_amount: %s\n", swap.ActualLimitAmount.String())
|
|
fmt.Printf(" slippage_bps: %s\n", swap.SlippageBps.String())
|
|
}
|
|
if !swap.FeeAmount.IsZero() || swap.FeeSide != "" {
|
|
fmt.Printf(" fee_amount: %s\n", swap.FeeAmount.String())
|
|
fmt.Printf(" lp_fee_amount: %s\n", swap.LpFeeAmount.String())
|
|
fmt.Printf(" fee_side: %s\n", swap.FeeSide)
|
|
fmt.Printf(" fee_mint: %s (decimals=%d)\n", swap.FeeMint, swap.FeeMintDecimals)
|
|
fmt.Printf(" fee_token_program: %s\n", swap.FeeTokenProgram)
|
|
}
|
|
fmt.Printf(" base_reserve: %s\n", swap.BaseReserve.String())
|
|
fmt.Printf(" quote_reserve: %s\n", swap.QuoteReserve.String())
|
|
fmt.Printf(" base_token_program: %s\n", swap.BaseTokenProgram)
|
|
fmt.Printf(" quote_token_program: %s\n", swap.QuoteTokenProgram)
|
|
fmt.Printf(" entry_contract: %s\n", swap.EntryContract)
|
|
fmt.Printf(" user_base_balance: %s\n", swap.UserBaseBalance.String())
|
|
fmt.Printf(" user_quote_balance: %s\n", swap.UserQuoteBalance.String())
|
|
fmt.Printf(" active_bin_id: %d\n", swap.ActiveBinId)
|
|
fmt.Printf(" start_bin_id: %d\n", swap.StartBinId)
|
|
fmt.Printf(" end_bin_id: %d\n", swap.EndBinId)
|
|
fmt.Printf(" remove_bp: %d\n", swap.RemoveBp)
|
|
fmt.Printf(" position_account: %s\n", swap.PositionAccount)
|
|
if swap.Mayhem {
|
|
fmt.Printf(" mayhem: true\n")
|
|
} else {
|
|
fmt.Printf(" mayhem: false\n")
|
|
}
|
|
fmt.Println()
|
|
}
|
|
}
|