solana-dex-parser
Version:
Solana Dex Transaction Parser
50 lines • 2.56 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PumpswapParser = void 0;
const base_parser_1 = require("../base-parser");
const parser_pumpswap_event_1 = require("./parser-pumpswap-event");
const util_1 = require("./util");
class PumpswapParser extends base_parser_1.BaseParser {
constructor(adapter, dexInfo, transferActions, classifiedInstructions) {
super(adapter, dexInfo, transferActions, classifiedInstructions);
this.eventParser = new parser_pumpswap_event_1.PumpswapEventParser(adapter);
}
processTrades() {
const events = this.eventParser
.parseInstructions(this.classifiedInstructions)
.filter((event) => ['BUY', 'SELL'].includes(event.type));
return events.map((event) => (event.type === 'BUY' ? this.createBuyInfo(event) : this.createSellInfo(event)));
}
createBuyInfo(data) {
const event = data.data;
const inputMint = this.adapter.splTokenMap.get(event.userQuoteTokenAccount).mint;
const inputDecimal = this.adapter.getTokenDecimals(inputMint);
const outputMint = this.adapter.splTokenMap.get(event.userBaseTokenAccount).mint;
const ouptDecimal = this.adapter.getTokenDecimals(outputMint);
const trade = (0, util_1.getPumpswapBuyInfo)(event, { mint: inputMint, decimals: inputDecimal }, { mint: outputMint, decimals: ouptDecimal }, {
slot: data.slot,
signature: data.signature,
timestamp: data.timestamp,
idx: data.idx,
dexInfo: this.dexInfo,
});
return this.utils.attachTokenTransferInfo(trade, this.transferActions);
}
createSellInfo(data) {
const event = data.data;
const inputMint = this.adapter.splTokenMap.get(event.userBaseTokenAccount).mint;
const inputDecimal = this.adapter.getTokenDecimals(inputMint);
const outputMint = this.adapter.splTokenMap.get(event.userQuoteTokenAccount).mint;
const ouptDecimal = this.adapter.getTokenDecimals(outputMint);
const trade = (0, util_1.getPumpswapSellInfo)(event, { mint: inputMint, decimals: inputDecimal }, { mint: outputMint, decimals: ouptDecimal }, {
slot: data.slot,
signature: data.signature,
timestamp: data.timestamp,
idx: data.idx,
dexInfo: this.dexInfo,
});
return this.utils.attachTokenTransferInfo(trade, this.transferActions);
}
}
exports.PumpswapParser = PumpswapParser;
//# sourceMappingURL=parser-pumpswap.js.map