Skip to content

Commit e872399

Browse files
authored
program: Add optional rent sysvar account (#138)
Add optional rent sysvar account
1 parent 065786e commit e872399

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

interface/src/instruction.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,14 @@ pub enum TokenInstruction<'a> {
372372
///
373373
/// Accounts expected by this instruction:
374374
///
375+
/// * Using runtime Rent sysvar
375376
/// 0. `[writable]` The native token account to sync with its underlying
376377
/// lamports.
378+
///
379+
/// * Using Rent sysvar account
380+
/// 0. `[writable]` The native token account to sync with its underlying
381+
/// lamports.
382+
/// 1. `[]` Rent sysvar.
377383
SyncNative,
378384
/// Like [`TokenInstruction::InitializeAccount2`], but does not require the
379385
/// Rent sysvar to be provided

program/src/processor.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,13 @@ impl Processor {
759759
let native_account_info = next_account_info(account_info_iter)?;
760760
Self::check_account_owner(program_id, native_account_info)?;
761761

762-
let rent = Rent::get()?;
763-
let rent_exempt_reserve = rent.minimum_balance(native_account_info.data_len());
762+
let rent_exempt_reserve = if let Ok(rent_sysvar_info) = next_account_info(account_info_iter)
763+
{
764+
let rent = Rent::from_account_info(rent_sysvar_info)?;
765+
rent.minimum_balance(native_account_info.data_len())
766+
} else {
767+
Rent::get()?.minimum_balance(native_account_info.data_len())
768+
};
764769

765770
let mut native_account = Account::unpack(&native_account_info.data.borrow())?;
766771

0 commit comments

Comments
 (0)