LI.FI Agent Skill
CRITICAL RULES (read first)
- 1. ONLY use
curl to call the LI.FI API. NEVER use web_search, web_fetch, or any other tool. - ONLY use the endpoints documented below. Do NOT guess or invent URLs.
- Base URL is
https://li.quest/v1/. No other base URL. - ALWAYS include auth header:
"x-lifi-api-key: $LIFI_API_KEY" (double quotes, dollar sign — shell expands it). - ALWAYS tell the user the quote is provided by LI.FI.
- Default slippage: 10% (0.10). If the user has a custom slippage in their strategy (via
defi_get_strategy), use that instead. The agent can also adjust dynamically per-transaction if the user requests it. - Default deadline: 10 minutes.
- ALWAYS add
&skipSimulation=true to all /v1/quote requests. Our EIP-7702 delegated wallets have on-chain code that breaks LI.FI's simulation. - NEVER construct ERC-20 approve calldata (hex) yourself. ALWAYS use the
defi_approve or defi_approve_and_send tools. - ALL swaps, bridges, and DeFi token operations MUST go through LI.FI. No exceptions. No manual DEX interactions.
Transaction Links
After every transaction broadcast, always provide a clickable block explorer link:
- - EVM:
[View tx](https://basescan.org/tx/0xHASH) — use the correct explorer (etherscan.io, basescan.org, arbiscan.io, polygonscan.com, optimistic.etherscan.io) - Sui: INLINECODE11
Sui
- - Sui chain ID:
9270000000000000. Use this for fromChain and toChain in LI.FI quote requests when the user wants Sui (e.g. fromChain=9270000000000000&toChain=9270000000000000 for same-chain Sui swap). - LI.FI supports Sui for same-chain swaps and bridging to/from EVM and Solana.
- For Sui quotes, use the user's suiAddress from
defi_get_wallet as fromAddress. - Execute Sui quotes with
defi_send_sui_transaction — pass the transaction bytes (hex) from the LI.FI quote. Do not use defi_send_transaction or defi_approve_and_send for Sui. - Sui does not use ERC-20 approvals; there is no approval step for Sui swaps.
Endpoints
GET /v1/chains — List supported chains
CODEBLOCK0
Use for: listing chains, testing connectivity. If user asks for a test, use this.
GET /v1/tokens — List tokens on chains
CODEBLOCK1
Params: chains (comma-separated chain IDs).
GET /v1/quote — Get swap/bridge quote with tx data
CODEBLOCK2
Params: fromChain, toChain, fromToken, toToken, fromAddress, toAddress (optional), fromAmount (in wei), slippage (decimal, e.g. 0.10 = 10%), skipSimulation=true (ALWAYS include).
Returns: estimate (with toAmount, toAmountMin, approvalAddress) and transactionRequest (ready for wallet submission).
After presenting a quote to the user, always include the estimated output amount, fees, and slippage. Get the user's wallet address with defi_get_wallet and use it as fromAddress in the quote.
Executing the quote
Check if ERC-20 approval is needed: If the quote's transactionRequest.value is "0x0" AND estimate.approvalAddress exists, the swap/bridge is using an ERC-20 token that needs approval first.
- - If approval IS needed: Use
defi_approve_and_send with:
-
token: the
action.fromToken.address from the quote
-
spender: the
estimate.approvalAddress from the quote
-
approveAmount: the
action.fromAmount from the quote (or omit for unlimited)
-
to,
value,
data,
gasLimit: from the quote's INLINECODE52
- - If approval is NOT needed (native ETH swap, value > 0x0): Use
defi_send_transaction with the quote's transactionRequest fields: to, value, data, chainId, and gasLimit (ALWAYS pass gasLimit from the quote).
NEVER construct approve calldata hex yourself. The defi_approve and defi_approve_and_send tools handle ABI encoding correctly.
Sui: For quotes where fromChain or toChain is Sui, use defi_send_sui_transaction with the quote's transaction bytes. No approval step.
POST /v1/advanced/routes — Get multiple route options
CODEBLOCK3
POST /v1/quote/contractCalls — Multi-step contract calls (BETA)
CODEBLOCK4
GET /v1/status — Check transfer status
CODEBLOCK5
Pass fromChain to speed up the lookup.
GET /v1/tools — List available bridges and exchanges
CODEBLOCK6
Docs
- - LLM docs: https://docs.li.fi/llms.txt
- OpenAPI: https://gist.githubusercontent.com/kenny-io/7fede47200a757195000bfbe14c5baee/raw/725cf9d4a6920d5b930925b0412d766aa53c701c/lifi-openapi.yaml
LI.FI 代理技能
关键规则(请先阅读)
- 1. 仅使用 curl 调用 LI.FI API。切勿使用 websearch、webfetch 或任何其他工具。
- 仅使用下方记录的端点。不要猜测或编造 URL。
- 基础 URL 为 https://li.quest/v1/。无其他基础 URL。
- 始终包含认证头:x-lifi-api-key: $LIFIAPIKEY(双引号,美元符号——shell 会展开它)。
- 始终告知用户报价由 LI.FI 提供。
- 默认滑点:10%(0.10)。 如果用户的策略中有自定义滑点(通过 defigetstrategy 获取),则使用该值。如果用户要求,代理也可以按交易动态调整。
- 默认截止时间:10 分钟。
- 始终在所有 /v1/quote 请求中添加 &skipSimulation=true。我们的 EIP-7702 委托钱包具有链上代码,会破坏 LI.FI 的模拟。
- 切勿自行构造 ERC-20 授权调用数据(十六进制)。始终使用 defiapprove 或 defiapproveandsend 工具。
- 所有交换、桥接和 DeFi 代币操作必须通过 LI.FI 进行。 无例外。不得手动与 DEX 交互。
交易链接
每次交易广播后,始终提供可点击的区块浏览器链接:
- - EVM:查看交易 — 使用正确的浏览器(etherscan.io、basescan.org、arbiscan.io、polygonscan.com、optimistic.etherscan.io)
- Sui:查看交易
Sui
- - Sui 链 ID:9270000000000000。当用户需要 Sui 时,在 LI.FI 报价请求中使用此值作为 fromChain 和 toChain(例如,同链 Sui 交换使用 fromChain=9270000000000000&toChain=9270000000000000)。
- LI.FI 支持 Sui 进行同链交换以及与 EVM 和 Solana 之间的桥接。
- 对于 Sui 报价,使用来自 defigetwallet 的用户的 suiAddress 作为 fromAddress。
- 使用 defisendsuitransaction 执行 Sui 报价 — 传递来自 LI.FI 报价的交易字节(十六进制)。对于 Sui,不要使用 defisendtransaction 或 defiapproveandsend。
- Sui 不使用 ERC-20 授权;Sui 交换没有授权步骤。
端点
GET /v1/chains — 列出支持的链
bash
curl -s --request GET \
--url https://li.quest/v1/chains \
--header x-lifi-api-key: $LIFIAPIKEY
用途:列出链、测试连接性。如果用户要求测试,请使用此端点。
GET /v1/tokens — 列出链上的代币
bash
curl -s --request GET \
--url https://li.quest/v1/tokens?chains=8453 \
--header x-lifi-api-key: $LIFIAPIKEY
参数:chains(逗号分隔的链 ID)。
GET /v1/quote — 获取包含交易数据的交换/桥接报价
bash
curl -s --request GET \
--url https://li.quest/v1/quote?fromChain=8453&toChain=8453&fromToken=ETH&toToken=USDC&fromAddress=0xYOUR_ADDRESS&fromAmount=100000000000000&slippage=0.10&skipSimulation=true \
--header x-lifi-api-key: $LIFIAPIKEY
参数:fromChain、toChain、fromToken、toToken、fromAddress、toAddress(可选)、fromAmount(以 wei 为单位)、slippage(小数,例如 0.10 = 10%)、skipSimulation=true(始终包含)。
返回:estimate(包含 toAmount、toAmountMin、approvalAddress)和 transactionRequest(准备提交到钱包)。
向用户展示报价后,始终包含估计的输出金额、费用和滑点。使用 defigetwallet 获取用户的钱包地址,并在报价中将其用作 fromAddress。
执行报价
检查是否需要 ERC-20 授权: 如果报价的 transactionRequest.value 为 0x0 且存在 estimate.approvalAddress,则交换/桥接使用的是需要先授权的 ERC-20 代币。
- - 如果需要授权: 使用 defiapproveand_send,参数如下:
- token:报价中的 action.fromToken.address
- spender:报价中的 estimate.approvalAddress
- approveAmount:报价中的 action.fromAmount(或省略以表示无限额)
- to、value、data、gasLimit:来自报价的 transactionRequest
- - 如果不需要授权(原生 ETH 交换,value > 0x0):使用 defisendtransaction,参数为报价的 transactionRequest 字段:to、value、data、chainId 和 gasLimit(始终传递报价中的 gasLimit)。
切勿自行构造授权调用数据的十六进制。 defiapprove 和 defiapproveandsend 工具会正确处理 ABI 编码。
Sui: 对于 fromChain 或 toChain 为 Sui 的报价,使用 defisendsui_transaction,参数为报价的交易字节。无需授权步骤。
POST /v1/advanced/routes — 获取多条路由选项
bash
curl -s --request POST \
--url https://li.quest/v1/advanced/routes \
--header Content-Type: application/json \
--header x-lifi-api-key: $LIFIAPIKEY \
--data {
fromChainId: 8453,
fromAmount: 100000000000000,
fromTokenAddress: 0x0000000000000000000000000000000000000000,
toChainId: 8453,
toTokenAddress: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913,
options: {
slippage: 0.10,
order: RECOMMENDED
}
}
POST /v1/quote/contractCalls — 多步合约调用(测试版)
bash
curl -s --request POST \
--url https://li.quest/v1/quote/contractCalls \
--header Content-Type: application/json \
--header x-lifi-api-key: $LIFIAPIKEY \
--data {
fromChain: 10,
fromToken: 0x4200000000000000000000000000000000000042,
fromAddress: 0xYOUR_ADDRESS,
toChain: 1,
toToken: ETH,
toAmount: 100000000000001,
contractCalls: []
}
GET /v1/status — 检查转账状态
bash
curl -s --request GET \
--url https://li.quest/v1/status?txHash=0xYOURTXHASH&fromChain=8453 \
--header x-lifi-api-key: $LIFIAPIKEY
传递 fromChain 以加快查询速度。
GET /v1/tools — 列出可用的桥接和交易所
bash
curl -s --request GET \
--url https://li.quest/v1/tools?chains=8453 \
--header x-lifi-api-key: $LIFIAPIKEY
文档
- - LLM 文档:https://docs.li.fi/llms.txt
- OpenAPI:https://gist.githubusercontent.com/kenny-io/7fede47200a757195000bfbe14c5baee/raw/725cf9d4a6920d5b930925b0412d766aa53c701c/lifi-openapi.yaml