Skip to content

Commit

Permalink
Merge branch 'deterministic-testing-integration2' of https://github.c…
Browse files Browse the repository at this point in the history
…om/bancorprotocol/fastlane-bot into deterministic-testing-integration2
  • Loading branch information
mikewcasale committed Mar 28, 2024
2 parents 7697a33 + 6965e8c commit 0c4c48b
Show file tree
Hide file tree
Showing 69 changed files with 8,705 additions and 2,691 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/release-and-pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,27 +175,4 @@ jobs:
password: ${{ secrets.FASTLANE_PYPI_API_TOKEN }}
repository-url: https://upload.pypi.org/legacy/

restart_jobs:
runs-on: ubuntu-latest
needs: combined_job
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Restart Databricks Jobs
run: |
echo "Getting list of jobs..."
JOB_LIST=$(curl -X GET -H "Authorization: Bearer ${{ secrets.SERVER_TOKEN }}" "https://${{ secrets.SERVER_DOMAIN }}/api/2.0/jobs/list")
echo "Jobs: $JOB_LIST"
for JOB in $(echo "${JOB_LIST}" | jq -r '.jobs[].job_id'); do
JOB_INFO=$(curl -X GET -H "Authorization: Bearer ${{ secrets.SERVER_TOKEN }}" "https://${{ secrets.SERVER_DOMAIN }}/api/2.0/jobs/get?job_id=$JOB")
CLUSTER_NAME=$(echo "$JOB_INFO" | jq -r '.settings.new_cluster.cluster_name')
if [ "$CLUSTER_NAME" = "Fastlane (v3)" ]; then
echo "Restarting job $JOB on cluster $CLUSTER_NAME..."
RESPONSE=$(curl -X POST -H "Authorization: Bearer ${{ secrets.SERVER_TOKEN }}" -d "{\"job_id\": $JOB}" "https://${{ secrets.SERVER_DOMAIN }}/api/2.0/jobs/run-now")
echo "Response: $RESPONSE"
fi
done

32 changes: 31 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,37 @@

## [Unreleased](https://github.com/bancorprotocol/fastlane-bot/tree/HEAD)

[Full Changelog](https://github.com/bancorprotocol/fastlane-bot/compare/v3.0.30...HEAD)
[Full Changelog](https://github.com/bancorprotocol/fastlane-bot/compare/v3.0.32...HEAD)

- Cleopatra and Stratum exchanges not handled correctly [\#488](https://github.com/bancorprotocol/fastlane-bot/issues/488)
- Test files under NBTest [\#448](https://github.com/bancorprotocol/fastlane-bot/issues/448)
- Mantle gas pricing and tx formatting needs to be handled correctly [\#386](https://github.com/bancorprotocol/fastlane-bot/issues/386)
- Incorrect Solidly Factory ABI used for scale & equalizer [\#372](https://github.com/bancorprotocol/fastlane-bot/issues/372)

- Add Support for multiple Carbon deployments per-chain [\#379](https://github.com/bancorprotocol/fastlane-bot/issues/379)
- Add support for Fantom Network [\#369](https://github.com/bancorprotocol/fastlane-bot/issues/369)
- python main.py --arb\_mode=b3\_two\_hop --alchemy\_max\_block\_fetch=200 --loglevel=INFO --backdate\_pools=False --polling\_interval=0 --reorg\_delay=0 --run\_data\_validator=False --limit\_bancor3\_flashloan\_tokens=True --randomizer=2 --default\_min\_profit\_gas\_token=0.01 --exchanges=carbon\_v1,bancor\_v3,uniswap\_v3,uniswap\_v2,sushiswap\_v2,balancer,pancakeswap\_v2,pancakeswap\_v3 --flashloan\_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,0x514910771AF9Ca656af840dff83E8264EcF986CA" [\#367](https://github.com/bancorprotocol/fastlane-bot/issues/367)
- Minor optimization in multicaller [\#348](https://github.com/bancorprotocol/fastlane-bot/issues/348)
- Add Handling of Flashloan Fee [\#346](https://github.com/bancorprotocol/fastlane-bot/issues/346)

Closed issues

- Fix rate-limit issue [\#375](https://github.com/bancorprotocol/fastlane-bot/issues/375)

## [v3.0.32](https://github.com/bancorprotocol/fastlane-bot/tree/v3.0.32) (2024-02-09)

[Full Changelog](https://github.com/bancorprotocol/fastlane-bot/compare/v3.0.31...v3.0.32)

- Update Base static data & small fix in Terraformer [\#363](https://github.com/bancorprotocol/fastlane-bot/pull/363) ([Lesigh-3100](https://github.com/Lesigh-3100))

Merged pull requests

- Release candidate [\#366](https://github.com/bancorprotocol/fastlane-bot/pull/366) ([zavelevsky](https://github.com/zavelevsky))
- Develop [\#365](https://github.com/bancorprotocol/fastlane-bot/pull/365) ([mikewcasale](https://github.com/mikewcasale))

## [v3.0.31](https://github.com/bancorprotocol/fastlane-bot/tree/v3.0.31) (2024-02-06)

[Full Changelog](https://github.com/bancorprotocol/fastlane-bot/compare/v3.0.30...v3.0.31)

Merged pull requests

Expand Down
3 changes: 2 additions & 1 deletion fastlane_bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .bot import CarbonBot as Bot, __VERSION__, __DATE__
from .config import Config, ConfigNetwork, ConfigDB, ConfigLogger, ConfigProvider

__version__ = "3.0.31"

__version__ = "3.1.1"
136 changes: 24 additions & 112 deletions fastlane_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,18 @@
from typing import Optional

from web3 import Web3
from web3.datastructures import AttributeDict

import fastlane_bot
from fastlane_bot.config import Config
from fastlane_bot.helpers import (
TxSubmitHandler,
TxSubmitHandlerBase,
TxReceiptHandler,
TxReceiptHandlerBase,
TxRouteHandler,
TxRouteHandlerBase,
TxHelpers,
TxHelpersBase,
TradeInstruction,
Univ3Calculator,
RouteStruct,
add_wrap_or_unwrap_trades_to_route,
split_carbon_trades
split_carbon_trades,
submit_transaction_tenderly
)
from fastlane_bot.helpers.routehandler import maximize_last_trade_per_tkn
from fastlane_bot.tools.cpc import ConstantProductCurve as CPC, CPCContainer, T
Expand All @@ -97,11 +91,7 @@ class CarbonBotBase:
----------
db: DatabaseManager
the database manager.
TxSubmitHandler: class derived from TxSubmitHandlerBase
the class to be instantiated for the transaction submit handler (default: TxSubmitHandler).
TxReceiptHandlerClass: class derived from TxReceiptHandlerBase
ditto (default: TxReceiptHandler).
TxRouteHandlerClass: class derived from TxRouteHandlerBase
TxRouteHandlerClass
ditto (default: TxRouteHandler).
TxHelpersClass: class derived from TxHelpersBase
ditto (default: TxHelpers).
Expand All @@ -112,8 +102,6 @@ class CarbonBotBase:
__DATE__ = __DATE__

db: QueryInterface = field(init=False)
TxSubmitHandler: any = None
TxReceiptHandlerClass: any = None
TxRouteHandlerClass: any = None
TxHelpersClass: any = None
ConfigObj: Config = None
Expand All @@ -135,17 +123,8 @@ def __post_init__(self):
self.polling_interval is None
), "polling_interval is now a parameter to run"

if self.TxReceiptHandlerClass is None:
self.TxReceiptHandlerClass = TxReceiptHandler
assert issubclass(
self.TxReceiptHandlerClass, TxReceiptHandlerBase
), f"TxReceiptHandlerClass not derived from TxReceiptHandlerBase {self.TxReceiptHandlerClass}"

if self.TxRouteHandlerClass is None:
self.TxRouteHandlerClass = TxRouteHandler
assert issubclass(
self.TxRouteHandlerClass, TxRouteHandlerBase
), f"TxRouteHandlerClass not derived from TxRouteHandlerBase {self.TxRouteHandlerClass}"

if self.TxHelpersClass is None:
self.TxHelpersClass = TxHelpers(ConfigObj=self.ConfigObj)
Expand Down Expand Up @@ -473,7 +452,7 @@ def _run(
randomizer=int,
data_validator=True,
replay_mode: bool = False,
) -> Optional[Tuple[str, List[Any]]]:
) -> Any:
"""
Runs the bot.
Expand All @@ -492,8 +471,7 @@ def _run(
Returns
-------
Optional[Tuple[str, List[Any]]]
The result.
Transaction hash.
"""
arbitrage = self._find_arbitrage(flashloan_tokens=flashloan_tokens, CCm=CCm, arb_mode=arb_mode, randomizer=randomizer)
Expand Down Expand Up @@ -1020,7 +998,7 @@ def _handle_trade_instructions(
self.ConfigObj.logger.info(
f"[bot._handle_trade_instructions] Opportunity with profit: {num_format(best_profit_gastkn)} does not meet minimum profit: {self.ConfigObj.DEFAULT_MIN_PROFIT_GAS_TOKEN}, discarding."
)
return None, None
return None

# Get the flashloan amount and token address
flashloan_token_address = fl_token
Expand Down Expand Up @@ -1067,17 +1045,12 @@ def _handle_trade_instructions(

# Check if the network is tenderly and submit the transaction accordingly
if self.ConfigObj.NETWORK == self.ConfigObj.NETWORK_TENDERLY:
return (
self._validate_and_submit_transaction_tenderly(
ConfigObj=self.ConfigObj,
flashloan_struct=flashloan_struct,
route_struct=route_struct_maximized,
src_amount=flashloan_amount_wei,
src_address=flashloan_token_address,
),
cids,
route_struct_maximized,
log_dict,
return submit_transaction_tenderly(
cfg=self.ConfigObj,
flashloan_struct=flashloan_struct,
route_struct=route_struct_maximized,
src_amount=flashloan_amount_wei,
src_address=flashloan_token_address,
)

# Log the route_struct
Expand All @@ -1094,21 +1067,16 @@ def _handle_trade_instructions(
tx_helpers = TxHelpers(ConfigObj=self.ConfigObj)

# Return the validate and submit transaction
return (
tx_helpers.validate_and_submit_transaction(
route_struct=route_struct_maximized,
src_amt=flashloan_amount_wei,
src_address=flashloan_token_address,
expected_profit_gastkn=best_profit_gastkn,
expected_profit_usd=best_profit_usd,
safety_override=False,
verbose=True,
log_object=log_dict,
flashloan_struct=flashloan_struct,
),
cids,
route_struct,
log_dict,
return tx_helpers.validate_and_submit_transaction(
route_struct=route_struct_maximized,
src_amt=flashloan_amount_wei,
src_address=flashloan_token_address,
expected_profit_gastkn=best_profit_gastkn,
expected_profit_usd=best_profit_usd,
safety_override=False,
verbose=True,
log_object=log_dict,
flashloan_struct=flashloan_struct,
)

def handle_logging_for_trade_instructions(self, log_id: int, **kwargs):
Expand Down Expand Up @@ -1212,56 +1180,6 @@ def log_flashloan_details(
f"[bot.log_flashloan_details] Trade Instructions: \n {best_trade_instructions_dic}"
)

def _validate_and_submit_transaction_tenderly(
self,
ConfigObj: Config,
route_struct: [RouteStruct],
src_address: str,
src_amount: int,
flashloan_struct: [Dict[str, Any]],
):
"""
Validate and submit the transaction tenderly
Parameters
----------
ConfigObj: Config
The Config object
route_struct: List[RouteStruct]
The route struct
src_address: str
The source address
src_amount: int
The source amount
flashloan_struct: List[Dict]
This is a list containing dicts that have Flashloan instructions
Returns
-------
Any
The transaction receipt
"""
tx_submit_handler = TxSubmitHandler(
ConfigObj=ConfigObj,
route_struct=route_struct,
flashloan_struct=flashloan_struct,
src_address=src_address,
src_amount=src_amount,
)
self.ConfigObj.logger.debug(
f"[bot._validate_and_submit_transaction_tenderly] route_struct: {route_struct}"
)
self.ConfigObj.logger.debug(
f"[bot._validate_and_submit_transaction_tenderly] src_address: {src_address}"
)
tx = tx_submit_handler.submit_transaction_tenderly(
route_struct=route_struct,
src_address=src_address,
src_amount=src_amount,
flashloan_struct=flashloan_struct,
)
return self.ConfigObj.w3.eth.wait_for_transaction_receipt(tx)

def validate_mode(self, mode: str):
"""
Validate the mode. If the mode is None, set it to RUN_CONTINUOUS.
Expand Down Expand Up @@ -1344,14 +1262,14 @@ def run_continuous_mode(
while True:
try:
CCm = self.get_curves()
tx_hash, cids, route_struct = self._run(
tx_hash = self._run(
flashloan_tokens,
CCm,
arb_mode=arb_mode,
data_validator=run_data_validator,
randomizer=randomizer,
)
if tx_hash and tx_hash[0]:
if tx_hash:
self.ConfigObj.logger.info(f"Arbitrage executed [hash={tx_hash}]")

time.sleep(self.polling_interval)
Expand Down Expand Up @@ -1509,12 +1427,6 @@ def run(
self.logging_path = logging_path
self.replay_from_block = replay_from_block

if self.TxSubmitHandler is None:
self.TxSubmitHandler = TxSubmitHandler(ConfigObj=self.ConfigObj)
assert issubclass(
self.TxSubmitHandler.__class__, TxSubmitHandlerBase
), f"[bot.run] TxSubmitHandler not derived from TxSubmitHandlerBase {self.TxSubmitHandler.__class__}"

if arb_mode in {"bancor_v3", "b3_two_hop"}:
run_data_validator = True
# The following logs are used for asserting various pytests, do not remove.
Expand Down
8 changes: 1 addition & 7 deletions fastlane_bot/config/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""


import subprocess
from abc import ABCMeta, ABC

from eth_typing import HexStr
Expand All @@ -16,7 +15,6 @@

import os
from dotenv import load_dotenv
from web3.middleware import geth_poa_middleware

load_dotenv()

Expand Down Expand Up @@ -157,7 +155,7 @@ def increment_nonce(self) -> None:
"""
self.nonce += 1

def connect_network(self, inject_middleware: bool):
def connect_network(self):
"""
Connect to the network
"""
Expand All @@ -169,9 +167,5 @@ def connect_network(self, inject_middleware: bool):
self.web3 = Web3(Web3.HTTPProvider(self.provider_url, request_kwargs={'timeout': 60}))
self.w3_async = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider(self.provider_url))

if inject_middleware:
self.web3.middleware_onion.inject(geth_poa_middleware, layer=0)
self.w3_async.middleware_onion.inject(geth_poa_middleware, layer=0)

logger.info(f"Connected to {self.network_id} network")
logger.info(f"Connected to {self.web3.provider.endpoint_uri} network")
1 change: 1 addition & 0 deletions fastlane_bot/config/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
PANCAKESWAP_V3_NAME = "pancakeswap_v3"
BUTTER_V3_NAME = "butter_v3"
AGNI_V3_NAME = "agni_v3"
FUSIONX_V3_NAME = "fusionx_v3"
CLEOPATRA_V3_NAME = "cleopatra_v3"
CARBON_V1_NAME = "carbon_v1"
CARBON_V1_FORK1_NAME = "altered_carbon"
Expand Down
6 changes: 2 additions & 4 deletions fastlane_bot/config/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
__VERSION__ = "0.9.1"
__DATE__ = "30/Apr 2023"

from web3.contract import Contract

from .base import ConfigBase
from . import selectors as S
from .network import ConfigNetwork
Expand Down Expand Up @@ -103,7 +101,7 @@ def __init__(self, network: ConfigNetwork, **kwargs):
provider_url=self.RPC_URL,
provider_name="alchemy",
)
self.connection.connect_network(network.NETWORK == N.NETWORK_MANTLE)
self.connection.connect_network()
self.w3 = self.connection.web3
self.w3_async = self.connection.w3_async
self.LOCAL_ACCOUNT = self.w3.eth.account.from_key(ETH_PRIVATE_KEY_BE_CAREFUL)
Expand Down Expand Up @@ -174,7 +172,7 @@ def __init__(self, network: ConfigNetwork, **kwargs):
provider_url=self.RPC_URL,
provider_name="tenderly",
)
self.connection.connect_network(network.NETWORK == N.NETWORK_MANTLE)
self.connection.connect_network()
self.w3 = self.connection.web3
self.LOCAL_ACCOUNT = self.w3.eth.account.from_key(ETH_PRIVATE_KEY_BE_CAREFUL)

Expand Down
Loading

0 comments on commit 0c4c48b

Please sign in to comment.