All files / src/parsers base-parser.ts

63.63% Statements 7/11
0% Branches 0/4
33.33% Functions 1/3
70% Lines 7/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  1x     1x       1x 1x 1x 1x   1x                      
import { TransactionAdapter } from '../transaction-adapter';
import { TransactionUtils } from '../transaction-utils';
import { ClassifiedInstruction, DexInfo, TradeInfo, TransferData } from '../types';
 
export abstract class BaseParser {
  protected readonly utils: TransactionUtils;
 
  constructor(
    protected readonly adapter: TransactionAdapter,
    protected readonly dexInfo: DexInfo,
    protected readonly transferActions: Record<string, TransferData[]>,
    protected readonly classifiedInstructions: ClassifiedInstruction[]
  ) {
    this.utils = new TransactionUtils(adapter);
  }
 
  abstract processTrades(): TradeInfo[];
 
  protected getTransfersForInstruction(programId: string, outerIndex: number, innerIndex?: number): TransferData[] {
    const key = `${programId}:${outerIndex}${innerIndex == undefined ? '' : `-${innerIndex}`}`;
    const transfers = this.transferActions[key] || [];
    return transfers.filter((t) => ['transfer', 'transferChecked'].includes(t.type));
  }
}