Skip to content

Commit df38b63

Browse files
committed
Simplify math
1 parent 3fff4ce commit df38b63

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

p-token/src/processor/close_account.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,11 @@ pub fn process_close_account(accounts: &[AccountInfo]) -> ProgramResult {
4444
}
4545
}
4646

47-
let destination_starting_lamports = destination_account_info.lamports();
4847
// SAFETY: single mutable borrow to `destination_account_info` lamports and
4948
// there are no "active" borrows of `source_account_info` account data.
5049
unsafe {
5150
// Moves the lamports to the destination account.
52-
*destination_account_info.borrow_mut_lamports_unchecked() = destination_starting_lamports
53-
.checked_add(source_account_info.lamports())
54-
.ok_or(TokenError::Overflow)?;
51+
*destination_account_info.borrow_mut_lamports_unchecked() += source_account_info.lamports();
5552
// Closes the source account.
5653
source_account_info.close_unchecked();
5754
}

p-token/src/processor/shared/burn.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ pub fn process_burn(
8383
source_account.set_amount(updated_source_amount);
8484
// Note: The amount of a token account is always within the range of the
8585
// mint supply (`u64`).
86-
let mint_supply = mint.supply().checked_sub(amount).unwrap();
87-
mint.set_supply(mint_supply);
86+
mint.set_supply(mint.supply() - amount);
8887
}
8988

9089
Ok(())

p-token/src/processor/withdraw_excess_lamports.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,12 @@ pub fn process_withdraw_excess_lamports(accounts: &[AccountInfo]) -> ProgramResu
8686
source_starting_lamports - transfer_amount;
8787
}
8888

89-
let destination_starting_lamports = destination_info.lamports();
9089
// SAFETY: single mutable borrow to `destination_info` lamports.
9190
unsafe {
9291
// Moves the lamports to the destination account.
93-
*destination_info.borrow_mut_lamports_unchecked() = destination_starting_lamports
94-
.checked_add(transfer_amount)
95-
.ok_or(TokenError::Overflow)?;
92+
//
93+
// Note: The total lamports supply is bound to `u64::MAX`.
94+
*destination_info.borrow_mut_lamports_unchecked() += transfer_amount;
9695
}
9796

9897
Ok(())

0 commit comments

Comments
 (0)