Skip to content

Commit

Permalink
Prevent division by 0 error in calc_withdraw_one_coin simulation (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIsshiki authored Mar 9, 2022
1 parent a002234 commit 23dc8d6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stable-swap-math/sim/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ def calc_withdraw_one_coin(self, token_amount, i):
dx_expected = xp[j] - xp[j] * D1 // D0
xp_reduced[j] -= fee * dx_expected // 10 ** 10

self.x = [x // (p // 10 ** 18) for x, p in zip(xp_reduced, self.p)]
self.x = [x * 10 ** 18 // p for x, p in zip(xp_reduced, self.p)]
dy = xp_reduced[i] - self.y_D(i, D1) - 1 # Withdraw less to account for rounding errors
self.x = [x // (p // 10 ** 18) for x, p in zip(xp, self.p)]
self.x = [x * 10 ** 18 // p for x, p in zip(xp, self.p)]
dy_0 = xp[i] - new_y

return dy, dy_0 - dy

0 comments on commit 23dc8d6

Please sign in to comment.