From 8b8875b3d0e6d1303d40fe3a60cc6e98f7113998 Mon Sep 17 00:00:00 2001 From: febo Date: Wed, 4 Mar 2026 23:09:59 +0000 Subject: [PATCH] Add optional rent sysvar account --- interface/src/instruction.rs | 6 ++++++ program/src/processor.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/interface/src/instruction.rs b/interface/src/instruction.rs index aa6efbb2..40b4337a 100644 --- a/interface/src/instruction.rs +++ b/interface/src/instruction.rs @@ -372,8 +372,14 @@ pub enum TokenInstruction<'a> { /// /// Accounts expected by this instruction: /// + /// * Using runtime Rent sysvar /// 0. `[writable]` The native token account to sync with its underlying /// lamports. + /// + /// * Using Rent sysvar account + /// 0. `[writable]` The native token account to sync with its underlying + /// lamports. + /// 1. `[]` Rent sysvar. SyncNative, /// Like [`TokenInstruction::InitializeAccount2`], but does not require the /// Rent sysvar to be provided diff --git a/program/src/processor.rs b/program/src/processor.rs index 9180213c..d0902573 100644 --- a/program/src/processor.rs +++ b/program/src/processor.rs @@ -759,8 +759,13 @@ impl Processor { let native_account_info = next_account_info(account_info_iter)?; Self::check_account_owner(program_id, native_account_info)?; - let rent = Rent::get()?; - let rent_exempt_reserve = rent.minimum_balance(native_account_info.data_len()); + let rent_exempt_reserve = if let Ok(rent_sysvar_info) = next_account_info(account_info_iter) + { + let rent = Rent::from_account_info(rent_sysvar_info)?; + rent.minimum_balance(native_account_info.data_len()) + } else { + Rent::get()?.minimum_balance(native_account_info.data_len()) + }; let mut native_account = Account::unpack(&native_account_info.data.borrow())?;