Hummingbot Gateway

repository·main·Indexed 42 days ago

https://github.com/hummingbot/gateway

A middleware API server (version 2.16.0) that provides a standardized REST interface for interacting with blockchain networks like Ethereum and Solana and various decentralized exchanges (DEXs). It abstracts protocol-specific complexities to enable trading bots to execute trades, manage liquidity, and check balances using consistent endpoints. It can be used as a standalone API server or integrated with the Hummingbot trading client.

Tokens
31.6K
Snippets
112
Records
164
Agent score
54%

What's inside Hummingbot Gateway

  1. Overview of PancakeSwap Solana CLMM Connector

    main

    The PancakeSwap Solana CLMM Connector integrates with PancakeSwap's Concentrated Liquidity Market Maker (CLMM) pools on Solana. It is a fork of Raydium CLMM and uses the same IDL (amm_v3) but operates with a unique Program ID.

    Key Technical Details:

    • Program ID: HpNfyc2Saw7RKkQd8nEL4khUcuPhQ7WwY1B2qjx8jxFq
    • Implementation: Uses manual buffer decoding for read-only operations (pool/position info) and Anchor instruction encoding for transactions (swaps/liquidity management).
    • Dependencies: Does not require the Raydium SDK.
  2. What is Hummingbot Gateway?

    main

    Hummingbot Gateway is a middleware API server that standardizes interactions with various blockchain networks and decentralized exchanges (DEXs). It provides a unified REST API to perform tasks like checking balances, executing trades, and managing wallets across different protocols (Ethereum, Solana, etc.) without needing to implement protocol-specific logic in your trading bot.

    Gateway can be used in two ways:

    1. Standalone API Server: Accessed directly via REST API endpoints.
    2. Hummingbot Client Integration: Used by the Hummingbot trading client to enable DEX trading and market making.
  3. Use the OKX DEX Aggregator Router Connector

    main

    The OKX DEX aggregator connector routes swaps across Solana DEX liquidity. It supports the mainnet-beta network (OKX chainIndex 501).

    This connector exposes the following standard Gateway router endpoints:

    • GET /connectors/okx/router/quote-swap
    • POST /connectors/okx/router/execute-quote
    • POST /connectors/okx/router/execute-swap
  4. Use the PancakeSwap Solana CLMM Connector

    main

    The PancakeSwap Solana CLMM Connector allows for interacting with PancakeSwap's Concentrated Liquidity Market Maker (CLMM) on the Solana network. It provides routes for reading pool information, managing liquidity positions, and executing swaps.

    Implemented Routes

    Read-Only Routes

    • Get Pool Info: Retrieve details about a specific liquidity pool.
    • Get Position Info: Retrieve details about a specific liquidity position.
    • Get Positions Owned: List all liquidity positions owned by a specific address.

    Swap Routes

    • Execute swaps using the PancakeSwap CLMM protocol on Solana.

    Position Management Routes

    • Manage liquidity positions (e.g., adding, removing, or modifying liquidity).
  5. Use the DFlow Router Connector

    main

    DFlow is a low-latency DEX aggregator for Solana. The Gateway connector exposes DFlow functionality through standard router endpoints. Note that this connector currently supports mainnet-beta only.

    Available endpoints:

    • GET /connectors/dflow/router/quote-swap: Retrieve a swap quote.
    • POST /connectors/dflow/router/execute-quote: Execute a previously obtained quote using a quoteId.
    • POST /connectors/dflow/router/execute-swap: Execute a direct swap.
  6. How the RPC Provider Abstraction works

    main

    Gateway uses an abstraction layer to allow switching between standard RPCs and optimized providers (like Infura for Ethereum or Helius for Solana).

    Key features include:

    • Provider Selection: Network configurations use the rpcProvider field to determine which provider to use.
    • Automatic Fallback: If an optimized provider is unavailable or unconfigured, the system gracefully falls back to a standard RPC.
    • Enhanced Capabilities: Optimized providers support features like WebSocket connections, transaction monitoring, and regional optimization.
    • Security: Provider API keys are isolated in dedicated configuration files located in conf/rpc/*.yml (e.g., infura.yml or helius.yml).
  7. Understand OKX connector execution flow and BUY orders

    main

    Execution Flow

    1. quote-swap: Calls the wallet-free GET /api/v6/dex/aggregator/quote and caches parameters under a quoteId.
    2. execute-quote: Because OKX transactions are wallet-bound, this step re-fetches GET /api/v6/dex/aggregator/swap using the executing wallet. This ensures a fresh route at execution time, bounded by the configured slippagePercent. The resulting unsigned transaction is then sent through Gateway's wallet-aware signer.

    BUY Orders

    • If OKX supports swapMode=exactOut, BUY orders are served natively.
    • Otherwise, the connector uses approximateIfNoExactOut=true (the default). In this mode, the input is approximated from a sell-leg exactIn quote, and the response is flagged with approximation: true.
  8. How EIP-1559 gas pricing works in Gateway

    main

    When submitting an EIP-1559 transaction, Gateway calculates the actual cost based on the network's baseFee and your configured parameters.

    The Formula: effectiveGasPrice = baseFee + min(maxPriorityFeePerGas, maxFeePerGas - baseFee)

    Example Calculation:

    • Configured maxFeePerGas: 0.1 GWEI
    • Configured maxPriorityFeePerGas: 0.01 GWEI
    • Network baseFee: 0.004 GWEI
    • Actual price paid: 0.004 + 0.01 = 0.014 GWEI
  9. How OKX request signing works

    main

    Every request sent by the connector includes the following headers:

    • OK-ACCESS-KEY
    • OK-ACCESS-PASSPHRASE
    • OK-ACCESS-TIMESTAMP (ISO 8601)
    • OK-ACCESS-SIGN

    The signature is generated using the following formula:

    base64(HMAC-SHA256(timestamp + method + requestPathWithQuery, secretKey))

    The connector ensures the signed string is byte-identical to the request path by serializing the query string itself.

  10. Best practices for RPC Provider implementation

    main

    When implementing a new RPC provider service, adhere to these principles:

    • Graceful Fallback: Always fall back to the standard RPC (e.g., StaticJsonRpcProvider) if the optimized provider is unavailable or the API key is missing.
    • Comprehensive Logging: Log provider selection, initialization steps, and any errors encountered.
    • Configuration Isolation: Store sensitive information like API keys in separate configuration files.
    • Network Mapping: Maintain a clear mapping between chain IDs and the provider's specific network naming convention.
    • Health Checks: Implement a healthCheck() method (e.g., by calling getBlockNumber()) to monitor provider availability.
    • WebSocket Support: Implement optional WebSocket support for real-time features.
    • Testing: Always create comprehensive live integration tests to verify the provider works with Gateway's API routes.
  11. Understand DFlow swap behavior and ExactIn constraints

    main

    When using the DFlow connector, be aware of the following operational logic:

    Execution Flow

    1. quote-swap calls DFlow's GET /quote and caches the response under a quoteId.
    2. execute-quote sends that quoteId to DFlow's POST /swap along with the executing wallet.
    3. DFlow returns a base64 transaction, which Gateway then signs using a local keypair or Ledger.

    BUY Orders and ExactIn

    DFlow is ExactIn-only. The API ignores swapMode parameters and always quotes ExactIn.

    • With approximateIfNoExactOut: true (Default): The required input is approximated from a sell-leg ExactIn quote. The response will be flagged with approximation: true, indicating the base amount received is an estimate.
    • With approximateIfNoExactOut: false: BUY requests will fail with an error.
  12. How Gateway's modular architecture works

    main

    Gateway is organized into several distinct layers to separate blockchain logic, DEX protocols, and core services:

    • Chains (src/chains): Contains blockchain-specific implementations (e.g., Ethereum, Solana). Each chain module includes core operations like getBalances and getTokens, chain-specific API routes, and configuration management. It also supports RPC Provider Services (like Infura or Helius) for optimized connectivity.
    • Connectors (src/connectors): Houses DEX protocol implementations. Connectors are subdivided into:
      • Router operations (router-routes/): Aggregator functionality for quoting and executing swaps (e.g., using the execute-quote pattern).
      • AMM operations (amm-routes/): Management of liquidity in V2-style Automated Market Maker pools.
      • CLMM operations (clmm-routes/): Management of Concentrated Liquidity pools with custom price ranges.
    • Services (src/services): Provides core infrastructure such as config-manager-v2.ts for validated configuration, logger.ts for logging, and token-service.ts for secure token list management.
    • Schemas (src/schemas): Uses TypeBox to define API request and response structures for routers, AMMs, and CLMMs.
    • Wallet (src/wallet): Handles wallet management logic.