Skip to content

Conversation

@Thedongraphix
Copy link

Summary

This PR introduces a new Uniswap V3 Action Provider for the Base network, enabling AI agents to perform token swaps on one of the most popular DEXs. This addresses a fundamental need for onchain agents and directly responds to functionality mentioned in the project's WISHLIST.md.

Motivation

Token swaps are a core primitive for DeFi operations. Every onchain agent needs the ability to exchange tokens, whether for:

  • Portfolio rebalancing
  • Yield farming strategies
  • Arbitrage opportunities
  • Basic token acquisition

This provider makes it simple for agents to get quotes and execute swaps with a single tool call.

Key Features

🔄 Two Core Actions

  • get_quote: Get swap quotes without executing (for planning & price discovery)
  • swap: Execute token swaps with comprehensive safety features

🛡️ Built-in Safety & UX

  • Slippage Protection: Configurable slippage tolerance (default 0.5%)
  • Automatic ERC20 Approvals: Handles token allowances automatically
  • Native ETH Support: Seamlessly works with WETH for ETH swaps
  • Clear Error Messages: Helpful feedback for troubleshooting

🌐 Network Support

  • Base Mainnet
  • Base Sepolia (for testing)

Implementation Details

Files Added

typescript/agentkit/src/action-providers/uniswap/
├── constants.ts # Contract addresses & ABIs
├── schemas.ts # Input validation schemas
├── uniswapActionProvider.ts # Main implementation
├── index.ts # Exports
└── tests/
└── uniswapActionProvider.test.ts # Unit tests

Architecture

  • Modular Design: Self-contained provider following agentkit patterns
  • Type Safety: Full TypeScript support with Zod validation
  • Consistent API: Uses same patterns as existing providers (ERC20, Compound, etc.)
  • Extensible: Easy to add more Uniswap features in the future

Usage Example

// Get a quote
const quote = await agent.getQuote({
  tokenIn: "0x...", // USDC address
  tokenOut: "0x...", // WETH address  
  amount: "100",    // 100 USDC
  fee: 3000        // 0.3% fee tier
});

// Execute swap
const result = await agent.swap({
  tokenIn: "0x...",
  tokenOut: "0x...",
  amount: "100",
  slippageTolerance: 0.5, // 0.5%
  fee: 3000
});

Testing

  • ✅ TypeScript compilation passes (npm run build)
  • ✅ Unit tests verify network support
  • ✅ Follows existing test patterns
  • ✅ Proper error handling

Value Proposition

This provider:

  • Solves a core need: Every agent needs token swaps
  • Reduces complexity: Handles approvals, slippage, and edge cases automatically
  • Follows best practices: Uses established agentkit patterns
  • Enables innovation: Unblocks agents from building advanced DeFi strategies

Breaking Changes

None - this is a purely additive change.

Additional Context

This implementation focuses on the most commonly used Uniswap V3 functionality while maintaining simplicity and safety. Future enhancements could include:

  • Multi-hop swaps
  • Liquidity provision
  • Fee tier optimization
  • Advanced order types

Ready to empower AI agents with seamless token swapping on Base!

@cb-heimdall
Copy link

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

@github-actions github-actions bot added action provider New action provider typescript labels Jul 6, 2025
@phdargen
Copy link
Contributor

Hi @Thedongraphix, thanks for your contribution! Looks pretty good, a few initial comments below.

*/
export const SwapSchema = z
.object({
tokenIn: z.string().describe("The contract address of the token to swap from"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest to use .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format"), for all contract addresses

import { uniswapActionProvider } from "../uniswapActionProvider";

describe("UniswapActionProvider", () => {
const actionProvider = uniswapActionProvider();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for the logic of each action. As a guide you can have a look at eg https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/action-providers/flaunch/flaunchActionProvider.test.ts that also tests some swap actions

@phdargen
Copy link
Contributor

It would be good to include the result of some manual end-to-end testing in the PR description. Add the new uniswap action provider to one of the chatbot examples, run it and copy your prompts + output for quote and swap queries here.

Please keep changes to the chatbot examples local and do not commit them.

/**
* Uniswap V3 contract addresses for Base networks
*/
export const UNISWAP_ADDRESSES: Record<string, Record<string, string>> = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: could be extended to a few more chains like ethereum, optimism, arbitrum, polygon (https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/network/network.ts)

You can find the contract addresses here:
https://docs.uniswap.org/contracts/v3/reference/deployments/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants