All files / src/parsers/raydium util.ts

44.44% Statements 4/9
0% Branches 0/14
0% Functions 0/1
37.5% Lines 3/8

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 561x 1x   1x                                                                                                        
import { DEX_PROGRAMS } from '../../constants';
import { convertToUiAmount, DexInfo, RaydiumLCPTradeEvent, TradeDirection, TradeInfo } from '../../types';
 
export const getRaydiumTradeInfo = (
  event: RaydiumLCPTradeEvent,
  inputToken: {
    mint: string;
    decimals: number;
  },
  outputToken: {
    mint: string;
    decimals: number;
  },
  info: {
    slot: number;
    signature: string;
    timestamp: number;
    idx?: string;
    dexInfo?: DexInfo;
  }
): TradeInfo => {
  const { mint: inputMint, decimals: inputDecimal } = inputToken;
  const { mint: outputMint, decimals: ouptDecimal } = outputToken;
  const isBuy = event.tradeDirection === TradeDirection.Buy;
  const fee = BigInt(event.protocolFee) + BigInt(event.platformFee);
  return {
    type: isBuy ? 'BUY' : 'SELL',
    inputToken: {
      mint: inputMint,
      amount: convertToUiAmount(event.amountIn, inputDecimal),
      amountRaw: event.amountIn.toString(),
      decimals: inputDecimal,
    },
    outputToken: {
      mint: outputMint,
      amount: convertToUiAmount(event.amountOut, ouptDecimal),
      amountRaw: event.amountOut.toString(),
      decimals: ouptDecimal,
    },
    fee: {
      mint: isBuy ? inputMint : outputMint,
      amount: convertToUiAmount(fee, isBuy ? inputDecimal : ouptDecimal),
      amountRaw: fee.toString(),
      decimals: isBuy ? inputDecimal : ouptDecimal,
    },
    user: event.user,
    programId: info.dexInfo?.programId || DEX_PROGRAMS.RAYDIUM_LCP.id,
    amm: DEX_PROGRAMS.RAYDIUM_LCP.name,
    route: info.dexInfo?.route || '',
    slot: info.slot,
    timestamp: info.timestamp,
    signature: info.signature,
    idx: info.idx || '',
  };
};