Skip to content

Commit

Permalink
Merge pull request #632 from bancorprotocol/624-replacement
Browse files Browse the repository at this point in the history
Fixes handling of flashloan tokens and target tokens where addresses can get dropped
  • Loading branch information
zavelevsky authored May 10, 2024
2 parents 154b32c + caa89a9 commit 6e340ac
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 58 deletions.
1 change: 0 additions & 1 deletion fastlane_bot/config/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ class ConfigNetwork(ConfigBase):

# FLAGS
#######################################################################################
GAS_TKN_IN_FLASHLOAN_TOKENS = None
IS_NO_FLASHLOAN_AVAILABLE = False

# HOOKS
Expand Down
15 changes: 7 additions & 8 deletions fastlane_bot/events/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,8 @@ def get_tokens(self) -> List[Token]:
token_set.add(self.create_token(record, f"tkn{str(idx)}_"))
except AttributeError:
pass
if self.ConfigObj.GAS_TKN_IN_FLASHLOAN_TOKENS:
token_set.add(Token(symbol=self.ConfigObj.NATIVE_GAS_TOKEN_SYMBOL, address=self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS, decimals=18))
token_set.add(Token(symbol=self.ConfigObj.WRAPPED_GAS_TOKEN_SYMBOL, address=self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, decimals=18))
token_set.add(Token(symbol=self.ConfigObj.NATIVE_GAS_TOKEN_SYMBOL, address=self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS, decimals=18))
token_set.add(Token(symbol=self.ConfigObj.WRAPPED_GAS_TOKEN_SYMBOL, address=self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, decimals=18))
return list(token_set)

def populate_tokens(self):
Expand All @@ -509,11 +508,11 @@ def populate_tokens(self):
self.token_list[token.address] = token
except AttributeError:
pass
if self.ConfigObj.GAS_TKN_IN_FLASHLOAN_TOKENS:
native_gas_tkn = Token(symbol=self.ConfigObj.NATIVE_GAS_TOKEN_SYMBOL, address=self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS, decimals=18)
wrapped_gas_tkn = Token(symbol=self.ConfigObj.WRAPPED_GAS_TOKEN_SYMBOL, address=self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, decimals=18)
self.token_list[native_gas_tkn.address] = native_gas_tkn
self.token_list[wrapped_gas_tkn.address] = wrapped_gas_tkn
# native and wrapped gas token info populated everytime
native_gas_tkn = Token(symbol=self.ConfigObj.NATIVE_GAS_TOKEN_SYMBOL, address=self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS, decimals=18)
wrapped_gas_tkn = Token(symbol=self.ConfigObj.WRAPPED_GAS_TOKEN_SYMBOL, address=self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, decimals=18)
self.token_list[native_gas_tkn.address] = native_gas_tkn
self.token_list[wrapped_gas_tkn.address] = wrapped_gas_tkn

def create_token(self, record: Dict[str, Any], prefix: str) -> Token:
"""
Expand Down
42 changes: 0 additions & 42 deletions fastlane_bot/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,6 @@ def get_config(

cfg.LIMIT_BANCOR3_FLASHLOAN_TOKENS = limit_bancor3_flashloan_tokens
cfg.DEFAULT_MIN_PROFIT_GAS_TOKEN = Decimal(default_min_profit_gas_token)
cfg.GAS_TKN_IN_FLASHLOAN_TOKENS = (
cfg.NATIVE_GAS_TOKEN_ADDRESS in flashloan_tokens
or cfg.WRAPPED_GAS_TOKEN_ADDRESS in flashloan_tokens
)
return cfg


Expand Down Expand Up @@ -1678,44 +1674,6 @@ def delete_tenderly_forks(forks_to_cleanup: List[str], mgr: Any) -> List[str]:

return forks_to_keep


def handle_target_token_addresses(static_pool_data: pd.DataFrame, target_tokens: List):
"""
Get the addresses of the target tokens.
Parameters
----------
static_pool_data : pd.DataFrame
The static pool data.
target_tokens : List
The target tokens.
Returns
-------
List
The addresses of the target tokens.
"""
# Get the addresses of the target tokens
target_token_addresses = []
if target_tokens:
for token in target_tokens:
target_token_addresses = (
target_token_addresses
+ static_pool_data[static_pool_data["tkn0_address"] == token][
"tkn0_address"
].tolist()
)
target_token_addresses = (
target_token_addresses
+ static_pool_data[static_pool_data["tkn1_address"] == token][
"tkn1_address"
].tolist()
)
target_token_addresses = list(set(target_token_addresses))
return target_token_addresses


def get_current_block(
last_block: int,
mgr: Any,
Expand Down
1 change: 0 additions & 1 deletion fastlane_bot/tests/test_034_Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

cfg_mock = Mock()
cfg_mock.logger = MagicMock()
cfg_mock.GAS_TKN_IN_FLASHLOAN_TOKENS = False
qi = QueryInterface(mgr=None, ConfigObj=cfg_mock)
qi.state = [{'exchange_name': 'uniswap_v2', 'address': '0x123', 'tkn0_key': 'TKN-0x123', 'tkn1_key': 'TKN-0x456', 'pair_name': 'Pair-0x789', 'liquidity': 10}, {'exchange_name': 'sushiswap_v2', 'address': '0xabc', 'tkn0_key': 'TKN-0xabc', 'tkn1_key': 'TKN-0xdef', 'pair_name': 'Pair-0xghi', 'liquidity': 0}]

Expand Down
7 changes: 1 addition & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
get_start_block,
set_network_to_mainnet_if_replay,
set_network_to_tenderly_if_replay,
handle_target_token_addresses,
get_current_block,
handle_tenderly_event_exchanges,
handle_static_pools_update,
Expand Down Expand Up @@ -255,10 +254,6 @@ def main(args: argparse.Namespace) -> None:
cfg, exchanges, args.blockchain, args.static_pool_data_filename, args.read_only
)

target_token_addresses = handle_target_token_addresses(
static_pool_data, args.target_tokens
)

# Break if timeout is hit to test the bot flags
if args.timeout == 1:
cfg.logger.info("Timeout to test the bot flags")
Expand All @@ -284,7 +279,7 @@ def main(args: argparse.Namespace) -> None:
solidly_v2_event_mappings=solidly_v2_event_mappings,
tokens=tokens.to_dict(orient="records"),
replay_from_block=args.replay_from_block,
target_tokens=target_token_addresses,
target_tokens=args.target_tokens,
tenderly_fork_id=args.tenderly_fork_id,
tenderly_event_exchanges=tenderly_event_exchanges,
w3_tenderly=w3_tenderly,
Expand Down

0 comments on commit 6e340ac

Please sign in to comment.