Skip to content

Commit

Permalink
Update to latest Aptos (#138)
Browse files Browse the repository at this point in the history
* updated error codes to constants

* Fix router v2 tests with constants

* Fix curves tests for common style of error codes

* Fix CLI version for CI and README
  • Loading branch information
borispovod authored Jan 8, 2023
1 parent 985ee1f commit d779298
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 161 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Get Aptos
uses: pontem-network/get-aptos@main
with:
version: aptos-cli-v1.0.0
version: aptos-cli-v1.0.3
token: ${{ secrets.GITHUB_TOKEN }}
prover: true

Expand Down
2 changes: 1 addition & 1 deletion Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ local = "./liquidswap_init/"

[dependencies.AptosFramework]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "main"
rev = "mainnet"
subdir = "aptos-move/framework/aptos-framework"

[dependencies.UQ64x64]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To integrate Liquidswap into your project vist [integration](https://docs.liquid

### Build

**Important:** we recommend Aptos CLI v1.0.0, as the newest version contains bugs related to dependencies resolving.
**Important:** we recommend Aptos CLI v1.0.3.

[Aptos CLI](https://github.com/aptos-labs/aptos-core/releases) required:

Expand Down
2 changes: 1 addition & 1 deletion liquidswap_init/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ liquidswap = "0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12

[dependencies.AptosFramework]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "main"
rev = "mainnet"
subdir = "aptos-move/framework/aptos-framework"
2 changes: 1 addition & 1 deletion liquidswap_lp/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ liquidswap_lp = "0x05a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c

[dev-dependencies.MoveStdlib]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "main"
rev = "mainnet"
subdir = "aptos-move/framework/move-stdlib"
4 changes: 2 additions & 2 deletions liquidswap_router_v2/sources/router_v2.move
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ module liquidswap::router_v2 {
const ERR_WRONG_AMOUNT: u64 = 200;
/// Wrong reserve used.
const ERR_WRONG_RESERVE: u64 = 201;
/// Wrong order of coin parameters.
const ERR_WRONG_COIN_ORDER: u64 = 208;
/// Insufficient amount in Y reserves.
const ERR_INSUFFICIENT_Y_AMOUNT: u64 = 202;
/// Insufficient amount in X reserves.
Expand All @@ -31,6 +29,8 @@ module liquidswap::router_v2 {
const ERR_UNREACHABLE: u64 = 207;
/// Provided coins amount cannot be converted without the overflow at the current price
const ERR_COIN_CONVERSION_OVERFLOW: u64 = 208;
/// Wrong order of coin parameters.
const ERR_WRONG_COIN_ORDER: u64 = 208;

// Consts
const MAX_U64: u128 = 18446744073709551615;
Expand Down
52 changes: 26 additions & 26 deletions liquidswap_router_v2/tests/router_v2_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 208)]
#[expected_failure(abort_code = router_v2::ERR_WRONG_COIN_ORDER)]
fun test_cannot_add_liquidity_to_pool_in_reverse_order() {
let (coin_admin, lp_owner) = register_pool_with_liquidity(101, 10100);

Expand All @@ -133,7 +133,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 203)]
#[expected_failure(abort_code = router_v2::ERR_INSUFFICIENT_X_AMOUNT)]
fun test_add_liquidity_to_fail_with_insufficient_x_coins() {
let (coin_admin, lp_owner) = register_pool_with_liquidity(0, 0);

Expand All @@ -153,7 +153,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 202)]
#[expected_failure(abort_code = router_v2::ERR_INSUFFICIENT_Y_AMOUNT)]
fun test_add_liquidity_to_fail_with_insufficient_y_coins() {
let (coin_admin, lp_owner) = register_pool_with_liquidity(0, 0);

Expand Down Expand Up @@ -204,7 +204,7 @@ module liquidswap::router_v2_tests {
// (it's checked with generic params, so I don't know)

#[test]
#[expected_failure(abort_code = 205)]
#[expected_failure(abort_code = router_v2::ERR_COIN_OUT_NUM_LESS_THAN_EXPECTED_MINIMUM)]
fun test_remove_liquidity_to_fail_if_less_than_minimum_x() {
let (_, lp_owner) = register_pool_with_liquidity(101, 10100);

Expand All @@ -223,7 +223,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 205)]
#[expected_failure(abort_code = router_v2::ERR_COIN_OUT_NUM_LESS_THAN_EXPECTED_MINIMUM)]
fun test_remove_liquidity_to_fail_if_less_than_minimum_y() {
let (_, lp_owner) = register_pool_with_liquidity(101, 10100);

Expand Down Expand Up @@ -310,7 +310,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 205)]
#[expected_failure(abort_code = router_v2::ERR_COIN_OUT_NUM_LESS_THAN_EXPECTED_MINIMUM)]
fun test_swap_exact_coin_for_coin_to_fail_if_less_than_minimum_out() {
let (coin_admin, _) = register_pool_with_liquidity(101, 10100);

Expand Down Expand Up @@ -389,7 +389,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 206)]
#[expected_failure(abort_code = router_v2::ERR_COIN_VAL_MAX_LESS_THAN_NEEDED)]
fun test_swap_coin_for_exact_coin_router_check_fails() {
let (coin_admin, _) = register_pool_with_liquidity(10000000000, 2800000000000);

Expand Down Expand Up @@ -430,7 +430,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 205)]
#[expected_failure(abort_code = router_v2::ERR_COIN_OUT_NUM_LESS_THAN_EXPECTED_MINIMUM)]
fun test_fail_if_price_fell_behind_threshold() {
let (coin_admin, lp_owner) = register_pool_with_liquidity(101, 10100);

Expand All @@ -448,7 +448,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 104)]
#[expected_failure(abort_code = liquidity_pool::ERR_EMPTY_COIN_IN)]
fun test_fail_if_swap_zero_coin() {
let (coin_admin, lp_owner) = register_pool_with_liquidity(101, 10100);

Expand Down Expand Up @@ -934,19 +934,19 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 200)]
#[expected_failure(abort_code = router_v2::ERR_WRONG_AMOUNT)]
fun test_fail_convert_with_current_price_coin_in_val() {
router_v2::convert_with_current_price(0, 1, 1);
}

#[test]
#[expected_failure(abort_code = 201)]
#[expected_failure(abort_code = router_v2::ERR_WRONG_RESERVE)]
fun test_fail_convert_with_current_price_reserve_in_size() {
router_v2::convert_with_current_price(1, 0, 1);
}

#[test]
#[expected_failure(abort_code = 201)]
#[expected_failure(abort_code = router_v2::ERR_WRONG_RESERVE)]
fun test_fail_convert_with_current_price_reserve_out_size() {
router_v2::convert_with_current_price(1, 1, 0);
}
Expand Down Expand Up @@ -1077,7 +1077,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 105)]
#[expected_failure(abort_code = liquidity_pool::ERR_INCORRECT_SWAP)]
fun test_fail_if_price_fell_behind_threshold_unchecked() {
let (coin_admin, lp_owner) = register_pool_with_liquidity(101, 10100);

Expand All @@ -1095,7 +1095,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 105)]
#[expected_failure(abort_code = liquidity_pool::ERR_INCORRECT_SWAP)]
fun test_stable_fail_if_price_fell_behind_threshold_unchecked() {
let (coin_admin, _) = register_stable_pool_with_liquidity(150000000, 15000000000);

Expand All @@ -1113,7 +1113,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 105)]
#[expected_failure(abort_code = liquidity_pool::ERR_INCORRECT_SWAP)]
fun test_stable_fail_if_price_fell_behind_threshold_unchecked_1() {
let (coin_admin, _) = register_stable_pool_with_liquidity(150000000, 15000000000);

Expand All @@ -1131,7 +1131,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 105)]
#[expected_failure(abort_code = liquidity_pool::ERR_INCORRECT_SWAP)]
fun test_stable_fail_if_price_fell_behind_threshold_unchecked_2() {
let (coin_admin, _) = register_stable_pool_with_liquidity(150000000, 15000000000);

Expand All @@ -1149,7 +1149,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 105)]
#[expected_failure(abort_code = liquidity_pool::ERR_INCORRECT_SWAP)]
fun test_swap_coin_for_coin_unchecked_fails() {
let (coin_admin, _) = register_pool_with_liquidity(10000000000, 2800000000000);

Expand Down Expand Up @@ -1185,7 +1185,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 203)]
#[expected_failure(abort_code = router_v2::ERR_INSUFFICIENT_X_AMOUNT)]
fun test_calc_optimal_coin_values_1() {
// 100 BTC, 2,800,000 USDT
let (_, _) = register_pool_with_liquidity(10000000000, 2800000000000);
Expand Down Expand Up @@ -1215,7 +1215,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 202)]
#[expected_failure(abort_code = router_v2::ERR_INSUFFICIENT_Y_AMOUNT)]
fun test_calc_optimal_coin_values_4() {
// 100 BTC, 28000 USDT
let (_, _) = register_pool_with_liquidity(10000000000, 28000000000);
Expand Down Expand Up @@ -1286,25 +1286,25 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 107)]
#[expected_failure(abort_code = liquidity_pool::ERR_POOL_DOES_NOT_EXIST)]
fun test_get_fees_config_fail_if_pool_does_not_exists() {
router_v2::get_fees_config<BTC, USDT, Uncorrelated>();
}

#[test]
#[expected_failure(abort_code = 107)]
#[expected_failure(abort_code = liquidity_pool::ERR_POOL_DOES_NOT_EXIST)]
fun test_get_fee_fail_if_pool_does_not_exists() {
router_v2::get_fee<BTC, USDT, Uncorrelated>();
}

#[test]
#[expected_failure(abort_code = 107)]
#[expected_failure(abort_code = liquidity_pool::ERR_POOL_DOES_NOT_EXIST)]
fun test_get_dao_fees_config_fail_if_pool_does_not_exists() {
router_v2::get_dao_fees_config<BTC, USDT, Uncorrelated>();
}

#[test]
#[expected_failure(abort_code = 107)]
#[expected_failure(abort_code = liquidity_pool::ERR_POOL_DOES_NOT_EXIST)]
fun test_get_dao_fee_fail_if_pool_does_not_exists() {
router_v2::get_dao_fee<BTC, USDT, Uncorrelated>();
}
Expand Down Expand Up @@ -1342,7 +1342,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 202)]
#[expected_failure(abort_code = router_v2::ERR_INSUFFICIENT_Y_AMOUNT)]
fun test_get_amount_in_aborts_if_coin_out_bigger_than_reserves() {
// 100 BTC, 28000 USDT
let (_, _) = register_pool_with_liquidity(28000000000, 28000000000);
Expand All @@ -1351,7 +1351,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 202)]
#[expected_failure(abort_code = router_v2::ERR_INSUFFICIENT_Y_AMOUNT)]
fun test_get_amount_in_if_coin_out_exactly_equals_reserve_out() {
// 100 BTC, 28000 USDT
let (_, _) = register_pool_with_liquidity(28000000000, 28000000000);
Expand All @@ -1360,7 +1360,7 @@ module liquidswap::router_v2_tests {
}

#[test]
#[expected_failure(abort_code = 208)]
#[expected_failure(abort_code = router_v2::ERR_COIN_CONVERSION_OVERFLOW)]
fun test_add_liquidity_with_imbalanced_reserves() {
// 100 BTC, 28000 USDT
let (coin_admin, lp_owner) = register_pool_with_liquidity(1, 10000000);
Expand Down
2 changes: 1 addition & 1 deletion liquidswap_router_v2/tests/scripts_v2_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ module liquidswap::scripts_v2_tests {
}

#[test]
#[expected_failure(abort_code = 105)]
#[expected_failure(abort_code = liquidity_pool::ERR_INCORRECT_SWAP)]
public entry fun test_unchecked_swap_fails_if_price_better_than_available_requested() {
let (coin_admin, lp_owner) = register_pool_with_existing_liquidity(101, 10100);

Expand Down
4 changes: 2 additions & 2 deletions sources/swap/router.move
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ module liquidswap::router {
const ERR_WRONG_AMOUNT: u64 = 200;
/// Wrong reserve used.
const ERR_WRONG_RESERVE: u64 = 201;
/// Wrong order of coin parameters.
const ERR_WRONG_COIN_ORDER: u64 = 208;
/// Insufficient amount in Y reserves.
const ERR_INSUFFICIENT_Y_AMOUNT: u64 = 202;
/// Insufficient amount in X reserves.
Expand All @@ -31,6 +29,8 @@ module liquidswap::router {
const ERR_COIN_VAL_MAX_LESS_THAN_NEEDED: u64 = 206;
/// Marks the unreachable place in code
const ERR_UNREACHABLE: u64 = 207;
/// Wrong order of coin parameters.
const ERR_WRONG_COIN_ORDER: u64 = 208;

// Public functions.

Expand Down
4 changes: 2 additions & 2 deletions tests/coin_helper_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ module liquidswap::coin_helper_tests {
}

#[test]
#[expected_failure(abort_code = 3001)]
#[expected_failure(abort_code = coin_helper::ERR_IS_NOT_COIN)]
fun test_assert_is_coin_failure() {
coin_helper::assert_is_coin<USDT>();
}

#[test]
#[expected_failure(abort_code = 3000)]
#[expected_failure(abort_code = coin_helper::ERR_CANNOT_BE_THE_SAME_COIN)]
fun test_cant_be_same_coin_failure() {
genesis::setup();

Expand Down
2 changes: 1 addition & 1 deletion tests/compare_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module liquidswap::compare_tests {
}

#[test]
#[expected_failure(abort_code = 3000)]
#[expected_failure(abort_code = coin_helper::ERR_CANNOT_BE_THE_SAME_COIN)]
fun test_is_sorted_cannot_be_equal() {
assert!(coin_helper::is_sorted<AptosCoin, AptosCoin>(), 1);
}
Expand Down
12 changes: 10 additions & 2 deletions tests/curves_tests.move
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#[test_only]
module liquidswap::curves_tests {
use liquidswap::curves::{is_stable, Uncorrelated, Stable, is_uncorrelated, is_valid_curve, assert_valid_curve};
use liquidswap::curves::{
Self,
is_stable,
Uncorrelated,
Stable,
is_uncorrelated,
is_valid_curve,
assert_valid_curve
};

struct UnknownCurve {}

Expand Down Expand Up @@ -30,7 +38,7 @@ module liquidswap::curves_tests {
}

#[test]
#[expected_failure(abort_code=10001)]
#[expected_failure(abort_code = curves::ERR_INVALID_CURVE)]
fun test_assert_is_valid_curve_fails() {
assert_valid_curve<UnknownCurve>();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/dao_storage_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module liquidswap::dao_storage_tests {
}

#[test]
#[expected_failure(abort_code = 401)]
#[expected_failure(abort_code = dao_storage::ERR_NOT_REGISTERED)]
fun test_deposit_fail_if_not_registered() {
let (coin_admin, lp_owner) = test_pool::setup_coins_and_lp_owner();

Expand Down Expand Up @@ -93,7 +93,7 @@ module liquidswap::dao_storage_tests {
}

#[test(dao_admin_acc = @dao_admin)]
#[expected_failure(abort_code = 65542)]
#[expected_failure(abort_code = 65542, location = aptos_framework::coin)]
fun test_withdraw_fail_if_more_deposited(dao_admin_acc: signer) {
let (coin_admin, lp_owner) = test_pool::setup_coins_and_lp_owner();

Expand All @@ -115,7 +115,7 @@ module liquidswap::dao_storage_tests {
}

#[test(dao_admin_acc = @0xca)]
#[expected_failure(abort_code = 402)]
#[expected_failure(abort_code = dao_storage::ERR_NOT_ADMIN_ACCOUNT)]
fun test_withdraw_fail_if_not_dao_admin(dao_admin_acc: signer) {
let (coin_admin, lp_owner) = test_pool::setup_coins_and_lp_owner();

Expand Down
Loading

0 comments on commit d779298

Please sign in to comment.