Skip to content

Commit

Permalink
Cleanup function routerhandler._calc_carbon_output
Browse files Browse the repository at this point in the history
  • Loading branch information
barak manos authored and platonfloria committed May 21, 2024
1 parent fb4ed73 commit 7daac19
Showing 1 changed file with 6 additions and 40 deletions.
46 changes: 6 additions & 40 deletions fastlane_bot/helpers/routehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,41 +727,6 @@ def decode_decimal_adjustment(self, value: Decimal, tkn_in_decimals: int or str,
(tkn_in_decimals - tkn_out_decimals) / Decimal("2")
)

def _get_output_trade_by_source_carbon(
self, y, z, A, B, fee, tkns_in: Decimal
) -> Tuple[Decimal, Decimal]:
"""
Refactored get output trade by source fastlane_bot.
Parameters
----------
y: Decimal
The y.
z: Decimal
The z.
A: Decimal
The A.
B: Decimal
The B.
fee: Decimal
The fee.
tkns_in: Decimal
The tokens in.
Returns
-------
Tuple[Decimal, Decimal]
The tuple of tokens in and tokens out.
"""

tkns_out = (tkns_in * (B * z + A * y) ** 2) / (tkns_in * (B * A * z + A ** 2 * y) + z ** 2)

if tkns_out > y:
tkns_out = y
tkns_in = (y * z ** 2) / ((A * y + B * z) * (A * y + B * z - A * y))

return tkns_in, tkns_out * (1 - fee)

def _calc_carbon_output(
self, curve: Pool, tkn_in: str, tkn_in_decimals: int, tkn_out_decimals: int, amount_in: Decimal
):
Expand Down Expand Up @@ -814,12 +779,13 @@ def _calc_carbon_output(
# print('[_calc_carbon_output] after decode: ', y, z, A, B)
assert y > 0, f"Trade incoming to empty Carbon curve: {curve}"

# print(f"[_calc_carbon_output] Carbon curve decoded: {y, z, A, B}, fee = {Decimal(curve.fee)}, amount_in={amount_in}")
amount_out = (amount_in * (B * z + A * y) ** 2) / (amount_in * (B * A * z + A ** 2 * y) + z ** 2)

amt_in, result = self._get_output_trade_by_source_carbon(
y=y, z=z, A=A, B=B, fee=Decimal(curve.fee_float), tkns_in=amount_in
)
return amt_in, result
if amount_out > y:
amount_out = y
amount_in = (y * z ** 2) / ((A * y + B * z) * (A * y + B * z - A * y))

return amount_in, amount_out * (1 - Decimal(curve.fee_float))

@staticmethod
def _single_trade_result_constant_product(
Expand Down

0 comments on commit 7daac19

Please sign in to comment.