2025-11-24 17:47:56 +08:00
|
|
|
package pump_parser
|
|
|
|
|
|
|
|
|
|
import (
|
2026-02-09 14:46:19 +08:00
|
|
|
"encoding/binary"
|
2025-11-24 17:47:56 +08:00
|
|
|
"encoding/hex"
|
2025-11-27 16:39:01 +08:00
|
|
|
"fmt"
|
2025-11-24 17:47:56 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
agbinary "github.com/gagliardetto/binary"
|
2026-02-09 14:46:19 +08:00
|
|
|
"github.com/gagliardetto/solana-go"
|
2025-11-27 16:39:01 +08:00
|
|
|
"github.com/mr-tron/base58"
|
2025-11-24 17:47:56 +08:00
|
|
|
)
|
|
|
|
|
|
2026-04-16 14:24:14 +08:00
|
|
|
type legacyPumpTradeEvent struct {
|
|
|
|
|
Mint solana.PublicKey
|
|
|
|
|
SolAmount uint64
|
|
|
|
|
TokenAmount uint64
|
|
|
|
|
IsBuy bool
|
|
|
|
|
User solana.PublicKey
|
|
|
|
|
Timestamp int64
|
|
|
|
|
VirtualSolReserves uint64
|
|
|
|
|
VirtualTokenReserves uint64
|
|
|
|
|
RealSolReserves uint64
|
|
|
|
|
RealTokenReserves uint64
|
|
|
|
|
FeeRecipient solana.PublicKey
|
|
|
|
|
FeeBasisPoints uint64
|
|
|
|
|
Fee uint64
|
|
|
|
|
Creator solana.PublicKey
|
|
|
|
|
CreatorFeeBasisPoints uint64
|
|
|
|
|
CreatorFee uint64
|
|
|
|
|
TrackVolume bool
|
|
|
|
|
TotalUnclaimedTokens uint64
|
|
|
|
|
TotalClaimedTokens uint64
|
|
|
|
|
CurrentSolVolume uint64
|
|
|
|
|
LastUpdateTimestamp int64
|
|
|
|
|
IxName string
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-24 17:47:56 +08:00
|
|
|
func TestTradeEvent(t *testing.T) {
|
|
|
|
|
hexData := "e445a52e51cb9a1dbddb7fd34ee661ee051d1834b36cc6f04cc5bd998d53ab2a566a0ca2415bcfad5f9ed6941a851d3f84ecb200000000006c267d17170000000190d2c525ef0ea205f4b4abfdb6eaaf37fcb5a1b1dec2e2689448eecab6ba93b6c922246900000000c314f11a0d000000be71bf9e22080200c368cd1e06000000bed9ac52910901004ac2f8d0dd5cbc97e3289c197cb5062a54f3d956b9ce6e5115f96567aa5cb3e65f000000000000002c6a010000000000c9e17c171227a50a5b62e3a4a3f8ff4fafe0bca9c332bdf7f32eedbc4229604d1e000000000000005f72000000000000010000000000000000000000000000000000000000000000000000000000000000100000006275795f65786163745f736f6c5f696e"
|
|
|
|
|
d, err := hex.DecodeString(hexData)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("Failed to decode base64 data: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-16 14:24:14 +08:00
|
|
|
var tradeEvent legacyPumpTradeEvent
|
2025-11-24 17:47:56 +08:00
|
|
|
|
|
|
|
|
err = agbinary.NewBorshDecoder(d[16:]).Decode(&tradeEvent)
|
|
|
|
|
if err != nil {
|
2026-04-16 14:24:14 +08:00
|
|
|
t.Fatalf("Failed to deserialize trade event: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if tradeEvent.IxName != "buy_exact_sol_in" {
|
|
|
|
|
t.Fatalf("IxName = %q, want buy_exact_sol_in", tradeEvent.IxName)
|
|
|
|
|
}
|
|
|
|
|
if tradeEvent.SolAmount != 11725956 {
|
|
|
|
|
t.Fatalf("SolAmount = %d, want 11725956", tradeEvent.SolAmount)
|
|
|
|
|
}
|
|
|
|
|
if !tradeEvent.IsBuy {
|
|
|
|
|
t.Fatalf("IsBuy = false, want true")
|
2025-11-24 17:47:56 +08:00
|
|
|
}
|
|
|
|
|
t.Logf("Trade Event: %+v", tradeEvent)
|
|
|
|
|
|
2025-11-27 16:39:01 +08:00
|
|
|
xx, err := base58.Decode("3Bxs48EzTZB4tzRd")
|
|
|
|
|
fmt.Println(len(xx), err)
|
|
|
|
|
|
2025-11-24 17:47:56 +08:00
|
|
|
}
|
2026-02-02 17:59:47 +08:00
|
|
|
func TestCal(t *testing.T) {
|
|
|
|
|
//e445a52e51cb9a1db94afc7d1bd7bc6f5e99e54b
|
|
|
|
|
// . b94afc7d1bd7bc6f
|
2026-02-09 14:46:19 +08:00
|
|
|
s := calculateDiscriminator("global:initialize_with_permission")
|
2026-02-02 17:59:47 +08:00
|
|
|
fmt.Println(hex.EncodeToString(s[:]))
|
2026-02-09 14:46:19 +08:00
|
|
|
|
|
|
|
|
s2, _ := base58.Decode("6ApXSNCamGdm")
|
|
|
|
|
s3 := binary.LittleEndian.Uint64(s2[1:])
|
|
|
|
|
fmt.Println(s2, s3)
|
|
|
|
|
|
|
|
|
|
fmt.Println(solana.MustPublicKeyFromBase58("BM9CcyErJcu2mjrFvUsRRrD3snGeHDDVirJLvL6EjvMN").IsOnCurve())
|
2026-02-02 17:59:47 +08:00
|
|
|
}
|