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.

98 lines (97 loc) 3.63 kB
// ATA Instruction Types export var ATAInstruction; (function (ATAInstruction) { ATAInstruction[ATAInstruction["Create"] = 0] = "Create"; ATAInstruction[ATAInstruction["CreateIdempotent"] = 1] = "CreateIdempotent"; })(ATAInstruction || (ATAInstruction = {})); /** * Main ATA decoder function */ export function decodeATAInstruction(instruction) { const data = instruction.data; const programId = instruction.programId; const accounts = instruction.accounts; // Handle empty data case - common for ATA create instructions if (!data || data.length === 0) { // For empty data, infer instruction type from account structure if (accounts.length >= 6) { // Standard ATA create instruction has 6 accounts: // [payer, associatedTokenAccount, owner, mint, systemProgram, tokenProgram] return decodeCreate(instruction, programId); } else { // Unknown ATA instruction with empty data return { type: 'ata-unknown', programId, data: { error: 'Unknown ATA instruction: empty data with unexpected account structure', accountCount: accounts.length, expectedAccounts: 6 }, accounts, raw: instruction }; } } const instructionType = data[0]; switch (instructionType) { case ATAInstruction.Create: return decodeCreate(instruction, programId); case ATAInstruction.CreateIdempotent: return decodeCreateIdempotent(instruction, programId); default: return { type: 'ata-unknown', programId, data: { instructionType, error: `Unknown ATA instruction type: ${instructionType}` }, accounts, raw: instruction }; } } /** * Decode Create ATA instruction */ function decodeCreate(instruction, programId) { var _a, _b, _c, _d, _e, _f; const accounts = instruction.accounts; return { type: 'ata-create', programId, data: { payer: (_a = accounts[0]) !== null && _a !== void 0 ? _a : null, associatedTokenAccount: (_b = accounts[1]) !== null && _b !== void 0 ? _b : null, owner: (_c = accounts[2]) !== null && _c !== void 0 ? _c : null, mint: (_d = accounts[3]) !== null && _d !== void 0 ? _d : null, systemProgram: (_e = accounts[4]) !== null && _e !== void 0 ? _e : null, tokenProgram: (_f = accounts[5]) !== null && _f !== void 0 ? _f : null }, accounts, raw: instruction }; } /** * Decode Create Idempotent ATA instruction */ function decodeCreateIdempotent(instruction, programId) { var _a, _b, _c, _d, _e, _f; const accounts = instruction.accounts; return { type: 'ata-create-idempotent', programId, data: { payer: (_a = accounts[0]) !== null && _a !== void 0 ? _a : null, associatedTokenAccount: (_b = accounts[1]) !== null && _b !== void 0 ? _b : null, owner: (_c = accounts[2]) !== null && _c !== void 0 ? _c : null, mint: (_d = accounts[3]) !== null && _d !== void 0 ? _d : null, systemProgram: (_e = accounts[4]) !== null && _e !== void 0 ? _e : null, tokenProgram: (_f = accounts[5]) !== null && _f !== void 0 ? _f : null }, accounts, raw: instruction }; }