diff --git a/CHANGELOG.md b/CHANGELOG.md index 4076d19ab..59fbda873 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,14 +2,22 @@ ## [Unreleased](https://github.com/bancorprotocol/fastlane-bot/tree/HEAD) -[Full Changelog](https://github.com/bancorprotocol/fastlane-bot/compare/v2.7.59...HEAD) +[Full Changelog](https://github.com/bancorprotocol/fastlane-bot/compare/v2.7.60...HEAD) -- Bug in automatic pool shutdown [\#192](https://github.com/bancorprotocol/fastlane-bot/issues/192) +- Bug - ensure no precision or rounding error when generating trades through Carbon [\#201](https://github.com/bancorprotocol/fastlane-bot/issues/201) +- Fix to use wei format for generating flashloans to avoid precision or rounding errors [\#202](https://github.com/bancorprotocol/fastlane-bot/pull/202) ([Lesigh-3100](https://github.com/Lesigh-3100)) Closed issues +- Warning! Error encountered during contract execution \[execution reverted\] [\#195](https://github.com/bancorprotocol/fastlane-bot/issues/195) - Ensure backward compatibility for python 3.8 in light of new async changes [\#188](https://github.com/bancorprotocol/fastlane-bot/issues/188) +## [v2.7.60](https://github.com/bancorprotocol/fastlane-bot/tree/v2.7.60) (2023-11-13) + +[Full Changelog](https://github.com/bancorprotocol/fastlane-bot/compare/v2.7.59...v2.7.60) + +- Bug in automatic pool shutdown [\#192](https://github.com/bancorprotocol/fastlane-bot/issues/192) + Merged pull requests - removing incompatible type reference for upcoming web3.py version change [\#189](https://github.com/bancorprotocol/fastlane-bot/pull/189) ([mikewcasale](https://github.com/mikewcasale)) diff --git a/fastlane_bot/__init__.py b/fastlane_bot/__init__.py index 4da7845e4..fa7675b9e 100644 --- a/fastlane_bot/__init__.py +++ b/fastlane_bot/__init__.py @@ -1,7 +1,7 @@ from .bot import CarbonBot as Bot, __VERSION__, __DATE__ from .config import Config, ConfigNetwork, ConfigDB, ConfigLogger, ConfigProvider -__version__ = '2.7.60' +__version__ = '2.7.61' diff --git a/fastlane_bot/helpers/routehandler.py b/fastlane_bot/helpers/routehandler.py index 37afdab14..00eda3759 100644 --- a/fastlane_bot/helpers/routehandler.py +++ b/fastlane_bot/helpers/routehandler.py @@ -357,6 +357,8 @@ def get_custom_address( return self.ConfigObj.CARBON_CONTROLLER_MAPPING[pool.exchange_name] elif pool.exchange_name in self.ConfigObj.UNI_V2_FORKS: return self.ConfigObj.UNI_V2_ROUTER_MAPPING[pool.exchange_name] + elif pool.exchange_name in self.ConfigObj.CARBON_V1_FORKS: + return self.ConfigObj.CARBON_CONTROLLER_ADDRESS elif pool.exchange_name in self.ConfigObj.UNI_V3_FORKS: return self.ConfigObj.UNI_V3_ROUTER_MAPPING[pool.exchange_name] else: @@ -382,7 +384,7 @@ def _get_flashloan_platform_id(self, tkn: str) -> int: int """ - if self.ConfigObj.NETWORK not in "ethereum": + if self.ConfigObj.NETWORK not in ["ethereum", "tenderly"]: return 7 # Using Bancor V3 to flashloan BNT, ETH, WBTC, LINK, USDC, USDT @@ -396,15 +398,14 @@ def _get_flashloan_struct(self, trade_instructions_objects: List[TradeInstructio Turns an object containing trade instructions into a struct with flashloan tokens and amounts ready to send to the smart contract. :param flash_tokens: an object containing flashloan tokens in the format {tkn: {"tkn": tkn_address, "flash_amt": tkn_amt}} """ - flash_tokens = self._extract_flashloan_tokens(trade_instructions=trade_instructions_objects) + flash_tokens = self._extract_single_flashloan_token(trade_instructions=trade_instructions_objects) flashloans = [] balancer = {"platformId": 7, "sourceTokens": [], "sourceAmounts": []} has_balancer = False for tkn in flash_tokens.keys(): platform_id = self._get_flashloan_platform_id(tkn) source_token = flash_tokens[tkn]["tkn"] - source_amounts = TradeInstruction._convert_to_wei(abs(flash_tokens[tkn]["flash_amt"]), - flash_tokens[tkn]["decimals"]) + source_amounts = abs(flash_tokens[tkn]["flash_amt"]) if platform_id == 7: has_balancer = True balancer["sourceTokens"].append(source_token) @@ -430,7 +431,7 @@ def wrapped_gas_token_to_native(self, tkn: str): the token address """ - if self.ConfigObj.NETWORK not in "ethereum": + if self.ConfigObj.NETWORK not in ["ethereum", "tenderly"]: return tkn if tkn in [self.ConfigObj.WRAPPED_GAS_TOKEN_KEY, self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS]: @@ -438,6 +439,16 @@ def wrapped_gas_token_to_native(self, tkn: str): else: return tkn + def _extract_single_flashloan_token(self, trade_instructions: List[TradeInstruction]) -> Dict: + """ + Generate a flashloan tokens and amounts. + :param trade_instructions: A list of trade instruction objects + """ + flash_tokens = {trade_instructions[0].tknin_key: {"tkn": self.wrapped_gas_token_to_native(trade_instructions[0]._tknin_address), + "flash_amt": trade_instructions[0].amtin_wei, + "decimals": trade_instructions[0].tknin_decimals}} + return flash_tokens + def _extract_flashloan_tokens(self, trade_instructions: List[TradeInstruction]) -> Dict: """ Generate a list of the flashloan tokens and amounts. @@ -456,14 +467,15 @@ def _extract_flashloan_tokens(self, trade_instructions: List[TradeInstruction]) tknin_key = self.wrapped_gas_token_to_native(trade.tknin_key) tknout_key = self.wrapped_gas_token_to_native(trade.tknout_key) - token_change[tknin_key]["amtin"] = token_change[tknin_key]["amtin"] + Decimal(str(trade.amtin)) - token_change[tknin_key]["balance"] = token_change[tknin_key]["balance"] - Decimal(str(trade.amtin)) - token_change[tknout_key]["amtout"] = token_change[tknout_key]["amtout"] + Decimal(str(trade.amtout)) - token_change[tknout_key]["balance"] = token_change[tknout_key]["balance"] + Decimal(str(trade.amtout)) + token_change[tknin_key]["amtin"] = token_change[tknin_key]["amtin"] + trade.amtin_wei + token_change[tknin_key]["balance"] = token_change[tknin_key]["balance"] - trade.amtin_wei + token_change[tknout_key]["amtout"] = token_change[tknout_key]["amtout"] + trade.amtout_wei + token_change[tknout_key]["balance"] = token_change[tknout_key]["balance"] + trade.amtout_wei if token_change[tknin_key]["balance"] < 0: flash_tokens[tknin_key] = {"tkn": trade._tknin_address, "flash_amt": token_change[tknin_key]["amtin"], "decimals": trade.tknin_decimals} + return flash_tokens def get_arb_contract_args( @@ -1333,7 +1345,7 @@ def _solve_trade_output( tkn1_key = curve.pair_name.split("/")[1] tkn0_decimals = int(trade.db.get_token(key=tkn0_key).decimals) tkn1_decimals = int(trade.db.get_token(key=tkn1_key).decimals) - if self.ConfigObj.NETWORK in "ethereum": + if self.ConfigObj.NETWORK in ["ethereum", "tenderly"]: tkn0_key = "WETH-6Cc2" if tkn0_key == "ETH-EEeE" and (trade.tknin_key == "WETH-6Cc2" or trade.tknout_key == "WETH-6Cc2") else tkn0_key tkn1_key = "WETH-6Cc2" if tkn1_key == "ETH-EEeE" and (trade.tknin_key == "WETH-6Cc2" or trade.tknout_key == "WETH-6Cc2") else tkn1_key diff --git a/resources/NBTest/NBTest_051_BalancerFlashloans.ipynb b/resources/NBTest/NBTest_051_BalancerFlashloans.ipynb index 2e9ffa43c..9a10e278f 100644 --- a/resources/NBTest/NBTest_051_BalancerFlashloans.ipynb +++ b/resources/NBTest/NBTest_051_BalancerFlashloans.ipynb @@ -25,7 +25,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "C:\\Users\\Kveen\\AppData\\Local\\Temp\\ipykernel_41036\\3597301263.py:29: MatplotlibDeprecationWarning: The seaborn styles shipped by Matplotlib are deprecated since 3.6, as they no longer correspond to the styles shipped by seaborn. However, they will remain available as 'seaborn-v0_8-