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 44 45 46 47 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 1x 3x 7x 3x 1x | import { DISCRIMINATORS } from '../constants';
import { TradeInfo } from '../types';
import { getInstructionData, getProgramName } from '../utils';
import { BaseParser } from './base-parser';
export class RaydiumParser extends BaseParser {
public processTrades(): TradeInfo[] {
const trades: TradeInfo[] = [];
console.log('<<<', this.classifiedInstructions)
this.classifiedInstructions.forEach(({ instruction, programId, outerIndex, innerIndex }) => {
if (this.notLiquidityEvent(instruction)) {
const transfers = this.getTransfersForInstruction(programId, outerIndex, innerIndex);
console.log(transfers);
if (transfers.length >= 2) {
const trade = this.utils.processSwapData(transfers.slice(0, 2), {
...this.dexInfo,
amm: this.dexInfo.amm || getProgramName(programId),
});
if (trade) {
if (transfers.length > 2) {
trade.fee = this.utils.getTransferTokenInfo(transfers[2]) ?? undefined;
}
trades.push(trade);
}
}
}
});
return trades;
}
private notLiquidityEvent(instruction: any): boolean {
if (instruction.data) {
const data = getInstructionData(instruction);
const a = Object.values(DISCRIMINATORS.RAYDIUM).some((it) => data.slice(0, 1).equals(it));
const b = Object.values(DISCRIMINATORS.RAYDIUM_CL)
.flatMap((it) => Object.values(it))
.some((it) => data.slice(0, 8).equals(it));
const c = Object.values(DISCRIMINATORS.RAYDIUM_CPMM).some((it) => data.slice(0, 8).equals(it));
return !a && !b && !c;
}
return true;
}
} |