FX SDK Agent Skill
Use this skill to produce reliable fx-sdk integrations for agent workflows.
Follow This Workflow
- 1. Confirm user intent: read-only query (
getPositions, getFxSaveConfig, getFxSaveBalance, getFxSaveRedeemStatus, getFxSaveClaimable), transaction-producing action (increase/reduce/adjust/deposit/repay, fxSAVE depositFxSave/withdrawFxSave/getRedeemTx), or Base–Ethereum bridge (getBridgeQuote / buildBridgeTx). - Collect required inputs before coding:
- -
market: ETH or INLINECODE14 - position type when needed:
long or INLINECODE16 - INLINECODE17
- token address from INLINECODE18
- amount fields (
bigint in wei-like units) - INLINECODE20 (must be
0 < slippage < 100) - INLINECODE22
- For bridge:
sourceChainId (1 | 8453), destChainId (1 | 8453), token (key or OFT address), amount, INLINECODE27 - For fxSAVE:
userAddress; for deposit tokenIn (usdc|fxUSD|fxUSDBasePool), amount (bigint), optional slippage; for withdraw tokenOut, amount (shares wei), instant (boolean), optional slippage when instant; for claim use getRedeemTx when cooldown complete
- 3. Create
FxSdk once and reuse it. - Return SDK result first (routes/tx plan), then optionally provide transaction sending loop.
- Keep nonce order from SDK-provided
txs; send transactions sequentially. Wait for each tx receipt before sending the next. - After all txs are confirmed, wait at least one block before querying balances or positions — on-chain state may lag the receipt.
- Validate inputs and surface SDK error messages directly when possible.
- If input comes from
agent-tools.json style payloads, convert amount strings to bigint before SDK calls.
Project Ground Truth
Repo: https://github.com/aladdindao/fx-sdk.git
Treat these as canonical project references before generating code:
- - INLINECODE44
- INLINECODE45
- INLINECODE46
Canonical Imports
CODEBLOCK0
Use custom RPC only when provided:
CODEBLOCK1
Method Map
- -
sdk.getPositions({ userAddress, market, type }): read-only; returns PositionInfo[] (positionId, rawColls, rawDebts, currentLeverage, lsdLeverage, rawCollsToken, rawDebtsToken, rawCollsDecimals, rawDebtsDecimals). - INLINECODE49 : open new position (
positionId: 0) or add collateral/leverage. - INLINECODE51 : reduce or close (
isClosePosition: true). - INLINECODE53 : rebalance leverage for existing position.
- INLINECODE54 : long pool only.
- INLINECODE55 : long pool only.
- INLINECODE56 : fee quote for LayerZero V2 OFT bridge (Base <-> Ethereum). Use source chain RPC.
- INLINECODE57 : build tx payload (to, data, value) to send on source chain; then send with wallet (same pattern as position txs). When Ethereum is source chain, user must approve
tx.to (RootEndPointV2) to spend the token before sending the bridge tx.
fxSAVE
- -
sdk.getFxSaveConfig(): fxSAVE protocol totals and config (totalSupplyWei, totalAssetsWei, cooldownPeriodSeconds, instantRedeemFeeRatio, expenseRatio, harvesterRatio, threshold); no user address required. - INLINECODE60 : fxSAVE balance (shares wei, optional assets wei).
- INLINECODE61 : pending redeem amount, cooldown, redeemableAt, isCooldownComplete.
- INLINECODE62 : redeem status plus
previewReceive (amountYieldOutWei, amountStableOutWei from previewRedeem — fxUSD + USDC to receive on claim). - INLINECODE64 : build claim tx when isCooldownComplete (uses
claim(receiver)); execute txs in order. - INLINECODE66 : deposit USDC/fxUSD/basePool; returns
{ txs } (approve + deposit). - INLINECODE68 : tokenOut
fxUSDBasePool → redeem; usdc/fxUSD and !instant → requestRedeem; usdc/fxUSD and instant → approve + instantRedeemFromFxSave; execute txs in order.
Token Addresses
| Token | Ethereum | Base |
|---|
| fxUSD | INLINECODE70 | INLINECODE71 |
Use tokens.fxUSD in SDK calls on Ethereum; pass the Base address directly when building bridge txs with sourceChainId: 8453.
Token Constraints
Honor SDK token checks:
- ETH market:
eth,
stETH,
weth,
wstETH,
usdc,
usdt,
fxUSD
- BTC market:
WBTC,
usdc,
usdt, INLINECODE84
- - depositAndMint / repayAndWithdraw (long only)
- ETH long:
eth |
stETH |
weth |
wstETH
- BTC long: INLINECODE89
-
tokenIn /
tokenOut:
usdc |
fxUSD |
fxUSDBasePool
-
fxUSDBasePool → direct redeem;
usdc/
fxUSD → requestRedeem (cooldown) or instant (fee + slippage)
- Amounts in wei (18 decimals for fxSAVE shares; 6 for USDC)
Common Errors
- -
"Input amount must be greater than 0" / "Amount to reduce must be greater than 0" → amount must be positive bigint. - INLINECODE100 → slippage must be a number in
(0, 100). - INLINECODE102 → use valid 0x address or
tokens.*. - INLINECODE104 → caller must own
positionId; verify with getPositions first. - INLINECODE107 → use allowed token for the market (see Token Constraints).
- Bridge:
"Unsupported bridge chainId" → each of sourceChainId/destChainId must be 1 or 8453 and they must differ. "Unsupported bridge token" → use fxUSD, fxSAVE, or valid OFT address on source chain. - fxSAVE:
tokenIn/tokenOut must be usdc, fxUSD, or fxUSDBasePool. Instant withdraw requires slippage.
Output Style For Agent Tasks
When user asks to integrate SDK into an AI agent, return:
- 1. A minimal adapter function with typed input.
- A safe dry-run mode (
planOnly) that returns SDK routes without sending transactions. - A transaction executor function that consumes one selected route/result and sends
txs in nonce order. - A post-execution step that waits ≥1 block then queries updated balance/positions to confirm the result.
- A validation checklist and command list.
Tool Schema Interop
If user provides values from agent-tools.json:
- - Parse wei strings with
BigInt(value). - Keep
positionId as number. - Keep
slippage as number in (0, 100). - Normalize token addresses with
tokens.* when possible. - For fxSAVE tools, convert
amountWei string to bigint; use tokenIn/tokenOut as-is (usdc, fxUSD, fxUSDBasePool).
Project-Specific References
Read these files when examples are required:
- - INLINECODE133
- INLINECODE134
- INLINECODE135
- INLINECODE136
- INLINECODE137
- INLINECODE138
- INLINECODE139
- INLINECODE140
- INLINECODE141
- INLINECODE142
- INLINECODE143
- INLINECODE144 (redeem status + claimable preview + claim; uses getFxSaveClaimable, getRedeemTx)
For reusable request shapes, adapter pattern, and test checklist, read:
- -
references/README.md — index of reference files and when to use each - INLINECODE146 — request templates for all methods, minimal snippets, validation checklist
- INLINECODE147 — typed FxAction adapter and sample payloads
FX SDK Agent 技能
使用此技能为代理工作流生成可靠的 fx-sdk 集成。
遵循此工作流
- 1. 确认用户意图:只读查询(getPositions、getFxSaveConfig、getFxSaveBalance、getFxSaveRedeemStatus、getFxSaveClaimable)、交易生成操作(increase/reduce/adjust/deposit/repay、fxSAVE depositFxSave/withdrawFxSave/getRedeemTx)或 Base–Ethereum 桥接(getBridgeQuote / buildBridgeTx)。
- 在编码前收集所需输入:
- - market:ETH 或 BTC
- 需要时指定头寸类型:long 或 short
- positionId
- 来自 tokens 的代币地址
- 金额字段(以 wei 为单位的 bigint)
- slippage(必须满足 0 < slippage < 100)
- userAddress
- 桥接:sourceChainId(1 | 8453)、destChainId(1 | 8453)、token(键或 OFT 地址)、amount、recipient
- fxSAVE:userAddress;存款 tokenIn(usdc|fxUSD|fxUSDBasePool)、amount(bigint)、可选 slippage;取款 tokenOut、amount(份额 wei)、instant(布尔值)、即时取款时可选 slippage;赎回冷却完成后使用 getRedeemTx
- 3. 创建 FxSdk 实例并重复使用。
- 首先返回 SDK 结果(路由/交易计划),然后可选提供交易发送循环。
- 保持 SDK 提供的 txs 中的 nonce 顺序;按顺序发送交易。在发送下一笔交易前等待每笔交易的回执。
- 所有交易确认后,等待至少一个区块再查询余额或头寸——链上状态可能滞后于交易回执。
- 验证输入并尽可能直接暴露 SDK 错误消息。
- 如果输入来自 agent-tools.json 风格的负载,在 SDK 调用前将金额字符串转换为 bigint。
项目真实信息
仓库:https://github.com/aladdindao/fx-sdk.git
在生成代码前将这些视为规范项目参考:
- - AGENTS.md
- README.md
- agent-tools.json
规范导入
ts
import { FxSdk, tokens } from @aladdindao/fx-sdk
仅在提供时使用自定义 RPC:
ts
const sdk = new FxSdk({ rpcUrl, chainId: 1 })
方法映射
- - sdk.getPositions({ userAddress, market, type }):只读;返回 PositionInfo[](positionId、rawColls、rawDebts、currentLeverage、lsdLeverage、rawCollsToken、rawDebtsToken、rawCollsDecimals、rawDebtsDecimals)。
- sdk.increasePosition(...):开新仓(positionId: 0)或增加抵押品/杠杆。
- sdk.reducePosition(...):减仓或平仓(isClosePosition: true)。
- sdk.adjustPositionLeverage(...):为现有头寸重新平衡杠杆。
- sdk.depositAndMint(...):仅限多头池。
- sdk.repayAndWithdraw(...):仅限多头池。
- sdk.getBridgeQuote(...):LayerZero V2 OFT 桥接(Base <-> Ethereum)的费用报价。使用源链 RPC。
- sdk.buildBridgeTx(...):构建在源链上发送的交易负载(to、data、value);然后使用钱包发送(与头寸交易相同模式)。当 Ethereum 为源链时,用户必须在发送桥接交易前授权 tx.to(RootEndPointV2)花费代币。
fxSAVE
- - sdk.getFxSaveConfig():fxSAVE 协议总量和配置(totalSupplyWei、totalAssetsWei、cooldownPeriodSeconds、instantRedeemFeeRatio、expenseRatio、harvesterRatio、threshold);无需用户地址。
- sdk.getFxSaveBalance({ userAddress }):fxSAVE 余额(份额 wei,可选资产 wei)。
- sdk.getFxSaveRedeemStatus({ userAddress }):待赎回金额、冷却时间、redeemableAt、isCooldownComplete。
- sdk.getFxSaveClaimable({ userAddress }):赎回状态加上 previewReceive(来自 previewRedeem 的 amountYieldOutWei、amountStableOutWei — 赎回时将收到的 fxUSD + USDC)。
- sdk.getRedeemTx({ userAddress, receiver? }):当 isCooldownComplete 时构建赎回交易(使用 claim(receiver));按顺序执行交易。
- sdk.depositFxSave({ userAddress, tokenIn, amount, slippage? }):存入 USDC/fxUSD/basePool;返回 { txs }(授权 + 存款)。
- sdk.withdrawFxSave({ userAddress, tokenOut, amount, instant?, slippage? }):tokenOut fxUSDBasePool → 赎回;usdc/fxUSD 且 !instant → requestRedeem;usdc/fxUSD 且 instant → 授权 + instantRedeemFromFxSave;按顺序执行交易。
代币地址
| 代币 | Ethereum | Base |
|---|
| fxUSD | 0x085780639CC2cACd35E474e71f4d000e2405d8f6 | 0x55380fe7A1910dFf29A47B622057ab4139DA42C5 |
在 Ethereum 上的 SDK 调用中使用 tokens.fxUSD;在构建 sourceChainId: 8453 的桥接交易时直接传递 Base 地址。
代币约束
遵守 SDK 代币检查:
- ETH 市场:eth、stETH、weth、wstETH、usdc、usdt、fxUSD
- BTC 市场:WBTC、usdc、usdt、fxUSD
- - depositAndMint / repayAndWithdraw(仅限多头)
- ETH 多头:eth | stETH | weth | wstETH
- BTC 多头:WBTC
- tokenIn / tokenOut:usdc | fxUSD | fxUSDBasePool
- fxUSDBasePool → 直接赎回;usdc/fxUSD → requestRedeem(冷却)或即时(费用 + 滑点)
- 金额以 wei 为单位(fxSAVE 份额 18 位小数;USDC 6 位小数)
常见错误
- - Input amount must be greater than 0 / Amount to reduce must be greater than 0 → 金额必须为正 bigint。
- Slippage must be between 0 and 100 (exclusive) → 滑点必须是 (0, 100) 范围内的数字。
- ... must be a valid Ethereum address → 使用有效的 0x 地址或 tokens.*。
- User is not the owner of this position → 调用者必须拥有 positionId;先用 getPositions 验证。
- Input/Output/Deposit/Withdraw token address must be ... → 使用市场允许的代币(参见代币约束)。
- 桥接:Unsupported bridge chainId → sourceChainId/destChainId 必须分别为 1 或 8453 且不能相同。Unsupported bridge token → 使用源链上的 fxUSD、fxSAVE 或有效的 OFT 地址。
- fxSAVE:tokenIn/tokenOut 必须是 usdc、fxUSD 或 fxUSDBasePool。即时取款需要 slippage。
代理任务的输出风格
当用户要求将 SDK 集成到 AI 代理中时,返回:
- 1. 一个带有类型输入的最小适配器函数。
- 一个安全的干运行模式(planOnly),返回 SDK 路由但不发送交易。
- 一个交易执行器函数,消耗一个选定的路由/结果并按