From c0529b206e540b09fb48f245fd868f71bb174bae Mon Sep 17 00:00:00 2001 From: Vladislav Vasilev <81014877+faust403@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:34:04 +0100 Subject: [PATCH] fix query_exchange_rate x2 --- contracts/lazy-staking/src/contract.rs | 10 ++++++---- contracts/lazy-staking/src/error.rs | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/contracts/lazy-staking/src/contract.rs b/contracts/lazy-staking/src/contract.rs index ead4ebef..c0720c94 100644 --- a/contracts/lazy-staking/src/contract.rs +++ b/contracts/lazy-staking/src/contract.rs @@ -73,10 +73,12 @@ fn query_exchange_rate(deps: Deps, env: Env) -> StdResult { ))?; let lazy_denom: String = DENOM.load(deps.storage)?; let lazy_total_supply = deps.querier.query_supply(lazy_denom)?; - let exchange_rate = asset_contract_balance.checked_mul(Decimal::from_ratio( - lazy_total_supply.amount, - Uint128::one(), - ))?; + let exchange_rate = asset_contract_balance + .checked_div(Decimal::from_ratio( + lazy_total_supply.amount, + Uint128::one(), + )) + .unwrap(); Ok(exchange_rate) } diff --git a/contracts/lazy-staking/src/error.rs b/contracts/lazy-staking/src/error.rs index 162bd118..1e01fc31 100644 --- a/contracts/lazy-staking/src/error.rs +++ b/contracts/lazy-staking/src/error.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{CheckedFromRatioError, OverflowError, StdError}; +use cosmwasm_std::{CheckedFromRatioError, DivideByZeroError, OverflowError, StdError}; use cw_ownable::OwnershipError; use cw_utils::PaymentError; use neutron_sdk::NeutronError; @@ -28,6 +28,8 @@ pub enum ContractError { PaymentError(#[from] PaymentError), #[error("{0}")] CheckedFromRatioError(#[from] CheckedFromRatioError), + #[error("{0}")] + DivideByZeroError(#[from] DivideByZeroError), } impl From for ContractError {