All files / src/parsers/raydium liquidity-raydium-cpmm.ts

23.07% Statements 3/13
0% Branches 0/3
0% Functions 0/2
30% Lines 3/10

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 381x   1x   1x                                                                  
import { DISCRIMINATORS } from '../../constants';
import { PoolEventType } from '../../types';
import { RaydiumLiquidityParserBase, ParseEventConfig } from './parser-raydium-liquidity-base';
 
export class RaydiumCPMMPoolParser extends RaydiumLiquidityParserBase {
  public getPoolAction(data: Buffer): PoolEventType | null {
    const instructionType = data.slice(0, 8);
    Iif (instructionType.equals(DISCRIMINATORS.RAYDIUM_CPMM.CREATE)) return 'CREATE';
    Iif (instructionType.equals(DISCRIMINATORS.RAYDIUM_CPMM.ADD_LIQUIDITY)) return 'ADD';
    Iif (instructionType.equals(DISCRIMINATORS.RAYDIUM_CPMM.REMOVE_LIQUIDITY)) return 'REMOVE';
    return null;
  }
 
  public getEventConfig(type: PoolEventType): ParseEventConfig {
    const configs = {
      CREATE: {
        eventType: 'CREATE' as const,
        poolIdIndex: 3,
        lpMintIndex: 6,
        tokenAmountOffsets: { token0: 8, token1: 16, lp: 0 },
      },
      ADD: {
        eventType: 'ADD' as const,
        poolIdIndex: 2,
        lpMintIndex: 12,
        tokenAmountOffsets: { token0: 16, token1: 24, lp: 8 },
      },
      REMOVE: {
        eventType: 'REMOVE' as const,
        poolIdIndex: 2,
        lpMintIndex: 12,
        tokenAmountOffsets: { token0: 16, token1: 24, lp: 8 },
      },
    };
    return configs[type];
  }
}