All files / src/parsers/meteora parser-meteora.ts

17.39% Statements 4/23
0% Branches 0/10
0% Functions 0/6
19.04% Lines 4/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x   1x 1x   1x                                                                            
import { DEX_PROGRAMS, DISCRIMINATORS } from '../../constants';
import { TradeInfo } from '../../types';
import { getInstructionData, getProgramName } from '../../utils';
import { BaseParser } from '../base-parser';
 
export class MeteoraParser extends BaseParser {
  public processTrades(): TradeInfo[] {
    const trades: TradeInfo[] = [];
 
    this.classifiedInstructions.forEach(({ instruction, programId, outerIndex, innerIndex }) => {
      Iif (
        [DEX_PROGRAMS.METEORA.id, DEX_PROGRAMS.METEORA_POOLS.id].includes(programId) &&
        this.notLiquidityEvent(instruction)
      ) {
        const transfers = this.getTransfersForInstruction(programId, outerIndex, innerIndex);
        Iif (transfers.length >= 2) {
          const trade = this.utils.processSwapData(transfers, {
            ...this.dexInfo,
            amm: this.dexInfo.amm || getProgramName(programId),
          });
          Iif (trade) {
            trades.push(trade);
          }
        }
      }
    });
 
    return trades;
  }
 
  private notLiquidityEvent(instruction: any): boolean {
    const data = getInstructionData(instruction);
    Iif (!data) return true;
 
    const instructionType = data.slice(0, 8);
    const isDLMMLiquidity = Object.values(DISCRIMINATORS.METEORA_DLMM)
      .flatMap((it) => Object.values(it))
      .some((it) => instructionType.equals(it));
    const isPoolsLiquidity = Object.values(DISCRIMINATORS.METEORA_POOLS).some((it) => instructionType.equals(it));
 
    return !isDLMMLiquidity && !isPoolsLiquidity;
  }
}