swap-execute
This skill should be used when the user asks to "execute swap", "broadcast swap", "send transaction", or wants to submit a previously built swap transaction on-chain. Uses Foundry's cast to broadcast the transaction.
- License 许可
- AGPL-3.0
- 最近更新
- 2026-11-15
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- swap-execute
- metadata
- { "tags": [ "defi", "openocean", "swap", "transaction", "evm", "foundry", "cast" ], "homepage": "https://openocean.finance", "provider": "OpenOcean" }
- description
- This skill should be used when the user asks to "execute swap", "broadcast swap", "send transaction", or wants to submit a previously built swap transaction on-chain. Uses Foundry's cast to broadcast the transaction.
03 SKILL.md 正文
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.
04 同仓库更多 Skills
troves
Deposit and withdraw from Troves DeFi yield vault strategies on Starknet. View available strategies, check positions, and manage vault deposits. Use this skill when the user mentions Troves, vault, yield vault, DeFi vault, strategy, yield farming, vault deposit, vault withdraw, earning yield through vaults, passive yield strategies, or wants to deposit into or withdraw from a yield strategy — even if they don't say "Troves" explicitly.
trade
Swap tokens on Starknet via Fibrous DEX aggregator. Supports per-provider selection (avnu, ekubo, or auto to race all). Use this skill when the user wants to swap, exchange, trade, convert, buy, or sell one token for another on Starknet. Also use when the user asks about token prices, exchange rates, DEX routing, best swap route, or wants to check how much they would receive for a given amount — even if they don't explicitly say "swap".
staking
Stake, unstake, claim, and compound rewards for STRK, WBTC, tBTC, SolvBTC, and LBTC on Starknet. View validators, pools, and staking positions. Use this skill when the user mentions staking, delegating, validators, staking pools, rewards, compounding, unstaking, earning yield, passive income on crypto, or wants to earn on their STRK or BTC tokens — even if they don't say "stake" explicitly.
send
Send STRK, ETH, or any ERC-20 token to a Starknet address. Supports simulation (dry-run) before execution. Use this skill when the user wants to send, transfer, pay, tip, or move tokens to another wallet address on Starknet. Also trigger when the user mentions sending funds to someone, making a payment, transferring assets, or moving crypto to a specific address — even if they just say "pay 10 STRK to 0x...".
portfolio
View a comprehensive DeFi portfolio dashboard and optimize portfolio allocation via automated rebalancing. Use this skill when the user wants an overview, summary, dashboard, total value, net worth, portfolio rebalancing, target allocation, or wants to see all their DeFi positions across Starknet at once. Also trigger when the user asks "what do I have", "show me everything", "how much am I worth", "my positions", "my investments", "rebalance my portfolio", "I want 50% ETH", "optimize my holdings", or any request for a holistic view of their Starknet holdings — even if they don't explicitly say "portfolio".
multi-swap
Execute multiple token swaps in a single Starknet transaction via Fibrous (default). Supports per-provider selection (avnu, ekubo, or auto to race all). Supports 2-3 swap pairs bundled into one multicall. Use this skill when the user wants to swap multiple token pairs at once, do batch swaps, execute several trades simultaneously, perform parallel swaps, or do bulk trading in one transaction. Also trigger when the user mentions "two swaps", "three swaps", "swap X and Y at the same time", or wants to convert multiple tokens in a single call.