@@ -372,6 +372,32 @@ fn build_instruction(ix: IntentInstruction) -> Result<Instruction, WasmSolanaErr
372372 ) )
373373 }
374374
375+ IntentInstruction :: StakeSplit {
376+ stake,
377+ split_stake,
378+ authority,
379+ lamports,
380+ } => {
381+ let stake_pubkey: Pubkey = stake. parse ( ) . map_err ( |_| {
382+ WasmSolanaError :: new ( & format ! ( "Invalid stakeSplit.stake: {}" , stake) )
383+ } ) ?;
384+ let split_stake_pubkey: Pubkey = split_stake. parse ( ) . map_err ( |_| {
385+ WasmSolanaError :: new ( & format ! ( "Invalid stakeSplit.splitStake: {}" , split_stake) )
386+ } ) ?;
387+ let authority_pubkey: Pubkey = authority. parse ( ) . map_err ( |_| {
388+ WasmSolanaError :: new ( & format ! ( "Invalid stakeSplit.authority: {}" , authority) )
389+ } ) ?;
390+ let amount: u64 = lamports. parse ( ) . map_err ( |_| {
391+ WasmSolanaError :: new ( & format ! ( "Invalid stakeSplit.lamports: {}" , lamports) )
392+ } ) ?;
393+ Ok ( build_stake_split (
394+ & stake_pubkey,
395+ & split_stake_pubkey,
396+ & authority_pubkey,
397+ amount,
398+ ) )
399+ }
400+
375401 // ===== SPL Token Program =====
376402 IntentInstruction :: TokenTransfer {
377403 source,
@@ -859,6 +885,25 @@ fn build_stake_authorize(
859885 )
860886}
861887
888+ /// Build a stake split instruction.
889+ /// Used for partial stake deactivation - splits lamports from one stake account to another.
890+ fn build_stake_split (
891+ stake : & Pubkey ,
892+ split_stake : & Pubkey ,
893+ authority : & Pubkey ,
894+ lamports : u64 ,
895+ ) -> Instruction {
896+ Instruction :: new_with_bincode (
897+ program_ids:: stake_program ( ) ,
898+ & StakeInstruction :: Split ( lamports) ,
899+ vec ! [
900+ AccountMeta :: new( * stake, false ) , // Source stake account
901+ AccountMeta :: new( * split_stake, false ) , // Destination stake account
902+ AccountMeta :: new_readonly( * authority, true ) , // Stake authority
903+ ] ,
904+ )
905+ }
906+
862907// ===== SPL Token Instruction Builders =====
863908
864909/// Build a TransferChecked instruction for SPL Token.
@@ -1454,4 +1499,28 @@ mod tests {
14541499 ) ;
14551500 verify_tx_structure ( & result. unwrap ( ) , 1 ) ;
14561501 }
1502+
1503+ #[ test]
1504+ fn test_build_stake_split ( ) {
1505+ let intent = TransactionIntent {
1506+ fee_payer : "DgT9qyYwYKBRDyDw3EfR12LHQCQjtNrKu2qMsXHuosmB" . to_string ( ) ,
1507+ nonce : Nonce :: Blockhash {
1508+ value : "GWaQEymC3Z9SHM2gkh8u12xL1zJPMHPCSVR3pSDpEXE4" . to_string ( ) ,
1509+ } ,
1510+ instructions : vec ! [ IntentInstruction :: StakeSplit {
1511+ stake: "FKjSjCqByQRwSzZoMXA7bKnDbJe41YgJTHFFzBeC42bH" . to_string( ) ,
1512+ split_stake: "5ZWgXcyqrrNpQHCme5SdC5hCeYb2o3fEJhF7Gok3bTVN" . to_string( ) ,
1513+ authority: "DgT9qyYwYKBRDyDw3EfR12LHQCQjtNrKu2qMsXHuosmB" . to_string( ) ,
1514+ lamports: "500000000" . to_string( ) , // 0.5 SOL
1515+ } ] ,
1516+ } ;
1517+
1518+ let result = build_transaction ( intent) ;
1519+ assert ! (
1520+ result. is_ok( ) ,
1521+ "Failed to build stake split: {:?}" ,
1522+ result
1523+ ) ;
1524+ verify_tx_structure ( & result. unwrap ( ) , 1 ) ;
1525+ }
14571526}
0 commit comments