DeFi Packages
The DeFi packages provide comprehensive tools for AI agents to interact with decentralized finance protocols across 60+ blockchain networks.
Overview
| Metric |
Value |
| Protocols |
15+ major DeFi protocols |
| Networks |
60+ EVM chains |
| Tools |
100+ MCP tools |
| Categories |
DEXs, Lending, Staking, Bridges |
Package Structure
packages/defi/
├── protocols/ # Major DeFi protocols
│ ├── uniswap-v3-mcp/
│ ├── aave-mcp/
│ ├── compound-v3-mcp/
│ ├── curve-mcp/
│ ├── gmx-v2-mcp/
│ ├── lido-mcp/
│ └── yearn-mcp/
├── layer2/ # L2-specific integrations
├── smart-chain/ # BNB Chain ecosystem
├── stablecoin-protocol/ # Sperax USDs
├── shared/ # Shared utilities
└── agents/ # DeFi automation agents
Quick Start
Installation
pnpm add @universal-crypto-mcp/defi
Using the Unified Adapter
import { DeFiAdapter } from '@universal-crypto-mcp/defi';
const defi = new DeFiAdapter({
rpcUrl: process.env.ETHEREUM_RPC_URL,
privateKey: process.env.PRIVATE_KEY,
});
// Swap tokens via Uniswap
const swap = await defi.swap({
protocol: 'uniswap-v3',
tokenIn: 'ETH',
tokenOut: 'USDC',
amount: '1.0',
slippage: 0.5,
});
// Get lending position from Aave
const position = await defi.getLendingPosition({
protocol: 'aave-v3',
address: '0xYourAddress',
});
Supported Protocols
DEXs (Decentralized Exchanges)
| Protocol |
Networks |
Features |
| Uniswap V3 |
Ethereum, Arbitrum, Optimism, Base, Polygon |
Swaps, Liquidity, Positions |
| Curve |
Ethereum, Arbitrum, Optimism, Polygon |
Stablecoin Swaps, Gauges |
| PancakeSwap |
BNB Chain, Ethereum, Arbitrum |
Swaps, Farms, V3 |
Lending Protocols
| Protocol |
Networks |
Features |
| Aave V3 |
Ethereum, Arbitrum, Optimism, Polygon, Avalanche |
Lending, Borrowing, Flash Loans |
| Compound V3 |
Ethereum, Arbitrum, Base, Polygon |
Supply, Borrow, Collateral |
| Venus |
BNB Chain |
Lending, Borrowing, VAI |
Derivatives & Perpetuals
| Protocol |
Networks |
Features |
| GMX V2 |
Arbitrum, Avalanche |
Perpetuals, Positions, Orders |
Staking & Yield
| Protocol |
Networks |
Features |
| Lido |
Ethereum |
ETH Staking, stETH, wstETH |
| Yearn |
Ethereum, Arbitrum, Optimism |
Vaults, Strategies, APY |
| Sperax |
Arbitrum |
USDs Stablecoin, Yield |
Multi-Chain Architecture
The DeFi packages use a unified interface across all supported networks:
import { createDeFiClient } from '@universal-crypto-mcp/defi';
// Create clients for different networks
const ethereumDefi = createDeFiClient({ network: 'ethereum' });
const arbitrumDefi = createDeFiClient({ network: 'arbitrum' });
const baseDefi = createDeFiClient({ network: 'base' });
// Same API across all networks
const quote = await ethereumDefi.getSwapQuote({
protocol: 'uniswap-v3',
tokenIn: 'ETH',
tokenOut: 'USDC',
amount: '1.0',
});
| Tool |
Description |
defi_swap |
Execute a token swap |
defi_quote |
Get swap quote without executing |
defi_routes |
Find best swap routes |
defi_slippage |
Calculate slippage tolerance |
| Tool |
Description |
defi_supply |
Supply assets to lending protocol |
defi_borrow |
Borrow assets |
defi_repay |
Repay borrowed assets |
defi_withdraw |
Withdraw supplied assets |
defi_position |
Get lending position details |
defi_rates |
Get current interest rates |
| Tool |
Description |
defi_stake |
Stake tokens |
defi_unstake |
Unstake tokens |
defi_rewards |
Check staking rewards |
defi_apr |
Get current APR/APY |
| Tool |
Description |
defi_add_liquidity |
Add liquidity to pool |
defi_remove_liquidity |
Remove liquidity |
defi_positions |
Get LP positions |
defi_pool_info |
Get pool details |
Configuration
Environment Variables
# RPC Endpoints
ETHEREUM_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY
ARBITRUM_RPC_URL=https://arb-mainnet.g.alchemy.com/v2/YOUR_KEY
BASE_RPC_URL=https://base-mainnet.g.alchemy.com/v2/YOUR_KEY
# Optional: Private key for transactions
PRIVATE_KEY=0x...
# Optional: Protocol-specific API keys
ALCHEMY_API_KEY=...
INFURA_API_KEY=...
Programmatic Configuration
import { DeFiConfig } from '@universal-crypto-mcp/defi';
const config: DeFiConfig = {
networks: {
ethereum: {
rpcUrl: process.env.ETHEREUM_RPC_URL,
chainId: 1,
},
arbitrum: {
rpcUrl: process.env.ARBITRUM_RPC_URL,
chainId: 42161,
},
},
defaultSlippage: 0.5, // 0.5%
gasMultiplier: 1.2,
};
Protocol Comparison
| Feature |
Uniswap V3 |
Aave V3 |
Curve |
GMX V2 |
| Type |
DEX |
Lending |
DEX |
Perps |
| Networks |
8+ |
7+ |
5+ |
2 |
| Gas Efficiency |
⭐⭐⭐ |
⭐⭐⭐⭐ |
⭐⭐ |
⭐⭐⭐ |
| Slippage |
Variable |
N/A |
Low (stables) |
Low |
| Best For |
Token swaps |
Earning yield |
Stable swaps |
Leverage |
Security Considerations
⚠️ Important security practices for DeFi interactions:
- Verify addresses - Always verify contract addresses before transactions
- Slippage protection - Set appropriate slippage limits
- Gas estimation - Check gas costs before executing
- Approval limits - Use limited token approvals
- Test networks - Test on testnets before mainnet
// Safe approval pattern
await defi.approve({
token: 'USDC',
spender: uniswapRouterAddress,
amount: '1000', // Limited approval, not unlimited
});
See Also