@@ -364,6 +364,7 @@ type StakingInstructions = {
364364 initialize ?: InitializeStakeParams ;
365365 delegate ?: DelegateStakeParams ;
366366 hasAtaInit ?: boolean ;
367+ ataInitInstruction ?: AtaInit ;
367368} ;
368369
369370type JitoStakingInstructions = StakingInstructions & {
@@ -454,7 +455,9 @@ function parseStakingActivateInstructions(
454455
455456 case ValidInstructionTypesEnum . InitializeAssociatedTokenAccount :
456457 stakingInstructions . hasAtaInit = true ;
457- instructionData . push ( {
458+ // Store the ATA init instruction - we'll decide later whether to add it to instructionData
459+ // based on staking type (Jito staking uses a flag instead of a separate instruction)
460+ stakingInstructions . ataInitInstruction = {
458461 type : InstructionBuilderTypes . CreateAssociatedTokenAccount ,
459462 params : {
460463 mintAddress : instruction . keys [ ataInitInstructionKeysIndexes . MintAddress ] . pubkey . toString ( ) ,
@@ -463,7 +466,7 @@ function parseStakingActivateInstructions(
463466 payerAddress : instruction . keys [ ataInitInstructionKeysIndexes . PayerAddress ] . pubkey . toString ( ) ,
464467 tokenName : findTokenName ( instruction . keys [ ataInitInstructionKeysIndexes . MintAddress ] . pubkey . toString ( ) ) ,
465468 } ,
466- } ) ;
469+ } ;
467470 break ;
468471 }
469472 }
@@ -536,6 +539,12 @@ function parseStakingActivateInstructions(
536539 }
537540 }
538541
542+ // For non-Jito staking, add the ATA instruction as a separate instruction
543+ // (Jito staking uses the createAssociatedTokenAccount flag in extraParams instead)
544+ if ( stakingType !== SolStakingTypeEnum . JITO && stakingInstructions . ataInitInstruction ) {
545+ instructionData . push ( stakingInstructions . ataInitInstruction ) ;
546+ }
547+
539548 instructionData . push ( stakingActivate ) ;
540549
541550 return instructionData ;
@@ -1171,7 +1180,10 @@ function parseStakingAuthorizeInstructions(
11711180 */
11721181function parseStakingAuthorizeRawInstructions ( instructions : TransactionInstruction [ ] ) : Array < Nonce | StakingAuthorize > {
11731182 const instructionData : Array < Nonce | StakingAuthorize > = [ ] ;
1174- assert ( instructions . length === 2 , 'Invalid number of instructions' ) ;
1183+ // StakingAuthorizeRaw transactions have:
1184+ // - 2 instructions: NonceAdvance + 1 Authorize (changing either staking OR withdraw authority)
1185+ // - 3 instructions: NonceAdvance + 2 Authorizes (changing BOTH staking AND withdraw authority)
1186+ assert ( instructions . length >= 2 && instructions . length <= 3 , 'Invalid number of instructions' ) ;
11751187 const advanceNonceInstruction = SystemInstruction . decodeNonceAdvance ( instructions [ 0 ] ) ;
11761188 const nonce : Nonce = {
11771189 type : InstructionBuilderTypes . NonceAdvance ,
@@ -1181,17 +1193,24 @@ function parseStakingAuthorizeRawInstructions(instructions: TransactionInstructi
11811193 } ,
11821194 } ;
11831195 instructionData . push ( nonce ) ;
1184- const authorize = instructions [ 1 ] ;
1185- assert ( authorize . keys . length === 5 , 'Invalid number of keys in authorize instruction' ) ;
1186- instructionData . push ( {
1187- type : InstructionBuilderTypes . StakingAuthorize ,
1188- params : {
1189- stakingAddress : authorize . keys [ 0 ] . pubkey . toString ( ) ,
1190- oldAuthorizeAddress : authorize . keys [ 2 ] . pubkey . toString ( ) ,
1191- newAuthorizeAddress : authorize . keys [ 3 ] . pubkey . toString ( ) ,
1192- custodianAddress : authorize . keys [ 4 ] . pubkey . toString ( ) ,
1193- } ,
1194- } ) ;
1196+
1197+ // Process all authorize instructions (1 or 2)
1198+ for ( let i = 1 ; i < instructions . length ; i ++ ) {
1199+ const authorize = instructions [ i ] ;
1200+ // Authorize instruction keys: [stakePubkey, clockSysvar, oldAuthority, newAuthority, custodian?]
1201+ // - 4 keys: no custodian required
1202+ // - 5 keys: custodian is present (required when stake is locked)
1203+ assert ( authorize . keys . length >= 4 && authorize . keys . length <= 5 , 'Invalid number of keys in authorize instruction' ) ;
1204+ instructionData . push ( {
1205+ type : InstructionBuilderTypes . StakingAuthorize ,
1206+ params : {
1207+ stakingAddress : authorize . keys [ 0 ] . pubkey . toString ( ) ,
1208+ oldAuthorizeAddress : authorize . keys [ 2 ] . pubkey . toString ( ) ,
1209+ newAuthorizeAddress : authorize . keys [ 3 ] . pubkey . toString ( ) ,
1210+ custodianAddress : authorize . keys . length === 5 ? authorize . keys [ 4 ] . pubkey . toString ( ) : '' ,
1211+ } ,
1212+ } ) ;
1213+ }
11951214 return instructionData ;
11961215}
11971216
@@ -1239,7 +1258,7 @@ function parseCustomInstructions(
12391258 return instructionData ;
12401259}
12411260
1242- function findTokenName (
1261+ export function findTokenName (
12431262 mintAddress : string ,
12441263 instructionMetadata ?: InstructionParams [ ] ,
12451264 _useTokenAddressTokenName ?: boolean
0 commit comments