import { FEE_PAYER_PUBKEYS } from '../../../../../../../constants/publicKeys' ; import type { ParsedConfirmedTransaction , ParsedInstruction } from '../../../../../types' ; import type { AbstractTransaction , Parser , TransactionDetails } from '../types' ; export class TransferTransaction implements AbstractTransaction { constructor ( public source , public destination , public amount , public wasPaidByP2POrg ? ) { } details ( sources ? ) { const isReceiver = this . destination ? sources ?. includes ( this . destination ) : false ; return { type : isReceiver ? 'receive' : 'transfer' , icon : isReceiver ? 'bottom' : 'top' , isReceiver , amount : this . amount , tokenAccount : isReceiver ? this . destination : this . source } ; } } export class TransferParser implements Parser { /**
     Check if transaction is transfer transaction
     */ static can ( instructions ) { return ( ( instructions . length === 1 || instructions . length === 4 || instructions . length === 2 ) && ( instructions . at ( - 1 ) ?. parsed ?. type === 'transfer' || instructions . at ( - 1 ) ?. parsed ?. type === 'transferChecked' ) ) ; } static parse ( transactionInfo ) { const instructions = transactionInfo . transaction . message . instructions ; const accountKeys = transactionInfo . transaction . message . accountKeys ; const transferInstruction = instructions . at ( - 1 ) as ParsedInstruction | undefined ; const source = transferInstruction ?. parsed ?. info . source ; const destination = transferInstruction ?. parsed ?. info . destination ; const amount = transferInstruction ?. parsed ?. info . lamports ?? transferInstruction ?. parsed ?. info . amount ?? transferInstruction ?. parsed ?. info . tokenAmount ?. amount ?? '0' ; const result = new TransferTransaction ( source , destination , amount ) ; const payer = accountKeys [ 0 ] ?. pubkey ?. toBase58 ( ) ; if ( payer && FEE_PAYER_PUBKEYS . has ( payer ) ) { result . wasPaidByP2POrg = true ; } return result ; } }