Skip to content

Commit

Permalink
Pool, Multihop: lints
Browse files Browse the repository at this point in the history
  • Loading branch information
gangov committed Dec 5, 2023
1 parent 690f7a7 commit 9354ad8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
31 changes: 24 additions & 7 deletions contracts/multihop/src/tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ fn simulate_swap_single_pool_no_fees() {
assert_eq!(result.total_commission_amount, 0i128);
assert_eq!(result.spread_amount, vec![&env, 0i128]);


// simulate reverse swap for exact results
let reverse_simulated_swap = multihop.simulate_reverse_swap(&operation, &2_000i128);

Expand Down Expand Up @@ -127,7 +126,10 @@ fn simulate_swap_three_equal_pools_no_fees() {

assert_eq!(simulated_swap.ask_amount, 50i128);
assert_eq!(simulated_swap.total_commission_amount, 0i128);
assert_eq!(simulated_swap.spread_amount, vec![&env, 0i128, 0i128, 0i128]);
assert_eq!(
simulated_swap.spread_amount,
vec![&env, 0i128, 0i128, 0i128]
);

// simulate reverse swap for exact results
let reverse_simulated_swap = multihop.simulate_reverse_swap(
Expand All @@ -151,7 +153,10 @@ fn simulate_swap_three_equal_pools_no_fees() {

assert_eq!(reverse_simulated_swap.offer_amount, 50i128);
assert_eq!(reverse_simulated_swap.total_commission_amount, 0i128);
assert_eq!(reverse_simulated_swap.spread_amount, vec![&env, 0i128, 0i128, 0i128]);
assert_eq!(
reverse_simulated_swap.spread_amount,
vec![&env, 0i128, 0i128, 0i128]
);
}

#[test]
Expand Down Expand Up @@ -276,7 +281,10 @@ fn simulate_swap_three_different_pools_no_fees() {
// constant product formula starts to with which amoutns such as 5k
assert_eq!(simulated_swap.ask_amount, 4_956i128);
assert_eq!(simulated_swap.total_commission_amount, 0i128);
assert_eq!(simulated_swap.spread_amount, vec![&env, 24i128, 12i128, 8i128]);
assert_eq!(
simulated_swap.spread_amount,
vec![&env, 24i128, 12i128, 8i128]
);

// simulate reverse swap returns same result
let reverse_simulated_swap = multihop.simulate_reverse_swap(
Expand All @@ -300,7 +308,10 @@ fn simulate_swap_three_different_pools_no_fees() {

assert_eq!(reverse_simulated_swap.offer_amount, 5_000i128);
assert_eq!(reverse_simulated_swap.total_commission_amount, 0i128);
assert_eq!(reverse_simulated_swap.spread_amount, vec![&env, 8i128, 12i128, 24i128]);
assert_eq!(
reverse_simulated_swap.spread_amount,
vec![&env, 8i128, 12i128, 24i128]
);
}

#[test]
Expand Down Expand Up @@ -397,7 +408,10 @@ fn simulate_swap_three_different_pools_with_fees() {
assert_eq!(simulated_swap.ask_amount, 203_143i128);
// total_commission_amount = 1_980 + 5_253 + 22_571 = 29_804
assert_eq!(simulated_swap.total_commission_amount, 29_804i128);
assert_eq!(simulated_swap.spread_amount, vec![&env, 198i128, 936i128, 10671i128]);
assert_eq!(
simulated_swap.spread_amount,
vec![&env, 198i128, 936i128, 10671i128]
);

// simulate reverse swap returns same result
let reverse_simulated_swap = multihop.simulate_reverse_swap(
Expand All @@ -422,7 +436,10 @@ fn simulate_swap_three_different_pools_with_fees() {
// one difference due to rounding
assert_eq!(reverse_simulated_swap.offer_amount, 9_999i128);
assert_eq!(reverse_simulated_swap.total_commission_amount, 29_803i128);
assert_eq!(reverse_simulated_swap.spread_amount, vec![&env, 10671i128, 934i128, 197i128]);
assert_eq!(
reverse_simulated_swap.spread_amount,
vec![&env, 10671i128, 934i128, 197i128]
);
}

#[test]
Expand Down
10 changes: 4 additions & 6 deletions contracts/pool/src/tests/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,6 @@ fn test_swap_fee_variants(swap_fees: i64, fee_percentage: i64, commission_fee: i
std::mem::swap(&mut token1, &mut token2);
}

let swap_fees = swap_fees; // 10% bps
let pool = deploy_liquidity_pool_contract(
&env,
None,
Expand Down Expand Up @@ -688,13 +687,12 @@ fn test_swap_fee_variants(swap_fees: i64, fee_percentage: i64, commission_fee: i
// Y_new = 991020024.637
// Y_rnd = 991020025
let output_amount = 991020025; // rounding
let fees;

if swap_fees < 100 {
fees = Decimal::bps(fee_percentage) * output_amount;
let fees = if swap_fees < 100 {
Decimal::bps(fee_percentage) * output_amount
} else {
fees = Decimal::percent(fee_percentage) * output_amount;
}
Decimal::percent(fee_percentage) * output_amount
};

assert_eq!(
result,
Expand Down

0 comments on commit 9354ad8

Please sign in to comment.