Skip to content

Commit

Permalink
In poolandtokens._carbon_to_cpc_dict, rely on utils.encodeOrder i…
Browse files Browse the repository at this point in the history
…nstead of duplicating its code
  • Loading branch information
barak manos committed May 25, 2024
1 parent a7cb59b commit 2f05b81
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions fastlane_bot/helpers/poolandtokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# from fastlane_bot.config import SUPPORTED_EXCHANGES, CARBON_V1_NAME, UNISWAP_V3_NAME
from fastlane_bot.helpers.univ3calc import Univ3Calculator
from fastlane_bot.tools.cpc import ConstantProductCurve
from fastlane_bot.utils import decodeOrder
from fastlane_bot.utils import decodeOrder, encodeOrder


class SolidlyV2StablePoolsNotSupported(Exception):
Expand Down Expand Up @@ -490,14 +490,17 @@ def _carbon_to_cpc_dict(self) -> Tuple[Dict, bool]:
# if the threshold is met and neither is a limit order and prices overlap then likely to be overlapping
if percent_component_met and no_limit_orders and prices_overlap:
# calculate the geometric mean
M = 1 / (p_marg_0 * p_marg_1).sqrt().sqrt()
pm = 1 / (p_marg_0 * p_marg_1).sqrt()
# modify the y_int based on the new geomean to the limit of y
for typed_args in strategy_typed_args:
H = typed_args["pa"].sqrt()
L = typed_args["pb"].sqrt()
yint0 = typed_args["y"] * (H - L) / (M - L) if M > L else typed_args["y"]
if typed_args["yint"] < yint0:
typed_args["yint"] = yint0
yint = encodeOrder({
'liquidity': typed_args["y"],
'lowestRate': typed_args["pb"],
'highestRate': typed_args["pa"],
'marginalRate': pm,
})["z"]
if typed_args["yint"] < yint:
typed_args["yint"] = yint

return {"strategy_typed_args": strategy_typed_args, "prices_overlap": prices_overlap}

Expand Down

0 comments on commit 2f05b81

Please sign in to comment.