Skip to content

Commit

Permalink
style: remove printlns
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo-sturdy committed Apr 9, 2024
1 parent 02409fd commit 9dabed3
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 70 deletions.
24 changes: 0 additions & 24 deletions contracts/astroport-liquidity-helper/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ pub fn execute_balancing_provide_liquidity(
pool: AstroportPool,
recipient: Option<String>,
) -> Result<Response, ContractError> {
println!("execute_balancing_provide_liquidity");
println!("info.funds: {:?}", info.funds);
println!("assets: {:?}", assets);
// Get response with message to do TransferFrom on any Cw20s and assert that
// native tokens have been received already.
let receive_res = receive_assets(&info, &env, &assets)?;
Expand Down Expand Up @@ -180,8 +177,6 @@ pub fn execute_balancing_provide_liquidity(
_ => None,
};

println!("tax_configs: {:?}", tax_configs);

// Calculate amount of tokens to swap
let (offer_asset, return_asset) = calc_xyk_balancing_swap(
assets_slice,
Expand All @@ -190,17 +185,10 @@ pub fn execute_balancing_provide_liquidity(
tax_configs,
)?;

deps.api.debug(&format!("assets: {}", &assets.to_string()));
// Update balances for liquidity provision
assets.add(&return_asset)?;
assets.deduct(&offer_asset)?;

println!("assets after: {:?}", assets);
println!("offer_asset: {:?}", offer_asset);
println!("return_asset: {:?}", return_asset);

deps.api.debug("post deduction");

// If either of the assets are still zero after the swap, we can't
// provide liquidity. This can happen if the amount of tokens to swap
// is so small that the returned amount of the other asset would be zero.
Expand All @@ -210,7 +198,6 @@ pub fn execute_balancing_provide_liquidity(
.map_or_else(Uint128::zero, |y| y.amount)
.is_zero()
}) {
println!("pool_assets: {:?}", pool.pool_assets);
if min_out.is_zero() {
// If min_out is zero, we can just return the received native
// assets. We don't need to return any Cw20 assets, because
Expand All @@ -221,7 +208,6 @@ pub fn execute_balancing_provide_liquidity(
.add_attribute("action", "No liquidity provided. Zero amount of asset")
.add_attribute("assets", assets.to_string())
.add_attribute("min_out", min_out);
println!("event: {:?}", event);

// Can only return funds if there are some
let mut res = Response::new().add_event(event);
Expand All @@ -241,8 +227,6 @@ pub fn execute_balancing_provide_liquidity(
}
}

println!("pool_assets 2: {:?}", pool.pool_assets);

// Create message to swap some of the asset to the other
if offer_asset.amount > Uint128::zero() && return_asset.amount > Uint128::zero() {
pool.swap(
Expand All @@ -265,14 +249,6 @@ pub fn execute_balancing_provide_liquidity(
let provide_liquidity_res =
pool.provide_liquidity(deps.as_ref(), &env, assets.clone(), min_out)?;

println!("assets: {:?}", assets);
println!("pool assets: {:?}", pool.pool_assets);
println!(
"real pool assets: {:?}",
pool.query_pool_info(&deps.querier)?.assets
);
println!("provide_liquidity_res: {:?}", provide_liquidity_res);

// Callback to return LP tokens
let callback_msg = CallbackMsg::ReturnLpTokens {
pool,
Expand Down
41 changes: 0 additions & 41 deletions contracts/astroport-liquidity-helper/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ pub mod big_decimal {
let a = BigDecimal::new(a.into());
let b = BigDecimal::new(b.into());
let expected = BigDecimal::new(expected.into());
println!("{:?}, {:?}", &a * &b, expected);
assert_eq!(&a * &b, expected);
assert_eq!(&a * b.clone(), expected);
assert_eq!(a.clone() * &b, expected);
Expand Down Expand Up @@ -641,26 +640,17 @@ pub fn constant_product_formula(
fee: Decimal,
tax_rate: Decimal,
) -> StdResult<Uint128> {
println!("constant_product_formula");
println!(
"offer_reserve: {}, ask_reserve: {}, offer_amount: {offer_amount}, fee: {fee}",
offer_reserve, ask_reserve
);
if !tax_rate.is_zero() {
let sale_tax = offer_amount * tax_rate;
offer_amount = offer_amount.checked_sub(sale_tax)?;
}
println!("offer_amount after tax: {offer_amount}");

let cp = offer_reserve.full_mul(ask_reserve);
let return_amount: Uint256 = (Decimal256::from_ratio(ask_reserve, 1u8)
- Decimal256::from_ratio(cp, offer_reserve + offer_amount))
* Uint256::from(1u8);
println!("return_amount: {return_amount}");
let commission_amount: Uint256 = return_amount * Decimal256::from(fee);
println!("commission_amount: {commission_amount}");
let return_amount: Uint256 = return_amount - commission_amount;
println!("return_amount after tax: {return_amount}");
Ok(return_amount.try_into()?)
}

Expand All @@ -677,7 +667,6 @@ pub fn calc_xyk_balancing_swap(
fee: Decimal,
tax_configs: Option<TaxConfigsChecked>,
) -> StdResult<(Asset, Asset)> {
println!("calc_xyk_balancing_swap");
// Make sure there is liquidity in the pool
if reserves[0].is_zero() || reserves[1].is_zero() {
return Err(StdError::generic_err("No liquidity in pool"));
Expand Down Expand Up @@ -717,43 +706,24 @@ pub fn calc_xyk_balancing_swap(
.unwrap_or(Decimal::zero());
let tax_rate: &BigDecimal = &tax_rate_decimal.into();

println!("pre calcs");

// Original formula:
// let two = &BigDecimal::from(2u128);
// let a = ask_reserve + ask_balance;
// let b = two * offer_reserve * (ask_reserve + ask_balance)
// - ((offer_reserve + offer_balance) * ask_reserve * fee_rate);
// let c = offer_reserve * (offer_reserve * ask_balance - offer_balance *
// ask_reserve); let discriminant = &b * &b - (two * two * &a * &c);
// // We know that for this equation, there is only one positive real solution
// let x = (discriminant.sqrt() - b) / (two * a);

// New formula including tax:
// Solve equation to find amount to swap
let two = &BigDecimal::from(2u128);
let four = two * two;
let numerator = offer_reserve * ask_reserve * (fee_rate - fee_rate * tax_rate)
+ (offer_balance + offer_reserve) * ask_reserve * fee_rate
- two * offer_reserve * (ask_balance + ask_reserve);
println!("numerator: {:?}", numerator);
let discriminant = (two * offer_reserve * ask_balance - offer_balance * ask_reserve * fee_rate
+ two * offer_reserve * ask_reserve * (BigDecimal::one() - fee_rate)
+ offer_reserve * ask_reserve * fee_rate * tax_rate)
.pow(2)
- four
* (ask_balance + ask_reserve + ask_reserve * (fee_rate * tax_rate - tax_rate))
* (offer_reserve.pow(2) * ask_balance - offer_balance * offer_reserve * ask_reserve);
println!("discriminant: {discriminant:?}");
let denominator = two
* (ask_balance + ask_reserve - ask_reserve * tax_rate + ask_reserve * fee_rate * tax_rate);

println!("denominator: {denominator:?}");

let x = (numerator + discriminant.sqrt()) / denominator;

println!("x: {x:?}");

// Divide by precision to get final result and convert to Uint128
let offer_amount: Uint128 = bigint_to_u128(&x.floor())?.into();
let offer_asset = Asset {
Expand All @@ -774,8 +744,6 @@ pub fn calc_xyk_balancing_swap(
info: assets[ask_idx].info.clone(),
};

println!("offer_asset: {offer_asset}, return_asset: {return_asset}");

Ok((offer_asset, return_asset))
}

Expand Down Expand Up @@ -811,9 +779,6 @@ mod test {
Decimal::from_ratio(ask_balance + return_amount, offer_balance - offer_amount);
let reserve_ratio_after_swap =
Decimal::from_ratio(ask_reserve - return_amount, offer_reserve + offer_amount);
println!(
"asset_ratio_after_swap: {asset_ratio_after_swap}, reserve_ratio_after_swap: {reserve_ratio_after_swap}"
);
assert_decimal_almost_eq(asset_ratio_after_swap, reserve_ratio_after_swap);
}

Expand Down Expand Up @@ -906,15 +871,10 @@ mod test {
// Same fee for all test cases
let fee = Decimal::permille(3);

println!("Assets: {assets:?}");
println!("Reserves: {reserves:?}");

// Calculate swap
let (swap_asset, return_asset) =
calc_xyk_balancing_swap(assets, reserves, fee, None).unwrap();

println!("Swap: {swap_asset:?}, Return: {return_asset:?}");

// If ratios are already almost the same, no swap should happen
if !should_swap {
assert_eq!(swap_asset.amount, Uint128::zero());
Expand All @@ -938,6 +898,5 @@ mod test {
swap_asset.amount,
return_asset.amount,
);
println!("------------------------------------");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,6 @@ pub fn test_balancing_provide_liquidity(
auto_stake: Some(false),
receiver: None,
};
println!(
"initial reserves {} uluna, {} astro",
reserves[0], reserves[1]
);
let _res = wasm.execute(
&uluna_astro_pair_addr,
&provide_liq_msg,
Expand Down Expand Up @@ -515,7 +511,6 @@ pub fn test_balancing_provide_liquidity(
None,
)
.unwrap();
println!("msgs: {msgs:?}");
let _res = runner
.execute_cosmos_msgs::<MsgExecuteContractResponse>(&msgs, &admin)
.unwrap();
Expand Down

0 comments on commit 9dabed3

Please sign in to comment.