okx-defi-invest
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOKX DeFi Invest
OKX DeFi Invest
Multi-chain DeFi product discovery and investment execution. The CLI handles precision conversion, multi-step orchestration, and validation internally.
For CLI parameter details, see references/cli-reference.md.
多链DeFi产品发现与投资执行工具。CLI会在内部处理精度转换、多步骤编排和校验。
如需了解CLI参数详情,请查看references/cli-reference.md。
Skill Routing
Skill路由规则
- For DeFi positions / holdings → use
okx-defi-portfolio - For token price/chart → use
okx-dex-market - For token search by name/contract → use
okx-dex-token - For DEX spot swap execution → use
okx-dex-swap - For wallet token balances → use
okx-wallet-portfolio - For broadcasting signed transactions → use
okx-onchain-gateway - For Agentic Wallet login, balance, contract-call → use
okx-agentic-wallet
- 若需查看DeFi头寸/持仓 → 使用
okx-defi-portfolio - 若需查询代币价格/图表 → 使用
okx-dex-market - 若需按名称/合约搜索代币 → 使用
okx-dex-token - 若需执行DEX现货兑换 → 使用
okx-dex-swap - 若需查询钱包代币余额 → 使用
okx-wallet-portfolio - 若需广播已签名交易 → 使用
okx-onchain-gateway - 若需Agentic Wallet登录、余额查询、合约调用 → 使用
okx-agentic-wallet
Command Index
命令索引
| # | Command | Description |
|---|---|---|
| 1 | | List top DeFi products by APY |
| 2 | | Search DeFi products |
| 3 | | Get full product details |
| 4 | | One-step deposit (CLI handles prepare + precision + calldata) |
| 5 | | One-step withdrawal (CLI handles position lookup + calldata) |
| 6 | | One-step reward claim (CLI handles reward check + calldata) |
| 7 | | List DeFi positions by platform |
| 8 | | Get detailed position info |
| 序号 | 命令 | 描述 |
|---|---|---|
| 1 | | 按APY排序列出热门DeFi产品 |
| 2 | | 搜索DeFi产品 |
| 3 | | 获取产品完整详情 |
| 4 | | 一键存款(CLI自动处理准备工作、精度转换和calldata生成) |
| 5 | | 一键提款(CLI自动处理头寸查询和calldata生成) |
| 6 | | 一键领取奖励(CLI自动处理奖励检查和calldata生成) |
| 7 | | 按平台列出DeFi头寸 |
| 8 | | 获取头寸详细信息 |
Investment Types
投资类型
| productGroup | Description |
|---|---|
| Single-token yield (savings, staking, vaults) |
| Liquidity pools (Uniswap V2/V3, PancakeSwap, etc.) |
| Lending / borrowing (Aave, Compound, etc.) |
| productGroup | 描述 |
|---|---|
| 单币生息(储蓄、质押、金库) |
| 流动性池(Uniswap V2/V3、PancakeSwap等) |
| 借贷(Aave、Compound等) |
Chain Support
支持链
CLI resolves chain names automatically (e.g. → , → , → ).
ethereum1bsc56solana501CLI会自动解析链名称(例如 → , → , → )。
ethereum1bsc56solana501Operation Flow
操作流程
Step 0: Address Resolution
步骤0:地址解析
When the user does NOT provide a wallet address, resolve it automatically from the Agentic Wallet before running any defi command:
1. onchainos wallet status → check if logged in, get active account
2. onchainos wallet addresses → get addresses grouped by chain category:
- XLayer addresses
- EVM addresses (Ethereum, BSC, Polygon, etc.)
- Solana addresses
3. Match address to target chain:
- EVM chains → use EVM address
- Solana → use Solana address
- XLayer → use XLayer addressRules:
- If the user provides an explicit address, use it directly — skip this step
- If wallet is not logged in, ask the user to log in first (→ ) or provide an address manually
okx-agentic-wallet - If the user says "check all accounts" or "all wallets", use to get all account IDs, then
wallet balance --all+wallet switch <id>for each accountwallet addresses - Always confirm the resolved address with the user before proceeding if the account has multiple addresses of the same type
当用户未提供钱包地址时,需在执行任何defi命令前,从Agentic Wallet自动解析地址:
1. onchainos wallet status → 检查是否已登录,获取活跃账户
2. onchainos wallet addresses → 获取按链分类的地址:
- XLayer地址
- EVM地址(以太坊、BSC、Polygon等)
- Solana地址
3. 匹配目标链对应的地址:
- EVM链 → 使用EVM地址
- Solana → 使用Solana地址
- XLayer → 使用XLayer地址规则:
- 若用户提供了明确地址,直接使用该地址——跳过此步骤
- 若钱包未登录,请先让用户登录(跳转至)或手动提供地址
okx-agentic-wallet - 若用户要求「检查所有账户」或「所有钱包」,使用获取所有账户ID,然后依次执行
wallet balance --all+wallet switch <id>wallet addresses - 若账户有多个同类型地址,在继续操作前务必与用户确认解析出的地址
Deposit (invest)
存款(invest)
1. defi search --token USDC --chain ethereum → pick investmentId
2. defi detail --investment-id <id> → confirm APY/TVL, get underlyingToken[].tokenAddress
3. token search --query <tokenAddress> --chains <chain> → get decimal (e.g. 6) for amount conversion
4. Ask user for amount → convert: userAmount × 10^decimal (e.g. 100 USDC → 100000000)
5. Check wallet balance (okx-wallet-portfolio) → if insufficient, warn user and stop
6. defi invest --investment-id <id> --address <addr> --token USDC --amount 100000000
→ CLI returns calldata (APPROVE + DEPOSIT steps)
7. User signs and broadcasts each step in orderToken decimal: GetfromtokenAddress→defi detail, then useunderlyingToken[].tokenAddressto gettoken search --query <tokenAddress>. Same approach as DEX swap.decimalCRITICAL — Balance check is REQUIRED before calling. You MUST calldefi investto verify the user has sufficient balance of the deposit token BEFORE generating calldata. If balance is insufficient, STOP and warn the user. Do NOT proceed tookx-wallet-portfoliowithout confirming balance. Skipping this step wastes gas and results in failed on-chain transactions.defi invest
1. defi search --token USDC --chain ethereum → 选择investmentId
2. defi detail --investment-id <id> → 确认APY/TVL,获取underlyingToken[].tokenAddress
3. token search --query <tokenAddress> --chains <chain> → 获取小数位数(例如6)用于金额转换
4. 询问用户存入金额 → 转换为最小单位:用户输入金额 × 10^小数位数(例如100 USDC → 100000000)
5. 检查钱包余额(调用okx-wallet-portfolio)→ 若余额不足,提示用户并终止操作
6. defi invest --investment-id <id> --address <addr> --token USDC --amount 100000000
→ CLI返回calldata(包含APPROVE + DEPOSIT步骤)
7. 用户依次签名并广播每一步代币小数位数:从获取defi detail(underlyingToken[].tokenAddress),再通过tokenAddress获取token search --query <tokenAddress>。与DEX兑换的处理方式一致。decimal关键注意事项——调用前必须检查余额。在生成calldata前,必须调用defi invest验证用户的存入代币余额是否充足。若余额不足,立即终止操作并提示用户。切勿跳过此步骤,否则会浪费Gas并导致链上交易失败。okx-wallet-portfolio
Withdraw
提款(withdraw)
CRITICAL — position-detail is MANDATORY before withdraw. You MUST callimmediately before everydefi position-detail, even if you already have position data from a previous call. Do NOT reuse stale position-detail results.defi withdraw
1. defi positions --address <addr> --chains ethereum
2. defi position-detail --address <addr> --chain ethereum --platform-id <pid>
→ MUST be called fresh — get investmentId, tokenPrecision, coinAmount (current balance)
3. Full exit:
defi withdraw --investment-id <id> --address <addr> --chain ethereum --ratio 1 --platform-id <pid>
Partial exit (convert coinAmount to minimal units: amount × 10^tokenPrecision):
defi withdraw --investment-id <id> --address <addr> --chain ethereum --amount <minimal_units> --platform-id <pid>
4. User signs and broadcastsPartial exit --amount: position-detail returnsin human-readable (e.g. "2.3792") andcoinAmount(e.g. 6). Convert to minimal units:tokenPrecision→floor(2.3792 × 10^6) = 2379200.--amount 2379200
关键注意事项——提款前必须调用position-detail。每次执行前,都必须调用defi withdraw,即使对话中已有历史头寸数据也不能复用。禁止使用过期的position-detail结果。defi position-detail
1. defi positions --address <addr> --chains ethereum
2. defi position-detail --address <addr> --chain ethereum --platform-id <pid>
→ 必须实时调用——获取investmentId、tokenPrecision、coinAmount(当前余额)
3. 全额退出:
defi withdraw --investment-id <id> --address <addr> --chain ethereum --ratio 1 --platform-id <pid>
部分退出(将coinAmount转换为最小单位:金额 × 10^tokenPrecision):
defi withdraw --investment-id <id> --address <addr> --chain ethereum --amount <minimal_units> --platform-id <pid>
4. 用户签名并广播部分退出的--amount参数:position-detail返回的为人类可读格式(例如"2.3792"),coinAmount为小数位数(例如6)。转换为最小单位:tokenPrecision→ 使用floor(2.3792 × 10^6) = 2379200。--amount 2379200
Claim Rewards
领取奖励(collect)
CRITICAL — position-detail is MANDATORY before collect. You MUST callimmediately before everydefi position-detail, even if you already have position data from a previous call in the conversation. Position data (rewards, investmentId, platformId, tokenId) changes after each on-chain operation (withdraw, previous collect, etc.), so stale data leads to wrong parameters or failed transactions. Do NOT skip this step. Do NOT reuse position-detail results from earlier in the conversation.defi collect
1. defi positions --address <addr> --chains ethereum
2. defi position-detail --address <addr> --chain ethereum --platform-id <pid>
→ MUST be called fresh — do NOT reuse prior results
3. defi collect --address <addr> --chain ethereum --reward-type REWARD_INVESTMENT --investment-id <id> --platform-id <pid>
→ CLI returns calldata (or skips if no rewards)
4. User signs and broadcasts关键注意事项——领取奖励前必须调用position-detail。每次执行前,都必须调用defi collect,即使对话中已有历史头寸数据也不能复用。头寸数据(奖励、investmentId、platformId、tokenId)会在每次链上操作(提款、之前的领取奖励等)后发生变化,使用过期数据会导致参数错误或交易失败。切勿跳过此步骤,禁止复用对话中早期的position-detail结果。defi position-detail
1. defi positions --address <addr> --chains ethereum
2. defi position-detail --address <addr> --chain ethereum --platform-id <pid>
→ 必须实时调用——禁止复用历史结果
3. defi collect --address <addr> --chain ethereum --reward-type REWARD_INVESTMENT --investment-id <id> --platform-id <pid>
→ CLI返回calldata(若无奖励则跳过)
4. 用户签名并广播V3 Pool Deposit
V3池存款
1. defi search --token USDT --platform PancakeSwap --chain bsc --product-group DEX_POOL
2. defi detail --investment-id <id>
3. Ask user for amount and tick range
4. Check wallet balance (okx-wallet-portfolio) → if insufficient, warn user and stop
5. defi invest --investment-id <id> --address <addr> --token USDT --amount 100000000 --range 5
→ CLI handles calculate-entry internally, returns calldata
6. User signs and broadcasts1. defi search --token USDT --platform PancakeSwap --chain bsc --product-group DEX_POOL
2. defi detail --investment-id <id>
3. 询问用户存入金额和tick区间
4. 检查钱包余额(调用okx-wallet-portfolio)→ 若余额不足,提示用户并终止操作
5. defi invest --investment-id <id> --address <addr> --token USDT --amount 100000000 --range 5
→ CLI内部处理入场价格计算,返回calldata
6. 用户签名并广播Step 3: Sign & Broadcast Calldata
步骤3:签名并广播Calldata
After // returns , execute each step via one of two paths:
investwithdrawcollectdataListPath A (user-provided wallet): user signs externally → broadcast via gateway
bash
undefinedinvestwithdrawcollectdataList路径A(用户自备钱包):用户外部签名 → 通过网关广播
bash
undefinedFor each dataList step:
对dataList中的每一步:
1. User signs the tx externally using dataList[N].to, dataList[N].serializedData, dataList[N].value
1. 用户使用dataList[N].to、dataList[N].serializedData、dataList[N].value在外部签名交易
2. Broadcast:
2. 广播:
onchainos gateway broadcast --signed-tx <signed_hex> --address <addr> --chain <chain>
onchainos gateway broadcast --signed-tx <signed_hex> --address <addr> --chain <chain>
3. Poll until confirmed:
3. 轮询直至交易确认:
onchainos gateway orders --address <addr> --chain <chain> --order-id <orderId>
onchainos gateway orders --address <addr> --chain <chain> --order-id <orderId>
→ wait for txStatus=2, then proceed to next step
→ 等待txStatus=2,再执行下一步
**Path B (Agentic Wallet)**: sign & broadcast via `wallet contract-call`
EVM chains (Ethereum, BSC, Polygon, Arbitrum, Base, etc.):
```bash
onchainos wallet contract-call \
--to <dataList[N].to> \
--chain <chainIndex> \
--input-data <dataList[N].serializedData> \
--value <value_in_UI_units>EVM (XLayer):
bash
onchainos wallet contract-call \
--to <dataList[N].to> \
--chain 196 \
--input-data <dataList[N].serializedData> \
--value <value_in_UI_units>Solana:
bash
onchainos wallet contract-call \
--to <dataList[N].to> \
--chain 501 \
--unsigned-tx <dataList[N].serializedData>contract-call--valuedataList[].valuecontract-call --valuevalue_UI = value / 10^nativeToken.decimalvalue"""0""0x0""0"--chaincontract-callgateway broadcastrealChainIndex113756501196Execution rules:
- Execute first, then
dataList[0], etc. Never in parallel.dataList[1] - Wait for on-chain confirmation before next step (Path A: ; Path B:
txStatus=2returns txHash).contract-call - If any step fails, stop all remaining steps and report which succeeded/failed.
/invest/withdrawonly return unsigned calldata — they do NOT broadcast. The CLI never holds private keys.collect
**路径B(Agentic Wallet)**:通过`wallet contract-call`签名并广播
EVM链(以太坊、BSC、Polygon、Arbitrum、Base等):
```bash
onchainos wallet contract-call \
--to <dataList[N].to> \
--chain <chainIndex> \
--input-data <dataList[N].serializedData> \
--value <value_in_UI_units>EVM链(XLayer):
bash
onchainos wallet contract-call \
--to <dataList[N].to> \
--chain 196 \
--input-data <dataList[N].serializedData> \
--value <value_in_UI_units>Solana链:
bash
onchainos wallet contract-call \
--to <dataList[N].to> \
--chain 501 \
--unsigned-tx <dataList[N].serializedData>contract-call--valuedataList[].valuecontract-call --valuevalue_UI = value / 10^原生代币小数位数value--chaincontract-callgateway broadcast113756501196执行规则:
- 先执行,再执行
dataList[0],以此类推。禁止并行执行dataList[1] - 等待上一步链上确认后再执行下一步(路径A:;路径B:
txStatus=2返回txHash)contract-call - 若某一步失败,终止所有后续步骤并告知用户成功/失败的步骤
/invest/withdraw仅返回未签名的calldata——不负责广播。CLI绝不会存储私钥。collect
Displaying Search / List Results
搜索/列表结果展示格式
| # | Platform | Chain | investmentId | Name | APY | TVL |
|---|---|---|---|---|---|---|
| 1 | Aave V3 | ETH | 9502 | USDC | 1.89% | $3.52B |
- is MANDATORY in every row
investmentId - is decimal → multiply by 100 and append
rate% - → format as human-readable USD ($3.52B, $537M)
tvl - Display data as-is — do NOT editorialize on APY values
| 序号 | 平台 | 链 | investmentId | 名称 | APY | TVL |
|---|---|---|---|---|---|---|
| 1 | Aave V3 | ETH | 9502 | USDC | 1.89% | $3.52B |
- 每一行必须包含
investmentId - 为小数格式 → 乘以100后添加
rate符号% - → 格式化为易读的美元金额(如$3.52B、$537M)
tvl - 按原始数据展示——不得对APY值进行编辑或评价
rewardType Reference
rewardType参考
| rewardType | When to use | Required params |
|---|---|---|
| Protocol-level rewards (e.g. AAVE token) | |
| Product mining/staking rewards | |
| V3 trading fee collection | |
| OKX bonus rewards | |
| Merkle proof-based bonus | |
| Unlocked principal after lock | |
| rewardType | 使用场景 | 必填参数 |
|---|---|---|
| 协议级奖励(例如AAVE代币) | |
| 产品挖矿/质押奖励 | |
| V3交易手续费领取 | |
| OKX专属奖励 | |
| 基于默克尔证明的奖励 | |
| 锁定期结束后解锁的本金 | |
Key Protocol Rules
核心协议规则
- Aave borrow: uses internally — do not expose to user
callDataType=WITHDRAW - Aave repay: uses internally — do not expose to user
callDataType=DEPOSIT - V3 Pool exit: pass +
--token-id(e.g.--ratiofor full exit)--ratio 1 - Partial withdrawal (non-V3): pass for the exit amount
--amount - Full withdrawal:
--ratio 1
- Aave借入:内部使用——无需向用户暴露此细节
callDataType=WITHDRAW - Aave偿还:内部使用——无需向用户暴露此细节
callDataType=DEPOSIT - V3池退出:需传入+
--token-id(例如全额退出使用--ratio)--ratio 1 - 非V3部分提款:需传入指定提款金额
--amount - 全额提款:使用
--ratio 1
Post-execution Suggestions
操作后建议
| Just completed | Suggest |
|---|---|
| View details → |
| Proceed → |
| View positions → |
| Check positions → |
| Check positions → |
| 刚完成的操作 | 建议后续操作 |
|---|---|
| 查看产品详情→ |
| 继续操作→ |
| 查看头寸→ |
| 检查头寸→ |
| 查询头寸→ |
Error Codes
错误码
| Code | Scenario | Handling |
|---|---|---|
| 84400 | Parameter null | Check required params — partial exit needs |
| 84021 | Asset syncing | "Position data is syncing, please retry shortly" |
| 84023 | Invalid expectOutputList | CLI auto-constructs from position-detail; retry or pass |
| 84014 | Balance check failed | Insufficient balance — check with |
| 84018 | Balancing failed | V3 balancing failed — adjust price range or increase slippage |
| 84010 | Token not supported | Check supported tokens via |
| 84001 | Platform not supported | DeFi platform not supported |
| 84016 | Contract execution failed | Check parameters and retry |
| 84019 | Address format mismatch | Address format invalid for this chain |
| 50011 | Rate limit | Wait and retry |
| 代码 | 场景 | 处理方式 |
|---|---|---|
| 84400 | 参数为空 | 检查必填参数——部分提款需传入 |
| 84021 | 资产同步中 | 「头寸数据正在同步,请稍后重试」 |
| 84023 | expectOutputList无效 | CLI会自动从position-detail构造参数;重试或传入 |
| 84014 | 余额检查失败 | 余额不足——调用 |
| 84018 | 平衡失败 | V3池平衡失败——调整价格区间或提高滑点 |
| 84010 | 代币不支持 | 通过 |
| 84001 | 平台不支持 | 该DeFi平台未被支持 |
| 84016 | 合约执行失败 | 检查参数后重试 |
| 84019 | 地址格式不匹配 | 该地址格式不适用于目标链 |
| 50011 | 触发速率限制 | 等待后重试 |
Global Notes
全局注意事项
- must be in minimal units (integer). Convert: userAmount × 10^tokenPrecision. Example: 0.1 USDC (precision=6) →
--amount. Get tokenPrecision from--amount 100000ordefi detaildefi position-detail - The wallet address parameter for ALL defi commands is
--address - default is
--slippage(1%); suggest"0.01"–"0.03"for volatile V3 pools"0.05" - CRITICAL — Solana transaction expiry: Solana DeFi transactions use base58-encoded VersionedTransaction with a blockhash that expires in ~60 seconds. After receiving calldata, you MUST warn the user: "This Solana transaction must be signed and broadcast within 60 seconds or it will expire. Please sign immediately." Do NOT proceed to other conversation without delivering this warning first.
- CRITICAL — High APY risk warning: When displaying search/list results, if any product has APY > 50% (rate > 0.5), you MUST warn the user: "WARNING: This product shows APY above 50%, which indicates elevated risk (potential impermanent loss, smart contract risk, or unsustainable rewards). Proceed with caution." Do NOT silently display high-APY products without this warning.
- CRITICAL — Address-chain compatibility: When calling or
defi positions, thedefi position-detailand chain parameters must be compatible. EVM addresses (--address) can only query EVM chains; Solana addresses (base58) can only query0x…. Never mix them — the API will return error 84019 (Address format error).solana- address → only pass EVM chains:
0x…ethereum,bsc,polygon,arbitrum,base,xlayer,avalanche,optimism,fantom,linea,scroll,zksync - base58 address → only pass
solana - If the user wants positions across both EVM and Solana, make two separate calls with the respective addresses
- User confirmation required before every invest/withdraw/collect execution
- Address used for calldata generation MUST match the signing address
- 必须为最小单位(整数)。转换方式:用户输入金额 × 10^tokenPrecision。示例:0.1 USDC(precision=6)→
--amount。从--amount 100000或defi detail获取tokenPrecisiondefi position-detail - 所有defi命令的钱包地址参数均为
--address - 默认值为
--slippage(1%);对于波动较大的V3池,建议设置为"0.01"–"0.03""0.05" - 关键注意事项——Solana交易过期时间:Solana DeFi交易使用base58编码的VersionedTransaction,其blockhash约60秒后过期。获取calldata后,必须立即提示用户:「此Solana交易需在60秒内签名并广播,否则将过期。请立即签名。」在发出此提示前,不得进行其他对话操作
- 关键注意事项——高APY风险提示:展示搜索/列表结果时,若任何产品APY>%50(rate>0.5),必须提示用户:「警告:该产品APY超过50%,存在高风险(可能无常损失、智能合约风险或奖励不可持续)。请谨慎操作。」不得静默展示高APY产品
- 关键注意事项——地址与链兼容性:调用或
defi positions时,defi position-detail和链参数必须兼容。EVM地址(--address)仅可查询EVM链;Solana地址(base58格式)仅可查询0x…链。禁止混合使用——否则API会返回错误码84019(地址格式错误)。solana- 地址 → 仅传入EVM链:
0x…ethereum,bsc,polygon,arbitrum,base,xlayer,avalanche,optimism,fantom,linea,scroll,zksync - base58地址 → 仅传入
solana - 若用户需要查询EVM和Solana链的头寸,需使用对应地址分别发起两次调用
- 执行invest/withdraw/collect前必须获得用户确认
- 生成calldata使用的地址必须与签名地址一致