Skip to content

Commit 47603a9

Browse files
committed
use LidoError for quote_withdraw_stake
1 parent 27a4726 commit 47603a9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

core/src/typedefs/exchange_rate.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use borsh::{BorshDeserialize, BorshSerialize};
22
use sanctum_u64_ratio::{Floor, Ratio};
33

4+
use crate::LidoError;
5+
46
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, BorshDeserialize, BorshSerialize)]
57
pub struct ExchangeRate {
68
pub computed_in_epoch: u64,
@@ -14,12 +16,15 @@ impl ExchangeRate {
1416
///
1517
/// Returns None on arithmetic failure
1618
#[inline]
17-
pub const fn quote_withdraw_stake(&self, stsol_amount: u64) -> Option<u64> {
19+
pub const fn quote_withdraw_stake(&self, stsol_amount: u64) -> Result<u64, LidoError> {
1820
let ratio = self.sol_balance_over_st_sol_supply();
1921
if ratio.0.is_zero() {
20-
return None;
22+
return Err(LidoError::CalculationFailure);
23+
}
24+
match ratio.apply(stsol_amount) {
25+
Some(v) => Ok(v),
26+
None => Err(LidoError::CalculationFailure),
2127
}
22-
ratio.apply(stsol_amount)
2328
}
2429

2530
#[inline]

0 commit comments

Comments
 (0)