84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
package pump_parser
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
func systemParser(result *RawTx, instr Instruction, innerInstructions InnerInstructions, offset [2]uint, tx *Tx) ([2]uint, error) {
|
|
var instruction Instruction
|
|
|
|
var found bool
|
|
if offset[1] == 0 {
|
|
instruction = result.Transaction.Message.Instructions[offset[0]]
|
|
found = true
|
|
} else {
|
|
for _, innerInstruction := range result.Meta.InnerInstructions {
|
|
if innerInstruction.Index == int(offset[0]) {
|
|
instruction = innerInstruction.Instructions[offset[1]-1]
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
}
|
|
if !found {
|
|
return increaseOffset(offset), fmt.Errorf("system program instruction not found, block: %d, tx: %s, outerIndex: %d, innerIndex: %d", result.Slot, result.TxHash(), offset[0], offset[1])
|
|
}
|
|
|
|
decode := instruction.Data
|
|
discriminator := binary.LittleEndian.Uint32(decode[0:4])
|
|
|
|
switch discriminator {
|
|
case transferDiscriminator:
|
|
return TransferParser(result, instruction, offset, tx, decode[4:])
|
|
default:
|
|
return increaseOffset(offset), nil
|
|
}
|
|
}
|
|
|
|
func TransferParser(result *RawTx, instruction Instruction, offset [2]uint, tx *Tx, decodeData []byte) ([2]uint, error) {
|
|
if len(decodeData) < 8 {
|
|
return increaseOffset(offset), nil
|
|
}
|
|
var lamports uint64 = binary.LittleEndian.Uint64(decodeData)
|
|
|
|
//from := result.accountList[result.Transaction.Message.Instructions[offset[0]].Accounts[0]]
|
|
to := result.accountList[instruction.Accounts[1]]
|
|
|
|
// load platform by to address
|
|
platform, ok := platformFeeAddresses[to]
|
|
if ok {
|
|
if tx.Platform != nil {
|
|
tx.Platform[platform] = platformInfo{
|
|
Platform: platform,
|
|
PlatformFee: decimal.NewFromInt(int64(lamports)).Div(decimal.NewFromInt(1e9)), // solana decimals
|
|
}
|
|
} else {
|
|
tx.Platform = make(map[string]platformInfo)
|
|
tx.Platform[platform] = platformInfo{
|
|
Platform: platform,
|
|
PlatformFee: decimal.NewFromInt(int64(lamports)).Div(decimal.NewFromInt(1e9)), // solana decimals
|
|
}
|
|
}
|
|
|
|
} else if offset[1] == 0 {
|
|
// load mev agent by to address
|
|
mevAgent, ok := mevAgentFeeAddresses[to]
|
|
if !ok {
|
|
// mark it as unknown
|
|
mevAgent = MevAgentUnknown
|
|
}
|
|
if tx.MevAgent == nil {
|
|
tx.MevAgent = make(map[string]mevInfo)
|
|
}
|
|
tx.MevAgent[mevAgent] = mevInfo{
|
|
MevAgent: mevAgent,
|
|
MevAgentFee: decimal.NewFromInt(int64(lamports)).Div(decimal.NewFromInt(1e9)), // solana decimals
|
|
}
|
|
}
|
|
|
|
return increaseOffset(offset), nil
|
|
}
|