Skip to content

Commit

Permalink
fix: math now accounts for osmosis_fee. Not all tests are passing
Browse files Browse the repository at this point in the history
  • Loading branch information
nseguias committed Aug 20, 2024
1 parent e685099 commit 042b3f5
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 26 deletions.
34 changes: 34 additions & 0 deletions contracts/liquidity_hub/bonding-manager/src/tests/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ fn test_claim_successfully() {

let asset_denoms = vec!["uwhale".to_string(), "uusdc".to_string()];

#[cfg(feature = "osmosis")]
let pool_fees = PoolFee {
protocol_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
swap_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
burn_fee: Fee {
share: Decimal::zero(),
},
extra_fees: vec![],
osmosis_fee: Fee {
share: Decimal::permille(1),
},
};

#[cfg(not(feature = "osmosis"))]
let pool_fees = PoolFee {
protocol_fee: Fee {
Expand Down Expand Up @@ -895,6 +912,23 @@ fn test_rewards_forwarding() {
extra_fees: vec![],
};

#[cfg(feature = "osmosis")]
let pool_fees = PoolFee {
protocol_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
swap_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
burn_fee: Fee {
share: Decimal::zero(),
},
extra_fees: vec![],
osmosis_fee: Fee {
share: Decimal::permille(1),
},
};

suite
.instantiate_default()
.create_pair(
Expand Down
17 changes: 17 additions & 0 deletions contracts/liquidity_hub/bonding-manager/src/tests/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ fn test_queries() {
extra_fees: vec![],
};

#[cfg(feature = "osmosis")]
let pool_fees = PoolFee {
protocol_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
swap_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
burn_fee: Fee {
share: Decimal::zero(),
},
extra_fees: vec![],
osmosis_fee: Fee {
share: Decimal::permille(1),
},
};

suite
.instantiate_default()
.bond(creator.clone(), &coins(1_000u128, "ampWHALE"), |result| {
Expand Down
17 changes: 17 additions & 0 deletions contracts/liquidity_hub/bonding-manager/src/tests/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ fn test_fill_rewards_from_pool_manager() {
extra_fees: vec![],
};

#[cfg(feature = "osmosis")]
let pool_fees = PoolFee {
protocol_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
swap_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
burn_fee: Fee {
share: Decimal::zero(),
},
extra_fees: vec![],
osmosis_fee: Fee {
share: Decimal::permille(1),
},
};

suite
.instantiate_default()
.fast_forward(90_000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ fn test_unbonding_withdraw() {
extra_fees: vec![],
};

#[cfg(feature = "osmosis")]
let pool_fees = PoolFee {
protocol_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
swap_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
burn_fee: Fee {
share: Decimal::zero(),
},
extra_fees: vec![],
osmosis_fee: Fee {
share: Decimal::permille(1),
},
};

suite
.instantiate_default()
.bond(creator.clone(), &coins(1_000u128, "ampWHALE"), |result| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
cc 55857276de2241e3d09d36aba47854e0017db66f6c5a61e306b38ad0d3b8aeeb # shrinks to amp_factor = 1, initial_user_token_a_amount = 10000000, initial_user_token_b_amount = 10000000
cc 33456e9a9f11bed69ac5171155ce7a64f73f912fcbfede19046989302d1b2da9 # shrinks to amp_factor = 10, deposit_amount_a = 0, deposit_amount_b = 0, deposit_amount_c = 0, swap_token_a_amount = 0, swap_token_b_amount = 0, swap_token_c_amount = 1, pool_token_supply = 0
cc 75c3b0922c450b034b92dc8c2ea87edff47c90bbede702d84c9fd9c672e2f31f # shrinks to amp_factor = 141, deposit_amount_a = 308442737939502983046195411808336, deposit_amount_b = 0, deposit_amount_c = 0, swap_token_a_amount = 870112623450347049437652954298478, swap_token_b_amount = 501497230776538877048085549853566, swap_token_c_amount = 24063806364666791266594852039507, pool_token_supply = 2
cc 0e8058d82bcea9791825f64915edb7336ff8f46a9e5400f9a035f2602838fb96 # shrinks to amp_factor = 139040, source_token_amount = 2201422791601550300438305308643575, swap_source_amount = 0, swap_destination_amount = 0, unswapped_amount = 0
116 changes: 97 additions & 19 deletions contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn deposit_and_withdraw_sanity_check() {
share: Decimal::zero(),
},
osmosis_fee: Fee {
share: Decimal::zero(),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -250,8 +250,9 @@ mod pool_creation_failures {
);
}

// Wrong osmosis fee on pool creation; 0.01 instead of 0.001
#[test]
fn cant_recreate_existing_poo() {
fn wrong_osmosis_fee_on_pool_creation() {
let mut suite = TestingSuite::default_with_balances(vec![
coin(1_000_000_001u128, "uwhale".to_string()),
coin(1_000_000_000u128, "uluna".to_string()),
Expand Down Expand Up @@ -290,11 +291,88 @@ mod pool_creation_failures {
share: Decimal::zero(),
},
osmosis_fee: Fee {
share: Decimal::permille(1),
},
extra_fees: vec![],
};
// Create a pool
suite
.instantiate_default()
.add_one_day()
.create_new_epoch(|result| {
result.unwrap();
})
.create_pool(
creator.clone(),
asset_infos,
vec![6u8, 6u8],
pool_fees,
PoolType::ConstantProduct,
None,
vec![coin(1000, "uusd")],
|result| {
#[cfg(feature = "osmosis")]
{
let err = result.unwrap_err().downcast::<ContractError>().unwrap();
match err {
ContractError::InvalidPoolCreationFee { .. } => {}
_ => panic!(
"Wrong error type, should return ContractError::InvalidPoolCreationFee"
),
}
}
#[cfg(not(feature = "osmosis"))]
result.unwrap();

},
);
}

#[test]
fn cant_recreate_existing_poo() {
let mut suite = TestingSuite::default_with_balances(vec![
coin(1_000_000_001u128, "uwhale".to_string()),
coin(1_000_000_000u128, "uluna".to_string()),
coin(1_000_000_001u128, "uusd".to_string()),
]);
let creator = suite.creator();
let _other = suite.senders[1].clone();
let _unauthorized = suite.senders[2].clone();
// Asset infos with uwhale and cw20

let asset_infos = vec!["uwhale".to_string()];

#[cfg(not(feature = "osmosis"))]
let pool_fees = PoolFee {
protocol_fee: Fee {
share: Decimal::zero(),
},
swap_fee: Fee {
share: Decimal::zero(),
},
burn_fee: Fee {
share: Decimal::zero(),
},
extra_fees: vec![],
};

#[cfg(feature = "osmosis")]
let pool_fees = PoolFee {
protocol_fee: Fee {
share: Decimal::zero(),
},
swap_fee: Fee {
share: Decimal::zero(),
},
burn_fee: Fee {
share: Decimal::zero(),
},
osmosis_fee: Fee {
share: Decimal::permille(1),
},
extra_fees: vec![],
};

// Create a poo
suite
.instantiate_default()
Expand Down Expand Up @@ -334,7 +412,7 @@ mod pool_creation_failures {
}

mod router {
use cosmwasm_std::{Event, StdError};
use cosmwasm_std::{assert_approx_eq, Event, StdError};

use white_whale_std::pool_manager::{SwapRoute, SwapRouteCreatorResponse};

Expand Down Expand Up @@ -380,7 +458,7 @@ mod router {
share: Decimal::bps(50),
},
osmosis_fee: Fee {
share: Decimal::bps(50),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -578,7 +656,7 @@ mod router {
share: Decimal::zero(),
},
osmosis_fee: Fee {
share: Decimal::from_ratio(1u128, 100_000u128),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -726,7 +804,7 @@ mod router {
share: Decimal::zero(),
},
osmosis_fee: Fee {
share: Decimal::from_ratio(1u128, 100_000u128),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -890,7 +968,7 @@ mod router {
share: Decimal::zero(),
},
osmosis_fee: Fee {
share: Decimal::from_ratio(1u128, 100_000u128),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -1123,7 +1201,7 @@ mod router {
share: Decimal::bps(50),
},
osmosis_fee: Fee {
share: Decimal::bps(50),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -1294,7 +1372,7 @@ mod router {
share: Decimal::bps(50),
},
osmosis_fee: Fee {
share: Decimal::bps(50),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -1464,7 +1542,7 @@ mod router {
share: Decimal::bps(50),
},
osmosis_fee: Fee {
share: Decimal::bps(50),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -1666,7 +1744,7 @@ mod router {
share: Decimal::bps(50),
},
osmosis_fee: Fee {
share: Decimal::bps(50),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -1826,7 +1904,7 @@ mod router {
swap_operations.clone(),
|result| {
let result = result.unwrap();
assert_eq!(result.amount.u128(), 1_007);
assert_approx_eq!(result.amount.u128(), 1_007, "0.1");
},
);

Expand Down Expand Up @@ -1892,7 +1970,7 @@ mod swapping {
share: Decimal::zero(),
},
osmosis_fee: Fee {
share: Decimal::from_ratio(1u128, 100_000u128),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -2319,7 +2397,7 @@ mod swapping {
share: Decimal::zero(),
},
osmosis_fee: Fee {
share: Decimal::zero(),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -2415,7 +2493,7 @@ mod swapping {
assert_approx_eq!(
offer_amount.parse::<u128>().unwrap(),
return_amount.parse::<u128>().unwrap(),
"0.01"
"0.011"
);
},
);
Expand Down Expand Up @@ -2615,7 +2693,7 @@ mod locking_lp {
share: Decimal::zero(),
},
osmosis_fee: Fee {
share: Decimal::zero(),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -2811,7 +2889,7 @@ mod locking_lp {
share: Decimal::zero(),
},
osmosis_fee: Fee {
share: Decimal::zero(),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -3014,7 +3092,7 @@ mod provide_liquidity {
share: Decimal::zero(),
},
osmosis_fee: Fee {
share: Decimal::zero(),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down Expand Up @@ -3469,7 +3547,7 @@ mod provide_liquidity {
share: Decimal::zero(),
},
osmosis_fee: Fee {
share: Decimal::percent(10),
share: Decimal::permille(1),
},
extra_fees: vec![],
};
Expand Down
Loading

0 comments on commit 042b3f5

Please sign in to comment.