DeFi Protocols API Reference
DeFi packages provide integrations with major decentralized finance protocols.
Packages
| Package | Protocol | Description |
|---|---|---|
@nirholas/uniswap-v3-mcp |
Uniswap V3 | Swaps, liquidity, positions |
@nirholas/aave-mcp |
Aave V3 | Lending, borrowing |
@nirholas/compound-v3-mcp |
Compound V3 | Supply, borrow |
@nirholas/curve-mcp |
Curve | Stablecoin swaps, pools |
@nirholas/gmx-v2-mcp |
GMX V2 | Perpetuals trading |
@nirholas/lido-mcp |
Lido | Liquid staking |
@nirholas/yearn-mcp |
Yearn | Yield optimization |
@nirholas/pancakeswap-mcp |
PancakeSwap | BSC DEX |
@nirholas/venus-mcp |
Venus | BSC lending |
Uniswap V3 API
Installation
Core Functions
swap
Execute a token swap on Uniswap V3.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
tokenIn |
string |
Yes | Input token address |
tokenOut |
string |
Yes | Output token address |
amount |
string |
Yes | Amount to swap (in wei) |
slippage |
number |
No | Max slippage (default: 0.005) |
recipient |
string |
No | Recipient address |
deadline |
number |
No | Transaction deadline |
Returns:
interface SwapResult {
transactionHash: string
amountIn: string
amountOut: string
effectivePrice: string
priceImpact: number
gasUsed: string
}
Example:
import { swap } from '@nirholas/uniswap-v3-mcp'
const result = await swap({
tokenIn: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
tokenOut: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
amount: '1000000000', // 1000 USDC
slippage: 0.01, // 1%
})
console.log(`Swapped for ${result.amountOut} WETH`)
quote
Get a swap quote without executing.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
tokenIn |
string |
Yes | Input token address |
tokenOut |
string |
Yes | Output token address |
amount |
string |
Yes | Amount to swap (in wei) |
chainId |
number |
No | Chain ID (default: 1) |
Returns:
interface QuoteResult {
amountOut: string
amountOutFormatted: string
priceImpact: number
route: PoolInfo[]
estimatedGas: string
}
addLiquidity
Add liquidity to a Uniswap V3 pool.
Parameters:
interface AddLiquidityParams {
token0: string
token1: string
fee: 500 | 3000 | 10000
amount0: string
amount1: string
tickLower: number
tickUpper: number
recipient?: string
deadline?: number
}
Returns:
interface AddLiquidityResult {
tokenId: string
liquidity: string
amount0: string
amount1: string
transactionHash: string
}
Position Management
getPosition
Get details of a liquidity position.
collectFees
Collect accumulated fees from a position.
removeLiquidity
Remove liquidity from a position.
Aave V3 API
Installation
Core Functions
supply
Supply assets to Aave to earn interest.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
asset |
string |
Yes | Asset address |
amount |
string |
Yes | Amount to supply (in wei) |
onBehalfOf |
string |
No | Recipient of aTokens |
Example:
import { supply } from '@nirholas/aave-mcp'
const result = await supply({
asset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
amount: '1000000000', // 1000 USDC
})
console.log(`Received ${result.aTokenAmount} aUSDC`)
borrow
Borrow assets from Aave using collateral.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
asset |
string |
Yes | Asset to borrow |
amount |
string |
Yes | Amount to borrow |
interestRateMode |
1 \| 2 |
Yes | 1 = Stable, 2 = Variable |
onBehalfOf |
string |
No | Address to borrow for |
repay
Repay borrowed assets.
withdraw
Withdraw supplied assets.
Position Queries
getUserAccountData
Get user's complete position data.
Returns:
interface AccountData {
totalCollateralBase: string
totalDebtBase: string
availableBorrowsBase: string
currentLiquidationThreshold: number
ltv: number
healthFactor: string
}
getUserReserveData
Get user data for a specific reserve.
Compound V3 API
Installation
Core Functions
supplyCollateral
Supply collateral to a Compound market.
borrowBase
Borrow the base asset (USDC) from Compound.
repayBase
Repay borrowed base asset.
withdrawCollateral
Withdraw supplied collateral.
Curve API
Installation
Core Functions
exchangeStable
Swap stablecoins with minimal slippage.
Example:
import { exchangeStable } from '@nirholas/curve-mcp'
// Swap USDC to DAI with minimal slippage
const result = await exchangeStable({
pool: '3pool',
tokenIn: 'USDC',
tokenOut: 'DAI',
amount: '10000000000', // 10,000 USDC
})
addLiquidityCurve
Add liquidity to a Curve pool.
GMX V2 API
Installation
Core Functions
openPosition
Open a leveraged position.
Parameters:
interface OpenPositionParams {
market: string // Market address
isLong: boolean // Long or short
collateralToken: string
collateralAmount: string
sizeDelta: string // Position size increase
leverage?: number // Target leverage (calculated from size/collateral)
acceptablePrice: string
triggerPrice?: string
}
closePosition
Close an existing position.
getPosition
Get position details.
Lido API
Installation
Core Functions
stakeEth
Stake ETH and receive stETH.
Example:
import { stakeEth } from '@nirholas/lido-mcp'
const result = await stakeEth('1000000000000000000') // 1 ETH
console.log(`Received ${result.stEthAmount} stETH`)
wrapStEth
Wrap stETH to wstETH (for DeFi compatibility).
unwrapWstEth
Unwrap wstETH back to stETH.
Yearn API
Installation
Core Functions
deposit
Deposit assets into a Yearn vault.
withdraw
Withdraw assets from a Yearn vault.
getVaults
Get all available vaults with APY data.
Returns:
interface Vault {
address: string
name: string
symbol: string
token: Token
apy: number
tvl: string
strategies: Strategy[]
}
Cross-Protocol Types
Common Interfaces
// Transaction result
interface TxResult {
transactionHash: string
blockNumber: number
gasUsed: string
status: 'success' | 'failed'
}
// Token approval
interface ApprovalParams {
token: string
spender: string
amount: string // Use MaxUint256 for unlimited
}
// Price oracle
interface PriceData {
price: string
decimals: number
timestamp: number
source: string
}