Skip to main content

OKX DEX Integration

Solana Agent Kit provides comprehensive integration with OKX DEX for token swapping, price quotes, and market data. This documentation covers the available actions and tools for interacting with OKX DEX.

Overview

OKX DEX integration allows you to:
  • Fetch chain data and supported tokens
  • Get price quotes for token swaps
  • Execute token swaps with customizable slippage
  • View available liquidity sources
  • Create LangChain tools for AI agent integration

Actions

Actions provide high-level functionality for common OKX DEX operations.

Chain Data

The OKX_DEX_CHAIN_DATA action retrieves information about blockchain networks supported by OKX DEX.

Tokens

The OKX_DEX_TOKENS action lists all tokens supported by OKX DEX.

Liquidity

The OKX_DEX_LIQUIDITY action retrieves available liquidity sources supported by OKX DEX.

Quote

The OKX_DEX_QUOTE action provides price quotes for token swaps.

Swap

The OKX_DEX_SWAP action executes token swaps on OKX DEX.

LangChain Tools

For AI agent integration with LangChain, the following tools are available:

Get Chain Data Tool

Get Tokens Tool

Get Liquidity Tool

Get Quote Tool

Execute Swap Tool

Confirm Swap Tool

Token Addresses

Here are some common token addresses for Solana:

Amount Conversion

When working with token amounts, you need to convert between human-readable amounts and base units (like lamports for SOL):

Error Handling

All actions and tools include error handling. Here’s an example of handling errors:

Advanced Features

Auto Slippage

You can enable auto slippage for potentially better swap rates:

Custom Wallet Address

You can specify a custom wallet address for the swap:

Integration with AI Agents

For AI agents built with LangChain, you can register these tools:

Best Practices

  1. Amount Validation: Always verify that amounts are positive and within acceptable ranges.
  2. Slippage Control: Use appropriate slippage values depending on token volatility.
  3. Error Handling: Implement comprehensive error handling for all operations.
  4. Gas Considerations: Make sure your wallet has enough SOL for transaction fees.
  5. User Confirmation: For UIs, always show and confirm quotes before executing swaps.

Troubleshooting

Common issues and their solutions:
  1. Insufficient Funds: Make sure your wallet has enough tokens for the swap.
  2. Price Impact Too High: Try reducing the amount or increasing slippage.
  3. Invalid Token Address: Double-check token addresses or use predefined constants.
  4. Failed Transaction: Check chain congestion and try again with higher slippage.

Resources