Skip to content

Commit

Permalink
Do not try to deserialize genesis end epoch info in Accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass committed Jan 9, 2025
1 parent f41b980 commit 1eb631a
Showing 1 changed file with 51 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ pub struct ExtendExpirationTsV0<'info> {
)]
pub closing_time_sub_dao_epoch_info: Box<Account<'info, SubDaoEpochInfoV0>>,
#[account(
init_if_needed,
payer = payer,
space = SubDaoEpochInfoV0::SIZE,
mut,
seeds = [
"sub_dao_epoch_info".as_bytes(),
sub_dao.key().as_ref(),
Expand All @@ -91,7 +89,8 @@ pub struct ExtendExpirationTsV0<'info> {
],
bump,
)]
pub genesis_end_sub_dao_epoch_info: Box<Account<'info, SubDaoEpochInfoV0>>,
/// CHECK: Verified when needed in the inner instr
pub genesis_end_sub_dao_epoch_info: UncheckedAccount<'info>,
pub proxy_config: Box<Account<'info, ProxyConfigV0>>,
pub system_program: Program<'info, System>,
}
Expand Down Expand Up @@ -180,43 +179,56 @@ pub fn handler(ctx: Context<ExtendExpirationTsV0>) -> Result<()> {
closing_time_sdei.exit(&id())?;
}

// Always update genesis_end_sdei
ctx.accounts.genesis_end_sub_dao_epoch_info.reload()?;
let genesis_end_sdei = &mut ctx.accounts.genesis_end_sub_dao_epoch_info;
if genesis_end_sdei.epoch > epoch {
msg!(
"Subtracting vehnt info from genesis end sdei {:?}",
vehnt_info_old
);
genesis_end_sdei.vehnt_in_closing_positions = genesis_end_sdei
.vehnt_in_closing_positions
.checked_sub(vehnt_info_old.genesis_end_vehnt_correction)
.unwrap();
genesis_end_sdei.fall_rates_from_closing_positions = genesis_end_sdei
.fall_rates_from_closing_positions
.checked_sub(vehnt_info_old.genesis_end_fall_rate_correction)
.unwrap();
msg!(
"Post subtraction genesis end sdei {} {}",
genesis_end_sdei.vehnt_in_closing_positions,
genesis_end_sdei.fall_rates_from_closing_positions
);
let genesis_end_is_closing = ctx.accounts.genesis_end_sub_dao_epoch_info.key()
== ctx.accounts.closing_time_sub_dao_epoch_info.key();
if !ctx.accounts.genesis_end_sub_dao_epoch_info.data_len() == 0 {
let mut parsed: Account<SubDaoEpochInfoV0>;
let genesis_end_sdei: &mut Account<SubDaoEpochInfoV0> = if genesis_end_is_closing {
&mut ctx.accounts.closing_time_sub_dao_epoch_info
} else {
parsed = Account::try_from(
&ctx
.accounts
.genesis_end_sub_dao_epoch_info
.to_account_info(),
)?;
&mut parsed
};
if genesis_end_sdei.epoch > epoch {
msg!(
"Subtracting vehnt info from genesis end sdei {:?}",
vehnt_info_old
);
genesis_end_sdei.vehnt_in_closing_positions = genesis_end_sdei
.vehnt_in_closing_positions
.checked_sub(vehnt_info_old.genesis_end_vehnt_correction)
.unwrap();
genesis_end_sdei.fall_rates_from_closing_positions = genesis_end_sdei
.fall_rates_from_closing_positions
.checked_sub(vehnt_info_old.genesis_end_fall_rate_correction)
.unwrap();
msg!(
"Post subtraction genesis end sdei {} {}",
genesis_end_sdei.vehnt_in_closing_positions,
genesis_end_sdei.fall_rates_from_closing_positions
);

genesis_end_sdei.vehnt_in_closing_positions = genesis_end_sdei
.vehnt_in_closing_positions
.checked_add(vehnt_info_new.genesis_end_vehnt_correction)
.unwrap();
genesis_end_sdei.fall_rates_from_closing_positions = genesis_end_sdei
.fall_rates_from_closing_positions
.checked_add(vehnt_info_new.genesis_end_fall_rate_correction)
.unwrap();
msg!(
"Post addition genesis end sdei {} {}",
genesis_end_sdei.vehnt_in_closing_positions,
genesis_end_sdei.fall_rates_from_closing_positions
);
genesis_end_sdei.vehnt_in_closing_positions = genesis_end_sdei
.vehnt_in_closing_positions
.checked_add(vehnt_info_new.genesis_end_vehnt_correction)
.unwrap();
genesis_end_sdei.fall_rates_from_closing_positions = genesis_end_sdei
.fall_rates_from_closing_positions
.checked_add(vehnt_info_new.genesis_end_fall_rate_correction)
.unwrap();
msg!(
"Post addition genesis end sdei {} {}",
genesis_end_sdei.vehnt_in_closing_positions,
genesis_end_sdei.fall_rates_from_closing_positions
);

genesis_end_sdei.exit(&id())?;
genesis_end_sdei.exit(&id())?;
}
}

Ok(())
Expand Down

0 comments on commit 1eb631a

Please sign in to comment.