Elsa x402 DeFi Tools
This skill provides access to the Elsa DeFi API for portfolio management, token analysis, and swap execution using x402 micropayments.
Standard Operating Procedure
Budget Controls
- - Maximum $0.05 per API call (configurable)
- Maximum $2.00 per day (configurable)
- Maximum 30 calls per minute rate limit
- Daily budget resets at midnight in configured timezone (default: UTC)
Recommended Swap Flow (OpenClaw)
When executing swaps, follow this 4-step flow:
CODEBLOCK0
Step 1: Get Quote - Show user what they'll receive
CODEBLOCK1
Step 2: Dry Run - Create pipeline, get pipeline_id
CODEBLOCK2
Step 3: User Confirmation - Present results and wait for explicit "yes"
Step 4: Execute Pipeline - Sign and broadcast transactions
CODEBLOCK3
Required Environment Variables
CODEBLOCK4
Critical Rules
- - NEVER execute swaps without showing the user the quote first
- NEVER call execution tools in a loop
- NEVER proceed if budget limits are exceeded
- ALWAYS check
elsa_budget_status if unsure about remaining budget - ALWAYS use dry-run mode first for any swap operation
Tool Catalog
Read-Only Tools (Always Available)
elsasearchtoken
Search for tokens across supported blockchains.
CODEBLOCK5
Input:
- -
query (string, required): Token name, symbol, or address - INLINECODE3 (number, optional): Max results (default: 10)
elsagettoken_price
Get current price for a token.
CODEBLOCK6
Input:
- -
token_address (string, required): Token contract address - INLINECODE5 (string, optional): Chain name (default: "base")
elsagetbalances
Get token balances for a wallet.
CODEBLOCK7
Input:
- -
wallet_address (string, required): Wallet address to query
elsagetportfolio
Get comprehensive portfolio analysis.
CODEBLOCK8
Input:
- -
wallet_address (string, required): Wallet address to analyze
elsaanalyzewallet
Get wallet behavior and risk assessment.
CODEBLOCK9
Input:
- -
wallet_address (string, required): Wallet address to analyze
elsagetswap_quote
Get a swap quote with optimal routing.
CODEBLOCK10
Input:
- -
from_chain (string, required): Source chain - INLINECODE10 (string, required): Source token address
- INLINECODE11 (string, required): Amount to swap
- INLINECODE12 (string, required): Destination chain
- INLINECODE13 (string, required): Destination token address
- INLINECODE14 (string, required): Wallet address
- INLINECODE15 (number, required): Slippage tolerance (0-50)
elsaexecuteswapdryrun
Simulate a swap without execution. Returns a confirmation token for subsequent confirmed execution.
CODEBLOCK11
Output includes:
- - Swap simulation results
- INLINECODE16 (if ELSAREQUIRECONFIRMATIONTOKEN=true)
- Token expires after ELSACONFIRMATIONTTLSECONDS
elsabudgetstatus
Check current budget usage and remaining limits.
CODEBLOCK12
Output:
- -
spent_today_usd: Amount spent today - INLINECODE18 : Remaining daily budget
- INLINECODE19 : Recent call count
- INLINECODE20 : Recent call details
elsagetlimit_orders
Get all limit orders for a wallet.
CODEBLOCK13
Input:
- -
wallet_address (string, required): Wallet address to query - INLINECODE22 (string, optional): Chain name (default: "base")
Output:
- -
orders: Array of limit orders with status, prices, and expiry
elsagetperp_positions
Get perpetual positions for a wallet.
CODEBLOCK14
Input:
- -
wallet_address (string, required): Wallet address to query
Output:
- -
positions: Array of open perp positions with PnL, leverage, and liquidation prices - INLINECODE26 : Sum of unrealized profits/losses
- INLINECODE27 : Total margin used
elsagettransaction_history
Get transaction history for a wallet.
CODEBLOCK15
Input:
- -
wallet_address (string, required): Wallet address to query - INLINECODE29 (string, optional): Filter by chain
- INLINECODE30 (number, optional): Max results (default: 20, max: 100)
Output:
- -
transactions: Array of transactions with details, token transfers, and status
Execution Tools (Requires ELSAENABLEEXECUTION_TOOLS=true)
elsaexecuteswap_confirmed
Execute a confirmed swap. Requires prior dry-run and confirmation token.
CODEBLOCK16
elsapipelineget_status
Check status of a pipeline/transaction.
CODEBLOCK17
elsapipelinesubmittxhash
Submit a signed transaction hash to the pipeline.
CODEBLOCK18
elsapipelinerunandwait
Orchestrate full pipeline execution with automatic signing and submission.
CODEBLOCK19
Modes:
- -
local_signer: Signs and broadcasts transactions using TRADEPRIVATEKEY - INLINECODE33 : Returns unsigned tx_data for external signing
elsacreatelimit_order
Create a limit order to execute when price reaches target.
CODEBLOCK20
Input:
- -
wallet_address (string, required): Wallet address - INLINECODE35 (string, required): Chain name
- INLINECODE36 (string, required): Token to sell
- INLINECODE37 (string, required): Token to buy
- INLINECODE38 (string, required): Amount to sell
- INLINECODE39 (string, required): Target price to trigger execution
- INLINECODE40 (number, optional): Hours until order expires (default: 24, max: 720)
elsacancellimit_order
Cancel an existing limit order.
CODEBLOCK21
Input:
- -
wallet_address (string, required): Wallet address - INLINECODE42 (string, required): Order ID to cancel
- INLINECODE43 (string, optional): Chain name (default: "base")
elsaopenperp_position
Open a perpetual futures position.
CODEBLOCK22
Input:
- -
wallet_address (string, required): Wallet address - INLINECODE45 (string, required): Market pair (e.g., "ETH-USD", "BTC-USD")
- INLINECODE46 (enum, required): "long" or "short"
- INLINECODE47 (string, required): Position size in USD
- INLINECODE48 (number, optional): Leverage multiplier (default: 1, max: 100)
- INLINECODE49 (string, optional): Take profit price
- INLINECODE50 (string, optional): Stop loss price
elsacloseperp_position
Close an open perpetual position.
CODEBLOCK23
Input:
- -
wallet_address (string, required): Wallet address - INLINECODE52 (string, required): Position ID to close
- INLINECODE53 (number, optional): Percentage to close (default: 100, range: 1-100)
Supported Chains
- - base (default)
- ethereum
- arbitrum
- optimism
- polygon
- bsc
- avalanche
- zksync
API Costs
| Tool | Estimated Cost |
|---|
| elsasearchtoken | $0.002 |
| elsagettoken_price |
$0.002 |
| elsa
getbalances | $0.002 |
| elsa
getportfolio | $0.002 |
| elsa
analyzewallet | $0.005 |
| elsa
getswap_quote | $0.002 |
| elsa
executeswap
dryrun | $0.005 |
| elsa
getlimit_orders | $0.002 |
| elsa
getperp_positions | $0.002 |
| elsa
gettransaction_history | $0.002 |
| elsa
createlimit_order | $0.05 |
| elsa
cancellimit_order | $0.01 |
| elsa
openperp_position | $0.05 |
| elsa
closeperp_position | $0.05 |
| elsa
executeswap_confirmed | $0.05 |
Coming Soon
- - Polymarket APIs - Prediction market trading and data
Elsa x402 DeFi 工具
此技能提供对Elsa DeFi API的访问,用于投资组合管理、代币分析以及使用x402微支付执行兑换。
标准操作流程
预算控制
- - 每次API调用最高$0.05(可配置)
- 每日最高$2.00(可配置)
- 每分钟最多30次调用的速率限制
- 每日预算在配置时区的午夜重置(默认:UTC)
推荐兑换流程(OpenClaw)
执行兑换时,请遵循以下4步流程:
┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────┐ ┌─────────────────────┐
│ 1. 获取报价 │ ──▶ │ 2. 模拟运行 │ ──▶ │ 3. 确认 │ ──▶ │ 4. 执行流水线 │
│ elsagetswapquote │ │ elsaexecuteswap │ │ [用户说 │ │ elsapipelinerun_ │
│ │ │ dryrun │ │ 是] │ │ andwait │
└─────────────────────┘ └─────────────────────┘ └─────────────┘ └─────────────────────┘
第1步:获取报价 - 向用户展示他们将收到的内容
bash
npx tsx scripts/index.ts elsagetswap_quote {
fromchain: base, fromtoken: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913,
fromamount: 10, tochain: base, to_token: 0x4200000000000000000000000000000000000006,
wallet_address: 0x..., slippage: 0.5
}
第2步:模拟运行 - 创建流水线,获取pipeline_id
bash
npx tsx scripts/index.ts elsaexecuteswapdryrun {...相同参数...}
返回:{ pipelineid: abc-123, confirmationtoken: ... }
第3步:用户确认 - 展示结果并等待明确的是
第4步:执行流水线 - 签名并广播交易
bash
ELSAENABLEEXECUTIONTOOLS=true npx tsx scripts/index.ts elsapipelinerunand_wait {
pipeline_id: abc-123,
timeout_seconds: 180,
pollintervalseconds: 3,
mode: local_signer
}
自动:签名批准交易 → 提交 → 签名兑换交易 → 提交 → 返回交易哈希
必需的环境变量
bash
用于x402 API支付
PAYMENT
PRIVATEKEY=0x...
用于签名兑换交易(可选 - 回退到PAYMENTPRIVATEKEY)
TRADE
PRIVATEKEY=0x...
启用执行工具
ELSA
ENABLEEXECUTION_TOOLS=true
关键规则
- - 绝不在未向用户展示报价的情况下执行兑换
- 绝不在循环中调用执行工具
- 绝不在超出预算限制时继续操作
- 始终在不确定剩余预算时检查elsabudgetstatus
- 始终对任何兑换操作先使用模拟运行模式
工具目录
只读工具(始终可用)
elsasearchtoken
跨支持的区块链搜索代币。
bash
npx tsx scripts/index.ts elsasearchtoken {query: USDC, limit: 5}
输入:
- - query(字符串,必需):代币名称、符号或地址
- limit(数字,可选):最大结果数(默认:10)
elsagettoken_price
获取代币的当前价格。
bash
npx tsx scripts/index.ts elsagettokenprice {tokenaddress: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913, chain: base}
输入:
- - token_address(字符串,必需):代币合约地址
- chain(字符串,可选):链名称(默认:base)
elsagetbalances
获取钱包的代币余额。
bash
npx tsx scripts/index.ts elsagetbalances {wallet_address: 0x...}
输入:
- - wallet_address(字符串,必需):要查询的钱包地址
elsagetportfolio
获取全面的投资组合分析。
bash
npx tsx scripts/index.ts elsagetportfolio {wallet_address: 0x...}
输入:
- - wallet_address(字符串,必需):要分析的钱包地址
elsaanalyzewallet
获取钱包行为和风险评估。
bash
npx tsx scripts/index.ts elsaanalyzewallet {wallet_address: 0x...}
输入:
- - wallet_address(字符串,必需):要分析的钱包地址
elsagetswap_quote
获取具有最优路由的兑换报价。
bash
npx tsx scripts/index.ts elsagetswap_quote {
from_chain: base,
from_token: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913,
from_amount: 100,
to_chain: base,
to_token: 0x4200000000000000000000000000000000000006,
wallet_address: 0x...,
slippage: 0.5
}
输入:
- - fromchain(字符串,必需):源链
- fromtoken(字符串,必需):源代币地址
- fromamount(字符串,必需):要兑换的金额
- tochain(字符串,必需):目标链
- totoken(字符串,必需):目标代币地址
- walletaddress(字符串,必需):钱包地址
- slippage(数字,必需):滑点容忍度(0-50)
elsaexecuteswapdryrun
模拟兑换而不执行。返回一个确认令牌,用于后续的确认执行。
bash
npx tsx scripts/index.ts elsaexecuteswapdryrun {
from_chain: base,
from_token: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913,
from_amount: 100,
to_chain: base,
to_token: 0x4200000000000000000000000000000000000006,
wallet_address: 0x...,
slippage: 0.5
}
输出包括:
- - 兑换模拟结果
- confirmationtoken(如果ELSAREQUIRECONFIRMATIONTOKEN=true)
- 令牌在ELSACONFIRMATIONTTL_SECONDS后过期
elsabudgetstatus
检查当前预算使用情况和剩余限制。
bash
npx tsx scripts/index.ts elsabudgetstatus {}
输出:
- - spenttodayusd:今日已花费金额
- remainingtodayusd:剩余每日预算
- callslastminute:最近调用次数
- last_calls:最近调用详情
elsagetlimit_orders
获取钱包的所有限价订单。
bash
npx tsx scripts/index.ts elsagetlimitorders {walletaddress: 0x..., chain: base}
输入:
- - wallet_address(字符串,必需):要查询的钱包地址
- chain(字符串,可选):链名称(默认:base)
输出:
- - orders:限价订单数组,包含状态、价格和到期时间
elsagetperp_positions
获取钱包的永续合约持仓。
bash
npx tsx scripts/index.ts elsagetperppositions {walletaddress: 0x...}
输入:
- - wallet_address(字符串,必需):要查询的钱包地址
输出:
- - positions:未平仓永续持仓数组,包含盈亏、杠杆和清算价格
- totalunrealizedpnl:未实现盈亏总和
- total_margin:使用的总保证金
elsagettransaction_history
获取钱包的交易历史。
bash
npx tsx scripts/index.ts