Documentation Index
Fetch the complete documentation index at: https://yieldxyz.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Exit Position
Generate the transactions needed to exit (withdraw from) a yield position using the Yield.xyz Actions API. This skill covers unstaking, withdrawing from lending protocols, exiting vaults, and handling cooldown periods.
When to Use
Activate this skill when the user asks to:
- Unstake tokens (e.g., “Unstake my ETH from Lido”)
- Withdraw from a lending protocol (e.g., “Withdraw USDC from Aave”)
- Exit a vault position
- Remove liquidity
- Stop earning yield on a position
- Claim unstaked/unlocked tokens
Authentication
Base URL
Step-by-Step Instructions
Step 1: Verify the Yield Supports Exits
curl "https://api.yield.xyz/v1/yields/{yieldId}" \
-H "x-api-key: $YIELD_API_KEY"
Confirm status.exit is true. Check metadata.cooldownPeriod for any withdrawal waiting period.
Step 2: Check Current Balance (Recommended)
Before exiting, verify the user has a position:
curl -X POST "https://api.yield.xyz/v1/yields/{yieldId}/balances" \
-H "x-api-key: $YIELD_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"address": "0xUserWalletAddress"
}'
This confirms the user has an active position and shows available balance types (staked, unstaking, claimable, etc.).
Step 3: Create the Exit Action
Endpoint: POST /v1/actions/exit
Request Body (CreateActionDto):
{
"yieldId": "ethereum-eth-lido-staking",
"address": "0xYourWalletAddress",
"arguments": {
"amount": "1000000000000000000"
}
}
For full withdrawal (vaults):
Some ERC-4626 vaults support useMaxAmount:
{
"yieldId": "ethereum-usdc-morpho-vault",
"address": "0xYourWalletAddress",
"arguments": {
"useMaxAmount": true
}
}
With validator (staking):
{
"yieldId": "cosmos-atom-native-staking",
"address": "cosmos1youraddress...",
"arguments": {
"amount": "1000000",
"validatorAddress": "cosmosvaloper1..."
}
}
cURL Example:
curl -X POST "https://api.yield.xyz/v1/actions/exit" \
-H "x-api-key: $YIELD_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"yieldId": "ethereum-eth-lido-staking",
"address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"arguments": {
"amount": "500000000000000000"
}
}'
Response (ActionDto):
{
"id": "action_xyz789",
"intent": "exit",
"type": "UNSTAKE",
"status": "CREATED",
"transactions": [
{
"id": "tx_003",
"type": "UNSTAKE",
"status": "CREATED",
"unsignedTransaction": "0x..."
}
]
}
Step 4: Sign and Submit Each Transaction
For each transaction in the transactions array, in order:
- Sign the
unsignedTransaction using the user’s wallet
- Broadcast the signed transaction to the blockchain
- Submit the hash to Yield.xyz:
curl -X PUT "https://api.yield.xyz/v1/transactions/{transactionId}/submit-hash" \
-H "x-api-key: $YIELD_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "hash": "0xTransactionHashHere..." }'
Step 5: Handle Cooldown Periods
Many staking yields have cooldown periods after unstaking:
| Network / Protocol | Typical Cooldown |
|---|
| Ethereum native staking | Variable (exit queue, ~1-5 days) |
| Cosmos (ATOM) | 21 days |
| Polkadot (DOT) | 28 days |
| Solana (SOL) | ~2-3 days (1 epoch) |
| Avalanche (AVAX) | 14 days (delegator) |
| Lido (stETH) | Up to ~4 days |
| Lending protocols (Aave, Compound) | Instant |
| ERC-4626 vaults | Usually instant |
After the cooldown period, the user may need to execute a claim_unstaked action using the manage-position skill.
Step 6: Verify Action Completion
curl "https://api.yield.xyz/v1/actions/{actionId}" \
-H "x-api-key: $YIELD_API_KEY"
Exit Action Types
| Type | Description |
|---|
UNSTAKE | Initiate unstaking (may trigger cooldown) |
WITHDRAW | Direct withdrawal (lending, vaults) |
WITHDRAW_ALL | Withdraw entire position |
REVOKE | Revoke delegation (some networks) |
Error Handling
| Status Code | Meaning | Action |
|---|
| 400 | Invalid parameters | Check amount doesn’t exceed balance; verify arguments |
| 401 | Unauthorized | Verify API key |
| 403 | Geoblocked | User’s region is restricted |
| 404 | Yield not found | Verify yield ID |
| 429 | Rate limited | Wait and retry |
Edge Cases
- Partial exits: Most yields support partial withdrawals. Specify the exact amount to withdraw.
- Cooldown in progress: If the user already has an unstaking request in cooldown, some protocols allow additional unstake requests while others don’t. Check balances for
unstaking balance types.
- WETH unwrapping: Some ERC-4626 vault exits with WETH as the underlying token will automatically unwrap to ETH.
- Price per share: Vault withdrawals convert the user’s share amount using the current price-per-share, which may differ from the deposit amount due to yield accrual.
- Minimum withdrawal: Some protocols have minimum withdrawal amounts.
- Instant vs delayed: Lending protocols and most vaults process withdrawals instantly. Native staking typically has a cooldown period.
- Claim after cooldown: After a staking cooldown completes, use the
manage-position skill with CLAIM_UNSTAKED action to claim the tokens.