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
Section titled “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-key
Basic Setup
Section titled “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
Section titled “Available Operations”The plugin provides the following operations:
- Token swaps between any supported tokens
- Quote retrieval for swap rates
Usage Examples
Section titled “Usage Examples”Here’s how to interact with your Odos-enabled agent:
Getting a Quote
Section titled “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
Section titled “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
Section titled “Configuration Options”The Odos plugin accepts these configuration parameters:
interface OdosActionParams { chain: Chain; // Blockchain network configuration walletPrivateKey: string; // Private key for transactions}
Error Handling
Section titled “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
Section titled “Best Practices”- Amount Verification: Double-check token amounts and decimals
- Token Approval: Ensure proper token approvals before swaps
Common Issues and Troubleshooting
Section titled “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