swap-build
This skill should be used when the user asks to "build a swap", "prepare swap transaction", "get swap calldata", or wants to create a transaction for a token trade. Builds full swap transaction with calldata from OpenOcean Aggregator.
- License 许可
- AGPL-3.0
- 最近更新
- 2026-11-15
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- swap-build
- metadata
- { "tags": [ "defi", "openocean", "swap", "transaction", "evm", "aggregator" ], "homepage": "https://openocean.finance", "provider": "OpenOcean" }
- description
- This skill should be used when the user asks to "build a swap", "prepare swap transaction", "get swap calldata", or wants to create a transaction for a token trade. Builds full swap transaction with calldata from OpenOcean Aggregator.
03 SKILL.md 正文
OpenOcean Swap Build Skill
Build a complete swap transaction with calldata using the OpenOcean aggregator. Given a token pair, amount, and sender address, fetch the best route and prepare the data required for on-chain execution.
Read Before Execution (Agent Checklist)
- Paths: Resolve reference files with glob first (do not read fixed paths first).
- Run:
**/token-registry.mdand**/api-reference.md. - Use the unique matched path and continue.
- Report error only when no unique match exists.
- Run:
- API: Use mcp_web_fetch to call the
gasPriceandswapendpoints. Theswaprequest must includeaccount={sender}in order to receive calldata. - Slippage: A user may say
slippage 100to mean 1% (100 bps). The API expects a percentage value, where1 = 1%. Convert withslippage_api = slippage_bps / 100. - Amount:
amountDecimalsmust be an integer string with no scientific notation. - Chain Normalization: Normalize user chain names to OpenOcean-supported
Chain Codebefore calling APIs (for exampleethereum->eth), or keep numeric chain ID as-is.
Input Parsing
The user will provide input like:
100 USDC to ETH on arbitrum from 0xYourAddress1 ETH to USDC on ethereum from 0xYourAddress slippage 1000.5 WBTC to DAI on polygon from 0xYourAddress
Extract these fields:
- amount — the human-readable amount to swap
- tokenIn — the input token symbol
- tokenOut — the output token symbol
- chain — the chain slug or ID
- sender — the sender wallet address (after "from")
- slippage — optional, in basis points (default: 100 = 1%). Convert it to a percentage before sending it to the API:
slippage_api = slippage_bps / 100.
Workflow
Step 1: Resolve Token Addresses
Read the token registry at references/token-registry.md.
Look up tokenIn and tokenOut for the specified chain. Match case-insensitively. Note the decimals for each token.
Native Token Address: For native tokens (ETH, BNB, MATIC, etc.), use:
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
If a token is not found in the registry:
Follow the fallback sequence in references/token-registry.md.
Step 2: Get Current Gas Price
Fetch current gas price:
GET https://open-api.openocean.finance/v4/:chain/gasPrice
Use the standard gas price from the response. Values in data are already in wei (use data.standard.legacyGasPrice or data.standard on non-Ethereum chains); pass them directly as gasPriceDecimals to swap.
Step 3: Convert Amount to Wei
amountInWei = amount * 10^(tokenIn decimals)
Use deterministic conversion:
python3 -c "print(int(AMOUNT * 10**DECIMALS))"
Step 4: Call the Swap API (GET request)
Use mcp_web_fetch with this URL format:
https://open-api.openocean.finance/v4/{chain}/swap?inTokenAddress={tokenInAddress}&outTokenAddress={tokenOutAddress}&amountDecimals={amountInWei}&gasPriceDecimals={gasPriceWei}&slippage={slippage_api}&account={sender}
slippage_api: percentage value from 0.05 to 50, where1 = 1%. If the user saysslippage 100, pass1; if they sayslippage 50, pass0.5.account: the user's wallet address. This field is required in order to receive calldata.
Step 5: Verify Response
Check code = 200 and ensure data.data field exists (contains calldata).
If code is not 200, handle the error according to the error-handling skill.
Step 6: Present Quote Details for Confirmation
Before returning calldata, show the user:
## OpenOcean Swap Build - Review Before Proceeding
**{amount} {tokenIn} → {minOutAmount} {tokenOut}** on {Chain}
| Detail | Value |
|---|---|
| Input | {amount} {tokenIn} (~${amountInUsd}) |
| Expected Output | {outAmount} {tokenOut} (~${amountOutUsd}) |
| Minimum Output | {minOutAmount} {tokenOut} (after {slippage}% slippage) |
| Gas estimate | {estimatedGas} units |
| Gas price | {gasPrice} wei (display in Gwei as gasPrice ÷ 10^9) |
| Price impact | {price_impact} |
| Router | `{to}` |
### Transaction Details
- **To**: `{to}` (OpenOcean router)
- **Value**: {value} wei (0 for ERC-20, >0 for native token)
- **Chain ID**: {chainId}
- **From**: `{from}`
⚠️ **Important:**
1. This builds the transaction but does NOT execute it
2. Minimum output is protected by contract
3. Gas costs are estimates only
4. Prices may change before execution
Do you want to proceed with building this swap? (Yes/No)
Step 7: If User Confirms, Return Calldata
If user confirms "Yes", return the complete transaction data:
## OpenOcean Swap Transaction Built
Transaction data ready for signing and broadcasting.
### Raw Transaction
```json
{
"from": "{from}",
"to": "{to}",
"value": "{value}",
"data": "{data}",
"gas": "{estimatedGas}",
"gasPrice": "{gasPrice}",
"chainId": {chainId}
}
Calldata (for manual construction)
Data: {data}
Next Steps
- Sign this transaction with your wallet
- Broadcast to the network
- Or use
/swap-executeto execute directly (requires Foundry)
Transaction hash will be available after broadcasting.
### Step 8: If User Declines, Cancel
If user says "No" or cancels:
Swap Build Cancelled
No transaction data was generated. You can:
- Adjust parameters and try again
- Use
/quoteto check prices first - Contact support if you have questions
## Important Notes
### Safety Checks
1. **Slippage Protection**: Minimum output is enforced by contract
2. **Gas Estimates**: Are estimates only, actual may vary
3. **Price Validity**: Quotes expire quickly, execute promptly
4. **Token Approvals**: ERC-20 tokens require approval before swapping
### Parameter Guidelines
- **Slippage:**
- 0.1% (10 bps) for stablecoin ↔ stablecoin
- 0.5% (50 bps) for common pairs
- 1-2% (100-200 bps) for volatile tokens
- **Gas Price**: Use current market rates from gasPrice endpoint. For the built transaction, use **data.gasPrice from the swap response** (wei) so the tx matches the quote. When displaying, gas price in Gwei = gasPrice ÷ 10^9 (never use the wei value as Gwei).
- **Deadline**: OpenOcean uses default 20-minute deadline
### Native vs ERC-20
- **Native token input**: `value` > 0, no approval needed
- **ERC-20 input**: `value` = 0, approval required before swap
- **Always check**: Token approvals before attempting swap
## Error Handling
Common issues:
1. **Insufficient Balance**: Check user has enough tokenIn + gas
2. **Insufficient Allowance**: ERC-20 needs approval first
3. **Rate Limited**: Wait and retry
4. **No Route**: Token pair may have no liquidity
For detailed error codes, see `skills/error-handling/SKILL.md`.
## Example Usage
/swap-build 1 ETH to USDC on ethereum from 0x742d35Cc6634C0532925a3b844Bc9e90F1b6fB28 slippage 50
This will:
1. Get ETH → USDC quote on Ethereum
2. Show details for confirmation
3. If confirmed, return transaction calldata
4. User can then sign and broadcast
## Next Steps After Build
After getting calldata, user can:
1. **Manual Execution**: Sign and broadcast using their wallet
2. **`/swap-execute`**: Use Foundry cast to execute (requires setup)
3. **`/swap-execute-fast`**: Build and execute in one step (dangerous)
**Remember**: Built transactions are not submitted until they are broadcast on-chain.
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.