Skip to content

Commit

Permalink
fix(optimize): OS-SQD-SUG-03
Browse files Browse the repository at this point in the history
  • Loading branch information
ogmedia committed Jul 22, 2022
1 parent 850858c commit e7108e1
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions programs/squads-mpl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,21 @@ pub mod squads_mpl {
if spots_left < 1{
// add space for 10 more keys
let needed_len = curr_data_size + ( 10 * 32 );
// reallocate more space
AccountInfo::realloc(&multisig_account_info, needed_len, false)?;
// if more lamports are needed, transfer them to the account
let rent_exempt_lamports = ctx.accounts.rent.minimum_balance(needed_len).max(1);
let top_up_lamports = rent_exempt_lamports.saturating_sub(ctx.accounts.multisig.to_account_info().lamports());
AccountInfo::realloc(&multisig_account_info, needed_len, false)?;
invoke(
&transfer(ctx.accounts.member.key, &ctx.accounts.multisig.key(), top_up_lamports),
&[
ctx.accounts.member.to_account_info().clone(),
multisig_account_info.clone(),
ctx.accounts.system_program.to_account_info().clone(),
],
)?;
if top_up_lamports > 0 {
invoke(
&transfer(ctx.accounts.member.key, &ctx.accounts.multisig.key(), top_up_lamports),
&[
ctx.accounts.member.to_account_info().clone(),
multisig_account_info.clone(),
ctx.accounts.system_program.to_account_info().clone(),
],
)?;
}
}
ctx.accounts.multisig.reload()?;
ctx.accounts.multisig.add_member(new_member)?;
Expand Down

0 comments on commit e7108e1

Please sign in to comment.