Skip to content

Commit

Permalink
checked ops
Browse files Browse the repository at this point in the history
  • Loading branch information
billythedummy authored and Arrowana committed Mar 15, 2024
1 parent 18bcd89 commit 8677483
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion libs/spl_stake_pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ impl SplStakePoolStakedex {
validator_index: usize,
withdraw_amount: u64,
) -> Result<WithdrawStakeQuote, StakePoolError> {
let validator_list_entry = self.validator_list.validators.get(validator_index).unwrap();
let validator_list_entry = self
.validator_list
.validators
.get(validator_index)
.ok_or(StakePoolError::ValidatorNotFound)?;
// only handle withdrawal from active stake accounts for simplicity.
// Likely other stake pools can't accept non active stake anyway
if validator_list_entry.status != StakeStatus::Active.into() {
Expand Down
11 changes: 6 additions & 5 deletions libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ impl<'a> WithdrawStakeQuoteIter<'a> {
.pool
.get_withdraw_stake_quote_for_validator_copied(curr_index, self.withdraw_amount)
.unwrap_or_default();
let next_state = if curr_index >= self.pool.validator_list.validators.len() - 1 {
WithdrawStakeQuoteIterState::Ended
} else {
WithdrawStakeQuoteIterState::Normal(curr_index + 1)
};
let next_state =
if curr_index >= self.pool.validator_list.validators.len().checked_sub(1)? {
WithdrawStakeQuoteIterState::Ended
} else {
WithdrawStakeQuoteIterState::Normal(curr_index.checked_add(1)?)
};
Some((wsq, next_state))
}

Expand Down

0 comments on commit 8677483

Please sign in to comment.