Skip to content

Commit

Permalink
test: fix max spread assetion in single-side lp test
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed May 1, 2024
1 parent 26d63dd commit a694b5d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 17 deletions.
6 changes: 4 additions & 2 deletions contracts/liquidity_hub/pool-manager/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::error::ContractError;
use crate::helpers::{reverse_simulate_swap_operations, simulate_swap_operations, validate_asset_balance};
use crate::helpers::{
reverse_simulate_swap_operations, simulate_swap_operations, validate_asset_balance,
};
use crate::queries::{get_pair, get_swap_route, get_swap_route_creator, get_swap_routes};
use crate::router::commands::{add_swap_routes, remove_swap_routes};
use crate::state::{
Config, SingleSideLiquidityProvisionBuffer, MANAGER_CONFIG, PAIRS, PAIR_COUNTER,
Config, SingleSideLiquidityProvisionBuffer, MANAGER_CONFIG, PAIR_COUNTER,
TMP_SINGLE_SIDE_LIQUIDITY_PROVISION,
};
use crate::{liquidity, manager, queries, router, swap};
Expand Down
4 changes: 2 additions & 2 deletions contracts/liquidity_hub/pool-manager/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::cmp::Ordering;
use cosmwasm_std::{Coin, Decimal256, Deps, Env, Fraction, Order, StdResult, Uint128};

use white_whale_std::pool_manager::{
AssetDecimalsResponse, Config, ReverseSimulationResponse, SimulationResponse, PairInfoResponse, SwapRoute, SwapRouteCreatorResponse,
SwapRouteResponse, SwapRoutesResponse,
AssetDecimalsResponse, Config, PairInfoResponse, ReverseSimulationResponse, SimulationResponse,
SwapRoute, SwapRouteCreatorResponse, SwapRouteResponse, SwapRoutesResponse,
};
use white_whale_std::pool_network::asset::PairType;

Expand Down
77 changes: 66 additions & 11 deletions contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ fn deposit_and_withdraw_sanity_check() {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand Down Expand Up @@ -405,6 +406,7 @@ mod router {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand All @@ -428,6 +430,7 @@ mod router {
"uluna-uusd".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uluna".to_string(),
Expand Down Expand Up @@ -596,6 +599,7 @@ mod router {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand All @@ -619,6 +623,7 @@ mod router {
"uluna-uusd".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uluna".to_string(),
Expand Down Expand Up @@ -737,6 +742,7 @@ mod router {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand All @@ -760,6 +766,7 @@ mod router {
"uluna-uusd".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uluna".to_string(),
Expand Down Expand Up @@ -895,6 +902,7 @@ mod router {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand All @@ -918,6 +926,7 @@ mod router {
"uluna-uusd".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uluna".to_string(),
Expand Down Expand Up @@ -1119,6 +1128,7 @@ mod router {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand All @@ -1142,6 +1152,7 @@ mod router {
"uluna-uusd".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uluna".to_string(),
Expand Down Expand Up @@ -1280,6 +1291,7 @@ mod router {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand All @@ -1299,6 +1311,7 @@ mod router {
"uluna-uusd".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uluna".to_string(),
Expand Down Expand Up @@ -1442,6 +1455,7 @@ mod router {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand All @@ -1461,6 +1475,7 @@ mod router {
"uluna-uusd".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uluna".to_string(),
Expand Down Expand Up @@ -1638,6 +1653,7 @@ mod router {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand All @@ -1661,6 +1677,7 @@ mod router {
"uluna-uusd".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uluna".to_string(),
Expand Down Expand Up @@ -1847,6 +1864,7 @@ mod swapping {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand Down Expand Up @@ -2068,6 +2086,7 @@ mod swapping {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand Down Expand Up @@ -2268,6 +2287,7 @@ mod swapping {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand Down Expand Up @@ -2565,6 +2585,7 @@ mod locking_lp {
"whale-uluna".to_string(),
Some(86_400u64),
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand Down Expand Up @@ -2630,6 +2651,7 @@ mod locking_lp {
"whale-uluna".to_string(),
Some(200_000u64),
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand Down Expand Up @@ -2752,6 +2774,7 @@ mod locking_lp {
"whale-uluna".to_string(),
Some(86_400u64),
Some("incentive_identifier".to_string()),
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand Down Expand Up @@ -2817,6 +2840,7 @@ mod locking_lp {
"whale-uluna".to_string(),
Some(200_000u64),
Some("incentive_identifier".to_string()),
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand Down Expand Up @@ -2863,7 +2887,7 @@ mod locking_lp {
}

mod provide_liquidity {
use cosmwasm_std::{coin, Coin, Decimal, Uint128};
use cosmwasm_std::{coin, Coin, Decimal, StdError, Uint128};

use white_whale_std::fee::{Fee, PoolFee};
use white_whale_std::pool_network::asset::MINIMUM_LIQUIDITY_AMOUNT;
Expand Down Expand Up @@ -2942,6 +2966,7 @@ mod provide_liquidity {
"whale-uluna".to_string(),
None,
None,
None,
vec![],
|result| {
let err = result.unwrap_err().downcast::<ContractError>().unwrap();
Expand All @@ -2957,6 +2982,7 @@ mod provide_liquidity {
"whale-uluna".to_string(),
None,
None,
None,
vec![Coin {
denom: "uosmo".to_string(),
amount: Uint128::from(1_000_000u128),
Expand All @@ -2975,6 +3001,7 @@ mod provide_liquidity {
"whale-uluna".to_string(),
None,
None,
None,
vec![Coin {
denom: "uwhale".to_string(),
amount: Uint128::from(1_000_000u128),
Expand All @@ -2998,6 +3025,7 @@ mod provide_liquidity {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uosmo".to_string(),
Expand All @@ -3022,6 +3050,7 @@ mod provide_liquidity {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand Down Expand Up @@ -3059,6 +3088,7 @@ mod provide_liquidity {
"whale-uluna".to_string(),
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
Expand All @@ -3069,6 +3099,31 @@ mod provide_liquidity {
amount: Uint128::from(1_000_000u128),
},
],
|result| {
let err = result.unwrap_err().downcast::<ContractError>().unwrap();

assert_eq!(
err,
ContractError::Std(StdError::generic_err("Spread limit exceeded"))
);
},
)
.provide_liquidity(
other.clone(),
"whale-uluna".to_string(),
None,
None,
Some(Decimal::percent(50)),
vec![
Coin {
denom: "uwhale".to_string(),
amount: Uint128::from(500_000u128),
},
Coin {
denom: "uwhale".to_string(),
amount: Uint128::from(500_000u128),
},
],
|result| {
result.unwrap();
},
Expand Down Expand Up @@ -3109,8 +3164,8 @@ mod provide_liquidity {
.find(|coin| coin.denom == "uluna".to_string())
.unwrap();

assert_eq!(whale.amount, Uint128::from(3_000_000u128));
assert_eq!(luna.amount, Uint128::from(995_000u128));
assert_eq!(whale.amount, Uint128::from(2_000_000u128));
assert_eq!(luna.amount, Uint128::from(996_667u128));
});

let pool_manager = suite.pool_manager_addr.clone();
Expand All @@ -3127,11 +3182,11 @@ mod provide_liquidity {
},
Coin {
denom: "uluna".to_string(),
amount: Uint128::from(995_000u128),
amount: Uint128::from(996_667u128),
},
Coin {
denom: "uwhale".to_string(),
amount: Uint128::from(3_000_000u128),
amount: Uint128::from(2_000_000u128),
},
]
);
Expand Down Expand Up @@ -3182,7 +3237,7 @@ mod provide_liquidity {
vec![
Coin {
denom: "uluna".to_string(),
amount: Uint128::from(9_497_002u128),
amount: Uint128::from(9_497_835u128),
},
Coin {
denom: "uosmo".to_string(),
Expand All @@ -3194,7 +3249,7 @@ mod provide_liquidity {
},
Coin {
denom: "uwhale".to_string(),
amount: Uint128::from(10_498_500u128),
amount: Uint128::from(9_999_000u128),
},
]
);
Expand Down Expand Up @@ -3226,7 +3281,7 @@ mod provide_liquidity {
},
Coin {
denom: "uwhale".to_string(),
amount: Uint128::from(8_000_000u128),
amount: Uint128::from(9_000_000u128),
},
]
);
Expand All @@ -3249,7 +3304,7 @@ mod provide_liquidity {
vec![
Coin {
denom: "uluna".to_string(),
amount: Uint128::from(10_497_500u128),
amount: Uint128::from(10_498_333u128),
},
Coin {
denom: "uosmo".to_string(),
Expand All @@ -3261,7 +3316,7 @@ mod provide_liquidity {
},
Coin {
denom: "uwhale".to_string(),
amount: Uint128::from(9_499_999u128),
amount: Uint128::from(9_999_999u128),
},
]
);
Expand All @@ -3275,7 +3330,7 @@ mod provide_liquidity {
vec![
Coin {
denom: "uluna".to_string(),
amount: Uint128::from(5_000u128),
amount: Uint128::from(3_333u128),
},
Coin {
denom: "uusd".to_string(),
Expand Down
Loading

0 comments on commit a694b5d

Please sign in to comment.