Skip to content

Commit c45b360

Browse files
committed
Make calc_withdraw_one_coin consistent with _calc_withdraw_one_coin
1 parent 5905501 commit c45b360

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

tests/simulation.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,24 @@ def remove_liquidity_imbalance(self, amounts):
148148

149149
def calc_withdraw_one_coin(self, token_amount, i):
150150
xp = self.xp()
151-
if self.fee:
152-
fee = self.fee - self.fee * xp[i] // sum(xp) + 5 * 10 ** 5
153-
else:
154-
fee = 0
151+
xp_reduced = xp
155152

156153
D0 = self.D()
157154
D1 = D0 - token_amount * D0 // self.tokens
158-
dy = xp[i] - self.y_D(i, D1)
159-
160-
return dy - dy * fee // 10 ** 10
155+
new_y = self.y_D(i, D1)
156+
157+
fee = self.fee * self.n // (4 * (self.n - 1))
158+
for j in range(self.n):
159+
dx_expected = 0
160+
if j == i:
161+
dx_expected = xp[j] * D1 // D0 - new_y
162+
else:
163+
dx_expected = xp[j] - xp[j] * D1 // D0
164+
xp_reduced[j] -= fee * dx_expected // 10 ** 10
165+
166+
self.x = [x // (p // 10 ** 18) for x, p in zip(xp_reduced, self.p)]
167+
dy = xp_reduced[i] - self.y_D(i, D1)
168+
self.x = [x // (p // 10 ** 18) for x, p in zip(xp, self.p)]
169+
dy_0 = (xp[i] - new_y)
170+
171+
return dy, dy_0 - dy

0 commit comments

Comments
 (0)