pub enum PoolType {
    StableSwap {
        /// The amount of amplification to perform on the constant product part of the swap formula.
        amp: u64,
    },
    ConstantProduct,
}
def ramp_A(_future_A: uint256, _future_time: uint256):
    assert msg.sender == self.owner  # dev: only owner
    assert block.timestamp >= self.initial_A_time + MIN_RAMP_TIME
    assert _future_time >= block.timestamp + MIN_RAMP_TIME  # dev: insufficient time

    initial_A: uint256 = self._A()
    future_A_p: uint256 = _future_A * A_PRECISION

    assert _future_A > 0 and _future_A < MAX_A
    if future_A_p < initial_A:
        assert future_A_p * MAX_A_CHANGE >= initial_A
    else:
        assert future_A_p <= initial_A * MAX_A_CHANGE

    self.initial_A = initial_A
    self.future_A = future_A_p
    self.initial_A_time = block.timestamp
    self.future_A_time = _future_time
pub fn provide_liquidity()  {

// ..snip
//@audit below we route the call when providing the liquidity to the stableswap implementation
                } else {
                    compute_lp_mint_amount_for_stableswap_deposit(
                        amp_factor,
                        // pool_assets hold the balances before the deposit was made
                        &pool_assets,
                        // add the deposit to the pool_assets to calculate the new balances
                        &add_coins(pool_assets.clone(), deposits.clone())?,
                        total_share,
                    )?
                    .ok_or(ContractError::StableLpMintError)?
                }
                // ..snip
}
pub fn compute_lp_mint_amount_for_stableswap_deposit(
    amp_factor: &u64,
    old_pool_assets: &[Coin],
    new_pool_assets: &[Coin],
    pool_lp_token_total_supply: Uint128,
) -> Result<Option<Uint128>, ContractError> {
    // Initial invariant
    let d_0 = compute_d(amp_factor, old_pool_assets).ok_or(ContractError::StableInvariantError)?;

    // Invariant after change, i.e. after deposit
    // notice that new_pool_assets already added the new deposits to the pool
    let d_1 = compute_d(amp_factor, new_pool_assets).ok_or(ContractError::StableInvariantError)?;

    // If the invariant didn't change, return None
    if d_1 <= d_0 {
        Ok(None)
    } else {
        let amount = Uint512::from(pool_lp_token_total_supply)
            .checked_mul(d_1.checked_sub(d_0)?)?
            .checked_div(d_0)?;
        Ok(Some(Uint128::try_from(amount)?))
    }
}
pub fn compute_y_raw(
    n_coins: u8,
    amp_factor: &u64,
    swap_in: Uint128,
    //swap_out: Uint128,
    no_swap: Uint128,
    d: Uint512,
) -> Option<Uint512> {
    let ann = amp_factor.checked_mul(n_coins.into())?; // A * n ** n

    // sum' = prod' = x
    // c =  D ** (n + 1) / (n ** (2 * n) * prod' * A)
    let mut c = d;

    c = c
        .checked_mul(d)
        .unwrap()
        .checked_div(swap_in.checked_mul(n_coins.into()).unwrap().into())
        .unwrap();

    c = c
        .checked_mul(d)
        .unwrap()
        .checked_div(no_swap.checked_mul(n_coins.into()).unwrap().into())
        .unwrap();
    c = c
        .checked_mul(d)
        .unwrap()
        .checked_div(ann.checked_mul(n_coins.into()).unwrap().into())
        .unwrap();
    // b = sum(swap_in, no_swap) + D // Ann - D
    // not subtracting D here because that could result in a negative.
    let b = d
        .checked_div(ann.into())
        .unwrap()
        .checked_add(swap_in.into())
        .unwrap()
        .checked_add(no_swap.into())
        .unwrap();

    // Solve for y by approximating: y**2 + b*y = c
    let mut y_prev: Uint512;
    let mut y = d;
    for _ in 0..1000 {
        y_prev = y;
        // y = (y * y + c) / (2 * y + b - d);
        let y_numerator = y.checked_mul(y).unwrap().checked_add(c).unwrap();
        let y_denominator = y
            .checked_mul(Uint512::from(2u8))
            .unwrap()
            .checked_add(b)
            .unwrap()
            .checked_sub(d)
            .unwrap();
        y = y_numerator.checked_div(y_denominator).unwrap();
        if y > y_prev {
            if y.checked_sub(y_prev).unwrap() <= Uint512::one() {
                break;
            }
        } else if y_prev.checked_sub(y).unwrap() <= Uint512::one() {
            break;
        }
    }
    Some(y)
}
Left side: Anxi + D
= 85 * 2 * (1000 + 1000) + 2000
= 85 * 2 * 2000 + 2000
= 340,000 + 2000
= 342,000

Right side: AD + (D^(n+1))/(n^nxi)
= 85 * 2000 + 2000/(2 * 1000 * 1000)
= 340,000 + 2000
= 342,000

Price impact for 10% imbalance trade  0.3%
Left side: Anxi + D
= 1000 * 2 * (1000 + 1000) + 2000
= 1000 * 2 * 2000 + 2000
= 4,000,000 + 2000
= 4,002,000

Right side: AD + (D^(n+1))/(n^nxi)
= 1000 * 2000 + 2000/(2 * 1000 * 1000)
= 4,000,000 + 2000
= 4,002,000

Price impact for 10% imbalance trade  0.025%
Left side: Anxi + D
= 10 * 2 * (1000 + 1000) + 2000
= 10 * 2 * 2000 + 2000
= 40,000 + 2000
= 42,000

Right side: AD + (D^(n+1))/(n^nxi)
= 10 * 2000 + 2000/(2 * 1000 * 1000)
= 40,000 + 2000
= 42,000

Price impact for 10% imbalance  2.5%
pub enum ExecuteMsg {
    RampAmplifier {
        future_amp: u64,
        future_time: u64,
    },
    StopRamp {},
}
const MAX_A: u64 = 1_000_000;  // 10^6
const MAX_A_CHANGE: u64 = 10;
const MIN_RAMP_TIME: u64 = 3600;  // 1 hour
