---
title: DeFi Protocol Tools
description: Tools for interacting with DeFi lending, DEX, stablecoins, and yield protocols
---
# DeFi Protocol Tools
Access **45+ DeFi protocols** with **100+ specialized tools** for lending, borrowing, swapping, and yield farming.
## Lending Protocols (45+ tools)
### Aave v3
**`aave_supply`** - Supply assets to Aave
```typescript
{
asset: string; // Token address
amount: string; // Amount to supply
onBehalfOf?: string;
chainId: number; // 1, 137, 42161, 10, 8453
}
```
**`aave_borrow`** - Borrow from Aave
```typescript
{
asset: string;
amount: string;
interestRateMode: 1 | 2; // 1=stable, 2=variable
chainId: number;
}
```
**`aave_repay`** - Repay borrowed assets
```typescript
{
asset: string;
amount: string; // or "max"
interestRateMode: 1 | 2;
chainId: number;
}
```
**`aave_withdraw`** - Withdraw supplied assets
```typescript
{
asset: string;
amount: string; // or "max"
to?: string;
chainId: number;
}
```
**`aave_get_user_data`** - Get user account data
```typescript
{
user: string;
chainId: number;
}
// Returns: totalCollateral, totalDebt, availableBorrow, healthFactor
```
### Compound v3
**`compound_supply`** - Supply to Compound
```typescript
{
asset: string;
amount: string;
chainId: number; // 1, 42161, 8453
}
```
**`compound_borrow`** - Borrow from Compound
```typescript
{
asset: string;
amount: string;
chainId: number;
}
```
**`compound_get_account`** - Get account position
```typescript
{
account: string;
chainId: number;
}
```
### Morpho Blue
**`morpho_supply`** - Supply to Morpho market
```typescript
{
marketId: string; // Market identifier
assets: string; // Amount to supply
shares: string; // Or shares to mint
onBehalfOf: string;
}
```
**`morpho_borrow`** - Borrow from Morpho
```typescript
{
marketId: string;
assets: string;
shares: string;
receiver: string;
}
```
## DEX & Trading (40+ tools)
### Uniswap v3
**`uniswap_swap_exact_input`** - Swap exact input amount
```typescript
{
tokenIn: string;
tokenOut: string;
amountIn: string;
amountOutMinimum: string;
fee: 500 | 3000 | 10000; // Fee tier
recipient: string;
deadline: number;
chainId: number;
}
```
**`uniswap_add_liquidity`** - Add liquidity to pool
```typescript
{
token0: string;
token1: string;
fee: 500 | 3000 | 10000;
amount0: string;
amount1: string;
tickLower: number;
tickUpper: number;
chainId: number;
}
```
**`uniswap_get_pool`** - Get pool information
```typescript
{
token0: string;
token1: string;
fee: number;
chainId: number;
}
```
### Curve
**`curve_exchange`** - Swap on Curve
```typescript
{
pool: string;
i: number; // From token index
j: number; // To token index
dx: string; // Input amount
min_dy: string; // Min output
chainId: number;
}
```
**`curve_add_liquidity`** - Add liquidity
```typescript
{
pool: string;
amounts: string[]; // Amount for each coin
min_mint_amount: string;
chainId: number;
}
```
### Jupiter (Solana)
**`jupiter_swap`** - Swap on Solana via Jupiter
```typescript
{
inputMint: string;
outputMint: string;
amount: number;
slippageBps: number;
wallet: string; // Keypair ID
}
```
**`jupiter_get_quote`** - Get swap quote
```typescript
{
inputMint: string;
outputMint: string;
amount: number;
slippageBps?: number;
}
```
## Stablecoin Protocols (20+ tools)
### MakerDAO
**`maker_open_vault`** - Open CDP/Vault
```typescript
{
ilk: string; // Collateral type
collateral: string;
dai: string;
chainId: number;
}
```
**`maker_deposit`** - Add collateral
```typescript
{
cdp: number;
amount: string;
chainId: number;
}
```
**`maker_generate_dai`** - Mint DAI
```typescript
{
cdp: number;
amount: string;
chainId: number;
}
```
### Liquity
**`liquity_open_trove`** - Open Trove
```typescript
{
collateral: string; // ETH amount
lusdAmount: string;
maxFeePercentage: string;
}
```
**`liquity_adjust_trove`** - Adjust position
```typescript
{
collateralChange: string;
lusdChange: string;
isDebtIncrease: boolean;
}
```
## Yield Farming (25+ tools)
### Yearn Finance
**`yearn_deposit`** - Deposit to vault
```typescript
{
vault: string; // Vault address
amount: string;
chainId: number;
}
```
**`yearn_withdraw`** - Withdraw from vault
```typescript
{
vault: string;
shares: string; // or "max"
chainId: number;
}
```
**`yearn_get_apy`** - Get vault APY
```typescript
{
vault: string;
chainId: number;
}
```
### Convex Finance
**`convex_stake`** - Stake Curve LP tokens
```typescript
{
pid: number; // Pool ID
amount: string;
chainId: number;
}
```
**`convex_claim_rewards`** - Claim CRV + CVX rewards
```typescript
{
pid: number;
chainId: number;
}
```
## Usage Examples
### Supply to Aave and Borrow
```typescript
import { defi } from '@universal-crypto/tools';
// Supply USDC as collateral
await defi.aave_supply({
asset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
amount: '1000', // 1000 USDC
chainId: 1,
});
// Check health factor
const userData = await defi.aave_get_user_data({
user: '0x...',
chainId: 1,
});
console.log(`Health Factor: ${userData.healthFactor}`);
// Borrow ETH
if (userData.healthFactor > 1.5) {
await defi.aave_borrow({
asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
amount: '0.5', // 0.5 ETH
interestRateMode: 2, // Variable
chainId: 1,
});
}
```
### Multi-Protocol Yield Optimization
```typescript
// Compare yields across protocols
const yields = await Promise.all([
defi.aave_get_supply_apy({ asset: 'USDC', chainId: 1 }),
defi.compound_get_supply_apy({ asset: 'USDC', chainId: 1 }),
defi.yearn_get_apy({ vault: 'USDC-vault', chainId: 1 }),
]);
console.log('Aave APY:', yields[0]);
console.log('Compound APY:', yields[1]);
console.log('Yearn APY:', yields[2]);
// Deposit to best yield
const bestIndex = yields.indexOf(Math.max(...yields));
// ... deposit logic
```
### DEX Aggregation with Best Price
```typescript
// Get quotes from multiple DEXs
const [uniQuote, curveQuote, sushiQuote] = await Promise.all([
defi.uniswap_get_quote({ tokenIn: 'USDC', tokenOut: 'ETH', amount: '1000' }),
defi.curve_get_dy({ pool: 'tricrypto', i: 0, j: 2, dx: '1000' }),
defi.sushi_get_amounts_out({ path: ['USDC', 'ETH'], amountIn: '1000' }),
]);
// Execute on best DEX
const bestQuote = Math.max(uniQuote, curveQuote, sushiQuote);
// ... execute swap
```
## Protocol Coverage
| Protocol | Chains | Tools | Features |
|----------|--------|-------|----------|
| **Aave v3** | 5 | 12 | Supply, borrow, flash loans |
| **Compound v3** | 3 | 8 | Supply, borrow, liquidate |
| **Morpho** | 1 | 10 | Optimized lending |
| **Uniswap v3** | 10 | 15 | Swap, liquidity, positions |
| **Curve** | 4 | 10 | Stablecoin swaps, pools |
| **Balancer** | 5 | 12 | Weighted pools, swaps |
| **MakerDAO** | 1 | 8 | CDP, DAI minting |
| **Yearn** | 6 | 8 | Vaults, strategies |
## Pricing
All DeFi tools are **free** - you only pay blockchain gas fees.
## Next Steps
- [Lending Guide](/guides/defi/lending) - Complete lending tutorial
- [DEX Trading](/guides/defi/dex) - DEX aggregation strategies
- [Yield Farming](/guides/defi/yield) - Optimize yield strategies
- [Risk Management](/guides/defi/risk) - Safety best practices