BotFi Docs
  • Intro
    • 🏩Welcome
    • ☔Why BotFi?
    • 🧩Features
  • 🕒Roadmap
  • BotFi
    • 🪙Tokenomics
    • 💰Revenue Allocation
    • 🛡️Audits
  • Developers
    • 📃Smart Contracts
      • BotFi Swap Engine
    • ⛓️Deployments
  • Guides
    • 🟢Getting started with BotFi
    • 🟡 Import an existing seed phrase into BotFi
    • 🔵Import a whitelisted ERC-20 token
    • 🟠Import a custom ERC-20 token
    • 🟤Switch between blockchain networks on BotFi
    • ⚪Executing swaps on BotFi
Powered by GitBook
On this page
  • Events
  • Functions
  1. Developers
  2. Smart Contracts

BotFi Swap Engine

PreviousSmart ContractsNextDeployments

Last updated 1 year ago

The smart contract codes for BotFi's Swap Engine are accessible on GitHub:

Events

Swap

// The event emitted after a successful swap
    event Swap(
        bytes32 routerId, 
        uint256 amount,
        address tokenA,
        uint    feeBps,
        address account  
    );

routerId: bytes32

The route ID bytes32 format. amount: uint256

The total transaction amount with protocol fee inclusive

tokenA: Address

The token that was exchanged for another.

feeBps: uint

The protocol fee percentage in basis point

account: Address

The address of the account that initiated the transaction

Functions

addRoute

   function addRoute(
        bytes32             id,
        bytes32             group, // uni_v2, uni_v3, 1inch, ...                  
        address  payable    router, 
        address             factory,
        address             weth,
        address             quoter,
        bool                enabled
    ) 

id: bytes32

The router ID should be an empty bytes32 string for a new route and a valid route ID when editing an existing route. For new routes, an incremental ID is automatically generated.

group: bytes32

The route group categorises liquidity sources into various groups based on their functions. For example, all DEXs using Uniswap v2 source code are grouped as uni_v2.

router: address

The router address of the liquidity source, such as the Uniswap v2 router address.

factory: address

The factory address of the liquidity source, such as the Uniswap v2 factory address.

weth: address

The address of the wrapped Ether or wrapped native token used on the chain.

quoter: address

The quoter is a smart contract where quotes are queried from off-chain sources, such as the swap user interface, before executing a swap. For uni_v2-based contracts, this field is always set to 0x0000000000000000000000000000.

enabled: bool

A boolean value indicating whether the route should be active (true) or not (false).

enableRoute

function enableRoute(bytes32 id, bool opt)

A helper function to quickly enable or disable a route

id: bytes32

The route ID in bytes32 format.

opt: bool

A boolean value indicating whether the route should be active (true) or not (false).

getAllRoutes

   function getAllRoutes()
        external
        view 
        returns (RouteParams[] memory rp)
    {

This function retrieves all routes and returns an array of RouteParams, encompassing both active and inactive routes

pauseSwap

  function pauseSwap(bool opt) 

This function allows the activation or deactivation of BotFi's swap engine.

opt: bool

The 'opt' parameter accepts a boolean value indicating whether the swap engine should be enabled (true) or disabled (false).

swap

  function swap(
        bytes32 routeId,
        uint256 amount, 
        address tokenA, 
        bytes calldata payload
    ) 

This function executes a swap based on the payload provided

routeId: bytes32

The route ID in bytes32 format.

amount: uint256

The total transaction amount with protocol fee inclusive

tokenA: Address

The token to be exchanged for another.

payload: bytes

The payload represents the calldata of the liquidity source, computed off-chain to save gas and enhance flexibility.

📃
https://github.com/botfi-app/botfi-swap