lifi
通过 LI.FI 协议进行跨链代币交换和桥接。获取报价、执行转账、跟踪进度并在超过 35 个区块链上进行 DeFi 操作。
安装 / 下载方式
TotalClaw CLI推荐
totalclaw install totalclaw:totalclaw~rhlsthrm-lifi-crosschaincURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~rhlsthrm-lifi-crosschain/file -o rhlsthrm-lifi-crosschain.md## 概述(中文)
通过 LI.FI 协议进行跨链代币交换和桥接。获取报价、执行转账、跟踪进度并在超过 35 个区块链上进行 DeFi 操作。
## 原文
# /lifi — Cross-Chain Swaps & Bridges
LI.FI is a cross-chain bridge and DEX aggregation protocol. It finds optimal routes across 35+ blockchains, comparing dozens of bridges (Stargate, Hop, Across, etc.) and DEXes (Uniswap, SushiSwap, 1inch, etc.) to execute token swaps and cross-chain transfers.
## Arguments: `$ARGUMENTS`
Parse the arguments:
- **First positional arg**: Action — `swap`, `bridge`, `track`, `routes`, `zap`, or a natural language request
- **Remaining args**: Details (token names, amounts, chains, tx hashes, etc.)
If no arguments are provided, ask the user what they want to do.
## Key Concepts
- **Base URL**: `https://li.quest/v1`
- The API returns `transactionRequest` objects (to, data, value, gasLimit, gasPrice) ready to sign — provide these to the agent's wallet
- **Native token address**: `0x0000000000000000000000000000000000000000` (for ETH, MATIC, BNB, etc.)
- Amounts are always in the token's **smallest unit** (wei): 1 ETH = `1000000000000000000` (18 decimals), 1 USDC = `1000000` (6 decimals)
- Optional API key via `x-lifi-api-key` header for higher rate limits (not required)
---
## API Reference
### Discovery Endpoints
#### GET /v1/chains — List supported blockchains
```bash
curl -s "https://li.quest/v1/chains"
# Optional: ?chainTypes=EVM or ?chainTypes=SVM
```
#### GET /v1/tokens — List supported tokens
```bash
curl -s "https://li.quest/v1/tokens?chains=1,137"
# Optional: chainTypes, minPriceUSD
```
#### GET /v1/token — Get specific token details
```bash
curl -s "https://li.quest/v1/token?chain=1&token=USDC"
# chain (required): chain ID or name. token (required): address or symbol
```
#### GET /v1/connections — Check available swap routes
```bash
curl -s "https://li.quest/v1/connections?fromChain=1&toChain=137&fromToken=0x0000000000000000000000000000000000000000"
# Optional: toToken, chainTypes, allowBridges
```
#### GET /v1/tools — List available bridges and DEXes
```bash
curl -s "https://li.quest/v1/tools"
# Returns {bridges: [{key, name}], exchanges: [{key, name}]}
```
### Quote & Swap Endpoints
#### GET /v1/quote — Get optimal route + transaction data
The primary endpoint for initiating any swap or bridge.
```bash
curl -s "https://li.quest/v1/quote?\
fromChain=1&toChain=137\
&fromToken=0x0000000000000000000000000000000000000000\
&toToken=0x0000000000000000000000000000000000000000\
&fromAddress=0xYOUR_WALLET\
&fromAmount=1000000000000000000\
&slippage=0.03"
```
**Required**: fromChain, toChain, fromToken, toToken, fromAddress, fromAmount
**Optional**: toAddress, slippage (decimal, e.g. 0.03 = 3%), integrator, order (RECOMMENDED|FASTEST|CHEAPEST|SAFEST), allowBridges, allowExchanges
Returns: `action`, `estimate` (toAmount, fees, executionDuration), and `transactionRequest` (to, data, value, gasLimit).
#### GET /v1/status — Track cross-chain transfer
```bash
curl -s "https://li.quest/v1/status?txHash=0xTX_HASH"
# Optional: bridge, fromChain, toChain
```
Returns: `status` (NOT_FOUND, PENDING, DONE, FAILED), `substatus` (COMPLETED, PARTIAL, REFUNDED), source/destination tx details.
### Advanced Routing
#### POST /v1/advanced/routes — Compare multiple route options
```bash
curl -s -X POST "https://li.quest/v1/advanced/routes" \
-H "Content-Type: application/json" \
-d '{
"fromChainId": "1",
"toChainId": "137",
"fromTokenAddress": "0x0000000000000000000000000000000000000000",
"toTokenAddress": "0x0000000000000000000000000000000000000000",
"fromAddress": "0xYOUR_WALLET",
"fromAmount": "1000000000000000000",
"options": {"order": "RECOMMENDED"}
}'
```
**Required**: fromChainId, toChainId, fromTokenAddress, toTokenAddress, fromAddress, fromAmount
**Optional**: toAddress, slippage, options.order
Returns: `routes[]` array — each route has steps, estimated output, fees, and execution time.
#### POST /v1/advanced/stepTransaction — Get tx data for a route step
```bash
curl -s -X POST "https://li.quest/v1/advanced/stepTransaction" \
-H "Content-Type: application/json" \
-d '{ ...step object from routes response... }'
```
Pass the entire step object from a route. Returns `transactionRequest` ready to sign.
#### POST /v1/quote/contractCalls — Zaps (multi-action DeFi composition)
```bash
curl -s -X POST "https://li.quest/v1/quote/contractCalls" \
-H "Content-Type: application/json" \
-d '{
"fromChain": "1",
"toChain": "137",
"fromToken": "0x0000000000000000000000000000000000000000",
"toToken": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
"fromAddress": "0xYOUR_WALLET",
"fromAmount": "1000000000000000000",
"contractCalls": [
{
"toContractAddress": "0xTARGET_CONTRACT",
"toContractCallData": "0xENCODED_FUNCTION_CALL",
"toContractGasLimit": "200000"
}
]
}'
```
**Required**: fromChain, toChain, fromToken, toToken, fromAddress, fromAmount, contractCalls[]
**Optional**: slippage
### Gas Information
#### GET /v1/gas/prices — Gas prices across all chains
```bash
curl -s "https://li.quest/v1/gas/prices"
```
#### GET /v1/gas/suggestion/{chainId} — Recommended gas params for a chain
```bash
curl -s "https://li.quest/v1/gas/suggestion/1"
```
---
## Guided Workflows
### Workflow 1 — Swap or Bridge Tokens
Use this for any "swap X for Y" or "bridge tokens to chain" request.
1. **Identify parameters** from the user's request:
- Source chain and token (e.g., "ETH on Ethereum")
- Destination chain and token (e.g., "USDC on Polygon")
- Amount in human-readable form (e.g., "1.5 ETH")
- Wallet address (the agent's wallet or user-specified)
2. **Look up token addresses** if the user gave symbols:
```bash
curl -s "https://li.quest/v1/token?chain=1&token=USDC"
```
Extract `address` and `decimals` from the response.
3. **Convert amount to smallest unit**:
- Multiply human amount by 10^decimals
- 1.5 ETH (18 decimals) → `1500000000000000000`
- 100 USDC (6 decimals) → `100000000`
4. **Get a quote**:
```bash
curl -s "https://li.quest/v1/quote?fromChain=1&toChain=137&fromToken=0x0000000000000000000000000000000000000000&toToken=0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359&fromAddress=0xWALLET&fromAmount=1500000000000000000&slippage=0.03"
```
5. **Present summary to user** (REQUIRED before returning tx data):
```
Swap: 1.5 ETH (Ethereum) → ~2,850 USDC (Polygon)
Route: Stargate bridge → Uniswap V3
Fees: ~$2.50 (gas) + $0.50 (bridge)
Estimated time: ~2 minutes
Slippage: 3%
```
6. **If ERC20 token**: Check if the LiFi contract has sufficient allowance. The spender address is `transactionRequest.to` from the quote response. If allowance < fromAmount, guide the user to approve the token first.
7. **Return `transactionRequest`** for signing by the agent's wallet.
8. **If cross-chain**: Explain that bridging is asynchronous — the source chain tx will confirm first, then the bridge delivers tokens to the destination. Offer to track with Workflow 3.
### Workflow 2 — Compare Routes
Use when the user wants to see options or find the best deal.
1. **Gather parameters** (same as Workflow 1, steps 1-3).
2. **Request multiple routes**:
```bash
curl -s -X POST "https://li.quest/v1/advanced/routes" \
-H "Content-Type: application/json" \
-d '{
"fromChainId": "1",
"toChainId": "137",
"fromTokenAddress": "0x0000000000000000000000000000000000000000",
"toTokenAddress": "0x0000000000000000000000000000000000000000",
"fromAddress": "0xWALLET",
"fromAmount": "1000000000000000000",
"options": {"order": "RECOMMENDED"}
}'
```
3. **Present comparison table**:
```
# Route Output Fees Time Bridge
1 Stargate → Uniswap V3 2,850 USDC $3.00 2 min Stargate
2 Hop → SushiSwap 2,845 USDC $2.80 5 min Hop
3 Across → 1inch 2,848 USDC $3.20 3 min Across