//contracts/pool-manager/src/helpers.rs

pub fn assert_slippage_tolerance(
    slippage_tolerance: &Option<Decimal>,
    deposits: &[Coin],
    pools: &[Coin],
    pool_type: PoolType,
    amount: Uint128,
    pool_token_supply: Uint128,
) -> Result<(), ContractError> {
    if let Some(slippage_tolerance) = *slippage_tolerance {
...
        let deposits: Vec<Uint256> = deposits.iter().map(|coin| coin.amount.into()).collect();
        let pools: Vec<Uint256> = pools.iter().map(|coin| coin.amount.into()).collect();
        // Ensure each prices are not dropped as much as slippage tolerance rate
        match pool_type {
            PoolType::StableSwap { .. } => {
                let pools_total: Uint256 = pools
                    .into_iter()
|>                  .fold(Uint256::zero(), |acc, x| acc.checked_add(x).unwrap());
                let deposits_total: Uint256 = deposits
                    .into_iter()
|>                  .fold(Uint256::zero(), |acc, x| acc.checked_add(x).unwrap());

                let pool_ratio = Decimal256::from_ratio(pools_total, pool_token_supply);
                let deposit_ratio = Decimal256::from_ratio(deposits_total, amount);

                // the slippage tolerance for the stableswap can't use a simple ratio for calculating
                // slippage when adding liquidity. Due to the math behind the stableswap, the amp factor
                // needs to be in as well, much like when swaps are done
|>              if pool_ratio * one_minus_slippage_tolerance > deposit_ratio {
                    return Err(ContractError::MaxSlippageAssertion);
                }
