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.

  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

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);

The plugin provides the following operations:

  • Token swaps between any supported tokens
  • Quote retrieval for swap rates

Here’s how to interact with your Odos-enabled agent:

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"
}

Query:

Swap 100 DAI to FXS

The agent will structure this as:

{
"fromToken": "0x...[DAI address]",
"toToken": "0x...[FXS address]",
"chain": "252",
"amount": "100000000"
}

The Odos plugin accepts these configuration parameters:

interface OdosActionParams {
chain: Chain; // Blockchain network configuration
walletPrivateKey: string; // Private key for transactions
}

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);
}
  • Amount Verification: Double-check token amounts and decimals
  • Token Approval: Ensure proper token approvals before swaps
  • 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