Skip to main content

Radius plugin for Uniswap

Project description

Radius AI Agent Toolkit - Uniswap Plugin

This plugin enables AI agents to interact with the Uniswap protocol on Radius, allowing them to get token quotes and perform token swaps.

This package is part of the Radius AI Agent Toolkit, which provides tools for integrating AI agents with the Radius platform.

Installation

# Install this specific package
pip install radius-ai-agent-sdk-plugin-uniswap

# Required dependencies
pip install radius-ai-agent-sdk
pip install radius-ai-agent-sdk-wallet-evm
pip install radius-ai-agent-sdk-wallet-web3
pip install radius-ai-agent-sdk-plugin-erc20

Prerequisites

  • Python >=3.10
  • Uniswap API key - Get it from: Uniswap Hub
  • Radius wallet setup with a funded account

Configuration

Required environment variables:

  • UNISWAP_API_KEY: Your Uniswap API key
    • Format: 32-character string
    • Required for: Accessing Uniswap's API for quotes and swaps
  • UNISWAP_BASE_URL: Uniswap API base URL
    • Format: Full URL with protocol and version
    • Default: https://api.uniswap.org/v1

Usage

from radius_plugins.uniswap import uniswap, UniswapPluginOptions
from radius_wallets.evm import create_evm_wallet_client
from radius.utils.get_tools import get_on_chain_tools

# Create a Radius wallet
wallet = await create_evm_wallet_client({
    "rpc_url": "YOUR_RPC_URL",
    "private_key": "YOUR_PRIVATE_KEY"
})

# Initialize the Uniswap plugin
uniswap_plugin = uniswap(UniswapPluginOptions(
    base_url=os.environ.get("UNISWAP_BASE_URL", "https://api.uniswap.org/v1"),
    api_key=os.environ.get("UNISWAP_API_KEY")
))

# Create AI agent tools with the Uniswap plugin
tools = await get_on_chain_tools(wallet=wallet, plugins=[uniswap_plugin])

API Reference

uniswap(options)

Creates a new Uniswap plugin instance.

Parameters:

  • options.base_url (string): Uniswap API base URL
  • options.api_key (string): Your Uniswap API key

Returns:

  • A UniswapPlugin instance that can be used with AI agent frameworks

Provided Tools

The Uniswap plugin provides the following AI agent tools:

uniswap_check_approval

Checks if a wallet has enough token approval for a swap.

Parameters:

  • token (string): The token address to check approval for
  • amount (string): The amount to approve
  • walletAddress (string): The wallet address to check

Example:

try:
    approval_status = await check_approval_tool.execute({
        "token": "0x51fCe89b9f6D4c530698f181167043e1bB4abf89",  # USDC on Radius testnet
        "amount": "1000000",  # 1 USDC (6 decimals)
        "walletAddress": "0xefbf7a6fa61a1602eb7630c92e79e5b6e63909e1"
    })
    
    print("Approval status:", approval_status)
    # { "status": "approved", "txHash": "0x..." }
except Exception as error:
    print(f"Approval check failed: {error}")

uniswap_get_quote

Gets a quote for swapping tokens.

Parameters:

  • tokenIn (string): The address of the input token
  • tokenOut (string): The address of the output token
  • amount (string): The amount of tokenIn to swap
  • type (string): The type of swap ("EXACT_INPUT" or "EXACT_OUTPUT")
  • protocols (list[string]): The protocols to use for the swap (e.g., ["V3"])

Example:

try:
    quote_params = {
        "tokenIn": "0x9aeEa4f3025940dBdbf6863C7e16a23Ea95272a4",   # RADUSD on Radius testnet
        "tokenOut": "0x51fCe89b9f6D4c530698f181167043e1bB4abf89",  # USDC on Radius testnet
        "amount": "1000000000000000000",  # 1 RADUSD (18 decimals)
        "type": "EXACT_INPUT",
        "protocols": ["V3"]
    }
    
    quote = await get_quote_tool.execute(quote_params)
    print("Swap quote result:", quote)
    # Quote data including estimated gas, output amount, etc.
except Exception as error:
    print(f"Getting quote failed: {error}")

uniswap_swap_tokens

Executes a token swap on Uniswap.

Parameters:

  • tokenIn (string): The address of the input token
  • tokenOut (string): The address of the output token
  • amount (string): The amount of tokenIn to swap
  • type (string): The type of swap ("EXACT_INPUT" or "EXACT_OUTPUT")
  • protocols (list[string]): The protocols to use for the swap (e.g., ["V3"])

Example:

try:
    swap_params = {
        "tokenIn": "0x9aeEa4f3025940dBdbf6863C7e16a23Ea95272a4",   # RADUSD on Radius testnet
        "tokenOut": "0x51fCe89b9f6D4c530698f181167043e1bB4abf89",  # USDC on Radius testnet
        "amount": "1000000000000000000",  # 1 RADUSD (18 decimals)
        "type": "EXACT_INPUT",
        "protocols": ["V3"]
    }
    
    swap_result = await swap_tokens_tool.execute(swap_params)
    print("Swap transaction:", swap_result)
    # { "txHash": "0x..." }
except Exception as error:
    print(f"Swap failed: {error}")

Note on Tool Naming: The Uniswap plugin explicitly prefixes its tool names with uniswap_ in the implementation, which is consistent with the final available tool names.

Integration Examples

For a complete example integrating this plugin with LangChain, see:

Related Packages

Resources

Contributing

Please see the Contributing Guide for detailed information about contributing to this toolkit.

License

This project is licensed under the MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

radius_ai_agent_sdk_plugin_uniswap-1.0.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file radius_ai_agent_sdk_plugin_uniswap-1.0.0.tar.gz.

File metadata

File hashes

Hashes for radius_ai_agent_sdk_plugin_uniswap-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2da54c1795275f7b762479b1f367726c0cfd85a008902765ec23dde08ea8bb3a
MD5 24517dcce25d9880c2824627e0df6fea
BLAKE2b-256 ed11eeab82f3232d9f44ac9c01bc5a3d1b79da77f68293ff0d4245f35a842a56

See more details on using hashes here.

File details

Details for the file radius_ai_agent_sdk_plugin_uniswap-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for radius_ai_agent_sdk_plugin_uniswap-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd50974798154ba037e48370273991fb81ae1005fa0a52632f089121ab2f8a77
MD5 71bc9fa2dc8358f66418622d2e18c67e
BLAKE2b-256 2bfcaf7dc963476000f7dcac303cea05e486d256d8d9fd69954a0cb2ee52ecd1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page