Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update divest asserts #59

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion contracts/partials/Errors.ligo
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ const err_wrong_pair_order : string = "Dex/wrong-pair-order";
const err_empty_route : string = "Dex/empty-route";
const err_low_max_a_in : string = "Dex/low-max-token-a-in";
const err_low_max_b_in : string = "Dex/low-max-token-b-in";
const err_swap_outdated : string = "Dex/swap-outdated";
const err_swap_outdated : string = "Dex/swap-outdated";
const err_wrong_reserves_state : string = "Dex/wrong-reserves-state";
const err_low_supply : string = "Dex/low-supply";
16 changes: 7 additions & 9 deletions contracts/partials/MethodsDex.ligo
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,18 @@ function divest_liquidity(
token_a_divested >= params.min_token_a_out
and token_b_divested >= params.min_token_b_out,
err_high_min_out);
assert_with_error(
pair.total_supply >= params.shares,
err_low_supply);

pair.total_supply := abs(pair.total_supply - params.shares);
pair.token_a_pool := abs(pair.token_a_pool - token_a_divested);
pair.token_b_pool := abs(pair.token_b_pool - token_b_divested);

if pair.total_supply = 0n
or pair.token_a_pool = 0n
or pair.token_b_pool = 0n
then {
pair.token_a_pool := 0n;
pair.token_b_pool := 0n;
pair.total_supply := 0n;
}
else skip;
assert_with_error(
((pair.total_supply or pair.token_a_pool or pair.token_b_pool) = 0n)
or (pair.total_supply * pair.token_a_pool * pair.token_b_pool =/= 0n),
err_wrong_reserves_state);

s.pairs[params.pair_id] := pair;

Expand Down