Skip to content

Commit

Permalink
Reduce branches
Browse files Browse the repository at this point in the history
  • Loading branch information
chanhosuh committed Nov 6, 2023
1 parent 735ff9f commit 1081569
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions curvesim/pool/cryptoswap/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,16 +999,12 @@ def _calc_withdraw_one_coin(

# Price calc
p: Optional[int] = None
if self.n == 2:
if calc_price and dy > 10**5 and token_amount > 10**5:
if self.n == 2 and calc_price:
if dy > 10**5 and token_amount > 10**5:
# p_i = dD / D0 * sum'(p_k * x_k) / (dy - dD / D0 * y0)
S: int = 0
precision: int = precisions[0]
if i == 1:
S = xx[0] * precisions[0]
precision = precisions[1]
else:
S = xx[1] * precisions[1]
j = (i + 1) % 2
precision: int = precisions[i]
S: int = xx[j] * precisions[j]
S = S * dD // D0
p = S * PRECISION // (dy * precision - dD * xx[i] * precision // D0)
if i == 0:
Expand Down Expand Up @@ -1062,8 +1058,8 @@ def lp_price(self) -> int:
price_oracle: List[int] = self.internal_price_oracle()
price: int = factory_2_coin.lp_price(virtual_price, price_oracle)
elif self.n == 3:
# 3-coin vyper contract uses cached packed oracle prices instead of
# internal_price_oracle()
# 3-coin vyper contract uses cached packed oracle prices
# instead of internal_price_oracle()
virtual_price = self.virtual_price
price_oracle = self._price_oracle
price = tricrypto_ng.lp_price(virtual_price, price_oracle)
Expand Down

0 comments on commit 1081569

Please sign in to comment.