AgentSkillsCN

krystal-defi-api

通过Krystal API提供DeFi流动性池数据、资金库管理及交易构建服务。当用户询问如何查找流动性池、获取池内数据(如TVL、成交量、年化收益率)、创建LP头寸、执行Zap交易、管理DeFi资金库(共享型或自动耕作型),或查询以太坊、BSC、Polygon、Arbitrum、Base、Solana等多条链上的钱包代币余额时,可选用此工具。

SKILL.md
--- frontmatter
name: krystal-defi-api
description: Provides DeFi liquidity pool data, vault management, and transaction building via the Krystal API. Use when the user asks about finding liquidity pools, pool analytics (TVL, volume, APR), creating LP positions, zap transactions, DeFi vaults (shared or auto-farm), or wallet token balances across chains like Ethereum, BSC, Polygon, Arbitrum, Base, and Solana.

Krystal API

DeFi liquidity pool explorer and transaction API supporting 13+ blockchains.

Quick Start

Base URL: https://api.krystal.app

bash
# Get top pools across all chains
curl "https://api.krystal.app/all/v2/lp_explorer/top_pools?skipCheckAutomation=true"

# Get pool details
curl "https://api.krystal.app/all/v1/lp_explorer/pool_detail?chainId=8453&poolAddress=0x..."

Instructions

Finding Pools

  1. Use Top Pools to discover high-performing pools
  2. Use Pool Detail for specific pool information
  3. Use Pool Chart for liquidity distribution visualization

Creating LP Positions

  1. Get pool details including tickSpacing from Pool Detail
  2. Calculate tick range aligned with pool's tick spacing
  3. Use Zap In to build the transaction
  4. Sign and send txData using a web3 provider

Increasing Liquidity (Swap and Increase)

  1. Get position tokenId from User Positions (for Solana, also pass nftMintAddress)
  2. Use Swap and Increase with tokenInAddress, amountIn, swapSlippage, and liquiditySlippage
  3. Set fundFromOwner=true and isVault=true when adding to a Krystal auto-farm vault position
  4. Sign and send txData using a web3 provider (same as Zap In)

Withdrawing LP Positions (Zap Out)

  1. Get position tokenId from User Positions (for Solana, also pass nftMintAddress)
  2. Use Zap Out with targetToken, liquidityPercent, swapSlippage, and withdrawSlippage
    • Set liquidityPercent = 0 to claim only fees (principal stays in the pool; claimed tokens are swapped to targetToken)
    • Use 0 < liquidityPercent ≤ 1 to withdraw principal liquidity (plus any fees) to targetToken
  3. Sign and send txData using a web3 provider (same as Zap In)

Compounding Fees into a Position

  1. Get position tokenId from User Positions (for Solana, also pass nftMintAddress)
  2. Use Compound with swapSlippage and liquiditySlippage to reinvest unclaimed fees back into the same position
  3. Set isVault=true when compounding a Krystal auto-farm vault position
  4. Sign and send txData using a web3 provider

Rebalancing Positions (Adjust Range)

  1. Get position tokenId from User Positions (for Solana, also pass nftMintAddress)
  2. Get pool tickSpacing from Pool Detail and choose new newTickLower and newTickUpper aligned with it
  3. Use Adjust Range with swapSlippage, liquiditySlippage, and withdrawSlippage
  4. On EVM chains, sign and send txData directly. On Solana, call with buildTx=true first to get txData, then sign and send it.

Exploring Vaults

  1. Use Vaults to list available vaults
  2. Filter by category (ALL_VAULT, NEW_VAULT, BOOST_VAULT) and isAutoFarmVault to narrow results
  3. Evaluate vaults by tvl, apr, riskScore, and vaultSecurities
  4. Use Vault Profile Stats to get a wallet's aggregate vault statistics (owned, joined, yields, PnL)

Viewing Positions

  1. Use User Positions to list a wallet's liquidity positions
  2. Check statsByChain["all"] for aggregate portfolio metrics (total PnL, APR, unclaimed fees)
  3. Filter by chainIds or positionStatus (open/closed) to narrow results
  4. Evaluate individual positions by pnl, apr, impermanentLoss, compareWithHodl, and status (IN_RANGE/OUT_RANGE)
  5. Use refreshAll=true for fresh on-chain data (slower) or omit for cached data (faster)

Wallet Operations

  1. Use Token Search to get user's token balances
  2. Select input token for swap/zap operations

Key Conventions

  • Always use skipCheckAutomation=true for faster responses
  • Monetary values: Returned as strings to preserve precision
  • APR values: Returned as numbers (percentages)
  • Native tokens: Use NativeTokenAddress placeholders
  • Amounts: Always in wei (smallest unit)

Endpoints Reference

EndpointPurpose
Top PoolsDiscover pools by TVL, volume, APR
Pool DetailGet pool info, tick spacing, incentives
Pool ChartLiquidity distribution and price history
Zap InBuild swap + mint transaction
Swap and IncreaseAdd liquidity to existing position (swap + increase)
Zap OutBuild withdraw + swap transaction
CompoundReinvest unclaimed fees into existing position
Adjust RangeRebalance position to new tick range
User PositionsList wallet LP positions & stats
VaultsList shared & auto-farm vaults
Token SearchQuery wallet token balances

Types Reference

See types.md for complete type definitions:

Core Types: Token, Pool, PoolDetail, ChainId, LPProtocolAlias

Chart Types: PoolChartData, Tick, PricePoint

Transaction Types: TxData, ZapTxInfo, SwapAmount

Position Types: UserPosition, PositionChainStats, PositionTokenAmount, PositionPool

Vault Types: Vault, VaultOwner, VaultSecurity, VaultStats

Wallet Types: WalletToken, TokenBalance