Skip to content

Commit

Permalink
Merge branch 'release-v0.2' of github.com:pontem-network/multi-swap i…
Browse files Browse the repository at this point in the history
…nto release-v0.2
  • Loading branch information
borispovod committed Aug 19, 2022
2 parents 0b1955a + 6604523 commit 03ffd13
Show file tree
Hide file tree
Showing 10 changed files with 448 additions and 444 deletions.
10 changes: 5 additions & 5 deletions Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ test_helpers = "0x12"

[dependencies.MoveStdlib]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "1570509e746b6626264cb6e9c0c8371683253961"
rev = "a58060f88d66b90a0548a506e22270b04a328db3"
subdir = "aptos-move/framework/move-stdlib"

[dependencies.AptosStdlib]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "1570509e746b6626264cb6e9c0c8371683253961"
rev = "a58060f88d66b90a0548a506e22270b04a328db3"
subdir = "aptos-move/framework/aptos-stdlib"

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

[dependencies.UQ64x64]
git = "https://github.com/pontem-network/UQ64x64.git"
rev = "v0.3.3"
rev = "v0.3.4"

[dependencies.U256]
git = "https://github.com/pontem-network/U256.git"
rev = "v0.3.3"
rev = "v0.3.4"
2 changes: 1 addition & 1 deletion sources/libs/math.move
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module liquidswap::math {
}

/// Returns 10^degree.
public fun pow_10(degree: u64): u64 {
public fun pow_10(degree: u8): u64 {
let res = 1;
let i = 0;
while (i < degree) {
Expand Down
3 changes: 2 additions & 1 deletion sources/swap/liquidity_pool.move
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ module liquidswap::liquidity_pool {
ERR_INVALID_CURVE
);

let (lp_mint_cap, lp_burn_cap) = coin::initialize<LP>(
let (lp_burn_cap, lp_freeze_cap, lp_mint_cap) = coin::initialize<LP>(
owner,
lp_name,
lp_symbol,
6,
true
);
coin::destroy_freeze_cap(lp_freeze_cap);

let x_scale = 0;
let y_scale = 0;
Expand Down
15 changes: 10 additions & 5 deletions sources/test_helpers/test_coins.move
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ module test_coin_admin::test_coins {
}

// Register one coin with custom details.
public fun register_coin<CoinType>(coin_admin: &signer, name: vector<u8>, symbol: vector<u8>, decimals: u64) {
let (mint_cap, burn_cap) = coin::initialize<CoinType>(
public fun register_coin<CoinType>(coin_admin: &signer, name: vector<u8>, symbol: vector<u8>, decimals: u8) {
let (burn_cap, freeze_cap, mint_cap, ) = coin::initialize<CoinType>(
coin_admin,
utf8(name),
utf8(symbol),
decimals,
true,
);
coin::destroy_freeze_cap(freeze_cap);

move_to(coin_admin, Capabilities<CoinType> {
mint_cap,
Expand All @@ -34,7 +35,7 @@ module test_coin_admin::test_coins {

// Register all known coins in one func.
public fun register_coins(coin_admin: &signer) {
let (usdt_mint_cap, usdt_burn_cap) =
let (usdt_burn_cap, usdt_freeze_cap, usdt_mint_cap) =
coin::initialize<USDT>(
coin_admin,
utf8(b"USDT"),
Expand All @@ -43,7 +44,7 @@ module test_coin_admin::test_coins {
true
);

let (btc_mint_cap, btc_burn_cap) =
let (btc_burn_cap, btc_freeze_cap, btc_mint_cap) =
coin::initialize<BTC>(
coin_admin,
utf8(b"BTC"),
Expand All @@ -52,7 +53,7 @@ module test_coin_admin::test_coins {
true
);

let (usdc_mint_cap, usdc_burn_cap) =
let (usdc_burn_cap, usdc_freeze_cap, usdc_mint_cap) =
coin::initialize<USDC>(
coin_admin,
utf8(b"USDC"),
Expand All @@ -75,6 +76,10 @@ module test_coin_admin::test_coins {
mint_cap: usdc_mint_cap,
burn_cap: usdc_burn_cap,
});

coin::destroy_freeze_cap(usdt_freeze_cap);
coin::destroy_freeze_cap(usdc_freeze_cap);
coin::destroy_freeze_cap(btc_freeze_cap);
}

public fun mint<CoinType>(coin_admin: &signer, amount: u64): Coin<CoinType> acquires Capabilities {
Expand Down
3 changes: 2 additions & 1 deletion sources/test_helpers/test_lp.move
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ module test_pool_owner::test_lp {
}

public fun register_lp_for_fails(pool_owner: &signer) {
let (mint_cap, burn_cap) =
let (burn_cap, freeze_cap, mint_cap) =
coin::initialize<LP>(
pool_owner,
utf8(b"LP"),
utf8(b"LP"),
6,
true
);
coin::destroy_freeze_cap(freeze_cap);

move_to(pool_owner, Capabilities<LP> { mint_cap, burn_cap });
}
Expand Down
18 changes: 9 additions & 9 deletions tests/coin_helper_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module liquidswap::coin_helper_tests {
use test_helpers::test_account::create_account;
use test_coin_admin::test_coins::{Self, BTC, USDT};

#[test(core = @core_resources, coin_admin = @test_coin_admin)]
fun test_end_to_end(core: signer, coin_admin: signer) {
genesis::setup(&core);
#[test(coin_admin = @test_coin_admin)]
fun test_end_to_end(coin_admin: signer) {
genesis::setup();
create_account(&coin_admin);

test_coins::register_coins(&coin_admin);
Expand Down Expand Up @@ -47,10 +47,10 @@ module liquidswap::coin_helper_tests {
coin_helper::assert_is_coin<USDT>();
}

#[test(core = @core_resources, coin_admin = @test_coin_admin)]
#[test(coin_admin = @test_coin_admin)]
#[expected_failure(abort_code = 3000)]
fun test_cant_be_same_coin_failure(core: signer, coin_admin: signer) {
genesis::setup(&core);
fun test_cant_be_same_coin_failure(coin_admin: signer) {
genesis::setup();
create_account(&coin_admin);

test_coins::register_coins(&coin_admin);
Expand All @@ -59,9 +59,9 @@ module liquidswap::coin_helper_tests {
let _ = coin_helper::is_sorted<USDT, USDT>();
}

#[test(core = @core_resources, coin_admin = @test_coin_admin)]
fun generate_lp_name(core: signer, coin_admin: signer) {
genesis::setup(&core);
#[test(coin_admin = @test_coin_admin)]
fun generate_lp_name(coin_admin: signer) {
genesis::setup();
create_account(&coin_admin);

test_coins::register_coins(&coin_admin);
Expand Down
43 changes: 21 additions & 22 deletions tests/dao_storage_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module liquidswap::dao_storage_tests {
use test_pool_owner::test_lp::LP;
use test_helpers::test_account::create_account;

#[test(core = @core_resources, pool_owner = @test_pool_owner)]
fun test_register(core: signer, pool_owner: signer) {
genesis::setup(&core);
#[test(pool_owner = @test_pool_owner)]
fun test_register(pool_owner: signer) {
genesis::setup();

create_account(&pool_owner);

Expand All @@ -28,9 +28,9 @@ module liquidswap::dao_storage_tests {
assert!(y_val == 0, 1);
}

#[test(core = @core_resources, coin_admin = @test_coin_admin, pool_owner = @test_pool_owner)]
fun test_deposit(core: signer, coin_admin: signer, pool_owner: signer) {
genesis::setup(&core);
#[test(coin_admin = @test_coin_admin, pool_owner = @test_pool_owner)]
fun test_deposit(coin_admin: signer, pool_owner: signer) {
genesis::setup();

create_account(&coin_admin);
create_account(&pool_owner);
Expand All @@ -52,10 +52,10 @@ module liquidswap::dao_storage_tests {
assert!(y_val == 1000000, 3);
}

#[test(core = @core_resources, coin_admin = @test_coin_admin, pool_owner = @test_pool_owner)]
#[test(coin_admin = @test_coin_admin, pool_owner = @test_pool_owner)]
#[expected_failure(abort_code = 401)]
fun test_deposit_fail_if_not_registered(core: signer, coin_admin: signer, pool_owner: signer) {
genesis::setup(&core);
fun test_deposit_fail_if_not_registered(coin_admin: signer, pool_owner: signer) {
genesis::setup();

create_account(&coin_admin);
create_account(&pool_owner);
Expand All @@ -69,9 +69,9 @@ module liquidswap::dao_storage_tests {
dao_storage::deposit_for_test<BTC, USDT, LP>(pool_owner_addr, btc_coins, usdt_coins);
}

#[test(core = @core_resources, coin_admin = @test_coin_admin, pool_owner = @test_pool_owner, dao_admin_acc = @dao_admin)]
fun test_withdraw(core: signer, coin_admin: signer, pool_owner: signer, dao_admin_acc: signer) {
genesis::setup(&core);
#[test(coin_admin = @test_coin_admin, pool_owner = @test_pool_owner, dao_admin_acc = @dao_admin)]
fun test_withdraw(coin_admin: signer, pool_owner: signer, dao_admin_acc: signer) {
genesis::setup();

create_account(&coin_admin);
create_account(&pool_owner);
Expand Down Expand Up @@ -99,10 +99,10 @@ module liquidswap::dao_storage_tests {
test_coins::burn(&coin_admin, y);
}

#[test(core = @core_resources, coin_admin = @test_coin_admin, pool_owner = @test_pool_owner, dao_admin_acc = @dao_admin)]
#[expected_failure(abort_code = 65541)]
fun test_withdraw_fail_if_more_deposited(core: signer, coin_admin: signer, pool_owner: signer, dao_admin_acc: signer) {
genesis::setup(&core);
#[test(coin_admin = @test_coin_admin, pool_owner = @test_pool_owner, dao_admin_acc = @dao_admin)]
#[expected_failure(abort_code = 65542)]
fun test_withdraw_fail_if_more_deposited(coin_admin: signer, pool_owner: signer, dao_admin_acc: signer) {
genesis::setup();

create_account(&coin_admin);
create_account(&pool_owner);
Expand All @@ -124,10 +124,10 @@ module liquidswap::dao_storage_tests {
test_coins::burn(&coin_admin, y);
}

#[test(core = @core_resources, coin_admin = @test_coin_admin, pool_owner = @test_pool_owner, dao_admin_acc = @0x09)]
#[test(coin_admin = @test_coin_admin, pool_owner = @test_pool_owner, dao_admin_acc = @0x09)]
#[expected_failure(abort_code = 402)]
fun test_withdraw_fail_if_not_dao_admin(core: signer, coin_admin: signer, pool_owner: signer, dao_admin_acc: signer) {
genesis::setup(&core);
fun test_withdraw_fail_if_not_dao_admin(coin_admin: signer, pool_owner: signer, dao_admin_acc: signer) {
genesis::setup();

create_account(&coin_admin);
create_account(&pool_owner);
Expand All @@ -149,14 +149,13 @@ module liquidswap::dao_storage_tests {
test_coins::burn(&coin_admin, y);
}

#[test(core = @core_resources, coin_admin = @test_coin_admin, pool_owner = @test_pool_owner, dao_admin_acc = @dao_admin)]
#[test(coin_admin = @test_coin_admin, pool_owner = @test_pool_owner, dao_admin_acc = @dao_admin)]
fun test_split_third_of_fees_into_dao_storage_account(
core: signer,
coin_admin: signer,
pool_owner: signer,
dao_admin_acc: signer,
) {
genesis::setup(&core);
genesis::setup();

create_account(&coin_admin);
create_account(&pool_owner);
Expand Down
Loading

0 comments on commit 03ffd13

Please sign in to comment.