Skip to content

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

  1. Install the required packages:

    Terminal window
    npm i @iqai/plugin-odos
  2. Create a .env file with required configuration:

    WALLET_PRIVATE_KEY=your-wallet-private-key
    OPENAI_API_KEY=your-openai-api-key

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

  1. Amount Verification: Double-check token amounts and decimals
  2. 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