Skip to content

Commit

Permalink
Fix swap_out and bump version to v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
icodezjb committed Nov 17, 2022
1 parent 13f3c53 commit 9865cb0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Move.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'swap'
version = '1.0.2'
version = '1.0.3'
license = "Apache-2.0"
upgrade_policy = "compatible"

Expand Down
2 changes: 1 addition & 1 deletion init/Move.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'init'
version = '1.0.2'
version = '1.0.3'
license = "Apache-2.0"
upgrade_policy = "compatible"

Expand Down
2 changes: 1 addition & 1 deletion lp/Move.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'lp'
version = '1.0.2'
version = '1.0.3'
license = "Apache-2.0"
upgrade_policy = "compatible"

Expand Down
6 changes: 2 additions & 4 deletions sources/implements.move
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,8 @@ module swap::implements {
) acquires LiquidityPool, Config {
let fee_multiplier = FEE_MULTIPLIER / 5; // 20% fee to swap fundation.
let fee_value = math::mul_div(coin_in_value, fee_multiplier, FEE_SCALE);
let coin_in_after_fee = coin_in_value - math::mul_div(coin_in_value, FEE_MULTIPLIER, FEE_SCALE);

let coin_out_value = get_amount_out(coin_in_after_fee, reserve_in, reserve_out);
let coin_out_value = get_amount_out(coin_in_value, reserve_in, reserve_out);
assert!(coin_out_value >= coin_out_min_value, ERR_COIN_OUT_NUM_LESS_THAN_EXPECTED_MINIMUM, );

let pool_address = pool_address();
Expand Down Expand Up @@ -401,9 +400,8 @@ module swap::implements {
) acquires LiquidityPool, Config {
let fee_multiplier = FEE_MULTIPLIER / 5; // 20% fee to swap fundation.
let fee_value = math::mul_div(coin_in_value, fee_multiplier, FEE_SCALE);
let coin_in_after_fee = coin_in_value - math::mul_div(coin_in_value, FEE_MULTIPLIER, FEE_SCALE);

let coin_out_value = get_amount_out(coin_in_after_fee, reserve_in, reserve_out);
let coin_out_value = get_amount_out(coin_in_value, reserve_in, reserve_out);
assert!(coin_out_value >= coin_out_min_value, ERR_COIN_OUT_NUM_LESS_THAN_EXPECTED_MINIMUM, );

let pool_address = pool_address();
Expand Down
14 changes: 7 additions & 7 deletions tests/interface_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ module swap::interface_tests {

let (reserve_usdt, reserve_xbtc) = implements::get_reserves_size<USDT, XBTC>();
let expected_xbtc = implements::get_amount_out(
(usdt_val / 100 * 997 / 1000),
(usdt_val / 100),
reserve_usdt,
reserve_xbtc
);
Expand Down Expand Up @@ -481,7 +481,7 @@ module swap::interface_tests {
let (reserve_usdt, reserve_xbtc) = implements::get_reserves_size<USDT, XBTC>();

let _expected_xbtc = implements::get_amount_out(
(math::mul_div(max_usdt, 997, 1000)),
max_usdt,
reserve_usdt,
reserve_xbtc
);
Expand Down Expand Up @@ -522,11 +522,11 @@ module swap::interface_tests {
assert!(70100 == reserve_xbtc, reserve_xbtc);

let expected_btc = implements::get_amount_out(
usdt_val - math::mul_div(usdt_val, 3, 1000),
usdt_val,
reserve_usdt,
reserve_xbtc
);
assert!(34944 == expected_btc, expected_btc);
assert!(34997 == expected_btc, expected_btc);

interface::swap<USDT, XBTC>(
&user_account,
Expand All @@ -535,17 +535,17 @@ module swap::interface_tests {
);
let (reserve_usdt, reserve_xbtc) = implements::get_reserves_size<USDT, XBTC>();
assert!(368802061 == reserve_usdt, reserve_usdt);
assert!(35156 == reserve_xbtc, reserve_xbtc);
assert!(35103 == reserve_xbtc, reserve_xbtc);

assert!(coin::balance<XBTC>(user) == xbtc_val + expected_btc, coin::balance<XBTC>(user));
assert!(coin::balance<USDT>(user) == 0, coin::balance<USDT>(user));

let expected_usdt = implements::get_amount_out(
xbtc_val - math::mul_div(xbtc_val, 3, 1000),
xbtc_val,
reserve_xbtc,
reserve_usdt
);
assert!(245127326 == expected_usdt, expected_usdt);
assert!(245497690 == expected_usdt, expected_usdt);

interface::swap<XBTC, USDT>(
&user_account,
Expand Down

0 comments on commit 9865cb0

Please sign in to comment.