Skip to content

Commit

Permalink
Merge pull request #245 from bancorprotocol/244-update-fast-lane-cont…
Browse files Browse the repository at this point in the history
…ract-address-on-base

Update network.py
  • Loading branch information
mikewcasale authored Dec 7, 2023
2 parents 07d5e62 + 935c03b commit 1522c8e
Show file tree
Hide file tree
Showing 18 changed files with 749 additions and 1,675 deletions.
2 changes: 1 addition & 1 deletion fastlane_bot/config/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ class _ConfigNetworkBase(ConfigNetwork):
WEB3_ALCHEMY_PROJECT_ID = os.environ.get("WEB3_ALCHEMY_BASE")

network_df = get_multichain_addresses(network="coinbase_base")
FASTLANE_CONTRACT_ADDRESS = "0x2f33499368C4239290B045e3A34DFFA2AeD2CA05"
FASTLANE_CONTRACT_ADDRESS = "0x2AE2404cD44c830d278f51f053a08F54b3756e1c"
MULTICALL_CONTRACT_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11"

CARBON_CONTROLLER_ADDRESS = GRAPHENE_CONTROLLER_ADDRESS = "0xfbF069Dbbf453C1ab23042083CFa980B3a672BbA"
Expand Down
1 change: 0 additions & 1 deletion fastlane_bot/config/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def __init__(self, network: ConfigNetwork, **kwargs):

else:
self.CARBON_CONTROLLER_CONTRACT = None
self.BANCOR_ARBITRAGE_CONTRACT = None
self.ARB_CONTRACT_VERSION = 10

if self.BANCOR_ARBITRAGE_CONTRACT is not None:
Expand Down
13 changes: 7 additions & 6 deletions fastlane_bot/helpers/tradeinstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ def __post_init__(self):
self._tknout_address = self.tknout_addr_override
self._tknout_decimals = self.tknout_dec_override
pool = self.db.get_pool(cid=self.cid.split('-')[0])
tokens = pool.get_token_addresses
self.tknin_is_wrapped = self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS in tokens and self._tknin_address in [self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS]
self.tknin_is_native = self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS in tokens and self._tknin_address in [self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS]
self.tknout_is_wrapped = self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS in tokens and self._tknout_address in [self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS]
self.tknout_is_native = self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS in tokens and self._tknout_address in [self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS]
assert not [self.tknin_is_wrapped, self.tknin_is_native, self.tknout_is_wrapped, self.tknout_is_native].count(True) > 1, f"[TradeInstruction __post_init__] only 1 token can be native or wrapped, [self.tknin_is_wrapped, self.tknin_is_native, self.tknout_is_wrapped, self.tknout_is_native] = {self.tknin_is_wrapped, self.tknin_is_native, self.tknout_is_wrapped, self.tknout_is_native}"
if self.tknout_dec_override is None:
tokens = pool.get_token_addresses
self.tknin_is_wrapped = self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS in tokens and self._tknin_address in [self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS]
self.tknin_is_native = self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS in tokens and self._tknin_address in [self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS]
self.tknout_is_wrapped = self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS in tokens and self._tknout_address in [self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS]
self.tknout_is_native = self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS in tokens and self._tknout_address in [self.ConfigObj.WRAPPED_GAS_TOKEN_ADDRESS, self.ConfigObj.NATIVE_GAS_TOKEN_ADDRESS]
assert not [self.tknin_is_wrapped, self.tknin_is_native, self.tknout_is_wrapped, self.tknout_is_native].count(True) > 1, f"[TradeInstruction __post_init__] only 1 token can be native or wrapped, [self.tknin_is_wrapped, self.tknin_is_native, self.tknout_is_wrapped, self.tknout_is_native] = {self.tknin_is_wrapped, self.tknin_is_native, self.tknout_is_wrapped, self.tknout_is_native}"

if self._amtout_wei is None:
self._amtout_wei = self._convert_to_wei(self.amtout, self._tknout_decimals)
Expand Down
18 changes: 12 additions & 6 deletions fastlane_bot/helpers/txhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def validate_and_submit_transaction(

# Get the current recommended priority fee from Alchemy, and increase it by our offset
current_max_priority_gas = int(
self.get_max_priority_fee_per_gas_alchemy() * self.ConfigObj.DEFAULT_GAS_PRICE_OFFSET) if self.ConfigObj.NETWORK in "ethereum" else 0
self.get_max_priority_fee_per_gas_alchemy() * self.ConfigObj.DEFAULT_GAS_PRICE_OFFSET) if self.ConfigObj.NETWORK in ["ethereum", "coinbase_base"] else 0

# Get current block number
block_number = self.web3.eth.get_block("latest")["number"]
Expand All @@ -333,7 +333,11 @@ def validate_and_submit_transaction(
self.ConfigObj.logger.info("Failed to construct trade, discarding.")
return None
gas_estimate = arb_tx["gas"]
current_gas_price = arb_tx["maxFeePerGas"]

if "maxFeePerGas" in arb_tx:
current_gas_price = arb_tx["maxFeePerGas"]
else:
current_gas_price = arb_tx["gasPrice"]

# Multiply expected gas by 0.8 to account for actual gas usage vs expected.
gas_cost_eth = Decimal(str(current_gas_price)) * Decimal(str(gas_estimate)) * Decimal(self.ConfigObj.EXPECTED_GAS_MODIFIER) / Decimal('10') ** Decimal('18')
Expand All @@ -344,10 +348,12 @@ def validate_and_submit_transaction(
adjusted_reward_usd = adjusted_reward * expected_profit_usd/expected_profit_eth

transaction_log = {"block_number": block_number, "gas": gas_estimate,
"base_fee_wei": (current_gas_price - arb_tx["maxPriorityFeePerGas"]),
"priority_fee_wei": arb_tx["maxPriorityFeePerGas"], "max_gas_fee_wei": current_gas_price,
"max_gas_fee_wei": current_gas_price,
"gas_cost_eth": num_format_float(gas_cost_eth),
"gas_cost_usd": + num_format_float(gas_cost_usd)}
if "maxPriorityFeePerGas" in arb_tx:
transaction_log["base_fee_wei"] = (current_gas_price - arb_tx["maxPriorityFeePerGas"])
transaction_log["priority_fee_wei"] = arb_tx["maxPriorityFeePerGas"]

log_json = {**log_object, **transaction_log}

Expand Down Expand Up @@ -565,7 +571,7 @@ def build_transaction_with_gas(
)
return None
try:
if access_list:
if access_list and self.ConfigObj.NETWORK_NAME in "ethereum":
access_list = self.get_access_list(transaction_data=transaction["data"], expected_gas=estimated_gas)

if access_list is not None:
Expand Down Expand Up @@ -618,7 +624,7 @@ def build_tx(
base_gas_price = int(base_gas_price)
max_gas_price = base_gas_price + max_priority_fee

if self.ConfigObj.NETWORK in "ethereum":
if self.ConfigObj.NETWORK in ["ethereum", "coinbase_base"]:
return {
"type": "0x2",
"maxFeePerGas": max_gas_price,
Expand Down
39 changes: 13 additions & 26 deletions fastlane_bot/modes/pairwise_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,19 @@ def find_arbitrage(
not_carbon_curves = [
x for x in CC.curves if x.params.exchange != "carbon_v1"
]
curve_combos = [[curve] + carbon_curves for curve in not_carbon_curves]
curve_combos = []

if len(carbon_curves) > 0:
base_direction_pair = carbon_curves[0].pair
base_direction_one = [curve for curve in carbon_curves if curve.pair == base_direction_pair]
base_direction_two = [curve for curve in carbon_curves if curve.pair != base_direction_pair]

if len(base_direction_one) > 0:
curve_combos += [[curve] + base_direction_one for curve in not_carbon_curves]

if len(base_direction_two) > 0:
curve_combos += [[curve] + base_direction_two for curve in not_carbon_curves]


for curve_combo in curve_combos:
src_token = tkn1
Expand All @@ -66,31 +78,6 @@ def find_arbitrage(
(O, profit_src, r, trade_instructions_df,) = self.run_main_flow(
curves=curve_combo, src_token=src_token, tkn0=tkn0, tkn1=tkn1
)

non_carbon_cids = [
curve.cid
for curve in curve_combo
if curve.params.get("exchange") != "carbon_v1"
]
non_carbon_row = trade_instructions_df.loc[non_carbon_cids[0]]
tkn0_into_carbon = non_carbon_row[0] < 0
wrong_direction_cids = self.get_wrong_direction_cids(
tkn0_into_carbon, trade_instructions_df
)

if non_carbon_cids and len(wrong_direction_cids) > 0:
filtered_curves = self.process_wrong_direction_pools(
curve_combo=curve_combo,
wrong_direction_cids=wrong_direction_cids,
)
if len(filtered_curves) < 2:
continue
(O, profit_src, r, trade_instructions_df,) = self.run_main_flow(
curves=filtered_curves,
src_token=src_token,
tkn0=tkn0,
tkn1=tkn1,
)
trade_instructions_dic = r.trade_instructions(O.TIF_DICTS)
trade_instructions = r.trade_instructions()

Expand Down
2 changes: 1 addition & 1 deletion fastlane_bot/tools/cpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def setcid(self, cid):
super().__setattr__("cid", cid)
return self

class CPCValidationError(BaseException): pass
class CPCValidationError(ValueError): pass

@classmethod
def from_kx(
Expand Down
72 changes: 12 additions & 60 deletions resources/NBTest/NBTest_048_RespectFlashloanTokensClickParam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
" \"--logging_path=fastlane_bot/data/\",\n",
" \"--timeout=1\",\n",
" \"--loglevel=DEBUG\",\n",
" \"--flashloan_tokens=BNT-FF1C,ETH-EEeE,ETH2X_FLI-65BD\",\n",
" \"--flashloan_tokens=BNT-FF1C,ETH-EEeE,ETH2x_FLI-65BD\",\n",
" \"--blockchain=ethereum\"\n",
" ]\n",
" subprocess.Popen(cmd)\n",
Expand Down Expand Up @@ -148,71 +148,23 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Searching for main.py in /Users/mikewcasale/Documents/GitHub/bancorprotocol/fastlane-bot/resources/NBTest\n",
"Found main.py in /Users/mikewcasale/Documents/GitHub/bancorprotocol/fastlane-bot\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-10-31 11:13:22,146 [fastlane:INFO] - \n",
"2023-10-31 11:13:22,146 [fastlane:INFO] - **********************************************\n",
"2023-10-31 11:13:22,146 [fastlane:INFO] - The logging path is set to: fastlane_bot/data//logs/20231031-111322/bot.log\n",
"2023-10-31 11:13:22,146 [fastlane:INFO] - **********************************************\n",
"2023-10-31 11:13:22,146 [fastlane:INFO] - \n",
"2023-10-31 11:13:22,593 [fastlane:INFO] - Using mainnet config\n",
"2023-10-31 11:13:22,645 [fastlane:INFO] - tokens: 20798, $CHAD-c918\n",
"2023-10-31 11:13:22,647 [fastlane:INFO] - unique_tokens: 20798\n",
"2023-10-31 11:13:22,653 [fastlane:INFO] - Flashloan tokens are set as: ['BNT-FF1C', 'ETH-EEeE', 'ETH2X_FLI-65BD'], <class 'list'>\n",
"2023-10-31 11:13:22,653 [fastlane:INFO] - Running data fetching for exchanges: ['carbon_v1', 'bancor_v3', 'bancor_v2', 'bancor_pol', 'uniswap_v3', 'uniswap_v2', 'sushiswap_v2', 'balancer', 'pancakeswap_v2', 'pancakeswap_v3']\n",
"2023-10-31 11:13:22,653 [fastlane:INFO] - \n",
" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n",
" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n",
" \n",
" Starting fastlane bot with the following configuration:\n",
" \n",
" cache_latest_only: True\n",
" backdate_pools: False\n",
" arb_mode: multi\n",
" flashloan_tokens: ['BNT-FF1C', 'ETH-EEeE', 'ETH2X_FLI-65BD']\n",
" n_jobs: -1\n",
" exchanges: ['carbon_v1', 'bancor_v3', 'bancor_v2', 'bancor_pol', 'uniswap_v3', 'uniswap_v2', 'sushiswap_v2', 'balancer', 'pancakeswap_v2', 'pancakeswap_v3']\n",
" polling_interval: 12\n",
" alchemy_max_block_fetch: 2000\n",
" static_pool_data_filename: static_pool_data\n",
" reorg_delay: 2\n",
" logging_path: fastlane_bot/data/logs/20231031-111322\n",
" loglevel: debug\n",
" static_pool_data_sample_sz: max\n",
" use_cached_events: True\n",
" run_data_validator: False\n",
" randomizer: 3\n",
" limit_bancor3_flashloan_tokens: False\n",
" default_min_profit_gas_token: 60\n",
" timeout: 1\n",
" target_tokens: None\n",
" replay_from_block: None\n",
" tenderly_fork_id: None\n",
" tenderly_event_exchanges: []\n",
" increment_time: 1\n",
" increment_blocks: 1\n",
" blockchain: ethereum\n",
" pool_data_update_frequency: -1\n",
" use_specific_exchange_for_target_tokens: None\n",
" \n",
" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n",
" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n",
" \n",
"2023-10-31 11:13:23,216 [fastlane:INFO] - Timeout to test the bot flags\n"
"Searching for main.py in c:\\Users\\Kveen\\PycharmProjects\\fastlane-bot\\resources\\NBTest\n",
"Found main.py in c:\\Users\\Kveen\\PycharmProjects\\fastlane-bot\n"
]
}
],
"source": [
"expected_log_line = \"Flashloan tokens are set as: ['BNT-FF1C', 'ETH-EEeE', 'ETH2X_FLI-65BD']\"\n",
"expected_log_line = \"Flashloan tokens are set as: ['BNT-FF1C', 'ETH-EEeE', 'ETH2x_FLI-65BD']\"\n",
"arb_mode = \"multi\"\n",
"run_command(arb_mode=arb_mode, expected_log_line=expected_log_line)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -231,7 +183,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.17"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ def run_command(arb_mode, expected_log_line):
"python",
main_script_path,
f"--arb_mode={arb_mode}",
"--default_min_profit_bnt=60",
"--default_min_profit_gas_token=60",
"--limit_bancor3_flashloan_tokens=False",
"--use_cached_events=True",
"--logging_path=fastlane_bot/data/",
"--timeout=1",
"--loglevel=DEBUG",
"--flashloan_tokens=BNT-FF1C,ETH-EEeE,ETH2X-FLI-USD",
"--flashloan_tokens=BNT-FF1C,ETH-EEeE,ETH2x_FLI-65BD",
"--blockchain=ethereum"
]
subprocess.Popen(cmd)
Expand All @@ -96,6 +96,8 @@ def run_command(arb_mode, expected_log_line):

# ## Test flashloan_tokens is Respected

expected_log_line = "Flashloan tokens are set as: ['BNT-FF1C', 'ETH-EEeE', 'ETH2X_FLI-USD']"
expected_log_line = "Flashloan tokens are set as: ['BNT-FF1C', 'ETH-EEeE', 'ETH2x_FLI-65BD']"
arb_mode = "multi"
run_command(arb_mode=arb_mode, expected_log_line=expected_log_line)


Loading

0 comments on commit 1522c8e

Please sign in to comment.