1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// Clap argument definitions for the AgentSwap binary.
// Exports: Cli and Commands.
// Deps: clap derive macros.
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(
name = "agentswap",
version,
about = "AgentSwap CLI — AI-agent-optimized DEX aggregator"
)]
pub struct Cli {
/// Output raw JSON instead of formatted tables
#[arg(short, long, global = true)]
pub json: bool,
/// AgentSwap service URL
#[arg(
short,
long,
global = true,
env = "AGENTSWAP_URL",
default_value = "https://api.agentswap.co"
)]
pub url: String,
/// API key for authenticated endpoints
#[arg(short = 'k', long, global = true, env = "SR_API_KEY")]
pub api_key: Option<String>,
/// Local signer key file for trade/MCP signing
#[arg(long, global = true, env = "AGENTSWAP_KEY_FILE")]
pub key_file: Option<String>,
/// Enable x402 paid retry flow
#[arg(long, global = true, env = "AGENTSWAP_X402")]
pub x402: bool,
/// Prefer x402 even when an API key is configured
#[arg(long, global = true)]
pub prefer_x402: bool,
/// Local key file used for x402 EIP-3009 signatures
#[arg(long, global = true, env = "AGENTSWAP_X402_KEY_FILE")]
pub x402_key_file: Option<String>,
/// x402 chain ID
#[arg(long, global = true, env = "AGENTSWAP_X402_CHAIN", default_value_t = 8453)]
pub x402_chain: u64,
/// Maximum x402 payment amount as unsigned decimal digits in raw token units
#[arg(long, global = true, env = "AGENTSWAP_X402_MAX_AMOUNT", default_value = "0")]
pub x402_max_amount: String,
/// x402 asset symbol or address selector
#[arg(long, global = true, env = "AGENTSWAP_X402_ASSET", default_value = "USDC")]
pub x402_asset: String,
/// Allow trade execution; otherwise trade is forced to dry-run
#[arg(long, global = true)]
pub allow_trade: bool,
/// Per-trade cap on amountIn as unsigned decimal digits in raw token units; refuses to sign/self-submit above it. Also bounds MCP trades.
#[arg(long = "max-amount", global = true, env = "AGENTSWAP_TRADE_MAX_AMOUNT")]
pub trade_max_amount: Option<String>,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
/// Get quotes for multiple token pairs at once
BatchQuote {
#[arg(short, long)]
chain: String,
#[arg(required = true)]
pairs: Vec<String>,
/// Unsigned decimal amount in the input token's smallest unit.
#[arg(short, long)]
amount: String,
},
/// List supported chains and DEX info
Chains,
/// Show wallet call instructions for buying API quota
BuyQuota {
#[arg(short, long)]
chain: String,
#[arg(short, long)]
token: String,
/// Unsigned decimal amount in the input token's smallest unit.
#[arg(short, long)]
amount: String,
},
/// Get a swap quote
Quote {
#[arg(short, long)]
chain: String,
#[arg(short, long)]
from: String,
#[arg(short, long)]
to: String,
/// Unsigned decimal amount in the input token's smallest unit.
#[arg(short, long)]
amount: String,
#[arg(short, long)]
slippage: Option<u16>,
#[arg(long)]
verify: bool,
},
/// Check service health
Health,
/// Show API key status, quota, and usage
KeyInfo,
/// List supported tokens
Tokens {
#[arg(short, long)]
chain: Option<String>,
},
/// Inspect a specific pool
Pools {
#[arg(short, long)]
chain: String,
#[arg(short, long)]
address: String,
},
/// Register a new API key via wallet signature
Register {
#[arg(long)]
address: String,
#[arg(long)]
private_key: Option<String>,
#[arg(long)]
key_file: Option<String>,
},
/// Show quote pricing + quota purchase contract mapping
Pricing,
/// Claim purchased API quote quota using an on-chain tx hash
QuotaClaim {
#[arg(short, long)]
chain: String,
#[arg(long)]
tx_hash: String,
},
/// Explain a saved quote route by hash
RouteExplain {
#[arg(long)]
hash: String,
},
/// Run an MCP server over stdio
Mcp,
/// Place, list, or inspect V6 open intents
Intent {
#[command(subcommand)]
command: IntentCommands,
},
/// Show the V6 policy and token budgets for an agent
Policy {
#[arg(short, long)]
chain: String,
#[arg(long)]
owner: String,
#[arg(long)]
agent: String,
#[arg(long)]
lookback_blocks: Option<u64>,
#[arg(long = "token")]
tokens: Vec<String>,
},
/// Quote and sign an agent order, optionally self-submitting it; dry-run requires a reachable RPC and deployed V6 proxy to verify policy and order hashes before signing
Trade {
#[arg(short, long)]
chain: String,
#[arg(short, long)]
from: String,
#[arg(short, long)]
to: String,
/// Unsigned decimal amount in the input token's smallest unit.
#[arg(short, long)]
amount: String,
#[arg(short, long)]
slippage: Option<u16>,
/// Optional unsigned decimal minimum output in raw token units.
#[arg(long)]
min_out: Option<String>,
#[arg(long, default_value = "agent-order")]
mode: String,
#[arg(long, env = "AGENTSWAP_PROXY")]
proxy: String,
#[arg(long)]
nonce: Option<String>,
#[arg(long, default_value_t = 120)]
deadline_secs: u64,
#[arg(long)]
dry_run: bool,
#[arg(long)]
self_submit: bool,
#[arg(long)]
key_file: Option<String>,
},
}
#[derive(Subcommand)]
pub enum IntentCommands {
/// Sign and announce an agent-placed open intent
Place {
#[arg(short, long)]
chain: String,
#[arg(long)]
proxy_owner: String,
#[arg(short, long)]
from: String,
#[arg(short, long)]
to: String,
/// Unsigned decimal input amount in the token's smallest unit.
#[arg(short, long)]
amount: String,
/// Unsigned decimal starting output in the token's smallest unit.
#[arg(long)]
start_out: String,
/// Unsigned decimal ending output in the token's smallest unit.
#[arg(long)]
end_out: String,
#[arg(long)]
decay_secs: Option<u64>,
#[arg(long)]
duration_secs: Option<u64>,
#[arg(long)]
deadline_secs: Option<u64>,
#[arg(long)]
relay: bool,
#[arg(long)]
self_submit: bool,
#[arg(long)]
dry_run: bool,
},
/// List announced intents by owner or agent
List {
#[arg(short, long)]
chain: String,
#[arg(long, conflicts_with = "agent", required_unless_present = "agent")]
owner: Option<String>,
#[arg(long, conflicts_with = "owner", required_unless_present = "owner")]
agent: Option<String>,
#[arg(long)]
lookback_blocks: Option<u64>,
},
/// Inspect an announced intent by bytes32 id
Status {
#[arg(short, long)]
chain: String,
#[arg(long)]
id: String,
#[arg(long)]
lookback_blocks: Option<u64>,
},
}