Skip to content

Commit

Permalink
fix lowe fee amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroccult committed Mar 13, 2024
1 parent 5b483a1 commit a5c8edf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
5 changes: 4 additions & 1 deletion ixo-swap/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{Decimal, StdError, Uint128};
use cosmwasm_std::{CheckedMultiplyFractionError, Decimal, StdError, Uint128};
use thiserror::Error;

#[derive(Error, Debug, PartialEq)]
Expand All @@ -9,6 +9,9 @@ pub enum ContractError {
#[error("{0}")]
Cw20Error(#[from] cw20_base_lp::ContractError),

#[error("{0}")]
CheckedMultiplyFraction(#[from] CheckedMultiplyFractionError),

#[error("{0}")]
PaymentError(#[from] cw_utils::PaymentError),

Expand Down
22 changes: 12 additions & 10 deletions ixo-swap/src/token_amount.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashMap, convert::TryInto};
use std::{collections::HashMap, convert::TryFrom};

use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Decimal, StdError, StdResult, Uint128, Uint256};
use cosmwasm_std::{CheckedMultiplyFractionError, Decimal, StdError, Uint128};
use cw1155::TokenId;

use crate::{
Expand Down Expand Up @@ -116,14 +116,16 @@ impl TokenAmount {
Ok(TokenAmount::Multiple(amounts))
}

fn get_percent_from_single(input_amount: Uint128, percent: Uint128) -> StdResult<TokenAmount> {
Ok(TokenAmount::Single(
input_amount
.full_mul(percent)
.checked_div(Uint256::from(SCALE_FACTOR))
.map_err(StdError::divide_by_zero)?
.try_into()?,
))
fn get_percent_from_single(
input_amount: Uint128,
percent: Uint128,
) -> Result<TokenAmount, CheckedMultiplyFractionError> {
let fraction = (SCALE_FACTOR.u128(), 1u128);
let result = input_amount
.full_mul(percent)
.checked_div_ceil(fraction)
.map_err(|err| err)?;
Ok(TokenAmount::Single(Uint128::try_from(result)?))
}
}

Expand Down

0 comments on commit a5c8edf

Please sign in to comment.