punm parser
This commit is contained in:
57
pump.go
57
pump.go
@@ -19,9 +19,9 @@ func increaseOffset(offset [2]uint) [2]uint {
|
||||
// pumpParser // routes pump program instructions to their respective parsers,
|
||||
// offset is [outerIndex, innerIndex] index of instructions in the transaction,
|
||||
// if innerIndex == 0 this is outer instruction,if it's an inner instruction, outerIndex is the index of the parent instruction.
|
||||
func pumpParser(result *RawTx, instruction Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) {
|
||||
func pumpParser(tx *Tx, instruction Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) {
|
||||
|
||||
if !result.accountList[instruction.ProgramIDIndex].Equals(pumpProgram) {
|
||||
if !tx.rawTx.accountList[instruction.ProgramIDIndex].Equals(pumpProgram) {
|
||||
return nil, increaseOffset(offset), fmt.Errorf("pump program instruction not found, offset, %d, %d", offset[0], offset[1])
|
||||
}
|
||||
|
||||
@@ -35,11 +35,11 @@ func pumpParser(result *RawTx, instruction Instruction, innerInstructions InnerI
|
||||
|
||||
switch discriminator {
|
||||
case pumpBuyV2Discriminator, pumpBuyDiscriminator, pumpSellDiscriminator:
|
||||
return BuyOrSellParser(result, instruction, innerInstructions, offset)
|
||||
return BuyOrSellParser(tx, instruction, innerInstructions, offset)
|
||||
case pumpCreateDiscriminator, pumpCreateV2Discriminator:
|
||||
return CreateParser(result, instruction, innerInstructions, offset)
|
||||
return CreateParser(tx, instruction, innerInstructions, offset)
|
||||
case pumpMigrateDiscriminator:
|
||||
return MigrateParser(result, instruction, innerInstructions, offset)
|
||||
return MigrateParser(tx, instruction, innerInstructions, offset)
|
||||
default:
|
||||
return nil, increaseOffset(offset), InstructionIgnoredError
|
||||
}
|
||||
@@ -82,21 +82,8 @@ type PumpCreateEvent struct {
|
||||
IsMayhemMode bool
|
||||
}
|
||||
|
||||
func getInnerInstructions(innerInstructions InnerInstructions, offset uint) ([]Instruction, error) {
|
||||
var inners []Instruction
|
||||
var prefixLen = offset
|
||||
if prefixLen > uint(len(innerInstructions.Instructions)) {
|
||||
return nil, fmt.Errorf("error inner instruction index out of range")
|
||||
}
|
||||
if prefixLen == 0 {
|
||||
inners = innerInstructions.Instructions
|
||||
} else {
|
||||
inners = innerInstructions.Instructions[prefixLen:]
|
||||
}
|
||||
return inners, nil
|
||||
}
|
||||
|
||||
func CreateParser(result *RawTx, 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) {
|
||||
result := tx.rawTx
|
||||
var entryContract = result.accountList[result.Transaction.Message.Instructions[offset[0]].ProgramIDIndex]
|
||||
|
||||
var programIndex = instr.ProgramIDIndex
|
||||
@@ -134,6 +121,16 @@ func CreateParser(result *RawTx, instr Instruction, innerInstructions InnerInstr
|
||||
userBase := getAccountBalanceAfterTx(result, userIndex)
|
||||
userQuote, _ := GetSolAfterTx(result, userIndex)
|
||||
|
||||
totalSupply := decimal.NewFromUint64(createEvent.TokenTotalSupply).Div(decimal.New(1, 6))
|
||||
tx.Token[createEvent.Mint] = TokenMeta{
|
||||
Mint: createEvent.Mint,
|
||||
TokenProgram: createEvent.TokenProgram,
|
||||
Decimals: 6,
|
||||
Name: createEvent.Name,
|
||||
Symbol: createEvent.Symbol,
|
||||
Url: createEvent.Uri,
|
||||
TotalSupply: &totalSupply,
|
||||
}
|
||||
return []Swap{
|
||||
{
|
||||
Program: SolProgramPump,
|
||||
@@ -186,7 +183,8 @@ type CompleteEvent struct {
|
||||
Timestamp int64
|
||||
}
|
||||
|
||||
func BuyOrSellParser(result *RawTx, 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
|
||||
var entryContract = result.accountList[result.Transaction.Message.Instructions[offset[0]].ProgramIDIndex]
|
||||
var err error
|
||||
var programIndex = instruction.ProgramIDIndex
|
||||
@@ -255,6 +253,13 @@ func BuyOrSellParser(result *RawTx, instruction Instruction, innerInstructions I
|
||||
event = "sell"
|
||||
baseTokenProgram = result.accountList[instruction.Accounts[9]]
|
||||
}
|
||||
if _, exists := tx.Token[tradeEvent.Mint]; !exists {
|
||||
tx.Token[tradeEvent.Mint] = TokenMeta{
|
||||
Mint: tradeEvent.Mint,
|
||||
TokenProgram: baseTokenProgram,
|
||||
Decimals: 6,
|
||||
}
|
||||
}
|
||||
swaps := []Swap{
|
||||
{
|
||||
Program: SolProgramPump,
|
||||
@@ -314,7 +319,8 @@ type MigrateEvent struct {
|
||||
Pool solana.PublicKey
|
||||
}
|
||||
|
||||
func MigrateParser(result *RawTx, instr Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) {
|
||||
func MigrateParser(tx *Tx, instr Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) {
|
||||
result := tx.rawTx
|
||||
var entryContract = result.accountList[result.Transaction.Message.Instructions[offset[0]].ProgramIDIndex]
|
||||
var err error
|
||||
programIndex := instr.ProgramIDIndex
|
||||
@@ -389,6 +395,13 @@ func MigrateParser(result *RawTx, instr Instruction, innerInstructions InnerInst
|
||||
}
|
||||
userQuote, _ := GetSolAfterTx(result, userIndex)
|
||||
|
||||
if _, exists := tx.Token[migrateEvent.Mint]; !exists {
|
||||
tx.Token[migrateEvent.Mint] = TokenMeta{
|
||||
Mint: migrateEvent.Mint,
|
||||
TokenProgram: baseTokenProgram,
|
||||
Decimals: 6,
|
||||
}
|
||||
}
|
||||
swaps := []Swap{
|
||||
{
|
||||
Program: SolProgramPump,
|
||||
|
||||
Reference in New Issue
Block a user