Drozdziak1/p2w init rent adjustment (#269)
* pyth2wormhole: add rent adjustment to the initialize() instruction * pyth2wormhole migrate(): Leave a note about rent adjustment The migrate() ix won't be called in the nearest future - it does not make sense to bloat the program bytecode with the rent adjustment. The note describes the what and why in detail.
This commit is contained in:
parent
65c273fa0a
commit
94aab8af8f
|
@ -1,4 +1,10 @@
|
|||
use solana_program::pubkey::Pubkey;
|
||||
use solana_program::{
|
||||
program::invoke,
|
||||
pubkey::Pubkey,
|
||||
rent::Rent,
|
||||
system_instruction,
|
||||
sysvar::Sysvar,
|
||||
};
|
||||
use solitaire::{
|
||||
trace,
|
||||
AccountState,
|
||||
|
@ -35,5 +41,21 @@ pub fn initialize(
|
|||
.create(ctx, accs.payer.info().key, CreationLamports::Exempt)?;
|
||||
accs.new_config.1 = data;
|
||||
|
||||
// TODO(2022-09-05): Remove this rent collection after
|
||||
// sysvar-based rent calculation becomes mainline in Solitaire.
|
||||
let config_balance = accs.new_config.info().lamports();
|
||||
let config_rent_exempt = Rent::get()?.minimum_balance(accs.new_config.info().data_len());
|
||||
|
||||
if config_balance < config_rent_exempt {
|
||||
let required_deposit = config_rent_exempt - config_balance;
|
||||
|
||||
let transfer_ix = system_instruction::transfer(
|
||||
accs.payer.key,
|
||||
accs.new_config.info().key,
|
||||
required_deposit,
|
||||
);
|
||||
invoke(&transfer_ix, ctx.accounts)?
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -70,6 +70,13 @@ pub fn migrate(ctx: &ExecutionContext, accs: &mut Migrate, data: ()) -> SoliResu
|
|||
));
|
||||
}
|
||||
|
||||
// NOTE(2022-09-06): This instruction does not contain the temporary rent
|
||||
// adjustment snippet necessary for PythNet compatibility. This
|
||||
// was done to minimize the footprint of this rather hacky
|
||||
// workaround. In case the migrate ix needs to be ran in a
|
||||
// weird-rent environment, copy the rent due snippet and adjust it
|
||||
// to work against `accs.new_config`.
|
||||
|
||||
// Populate new config
|
||||
accs.new_config
|
||||
.create(ctx, accs.payer.info().key, CreationLamports::Exempt)?;
|
||||
|
|
Loading…
Reference in New Issue