liberfi-swap
Execute token swaps and manage on-chain transactions: list supported swap chains, browse available swap tokens, get swap quotes with price/slippage/route info, build signable swap transactions, estimate gas/transaction fees, and broadcast signed transactions to the blockchain. Trigger words: swap, trade, exchange, buy token, sell token, convert, swap tokens, trade tokens, exchange tokens, buy crypto, sell crypto, get a quote, swap quote, price quote, how much will I get, swap rate, exchange rate, slippage, swap route, best price, execute swap, confirm swap, make a trade, place a trade, transaction, send transaction, broadcast, submit transaction, tx, send tx, gas fee, transaction fee, fee estimate, gas estimate, how much gas, supported chains, swap chains, which chains, available tokens, swap tokens, chain list, token list, build transaction, sign transaction. Chinese: 兑换, 交易, 买入, 卖出, 换币, 代币兑换, 报价, 兑换报价, 价格, 能换多少, 滑点, 路由, 最优价格, 执行交易, 确认交易, 发送交易, 广播交易, 手续费, Gas费, 费用估算, 支持的链, 可用代币, 构建交易, 签名交易. CRITICAL: Always use `--json` flag for structured output. CRITICAL: Swap amounts are in **smallest unit** (e.g. lamports for SOL, wei for ETH). CRITICAL: ALWAYS run `lfi token security` on the target token BEFORE executing a swap. CRITICAL: NEVER execute swap or send transaction without explicit user confirmation. Do NOT use this skill for: - Token search, info, security audit, K-line → use liberfi-token - Trending tokens or new token rankings → use liberfi-market - Wallet holdings, activity, or PnL stats → use liberfi-portfolio - Token holder or trader analysis → use liberfi-token Do NOT activate on vague inputs like "trade" or "buy" without specifying tokens or amounts.
NPX Install
npx skill4agent add liberfi-io/liberfi-skills liberfi-swapTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →LiberFi Swap & Transaction
Pre-flight Checks
| Command | Requires Auth |
|---|---|
| No |
| No |
| No |
| No |
| Yes (JWT, uses TEE wallet) |
| Yes (JWT, uses TEE wallet) |
- Run
lfi status --json - If not authenticated:
- Agent:
lfi login key --role AGENT --json - Human: →
lfi login <email> --jsonlfi verify <otpId> <code> --json
- Agent:
- Run to confirm wallet addresses
lfi whoami --json
- Confirm the user knows the input/output token addresses (or help look them up via or
lfi swap tokens)lfi token search - Note: is now optional for
--account. If omitted, the server uses the authenticated user's TEE wallet address automatically.swap execute
Skill Routing
| If user asks about... | Route to |
|---|---|
| Token search, price, details, security | liberfi-token |
| Token K-line, candlestick chart | liberfi-token |
| Token holders, smart money traders | liberfi-token |
| Trending tokens, market rankings | liberfi-market |
| Newly listed tokens | liberfi-market |
| Wallet holdings, balance, PnL | liberfi-portfolio |
| Wallet activity, transaction history | liberfi-portfolio |
CLI Command Index
Query Commands (read-only)
| Command | Description | Auth |
|---|---|---|
| List all supported swap chains | No |
| List available swap tokens | No |
Mutating Commands (generate transactions)
| Command | Description | Auth |
|---|---|---|
| Get a swap quote | No |
| Execute swap via TEE wallet | Yes |
| Build, sign, and broadcast swap in one step via TEE wallet | Yes |
| Estimate transaction fee / gas | No |
| Broadcast a signed transaction | Yes |
Parameter Reference
- — Required. Input token address
--in <address> - — Required. Output token address
--out <address> - — Required. Input amount in smallest unit (lamports, wei, etc.)
--amount <amount> - — Required.
--chain-family <family>orevmsvm - — Required. Numeric chain ID (e.g.
--chain-id <id>for Solana mainnet,0for Ethereum)1 - — Slippage tolerance in basis points (e.g.
--slippage-bps <bps>= 1%)100 - —
--swap-mode <mode>(default) orExactInExactOut
- — Optional. Wallet address override. If omitted, the server uses the authenticated user's TEE wallet automatically. Requires authentication.
--account <address> - — Opaque quote result JSON from a prior
--quote-result <json>call (pass through without modification)swap quote
- — Required.
--chain-family <family>orevmsvm - — Required. Numeric chain ID
--chain-id <id> - — Required. Transaction data as JSON string (structure depends on chain family)
--data <json>
- — Required.
--chain-family <family>orevmsvm - — Required. Numeric chain ID
--chain-id <id> - — Required. Full quote result JSON from a prior
--quote-result <json>call (pass through without modification)lfi swap quote - — Override slippage tolerance in basis points
--slippage-bps <bps>
- — Required.
--chain-family <family>orevmsvm - — Required. Numeric chain ID
--chain-id <id> - — Required. Signed transaction in base64 or hex encoding
--signed-tx <data>
Operation Flow
List Supported Chains
- Fetch chains:
lfi swap chains --json - Present: Show chain name, chain ID, chain family (evm/svm)
- Suggest next step: "Which chain do you want to trade on?"
Find Available Tokens
- Fetch tokens:
lfi swap tokens --chain-id <id> --json - Present: Show token name, symbol, address
- Suggest next step: "Which tokens do you want to swap?"
Get a Swap Quote
- Collect inputs: Input token, output token, amount, chain family, chain ID
- (mandatory) Run security check:
lfi token security <chain> <outputTokenAddress> --json - Review security result — warn user if any risk flags
- Get quote:
lfi swap quote --in <in> --out <out> --amount <amt> --chain-family <fam> --chain-id <id> --json - Present: Show input amount, expected output amount, price impact, slippage, route
- Suggest next step: "Want to execute this swap?"
Execute a Swap (Full Flow)
lfi status --json # check session
# If not authenticated:
lfi login key --role AGENT --json # agent
# or: lfi login <email> --json → lfi verify <otpId> <code> --json
lfi whoami --json # confirm evmAddress / solAddress- Collect inputs: Input/output tokens, amount, chain
- (mandatory) Security check:
lfi token security <chain> <outputTokenAddress> --json - If security flags found → warn user, recommend NOT proceeding
- Get quote first:
lfi swap quote --in <in> --out <out> --amount <amt> --chain-family <fam> --chain-id <id> --json - Present swap summary to user:
- Input: X amount of TokenA
- Output: ~Y amount of TokenB
- Slippage: Z%
- Estimated fees (if available)
- (mandatory) Wait for explicit user confirmation
- Execute swap:
lfi swap execute --in <in> --out <out> --amount <amt> --chain-family <fam> --chain-id <id> --quote-result '<quoteJson>' --json- The server signs the transaction using the authenticated user's TEE wallet.
- No manual signing step required — the response contains the result or signed tx hash.
- Suggest next step: "Swap submitted! You can track it on the block explorer."
Execute Swap in One Step (sign-and-send)
swap executelfi status --json # check session
# If not authenticated:
lfi login key --role AGENT --json # agent
# or: lfi login <email> --json → lfi verify <otpId> <code> --json- Collect inputs: Chain family, chain ID, and the quote result JSON from a prior call
swap quote - (mandatory) Security check already performed during the quote step — do not skip
- Present swap summary and wait for explicit user confirmation
- Execute:
lfi swap sign-and-send --chain-family <fam> --chain-id <id> --quote-result '<quoteJson>' --json- The server builds the transaction, signs it via the authenticated user's TEE wallet, and broadcasts it in one step.
- Suggest next step: "Swap submitted! You can track it on the block explorer."
sign-and-sendexecute- Use when you already have a
sign-and-sendand want a single atomic call.quote_result - Use when you want to specify input/output tokens and amount directly (it internally fetches a quote).
execute
Estimate Transaction Fee
- Estimate:
lfi tx estimate --chain-family <fam> --chain-id <id> --data '<txJson>' --json - Present: Show estimated gas/fee in native token and USD equivalent
- Suggest next step: "Ready to send?"
Broadcast Signed Transaction (when using external wallet)
- (mandatory) Ensure authenticated:
lfi status --json - (mandatory) Final confirmation: "Are you sure you want to broadcast this transaction? This is irreversible."
- Send:
lfi tx send --chain-family <fam> --chain-id <id> --signed-tx <signedData> --json - Present: Show transaction hash
- Suggest next step: "Transaction submitted! You can track it on the block explorer."
Cross-Skill Workflows
"I want to swap SOL for USDC"
Full flow: auth → token → swap
- auth → — Check session; if not authed →
lfi status --jsonlfi login key --json - auth → — Confirm solAddress
lfi whoami --json - token → — Find USDC address on Solana
lfi token search --q "USDC" --chains sol --json - token → — Security check (mandatory)
lfi token security sol <usdcAddress> --json - swap → — Get quote
lfi swap quote --in So11111111111111111111111111111111111111112 --out <usdcAddress> --amount <amt> --chain-family svm --chain-id 0 --json - Present quote summary, wait for user confirmation
- swap → — Server signs via TEE wallet
lfi swap execute --in ... --out ... --amount ... --chain-family svm --chain-id 0 --json
"What's the best price to buy this trending token?"
Full flow: auth → market → token → swap
- auth → — Check session; if not authed →
lfi status --jsonlfi login key --json - market → — Get trending tokens
lfi ranking trending sol 1h --limit 5 --json - User picks a token
- token → — Mandatory security check
lfi token security sol <address> --json - swap →
lfi swap quote --in <baseToken> --out <address> --amount <amt> --chain-family svm --chain-id 0 --json - Present quote with price impact analysis, wait for confirmation
- swap → — Server signs via TEE wallet
lfi swap execute --in ... --out ... --json
"Check my wallet, then sell half of my biggest holding"
Full flow: auth → portfolio → token → swap
- auth → — Check session; if not authed →
lfi status --jsonlfi login key --json - auth → — Get solAddress / evmAddress
lfi whoami --json - portfolio → — Get holdings
lfi wallet holdings sol <solAddress> --json - Identify largest holding, calculate half amount in smallest unit
- token → — Security check
lfi token security sol <tokenAddress> --json - swap →
lfi swap quote --in <tokenAddress> --out <baseToken> --amount <halfAmt> --chain-family svm --chain-id 0 --json - Present quote, wait for confirmation
- swap → — Server signs via TEE wallet
lfi swap execute --in ... --out ... --json
Suggest Next Steps
| Just completed | Suggest to user |
|---|---|
| Chain list | "Which chain do you want to trade on?" / "想在哪条链上交易?" |
| Token list | "Which tokens do you want to swap?" / "想兑换哪些代币?" |
| Swap quote | "Want to execute this swap?" / "要执行这笔兑换吗?" |
| Swap execute (TEE) | "Swap submitted via your LiberFi TEE wallet!" / "已通过LiberFi TEE钱包提交兑换!" |
| Swap sign-and-send | "Swap built, signed, and broadcast in one step!" / "兑换已一步完成构建、签名并广播!" |
| Fee estimate | "Ready to send?" / "准备好发送了吗?" |
| Tx send | "Transaction submitted! Track it on the block explorer." / "交易已提交!可在区块浏览器上查看。" |
| Not authenticated | "Please log in first: |
Edge Cases
- Insufficient balance: If the swap execute fails with an insufficient balance error, inform the user and suggest checking their holdings via
lfi wallet holdings - Slippage exceeded: If the quote shows high price impact (>5%), warn the user and suggest reducing the amount or increasing slippage tolerance
- Invalid token address: Validate format before calling the API; ask user to verify the address
- Unknown chain family: Only and
evmare supported; if user mentions a chain, map it to the correct family (e.g. Solana →svm, Ethereum/BSC/Base →svm)evm - Amount format error: Remind user that amounts must be in smallest unit (lamports for SOL = amount * 10^9, wei for ETH = amount * 10^18)
- Transaction already submitted: If tx send fails, warn that the transaction may have already been broadcast; check status before retrying
- Quote expired: Quotes have a limited validity window; if too much time passes, get a new quote before executing
- Network timeout: Retry once after 3 seconds; if still fails, suggest checking connectivity
Common Pitfalls
| Pitfall | Correct Approach |
|---|---|
| Using human-readable amounts (e.g. "1 SOL") | Convert to smallest unit first: 1 SOL = 1,000,000,000 lamports |
| Skipping security check before swap | ALWAYS run |
| Executing swap without user confirmation | ALWAYS show quote summary and wait for explicit "yes" |
| Passing modified quote_result to execute / sign-and-send | Pass the quote_result JSON through WITHOUT any modification |
Calling | Check |
| Assuming a wallet address without checking | Call |
| Retrying failed tx send without checking | The tx may have been submitted; check on-chain status first |
Using | Call |
Security Notes
- Swap and transaction operations are HIGH RISK — they can move funds irreversibly
- NEVER execute or
swap executewithout explicit user confirmationtx send - ALWAYS run on the output token before presenting a swap quote
token security - If the security audit reveals honeypot or high tax flags, strongly recommend the user NOT proceed
- The field is opaque — pass it through as-is; do not interpret, modify, or display its raw content
quote_result - Transaction amounts in smallest unit are easy to get wrong — always double-check with the user: "You want to swap X SOL (= Y lamports), correct?"
- After broadcasting, provide the transaction hash so the user can independently verify on a block explorer