Compare commits

..

7 Commits

Author SHA1 Message Date
thloyi
3d447ef2e8 fix errTx mev and cu 2026-02-27 17:07:49 +08:00
thloyi
b0d4342fa2 pump and pump swap errTx parser 2026-02-27 16:37:15 +08:00
cachalots
972ddc7960 IsCashbackCoin 2026-02-27 02:10:12 +08:00
bcd442195c chore: support IsCashbackEnabled 2026-02-27 01:43:07 +08:00
0633707142 chore: add trojan fee addresses 2026-02-26 15:19:57 +08:00
8e49f01054 must to next inner at least 2026-02-21 09:29:28 +08:00
thloyi
62cc64a90a fix from rpc ComputeUnitsConsumed 2026-02-12 10:43:30 +08:00
14 changed files with 733 additions and 731 deletions

View File

@@ -1,576 +0,0 @@
package pump_parser
import (
"log"
"strings"
"github.com/gagliardetto/solana-go"
)
func checkBonkGmgnBuy(rawTx *RawTx) bool {
// 检查交易版本
var version, _ = rawTx.Version.(solana.MessageVersion)
if version != solana.MessageVersionLegacy {
return false
}
// 检查交易指令数量
if len(rawTx.Transaction.Message.Instructions) != 10 && len(rawTx.Transaction.Message.Instructions) != 9 {
return false
}
accountList := rawTx.getAccountList()
// 检查 cu limit
{
instruction := rawTx.Transaction.Message.Instructions[0]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.ComputeBudget {
return false
}
if len(instruction.Accounts) != 1 {
return false
}
accountId := accountList[instruction.Accounts[0]].String()
if !strings.HasPrefix(accountId, "jitodontfront1111111111151111111111111655") {
return false
}
}
// 检查 cu price
{
instruction := rawTx.Transaction.Message.Instructions[1]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.ComputeBudget {
return false
}
}
// 检查 ata.createIdempotent
{
instruction := rawTx.Transaction.Message.Instructions[2]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SPLAssociatedTokenAccountProgramID {
return false
}
if instruction.Data.String() != "2" {
return false
}
if len(instruction.Accounts) < 4 {
return false
}
// gmgn 会先创建 wsol 账户, 而不是 token 账户
accountId := accountList[instruction.Accounts[3]]
if accountId != solana.WrappedSol {
return false
}
}
// 检查 transfer
{
instruction := rawTx.Transaction.Message.Instructions[3]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SystemProgramID {
return false
}
if len(instruction.Data) == 0 || instruction.Data[0] != 2 {
return false
}
}
// 检查 token.syncNative
{
instruction := rawTx.Transaction.Message.Instructions[4]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.TokenProgramID {
return false
}
if instruction.Data.String() != "J" {
return false
}
}
offset := 5
if len(rawTx.Transaction.Message.Instructions) == 10 {
// 检查 ata.create
{
instruction := rawTx.Transaction.Message.Instructions[offset]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SPLAssociatedTokenAccountProgramID {
return false
}
if instruction.Data.String() != "1" {
return false
}
}
offset++
}
// 检查 bonk.buy
{
instruction := rawTx.Transaction.Message.Instructions[offset]
programId := accountList[instruction.ProgramIDIndex]
if programId != raydiumLaunchLabProgramID {
return false
}
}
offset++
// 检查 token.closeAccount
{
instruction := rawTx.Transaction.Message.Instructions[offset]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.TokenProgramID {
return false
}
if instruction.Data.String() != "A" {
return false
}
}
offset++
// 检查 transfer
{
instruction := rawTx.Transaction.Message.Instructions[offset]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SystemProgramID {
return false
}
if len(instruction.Data) == 0 || instruction.Data[0] != 2 {
return false
}
}
offset++
// 检查 transfer
{
instruction := rawTx.Transaction.Message.Instructions[offset]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SystemProgramID {
return false
}
if len(instruction.Data) == 0 || instruction.Data[0] != 2 {
return false
}
}
return true
}
var (
axiomTxLoopupTable = solana.MustPublicKeyFromBase58("7RKtfATWCe98ChuwecNq8XCzAzfoK3DtZTprFsPMGtio")
axiomProgramID = solana.MustPublicKeyFromBase58("AxiomfHaWDemCFBLBayqnEnNwE6b7B2Qz3UmzMpgbMG6")
gmgnProgramID = solana.MustPublicKeyFromBase58("GMgnVFR8Jb39LoXsEVzb3DvBy3ywCmdmJquHUy1Lrkqb")
)
func checkBonkAxiomBuy(rawTx *RawTx) bool {
// 检查交易版本
var version, _ = rawTx.Version.(solana.MessageVersion)
if version == solana.MessageVersionLegacy || len(rawTx.Transaction.Message.AddressTableLookups) != 1 {
log.Printf("CheckBonkAxiomBuy: Invalid transaction version or address table lookups: %v %v %v", rawTx.Transaction.Signatures[0].String(), version, len(rawTx.Transaction.Message.AddressTableLookups))
return false
}
// 检查 addressLookupTable 是否是 Axiom 的
if rawTx.Transaction.Message.AddressTableLookups[0].AccountKey != axiomTxLoopupTable {
log.Printf("CheckBonkAxiomBuy: Invalid address lookup table: %v", rawTx.Transaction.Signatures[0].String())
return false
}
// 检查交易指令数量
if len(rawTx.Transaction.Message.Instructions) != 10 {
return false
}
accountList := rawTx.getAccountList()
// 检查 cu limit
{
instruction := rawTx.Transaction.Message.Instructions[0]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.ComputeBudget {
log.Printf("CheckBonkAxiomBuy: Invalid program ID for ComputeBudget: %v", programId)
return false
}
if len(instruction.Accounts) != 1 {
log.Printf("CheckBonkAxiomBuy: Invalid number of accounts for ComputeBudget: %v", len(instruction.Accounts))
return false
}
accountId := accountList[instruction.Accounts[0]].String()
if !strings.HasPrefix(accountId, "jitodontfront") || !strings.HasSuffix(accountId, "TradeWithAxiomDotTrade") {
log.Printf("CheckBonkAxiomBuy: Invalid account ID for ComputeBudget: %v", accountId)
return false
}
}
// 检查 cu price
{
instruction := rawTx.Transaction.Message.Instructions[1]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.ComputeBudget {
log.Printf("CheckBonkAxiomBuy: Invalid program ID for ComputeBudget: %v", programId)
return false
}
}
// 检查 ata.createIdempotent
{
instruction := rawTx.Transaction.Message.Instructions[2]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SPLAssociatedTokenAccountProgramID {
log.Printf("CheckBonkAxiomBuy: Invalid program ID for SPLAssociatedTokenAccount: %v", programId)
return false
}
if instruction.Data.String() != "2" {
log.Printf("CheckBonkAxiomBuy: Invalid data for SPLAssociatedTokenAccount: %v", instruction.Data.String())
return false
}
if len(instruction.Accounts) < 4 {
log.Printf("CheckBonkAxiomBuy: Invalid number of accounts for SPLAssociatedTokenAccount: %v", len(instruction.Accounts))
return false
}
// axiom 会先创建 token 账户, 而不是 wsol 账户
accountId := accountList[instruction.Accounts[3]]
if accountId == solana.WrappedSol {
log.Printf("CheckBonkAxiomBuy: Invalid account ID for SPLAssociatedTokenAccount, expected token account but got wsol: %v", accountId)
return false
}
}
// 检查 ata.createIdempotent
{
instruction := rawTx.Transaction.Message.Instructions[3]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SPLAssociatedTokenAccountProgramID {
log.Printf("CheckBonkAxiomBuy: Invalid program ID for SPLAssociatedTokenAccount2: %v", programId)
return false
}
if instruction.Data.String() != "2" {
log.Printf("CheckBonkAxiomBuy: Invalid data for SPLAssociatedTokenAccount2: %v", instruction.Data.String())
return false
}
if len(instruction.Accounts) < 4 {
log.Printf("CheckBonkAxiomBuy: Invalid number of accounts for SPLAssociatedTokenAccount2: %v", len(instruction.Accounts))
return false
}
// axiom 会先创建 token 账户, 而不是 wsol 账户
accountId := accountList[instruction.Accounts[3]]
if accountId != solana.WrappedSol {
log.Printf("CheckBonkAxiomBuy: Invalid account ID for SPLAssociatedTokenAccount2, expected wsol but got: %v", accountId)
return false
}
}
// 检查 transfer
{
instruction := rawTx.Transaction.Message.Instructions[4]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SystemProgramID {
log.Printf("CheckBonkAxiomBuy: Invalid program ID for SystemProgram3: %v", programId)
return false
}
if len(instruction.Data) == 0 || instruction.Data[0] != 2 {
log.Printf("CheckBonkAxiomBuy: Invalid data for SystemProgram transfer3: %v", instruction.Data)
return false
}
}
// 检查 token.syncNative
{
instruction := rawTx.Transaction.Message.Instructions[5]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.TokenProgramID {
log.Printf("CheckBonkAxiomBuy: Invalid program ID for TokenProgram3: %v", programId)
return false
}
if instruction.Data.String() != "J" {
log.Printf("CheckBonkAxiomBuy: Invalid data for TokenProgram syncNative3: %v", instruction.Data.String())
return false
}
}
// 检查 bonk.buy
{
instruction := rawTx.Transaction.Message.Instructions[6]
programId := accountList[instruction.ProgramIDIndex]
if programId != raydiumLaunchLabProgramID {
return false
}
}
// 检查 token.closeAccount
{
instruction := rawTx.Transaction.Message.Instructions[7]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.TokenProgramID {
log.Printf("CheckBonkAxiomBuy: Invalid program ID for TokenProgram closeAccount: %v", programId)
return false
}
if instruction.Data.String() != "A" {
log.Printf("CheckBonkAxiomBuy: Invalid data for TokenProgram closeAccount: %v", instruction.Data.String())
return false
}
}
// 检查 transfer
{
instruction := rawTx.Transaction.Message.Instructions[8]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SystemProgramID {
log.Printf("CheckBonkAxiomBuy: Invalid program ID for SystemProgram transfer4: %v", programId)
return false
}
if len(instruction.Data) == 0 || instruction.Data[0] != 2 {
log.Printf("CheckBonkAxiomBuy: Invalid data for SystemProgram transfer4: %v", instruction.Data)
return false
}
}
// 检查 transfer
{
instruction := rawTx.Transaction.Message.Instructions[9]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SystemProgramID {
log.Printf("CheckBonkAxiomBuy: Invalid program ID for SystemProgram transfer5: %v", programId)
return false
}
if len(instruction.Data) == 0 || instruction.Data[0] != 2 {
log.Printf("CheckBonkAxiomBuy: Invalid data for SystemProgram transfer5: %v", instruction.Data)
return false
}
}
return true
}
func checkPumpFunAxiomBuy(rawTx *RawTx) bool {
// 检查交易版本
if rawTx.Version == "legacy" || len(rawTx.Transaction.Message.AddressTableLookups) != 1 {
return false
}
// 检查 addressLookupTable 是否是 Axiom 的
if rawTx.Transaction.Message.AddressTableLookups[0].AccountKey != axiomTxLoopupTable {
return false
}
// 检查交易指令数量
if len(rawTx.Transaction.Message.Instructions) != 6 {
return false
}
accountList := rawTx.getAccountList()
// 检查 cu limit
{
instruction := rawTx.Transaction.Message.Instructions[0]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.ComputeBudget {
return false
}
if len(instruction.Accounts) != 1 {
return false
}
accountId := accountList[instruction.Accounts[0]].String()
if !strings.HasPrefix(accountId, "jitodontfront") || !strings.HasSuffix(accountId, "TradeWithAxiomDotTrade") {
return false
}
}
// 检查 cu price
{
instruction := rawTx.Transaction.Message.Instructions[1]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.ComputeBudget {
return false
}
}
// 检查 ata.createIdempotent
{
instruction := rawTx.Transaction.Message.Instructions[2]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SPLAssociatedTokenAccountProgramID {
return false
}
if instruction.Data.String() != "2" {
return false
}
if len(instruction.Accounts) < 4 {
return false
}
// axiom 会先创建 token 账户, 而不是 wsol 账户
accountId := accountList[instruction.Accounts[3]]
if accountId == solana.WrappedSol {
return false
}
}
// 检查调用axiom合约
{
instruction := rawTx.Transaction.Message.Instructions[3]
programId := accountList[instruction.ProgramIDIndex]
if programId != axiomProgramID {
return false
}
}
// 检查 transfer
{
instruction := rawTx.Transaction.Message.Instructions[4]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SystemProgramID {
return false
}
if len(instruction.Data) == 0 || instruction.Data[0] != 2 {
return false
}
}
// 检查 transfer
{
instruction := rawTx.Transaction.Message.Instructions[5]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SystemProgramID {
return false
}
if len(instruction.Data) == 0 || instruction.Data[0] != 2 {
return false
}
}
return true
}
func checkPumpFunGmgnBuy(rawTx *RawTx) bool {
// 检查交易版本
if rawTx.Version != "legacy" {
return false
}
// 检查交易指令数量
if len(rawTx.Transaction.Message.Instructions) != 6 {
return false
}
accountList := rawTx.getAccountList()
// 检查 cu limit
{
instruction := rawTx.Transaction.Message.Instructions[0]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.ComputeBudget {
return false
}
if len(instruction.Accounts) != 1 {
return false
}
accountId := accountList[instruction.Accounts[0]].String()
if !strings.HasPrefix(accountId, "jitodontfront1111111111151111111111111655") {
return false
}
}
// 检查 cu price
{
instruction := rawTx.Transaction.Message.Instructions[1]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.ComputeBudget {
return false
}
}
// 检查 ata.createIdempotent
{
instruction := rawTx.Transaction.Message.Instructions[2]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SPLAssociatedTokenAccountProgramID {
return false
}
if instruction.Data.String() != "2" {
return false
}
if len(instruction.Accounts) < 4 {
return false
}
accountId := accountList[instruction.Accounts[3]]
if accountId == solana.WrappedSol {
return false
}
}
// 检查调用 gmgn 合约
{
instruction := rawTx.Transaction.Message.Instructions[3]
programId := accountList[instruction.ProgramIDIndex]
if programId != gmgnProgramID {
return false
}
}
// 检查 transfer
{
instruction := rawTx.Transaction.Message.Instructions[4]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SystemProgramID {
return false
}
if len(instruction.Data) == 0 || instruction.Data[0] != 2 {
return false
}
}
// 检查 transfer
{
instruction := rawTx.Transaction.Message.Instructions[5]
programId := accountList[instruction.ProgramIDIndex]
if programId != solana.SystemProgramID {
return false
}
if len(instruction.Data) == 0 || instruction.Data[0] != 2 {
return false
}
}
return true
}

View File

@@ -39,6 +39,8 @@ var platformFeeAddresses = map[solana.PublicKey]string{
solana.MustPublicKeyFromBase58("F4hJ3Ee3c5UuaorKAMfELBjYCjiiLH75haZTKqTywRP3"): PlatformBullX, solana.MustPublicKeyFromBase58("F4hJ3Ee3c5UuaorKAMfELBjYCjiiLH75haZTKqTywRP3"): PlatformBullX,
solana.MustPublicKeyFromBase58("47hEzz83VFR23rLTEeVm9A7eFzjJwjvdupPPmX3cePqF"): PlatformBanana, solana.MustPublicKeyFromBase58("47hEzz83VFR23rLTEeVm9A7eFzjJwjvdupPPmX3cePqF"): PlatformBanana,
solana.MustPublicKeyFromBase58("9yMwSPk9mrXSN7yDHUuZurAh1sjbJsfpUqjZ7SvVtdco"): PlatformTrojan, solana.MustPublicKeyFromBase58("9yMwSPk9mrXSN7yDHUuZurAh1sjbJsfpUqjZ7SvVtdco"): PlatformTrojan,
solana.MustPublicKeyFromBase58("92Med3qeK7duC5iiYsHX38H2f2twJfRsSx93oNrza2VH"): PlatformTrojan,
solana.MustPublicKeyFromBase58("65gDv7pZQCZELsNpNYSFEBtNFpWZAbxmRFB6BGMqFkHH"): PlatformTrojan,
solana.MustPublicKeyFromBase58("4mih95RmBqfHYvEfqq6uGGLp1Fr3gVS3VNSEa3JVRfQK"): PlatformRaybot, solana.MustPublicKeyFromBase58("4mih95RmBqfHYvEfqq6uGGLp1Fr3gVS3VNSEa3JVRfQK"): PlatformRaybot,
solana.MustPublicKeyFromBase58("3udvfL24waJcLhskRAsStNMoNUvtyXdxrWQz4hgi953N"): PlatformMoonshot, solana.MustPublicKeyFromBase58("3udvfL24waJcLhskRAsStNMoNUvtyXdxrWQz4hgi953N"): PlatformMoonshot,
solana.MustPublicKeyFromBase58("3kxSQybWEeQZsMuNWMRJH4TxrhwoDwfv41TNMLRzFP5A"): PlatformMEVX, solana.MustPublicKeyFromBase58("3kxSQybWEeQZsMuNWMRJH4TxrhwoDwfv41TNMLRzFP5A"): PlatformMEVX,

154
error.go
View File

@@ -79,54 +79,54 @@ const (
const ( const (
GenericError InstructionErrorVariant = iota GenericError InstructionErrorVariant = iota
/// The arguments provided to a program were invalid // InvalidArgument / The arguments provided to a program were invalid
InvalidArgument InvalidArgument
/// An instruction's data contents were invalid // InvalidInstructionData / An instruction's data contents were invalid
InvalidInstructionData InvalidInstructionData
/// An account's data contents was invalid // InvalidAccountData / An account's data contents was invalid
InvalidAccountData InvalidAccountData
/// An account's data was too small // AccountDataTooSmall / An account's data was too small
AccountDataTooSmall AccountDataTooSmall
/// An account's balance was too small to complete the instruction // InsufficientFunds / An account's balance was too small to complete the instruction
InsufficientFunds InsufficientFunds
/// The account did not have the expected program id // IncorrectProgramId / The account did not have the expected program id
IncorrectProgramId IncorrectProgramId
/// A signature was required but not found // MissingRequiredSignature / A signature was required but not found
MissingRequiredSignature MissingRequiredSignature
/// An initialize instruction was sent to an account that has already been initialized. // AccountAlreadyInitialized / An initialize instruction was sent to an account that has already been initialized.
AccountAlreadyInitialized AccountAlreadyInitialized
/// An attempt to operate on an account that hasn't been initialized. // UninitializedAccount / An attempt to operate on an account that hasn't been initialized.
UninitializedAccount UninitializedAccount
/// Program's instruction lamport balance does not equal the balance after the instruction // UnbalancedInstruction / Program's instruction lamport balance does not equal the balance after the instruction
UnbalancedInstruction UnbalancedInstruction
/// Program illegally modified an account's program id // ModifiedProgramId / Program illegally modified an account's program id
ModifiedProgramId ModifiedProgramId
/// Program spent the lamports of an account that doesn't belong to it // ExternalAccountLamportSpend / Program spent the lamports of an account that doesn't belong to it
ExternalAccountLamportSpend ExternalAccountLamportSpend
/// Program modified the data of an account that doesn't belong to it // ExternalAccountDataModified / Program modified the data of an account that doesn't belong to it
ExternalAccountDataModified ExternalAccountDataModified
/// Read-only account's lamports modified // ReadonlyLamportChange / Read-only account's lamports modified
ReadonlyLamportChange ReadonlyLamportChange
/// Read-only account's data was modified // ReadonlyDataModified / Read-only account's data was modified
ReadonlyDataModified ReadonlyDataModified
/// An account was referenced more than once in a single instruction // DuplicateAccountIndex / An account was referenced more than once in a single instruction
// Deprecated, instructions can now contain duplicate accounts // Deprecated, instructions can now contain duplicate accounts
DuplicateAccountIndex DuplicateAccountIndex
/// Executable bit on account changed, but shouldn't have // ExecutableModified / Executable bit on account changed, but shouldn't have
ExecutableModified ExecutableModified
/// Rent_epoch account changed, but shouldn't have // RentEpochModified / Rent_epoch account changed, but shouldn't have
RentEpochModified RentEpochModified
/// The instruction expected additional account keys // NotEnoughAccountKeys / The instruction expected additional account keys
NotEnoughAccountKeys NotEnoughAccountKeys
/// Program other than the account's owner changed the size of the account data // AccountDataSizeChanged / Program other than the account's owner changed the size of the account data
AccountDataSizeChanged AccountDataSizeChanged
/// The instruction expected an executable account // AccountNotExecutable / The instruction expected an executable account
AccountNotExecutable AccountNotExecutable
/// Failed to borrow a reference to account data, already borrowed // AccountBorrowFailed / Failed to borrow a reference to account data, already borrowed
AccountBorrowFailed AccountBorrowFailed
/// Account data has an outstanding reference after a program's execution // InstructionAccountBorrowOutstanding / Account data has an outstanding reference after a program's execution
InstructionAccountBorrowOutstanding InstructionAccountBorrowOutstanding
/// The same account was multiply passed to an on-chain program's entrypoint, but the program // DuplicateAccountOutOfSync / The same account was multiply passed to an on-chain program's entrypoint, but the program
/// modified them differently. A program can only modify one instance of the account because /// modified them differently. A program can only modify one instance of the account because
/// the runtime cannot determine which changes to pick or how to merge them if both are modified /// the runtime cannot determine which changes to pick or how to merge them if both are modified
DuplicateAccountOutOfSync DuplicateAccountOutOfSync
@@ -136,42 +136,42 @@ const (
Custom // Custom(u32), Custom // Custom(u32),
/// The return value from the program was invalid. Valid errors are either a defined builtin // InvalidError / The return value from the program was invalid. Valid errors are either a defined builtin
/// error value or a user-defined error in the lower 32 bits. /// error value or a user-defined error in the lower 32 bits.
InvalidError InvalidError
/// Executable account's data was modified // ExecutableDataModified / Executable account's data was modified
ExecutableDataModified ExecutableDataModified
/// Executable account's lamports modified // ExecutableLamportChange / Executable account's lamports modified
ExecutableLamportChange ExecutableLamportChange
/// Executable accounts must be rent exempt // ExecutableAccountNotRentExempt / Executable accounts must be rent exempt
ExecutableAccountNotRentExempt ExecutableAccountNotRentExempt
/// Unsupported program id // UnsupportedProgramId / Unsupported program id
UnsupportedProgramId UnsupportedProgramId
/// Cross-program invocation call depth too deep // CallDepth / Cross-program invocation call depth too deep
CallDepth CallDepth
/// An account required by the instruction is missing // MissingAccount / An account required by the instruction is missing
MissingAccount MissingAccount
/// Cross-program invocation reentrancy not allowed for this instruction // ReentrancyNotAllowed / Cross-program invocation reentrancy not allowed for this instruction
ReentrancyNotAllowed ReentrancyNotAllowed
/// Length of the seed is too long for address generation // MaxSeedLengthExceeded / Length of the seed is too long for address generation
MaxSeedLengthExceeded MaxSeedLengthExceeded
/// Provided seeds do not result in a valid address // InvalidSeeds / Provided seeds do not result in a valid address
InvalidSeeds InvalidSeeds
/// Failed to reallocate account data of this length // InvalidRealloc / Failed to reallocate account data of this length
InvalidRealloc InvalidRealloc
/// Computational budget exceeded // ComputationalBudgetExceeded / Computational budget exceeded
ComputationalBudgetExceeded ComputationalBudgetExceeded
/// Cross-program invocation with unauthorized signer or writable account // PrivilegeEscalation / Cross-program invocation with unauthorized signer or writable account
PrivilegeEscalation PrivilegeEscalation
/// Failed to create program execution environment // ProgramEnvironmentSetupFailure / Failed to create program execution environment
ProgramEnvironmentSetupFailure ProgramEnvironmentSetupFailure
/// Program failed to complete // ProgramFailedToComplete / Program failed to complete
ProgramFailedToComplete ProgramFailedToComplete
/// Program failed to compile // ProgramFailedToCompile / Program failed to compile
ProgramFailedToCompile ProgramFailedToCompile
/// Account is immutable // Immutable / Account is immutable
Immutable Immutable
/// Incorrect authority provided // IncorrectAuthority / Incorrect authority provided
IncorrectAuthority IncorrectAuthority
/// Failed to serialize or deserialize account data /// Failed to serialize or deserialize account data
/// ///
@@ -185,23 +185,23 @@ const (
BorshIoError // BorshIoError(String) BorshIoError // BorshIoError(String)
// An account does not have enough lamports to be rent-exempt // AccountNotRentExempt An account does not have enough lamports to be rent-exempt
AccountNotRentExempt AccountNotRentExempt
/// Invalid account owner // InvalidAccountOwner Invalid account owner
InvalidAccountOwner InvalidAccountOwner
/// Program arithmetic overflowed // ArithmeticOverflow Program arithmetic overflowed
ArithmeticOverflow ArithmeticOverflow
/// Unsupported sysvar // UnsupportedSysvar Unsupported sysvar
UnsupportedSysvar UnsupportedSysvar
/// Illegal account owner // IllegalOwner Illegal account owner
IllegalOwner IllegalOwner
/// Accounts data allocations exceeded the maximum allowed per transaction // MaxAccountsDataAllocationsExceeded / Accounts data allocations exceeded the maximum allowed per transaction
MaxAccountsDataAllocationsExceeded MaxAccountsDataAllocationsExceeded
/// Max accounts exceeded // MaxAccountsExceeded Max accounts exceeded
MaxAccountsExceeded MaxAccountsExceeded
/// Max instruction trace length exceeded // MaxInstructionTraceLengthExceeded Max instruction trace length exceeded
MaxInstructionTraceLengthExceeded MaxInstructionTraceLengthExceeded
/// Builtin programs must consume compute units // BuiltinProgramsMustConsumeComputeUnits Builtin programs must consume compute units
BuiltinProgramsMustConsumeComputeUnits BuiltinProgramsMustConsumeComputeUnits
) )
@@ -210,6 +210,15 @@ type TransactionError struct {
rest []byte rest []byte
} }
type TransactionParsedError struct {
Index uint8
Variant TransactionErrorVariant
Enum InstructionErrorVariant
CustomCode uint32
UnKnown string
}
var ( var (
ErrInvalidTransactionError = errors.New("invalid transaction error") ErrInvalidTransactionError = errors.New("invalid transaction error")
NotAnInstructionError = errors.New("not an instruction error") NotAnInstructionError = errors.New("not an instruction error")
@@ -233,6 +242,49 @@ func DecodeTransactionError(data []byte) (*TransactionError, error) {
return &err, nil return &err, nil
} }
func ParseTransactionErrorFromGeyser(data []byte) *TransactionParsedError {
if len(data) == 0 {
return nil
}
transactionError, err := DecodeTransactionError(data)
if err != nil {
return &TransactionParsedError{
UnKnown: string(data),
}
}
enumErr, err := transactionError.GetInstructionError()
if err != nil {
return &TransactionParsedError{
Variant: transactionError.Variant,
UnKnown: string(data),
}
}
if enumErr.Variant != Custom {
return &TransactionParsedError{
Index: enumErr.Index,
Variant: transactionError.Variant,
Enum: enumErr.Variant,
}
}
customCode, err := enumErr.Custom()
if err != nil {
return &TransactionParsedError{
Index: enumErr.Index,
Variant: transactionError.Variant,
Enum: enumErr.Variant,
UnKnown: string(data),
}
}
return &TransactionParsedError{
Index: enumErr.Index,
Variant: transactionError.Variant,
Enum: enumErr.Variant,
CustomCode: customCode.Code,
}
}
func (e *TransactionError) GetCustomErrorCode() (uint8, uint32, error) { func (e *TransactionError) GetCustomErrorCode() (uint8, uint32, error) {
instr, err := e.GetInstructionError() instr, err := e.GetInstructionError()
if err != nil { if err != nil {

47
error_test.go Normal file
View File

@@ -0,0 +1,47 @@
package pump_parser
import (
"encoding/base64"
"testing"
)
func TestDecodeTransactionError(t *testing.T) {
var testCases = []struct {
name string
data string
}{
{
name: "ComputationalBudgetExceeded",
data: "CAAAAAMlAAAA",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
bytesData, err := base64.StdEncoding.DecodeString(tc.data)
if err != nil {
t.Fatalf("Failed to decode base64 data for %s: %v", tc.name, err)
return
}
te, err := DecodeTransactionError(bytesData)
if err != nil {
t.Errorf("Decoded error for %s: %v", tc.name, err)
return
}
if te.Variant != InstructionError {
t.Errorf("Expected Variant to be InstructionError for %s, got %d", tc.name, te.Variant)
return
}
errName, err := te.GetInstructionError()
if err != nil {
t.Errorf("Failed to get instruction error for %s: %v", tc.name, err)
return
}
if errName.Variant != ComputationalBudgetExceeded {
t.Errorf("Expected instruction error variant to be Custom for %s, got %d", tc.name, errName.Variant)
return
}
})
}
}

View File

@@ -5,10 +5,17 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/gagliardetto/solana-go"
"github.com/shopspring/decimal"
parser "github.com/thloyi/pump-parser" parser "github.com/thloyi/pump-parser"
example "github.com/thloyi/pump-parser/internal/example" example "github.com/thloyi/pump-parser/internal/example"
) )
var (
pumpProgram = solana.MustPublicKeyFromBase58("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P")
pumpAmmProgram = solana.MustPublicKeyFromBase58("pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA")
)
func main() { func main() {
//pool, err := ants.NewPool(100, ants.WithPreAlloc(true), ants.WithNonblocking(true)) //pool, err := ants.NewPool(100, ants.WithPreAlloc(true), ants.WithNonblocking(true))
//if err != nil { //if err != nil {
@@ -31,7 +38,7 @@ func main() {
continue continue
} }
ptx := msg.Tx ptx := msg.Tx
fmt.Println("consume", ptx.ComputeUnitsConsumed, "limit", ptx.CuLimit, "hash", ptx.GetTxHash()) // fmt.Println("consume", ptx.ComputeUnitsConsumed, "limit", ptx.CuLimit, "hash", ptx.GetTxHash())
//data, _ := json.Marshal(tx) //data, _ := json.Marshal(tx)
//fmt.Println(string(data)) //fmt.Println(string(data))
//continue //continue
@@ -44,43 +51,9 @@ func main() {
//} //}
// 处理交易 // 处理交易
txErr, ok := ptx.Err.(*parser.TransactionError) if len(ptx.Swaps) > 0 && (ptx.Swaps[0].Program == parser.SolProgramPump || ptx.Swaps[0].Program == parser.SolProgramPumpAMM) {
var customerErrCode uint32 fmt.Printf("success tx : %s, program: %s, event: %s, block: %d, tx: %s, base: %s, quote: %s \n", time.Now().Format("2006-01-02 15:04:05"), ptx.Swaps[0].Program, ptx.Swaps[0].Event, ptx.Block, ptx.GetTxHash(),
var instructorErrIndex uint8 ptx.Swaps[0].BaseAmount.Div(decimal.NewFromInt(1e6)), ptx.Swaps[0].QuoteAmount.Div(decimal.NewFromInt(1e9)))
if ok {
instructorErrIndex, customerErrCode, _ = txErr.GetCustomErrorCode()
fmt.Printf("now: %s, block: %d, tx: %s, errInstr Code: %d, errInstrIndex: %d, err: %v\n", time.Now().Format("2006-01-02 15:04:05"), ptx.Block, ptx.GetTxHash(), customerErrCode, instructorErrIndex, ptx.Err)
} else {
txs := example.FromTx(ptx)
if len(txs) == 0 {
fmt.Printf("tx is empty, block: %d, tx %s \n", ptx.Block, ptx.GetTxHash())
continue
}
// printed := false
for _, tx := range txs {
if tx.Program != parser.SolProgramPumpAMM {
continue
}
if tx.EntryContract == "" || tx.EntryContract == parser.SolProgramPumpAMM || tx.EntryContract == parser.EntryContractOKXDexRouterV2 || tx.EntryContract == "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr" {
continue
}
//if tx.Token1Amount.GreaterThanOrEqual(decimal.NewFromFloat(0.1)) || tx.Event != "buy" {
// continue
//}
// printed = true
fmt.Printf("t: %s, block: %d, hash: %s, maker: %s, program: %s, event: %s, token0: %s, entryContract: %s, token balance: %s, EntryContract: %s\n",
time.Now().Format(time.RFC3339Nano),
tx.Block, tx.GetTxHash(), tx.Maker, tx.Program, tx.Event, tx.Token0Amount, tx.EntryContract, tx.AfterSignerToken0Balance, tx.EntryContract)
//break
}
//if !printed {
// continue
//}
//fmt.Printf("t: %s, block: %d, hash: %s, signer: %s, program: %s, event: %s, token0: %s, token1: %s, signer before sol :%s, after sol: %s, after token: %s, tokencreator: %s, tokenprogram: %s, mayhem: %t\n",
// time.Now().Format(time.RFC3339Nano),
// tx.Block, tx.GetTxHash(), tx.Maker, tx.Program, tx.Event, tx.Token0Amount.String(), tx.Token1Amount.String(),
// tx.BeforeSolBalance, tx.AfterSOLBalance, tx.AfterSignerToken0Balance, tx.TokenCreator, tx.Token0Program, tx.Mayhem)
} }
// currentBlock = ptx.Block // currentBlock = ptx.Block
// //

View File

@@ -3,7 +3,6 @@ package parser
import ( import (
"fmt" "fmt"
"github.com/shopspring/decimal"
types "github.com/thloyi/pump-parser" types "github.com/thloyi/pump-parser"
) )
@@ -23,24 +22,14 @@ func NewPumpHandler(cb func(*types.Tx)) *PumpHandler {
func (h *PumpHandler) HandleMessage(rawTx *types.RawTx) { func (h *PumpHandler) HandleMessage(rawTx *types.RawTx) {
if rawTx.Meta.Err != nil { if rawTx.Meta.Err != nil {
// Notify the channel about the failed transaction // Notify the channel about the failed transaction
beforeSolBalance := decimal.Zero var parsedTx = &types.Tx{}
afterSolBalance := decimal.Zero parsedTx.SetRawTx(rawTx)
if rawTx.Meta.PreBalances != nil && len(rawTx.Meta.PreBalances) > 0 { err := parsedTx.Parser()
beforeSolBalance = decimal.NewFromUint64(rawTx.Meta.PreBalances[0]).Div(decimal.NewFromInt(1e9)) if err != nil {
fmt.Printf("parser failed tx error: %s, block: %d tx: %s\n", err, rawTx.Slot, rawTx.TxHash())
return
} }
if rawTx.Meta.PostBalances != nil && len(rawTx.Meta.PostBalances) > 0 { h.callback(parsedTx)
afterSolBalance = decimal.NewFromUint64(rawTx.Meta.PostBalances[0]).Div(decimal.NewFromInt(1e9))
}
h.callback(&types.Tx{
TxHash: (*[64]byte)((rawTx.Transaction.Signatures[0][:])),
Err: rawTx.Meta.Err,
Signer: rawTx.GetSigner(),
Block: rawTx.Slot,
BlockIndex: uint64(rawTx.IndexWithinBlock),
BeforeSolBalance: beforeSolBalance,
AfterSOLBalance: afterSolBalance,
})
return return
} }

View File

@@ -50,7 +50,8 @@ type Tx struct {
AfterSOLBalance decimal.Decimal `gorm:"column:after_sol_balance;type:numeric" json:"after_sol_balance"` AfterSOLBalance decimal.Decimal `gorm:"column:after_sol_balance;type:numeric" json:"after_sol_balance"`
EntryContract string `gorm:"column:tx_entry_contract;type:entry_contract;default:'none'" json:"tx_entry_contract"` EntryContract string `gorm:"column:tx_entry_contract;type:entry_contract;default:'none'" json:"tx_entry_contract"`
Mayhem bool Mayhem bool
Cashback bool `json:"is_cashback_coin"`
} }
func (tx *Tx) GetTxHash() string { func (tx *Tx) GetTxHash() string {
@@ -121,6 +122,7 @@ func FromTx(tx *parser.Tx) []*Tx {
EntryContract: s.CheckEntryContract(), EntryContract: s.CheckEntryContract(),
Mayhem: s.Mayhem, Mayhem: s.Mayhem,
Cashback: s.Cashback,
} }
} else if s.Program == "PumpAMM" { } else if s.Program == "PumpAMM" {
if s.BaseMint.Equals(solana.WrappedSol) { if s.BaseMint.Equals(solana.WrappedSol) {
@@ -175,6 +177,7 @@ func FromTx(tx *parser.Tx) []*Tx {
EntryContract: s.CheckEntryContract(), EntryContract: s.CheckEntryContract(),
Mayhem: s.Mayhem, Mayhem: s.Mayhem,
Cashback: s.Cashback,
} }
} else { } else {
newTx = &Tx{ newTx = &Tx{
@@ -219,6 +222,7 @@ func FromTx(tx *parser.Tx) []*Tx {
EntryContract: s.CheckEntryContract(), EntryContract: s.CheckEntryContract(),
Mayhem: s.Mayhem, Mayhem: s.Mayhem,
Cashback: s.Cashback,
} }
} }
} }

View File

@@ -50,21 +50,18 @@ type Client struct {
func NewClientWithPumpSwap(endpoint string, ch chan SubscriptionMessage) *Client { func NewClientWithPumpSwap(endpoint string, ch chan SubscriptionMessage) *Client {
var subscription pb.SubscribeRequest var subscription pb.SubscribeRequest
var failed = false //var failed = true
var vote = false var vote = false
subscription.Transactions = make(map[string]*pb.SubscribeRequestFilterTransactions) subscription.Transactions = make(map[string]*pb.SubscribeRequestFilterTransactions)
subscription.Transactions["transactions_sub"] = &pb.SubscribeRequestFilterTransactions{ subscription.Transactions["transactions_sub"] = &pb.SubscribeRequestFilterTransactions{
Failed: &failed, //Failed: &failed,
Vote: &vote, Vote: &vote,
} }
subscription.Transactions["transactions_sub"].AccountInclude = []string{ subscription.Transactions["transactions_sub"].AccountInclude = []string{
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA", //Pump AMM "pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA", //Pump AMM
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P", //Pump "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P", //Pump
} }
subscription.Transactions["transactions_sub"].AccountRequired = []string{
"ARu4n5mFdZogZAravu7CcizaojWnS6oqka37gdLT5SZn",
}
subscription.BlocksMeta = make(map[string]*pb.SubscribeRequestFilterBlocksMeta) subscription.BlocksMeta = make(map[string]*pb.SubscribeRequestFilterBlocksMeta)
subscription.BlocksMeta["block_meta"] = &pb.SubscribeRequestFilterBlocksMeta{} subscription.BlocksMeta["block_meta"] = &pb.SubscribeRequestFilterBlocksMeta{}
@@ -85,12 +82,12 @@ func NewClientWithPumpSwap(endpoint string, ch chan SubscriptionMessage) *Client
func NewClientWithLaunchLab(endpoint string, ch chan SubscriptionMessage) *Client { func NewClientWithLaunchLab(endpoint string, ch chan SubscriptionMessage) *Client {
var subscription pb.SubscribeRequest var subscription pb.SubscribeRequest
var failed = false //var failed = false
var vote = false var vote = false
subscription.Transactions = make(map[string]*pb.SubscribeRequestFilterTransactions) subscription.Transactions = make(map[string]*pb.SubscribeRequestFilterTransactions)
subscription.Transactions["transactions_sub"] = &pb.SubscribeRequestFilterTransactions{ subscription.Transactions["transactions_sub"] = &pb.SubscribeRequestFilterTransactions{
Failed: &failed, //Failed: &failed,
Vote: &vote, Vote: &vote,
} }
subscription.Transactions["transactions_sub"].AccountInclude = []string{ subscription.Transactions["transactions_sub"].AccountInclude = []string{

View File

@@ -23,7 +23,7 @@ var ()
func main() { func main() {
var slot uint64 = 399477968 var slot uint64 = 403021435
var data = NewBlockData(decimal.NewFromFloat(100.0)) var data = NewBlockData(decimal.NewFromFloat(100.0))
client := rpc.New("https://staked.helius-rpc.com?api-key=5adcf1f9-5719-43d1-bf3f-c2d4e1e5f94d") client := rpc.New("https://staked.helius-rpc.com?api-key=5adcf1f9-5719-43d1-bf3f-c2d4e1e5f94d")
var rewards = false var rewards = false
@@ -53,9 +53,9 @@ func main() {
fmt.Println("from rpc tx error:", i, err) fmt.Println("from rpc tx error:", i, err)
break break
} }
if rawTx.Meta.Err != nil { //if rawTx.Meta.Err != nil {
continue // continue
} //}
parsedTx, err := solana_parser.ParseRawTx(rawTx) parsedTx, err := solana_parser.ParseRawTx(rawTx)
if err != nil { if err != nil {
fmt.Println("parse tx error:", i, rawTx.TxHash(), err) fmt.Println("parse tx error:", i, rawTx.TxHash(), err)
@@ -91,9 +91,7 @@ func main() {
fmt.Println("parse action error:", "tx", result.GetTxHash(), "i", i, "err", err) fmt.Println("parse action error:", "tx", result.GetTxHash(), "i", i, "err", err)
} }
} }
if result.GetTxHash() == "3vMp5Lqm7PxS9MXfXgmptKA9xLkyfKfJpuFs2mUfhRuqTWjGj7DcvSb65NsHQH5RF9JXVLbxrpUHV4LXrgmjXmft" {
fmt.Println("xxx")
}
} }
fmt.Println("slot", slot, "tx count: ", len(data.Txs)) fmt.Println("slot", slot, "tx count: ", len(data.Txs))

View File

@@ -2,7 +2,6 @@ package pump_parser
import ( import (
"errors" "errors"
"log"
"slices" "slices"
"github.com/gagliardetto/solana-go" "github.com/gagliardetto/solana-go"
@@ -14,6 +13,11 @@ var defaultSwapPrograms = map[solana.PublicKey]swapParser{
pumpProgram: pumpParser, pumpProgram: pumpParser,
} }
var errTxParserPrograms = map[solana.PublicKey]swapParser{
pumpAmmProgram: pumpAmmParser,
pumpProgram: pumpParser,
}
var swapPrograms = cloneSwapPrograms(defaultSwapPrograms) var swapPrograms = cloneSwapPrograms(defaultSwapPrograms)
type ParserOption func(*parserConfig) type ParserOption func(*parserConfig)
@@ -97,6 +101,46 @@ func (tx *Tx) Parser() error {
tx.Token = make(map[solana.PublicKey]TokenMeta) tx.Token = make(map[solana.PublicKey]TokenMeta)
if tx.rawTx.Meta.Err != nil {
tx.Err = tx.rawTx.Meta.Err
if tx.Err.UnKnown != "" {
return nil
}
if len(tx.rawTx.Transaction.Message.Instructions) <= int(tx.Err.Index) {
return nil
}
programIdx := tx.rawTx.Transaction.Message.Instructions[tx.Err.Index].ProgramIDIndex
if len(accountList) <= programIdx {
return nil
}
programAccount := accountList[programIdx]
parserFunc, exists := errTxParserPrograms[programAccount]
if !exists {
return nil
}
// parse failed tx
swaps, _, err := parserFunc(tx, tx.rawTx.Transaction.Message.Instructions[tx.Err.Index], InnerInstructions{}, [2]uint{uint(tx.Err.Index), uint(0)})
if err != nil {
return nil
//fmt.Printf("parser failed tx error: %s, block: %d tx: %s\n", err, tx.Block, tx.GetTxHash())
}
if len(swaps) > 0 {
tx.Swaps = swaps
}
for i, instr := range tx.rawTx.Transaction.Message.Instructions {
if p, exists := actionPrograms[accountList[instr.ProgramIDIndex]]; exists {
_, err := p(tx, instr, InnerInstructions{}, [2]uint{uint(i), uint(0)})
if err != nil {
if errors.Is(err, InstructionIgnoredError) {
continue
}
continue
}
}
}
return nil
}
var innersMap = make(map[int]InnerInstructions) var innersMap = make(map[int]InnerInstructions)
for _, inner := range tx.rawTx.Meta.InnerInstructions { for _, inner := range tx.rawTx.Meta.InnerInstructions {
innersMap[inner.Index] = inner innersMap[inner.Index] = inner
@@ -144,7 +188,7 @@ func (tx *Tx) Parser() error {
innerLength := len(innersMap[i].Instructions) innerLength := len(innersMap[i].Instructions)
for j := 1; j <= innerLength; { for j := 1; j <= innerLength; {
if j <= 0 || j > innerLength { if j <= 0 || j > innerLength {
log.Printf("inner instruction index is out if range, block: %d, tx: %s, outerIndex: %d, innerIndex: %d", tx.Block, tx.GetTxHash(), ii, j) //log.Printf("inner instruction index is out if range, block: %d, tx: %s, outerIndex: %d, innerIndex: %d", tx.Block, tx.GetTxHash(), ii, j)
break break
} }
innerInstr := innersMap[i].Instructions[j-1] innerInstr := innersMap[i].Instructions[j-1]
@@ -177,8 +221,13 @@ func (tx *Tx) Parser() error {
tx.Swaps = append(tx.Swaps, swap) tx.Swaps = append(tx.Swaps, swap)
} }
// tx.Swaps = append(tx.Swaps, swaps...) // tx.Swaps = append(tx.Swaps, swaps...)
j = int(offset[1]) if ii == int(offset[0]) && j == int(offset[1]) {
ii = int(offset[0]) j = j + 1
} else {
j = int(offset[1])
ii = int(offset[0])
}
} else if p, exists := actionPrograms[innerProgramAccount]; exists { } else if p, exists := actionPrograms[innerProgramAccount]; exists {
offset, err := p(tx, innerInstr, innersMap[i], [2]uint{uint(i), uint(j)}) offset, err := p(tx, innerInstr, innersMap[i], [2]uint{uint(i), uint(j)})
if err != nil { if err != nil {

129
pump.go
View File

@@ -34,10 +34,19 @@ func pumpParser(tx *Tx, instruction Instruction, innerInstructions InnerInstruct
switch discriminator { switch discriminator {
case pumpBuyV2Discriminator, pumpBuyDiscriminator, pumpSellDiscriminator: case pumpBuyV2Discriminator, pumpBuyDiscriminator, pumpSellDiscriminator:
if tx.Err != nil {
return failedTxBuyOrSellParser(tx, instruction, innerInstructions, offset)
}
return BuyOrSellParser(tx, instruction, innerInstructions, offset) return BuyOrSellParser(tx, instruction, innerInstructions, offset)
case pumpCreateDiscriminator, pumpCreateV2Discriminator: case pumpCreateDiscriminator, pumpCreateV2Discriminator:
if tx.Err != nil {
return nil, increaseOffset(offset), InstructionIgnoredError
}
return CreateParser(tx, instruction, innerInstructions, offset) return CreateParser(tx, instruction, innerInstructions, offset)
case pumpMigrateDiscriminator: case pumpMigrateDiscriminator:
if tx.Err != nil {
return nil, increaseOffset(offset), InstructionIgnoredError
}
return MigrateParser(tx, instruction, innerInstructions, offset) return MigrateParser(tx, instruction, innerInstructions, offset)
default: default:
return nil, increaseOffset(offset), InstructionIgnoredError return nil, increaseOffset(offset), InstructionIgnoredError
@@ -79,6 +88,7 @@ type PumpCreateEvent struct {
TokenTotalSupply uint64 TokenTotalSupply uint64
TokenProgram solana.PublicKey TokenProgram solana.PublicKey
IsMayhemMode bool IsMayhemMode bool
IsCashbackEnabled bool
} }
func CreateParser(tx *Tx, instr Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) { func CreateParser(tx *Tx, instr Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) {
@@ -148,6 +158,7 @@ func CreateParser(tx *Tx, instr Instruction, innerInstructions InnerInstructions
BaseReserve: decimal.NewFromUint64(createEvent.RealTokenReserves), BaseReserve: decimal.NewFromUint64(createEvent.RealTokenReserves),
QuoteReserve: decimal.Zero, QuoteReserve: decimal.Zero,
Mayhem: createEvent.IsMayhemMode, Mayhem: createEvent.IsMayhemMode,
Cashback: createEvent.IsCashbackEnabled,
UserBaseBalance: userBase, UserBaseBalance: userBase,
UserQuoteBalance: decimal.NewFromUint64(userQuote), UserQuoteBalance: decimal.NewFromUint64(userQuote),
EntryContract: entryContract, EntryContract: entryContract,
@@ -176,6 +187,16 @@ type PumpTradeEvent struct {
CreatorFeeBasisPoints uint64 CreatorFeeBasisPoints uint64
CreatorFee uint64 CreatorFee uint64
TrackVolume bool
TotalUnclaimedTokens uint64
TotalClaimedTokens uint64
CurrentSolVolume uint64
LastUpdateTimestamp int64
IxName string
MayhemMode bool
CashbackFeeBasisPoints uint64
Cashback uint64
} }
type PumpTradeFeeArg struct { type PumpTradeFeeArg struct {
@@ -191,6 +212,112 @@ type CompleteEvent struct {
Timestamp int64 Timestamp int64
} }
type PumpTradeArgs struct {
Discriminator [8]byte
Amount1 uint64
Amount2 uint64
}
func failedTxBuyOrSellParser(tx *Tx, instruction Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) {
if tx.Err == nil || tx.Err.UnKnown != "" {
return nil, increaseOffset(offset), fmt.Errorf("tx pump failed but error is nil, offset, %d, %d", offset[0], offset[1])
}
if tx.Err.Variant != InstructionError {
return nil, increaseOffset(offset), fmt.Errorf("failed tx pump failed but error variant is not instruction error, offset, %d, %d", offset[0], offset[1])
}
if tx.Err.Enum != Custom && tx.Err.Enum != ComputationalBudgetExceeded {
return nil, increaseOffset(offset), fmt.Errorf("failed tx pump failed but error is not custom or computational budget exceeded, offset, %d, %d", offset[0], offset[1])
}
if tx.Err.Enum == Custom {
if !(tx.Err.CustomCode == 1 ||
tx.Err.CustomCode == 6042 ||
tx.Err.CustomCode == 6041 ||
tx.Err.CustomCode == 6040 ||
tx.Err.CustomCode == 6023 || tx.Err.CustomCode == 6021 || tx.Err.CustomCode == 6003 || tx.Err.CustomCode == 6002) {
return nil, increaseOffset(offset), fmt.Errorf("failed tx pump failed but custom error code is unexpected, offset, %d, %d, code: %d", offset[0], offset[1], tx.Err.CustomCode)
}
}
result := tx.rawTx
var entryContract = result.accountList[result.Transaction.Message.Instructions[offset[0]].ProgramIDIndex]
user := result.accountList[instruction.Accounts[6]]
ataUserIdx := instruction.Accounts[5]
userIndex := instruction.Accounts[6]
mint := result.accountList[instruction.Accounts[2]]
var args PumpTradeArgs
err := agbinary.NewBorshDecoder(instruction.Data[:]).Decode(&args)
if err != nil {
return nil, increaseOffset(offset), fmt.Errorf("failed tx pump buy/sell decode error: %v, offset, %d, %d", err, offset[0], offset[1])
}
var event string
var (
solAmount, tokenAmount uint64
)
if bytes.Equal(args.Discriminator[:], pumpBuyV2Discriminator[:]) {
event = "buy_failed"
solAmount = args.Amount1
tokenAmount = args.Amount2
} else if bytes.Equal(args.Discriminator[:], pumpBuyDiscriminator[:]) {
event = "buy_failed"
solAmount = args.Amount2
tokenAmount = args.Amount1
} else if bytes.Equal(args.Discriminator[:], pumpSellDiscriminator[:]) {
event = "sell_failed"
solAmount = args.Amount2
tokenAmount = args.Amount1
} else {
return nil, increaseOffset(offset), fmt.Errorf("unknown pump trade instruction discriminator, offset, %d, %d", offset[0], offset[1])
}
var baseTokenProgram solana.PublicKey
if event == "buy_failed" {
baseTokenProgram = result.accountList[instruction.Accounts[8]]
} else {
baseTokenProgram = result.accountList[instruction.Accounts[9]]
}
if !user.IsOnCurve() && (entryContract.Equals(okxDexRoutersV2) || entryContract.Equals(okxAggregatorV2)) {
userBaseAmount, ataIndex := tokenBalanceChange(result, 0, baseTokenProgram, mint)
//&& userBaseAmount.BigInt().Uint64() == tradeEvent.TokenAmount
if !userBaseAmount.IsZero() {
user = result.accountList[0]
userIndex = 0
ataUserIdx = ataIndex
}
}
userBase := getAccountBalanceAfterTx(result, ataUserIdx)
userQuote, _ := GetSolAfterTx(result, userIndex)
bcIdx := instruction.Accounts[3]
bcAtaIndex := instruction.Accounts[4]
solReserves, _ := GetSolAfterTx(result, bcIdx)
tokenReserves := getAccountBalanceAfterTx(result, bcAtaIndex)
swaps := []Swap{
{
Program: SolProgramPump,
Event: event,
Pool: result.accountList[instruction.Accounts[3]],
BaseMint: mint,
QuoteMint: solana.PublicKey{},
BaseTokenProgram: baseTokenProgram,
QuoteTokenProgram: solana.PublicKey{},
BaseMintDecimals: 6,
QuoteMintDecimals: 9,
User: user,
BaseAmount: decimal.NewFromUint64(tokenAmount),
QuoteAmount: decimal.NewFromUint64(solAmount),
BaseReserve: tokenReserves,
QuoteReserve: decimal.NewFromUint64(solReserves),
Mayhem: isMayhemPump(result.accountList[instruction.Accounts[1]]),
UserBaseBalance: userBase,
UserQuoteBalance: decimal.NewFromUint64(userQuote),
EntryContract: entryContract,
},
}
return swaps, offset, nil
}
func BuyOrSellParser(tx *Tx, instruction Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) { func BuyOrSellParser(tx *Tx, instruction Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) {
result := tx.rawTx result := tx.rawTx
var entryContract = result.accountList[result.Transaction.Message.Instructions[offset[0]].ProgramIDIndex] var entryContract = result.accountList[result.Transaction.Message.Instructions[offset[0]].ProgramIDIndex]
@@ -312,6 +439,7 @@ func BuyOrSellParser(tx *Tx, instruction Instruction, innerInstructions InnerIns
solAmount = solAmount - fee solAmount = solAmount - fee
} }
} }
isCashbackCoin := tradeEvent.CashbackFeeBasisPoints > 0 || tradeEvent.Cashback > 0
swaps := []Swap{ swaps := []Swap{
{ {
Program: SolProgramPump, Program: SolProgramPump,
@@ -333,6 +461,7 @@ func BuyOrSellParser(tx *Tx, instruction Instruction, innerInstructions InnerIns
UserBaseBalance: userBase, UserBaseBalance: userBase,
UserQuoteBalance: decimal.NewFromUint64(userQuote), UserQuoteBalance: decimal.NewFromUint64(userQuote),
EntryContract: entryContract, EntryContract: entryContract,
Cashback: isCashbackCoin,
}, },
} }
if completed { if completed {

View File

@@ -41,6 +41,8 @@ type ammBuyEvent struct {
LastUpdateTimestamp int64 LastUpdateTimestamp int64
MinBaseAmountOut uint64 MinBaseAmountOut uint64
IxName string IxName string
CashbackFeeBasisPoints uint64
Cashback uint64
} }
type ammCreatePoolEvent struct { type ammCreatePoolEvent struct {
@@ -113,6 +115,8 @@ type ammSellEvent struct {
CoinCreator solana.PublicKey CoinCreator solana.PublicKey
CoinCreatorFeeBasisPoints uint64 CoinCreatorFeeBasisPoints uint64
CoinCreatorFee uint64 CoinCreatorFee uint64
CashbackFeeBasisPoints uint64
Cashback uint64
} }
type ammWithdrawEvent struct { type ammWithdrawEvent struct {
@@ -148,14 +152,29 @@ func pumpAmmParser(tx *Tx, instruction Instruction, innerInstructions InnerInstr
discriminator := *(*[8]byte)(decode[:8]) discriminator := *(*[8]byte)(decode[:8])
switch discriminator { switch discriminator {
case pumpAmmCreateDiscriminator: case pumpAmmCreateDiscriminator:
if tx.Err != nil {
return nil, increaseOffset(offset), InstructionIgnoredError
}
return ammCreatePoolParser(tx, instruction, innerInstructions, offset) return ammCreatePoolParser(tx, instruction, innerInstructions, offset)
case pumpAmmBuyDiscriminator, pumpAmmBuyV2Discriminator: case pumpAmmBuyDiscriminator, pumpAmmBuyV2Discriminator:
if tx.Err != nil {
return failedTxAmmBuyParser(tx, instruction, innerInstructions, offset)
}
return ammBuyParser(tx, instruction, innerInstructions, offset) return ammBuyParser(tx, instruction, innerInstructions, offset)
case pumpAmmSellDiscriminator: case pumpAmmSellDiscriminator:
if tx.Err != nil {
return failedTxAmmSellParser(tx, instruction, innerInstructions, offset)
}
return ammSellParser(tx, instruction, innerInstructions, offset) return ammSellParser(tx, instruction, innerInstructions, offset)
case pumpAmmDepositDiscriminator: case pumpAmmDepositDiscriminator:
if tx.Err != nil {
return nil, increaseOffset(offset), InstructionIgnoredError
}
return depositParse(tx, instruction, innerInstructions, offset) return depositParse(tx, instruction, innerInstructions, offset)
case pumpAmmWithdrawDiscriminator: case pumpAmmWithdrawDiscriminator:
if tx.Err != nil {
return nil, increaseOffset(offset), InstructionIgnoredError
}
return withdrawParse(tx, instruction, innerInstructions, offset) return withdrawParse(tx, instruction, innerInstructions, offset)
default: default:
return nil, increaseOffset(offset), InstructionIgnoredError return nil, increaseOffset(offset), InstructionIgnoredError
@@ -236,6 +255,254 @@ func ammCreatePoolParser(tx *Tx, instruction Instruction, innerInstructions Inne
} }
type PumpSwapArgs struct {
Discriminator [8]byte
Amount1 uint64
Amount2 uint64
}
func failedTxAmmBuyParser(tx *Tx, instruction Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) {
if tx.Err == nil || tx.Err.UnKnown != "" {
return nil, increaseOffset(offset), fmt.Errorf("tx pump amm sell failed but error is nil, offset, %d, %d", offset[0], offset[1])
}
if tx.Err.Variant != InstructionError {
return nil, increaseOffset(offset), fmt.Errorf("failed tx pump amm sell failed but error variant is not instruction error, offset, %d, %d", offset[0], offset[1])
}
if tx.Err.Enum != Custom && tx.Err.Enum != ComputationalBudgetExceeded {
return nil, increaseOffset(offset), fmt.Errorf("failed tx pump amm sell failed but error is not custom or computational budget exceeded, offset, %d, %d", offset[0], offset[1])
}
if tx.Err.Enum == Custom {
if !(tx.Err.CustomCode == 1 || tx.Err.CustomCode == 6004 ||
tx.Err.CustomCode == 6040 ||
tx.Err.CustomCode == 6039 ||
tx.Err.CustomCode == 6016 ||
tx.Err.CustomCode == 6014) {
return nil, increaseOffset(offset), fmt.Errorf("failed tx pump amm sell failed but custom error code is unexpected, offset, %d, %d, code: %d", offset[0], offset[1], tx.Err.CustomCode)
}
}
result := tx.rawTx
var entryContract = result.accountList[result.Transaction.Message.Instructions[offset[0]].ProgramIDIndex]
var args PumpSwapArgs
err := agbinary.NewBorshDecoder(instruction.Data[:]).Decode(&args)
if err != nil {
return nil, increaseOffset(offset), fmt.Errorf("failed tx pump amm buy failed decode error: %v, offset, %d, %d", err, offset[0], offset[1])
}
var event string
var (
quoteAmount, tokenAmount uint64
)
if bytes.Equal(args.Discriminator[:], pumpAmmBuyV2Discriminator[:]) {
event = "buy_failed"
quoteAmount = args.Amount1
tokenAmount = args.Amount2
} else if bytes.Equal(args.Discriminator[:], pumpAmmBuyDiscriminator[:]) {
event = "buy_failed"
quoteAmount = args.Amount2
tokenAmount = args.Amount1
} else {
return nil, increaseOffset(offset), fmt.Errorf("unknown pump amm trade instruction discriminator, offset, %d, %d", offset[0], offset[1])
}
baseMint := result.accountList[instruction.Accounts[3]]
quoteMint := result.accountList[instruction.Accounts[4]]
baseTokenProgram := result.accountList[instruction.Accounts[11]]
quoteTokenProgram := result.accountList[instruction.Accounts[12]]
poolBaseAccountIdx := instruction.Accounts[7]
poolQuoteAccountIdx := instruction.Accounts[8]
var (
baseMintDecimals uint8
quoteMintDecimals uint8
)
for _, meta := range result.Meta.PostTokenBalances {
if meta.AccountIndex == poolBaseAccountIdx {
baseMintDecimals = uint8(meta.UITokenAmount.Decimals)
} else if meta.AccountIndex == poolQuoteAccountIdx {
quoteMintDecimals = uint8(meta.UITokenAmount.Decimals)
}
}
if _, exists := tx.Token[baseMint]; !exists && !baseMint.Equals(wSolMint) {
tx.Token[baseMint] = TokenMeta{
Mint: baseMint,
Decimals: baseMintDecimals,
TokenProgram: baseTokenProgram,
}
}
if _, exists := tx.Token[quoteMint]; !exists && !quoteMint.Equals(wSolMint) {
tx.Token[quoteMint] = TokenMeta{
Mint: quoteMint,
Decimals: quoteMintDecimals,
TokenProgram: quoteTokenProgram,
}
}
var eventUser = tx.rawTx.accountList[instruction.Accounts[1]]
baseMintAtaUserIdx := instruction.Accounts[5]
userIndex := instruction.Accounts[1]
if !eventUser.IsOnCurve() && (entryContract.Equals(okxDexRoutersV2) || entryContract.Equals(okxAggregatorV2)) {
userBaseAmount, ataIndex := tokenBalanceChange(result, 0, baseTokenProgram, baseMint)
// && userBaseAmount.BigInt().Uint64() == event.BaseAmountOut
if !userBaseAmount.IsZero() {
eventUser = result.accountList[0]
userIndex = 0
baseMintAtaUserIdx = ataIndex
}
}
userBase := getAccountBalanceAfterTx(result, baseMintAtaUserIdx)
userQuote := GetTokenBalanceAfterTx(result, userIndex, quoteTokenProgram, quoteMint)
if quoteMint.Equals(wSolMint) {
userBalance, _ := GetSolAfterTx(result, userIndex)
userQuote = userQuote.Add(decimal.NewFromUint64(userBalance))
}
baseReserve := getAccountBalanceAfterTx(result, instruction.Accounts[7])
quoteReserve := getAccountBalanceAfterTx(result, instruction.Accounts[8])
return []Swap{
{
Program: SolProgramPumpAMM,
Event: event,
Pool: tx.rawTx.accountList[instruction.Accounts[0]],
BaseMint: baseMint,
QuoteMint: quoteMint,
BaseTokenProgram: baseTokenProgram,
QuoteTokenProgram: quoteTokenProgram,
BaseMintDecimals: baseMintDecimals,
QuoteMintDecimals: quoteMintDecimals,
User: eventUser,
BaseAmount: decimal.NewFromUint64(tokenAmount),
QuoteAmount: decimal.NewFromUint64(quoteAmount),
BaseReserve: baseReserve,
QuoteReserve: quoteReserve,
Mayhem: isMayhemPump(result.accountList[instruction.Accounts[9]]),
UserBaseBalance: userBase,
UserQuoteBalance: userQuote,
EntryContract: entryContract,
},
}, offset, nil
}
func failedTxAmmSellParser(tx *Tx, instruction Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) {
if tx.Err == nil || tx.Err.UnKnown != "" {
return nil, increaseOffset(offset), fmt.Errorf("tx pump amm sell failed but error is nil, offset, %d, %d", offset[0], offset[1])
}
if tx.Err.Variant != InstructionError {
return nil, increaseOffset(offset), fmt.Errorf("failed tx pump amm sell failed but error variant is not instruction error, offset, %d, %d", offset[0], offset[1])
}
if tx.Err.Enum != Custom && tx.Err.Enum != ComputationalBudgetExceeded {
return nil, increaseOffset(offset), fmt.Errorf("failed tx pump amm sell failed but error is not custom or computational budget exceeded, offset, %d, %d", offset[0], offset[1])
}
if tx.Err.Enum == Custom {
if !(tx.Err.CustomCode == 1 || tx.Err.CustomCode == 6004 ||
tx.Err.CustomCode == 6040 ||
tx.Err.CustomCode == 6039 ||
tx.Err.CustomCode == 6016 ||
tx.Err.CustomCode == 6014) {
return nil, increaseOffset(offset), fmt.Errorf("failed tx pump amm sell failed but custom error code is unexpected, offset, %d, %d, code: %d", offset[0], offset[1], tx.Err.CustomCode)
}
}
result := tx.rawTx
var entryContract = result.accountList[result.Transaction.Message.Instructions[offset[0]].ProgramIDIndex]
var args PumpSwapArgs
err := agbinary.NewBorshDecoder(instruction.Data[:]).Decode(&args)
if err != nil {
return nil, increaseOffset(offset), fmt.Errorf("failed tx pump amm buy failed decode error: %v, offset, %d, %d", err, offset[0], offset[1])
}
var event string
var (
quoteAmount, tokenAmount uint64
)
if bytes.Equal(args.Discriminator[:], pumpAmmSellDiscriminator[:]) {
event = "sell_failed"
tokenAmount = args.Amount1
quoteAmount = args.Amount2
} else {
return nil, increaseOffset(offset), fmt.Errorf("unknown pump amm trade instruction discriminator, offset, %d, %d", offset[0], offset[1])
}
baseMint := result.accountList[instruction.Accounts[3]]
quoteMint := result.accountList[instruction.Accounts[4]]
baseTokenProgram := result.accountList[instruction.Accounts[11]]
quoteTokenProgram := result.accountList[instruction.Accounts[12]]
poolBaseAccountIdx := instruction.Accounts[7]
poolQuoteAccountIdx := instruction.Accounts[8]
var (
baseMintDecimals uint8
quoteMintDecimals uint8
)
for _, meta := range result.Meta.PostTokenBalances {
if meta.AccountIndex == poolBaseAccountIdx {
baseMintDecimals = uint8(meta.UITokenAmount.Decimals)
} else if meta.AccountIndex == poolQuoteAccountIdx {
quoteMintDecimals = uint8(meta.UITokenAmount.Decimals)
}
}
if _, exists := tx.Token[baseMint]; !exists && !baseMint.Equals(wSolMint) {
tx.Token[baseMint] = TokenMeta{
Mint: baseMint,
Decimals: baseMintDecimals,
TokenProgram: baseTokenProgram,
}
}
if _, exists := tx.Token[quoteMint]; !exists && !quoteMint.Equals(wSolMint) {
tx.Token[quoteMint] = TokenMeta{
Mint: quoteMint,
Decimals: quoteMintDecimals,
TokenProgram: quoteTokenProgram,
}
}
var eventUser = tx.rawTx.accountList[instruction.Accounts[1]]
baseMintAtaUserIdx := instruction.Accounts[5]
userIndex := instruction.Accounts[1]
if !eventUser.IsOnCurve() && (entryContract.Equals(okxDexRoutersV2) || entryContract.Equals(okxAggregatorV2)) {
userBaseAmount, ataIndex := tokenBalanceChange(result, 0, baseTokenProgram, baseMint)
// && userBaseAmount.BigInt().Uint64() == event.BaseAmountIn
if !userBaseAmount.IsZero() {
eventUser = result.accountList[0]
userIndex = 0
baseMintAtaUserIdx = ataIndex
}
}
userBase := getAccountBalanceAfterTx(result, baseMintAtaUserIdx)
userQuote := GetTokenBalanceAfterTx(result, userIndex, quoteTokenProgram, quoteMint)
if quoteMint.Equals(wSolMint) {
userBalance, _ := GetSolAfterTx(result, userIndex)
userQuote = userQuote.Add(decimal.NewFromUint64(userBalance))
}
baseReserve := getAccountBalanceAfterTx(result, instruction.Accounts[7])
quoteReserve := getAccountBalanceAfterTx(result, instruction.Accounts[8])
return []Swap{
{
Program: SolProgramPumpAMM,
Event: event,
Pool: tx.rawTx.accountList[instruction.Accounts[0]],
BaseMint: baseMint,
QuoteMint: quoteMint,
BaseTokenProgram: baseTokenProgram,
QuoteTokenProgram: quoteTokenProgram,
BaseMintDecimals: baseMintDecimals,
QuoteMintDecimals: quoteMintDecimals,
User: eventUser,
BaseAmount: decimal.NewFromUint64(tokenAmount),
QuoteAmount: decimal.NewFromUint64(quoteAmount),
BaseReserve: baseReserve,
QuoteReserve: quoteReserve,
Mayhem: isMayhemPump(result.accountList[instruction.Accounts[9]]),
UserBaseBalance: userBase,
UserQuoteBalance: userQuote,
EntryContract: entryContract,
},
}, offset, nil
}
func ammBuyParser(tx *Tx, instruction Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) { func ammBuyParser(tx *Tx, instruction Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) {
result := tx.rawTx result := tx.rawTx
var entryContract = result.accountList[result.Transaction.Message.Instructions[offset[0]].ProgramIDIndex] var entryContract = result.accountList[result.Transaction.Message.Instructions[offset[0]].ProgramIDIndex]
@@ -329,6 +596,7 @@ func ammBuyParser(tx *Tx, instruction Instruction, innerInstructions InnerInstru
userBalance, _ := GetSolAfterTx(result, userIndex) userBalance, _ := GetSolAfterTx(result, userIndex)
userQuote = userQuote.Add(decimal.NewFromUint64(userBalance)) userQuote = userQuote.Add(decimal.NewFromUint64(userBalance))
} }
isCashbackCoin := event.CashbackFeeBasisPoints > 0 || event.Cashback > 0
return []Swap{ return []Swap{
{ {
Program: SolProgramPumpAMM, Program: SolProgramPumpAMM,
@@ -347,6 +615,7 @@ func ammBuyParser(tx *Tx, instruction Instruction, innerInstructions InnerInstru
BaseReserve: decimal.NewFromUint64(event.PoolBaseTokenReserve - event.BaseAmountOut), BaseReserve: decimal.NewFromUint64(event.PoolBaseTokenReserve - event.BaseAmountOut),
QuoteReserve: decimal.NewFromUint64(event.PoolQuoteTokenReserve + event.QuoteAmountIn), QuoteReserve: decimal.NewFromUint64(event.PoolQuoteTokenReserve + event.QuoteAmountIn),
Mayhem: isMayhemPump(result.accountList[instruction.Accounts[9]]), Mayhem: isMayhemPump(result.accountList[instruction.Accounts[9]]),
Cashback: isCashbackCoin,
UserBaseBalance: userBase, UserBaseBalance: userBase,
UserQuoteBalance: userQuote, UserQuoteBalance: userQuote,
EntryContract: entryContract, EntryContract: entryContract,
@@ -448,6 +717,7 @@ func ammSellParser(tx *Tx, instruction Instruction, innerInstructions InnerInstr
userBalance, _ := GetSolAfterTx(result, userIndex) userBalance, _ := GetSolAfterTx(result, userIndex)
userQuote = userQuote.Add(decimal.NewFromUint64(userBalance)) userQuote = userQuote.Add(decimal.NewFromUint64(userBalance))
} }
isCashbackCoin := event.CashbackFeeBasisPoints > 0 || event.Cashback > 0
return []Swap{ return []Swap{
{ {
Program: SolProgramPumpAMM, Program: SolProgramPumpAMM,
@@ -466,6 +736,7 @@ func ammSellParser(tx *Tx, instruction Instruction, innerInstructions InnerInstr
BaseReserve: decimal.NewFromUint64(event.PoolBaseTokenReserves + event.BaseAmountIn), BaseReserve: decimal.NewFromUint64(event.PoolBaseTokenReserves + event.BaseAmountIn),
QuoteReserve: decimal.NewFromUint64(event.PoolQuoteTokenReserves - event.QuoteAmountOut), QuoteReserve: decimal.NewFromUint64(event.PoolQuoteTokenReserves - event.QuoteAmountOut),
Mayhem: isMayhemPump(result.accountList[instruction.Accounts[9]]), Mayhem: isMayhemPump(result.accountList[instruction.Accounts[9]]),
Cashback: isCashbackCoin,
UserBaseBalance: userBase, UserBaseBalance: userBase,
UserQuoteBalance: userQuote, UserQuoteBalance: userQuote,
EntryContract: entryContract, EntryContract: entryContract,

106
rawtx.go
View File

@@ -73,6 +73,10 @@ func (tx *RawTx) GetAccountLust() []solana.PublicKey {
return tx.getAccountList() return tx.getAccountList()
} }
func (tx *RawTx) GetAccountList() []solana.PublicKey {
return tx.getAccountList()
}
func (tx *RawTx) TxHash() string { func (tx *RawTx) TxHash() string {
if len(tx.Transaction.Signatures) > 0 { if len(tx.Transaction.Signatures) > 0 {
return tx.Transaction.Signatures[0].String() return tx.Transaction.Signatures[0].String()
@@ -146,17 +150,17 @@ func (tb *TokenBalance) ParseAccount() {
} }
type Meta struct { type Meta struct {
Err interface{} `json:"err"` Err *TransactionParsedError `json:"err"`
Fee uint64 `json:"fee"` Fee uint64 `json:"fee"`
InnerInstructions []InnerInstructions `json:"innerInstructions"` InnerInstructions []InnerInstructions `json:"innerInstructions"`
LoadedAddresses LoadedAddresses `json:"loadedAddresses"` LoadedAddresses LoadedAddresses `json:"loadedAddresses"`
LogMessages []string `json:"logMessages"` LogMessages []string `json:"logMessages"`
PostBalances []uint64 `json:"postBalances"` PostBalances []uint64 `json:"postBalances"`
PostTokenBalances []TokenBalance `json:"postTokenBalances"` PostTokenBalances []TokenBalance `json:"postTokenBalances"`
PreBalances []uint64 `json:"preBalances"` PreBalances []uint64 `json:"preBalances"`
PreTokenBalances []TokenBalance `json:"preTokenBalances"` PreTokenBalances []TokenBalance `json:"preTokenBalances"`
Rewards []interface{} `json:"rewards"` Rewards []interface{} `json:"rewards"`
ComputeUnitsConsumed uint64 `json:"computeUnitsConsumed"` ComputeUnitsConsumed uint64 `json:"computeUnitsConsumed"`
} }
type Header struct { type Header struct {
NumReadonlySignedAccounts int `json:"numReadonlySignedAccounts"` NumReadonlySignedAccounts int `json:"numReadonlySignedAccounts"`
@@ -294,6 +298,16 @@ func InstructionsFromRpc(instructions []solana.CompiledInstruction) []Instructio
return instrs return instrs
} }
type RpcTransactionErr []interface{}
func marshalRpcTransactionErr(err any) string {
e, _ := json.Marshal(err)
if len(e) == 0 {
return "UnKnown"
}
return string(e)
}
func FromRpcTransactionWithMeta(tx rpc.TransactionWithMeta, blockTime *uint64, slot uint64, index int64) (*RawTx, error) { func FromRpcTransactionWithMeta(tx rpc.TransactionWithMeta, blockTime *uint64, slot uint64, index int64) (*RawTx, error) {
created := int64(0) created := int64(0)
if blockTime != nil { if blockTime != nil {
@@ -321,12 +335,68 @@ func FromRpcTransactionWithMeta(tx rpc.TransactionWithMeta, blockTime *uint64, s
yTx, _ := tx.GetTransaction() yTx, _ := tx.GetTransaction()
if meta.Err != nil { if meta.Err != nil {
e, _ := json.Marshal(meta.Err) if iErr, ok := meta.Err.(map[string]any); ok {
sTx.Meta.Err = string(e) instructionError := iErr["InstructionError"]
if instructionError == nil {
sTx.Meta.Err = &TransactionParsedError{
UnKnown: marshalRpcTransactionErr(meta.Err),
}
} else {
if oErr, ok := instructionError.([]any); ok {
if len(oErr) <= 1 {
sTx.Meta.Err = &TransactionParsedError{
UnKnown: marshalRpcTransactionErr(meta.Err),
}
} else if instrIdx, ok := oErr[0].(float64); ok {
sTx.Meta.Err = &TransactionParsedError{
Index: uint8(instrIdx),
Variant: InstructionError,
}
errDetail, ok := oErr[1].(string)
if ok {
if errDetail == "ComputationalBudgetExceeded" {
sTx.Meta.Err.Enum = ComputationalBudgetExceeded
} else {
sTx.Meta.Err.UnKnown = errDetail
}
} else {
errDetail2, ok := oErr[1].(map[string]any)
if ok && len(errDetail2) > 0 && errDetail2["Custom"] != nil {
custom, ok := errDetail2["Custom"].(float64)
if ok {
sTx.Meta.Err.Enum = Custom
sTx.Meta.Err.CustomCode = uint32(custom)
} else {
sTx.Meta.Err.UnKnown = marshalRpcTransactionErr(meta.Err)
}
} else {
sTx.Meta.Err.UnKnown = marshalRpcTransactionErr(meta.Err)
}
}
} else {
sTx.Meta.Err = &TransactionParsedError{
UnKnown: marshalRpcTransactionErr(meta.Err),
}
}
} else {
sTx.Meta.Err = &TransactionParsedError{
UnKnown: marshalRpcTransactionErr(meta.Err),
}
}
}
} else {
sTx.Meta.Err = &TransactionParsedError{
UnKnown: marshalRpcTransactionErr(meta.Err),
}
}
} }
sTx.Meta.Fee = meta.Fee sTx.Meta.Fee = meta.Fee
//sTx.Meta.InnerInstructions = meta.InnerInstructions //sTx.Meta.InnerInstructions = meta.InnerInstructions
if meta.ComputeUnitsConsumed != nil {
sTx.Meta.ComputeUnitsConsumed = *meta.ComputeUnitsConsumed
}
for _, innerInstr := range meta.InnerInstructions { for _, innerInstr := range meta.InnerInstructions {
var instrs []Instruction var instrs []Instruction
for _, instr := range innerInstr.Instructions { for _, instr := range innerInstr.Instructions {
@@ -514,6 +584,7 @@ func intSliceFromUint16Slice(in []uint16) []int {
} }
return out return out
} }
func getAtaIdxByOwner(result *RawTx, owner solana.PublicKey, mint solana.PublicKey) (int, error) { func getAtaIdxByOwner(result *RawTx, owner solana.PublicKey, mint solana.PublicKey) (int, error) {
var preBalance *TokenBalance var preBalance *TokenBalance
for _, pre := range result.Meta.PreTokenBalances { for _, pre := range result.Meta.PreTokenBalances {
@@ -796,12 +867,7 @@ func ConvertYellowstoneGrpcTransactionToSolanaTransaction(y *pb.SubscribeUpdateT
if meta.Err != nil && len(meta.Err.GetErr()) > 0 { if meta.Err != nil && len(meta.Err.GetErr()) > 0 {
// If the transaction has an error, we set the error in the Meta // If the transaction has an error, we set the error in the Meta
transError, err := DecodeTransactionError(meta.Err.GetErr()) sTx.Meta.Err = ParseTransactionErrorFromGeyser(meta.Err.GetErr())
if err != nil {
sTx.Meta.Err = err
} else {
sTx.Meta.Err = transError
}
// sTx.Meta.Err = meta.Err.GetErr() // sTx.Meta.Err = meta.Err.GetErr()
} }
sTx.Meta.Fee = meta.Fee sTx.Meta.Fee = meta.Fee

15
tx.go
View File

@@ -31,6 +31,7 @@ type Swap struct {
BaseReserve decimal.Decimal BaseReserve decimal.Decimal
QuoteReserve decimal.Decimal QuoteReserve decimal.Decimal
Mayhem bool Mayhem bool
Cashback bool
UserBaseBalance decimal.Decimal UserBaseBalance decimal.Decimal
UserQuoteBalance decimal.Decimal UserQuoteBalance decimal.Decimal
@@ -78,13 +79,13 @@ type Tx struct {
rawTx *RawTx rawTx *RawTx
Vote bool Vote bool
Signer solana.PublicKey Signer solana.PublicKey
Err interface{} `json:"err,omitempty"` Err *TransactionParsedError `json:"err,omitempty"`
Swaps []Swap `json:"swaps,omitempty"` Swaps []Swap `json:"swaps,omitempty"`
SolTransfer []SolTransfer `json:"sol_transfer,omitempty"` SolTransfer []SolTransfer `json:"sol_transfer,omitempty"`
Block uint64 `json:"block"` Block uint64 `json:"block"`
BlockIndex uint64 `json:"index"` BlockIndex uint64 `json:"index"`
TxHash *[64]byte `json:"-"` TxHash *[64]byte `json:"-"`
BlockAt int64 `json:"block_at"` BlockAt int64 `json:"block_at"`
CuFee decimal.Decimal `json:"cu_fee"` CuFee decimal.Decimal `json:"cu_fee"`