Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding shortfall protection for account migration. #412

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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