Skip to content

Commit

Permalink
Merge pull request #232 from bancorprotocol/226-specific-exchanges-bug
Browse files Browse the repository at this point in the history
If gas tkn or wrapped gas token is in flashloan tokens, always include both in token list
  • Loading branch information
NIXBNT authored Nov 28, 2023
2 parents b1de6b8 + 7ae87d6 commit a3db93b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions fastlane_bot/config/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ class ConfigNetwork(ConfigBase):
NETWORK_POLYGON_ZKEVM = S.NETWORK_POLYGON_ZKEVM
NETWORK_OPTIMISM = S.NETWORK_OPTIMISM

# FLAGS
#######################################################################################
GAS_TKN_IN_FLASHLOAN_TOKENS = None

@classmethod
def new(cls, network=None):
"""
Expand Down Expand Up @@ -558,6 +562,9 @@ class _ConfigNetworkTenderly(ConfigNetwork):

BALANCER_VAULT_ADDRESS = "0xBA12222222228d8Ba445958a75a0704d566BF2C8"

CHAIN_SPECIFIC_EXCHANGES = ["carbon_v1", "bancor_v2", "bancor_v3", "bancor_pol"]
CHAIN_SPECIFIC_EXCHANGES = [ex for ex in CHAIN_SPECIFIC_EXCHANGES if ex is not None]

def __init__(self, **kwargs):
super().__init__(**kwargs)

Expand Down
3 changes: 3 additions & 0 deletions fastlane_bot/events/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ def get_tokens(self) -> List[Token]:
for record in self.state:
for idx in range(len(record["descr"].split("/"))):
token_set.add(self.create_token(record, f"tkn{str(idx)}_"))
if self.ConfigObj.GAS_TKN_IN_FLASHLOAN_TOKENS:
token_set.add(Token(symbol=self.ConfigObj.NATIVE_GAS_TOKEN_KEY.split("-")[0], key=self.ConfigObj.NATIVE_GAS_TOKEN_KEY, address=self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS, decimals=18))
token_set.add(Token(symbol=self.ConfigObj.WRAPPED_GAS_TOKEN_KEY.split("-")[0], key=self.ConfigObj.WRAPPED_GAS_TOKEN_KEY, address=self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, decimals=18))
return list(token_set)

def create_token(self, record: Dict[str, Any], prefix: str) -> Token:
Expand Down
4 changes: 4 additions & 0 deletions fastlane_bot/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ def get_config(
loglevel: str,
logging_path: str,
blockchain: str,
flashloan_tokens: str,
tenderly_fork_id: str = None,
) -> Config:
"""
Expand All @@ -478,6 +479,8 @@ def get_config(
The logging path.
blockchain : str
The name of the blockchain
flashloan_tokens (str):
Comma seperated list of tokens that the bot can use for flash loans.
tenderly_fork_id : str, optional
The Tenderly fork ID, by default None
Expand Down Expand Up @@ -507,6 +510,7 @@ def get_config(
cfg.logger.info("Using mainnet 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_KEY in flashloan_tokens or cfg.WRAPPED_GAS_TOKEN_KEY in flashloan_tokens)
return cfg


Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ def main(
loglevel,
logging_path,
blockchain,
flashloan_tokens,
tenderly_fork_id,
)
# TODO: add blockchain support
Expand Down
6 changes: 4 additions & 2 deletions resources/NBTest/NBTest_034_Interface.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"source": [
"cfg_mock = Mock()\n",
"cfg_mock.logger = MagicMock()\n",
"cfg_mock.GAS_TKN_IN_FLASHLOAN_TOKENS = False\n",
"qi = QueryInterface(mgr=None, ConfigObj=cfg_mock)\n",
"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 Expand Up @@ -207,7 +208,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 8,
"id": "d2df5597",
"metadata": {
"ExecuteTime": {
Expand All @@ -220,6 +221,7 @@
"new_state = [{'exchange_name': 'bancor_v2', 'address': '0xabc', 'descr': 'TKN-0x123/TKN-0xdef', 'tkn0_key': 'TKN-0x123', 'tkn1_key': 'TKN-0xdef', 'pair_name': 'Pair-0xghi', 'liquidity': 10}]\n",
"qi.update_state(new_state)\n",
"token = qi.get_token('TKN-0x123')\n",
"\n",
"assert isinstance(token, Token)"
]
},
Expand All @@ -233,7 +235,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 9,
"id": "d2696dba",
"metadata": {
"ExecuteTime": {
Expand Down
4 changes: 4 additions & 0 deletions resources/NBTest/NBTest_034_Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

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 Expand Up @@ -75,10 +76,13 @@

# ## test_get_token

# +
new_state = [{'exchange_name': 'bancor_v2', 'address': '0xabc', 'descr': 'TKN-0x123/TKN-0xdef', 'tkn0_key': 'TKN-0x123', 'tkn1_key': 'TKN-0xdef', 'pair_name': 'Pair-0xghi', 'liquidity': 10}]
qi.update_state(new_state)
token = qi.get_token('TKN-0x123')

assert isinstance(token, Token)
# -

# ## test_get_pool

Expand Down

0 comments on commit a3db93b

Please sign in to comment.