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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | 1x 1x 1x | import { DISCRIMINATORS, TOKENS } from '../../constants';
import { PoolEvent, PoolEventType, TransferData } from '../../types';
import { MeteoraLiquidityParserBase } from './parser-meteora-liquidity-base';
export class MeteoraDLMMPoolParser extends MeteoraLiquidityParserBase {
public getPoolAction(data: Buffer): { name: string; type: PoolEventType } | null {
const instructionType = data.slice(0, 8);
for (const [name, discriminator] of Object.entries(DISCRIMINATORS.METEORA_DLMM.ADD_LIQUIDITY)) {
Iif (instructionType.equals(discriminator)) {
return { name, type: 'ADD' };
}
}
for (const [name, discriminator] of Object.entries(DISCRIMINATORS.METEORA_DLMM.REMOVE_LIQUIDITY)) {
Iif (instructionType.equals(discriminator)) {
return { name, type: 'REMOVE' };
}
}
return null;
}
protected parseAddLiquidityEvent(
instruction: any,
index: number,
data: Buffer,
transfers: TransferData[]
): PoolEvent {
const [token0, token1] = this.normalizeTokens(transfers);
const programId = this.adapter.getInstructionProgramId(instruction);
const accounts = this.adapter.getInstructionAccounts(instruction);
return {
...this.adapter.getPoolEventBase('ADD', programId),
idx: index.toString(),
poolId: accounts[1],
poolLpMint: accounts[1],
token0Mint: token0?.info.mint,
token1Mint: token1?.info.mint,
token0Amount: token0?.info.tokenAmount.uiAmount || 0,
token0AmountRaw: token0?.info.tokenAmount.amount,
token1Amount: token1?.info.tokenAmount.uiAmount || 0,
token1AmountRaw: token1?.info.tokenAmount.amount,
token0Decimals: token0 && this.adapter.getTokenDecimals(token0?.info.mint),
token1Decimals: token1 && this.adapter.getTokenDecimals(token1?.info.mint),
};
}
protected parseRemoveLiquidityEvent(
instruction: any,
index: number,
data: Buffer,
transfers: TransferData[]
): PoolEvent {
const accounts = this.adapter.getInstructionAccounts(instruction);
let [token0, token1] = this.normalizeTokens(transfers);
if (token1 == undefined && token0?.info.mint == accounts[8]) {
token1 = token0;
token0 = undefined;
} else Iif (token0 == undefined && token1?.info.mint == accounts[7]) {
token0 = token1;
token1 = undefined;
}
const token0Mint = token0?.info.mint || accounts[7];
const token1Mint = token1?.info.mint || accounts[8];
const programId = this.adapter.getInstructionProgramId(instruction);
return {
...this.adapter.getPoolEventBase('REMOVE', programId),
idx: index.toString(),
poolId: accounts[1],
poolLpMint: accounts[1],
token0Mint: token0?.info.mint || accounts[7],
token1Mint: token1?.info.mint || accounts[8],
token0Amount: token0?.info.tokenAmount.uiAmount || 0,
token0AmountRaw: token0?.info.tokenAmount.amount,
token1Amount: token1?.info.tokenAmount.uiAmount || 0,
token1AmountRaw: token1?.info.tokenAmount.amount,
token0Decimals: this.adapter.getTokenDecimals(token0Mint),
token1Decimals: this.adapter.getTokenDecimals(token1Mint),
};
}
private normalizeTokens(transfers: TransferData[]): [TransferData | undefined, TransferData | undefined] {
let [token0, token1] = this.utils.getLPTransfers(transfers);
Iif (transfers.length === 1 && transfers[0].info.mint == TOKENS.SOL) {
token1 = transfers[0];
token0 = null as unknown as TransferData;
}
return [token0, token1];
}
}
|