OpenOcean Swap Execute Skill
Execute a previously built swap transaction on-chain using Foundry's cast send. This skill takes transaction data from /swap-build and broadcasts it to the network.
Prerequisites
Required Tools:
- Foundry installed, with the
castcommand available - RPC endpoint for the target chain
- Wallet access (environment variable, Ledger, Trezor, or keystore)
Wallet Setup Options:
- Environment variables —
ETH_RPC_URLandETH_FROMare set - Ledger — Hardware wallet connected
- Trezor — Hardware wallet connected
- Keystore — Encrypted keyfile with password
Input Parsing
The user will provide:
- Transaction data (from previous
/swap-buildoutput) - Optional wallet method specification
Common patterns:
- Just
/swap-execute(uses default environment setup) /swap-execute ledger(uses Ledger hardware wallet)/swap-execute trezor(uses Trezor hardware wallet)/swap-execute keystore mykey(uses keystore file)
Workflow
Step 1: Verify Transaction Data
Check that the user has provided complete transaction data. It should include:
from— sender addressto— OpenOcean router addressvalue— transaction value (wei)data— encoded calldatagas— gas limitgasPrice— gas price (wei)chainId— chain ID
If any required field is missing, ask the user to run /swap-build first.
Step 2: Confirm Execution
Before broadcasting, show transaction summary:
## OpenOcean Swap Execute - Final Confirmation
**⚠️ WARNING: This will broadcast a transaction on-chain. Funds will be transferred.**
### Transaction Summary
- **From**: `{from}`
- **To**: `{to}` (OpenOcean router)
- **Value**: {value} wei ({valueEth} ETH)
- **Gas**: {gas} units
- **Gas Price**: {gasPrice} wei ({gasPriceGwei} Gwei)
- **Chain**: {chainName} (ID: {chainId})
- **Estimated Cost**: {estimatedCost} ETH (~${estimatedCostUsd})
### Funds Impact
- **Input**: {amountIn} {tokenIn}
- **Minimum Output**: {minOutAmount} {tokenOut}
- **Max Gas Cost**: {maxGasCost} ETH
**Are you absolutely sure you want to execute this swap?** (Yes/No)
Step 3: If User Confirms, Execute with cast
If user confirms "Yes", execute the transaction.
Method 1: Environment Variables (Default)
cast send --rpc-url $ETH_RPC_URL \
--from $ETH_FROM \
--value {value} \
--gas {gas} \
--gas-price {gasPrice} \
--chain {chainId} \
{to} {data}
Method 2: Ledger
cast send --rpc-url $ETH_RPC_URL \
--ledger \
--value {value} \
--gas {gas} \
--gas-price {gasPrice} \
--chain {chainId} \
{to} {data}
Method 3: Trezor
cast send --rpc-url $ETH_RPC_URL \
--trezor \
--value {value} \
--gas {gas} \
--gas-price {gasPrice} \
--chain {chainId} \
{to} {data}
Method 4: Keystore
cast send --rpc-url $ETH_RPC_URL \
--keystore /path/to/keystore \
--value {value} \
--gas {gas} \
--gas-price {gasPrice} \
--chain {chainId} \
{to} {data}
Step 4: Handle the Execution Result
If successful:
## ✅ Swap Executed Successfully
**Transaction Hash**: `{txHash}`
**Block Explorer**: {explorerUrl}
### Details
- **Status**: Pending confirmation
- **Gas Used**: {gasUsed} units
- **Effective Gas Price**: {effectiveGasPrice} wei
- **Total Cost**: {totalCost} ETH
### Next Steps
1. Monitor confirmation on block explorer
2. Check token balance after confirmation
3. Verify minimum output was received
If failed:
## ❌ Swap Execution Failed
**Error**: {errorMessage}
### Possible Causes
1. Insufficient balance for gas + value
2. Insufficient token allowance
3. Price moved beyond slippage tolerance
4. Network congestion
5. Wallet not properly configured
### Troubleshooting
1. Check wallet balance and allowances
2. Verify RPC endpoint is working
3. Try with higher slippage
4. Wait for better network conditions
Step 5: If User Declines, Cancel
If user says "No" or cancels:
## Swap Execution Cancelled
The transaction was not broadcast. You can:
- Review the transaction details again
- Adjust parameters and rebuild
- Use `/quote` to check current prices
Important Notes
Safety Warnings
- Irreversible: On-chain transactions cannot be undone
- Gas Costs: Gas will still be charged even if the swap fails
- Price Risk: Prices may change between quote and execution
- Slippage: Minimum output is enforced, but may be less than expected
Best Practices
- Test First: Always test with small amounts first
- Monitor Gas: Use appropriate gas price for current conditions
- Check Allowances: Ensure ERC-20 approvals are set
- Verify Network: Confirm correct chain and RPC endpoint
Gas Configuration
- Gas Limit: Use the estimate from OpenOcean and add a 20% buffer
- Gas Price: Use current market rates
- Priority Fee: For EIP-1559 chains, use an appropriate priority fee
Error Handling
Common execution errors:
insufficient funds for gas * price + value- User doesn't have enough native token for gas + value
- Solution: Add funds or reduce amount
execution reverted: OpenOcean: insufficient output amount- Price moved beyond slippage tolerance
- Solution: Increase slippage or try again
execution reverted: ERC20: transfer amount exceeds allowance- Token not approved for spending
- Solution: Approve token first
nonce too lowornonce too high- Transaction nonce mismatch
- Solution: Let wallet manage nonces automatically
For detailed troubleshooting, see skills/error-handling/SKILL.md.
Example Workflow
User: /swap-build 1 ETH to USDC on ethereum from 0x...
Agent: Shows quote, asks for confirmation
User: Yes
Agent: Returns transaction data
User: /swap-execute
Agent: Shows final confirmation
User: Yes
Agent: Executes with cast, returns tx hash
Alternative: Fast Execution
For automated workflows, consider /swap-execute-fast which builds and executes in one step (no confirmation prompts). Use with extreme caution.
Post-Execution
After successful execution:
- Monitor transaction on block explorer
- Verify token balances updated
- Check that minimum output was received
- Save transaction hash for records
Remember: A successful transaction does not necessarily mean the swap outcome was correct. Always verify the final result.