FraxLend Plugin
The FraxLend plugin enables your agent to interact with FraxLend protocol, providing comprehensive lending and borrowing capabilities. It supports various operations including lending, borrowing, withdrawing, and managing collateral on the Fraxtal network.
Installation
Section titled “Installation”-
Install the required packages:
Terminal window npm i @iqai/plugin-fraxlendTerminal window pnpm add @iqai/plugin-fraxlendTerminal window yarn add @iqai/plugin-fraxlend -
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 a complete example of setting up an agent with the FraxLend plugin:
import { AgentBuilder, ModelProviderName } from "@iqai/agent";import { createFraxlendPlugin } from "@iqai/plugin-fraxlend";import { fraxtal } from "viem/chains";
async function main() { // Initialize FraxLend plugin const fraxlendPlugin = await createFraxlendPlugin({ 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(fraxlendPlugin) .build();
await agent.start();}
main().catch(console.error);
Available Operations
Section titled “Available Operations”The plugin provides the following operations:
- Lending Management
- Deposit assets
- Withdraw assets
- Borrowing Operations
- Borrow assets
- Repay borrowed amounts
- Collateral Management
- Add collateral
- Remove collateral
- Information Retrieval
- Get lending statistics
- View agent positions
- Find pair addresses
Usage Examples
Section titled “Usage Examples”Here’s how to interact with your FraxLend-enabled agent through natural language:
Finding Pair Addresses
Section titled “Finding Pair Addresses”Query:
What's the pair address for FRAX-ETH pool with the highest APR?
The agent will process this to:
{ "assetSymbol": "FRAX", "collateralSymbol": "ETH", "sortByApr": "highest"}
Lending Assets
Section titled “Lending Assets”Query:
I want to lend 100 FRAX to the FRAX-ETH pool at 0x123...abc
Agent processes this as:
{ "pairAddress": "0x123...abc", "amount": "100000000000000000000"}
Borrowing
Section titled “Borrowing”Query:
Borrow 1000 FRAX using 2 ETH as collateral from the pool at 0x123...abc
Agent structures this as:
{ "pairAddress": "0x123...abc", "borrowAmount": "1000000000000000000000", "collateralAmount": "2000000000000000000", "receiver": "0x456...def"}
Checking Positions
Section titled “Checking Positions”Query:
Show my current FraxLend positions
Configuration Options
Section titled “Configuration Options”The FraxLend plugin accepts these configuration parameters:
interface FraxLendPluginConfig { chain: Chain; // Blockchain network configuration walletPrivateKey: string; // Private key for transactions}
Error Handling
Section titled “Error Handling”Always implement proper error handling when using the plugin:
try { const fraxlendPlugin = await createFraxlendPlugin({ chain: fraxtal, walletPrivateKey: process.env.WALLET_PRIVATE_KEY, });} catch (error) { console.error('Failed to initialize FraxLend plugin:', error);}
Best Practices
Section titled “Best Practices”- Environment Variables: Always use environment variables for sensitive information like private keys
- Transaction Validation: Double-check amounts and addresses before confirming transactions
- Error Handling: Implement proper error handling for all operations
- Gas Management: Consider gas costs for operations on the Fraxtal network
Common Issues and Troubleshooting
Section titled “Common Issues and Troubleshooting”- Invalid Pair Address: Ensure you’re using the correct pair address for the pool
- Insufficient Balance: Verify you have enough tokens for the operation
- Transaction Failures: Check gas settings and network status