token_withdraw: avoid silencing errors with is_ok() (#936)

This commit is contained in:
Christian Kamm 2024-04-08 16:28:25 +02:00 committed by GitHub
parent 9df73a0dfd
commit 653cf9f30b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -820,6 +820,12 @@ impl HealthCache {
})
}
pub fn has_token_info(&self, token_index: TokenIndex) -> bool {
self.token_infos
.iter()
.any(|t| t.token_index == token_index)
}
pub fn perp_info(&self, perp_market_index: PerpMarketIndex) -> Result<&PerpInfo> {
Ok(&self.perp_infos[self.perp_info_index(perp_market_index)?])
}

View File

@ -156,7 +156,7 @@ pub fn token_withdraw(ctx: Context<TokenWithdraw>, amount: u64, allow_borrow: bo
// Health check
//
if let Some((mut health_cache, pre_init_health_lower_bound)) = pre_health_opt {
if health_cache.token_info_index(token_index).is_ok() {
if health_cache.has_token_info(token_index) {
// This is the normal case: the health cache knows about the token, we can
// compute the health for the new state by adjusting its balance
health_cache.adjust_token_balance(&bank, native_position_after - native_position)?;