Fastlane Arbitrage Bot

repository·main·Indexed 41 days ago

https://github.com/bancorprotocol/fastlane-bot

An open-source arbitrage system designed to identify and execute arbitrage opportunities between Carbon, Bancor, and other DEXes using atomic flashloan transactions. Version 3.2.7 includes an Invariants Module for high-performance analysis of AMM invariant functions and supports multiple arbitrage modes including single, multi, and triangular arbitrage across various blockchain networks.

Tokens
15.7K
Snippets
46
Records
87
Agent score
50%

What's inside Fastlane Bot

  1. Use the Invariants module for formal verification

    main
    The tools.invariants module provides a framework for defining and checking invariants within the bot. It is composed of several sub-modules including functions, invariant, and helpers (which includes vector and kernel utilities). This module is used to ensure that the bot's state or specific execution paths adhere to required logical constraints.
  2. Use the ArbGraphs module for arbitrage graph modeling

    main
    The tools.arbgraphs module provides the infrastructure for modeling arbitrage opportunities as directed graphs. It allows for the representation of assets as nodes and exchange rates/liquidity paths as edges, enabling the detection of profitable cycles (arbitrage paths) within a network of liquidity pools or exchanges.
  3. Understand the difference between tools and helpers modules

    main

    The project distinguishes between two internal modules: tools and helpers.

    • tools module: These modules are designed to be importable from within the Carbon library.
    • helpers module: These modules cannot be imported from within the Carbon library.

    Warning: Neither tools nor helpers are part of the official Carbon API. Their structure and availability may change at any time without notice.

  4. Understand the Invariants Module purpose

    main

    The Invariants Module is designed for high-performance analysis of Automated Market Maker (AMM) invariant functions, specifically of the form $f(x,y) = k$.

    Its primary goal is to allow the FastLane Arbitrage bot to approximate complex, non-analytically tractable invariant functions (like the Solidly stable swap invariant $f(x,y) = x^3y + xy^3$) using piecewise constant product invariant functions ($f(x,y) = xy$). This approach avoids the performance penalty of purely numerical solutions while maintaining accuracy for arbitrage calculations.

  5. Understand Constant Product Curves (CPC) and CurveBase

    main

    In the fastlane-bot ecosystem, a Constant Product Curve (CPC) refers to the hyperbolic curve defined by the formula $xy=k$, which is the standard model for many Automated Market Makers (AMMs).

    To ensure compatibility with the Optimizer module, all curve implementations must derive from the CurveBase abstract base class. CurveBase defines the required interface and functions that any curve class must implement to be used by the optimizer for arbitrage calculations.

  6. Use the main Optimizer modules

    main

    The bot provides several specialized optimizer classes for arbitrage calculations. All these modules derive from the CPCArbOptimizer base class. Depending on your specific arbitrage strategy, you should choose one of the following:

    • MargPOptimizer: Used for specific marginal profit optimization.
    • PairOptimizer: Used for optimizing arbitrage between specific pairs.
    • ConvexOptimizer: Used when the optimization problem can be modeled as a convex optimization problem.
  7. Construct arbitrage graphs using Node, Edge, Path, and Cycle classes

    main

    To build a complete arbitrage model, use the following component classes:

    • Node: Represents an individual asset or state in the graph.
    • Edge: Represents a directed liquidity path or exchange rate between two nodes.
    • Path: A sequence of edges representing a traversal through the graph.
    • Cycle: A specific type of path that starts and ends at the same node, used to identify potential arbitrage loops.
    • Amount: A utility class for handling the quantities of assets involved in the graph operations.
  8. How the Fastlane Bot identifies and executes arbitrage

    main
    The Fastlane Bot identifies arbitrage opportunities by searching for price discrepancies between different Decentralized Exchanges (DEXes). Once an opportunity is identified, the bot submits a transaction to the Fast Lane contract. The contract then takes a flashloan and executes the necessary trades to close the arbitrage loop.
  9. Understand Weighted Constant Product Formulas

    main

    The Weighted Constant Product model uses a parameter $\alpha$ to define the weight of token $x$ in a liquidity pool. When $\alpha = 1/2$, it behaves as a standard constant product market maker. The model uses several mathematical relationships to determine token balances, the pool invariant $k$, and the marginal price $p$.

    ### Parameter Definitions
    - $x, y$: Token balances in native units
    - $\alpha$: Weight of the $x$ token
    - $\lambda$: Weight ratio, where $\lambda = \alpha / (1 - \alpha)$
    - $k$: The pool invariant