From 929bb404e3c34c44714d042b431b919e54879810 Mon Sep 17 00:00:00 2001 From: Chan-Ho Suh Date: Mon, 25 Sep 2023 12:05:20 -0400 Subject: [PATCH] Reduce branches --- curvesim/pool/cryptoswap/pool.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/curvesim/pool/cryptoswap/pool.py b/curvesim/pool/cryptoswap/pool.py index ecff307a6..7a22fa499 100644 --- a/curvesim/pool/cryptoswap/pool.py +++ b/curvesim/pool/cryptoswap/pool.py @@ -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: @@ -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)