lifi-stablecoin-swap
它能做什么
本指南展示如何构建稳定币兑换,用户发送 100 USDC,并收到 100 USDC,无论是在同一条链上还是跨链。它说明 LI.FI 求解器网络如何完成订单,以及如何在链上验证,适合开发支付或金融科技产品的团队。
适用场景
- ✓当你希望用户能以精确的一比一金额,将一种稳定币兑换为另一种的时候。
- ✓当你正在开发需要固定、清晰金额的支付或数字银行应用时。
- ✓当你希望跨链稳定币转账中,用户只看到一个数字的时候。
技能链接
https://github.com/internet-court/internet-court-skill/blob/main/vendored/lifi/lifi-stablecoin-swap/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我希望我的金融科技应用让用户发送 100 USDC,并在另一条链上恰好收到 100 USDC。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会先在 LI.FI 设置集成方账户,然后使用 Intents TypeScript SDK 请求报价、构建链上订单并跟踪。一比一的报价只会在你的集成方密钥下返回,且仅适用于受支持的稳定币交易对。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Build a 1:1 Stablecoin Swap with LI.FI Intents
A normal crypto transfer leaks value to gas and spreads — send 100 USDC, ~99.8 arrives. For a neobank, payment processor, or regulated fintech, that's a non-starter: their users expect that sending 100 means 100 arrives.
LI.FI Intents lets you offer exactly that — send 100 USDC, receive 100 USDC (or USDT, or another supported stablecoin), same-chain or cross-chain. A solver from LI.FI's network fronts the destination gas and sources the liquidity, then settles against the user's deposit, so the end user sees one number from start to finish, provable on a public block explorer.
The primary integration is the @lifi/intent TypeScript SDK — it requests the quote, builds
the on-chain order, and tracks it. The raw REST API is in §7 for non-TypeScript backends.
1. Enable 1:1 quoting on your integrator account
1:1 stablecoin quoting is a capability provisioned on your LI.FI integrator account:
- Register an integrator ID on the LI.FI Partner Portal — https://portal.li.fi
- Complete an integration agreement with LI.FI. As part of onboarding, 1:1 stablecoin quoting is enabled for your integrator.
- Quote requests made under your integrator key then return 1:1 amounts for supported stablecoin pairs.
The integration code below is identical regardless — what makes the quote come back 1:1 is your onboarded integrator. See https://docs.li.fi/lifi-intents/introduction or contact LI.FI to enable it.
2. The flow
order.li.fi is the Intents API. The escrow flow is the recommended default and takes four steps:
1. Quote getQuotes(...) -> guaranteed output amount (1:1)
2. Approve ERC-20 approve(InputSettlerEscrow, amount) -> let the settler pull the input token
3. Open escrow.open(StandardOrder) on-chain -> locks funds, emits Open(orderId)
4. Track GET /orders/status?onChainOrderId=... -> Signed -> Delivered -> Settled
Opening the order emits Open(bytes32 indexed orderId, ...); solvers watch for that event and fill
on the destination chain, so the escrow flow needs no order-submission call. You poll status
until the funds land, then show the user the destination transaction. The orderId is the
receipt — anyone can independently verify the deposit and the delivery matched.
(There is also a Compact / gasless flow — deposit once into The Compact, then sign and submit each order off-chain. Use escrow unless you specifically want gasless after a one-time deposit.)
npm install @lifi/intent viem
(The runnable interface in the quickstart also uses wagmi + @tanstack/react-query for the
wallet — its install line includes them.)
Setup note: the SDK uses
bigintliterals (100_000_000n).create-next-appdefaultstsconfig.jsonto"target": "ES2017", which rejects them — set"target": "ES2020"(or higher).
3. Quote (1:1)
getQuotes with your integrator key. IntentApi(true) targets mainnet / the production solver
network. Amounts are bigint in the token's smallest units (100 USDC = 100_000_000n, 6 decimals).
Under a 1:1-enabled integrator on a supported stablecoin pair, the output equals the input.
import { IntentApi } from "@lifi/intent";
const api = new IntentApi(true);
const res = await api.getQuotes({
user, // the user's 0x address
userChainId: 8453, // source chain (Base)
integratorKey: process.env.LIFI_INTEGRATOR_KEY, // your onboarded integrator key
inputs: [{ sender: user, asset: usdcOnBase, chainId: 8453, amount: 100_000_000n }],
outputs: [{ receiver: user, asset: usdcOnArb, chainId: 42161, amount: 0n }],
});
const quote = res.quotes[0];
if (!quote) throw new Error("No quote available for this pair");
const received = BigInt(quote.preview.outputs[0].amount); // == 100_000_000n for a 1:1 pair
const quoteId = quote.quoteId;
4. Build & open the order
The SDK builds the StandardOrder for you — pass plain token addresses + chain ids; it computes
the nonce, deadlines, oracle, and EIP-7930 encoding. getOracle supplies the verifier oracle
(Polymer addresses below). Then call open(order) on the escrow settler the SDK gives you.
import { Intent, type IntentDeps, type StandardEVM } from "@lifi/intent";
import type { WalletClient } from "viem";
const POLYMER_ORACLE = "0x0000003E06000007A224
常见问题
为什么普通转账的金额会有所不同?
Gas 费和价差会占用一小部分,因此普通转账到账的金额可能略少于你发送的金额。
获取一比一报价之前我需要什么?
需要 LI.FI 合作伙伴门户中的集成方 ID,以及与 LI.FI 签订的集成协议。
我可以在 TypeScript 之外使用它吗?
可以。该技能包含供非 TypeScript 后端使用的原始 REST API。
详情
作者的原始描述
Build a production 1:1 stablecoin swap with LI.FI Intents — an interface or backend where the amount the user sends equals the amount they receive (no visible gas or solver fees), same-chain or cross-chain, filled by LI.FI's solver network and verifiable on-chain. USE THIS SKILL WHEN USER WANTS TO: - Build a 1:1 stablecoin swap interface ("send 100 USDC, receive 100 USDC"), same- or cross-chain - Add stablecoin transfers with a guaranteed output amount to an app, backend, or bot - Build enterprise/fintech-grade transfers with no visible gas or solver fees for the end user - Implement the LI.FI
热度
- GitHub 星标
- 7.0k
- 排名
- #13639
- 许可证
- —
- 更新时间
- 2026/10/26
评论
- …
同一仓库的更多技能
internet-court
7.0k帮你的智能体安全地向其他 AI 智能体或付费服务付款、雇用或进行交易,并指引它找到合适的专业指南。
genlayer-erc7710-connector
7.0k帮你的智能体把 AI 审核结果与权限系统连接起来,使不合格的审核可以限制或取消智能体的权限。
genlayer-intelligent-contracts
7.0k帮你的智能体定义 AI 裁判的规则、证据和输出,用于检查另一个智能体是否遵循了其授权范围。
x402-erc7710
7.0k帮你的智能体按次为网络服务付款,并设置在权限预算范围内的持续支出。