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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | 1x 1x 1x 1x 1x | import { TransactionAdapter } from '../../transaction-adapter';
import {
ClassifiedInstruction,
DexInfo,
RaydiumLCPEvent,
RaydiumLCPTradeEvent,
TradeDirection,
TradeInfo,
TransferData,
} from '../../types';
import { BaseParser } from '../base-parser';
import { RaydiumLaunchpadEventParser } from './parser-raydium-launchpad-event';
import { getRaydiumTradeInfo } from './util';
export class RaydiumLaunchpadParser extends BaseParser {
private eventParser: RaydiumLaunchpadEventParser;
constructor(
adapter: TransactionAdapter,
dexInfo: DexInfo,
transferActions: Record<string, TransferData[]>,
classifiedInstructions: ClassifiedInstruction[]
) {
super(adapter, dexInfo, transferActions, classifiedInstructions);
this.eventParser = new RaydiumLaunchpadEventParser(adapter);
}
public processTrades(): TradeInfo[] {
const events = this.eventParser
.parseInstructions(this.classifiedInstructions)
.filter((event) => event.type === 'TRADE');
return events.map((event) => this.createTradeInfo(event));
}
private createTradeInfo(data: RaydiumLCPEvent): TradeInfo {
const event = data.data as RaydiumLCPTradeEvent;
const isBuy = event.tradeDirection == TradeDirection.Buy;
const [inputToken, inputDecimal, outputToken, outputDecimal] = isBuy
? [
event.quoteMint,
this.adapter.splDecimalsMap.get(event.quoteMint),
event.baseMint,
this.adapter.splDecimalsMap.get(event.baseMint),
]
: [
event.baseMint,
this.adapter.splDecimalsMap.get(event.baseMint),
event.quoteMint,
this.adapter.splDecimalsMap.get(event.quoteMint),
];
Iif (!inputToken || !outputToken) throw new Error('Token not found');
const trade = getRaydiumTradeInfo(
event,
{ mint: inputToken, decimals: inputDecimal! },
{ mint: outputToken, decimals: outputDecimal! },
{
slot: data.slot,
signature: data.signature,
timestamp: data.timestamp,
idx: data.idx,
dexInfo: this.dexInfo,
}
);
return this.utils.attachTokenTransferInfo(trade, this.transferActions);
}
}
|