DeFi Yield Strategies
Discover yield opportunities across DeFi protocols (Aave, Compound, and others), deposit tokens to earn yield, and withdraw when ready. This is a full lifecycle skill covering discovery through to exit.
Confirm wallet is authenticated
CODEBLOCK0
If the wallet is not authenticated, refer to the authenticate skill.
Step 1: Discover Yield Strategies
Search for available yield opportunities:
CODEBLOCK1
discoverYieldStrategies Parameters
| Parameter | Required | Description |
|---|
| INLINECODE1 | No | Filter by blockchain (e.g. ethereum, polygon, arbitrum, base) |
| INLINECODE6 |
No | Filter by token contract address |
|
--minApy | No | Minimum APY percentage (e.g.
5 for 5%) |
|
--maxRisk | No | Maximum risk level filter (e.g.
low,
medium,
high) |
|
--sortBy | No | Sort results (e.g.
apy,
risk) |
Step 2: Deposit for Yield
Once a strategy is selected, deposit tokens into it:
CODEBLOCK2
depositForYield Parameters
| Parameter | Required | Description |
|---|
| INLINECODE16 | Yes | Blockchain where the strategy runs |
| INLINECODE17 |
Yes | Strategy identifier from
discoverYieldStrategies results |
|
--amount | Yes | Amount to deposit (human-readable) |
|
--tokenAddress | No | Token to deposit (if strategy accepts multiple tokens) |
Step 3: Withdraw from Yield
Exit a position and retrieve tokens:
CODEBLOCK3
withdrawFromYield Parameters
| Parameter | Required | Description |
|---|
| INLINECODE21 | Yes | Blockchain of the position |
| INLINECODE22 |
Yes | Position identifier from the deposit result |
|
--amount | No | Amount to withdraw (omit for full withdrawal) |
|
--recipient | No | Custom recipient address (defaults to own wallet) |
Example Session
CODEBLOCK4
Flow
- 1. Check authentication with INLINECODE25
- Check available balance with INLINECODE26
- Discover strategies with
fdx call discoverYieldStrategies — present options to the human - Human selects a strategy — confirm the choice, risks, and deposit amount
- Execute deposit with INLINECODE28
- When the human wants to exit, withdraw with INLINECODE29
Important: DeFi protocols carry smart contract risk. Always present the risk level to your human and let them make the final decision on which strategy to use and how much to deposit.
Prerequisites
- - Must be authenticated (
fdx status to check, see authenticate skill) - Wallet must hold sufficient balance of the deposit token on the target chain
- If insufficient funds, suggest using the
fund-wallet skill or swap-tokens skill to acquire the needed token
Error Handling
- - "Not authenticated" — Run
fdx setup first, or see authenticate skill - "Insufficient balance" — Check balance; see
fund-wallet skill - "Invalid strategyId" — Re-run
discoverYieldStrategies to get current strategy IDs - "Invalid positionId" — The position may have already been withdrawn
DeFi 收益策略
发现 DeFi 协议(Aave、Compound 等)中的收益机会,存入代币赚取收益,并在准备就绪时提取。这是一个涵盖从发现到退出的完整生命周期技能。
确认钱包已认证
bash
fdx status
如果钱包未认证,请参考 authenticate 技能。
步骤 1:发现收益策略
搜索可用的收益机会:
bash
浏览所有可用策略
fdx call discoverYieldStrategies
按链筛选
fdx call discoverYieldStrategies --chainKey ethereum
按代币筛选
fdx call discoverYieldStrategies --chainKey ethereum --tokenAddress 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
按最低年化收益率和风险等级筛选
fdx call discoverYieldStrategies --chainKey ethereum --minApy 5 --maxRisk low
排序结果
fdx call discoverYieldStrategies --chainKey ethereum --sortBy apy
discoverYieldStrategies 参数
| 参数 | 必填 | 描述 |
|---|
| --chainKey | 否 | 按区块链筛选(例如 ethereum、polygon、arbitrum、base) |
| --tokenAddress |
否 | 按代币合约地址筛选 |
| --minApy | 否 | 最低年化收益率百分比(例如 5 表示 5%) |
| --maxRisk | 否 | 最高风险等级筛选(例如 low、medium、high) |
| --sortBy | 否 | 排序方式(例如 apy、risk) |
步骤 2:存入以获取收益
选定策略后,将代币存入其中:
bash
fdx call depositForYield \
--chainKey \
--strategyId \
--amount
depositForYield 参数
| 参数 | 必填 | 描述 |
|---|
| --chainKey | 是 | 策略运行的区块链 |
| --strategyId |
是 | 来自 discoverYieldStrategies 结果的策略标识符 |
| --amount | 是 | 存入数量(人类可读格式) |
| --tokenAddress | 否 | 存入的代币(如果策略接受多种代币) |
步骤 3:从收益中提取
退出仓位并取回代币:
bash
fdx call withdrawFromYield \
--chainKey \
--positionId
withdrawFromYield 参数
| 参数 | 必填 | 描述 |
|---|
| --chainKey | 是 | 仓位所在的区块链 |
| --positionId |
是 | 来自存入结果的仓位标识符 |
| --amount | 否 | 提取数量(省略则全额提取) |
| --recipient | 否 | 自定义接收地址(默认为自己的钱包) |
示例会话
bash
检查认证和余额
fdx status
fdx call getWalletOverview --chainKey ethereum
在以太坊上发现年化收益率至少 3% 的 USDC 收益策略
fdx call discoverYieldStrategies \
--chainKey ethereum \
--tokenAddress 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 \
--minApy 3 \
--sortBy apy
将 1000 USDC 存入选定的策略
fdx call depositForYield \
--chainKey ethereum \
--strategyId
\
--amount 1000
稍后:全额提取仓位
fdx call withdrawFromYield \
--chainKey ethereum \
--positionId
流程
- 1. 使用 fdx status 检查认证状态
- 使用 fdx call getWalletOverview --chainKey 检查可用余额
- 使用 fdx call discoverYieldStrategies 发现策略 — 向用户展示选项
- 用户选择策略 — 确认选择、风险和存入金额
- 使用 fdx call depositForYield 执行存入
- 当用户想要退出时,使用 fdx call withdrawFromYield 提取
重要提示: DeFi 协议存在智能合约风险。始终向用户展示风险等级,让他们对使用哪个策略以及存入多少金额做出最终决定。
前置条件
- - 必须已认证(使用 fdx status 检查,参见 authenticate 技能)
- 钱包在目标链上必须持有足够的存入代币余额
- 如果资金不足,建议使用 fund-wallet 技能或 swap-tokens 技能获取所需代币
错误处理
- - 未认证 — 先运行 fdx setup,或参见 authenticate 技能
- 余额不足 — 检查余额;参见 fund-wallet 技能
- 无效的 strategyId — 重新运行 discoverYieldStrategies 获取当前策略 ID
- 无效的 positionId — 该仓位可能已被提取