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 48 49 50 51 52 53 54 55 56 | 1x 1x 1x 1x | import { DEX_PROGRAMS, DISCRIMINATORS } from '../constants';
import { DexInfo, TradeInfo, TransferData } from '../types';
import { getInstructionData, getProgramName } from '../utils';
import { TransactionAdapter } from '../transaction-adapter';
import { TransactionUtils } from '../transaction-utils';
export class OrcaParser {
private readonly utils: TransactionUtils;
constructor(
private readonly adapter: TransactionAdapter,
private readonly dexInfo: DexInfo,
private readonly transferActions: Record<string, TransferData[]>
) {
this.utils = new TransactionUtils(adapter);
}
public processTrades(): TradeInfo[] {
const trades: TradeInfo[] = [];
Object.entries(this.transferActions).forEach((it) => {
trades.push(...this.parseTransferAction(it));
});
return trades;
}
public parseTransferAction(transfer: [string, TransferData[]]): TradeInfo[] {
const trades: TradeInfo[] = [];
const [programId, idxs] = transfer[0].split(':');
const [outerIndex, innerIndex] = idxs.split('-');
Iif (transfer[1].length >= 2 && DEX_PROGRAMS.ORCA.id == programId) {
const instruction = innerIndex
? this.adapter.getInnerInstruction(Number(outerIndex), Number(innerIndex))
: this.adapter.instructions[Number(outerIndex)];
Iif (this.notLiquidityEvent(instruction)) {
const trade = this.utils.processSwapData(transfer[1], {
...this.dexInfo,
amm: this.dexInfo.amm || getProgramName(programId),
});
Iif (trade) {
trades.push(trade);
}
}
}
return trades;
}
private notLiquidityEvent(instruction: any): boolean {
Iif (instruction.data) {
const instructionType = getInstructionData(instruction).slice(0, 8);
return !Object.values(DISCRIMINATORS.ORCA).some((it) => instructionType.equals(it));
}
return true;
}
}
|