|
@@ -2,6 +2,7 @@ import { ParsedTransactionWithMeta, PublicKey } from '@solana/web3.js'
|
|
|
import type { OperationType, ParsedOperation } from './types'
|
|
import type { OperationType, ParsedOperation } from './types'
|
|
|
|
|
|
|
|
const BYREAL_PROGRAM_ID = 'REALQqNEomY6cQGZJUGwywTBD2UmDT32rZcNnfxQ5N2'
|
|
const BYREAL_PROGRAM_ID = 'REALQqNEomY6cQGZJUGwywTBD2UmDT32rZcNnfxQ5N2'
|
|
|
|
|
+const MEMO_PROGRAM_ID = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'
|
|
|
|
|
|
|
|
// Instruction discriminators from byreal_amm_v3.json IDL
|
|
// Instruction discriminators from byreal_amm_v3.json IDL
|
|
|
const DISCRIMINATORS: Record<string, { type: OperationType; bytes: number[] }> = {
|
|
const DISCRIMINATORS: Record<string, { type: OperationType; bytes: number[] }> = {
|
|
@@ -240,6 +241,31 @@ function decodeLiquidityEvent(
|
|
|
return null
|
|
return null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Extract referer_position from memo instruction in the transaction.
|
|
|
|
|
+ * The memo format is: referer_position={pubkey}
|
|
|
|
|
+ */
|
|
|
|
|
+function extractRefererFromMemo(tx: ParsedTransactionWithMeta): string | undefined {
|
|
|
|
|
+ const instructions = tx.transaction.message.instructions
|
|
|
|
|
+ for (const ix of instructions) {
|
|
|
|
|
+ if ('programId' in ix && ix.programId.toBase58() === MEMO_PROGRAM_ID) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ let memoText = ''
|
|
|
|
|
+ if ('data' in ix && typeof ix.data === 'string') {
|
|
|
|
|
+ memoText = Buffer.from(ix.data, 'base64').toString('utf-8')
|
|
|
|
|
+ } else if ('parsed' in ix && typeof ix.parsed === 'string') {
|
|
|
|
|
+ memoText = ix.parsed
|
|
|
|
|
+ }
|
|
|
|
|
+ const match = memoText.match(/referer_position=([1-9A-HJ-NP-Za-km-z]{32,44})/)
|
|
|
|
|
+ if (match) return match[1]
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ // Skip unparseable memo
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return undefined
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export function parseTransaction(
|
|
export function parseTransaction(
|
|
|
tx: ParsedTransactionWithMeta,
|
|
tx: ParsedTransactionWithMeta,
|
|
|
watchedAddresses: Set<string>,
|
|
watchedAddresses: Set<string>,
|
|
@@ -307,6 +333,9 @@ export function parseTransaction(
|
|
|
result.mintA = ixAccounts[18] || ''
|
|
result.mintA = ixAccounts[18] || ''
|
|
|
result.mintB = ixAccounts[19] || ''
|
|
result.mintB = ixAccounts[19] || ''
|
|
|
|
|
|
|
|
|
|
+ // Extract referer_position from memo instruction (if present)
|
|
|
|
|
+ result.refererPosition = extractRefererFromMemo(tx)
|
|
|
|
|
+
|
|
|
// Decode event for tick range, amounts, and nftOwner validation
|
|
// Decode event for tick range, amounts, and nftOwner validation
|
|
|
const createEvent = decodeCreatePositionEvent(logs)
|
|
const createEvent = decodeCreatePositionEvent(logs)
|
|
|
if (createEvent) {
|
|
if (createEvent) {
|