bancorprotocol / fastlane-bot

Fast Lane, an open-source arbitrage protocol, allows any user to perform arbitrage between Bancor ecosystem protocols and external exchanges and redirect arbitrage profits back to the protocol.
https://github.com/bancorprotocol/fastlane-bot
MIT License
133 stars 58 forks source link
arbitrage-trading-bot bancor-protocol defi

Fastlane Arbitrage Bot

⚠️ WARNING: Use at Your Own Risk

The Fastlane Bot requires an Ethereum private key. Your funds are AT RISK when you run the Fastlane Arbitrage Bot. Read the Preparation section below. The bot is provided as-is, with the authors and the Bprotocol Foundation not liable for any losses.

Overview

Arbitrage opportunities occur when token prices between DEXes are imbalanced, and can be closed by making specific trades on the imbalanced DEXes.

The Fastlane is an open-source system that anyone can run, consisting of the Fastlane smart contract, and the Fastlane Arbitrage Bot.

The Fastlane Arbitrage Bot identifies arbitrage opportunities and closes them by executing trades using the Fastlane Smart Contract. The bot can search for opportunities between Carbon and Carbon forks, Bancor, and other DEXes. This enhances market efficiency by aligning Carbon, Carbon forks, and Bancor with market trends.

The system works by executing atomic transactions that take flashloans to fulfill the capital requirements of trades, meaning only gas costs are required to submit transactions.

Permanent URL for this repository: github.com/bancorprotocol/fastlane-bot

For frequently asked questions, see FAQ.

Profit Split

Any profit from an arbitrage trade is split between the contract caller & the Protocol.

Competition

The Fastlane Arbitrage Bot is competitive in nature. Bot operators compete to close arbitrage opportunities. There are many ways to improve a bot's competitiveness; the following document contains a short list of ideas on how to make a bot more competitive: How to make your bot competitive.

Getting Started

Installation

Install Fastlane Arbitrage Bot from PyPi using the following command:

Clone the repo from Bancor's GitHub and install:

git clone https://github.com/bancorprotocol/fastlane-bot
cd fastlane-bot
pip install poetry
poetry install

Once the environment is ready, all commands should be prepended with poetry run in order to be executed in the corresponding virtual environment. Alternatively, virtual environment can be activated once using poetry shell.

Legacy Installation (v1.0)

You can access the legacy version of the Fastlane Arbitrage Bot, which was solely designed to facilitate single triangle arbitrage transactions which both initiate and conclude with BNT on the Bancor V3 exchange, by referring to the following link:

github.com/bancorprotocol/fastlane-bot/releases/tag/v1.0

Dependencies

Project depends on poetry and pyproject.toml. However, in order to preserve backward compatibility, after any change to dependencies, the following command should be run, to update requirement.txt

poetry export --without-hashes --format=requirements.txt > requirements.txt

Preparation

The Fastlane Arbitrage Bot needs access to an Ethereum wallet's private key. THIS KEY IS AT RISK AND SHOULD NOT BE USED ELSEWHERE. Maintain some ETH in the wallet for gas fees and regularly sweep profits. Supply the private key to the bot using an environment variable, as shown:

set ETH_PRIVATE_KEY_BE_CAREFUL="0x9c..."

The bot also needs access to the Ethereum blockchain, preconfigured to use Alchemy. Obtain a free API key from alchemy.com and supply it to the bot using an environment variable:

set WEB3_ALCHEMY_PROJECT_ID="0-R5..."

The bot uses python-dotenv to load environment variables from a .env file in the root directory. However, this is not recommended for security reasons, especially on unencrypted disks.

export WEB3_ALCHEMY_PROJECT_ID="0-R5..."
export ETH_PRIVATE_KEY_BE_CAREFUL="0x9c..."
export WEB3_ALCHEMY_BASE="api_key_here"
export WEB3_FANTOM="api_key_here"
export WEB3_MANTLE="api_key_here"
export WEB3_LINEA="api_key_here"
export WEB3_SEI="api_key_here"

Note: To use the Fantom public RPC, write "public" in place of the API key.

Execution

After installation, run the bot with default parameters using the command:

poetry run python main.py 

Configuration Options

You can configure the Fastlane Arbitrage Bot using the options in the @click.option section of main.py. An overview of options is provided below:

Specify options in the command line. For example:

poetry run python main.py --arb_mode=multi --polling_interval=12 --reorg_delay=10 --loglevel=INFO

Troubleshooting

If you encounter import errors or ModuleNotFound exceptions, try:

poetry run python <absolute_path>/main.py

Change Log

We follow semantic versioning (major.minor.patch), updating the major number for backward incompatible API changes, minor for compatible changes, and patch for minor patches.

Example Start Configurations

The following examples are command-line inputs that start the bot with different configurations:

Bancor V3-focused arbitrage

poetry run 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"

Carbon-focused pairwise arbitrage

poetry run python main.py --arb_mode=multi --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --run_data_validator=False --default_min_profit_gas_token=0.01 --randomizer=2 --exchanges=bancor_v3,bancor_v2,carbon_v1,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"

Unfocused pairwise arbitrage

poetry run python main.py --arb_mode=multi_pairwise_all --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --run_data_validator=False --default_min_profit_gas_token=0.01 --randomizer=2 --exchanges=bancor_v3,bancor_v2,carbon_v1,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"

Triangular Carbon-focused arbitrage

poetry run python main.py --arb_mode=multi_triangle --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --run_data_validator=False --default_min_profit_gas_token=0.01 --randomizer=2 --exchanges=bancor_v3,bancor_v2,carbon_v1,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"