Skip to content

Commit

Permalink
Adding shortfall protection for account migration. (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus authored Apr 27, 2022
1 parent 79a1792 commit 56e0995
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions auction-house/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,34 @@ pub mod auction_house {
],
)?;

// For native purchases, verify that the amount in escrow is sufficient to actually purchase the token.
// This is intended to cover the migration from pre-rent-exemption checked accounts to rent-exemption checked accounts.
// The fee payer makes up the shortfall up to the amount of rent for an empty account.
if is_native {
let diff = rent_checked_sub(escrow_payment_account.to_account_info(), buyer_price)?;
if diff != buyer_price {
// Return the shortfall amount (if greater than 0 but less than rent), but don't exceed the minimum rent the account should need.
let shortfall = std::cmp::min(
diff.checked_sub(buyer_price)
.ok_or(ErrorCode::NumericalOverflow)?,
rent.minimum_balance(escrow_payment_account.data_len()),
);
invoke_signed(
&system_instruction::transfer(
&fee_payer.key,
&escrow_payment_account.key,
shortfall,
),
&[
fee_payer.to_account_info(),
escrow_payment_account.to_account_info(),
system_program.to_account_info(),
],
&[&fee_payer_seeds],
)?;
}
}

if metadata.data_is_empty() {
return Err(ErrorCode::MetadataDoesntExist.into());
}
Expand Down

0 comments on commit 56e0995

Please sign in to comment.