Skip to content

Commit

Permalink
Merge pull request #37 from madfish-solutions/fix_rounding
Browse files Browse the repository at this point in the history
fix accurancy
  • Loading branch information
lourenc authored May 27, 2021
2 parents 0a19e4d + d86d9ca commit 9ae028e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion contracts/partials/MethodDex.ligo
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,10 @@ function invest_liquidity (const p : dex_action; const s : dex_storage; const th
s := update_reward(s);

(* calculate tokens to be withdrawn *)
const tokens_required : nat = shares_purchased * s.token_pool / s.total_supply;
var tokens_required : nat := shares_purchased * s.token_pool / s.total_supply;
if shares_purchased * s.token_pool > tokens_required * s.total_supply then
tokens_required := tokens_required + 1n
else skip;

(* ensure *)
if tokens_required = 0n (* required tokens doesn't exceed max allowed by user *)
Expand Down
6 changes: 6 additions & 0 deletions contracts/partials/TTMethodDex.ligo
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,13 @@ function invest_liquidity (const p : dex_action; const s : dex_storage; const th

(* calculate tokens to be withdrawn *)
const tokens_a_required : nat = shares_purchased * pair.token_a_pool / pair.total_supply;
if shares_purchased * pair.token_a_pool > tokens_a_required * pair.total_supply then
tokens_a_required := tokens_a_required + 1n
else skip;
const tokens_b_required : nat = shares_purchased * pair.token_b_pool / pair.total_supply;
if shares_purchased * pair.token_b_pool > tokens_b_required * pair.total_supply then
tokens_b_required := tokens_b_required + 1n
else skip;

(* ensure *)
if tokens_a_required = 0n (* providing liquidity won't impact on price *)
Expand Down

0 comments on commit 9ae028e

Please sign in to comment.