all parser

This commit is contained in:
thloyi
2026-02-09 14:46:19 +08:00
parent 5da088ce13
commit 9ece4aebb9
22 changed files with 6720 additions and 174 deletions

View File

@@ -193,7 +193,6 @@ func metaoradlmmParser(tx *Tx, instruction Instruction, innerInstructions InnerI
}
decode := instruction.Data
if len(decode) < 8 {
offset[1] += 1
return nil, increaseOffset(offset), fmt.Errorf("meteora dlmm program instruction data too short, offset, %d, %d", offset[0], offset[1])
}
@@ -255,11 +254,11 @@ func metaoradlmmInitializeParser(tx *Tx, instruction Instruction, innerInstructi
var programIndex = instruction.ProgramIDIndex
for innerIndex, innerInstr := range inners {
if innerInstr.ProgramIDIndex == programIndex && bytes.Equal(innerInstr.Data[:8], pumpEventDiscriminator[:]) && bytes.Equal(innerInstr.Data[8:16], meteoraInitializeLbPairEventDiscriminator[:]) {
if innerInstr.ProgramIDIndex == programIndex && len(innerInstr.Data) >= 16 && bytes.Equal(innerInstr.Data[:8], pumpEventDiscriminator[:]) && bytes.Equal(innerInstr.Data[8:16], meteoraInitializeLbPairEventDiscriminator[:]) {
if offset[1] == 0 {
offset[0] += 1
} else {
offset[1] += uint(innerIndex) + 1 + prefixLen
offset[1] = uint(innerIndex) + 1 + prefixLen
}
break
}
@@ -281,7 +280,6 @@ func metaoradlmmSwapParser(tx *Tx, instruction Instruction, innerInstructions In
decode := instruction.Data
if len(decode) < 8 {
offset[1] += 1
return nil, increaseOffset(offset), fmt.Errorf("meteora dlmm swap instruction data too short, offset, %d, %d", offset[0], offset[1])
}
@@ -321,11 +319,31 @@ func metaoradlmmSwapParser(tx *Tx, instruction Instruction, innerInstructions In
tokenXProgram := result.accountList[accounts.tokenXProgramIdx]
tokenYProgram := result.accountList[accounts.tokenYProgramIdx]
swapEvent, nextOffset, err := dlmmSwapEventFromInnerInstructions(innerInstructions, instruction, offset)
var prefixLen = offset[1]
var swapEvent dlmmSwapEvent
inners, err := getInnerInstructions(innerInstructions, prefixLen)
if err != nil {
return nil, nextOffset, err
return nil, increaseOffset(offset), fmt.Errorf("meteora dlmm swap get inner instructions error: %v, offset, %d, %d", err, offset[0], prefixLen)
}
for innerIndex, innerInstr := range inners {
if innerInstr.ProgramIDIndex != instruction.ProgramIDIndex {
continue
}
if len(innerInstr.Data) < 16 || !bytes.Equal(innerInstr.Data[:8], eventDiscriminator[:]) || !bytes.Equal(innerInstr.Data[8:16], meteoraDlmmSwapEventDiscriminator[:]) {
continue
}
if offset[1] == 0 {
offset[0] += 1
} else {
offset[1] = uint(innerIndex) + 1 + prefixLen
}
if err := agbinary.NewBorshDecoder(innerInstr.Data[16:]).Decode(&swapEvent); err != nil {
return nil, offset, fmt.Errorf("meteora dlmm swap event decode error: %v, offset, %d, %d", err, offset[0], offset[1])
}
break
}
offset = nextOffset
baseMint, quoteMint, baseIsX := dlmmSelectBaseQuote(tokenXMint, tokenYMint)
baseTokenProgram := tokenXProgram
@@ -818,30 +836,6 @@ func dlmmSelectBaseQuote(tokenX, tokenY solana.PublicKey) (baseMint solana.Publi
return tokenX, tokenY, true
}
func dlmmSwapEventFromInnerInstructions(innerInstructions InnerInstructions, instruction Instruction, offset [2]uint) (dlmmSwapEvent, [2]uint, error) {
var prefixLen = offset[1]
inners, err := getInnerInstructions(innerInstructions, prefixLen)
if err != nil {
return dlmmSwapEvent{}, increaseOffset(offset), fmt.Errorf("meteora dlmm swap get inner instructions error: %v, offset, %d, %d", err, offset[0], prefixLen)
}
for innerIndex, innerInstr := range inners {
if innerInstr.ProgramIDIndex != instruction.ProgramIDIndex {
continue
}
event, ok := dlmmDecodeSwapEvent(innerInstr.Data)
if !ok {
continue
}
if offset[1] == 0 {
offset[0] += 1
} else {
offset[1] += uint(innerIndex) + 1 + prefixLen
}
return event, offset, nil
}
return dlmmSwapEvent{}, increaseOffset(offset), fmt.Errorf("meteora dlmm swap event not found, offset, %d, %d", offset[0], prefixLen)
}
func dlmmAddLiquidityEventFromInnerInstructions(innerInstructions InnerInstructions, instruction Instruction, offset [2]uint) (dlmmAddLiquidityEvent, [2]uint, error) {
var prefixLen = offset[1]
inners, err := getInnerInstructions(innerInstructions, prefixLen)
@@ -859,7 +853,7 @@ func dlmmAddLiquidityEventFromInnerInstructions(innerInstructions InnerInstructi
if offset[1] == 0 {
offset[0] += 1
} else {
offset[1] += uint(innerIndex) + 1 + prefixLen
offset[1] = uint(innerIndex) + 1 + prefixLen
}
return event, offset, nil
}
@@ -883,34 +877,13 @@ func dlmmRemoveLiquidityEventFromInnerInstructions(innerInstructions InnerInstru
if offset[1] == 0 {
offset[0] += 1
} else {
offset[1] += uint(innerIndex) + 1 + prefixLen
offset[1] = uint(innerIndex) + 1 + prefixLen
}
return event, offset, nil
}
return dlmmRemoveLiquidityEvent{}, increaseOffset(offset), fmt.Errorf("meteora dlmm remove liquidity event not found, offset, %d, %d", offset[0], prefixLen)
}
func dlmmDecodeSwapEvent(data []byte) (dlmmSwapEvent, bool) {
switch {
case len(data) >= 8 && bytes.Equal(data[:8], meteoraDlmmSwapEventDiscriminator[:]):
var event dlmmSwapEvent
if err := agbinary.NewBorshDecoder(data[8:]).Decode(&event); err != nil {
return dlmmSwapEvent{}, false
}
return event, true
case len(data) >= 16 &&
bytes.Equal(data[:8], eventDiscriminator[:]) &&
bytes.Equal(data[8:16], meteoraDlmmSwapEventDiscriminator[:]):
var event dlmmSwapEvent
if err := agbinary.NewBorshDecoder(data[16:]).Decode(&event); err != nil {
return dlmmSwapEvent{}, false
}
return event, true
default:
return dlmmSwapEvent{}, false
}
}
func dlmmDecodeAddLiquidityEvent(data []byte) (dlmmAddLiquidityEvent, bool) {
switch {
case len(data) >= 8 && bytes.Equal(data[:8], meteoraDlmmAddLiquidityEventDiscriminator[:]):