Odos Plugin
The Odos plugin enables your agent to perform token swaps and exchanges using the Odos protocol. It provides optimized routing for token exchanges with competitive rates.
Installation
-
Install the required packages:
Terminal window npm i @iqai/plugin-odosTerminal window pnpm add @iqai/plugin-odosTerminal window yarn add @iqai/plugin-odos -
Create a
.env
file with required configuration:WALLET_PRIVATE_KEY=your-wallet-private-keyOPENAI_API_KEY=your-openai-api-keyNever commit your
.env
file or share your private key. Anyone with access to your private key can control your wallet and funds. Make sure to:- Add
.env
to your.gitignore
file - Never share your private key in any form
- Use a dedicated development wallet with limited funds
- Add
Basic Setup
Hereβs how to set up an agent with the Odos plugin:
import { AgentBuilder, ModelProviderName } from "@iqai/agent";import { createOdosPlugin } from "@iqai/plugin-odos";import { fraxtal } from "viem/chains";
async function main() { // Initialize Odos plugin const odosPlugin = await createOdosPlugin({ chain: fraxtal, walletPrivateKey: process.env.WALLET_PRIVATE_KEY, });
// Create agent with plugin const agent = new AgentBuilder() .withModelProvider( ModelProviderName.OPENAI, process.env.OPENAI_API_KEY ) .withPlugin(odosPlugin) .build();
await agent.start();}
main().catch(console.error);
Available Operations
The plugin provides the following operations:
- Token swaps between any supported tokens
- Quote retrieval for swap rates
Usage Examples
Hereβs how to interact with your Odos-enabled agent:
Getting a Quote
Query:
Get me a quote for swapping 1 wfrxEth to FRAX on Fraxtal
The agent will process this to:
{ "fromToken": "0x...[wfrxEth address]", "toToken": "0x...[FRAX address]", "chain": "252", "amount": "1000000000000000000"}
Performing a Swap
Query:
Swap 100 DAI to FXS
The agent will structure this as:
{ "fromToken": "0x...[DAI address]", "toToken": "0x...[FXS address]", "chain": "252", "amount": "100000000"}
Configuration Options
The Odos plugin accepts these configuration parameters:
interface OdosActionParams { chain: Chain; // Blockchain network configuration walletPrivateKey: string; // Private key for transactions}
Error Handling
Implement proper error handling when using the plugin:
try { const odosPlugin = await createOdosPlugin({ chain: fraxtal, walletPrivateKey: process.env.WALLET_PRIVATE_KEY, });} catch (error) { console.error('Failed to initialize Odos plugin:', error);}
Best Practices
- Amount Verification: Double-check token amounts and decimals
- Token Approval: Ensure proper token approvals before swaps
Common Issues and Troubleshooting
- Insufficient Balance: Ensure you have enough tokens for the swap
- Token Approval: Check if tokens are approved for swapping
- Network Congestion: Consider retry mechanisms during high network activity
Token availability may vary based on network liquidity and market conditions