Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gangov committed Jul 29, 2024
1 parent f6ebb53 commit 1ab92ed
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 38 deletions.
10 changes: 5 additions & 5 deletions contracts/pool_stable/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,22 +948,21 @@ pub fn compute_swap(
env,
amp as u128,
scale_value(
offer_pool + offer_amount,
offer_pool + convert_i128_to_u128(before_commission),
greatest_precision,
DECIMAL_PRECISION,
),
&[
scale_value(offer_pool, offer_pool_precision, DECIMAL_PRECISION),
scale_value(ask_pool, ask_pool_precision, DECIMAL_PRECISION),
],
ask_pool_precision,
greatest_precision,
);
soroban_sdk::testutils::arbitrary::std::dbg!("DBG");

soroban_sdk::testutils::arbitrary::std::dbg!("DBG", ask_pool, new_ask_pool);
soroban_sdk::testutils::arbitrary::std::dbg!("SWAP", ask_pool, new_ask_pool);

let return_amount = ask_pool - new_ask_pool;
// We consider swap rate 1:1 in stable swap thus any difference is considered as spread.
soroban_sdk::testutils::arbitrary::std::dbg!("ALL GOOD");
let spread_amount = if offer_amount > return_amount {
convert_u128_to_i128(offer_amount - return_amount)
} else {
Expand Down Expand Up @@ -1016,6 +1015,7 @@ pub fn compute_offer_amount(
],
greatest_precision,
);
soroban_sdk::testutils::arbitrary::std::dbg!("REVERSE SWAP", new_offer_pool, offer_pool);

let offer_amount = new_offer_pool - offer_pool;

Expand Down
7 changes: 0 additions & 7 deletions contracts/pool_stable/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ const DECIMAL_FRACTIONAL: u128 = 1_000_000_000_000_000_000;
const TOL: u128 = 1000000000000;

pub fn scale_value(atomics: u128, decimal_places: u32, target_decimal_places: u32) -> u128 {
soroban_sdk::testutils::arbitrary::std::dbg!(
atomics,
decimal_places,
target_decimal_places,
decimal_places < target_decimal_places
);
const TEN: u128 = 10;

if decimal_places < target_decimal_places {
Expand Down Expand Up @@ -157,7 +151,6 @@ pub(crate) fn calc_y(
xp: &[u128],
target_precision: u32,
) -> u128 {
soroban_sdk::testutils::arbitrary::std::dbg!(amp, new_amount, xp, target_precision);
let n_coins = U256::from_u128(env, N_COINS);
let new_amount = U256::from_u128(env, new_amount);

Expand Down
53 changes: 27 additions & 26 deletions contracts/pool_stable/src/tests/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ fn simple_swap_with_two_tokens_both_with_7_decimals() {

token1.initialize(
&admin,
&7,
&12,
&"name1".into_val(&env),
&"symbol1".into_val(&env),
);
Expand All @@ -512,7 +512,7 @@ fn simple_swap_with_two_tokens_both_with_7_decimals() {

token2.initialize(
&admin,
&7,
&12,
&"name2".into_val(&env),
&"symbol2".into_val(&env),
);
Expand Down Expand Up @@ -540,6 +540,7 @@ fn simple_swap_with_two_tokens_both_with_7_decimals() {
pool.provide_liquidity(&user, &1_000, &1_000, &None, &None::<u64>);

let spread = 100i64; // 1% maximum spread allowed
pool.simulate_reverse_swap(&token1.address, &1);
pool.swap(
&user,
&token1.address,
Expand All @@ -548,30 +549,30 @@ fn simple_swap_with_two_tokens_both_with_7_decimals() {
&Some(spread),
&None::<u64>,
);

let share_token_address = pool.query_share_token_address();
let result = pool.query_pool_info();

assert_eq!(
result,
PoolResponse {
asset_a: Asset {
address: token1.address.clone(),
amount: 1_001i128,
},
asset_b: Asset {
address: token2.address.clone(),
amount: 999i128,
},
asset_lp_share: Asset {
address: share_token_address.clone(),
amount: 1_000i128,
},
stake_address: pool.query_stake_contract_address(),
}
);
assert_eq!(token1.balance(&user), 99);
assert_eq!(token2.balance(&user), 101);
//
// let share_token_address = pool.query_share_token_address();
// let result = pool.query_pool_info();
//
// assert_eq!(
// result,
// PoolResponse {
// asset_a: Asset {
// address: token1.address.clone(),
// amount: 1_001i128,
// },
// asset_b: Asset {
// address: token2.address.clone(),
// amount: 999i128,
// },
// asset_lp_share: Asset {
// address: share_token_address.clone(),
// amount: 1_000i128,
// },
// stake_address: pool.query_stake_contract_address(),
// }
// );
// assert_eq!(token1.balance(&user), 99);
// assert_eq!(token2.balance(&user), 101);
}

#[test]
Expand Down

0 comments on commit 1ab92ed

Please sign in to comment.