UNPKG

@gorbchain-xyz/chaindecode

Version:

GorbchainSDK V1.3+ - Complete Solana development toolkit with advanced cryptography, messaging, and collaboration features. Build secure applications with blockchain, DeFi, and end-to-end encryption.

243 lines (242 loc) 7.79 kB
/** * Rich Transaction Operations - Enhanced transaction functions with decoded context * * These functions provide comprehensive transaction analysis including: * - Decoded instruction details * - Token metadata for token-related transactions * - Human-readable summaries * - Balance changes and effects */ import type { GorbchainSDK } from '../sdk/GorbchainSDK.js'; /** * Rich instruction with complete context and metadata */ export interface RichInstruction { /** Instruction index in the transaction */ index: number; /** Program ID that processed this instruction */ programId: string; /** Program name (e.g., 'System Program', 'SPL Token') */ programName: string; /** Instruction type (e.g., 'Transfer', 'CreateAccount') */ type: string; /** Human-readable description */ description: string; /** Raw instruction data */ data: Uint8Array; /** Account addresses involved */ accounts: string[]; /** Decoded instruction details */ decoded: { /** Instruction-specific data */ [key: string]: any; }; /** Token-related information (if applicable) */ tokens?: { /** Token transfers in this instruction */ transfers: Array<{ /** Source account */ from: string; /** Destination account */ to: string; /** Token mint address */ mint: string; /** Amount transferred (raw) */ amount: string; /** Formatted amount with decimals */ amountFormatted: string; /** Token metadata */ token: { name?: string; symbol?: string; decimals: number; isNFT: boolean; image?: string; }; }>; /** Token accounts created/closed */ accountChanges: Array<{ /** Account address */ account: string; /** Change type */ type: 'created' | 'closed' | 'frozen' | 'thawed'; /** Associated token mint */ mint?: string; /** Token metadata */ token?: { name?: string; symbol?: string; decimals: number; }; }>; }; /** SOL balance changes (if applicable) */ solChanges?: Array<{ /** Account address */ account: string; /** Balance change in lamports */ change: number; /** Balance change in SOL */ changeSOL: number; /** Change type */ type: 'debit' | 'credit'; }>; /** Fees consumed by this instruction */ fees?: { /** Base fee in lamports */ base: number; /** Compute budget consumed */ computeUnits?: number; /** Priority fee in lamports */ priority?: number; }; /** Instruction result */ result: { /** Whether instruction succeeded */ success: boolean; /** Error message if failed */ error?: string; /** Program logs */ logs: string[]; }; } /** * Rich transaction with complete analysis and context */ export interface RichTransaction { /** Transaction signature */ signature: string; /** Block slot */ slot?: number; /** Block time timestamp */ blockTime?: number; /** Confirmation status */ confirmationStatus?: 'processed' | 'confirmed' | 'finalized'; /** Transaction fee in lamports */ fee: number; /** Whether transaction succeeded */ success: boolean; /** Error message if failed */ error?: string; /** Rich instructions with decoded context */ instructions: RichInstruction[]; /** Transaction summary */ summary: { /** Primary action of the transaction */ primaryAction: string; /** Human-readable description */ description: string; /** Transaction category */ category: 'transfer' | 'swap' | 'nft' | 'defi' | 'governance' | 'system' | 'unknown'; /** Key participants */ participants: Array<{ /** Wallet address */ address: string; /** Role in transaction */ role: 'sender' | 'receiver' | 'authority' | 'program'; /** Address label if known */ label?: string; }>; /** Total SOL involved */ totalSOL: number; /** Total tokens involved */ totalTokens: number; /** Total NFTs involved */ totalNFTs: number; }; /** Balance changes across all accounts */ balanceChanges: { /** SOL balance changes */ sol: Array<{ account: string; before: number; after: number; change: number; }>; /** Token balance changes */ tokens: Array<{ account: string; mint: string; token: { name?: string; symbol?: string; decimals: number; isNFT: boolean; }; before: string; after: string; change: string; changeFormatted: string; }>; }; /** Transaction metadata */ meta: { /** Compute units consumed */ computeUnitsConsumed?: number; /** Inner instructions count */ innerInstructionsCount: number; /** Total accounts involved */ totalAccounts: number; /** Programs involved */ programsInvolved: string[]; /** Analysis duration in milliseconds */ analysisDuration: number; /** Whether metadata was resolved */ metadataResolved: boolean; }; } /** * Get rich transaction with complete decoded context and metadata * * This function enhances the basic getTransaction with: * - Complete instruction decoding with human-readable descriptions * - Token metadata for all token-related operations * - Balance change analysis * - Transaction categorization and summary * - Human-readable transaction description * * @param sdk - GorbchainSDK instance * @param signature - Transaction signature to analyze * @param options - Configuration options * @returns Promise resolving to rich transaction with full context * * @example * ```typescript * const sdk = new GorbchainSDK({ rpcEndpoint: 'https://rpc.gorbchain.xyz' }); * * const richTx = await getRichTransaction(sdk, 'transaction_signature', { * includeTokenMetadata: true, * includeBalanceChanges: true, * resolveAddressLabels: true * }); * * console.log(richTx.summary.description); * // "Alice sent 100 USDC to Bob" * * console.log(`Category: ${richTx.summary.category}`); * console.log(`Total SOL involved: ${richTx.summary.totalSOL}`); * * // Analyze each instruction * richTx.instructions.forEach((instruction, i) => { * console.log(`${i + 1}. ${instruction.description}`); * * if (instruction.tokens?.transfers) { * instruction.tokens.transfers.forEach(transfer => { * console.log(` → ${transfer.amountFormatted} ${transfer.token.symbol} from ${transfer.from} to ${transfer.to}`); * }); * } * }); * ``` */ export declare function getRichTransaction(sdk: GorbchainSDK, signature: string, options?: { /** Whether to include token metadata */ includeTokenMetadata?: boolean; /** Whether to include balance changes */ includeBalanceChanges?: boolean; /** Whether to resolve address labels */ resolveAddressLabels?: boolean; /** Maximum retries for metadata fetching */ maxRetries?: number; /** Custom commitment level */ commitment?: 'processed' | 'confirmed' | 'finalized'; }): Promise<RichTransaction>;