@intent-engine/cli 0.1.23 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/assets/viperjs-judge.sha256 +1 -0
  2. package/assets/viperjs-judge.wasm +0 -0
  3. package/dist/src/admin-commands.d.ts +13 -0
  4. package/dist/src/admin-commands.js +185 -0
  5. package/dist/src/admin-commands.js.map +1 -0
  6. package/dist/src/agent/actions.d.ts +2 -0
  7. package/dist/src/agent/actions.js +1 -1
  8. package/dist/src/agent/actions.js.map +1 -1
  9. package/dist/src/agent/claims.js +13 -12
  10. package/dist/src/agent/claims.js.map +1 -1
  11. package/dist/src/agent/create.d.ts +1 -0
  12. package/dist/src/agent/create.js +9 -3
  13. package/dist/src/agent/create.js.map +1 -1
  14. package/dist/src/agent/mandate-agent.d.ts +2 -0
  15. package/dist/src/agent/mandate-agent.js +138 -0
  16. package/dist/src/agent/mandate-agent.js.map +1 -0
  17. package/dist/src/agent/mandate-grant.d.ts +2 -0
  18. package/dist/src/agent/mandate-grant.js +192 -0
  19. package/dist/src/agent/mandate-grant.js.map +1 -0
  20. package/dist/src/agent/mandate-revoke.d.ts +1 -0
  21. package/dist/src/agent/mandate-revoke.js +142 -0
  22. package/dist/src/agent/mandate-revoke.js.map +1 -0
  23. package/dist/src/agent/mandate-state.d.ts +33 -0
  24. package/dist/src/agent/mandate-state.js +85 -0
  25. package/dist/src/agent/mandate-state.js.map +1 -0
  26. package/dist/src/agent/mandate.d.ts +4 -26
  27. package/dist/src/agent/mandate.js +4 -479
  28. package/dist/src/agent/mandate.js.map +1 -1
  29. package/dist/src/agent/mcp.js +9 -3
  30. package/dist/src/agent/mcp.js.map +1 -1
  31. package/dist/src/agent/prepare.js +1 -1
  32. package/dist/src/agent/prepare.js.map +1 -1
  33. package/dist/src/agent/problems.d.ts +28 -1
  34. package/dist/src/agent/problems.js +47 -1
  35. package/dist/src/agent/problems.js.map +1 -1
  36. package/dist/src/agent/read.d.ts +12 -0
  37. package/dist/src/agent/read.js +20 -6
  38. package/dist/src/agent/read.js.map +1 -1
  39. package/dist/src/agent/registry.js +8 -1
  40. package/dist/src/agent/registry.js.map +1 -1
  41. package/dist/src/agent/relay.d.ts +2 -0
  42. package/dist/src/agent/relay.js +11 -3
  43. package/dist/src/agent/relay.js.map +1 -1
  44. package/dist/src/agent/reputation.d.ts +4 -0
  45. package/dist/src/agent/reputation.js +127 -0
  46. package/dist/src/agent/reputation.js.map +1 -0
  47. package/dist/src/agent/sales.d.ts +29 -0
  48. package/dist/src/agent/sales.js +248 -0
  49. package/dist/src/agent/sales.js.map +1 -0
  50. package/dist/src/agent/signed-prepare.d.ts +1 -0
  51. package/dist/src/agent/signed-prepare.js +138 -0
  52. package/dist/src/agent/signed-prepare.js.map +1 -0
  53. package/dist/src/agent/signed-relay.d.ts +25 -0
  54. package/dist/src/agent/signed-relay.js +69 -0
  55. package/dist/src/agent/signed-relay.js.map +1 -0
  56. package/dist/src/agent/signed-submit.d.ts +2 -0
  57. package/dist/src/agent/signed-submit.js +137 -0
  58. package/dist/src/agent/signed-submit.js.map +1 -0
  59. package/dist/src/agent/signed-terms.d.ts +85 -0
  60. package/dist/src/agent/signed-terms.js +84 -0
  61. package/dist/src/agent/signed-terms.js.map +1 -0
  62. package/dist/src/agent/signed.d.ts +4 -13
  63. package/dist/src/agent/signed.js +4 -361
  64. package/dist/src/agent/signed.js.map +1 -1
  65. package/dist/src/agent/wallet/account.d.ts +4 -0
  66. package/dist/src/agent/wallet/account.js +84 -0
  67. package/dist/src/agent/wallet/account.js.map +1 -0
  68. package/dist/src/agent/wallet/attest.d.ts +4 -0
  69. package/dist/src/agent/wallet/attest.js +178 -0
  70. package/dist/src/agent/wallet/attest.js.map +1 -0
  71. package/dist/src/agent/wallet/committee.d.ts +4 -0
  72. package/dist/src/agent/wallet/committee.js +155 -0
  73. package/dist/src/agent/wallet/committee.js.map +1 -0
  74. package/dist/src/agent/wallet/delivery.d.ts +13 -0
  75. package/dist/src/agent/wallet/delivery.js +171 -0
  76. package/dist/src/agent/wallet/delivery.js.map +1 -0
  77. package/dist/src/agent/wallet/escrow.d.ts +7 -0
  78. package/dist/src/agent/wallet/escrow.js +164 -0
  79. package/dist/src/agent/wallet/escrow.js.map +1 -0
  80. package/dist/src/agent/wallet/fills.d.ts +27 -0
  81. package/dist/src/agent/wallet/fills.js +80 -0
  82. package/dist/src/agent/wallet/fills.js.map +1 -0
  83. package/dist/src/agent/wallet/guard.d.ts +57 -0
  84. package/dist/src/agent/wallet/guard.js +205 -0
  85. package/dist/src/agent/wallet/guard.js.map +1 -0
  86. package/dist/src/agent/wallet/offer.d.ts +50 -0
  87. package/dist/src/agent/wallet/offer.js +80 -0
  88. package/dist/src/agent/wallet/offer.js.map +1 -0
  89. package/dist/src/agent/wallet/receipt.d.ts +42 -0
  90. package/dist/src/agent/wallet/receipt.js +102 -0
  91. package/dist/src/agent/wallet/receipt.js.map +1 -0
  92. package/dist/src/agent/wallet/record.d.ts +31 -0
  93. package/dist/src/agent/wallet/record.js +178 -0
  94. package/dist/src/agent/wallet/record.js.map +1 -0
  95. package/dist/src/agent/wallet/releases.d.ts +40 -0
  96. package/dist/src/agent/wallet/releases.js +245 -0
  97. package/dist/src/agent/wallet/releases.js.map +1 -0
  98. package/dist/src/agent/wallet/split.d.ts +10 -0
  99. package/dist/src/agent/wallet/split.js +271 -0
  100. package/dist/src/agent/wallet/split.js.map +1 -0
  101. package/dist/src/agent/wallet/trade.d.ts +14 -0
  102. package/dist/src/agent/wallet/trade.js +243 -0
  103. package/dist/src/agent/wallet/trade.js.map +1 -0
  104. package/dist/src/agent/wallet/wait.d.ts +5 -0
  105. package/dist/src/agent/wallet/wait.js +99 -0
  106. package/dist/src/agent/wallet/wait.js.map +1 -0
  107. package/dist/src/agent/wallet.d.ts +19 -73
  108. package/dist/src/agent/wallet.js +30 -1322
  109. package/dist/src/agent/wallet.js.map +1 -1
  110. package/dist/src/arg-options.d.ts +405 -0
  111. package/dist/src/arg-options.js +361 -0
  112. package/dist/src/arg-options.js.map +1 -0
  113. package/dist/src/arg-usage.d.ts +7 -0
  114. package/dist/src/arg-usage.js +60 -0
  115. package/dist/src/arg-usage.js.map +1 -0
  116. package/dist/src/arg-values.d.ts +47 -0
  117. package/dist/src/arg-values.js +284 -0
  118. package/dist/src/arg-values.js.map +1 -0
  119. package/dist/src/args.d.ts +7 -545
  120. package/dist/src/args.js +103 -926
  121. package/dist/src/args.js.map +1 -1
  122. package/dist/src/artifact.d.ts +28 -0
  123. package/dist/src/artifact.js +103 -0
  124. package/dist/src/artifact.js.map +1 -0
  125. package/dist/src/check-process.d.ts +46 -0
  126. package/dist/src/check-process.js +416 -0
  127. package/dist/src/check-process.js.map +1 -0
  128. package/dist/src/command-builders.d.ts +37 -0
  129. package/dist/src/command-builders.js +216 -0
  130. package/dist/src/command-builders.js.map +1 -0
  131. package/dist/src/command-types.d.ts +285 -0
  132. package/dist/src/command-types.js +2 -0
  133. package/dist/src/command-types.js.map +1 -0
  134. package/dist/src/commands.d.ts +7 -43
  135. package/dist/src/commands.js +76 -457
  136. package/dist/src/commands.js.map +1 -1
  137. package/dist/src/committee-commands.d.ts +31 -0
  138. package/dist/src/committee-commands.js +167 -0
  139. package/dist/src/committee-commands.js.map +1 -0
  140. package/dist/src/event-feed.d.ts +13 -0
  141. package/dist/src/event-feed.js +46 -0
  142. package/dist/src/event-feed.js.map +1 -0
  143. package/dist/src/flow-commands.d.ts +8 -0
  144. package/dist/src/flow-commands.js +116 -0
  145. package/dist/src/flow-commands.js.map +1 -0
  146. package/dist/src/flows.d.ts +6 -0
  147. package/dist/src/flows.js +84 -10
  148. package/dist/src/flows.js.map +1 -1
  149. package/dist/src/host-judge.d.ts +11 -0
  150. package/dist/src/host-judge.js +120 -0
  151. package/dist/src/host-judge.js.map +1 -0
  152. package/dist/src/job-commands.d.ts +9 -0
  153. package/dist/src/job-commands.js +89 -0
  154. package/dist/src/job-commands.js.map +1 -0
  155. package/dist/src/judge-errors.d.ts +12 -0
  156. package/dist/src/judge-errors.js +16 -0
  157. package/dist/src/judge-errors.js.map +1 -0
  158. package/dist/src/judge.d.ts +25 -16
  159. package/dist/src/judge.js +179 -103
  160. package/dist/src/judge.js.map +1 -1
  161. package/dist/src/main.d.ts +5 -1
  162. package/dist/src/main.js +36 -9
  163. package/dist/src/main.js.map +1 -1
  164. package/dist/src/monitor-args.d.ts +11 -0
  165. package/dist/src/monitor-args.js +58 -0
  166. package/dist/src/monitor-args.js.map +1 -0
  167. package/dist/src/monitor-fills.d.ts +13 -0
  168. package/dist/src/monitor-fills.js +56 -0
  169. package/dist/src/monitor-fills.js.map +1 -0
  170. package/dist/src/monitor.d.ts +60 -0
  171. package/dist/src/monitor.js +295 -0
  172. package/dist/src/monitor.js.map +1 -0
  173. package/dist/src/order-builders.d.ts +10 -0
  174. package/dist/src/order-builders.js +172 -0
  175. package/dist/src/order-builders.js.map +1 -0
  176. package/dist/src/render.d.ts +1 -0
  177. package/dist/src/render.js +9 -0
  178. package/dist/src/render.js.map +1 -1
  179. package/dist/src/reputation-commands.d.ts +8 -0
  180. package/dist/src/reputation-commands.js +20 -0
  181. package/dist/src/reputation-commands.js.map +1 -0
  182. package/dist/src/runtime.d.ts +22 -0
  183. package/dist/src/runtime.js +2 -0
  184. package/dist/src/runtime.js.map +1 -0
  185. package/dist/src/sandbox.d.ts +46 -0
  186. package/dist/src/sandbox.js +142 -0
  187. package/dist/src/sandbox.js.map +1 -0
  188. package/dist/src/solve-commands.d.ts +25 -0
  189. package/dist/src/solve-commands.js +175 -0
  190. package/dist/src/solve-commands.js.map +1 -0
  191. package/dist/src/tokens.js +2 -1
  192. package/dist/src/tokens.js.map +1 -1
  193. package/dist/src/trust-args.d.ts +6 -0
  194. package/dist/src/trust-args.js +76 -0
  195. package/dist/src/trust-args.js.map +1 -0
  196. package/dist/src/version.d.ts +1 -1
  197. package/dist/src/version.js +1 -1
  198. package/dist/src/viper.d.ts +66 -0
  199. package/dist/src/viper.js +282 -0
  200. package/dist/src/viper.js.map +1 -0
  201. package/dist/src/wallet.d.ts +4 -1
  202. package/dist/src/wallet.js +25 -5
  203. package/dist/src/wallet.js.map +1 -1
  204. package/package.json +18 -7
  205. package/dist/src/events.d.ts +0 -8
  206. package/dist/src/events.js +0 -43
  207. package/dist/src/events.js.map +0 -1
  208. package/dist/src/transport.d.ts +0 -208
  209. package/dist/src/transport.js +0 -441
  210. package/dist/src/transport.js.map +0 -1
package/dist/src/args.js CHANGED
@@ -1,11 +1,22 @@
1
1
  import { parseArgs } from "node:util";
2
- import { MAX_PRIORITY_PRICE } from "./compute.js";
3
- import { MAX_EXPIRES_IN } from "./agent/create.js";
4
- import { MANDATE_KIND_NAMES } from "./agent/mandate.js";
2
+ import { AUTO_PRICE_CAP } from "./compute.js";
5
3
  import { MAX_SUBMIT_WITHIN } from "./agent/signed.js";
6
- import { DEVNET_URL, tokenNamed } from "./tokens.js";
7
- import { address } from "@solana/kit";
8
- import { I64_MAX, I64_MIN, isMemoUrl, Kind, kindBit, MAX_PARTNER_BPS, MEMO_URL_RULE, TOKEN_AMOUNT_PATTERN, U64_MAX, } from "@intent-engine/core";
4
+ import { DEVNET_URL } from "./tokens.js";
5
+ import { ACCEPTS, OPTIONS } from "./arg-options.js";
6
+ import { addressList, amountOf, https, key, memoUrlOf, mintList, named, noRepeats, noSub, onlyAccepted, optionalField, outputOf, parseAddress, parseBounded, parseFeeBps, parseI64, parseKindFees, parseKinds, parseLimit, parseMaxRent, parsePause, parsePriority, parseSolCost, required, sha256Of, u64, unitsOf, UsageError, } from "./arg-values.js";
7
+ import { agentSpec, authorityOf, configChange, JUDGE_TIMEOUT, market, MAX_JUDGE_TIMEOUT, maxPagesOf, profitFloors, relaySpec, releaseOption, runOf, solveFeeAboveCap, treasury, walletLimits, } from "./command-builders.js";
8
+ import { createTerms, mandate, terms } from "./order-builders.js";
9
+ import { USAGE } from "./arg-usage.js";
10
+ import { sandboxOf } from "./sandbox.js";
11
+ import { committeeOf, feedbackOf, reputationOf } from "./trust-args.js";
12
+ import { monitorOf } from "./monitor-args.js";
13
+ import { DEFAULT_MAX_RENT, DEFAULT_MAX_SOL_COST } from "@intent-engine/solver";
14
+ import { MIN_CAP_WINDOW_SECS } from "@intent-engine/core";
15
+ export { ACCEPTS, GLOBAL_OPTIONS, SUB_ACCEPTS, TOKEN_SIDES } from "./arg-options.js";
16
+ export { COMMANDS, SHAPES, USAGE, usageOf } from "./arg-usage.js";
17
+ export { MAX_EVENT_LIMIT, MAX_RENT_FORMAT, MAX_SOL_COST_FORMAT, outputOf, parseFeeBps, parseI64, parseKinds, parseLimit, parseMaxRent, parsePause, parsePriority, parseSolCost, parseU64, SHA256_NEEDED, UsageError, } from "./arg-values.js";
18
+ export { expiry, MANDATE_USE_KINDS, needsSpecHash, order, SPEC_HASH_FORMAT } from "./order-builders.js";
19
+ export { AGENT_DEFAULT_HOURLY_LAMPORTS, AGENT_NEEDS_OWNERS, ISSUE_ALONE, ISSUE_FORMAT, JUDGE_TIMEOUT, MAX_DELIVERY_PAGES, MAX_JUDGE_TIMEOUT, ONE_MARKET, RELAY_DEFAULT_HOURLY_LAMPORTS, RELAY_DEFAULT_TTL, RELAY_MAX_TTL, RELAY_NEEDS_FEES, RELEASE_NEEDED, RUN_NEEDED, solveFeeAboveCap, TREASURY_CREATE_NEEDS_MINTS, WALLET_LIMITS_NEED_WALLET, zeroProfit, } from "./command-builders.js";
9
20
  export const DEFAULT_URL = "http://127.0.0.1:8899";
10
21
  export const CLUSTERS = {
11
22
  localnet: DEFAULT_URL,
@@ -18,923 +29,11 @@ export const ENV_KEYPAIR = "INTENT_ENGINE_KEYPAIR";
18
29
  const SETUP_CLUSTER = "devnet";
19
30
  export const WALLET_NOT_MAINNET = "mcp --wallet keeps its key in a file on this machine, so it serves devnet, testnet and localnet only";
20
31
  const BALANCE_OF_ONE = "balance takes --keypair or --owner, not both";
21
- export const GLOBAL_OPTIONS = ["output", "help"];
22
- export class UsageError extends Error {
23
- }
24
- export const RELAY_NEEDS_FEES = "--relayer needs --relay-fee naming every input token it relays as mint=amount; amount may be 0, and other tokens are refused";
25
- export const AGENT_NEEDS_OWNERS = "--agent needs --agent-owners naming every owner whose mandates this agent key may use";
26
- export const RELAY_DEFAULT_TTL = 24 * 60 * 60;
27
- export const RELAY_DEFAULT_HOURLY_LAMPORTS = 100000000n;
28
- export const AGENT_DEFAULT_HOURLY_LAMPORTS = 50000000n;
29
- export const RELAY_MAX_TTL = 365 * 24 * 60 * 60;
30
- const RELAY_DEFAULT_PER_HOUR = 10;
31
- const RELAY_MIN_TTL = 60;
32
- export const TOKEN_SIDES = {
33
- "amount-in": "input",
34
- make: "input",
35
- "per-intent": "input",
36
- total: "input",
37
- "agent-fee": "input",
38
- "floor-in": "input",
39
- "relayer-fee": "input",
40
- amount: "input",
41
- "min-out": "output",
42
- take: "output",
43
- "start-out": "output",
44
- "end-out": "output",
45
- "floor-out": "output",
46
- };
47
- const OPTIONS = {
48
- url: { type: "string" },
49
- keypair: { type: "string" },
50
- relayer: { type: "string" },
51
- agent: { type: "string" },
52
- wallet: { type: "boolean" },
53
- "wallet-per-trade": { type: "string" },
54
- "wallet-per-hour": { type: "string" },
55
- "relay-max-lamports": { type: "string" },
56
- "relay-max-ttl": { type: "string" },
57
- "relay-per-hour": { type: "string" },
58
- "relay-hourly-lamports": { type: "string" },
59
- "relay-fee": { type: "string" },
60
- "priority-fee": { type: "string" },
61
- authority: { type: "string" },
62
- "fill-disabled": { type: "string" },
63
- "new-admin": { type: "string" },
64
- "agent-hourly-lamports": { type: "string" },
65
- "agent-owners": { type: "string" },
66
- owner: { type: "string" },
67
- nonce: { type: "string" },
68
- at: { type: "string" },
69
- base: { type: "string" },
70
- "input-mint": { type: "string" },
71
- "output-mint": { type: "string" },
72
- "expires-at": { type: "string" },
73
- "amount-in": { type: "string" },
74
- "min-out": { type: "string" },
75
- make: { type: "string" },
76
- take: { type: "string" },
77
- guardian: { type: "string" },
78
- "fee-recipient": { type: "string" },
79
- "fee-bps": { type: "string" },
80
- kinds: { type: "string" },
81
- flags: { type: "string" },
82
- "dry-run": { type: "boolean" },
83
- yes: { type: "boolean" },
84
- help: { type: "boolean" },
85
- version: { type: "boolean" },
86
- follow: { type: "boolean" },
87
- watch: { type: "boolean" },
88
- output: { type: "string" },
89
- interval: { type: "string" },
90
- "expires-in": { type: "string" },
91
- "start-out": { type: "string" },
92
- "end-out": { type: "string" },
93
- "start-at": { type: "string" },
94
- "end-at": { type: "string" },
95
- "min-result": { type: "string" },
96
- "max-result": { type: "string" },
97
- attestor: { type: "string" },
98
- "per-intent": { type: "string" },
99
- total: { type: "string" },
100
- "max-intents": { type: "string" },
101
- "max-ttl": { type: "string" },
102
- "valid-for": { type: "string" },
103
- "floor-out": { type: "string" },
104
- "floor-in": { type: "string" },
105
- "agent-fee": { type: "string" },
106
- id: { type: "string" },
107
- mint: { type: "string" },
108
- amount: { type: "string" },
109
- out: { type: "string" },
110
- file: { type: "string" },
111
- "submit-within": { type: "string" },
112
- "relayer-fee": { type: "string" },
113
- units: { type: "string" },
114
- "fund-accounts": { type: "boolean" },
115
- limit: { type: "string" },
116
- bounty: { type: "string" },
117
- "create-fee": { type: "string" },
118
- "kind-fees": { type: "string" },
119
- "partner-cut": { type: "string" },
120
- partner: { type: "string" },
121
- jupiter: { type: "string" },
122
- jito: { type: "string" },
123
- tip: { type: "string" },
124
- "min-profit": { type: "string" },
125
- issue: { type: "string" },
126
- "max-fee-bps": { type: "string" },
127
- "slippage-bps": { type: "string" },
128
- "route-program": { type: "string" },
129
- "lookup-table": { type: "string" },
130
- solver: { type: "string" },
131
- "partner-bps": { type: "string" },
132
- mints: { type: "string" },
133
- create: { type: "boolean" },
134
- intent: { type: "string" },
135
- sha256: { type: "string" },
136
- "work-url": { type: "string" },
137
- spec: { type: "string" },
138
- artifact: { type: "string" },
139
- run: { type: "string" },
140
- "pay-to": { type: "string" },
141
- timeout: { type: "string" },
142
- verdict: { type: "string" },
143
- };
144
- const KIND_NAMES = {
145
- swap: Kind.SwapExactIn,
146
- limit: Kind.LimitOrder,
147
- dutch: Kind.DutchAuction,
148
- attested: Kind.AttestedResult,
149
- };
150
- const PAUSE_NAMES = { none: 0, create: 1, fill: 2, all: 3 };
151
- export function parseKinds(text) {
152
- return parseKindSet(text, "kinds", false);
153
- }
154
- function parseKindSet(text, key, allowNone) {
155
- if (allowNone && text === "none") {
156
- return 0n;
157
- }
158
- let mask = 0n;
159
- for (const name of text.split(",")) {
160
- const kind = KIND_NAMES[name];
161
- if (kind === undefined) {
162
- throw new UsageError(`--${key} takes ${allowNone ? "none or " : ""}a comma list of swap, limit, dutch, attested; got ${name}`);
163
- }
164
- mask |= kindBit(kind);
165
- }
166
- return mask;
167
- }
168
- export function parsePause(text, key) {
169
- const flags = PAUSE_NAMES[text];
170
- if (flags === undefined) {
171
- throw new UsageError(`--${key} must be none, create, fill or all`);
172
- }
173
- return flags;
174
- }
175
- function parseBounded(text, key, max, min = 0) {
176
- if (!/^\d+$/.test(text) || BigInt(text) > BigInt(max) || BigInt(text) < BigInt(min)) {
177
- throw new UsageError(`--${key} must be an integer from ${min} to ${max}`);
178
- }
179
- return Number(text);
180
- }
181
- function parseKindFees(text) {
182
- const bps = [0, 0, 0, 0];
183
- let mask = 0;
184
- if (text === "") {
185
- return { mask, bps };
186
- }
187
- for (const pair of text.split(",")) {
188
- const [name, value] = pair.split("=");
189
- const kind = name === undefined ? undefined : KIND_NAMES[name];
190
- if (kind === undefined || value === undefined) {
191
- throw new UsageError(`--kind-fees takes name=bps pairs for swap, limit, dutch, attested; got ${pair}`);
192
- }
193
- if ((mask & (1 << kind)) !== 0) {
194
- throw new UsageError(`--kind-fees names ${name} twice`);
195
- }
196
- mask |= 1 << kind;
197
- bps[kind - 1] = parseBounded(value, "kind-fees", 0xffff);
198
- }
199
- return { mask, bps };
200
- }
201
- export const MAX_EVENT_LIMIT = 1_000;
202
- export function parseLimit(text) {
203
- if (!/^\d+$/.test(text) || Number(text) < 1 || Number(text) > MAX_EVENT_LIMIT) {
204
- throw new UsageError(`--limit must be an integer from 1 to ${MAX_EVENT_LIMIT}`);
205
- }
206
- return Number(text);
207
- }
208
- export function parseFeeBps(text) {
209
- if (!/^\d+$/.test(text) || BigInt(text) > 65535n) {
210
- throw new UsageError("--fee-bps must be an integer from 0 to 65535");
211
- }
212
- return Number(text);
213
- }
214
- const EXPIRY = ["expires-at", "expires-in"];
215
- const ORDER = [
216
- "amount-in",
217
- "min-out",
218
- "make",
219
- "take",
220
- "start-out",
221
- "end-out",
222
- "start-at",
223
- "end-at",
224
- "min-result",
225
- "max-result",
226
- "attestor",
227
- ];
228
- const MANDATE_ORDER = ORDER.filter((o) => o !== "min-result" && o !== "max-result" && o !== "attestor");
229
- export const MANDATE_USE_KINDS = "a mandate covers swap, limit and dutch orders; name one of those";
230
- export const ACCEPTS = {
231
- setup: ["url", "keypair"],
232
- balance: ["url", "keypair", "owner", "mints"],
233
- pda: ["owner", "nonce"],
234
- hash: ["artifact"],
235
- show: ["url", "owner", "nonce"],
236
- domain: ["url"],
237
- mcp: [
238
- "url",
239
- "priority-fee",
240
- "relayer",
241
- "relay-max-lamports",
242
- "relay-max-ttl",
243
- "relay-per-hour",
244
- "relay-hourly-lamports",
245
- "relay-fee",
246
- "agent",
247
- "agent-hourly-lamports",
248
- "agent-owners",
249
- "wallet",
250
- "wallet-per-trade",
251
- "wallet-per-hour",
252
- ],
253
- quote: ["url", "owner", "nonce", "at"],
254
- cancel: ["url", "priority-fee", "keypair", "nonce"],
255
- expire: ["url", "priority-fee", "keypair", "owner", "nonce"],
256
- close: ["url", "priority-fee", "keypair", "owner", "nonce"],
257
- "advance-nonce": ["url", "priority-fee", "keypair", "base"],
258
- "advance-epoch": ["url", "priority-fee", "keypair"],
259
- "init-config": ["url", "priority-fee", "keypair", "authority", "yes", "guardian", "fee-recipient", "fee-bps", "kinds", "flags"],
260
- "raise-pause": ["url", "priority-fee", "keypair", "authority", "yes", "flags"],
261
- "set-economics": ["url", "priority-fee", "keypair", "authority", "yes", "bounty", "create-fee", "kind-fees", "partner-cut"],
262
- "update-config": [
263
- "url",
264
- "priority-fee",
265
- "keypair",
266
- "authority",
267
- "yes",
268
- "guardian",
269
- "fee-recipient",
270
- "fee-bps",
271
- "kinds",
272
- "fill-disabled",
273
- ],
274
- "propose-admin": ["url", "priority-fee", "keypair", "authority", "yes", "new-admin"],
275
- "accept-admin": ["url", "priority-fee", "keypair", "authority", "yes"],
276
- solve: ["url", "priority-fee", "keypair", "jupiter", "issue", "jito", "tip", "min-profit", "max-fee-bps", "slippage-bps", "route-program", "lookup-table", "watch", "interval"],
277
- "solver-table": ["url", "solver", "mints"],
278
- "lower-pause": ["url", "priority-fee", "keypair", "authority", "yes", "flags"],
279
- events: ["url", "limit", "follow", "interval"],
280
- jobs: ["url", "attestor"],
281
- deliver: ["url", "priority-fee", "keypair", "yes", "intent", "sha256", "work-url"],
282
- deliveries: ["url", "attestor", "intent"],
283
- judge: ["url", "priority-fee", "keypair", "yes", "owner", "nonce", "spec", "artifact", "run", "pay-to", "timeout", "verdict"],
284
- crank: ["url", "priority-fee", "keypair", "dry-run", "fund-accounts"],
285
- treasury: ["url", "priority-fee", "keypair", "yes", "mints", "create"],
286
- create: [
287
- "url",
288
- "priority-fee",
289
- "keypair",
290
- "yes",
291
- "nonce",
292
- "input-mint",
293
- "output-mint",
294
- ...EXPIRY,
295
- ...ORDER,
296
- "partner",
297
- "partner-bps",
298
- "units",
299
- ],
300
- list: ["url", "keypair", "owner"],
301
- mandate: [
302
- "url",
303
- "priority-fee",
304
- "keypair",
305
- "yes",
306
- "owner",
307
- "agent",
308
- "id",
309
- "input-mint",
310
- "output-mint",
311
- "kinds",
312
- "per-intent",
313
- "total",
314
- "max-intents",
315
- "max-ttl",
316
- "valid-for",
317
- "floor-out",
318
- "floor-in",
319
- "partner",
320
- "partner-bps",
321
- "agent-fee",
322
- "nonce",
323
- ...EXPIRY,
324
- ...ORDER,
325
- "units",
326
- ],
327
- approve: ["url", "priority-fee", "keypair", "yes", "mint", "amount", "units"],
328
- "revoke-approval": ["url", "priority-fee", "keypair", "yes", "mint"],
329
- signed: [
330
- "url",
331
- "keypair",
332
- "yes",
333
- "out",
334
- "file",
335
- "nonce",
336
- "input-mint",
337
- "output-mint",
338
- "submit-within",
339
- "relayer-fee",
340
- ...EXPIRY,
341
- ...ORDER,
342
- "partner",
343
- "partner-bps",
344
- "units",
345
- ],
346
- };
347
- export const SUB_ACCEPTS = {
348
- mandate: {
349
- grant: [
350
- "url",
351
- "priority-fee",
352
- "keypair",
353
- "yes",
354
- "agent",
355
- "id",
356
- "input-mint",
357
- "output-mint",
358
- "kinds",
359
- "per-intent",
360
- "total",
361
- "max-intents",
362
- "max-ttl",
363
- "valid-for",
364
- "floor-out",
365
- "floor-in",
366
- "partner",
367
- "partner-bps",
368
- "agent-fee",
369
- "units",
370
- ],
371
- show: ["url", "keypair", "agent", "id", "owner"],
372
- revoke: ["url", "priority-fee", "keypair", "yes", "agent", "id"],
373
- use: ["url", "priority-fee", "keypair", "yes", "owner", "id", "nonce", ...EXPIRY, ...MANDATE_ORDER, "units"],
374
- },
375
- signed: {
376
- prepare: [
377
- "url",
378
- "keypair",
379
- "yes",
380
- "out",
381
- "nonce",
382
- "input-mint",
383
- "output-mint",
384
- "submit-within",
385
- "relayer-fee",
386
- ...EXPIRY,
387
- ...ORDER,
388
- "partner",
389
- "partner-bps",
390
- "units",
391
- ],
392
- submit: ["url", "keypair", "yes", "file"],
393
- },
394
- };
395
- function noRepeats(argv) {
396
- const seen = new Set();
397
- for (const arg of argv) {
398
- if (arg === "--") {
399
- return;
400
- }
401
- if (!arg.startsWith("--")) {
402
- continue;
403
- }
404
- const name = arg.slice(2).split("=")[0] ?? "";
405
- if (seen.has(name)) {
406
- throw new UsageError(`--${name} is given more than once`);
407
- }
408
- seen.add(name);
409
- }
410
- }
411
- function onlyAccepted(verb, sub, values) {
412
- const accepted = verb === undefined ? undefined : (SUB_ACCEPTS[verb]?.[sub ?? ""] ?? ACCEPTS[verb]);
413
- const named = verb !== undefined && SUB_ACCEPTS[verb]?.[sub ?? ""] !== undefined ? `${verb} ${sub}` : verb;
414
- if (accepted === undefined) {
415
- return;
416
- }
417
- for (const [key, value] of Object.entries(values)) {
418
- if (value !== undefined &&
419
- !accepted.includes(key) &&
420
- !GLOBAL_OPTIONS.includes(key)) {
421
- throw new UsageError(`${named} does not take --${key}`);
422
- }
423
- }
424
- }
425
- function required(values, key) {
426
- const value = values[key];
427
- if (value === undefined) {
428
- throw new UsageError(`missing --${key}`);
429
- }
430
- return value;
431
- }
432
- export function parseU64(text, key) {
433
- if (!/^\d+$/.test(text) || BigInt(text) > U64_MAX) {
434
- throw new UsageError(`--${key} must be an integer from 0 to ${U64_MAX}`);
435
- }
436
- return BigInt(text);
437
- }
438
- export function parseI64(text, key) {
439
- if (!/^-?\d+$/.test(text) || BigInt(text) < I64_MIN || BigInt(text) > I64_MAX) {
440
- throw new UsageError(`--${key} must be an integer from ${I64_MIN} to ${I64_MAX}`);
441
- }
442
- return BigInt(text);
443
- }
444
- function parseAddress(text, key) {
445
- try {
446
- return address(text);
447
- }
448
- catch {
449
- throw new UsageError(`--${key} is not a base58 address`);
450
- }
451
- }
452
- const u64 = (values, key) => parseU64(required(values, key), key);
453
- const key = (values, name) => parseAddress(required(values, name), name);
454
- function amountOf(values, name) {
455
- const side = TOKEN_SIDES[name];
456
- if (values.units === "raw" || side === undefined) {
457
- return u64(values, name).toString();
458
- }
459
- const text = required(values, name);
460
- if (!TOKEN_AMOUNT_PATTERN.test(text)) {
461
- throw new UsageError(`--${name} must be a token amount like 12 or 0.5`);
462
- }
463
- return { tokens: text, side };
464
- }
465
- function unitsOf(values) {
466
- if (values.units !== undefined && values.units !== "raw" && values.units !== "tokens") {
467
- throw new UsageError("--units must be raw or tokens");
468
- }
469
- }
470
- const timeOf = (values, name) => parseI64(required(values, name), name).toString();
471
- const ORDER_FIELDS = {
472
- swap: ["amount-in", "min-out"],
473
- limit: ["make", "take"],
474
- dutch: ["amount-in", "start-out", "end-out", "start-at", "end-at"],
475
- attested: ["amount-in", "min-result", "max-result", "attestor"],
476
- };
477
- export function order(kind, values) {
478
- const fields = kind === undefined ? undefined : ORDER_FIELDS[kind];
479
- if (fields === undefined) {
480
- throw new UsageError("name the order kind: swap, limit, dutch or attested");
481
- }
482
- for (const name of ORDER) {
483
- if (values[name] !== undefined && !fields.includes(name)) {
484
- throw new UsageError(`a ${kind} order does not take --${name}`);
485
- }
486
- }
487
- switch (kind) {
488
- case "swap":
489
- return { kind, amount_in: amountOf(values, "amount-in"), min_out: amountOf(values, "min-out") };
490
- case "limit":
491
- return { kind, make_amount: amountOf(values, "make"), take_amount: amountOf(values, "take") };
492
- case "dutch":
493
- return {
494
- kind,
495
- amount_in: amountOf(values, "amount-in"),
496
- start_out: amountOf(values, "start-out"),
497
- end_out: amountOf(values, "end-out"),
498
- start_time: timeOf(values, "start-at"),
499
- end_time: timeOf(values, "end-at"),
500
- };
501
- default:
502
- return {
503
- kind,
504
- amount_in: amountOf(values, "amount-in"),
505
- min_result: amountOf(values, "min-result"),
506
- max_result: amountOf(values, "max-result"),
507
- attestor: key(values, "attestor"),
508
- };
509
- }
510
- }
511
- export function expiry(values) {
512
- if ((values["expires-at"] === undefined) === (values["expires-in"] === undefined)) {
513
- throw new UsageError("give exactly one of --expires-at or --expires-in");
514
- }
515
- return values["expires-at"] === undefined
516
- ? { expires_in: parseBounded(required(values, "expires-in"), "expires-in", MAX_EXPIRES_IN) }
517
- : { expires_at: timeOf(values, "expires-at") };
518
- }
519
- function partner(values) {
520
- if (values.partner === undefined && values["partner-bps"] === undefined) {
521
- return {};
522
- }
523
- return {
524
- partner: {
525
- account: key(values, "partner"),
526
- bps: parseBounded(required(values, "partner-bps"), "partner-bps", MAX_PARTNER_BPS),
527
- },
528
- };
529
- }
530
- const optionalField = (values, name, field, read) => values[name] === undefined ? {} : { [field]: read(values, name) };
531
- function terms(kind, values) {
532
- return {
533
- input_mint: key(values, "input-mint"),
534
- output_mint: key(values, "output-mint"),
535
- order: order(kind, values),
536
- ...expiry(values),
537
- ...optionalField(values, "nonce", "nonce", amountOf),
538
- ...partner(values),
539
- };
540
- }
541
- function grant(values) {
542
- const kinds = required(values, "kinds").split(",");
543
- for (const name of kinds) {
544
- if (!MANDATE_KIND_NAMES.includes(name)) {
545
- throw new UsageError(`--kinds takes a comma list of swap, limit, dutch; got ${name}`);
546
- }
547
- }
548
- return {
549
- agent: key(values, "agent"),
550
- input_mint: key(values, "input-mint"),
551
- output_mint: key(values, "output-mint"),
552
- kinds,
553
- per_intent: amountOf(values, "per-intent"),
554
- total: amountOf(values, "total"),
555
- max_intents: parseBounded(required(values, "max-intents"), "max-intents", 0xffff_ffff),
556
- max_ttl: parseBounded(required(values, "max-ttl"), "max-ttl", MAX_EXPIRES_IN),
557
- valid_for: parseBounded(required(values, "valid-for"), "valid-for", MAX_EXPIRES_IN),
558
- floor: { out: amountOf(values, "floor-out"), in: amountOf(values, "floor-in") },
559
- ...optionalField(values, "id", "id", amountOf),
560
- ...partner(values),
561
- ...optionalField(values, "agent-fee", "agent_fee", amountOf),
562
- };
563
- }
564
- function mandate(sub, kind, remote, values) {
565
- const flow = (name, input) => ({
566
- name: "flow",
567
- ...remote,
568
- flow: name,
569
- keypair: required(values, "keypair"),
570
- yes: values.yes === true,
571
- input,
572
- });
573
- const ref = () => ({ agent: key(values, "agent"), ...optionalField(values, "id", "id", amountOf) });
574
- if (sub !== "use") {
575
- noSub(kind);
576
- }
577
- switch (sub) {
578
- case "grant":
579
- return flow("mandate-grant", grant(values));
580
- case "revoke":
581
- return flow("mandate-revoke", ref());
582
- case "show":
583
- return {
584
- name: "lookup",
585
- ...remote,
586
- lookup: "mandate-show",
587
- keypair: values.keypair,
588
- input: { ...ref(), ...optionalField(values, "owner", "owner", key) },
589
- };
590
- case "use":
591
- if (kind === "attested") {
592
- throw new UsageError(MANDATE_USE_KINDS);
593
- }
594
- return flow("mandate-use", {
595
- owner: key(values, "owner"),
596
- order: order(kind, values),
597
- ...expiry(values),
598
- ...optionalField(values, "id", "id", amountOf),
599
- ...optionalField(values, "nonce", "nonce", amountOf),
600
- });
601
- default:
602
- throw new UsageError("mandate needs grant, show, revoke or use");
603
- }
604
- }
605
- function https(text, key) {
606
- let parsed;
607
- try {
608
- parsed = new URL(text);
609
- }
610
- catch {
611
- throw new UsageError(`--${key} is not a url`);
612
- }
613
- if (parsed.protocol !== "https:") {
614
- throw new UsageError(`--${key} must be an https url`);
615
- }
616
- return text.replace(/\/+$/, "");
617
- }
618
- function relaySpec(values) {
619
- const policy = [
620
- values["relay-max-lamports"],
621
- values["relay-max-ttl"],
622
- values["relay-per-hour"],
623
- values["relay-hourly-lamports"],
624
- values["relay-fee"],
625
- ];
626
- if (values.relayer === undefined) {
627
- if (policy.some((v) => v !== undefined)) {
628
- throw new UsageError("the --relay-* limits need --relayer");
629
- }
630
- return undefined;
631
- }
632
- if (values["relay-fee"] === undefined) {
633
- throw new UsageError(RELAY_NEEDS_FEES);
634
- }
635
- const maxTtl = parseBounded(values["relay-max-ttl"] ?? String(RELAY_DEFAULT_TTL), "relay-max-ttl", RELAY_MAX_TTL);
636
- const perHour = parseBounded(values["relay-per-hour"] ?? String(RELAY_DEFAULT_PER_HOUR), "relay-per-hour", 3_600);
637
- if (maxTtl < RELAY_MIN_TTL || perHour < 1) {
638
- throw new UsageError(`--relay-max-ttl must be at least ${RELAY_MIN_TTL} and --relay-per-hour at least 1`);
639
- }
640
- return {
641
- keypair: values.relayer,
642
- maxLamports: values["relay-max-lamports"] === undefined ? 0n : u64(values, "relay-max-lamports"),
643
- maxTtl: BigInt(maxTtl),
644
- perHour,
645
- hourlyLamports: values["relay-hourly-lamports"] === undefined
646
- ? RELAY_DEFAULT_HOURLY_LAMPORTS
647
- : u64(values, "relay-hourly-lamports"),
648
- fees: mintAmounts(values["relay-fee"], "relay-fee"),
649
- };
650
- }
651
- function mintAmounts(text, name) {
652
- const amounts = new Map();
653
- for (const entry of text === undefined ? [] : text.split(",")) {
654
- const [mint, amount, ...rest] = entry.split("=");
655
- if (mint === undefined || amount === undefined || rest.length > 0) {
656
- throw new UsageError(`--${name} takes mint=amount pairs separated by commas`);
657
- }
658
- const key = parseAddress(mint.trim(), name);
659
- if (amounts.has(key)) {
660
- throw new UsageError(`--${name} names ${key} twice`);
661
- }
662
- amounts.set(key, parseU64(amount.trim(), name));
663
- }
664
- return amounts;
665
- }
666
- export const WALLET_LIMITS_NEED_WALLET = "--wallet-per-trade and --wallet-per-hour need --wallet";
667
- const wholeTokens = (key) => `--${key} takes token=amount pairs separated by commas, such as SOL=0.1,TEST=20`;
668
- function tokenAmounts(text, key, url) {
669
- const amounts = new Map();
670
- for (const entry of text === undefined ? [] : text.split(",")) {
671
- const [name, amount, ...rest] = entry.split("=");
672
- if (name === undefined || amount === undefined || rest.length > 0 || !TOKEN_AMOUNT_PATTERN.test(amount.trim())) {
673
- throw new UsageError(wholeTokens(key));
674
- }
675
- const mint = tokenNamed(name.trim(), url);
676
- if (mint instanceof Error) {
677
- throw new UsageError(`--${key}: ${mint.message}`);
678
- }
679
- const parsed = parseAddress(mint, key);
680
- if (amounts.has(parsed)) {
681
- throw new UsageError(`--${key} names ${name.trim()} twice`);
682
- }
683
- amounts.set(parsed, amount.trim());
684
- }
685
- return amounts;
686
- }
687
- function walletLimits(values, url) {
688
- if (values.wallet !== true) {
689
- if (values["wallet-per-trade"] !== undefined || values["wallet-per-hour"] !== undefined) {
690
- throw new UsageError(WALLET_LIMITS_NEED_WALLET);
691
- }
692
- return null;
693
- }
694
- return {
695
- perTrade: tokenAmounts(values["wallet-per-trade"], "wallet-per-trade", url),
696
- perHour: tokenAmounts(values["wallet-per-hour"], "wallet-per-hour", url),
697
- };
698
- }
699
- function agentSpec(values) {
700
- if (values.agent === undefined) {
701
- if (values["agent-hourly-lamports"] !== undefined || values["agent-owners"] !== undefined) {
702
- throw new UsageError("the --agent-* limits need --agent");
703
- }
704
- return undefined;
705
- }
706
- const owners = values["agent-owners"];
707
- if (owners === undefined) {
708
- throw new UsageError(AGENT_NEEDS_OWNERS);
709
- }
710
- return {
711
- keypair: values.agent,
712
- hourlyLamports: values["agent-hourly-lamports"] === undefined
713
- ? AGENT_DEFAULT_HOURLY_LAMPORTS
714
- : u64(values, "agent-hourly-lamports"),
715
- owners: owners.split(",").map((o) => parseAddress(o.trim(), "agent-owners")),
716
- };
717
- }
718
- export function parsePriority(text) {
719
- if (text === undefined) {
720
- return 0n;
721
- }
722
- if (text === "auto") {
723
- return "auto";
724
- }
725
- const price = parseU64(text, "priority-fee");
726
- if (price > MAX_PRIORITY_PRICE) {
727
- throw new UsageError(`--priority-fee is micro-lamports per compute unit and at most ${MAX_PRIORITY_PRICE}; use auto for the recent market price`);
728
- }
729
- return price;
730
- }
731
- function authorityOf(values) {
732
- if (values.keypair !== undefined && values.authority !== undefined) {
733
- throw new UsageError("pass --keypair to sign and send, or --authority to print an unsigned transaction, not both");
734
- }
735
- if (values.authority !== undefined) {
736
- if (values.yes === true) {
737
- throw new UsageError("--yes signs and sends with --keypair; --authority only prints an unsigned transaction");
738
- }
739
- return { authority: key(values, "authority") };
740
- }
741
- return { keypair: required(values, "keypair"), yes: values.yes === true };
742
- }
743
- function configChange(values) {
744
- const change = {
745
- guardian: values.guardian === undefined ? undefined : key(values, "guardian"),
746
- feeRecipient: values["fee-recipient"] === undefined ? undefined : key(values, "fee-recipient"),
747
- feeBps: values["fee-bps"] === undefined ? undefined : parseFeeBps(values["fee-bps"]),
748
- enabledKinds: values.kinds === undefined ? undefined : parseKinds(values.kinds),
749
- fillDisabledKinds: values["fill-disabled"] === undefined ? undefined : parseKindSet(values["fill-disabled"], "fill-disabled", true),
750
- };
751
- if (Object.values(change).every((v) => v === undefined)) {
752
- throw new UsageError("update-config needs at least one of --guardian, --fee-recipient, --fee-bps, --kinds, --fill-disabled");
753
- }
754
- return change;
755
- }
756
- const MINT_KEYS = ["input-mint", "output-mint", "mint"];
757
- function resolved(text, url) {
758
- const mint = tokenNamed(text, url);
759
- if (mint instanceof Error) {
760
- throw new UsageError(mint.message);
761
- }
762
- return mint;
763
- }
764
- function named(values, url) {
765
- for (const name of MINT_KEYS) {
766
- const text = values[name];
767
- if (text !== undefined) {
768
- values[name] = resolved(text, url);
769
- }
770
- }
771
- if (values.mints !== undefined) {
772
- values.mints = values.mints
773
- .split(",")
774
- .map((m) => resolved(m.trim(), url))
775
- .join(",");
776
- }
777
- }
778
- function mintList(text) {
779
- return addressList(text, "mints");
780
- }
781
- export const ISSUE_FORMAT = "--issue takes <input mint>:<output mint>=<out>/<in> entries separated by commas";
782
- export const ONE_MARKET = "solve needs exactly one of --jupiter or --issue";
783
- export const ISSUE_ALONE = "--issue mints the output itself, so --slippage-bps and --route-program do not apply";
784
- function issues(text) {
785
- const routes = [];
786
- for (const entry of text.split(",")) {
787
- const match = /^([^:=/]+):([^:=/]+)=([^:=/]+)\/([^:=/]+)$/.exec(entry.trim());
788
- if (match === null) {
789
- throw new UsageError(ISSUE_FORMAT);
790
- }
791
- const [, input = "", output = "", out = "", per = ""] = match;
792
- const route = {
793
- inputMint: parseAddress(input.trim(), "issue"),
794
- outputMint: parseAddress(output.trim(), "issue"),
795
- out: parseU64(out.trim(), "issue"),
796
- in: parseU64(per.trim(), "issue"),
797
- };
798
- if (route.out === 0n || route.in === 0n) {
799
- throw new UsageError("--issue rates must be positive on both sides");
800
- }
801
- if (routes.some((r) => r.inputMint === route.inputMint && r.outputMint === route.outputMint)) {
802
- throw new UsageError(`--issue names ${route.inputMint}:${route.outputMint} twice`);
803
- }
804
- routes.push(route);
805
- }
806
- return routes;
807
- }
808
- function market(values) {
809
- if ((values.jupiter === undefined) === (values.issue === undefined)) {
810
- throw new UsageError(ONE_MARKET);
811
- }
812
- if (values.issue === undefined) {
813
- return { jupiter: https(required(values, "jupiter"), "jupiter"), issue: [] };
814
- }
815
- if (values["slippage-bps"] !== undefined || values["route-program"] !== undefined) {
816
- throw new UsageError(ISSUE_ALONE);
817
- }
818
- return { jupiter: undefined, issue: issues(values.issue) };
819
- }
820
- function addressList(text, name) {
821
- const items = [...new Set(text.split(",").map((m) => m.trim()))];
822
- if (items.some((m) => m === "")) {
823
- throw new UsageError(`--${name} takes a comma list of addresses`);
824
- }
825
- return items.map((m) => parseAddress(m, name));
826
- }
827
- export const TREASURY_CREATE_NEEDS_MINTS = "--create needs --mints naming the tokens to open treasury accounts for; anyone can open intents in any token, so the list must be yours";
828
- function treasury(remote, values) {
829
- const create = values.create === true;
830
- if (values.yes === true && !create) {
831
- throw new UsageError("--yes only applies with --create");
832
- }
833
- if (create && values.mints === undefined) {
834
- throw new UsageError(TREASURY_CREATE_NEEDS_MINTS);
835
- }
836
- return {
837
- name: "treasury",
838
- ...remote,
839
- mints: values.mints === undefined ? null : mintList(values.mints),
840
- create,
841
- keypair: create ? required(values, "keypair") : values.keypair,
842
- yes: values.yes === true,
843
- };
844
- }
845
- export const SHA256_NEEDED = "--sha256 must be the work's sha256 as 64 hex digits";
846
- function sha256Of(text) {
847
- if (!/^[0-9a-fA-F]{64}$/.test(text)) {
848
- throw new UsageError(SHA256_NEEDED);
849
- }
850
- return text.toLowerCase();
851
- }
852
- function workUrlOf(text) {
853
- if (!isMemoUrl(text)) {
854
- throw new UsageError(`--work-url must be ${MEMO_URL_RULE}`);
855
- }
856
- return text;
857
- }
858
- export const JUDGE_TIMEOUT = 600;
859
- export const MAX_JUDGE_TIMEOUT = 86_400;
860
- export const RUN_NEEDED = "--run must name the command that checks the artifact";
861
- function runOf(text) {
862
- if (text.trim() === "") {
863
- throw new UsageError(RUN_NEEDED);
864
- }
865
- return text;
866
- }
867
- function noSub(sub) {
868
- if (sub !== undefined) {
869
- throw new UsageError(`unexpected argument ${sub}`);
870
- }
871
- }
872
32
  export function clusterUrl(text) {
873
33
  return CLUSTERS[text] ?? text;
874
34
  }
875
- export function outputOf(argv) {
876
- const at = argv.lastIndexOf("--output");
877
- const inline = argv.findLast((a) => a.startsWith("--output="));
878
- const value = at >= 0 ? argv[at + 1] : inline?.slice("--output=".length);
879
- if (value === undefined) {
880
- return "json";
881
- }
882
- if (value !== "json" && value !== "text") {
883
- throw new UsageError("--output must be json or text");
884
- }
885
- return value;
886
- }
887
35
  export const MAX_FOLLOW_INTERVAL = 3_600;
888
36
  export const WATCH_INTERVAL = 5;
889
- export const COMMANDS = "setup | balance | pda | domain | mcp | show config | show intent | quote | cancel | expire | close | advance-nonce | advance-epoch | create swap|limit|dutch|attested | list | mandate grant|show|revoke|use <kind> | approve | revoke-approval | signed prepare <kind>|submit | init-config | update-config | set-economics | propose-admin | accept-admin | solve | raise-pause | lower-pause | crank | treasury | solver-table | events | jobs | deliver | deliveries | judge | hash | version | help [command]";
890
- export const USAGE = `usage: ${COMMANDS}`;
891
- const MANDATE_ORDER_SHAPE = "(--amount-in --min-out | --make --take | --amount-in --start-out --end-out --start-at --end-at)";
892
- const ORDER_SHAPE = "(--amount-in --min-out | --make --take | --amount-in --start-out --end-out --start-at --end-at | --amount-in --min-result --max-result --attestor)";
893
- const PARTNER_SHAPE = "[--partner <address> --partner-bps <n>]";
894
- export const SHAPES = {
895
- setup: "[--url <cluster>] [--keypair <file>]",
896
- balance: "[--keypair <file> | --owner <address>] [--mints <mint,...>]",
897
- pda: "--owner <address> --nonce <n>",
898
- hash: "--artifact <file or directory>",
899
- show: "config | intent --owner <address> --nonce <n>",
900
- domain: "",
901
- mcp: "[--wallet [--wallet-per-trade <token=amount,...>] [--wallet-per-hour <token=amount,...>]] [--relayer <keypair> --relay-fee <mint=amount,...> [--relay-max-lamports] [--relay-max-ttl] [--relay-per-hour] [--relay-hourly-lamports]] [--agent <keypair> --agent-owners <address,...> [--agent-hourly-lamports]]",
902
- quote: "--owner <address> --nonce <n> [--at <unix>]",
903
- cancel: "--keypair <file> --nonce <n>",
904
- expire: "--keypair <file> --owner <address> --nonce <n>",
905
- close: "--keypair <file> --owner <address> --nonce <n>",
906
- "advance-nonce": "--keypair <file> --base <n>",
907
- "advance-epoch": "--keypair <file>",
908
- "init-config": "(--keypair <file> [--yes] | --authority <address>) --guardian --fee-recipient --fee-bps --kinds [--flags create|fill|all]",
909
- "update-config": "(--keypair <file> [--yes] | --authority <address>) and any of --guardian --fee-recipient --fee-bps --kinds --fill-disabled",
910
- "propose-admin": "(--keypair <file> [--yes] | --authority <address>) --new-admin <address>",
911
- "accept-admin": "(--keypair <file> [--yes] | --authority <address>)",
912
- "raise-pause": "(--keypair <file> [--yes] | --authority <address>) --flags create|fill|all",
913
- "lower-pause": "(--keypair <file> [--yes] | --authority <address>) --flags create|fill|all",
914
- "set-economics": "(--keypair <file> [--yes] | --authority <address>) --bounty --create-fee [--kind-fees] [--partner-cut]",
915
- solve: "--keypair <file> (--jupiter <url> | --issue <input mint>:<output mint>=<out>/<in>,...) --min-profit <output mint=raw,...> [--priority-fee <micro-lamports|auto>] [--max-fee-bps <n>] [--slippage-bps <n>] [--jito <url> [--tip <lamports>]] [--route-program <program the aggregator swaps through>] [--lookup-table <address,...>] [--watch [--interval <seconds>]]",
916
- "solver-table": "--solver <address> --mints <mint,...>",
917
- crank: "--keypair <file> [--dry-run] [--fund-accounts]",
918
- treasury: "[--mints <mint,...>] [--create --mints <mint,...> --keypair <payer file> [--yes]]",
919
- events: "[--limit <n>] [--follow [--interval <seconds>]]",
920
- jobs: "[--attestor <address>]",
921
- deliver: "--keypair <worker file> --intent <address> --sha256 <64 hex> --work-url <https url> [--yes]",
922
- deliveries: "--attestor <address> --intent <address>",
923
- judge: "--keypair <judge file> --owner <address> --nonce <n> --spec <file> --artifact <file or directory> --run <command> [--pay-to <wallet>] [--timeout <seconds>] [--verdict <file>] [--yes]",
924
- create: `swap|limit|dutch|attested --keypair <file> --input-mint --output-mint (--expires-at | --expires-in) ${ORDER_SHAPE} [--nonce <n>] ${PARTNER_SHAPE} [--units tokens|raw] [--yes]`,
925
- list: "--owner <address> or --keypair <file>; --owner wins when both are given",
926
- mandate: `grant --keypair <file> --agent --input-mint --output-mint --kinds --per-intent --total --max-intents --max-ttl --valid-for --floor-out --floor-in [--agent-fee] ${PARTNER_SHAPE} [--id] [--units tokens|raw] [--yes] | show --agent (--owner <address> | --keypair <file>) [--id] | revoke --keypair <file> --agent [--id] [--yes] | use swap|limit|dutch --keypair <file> --owner (--expires-at | --expires-in) ${MANDATE_ORDER_SHAPE} [--id] [--nonce <n>] [--units tokens|raw] [--yes]`,
927
- approve: "--keypair <file> --mint <mint> --amount <amount> [--units tokens|raw] [--yes]",
928
- "revoke-approval": "--keypair <file> --mint <mint> [--yes]",
929
- signed: `prepare swap|limit|dutch|attested --keypair <file> --out <file> --input-mint --output-mint (--expires-at | --expires-in) ${ORDER_SHAPE} [--nonce <n>] [--submit-within <seconds>] [--relayer-fee] ${PARTNER_SHAPE} [--units tokens|raw] [--yes] | submit --keypair <relayer file> --file <file> [--yes]`,
930
- };
931
- export function usageOf(verb) {
932
- const known = verb !== undefined && ACCEPTS[verb] !== undefined;
933
- return {
934
- usage: known ? `${verb} ${SHAPES[verb] ?? ""}`.trim() : COMMANDS,
935
- options: known ? [...(ACCEPTS[verb] ?? []), ...GLOBAL_OPTIONS].map((o) => `--${o}`) : [],
936
- };
937
- }
938
37
  export function parse(argv, env = {}) {
939
38
  noRepeats(argv);
940
39
  let parsed;
@@ -991,7 +90,10 @@ export function parse(argv, env = {}) {
991
90
  if (sub === "intent") {
992
91
  return { name: "show-intent", ...remote, owner: key(values, "owner"), nonce: u64(values, "nonce") };
993
92
  }
994
- throw new UsageError("show needs config or intent");
93
+ if (sub === "mint-cap") {
94
+ return { name: "show-mint-cap", ...remote, mint: key(values, "mint") };
95
+ }
96
+ throw new UsageError("show needs config, intent or mint-cap");
995
97
  case "setup":
996
98
  noSub(sub);
997
99
  return { name: "setup", ...remote, keypair: values.keypair };
@@ -1027,7 +129,14 @@ export function parse(argv, env = {}) {
1027
129
  };
1028
130
  case "cancel":
1029
131
  noSub(sub);
1030
- return { name: "cancel", ...remote, keypair: required(values, "keypair"), nonce: u64(values, "nonce") };
132
+ return {
133
+ name: "cancel",
134
+ ...remote,
135
+ keypair: required(values, "keypair"),
136
+ yes: values.yes === true,
137
+ nonce: u64(values, "nonce"),
138
+ close: values.close === true,
139
+ };
1031
140
  case "expire":
1032
141
  case "close":
1033
142
  noSub(sub);
@@ -1035,6 +144,7 @@ export function parse(argv, env = {}) {
1035
144
  name: verb,
1036
145
  ...remote,
1037
146
  keypair: required(values, "keypair"),
147
+ yes: values.yes === true,
1038
148
  owner: key(values, "owner"),
1039
149
  nonce: u64(values, "nonce"),
1040
150
  };
@@ -1090,6 +200,9 @@ export function parse(argv, env = {}) {
1090
200
  if (values.interval !== undefined && values.watch !== true) {
1091
201
  throw new UsageError("--interval needs --watch");
1092
202
  }
203
+ if (remote.priority !== "auto" && remote.priority > AUTO_PRICE_CAP) {
204
+ throw new UsageError(solveFeeAboveCap);
205
+ }
1093
206
  return {
1094
207
  name: "solve",
1095
208
  ...remote,
@@ -1097,8 +210,10 @@ export function parse(argv, env = {}) {
1097
210
  ...market(values),
1098
211
  jito: values.jito === undefined ? undefined : https(values.jito, "jito"),
1099
212
  tipLamports,
1100
- minProfit: mintAmounts(required(values, "min-profit"), "min-profit"),
213
+ minProfit: profitFloors(required(values, "min-profit")),
1101
214
  maxFeeBps: parseBounded(values["max-fee-bps"] ?? "100", "max-fee-bps", 200),
215
+ maxSolCost: values["max-sol-cost"] === undefined ? DEFAULT_MAX_SOL_COST : parseSolCost(values["max-sol-cost"]),
216
+ maxRent: values["max-rent"] === undefined ? DEFAULT_MAX_RENT : parseMaxRent(values["max-rent"]),
1102
217
  slippageBps: parseBounded(values["slippage-bps"] ?? "50", "slippage-bps", 10_000),
1103
218
  routeProgram: values["route-program"] === undefined ? undefined : parseAddress(values["route-program"], "route-program"),
1104
219
  lookupTables: values["lookup-table"] === undefined ? [] : addressList(values["lookup-table"], "lookup-table"),
@@ -1114,6 +229,31 @@ export function parse(argv, env = {}) {
1114
229
  case "accept-admin":
1115
230
  noSub(sub);
1116
231
  return { name: "accept-admin", ...remote, by: authorityOf(values) };
232
+ case "set-mint-cap": {
233
+ noSub(sub);
234
+ const maxPerOrder = u64(values, "max-per-order");
235
+ const windowCap = u64(values, "window-cap");
236
+ if (maxPerOrder === 0n) {
237
+ throw new UsageError("--max-per-order must be above zero");
238
+ }
239
+ if (windowCap < maxPerOrder) {
240
+ throw new UsageError("--window-cap must be at least --max-per-order");
241
+ }
242
+ return {
243
+ name: "set-mint-cap",
244
+ ...remote,
245
+ by: authorityOf(values),
246
+ mint: key(values, "mint"),
247
+ maxPerOrder,
248
+ windowCap,
249
+ windowSecs: parseBounded(required(values, "window-secs"), "window-secs", 0xffff_ffff, MIN_CAP_WINDOW_SECS),
250
+ };
251
+ }
252
+ case "set-caps-required":
253
+ if (sub !== "on" && sub !== "off") {
254
+ throw new UsageError("set-caps-required needs on or off");
255
+ }
256
+ return { name: "set-caps-required", ...remote, by: authorityOf(values), required: sub === "on" };
1117
257
  case "events":
1118
258
  noSub(sub);
1119
259
  if (values.follow === true) {
@@ -1143,13 +283,36 @@ export function parse(argv, env = {}) {
1143
283
  yes: values.yes === true,
1144
284
  intent: key(values, "intent"),
1145
285
  sha256: sha256Of(required(values, "sha256")),
1146
- workUrl: workUrlOf(required(values, "work-url")),
286
+ workUrl: memoUrlOf(required(values, "work-url"), "work-url"),
1147
287
  };
1148
288
  case "deliveries":
1149
289
  noSub(sub);
1150
- return { name: "deliveries", ...remote, attestor: key(values, "attestor"), intent: key(values, "intent") };
1151
- case "judge":
290
+ return { name: "deliveries", ...remote, attestor: key(values, "attestor"), intent: key(values, "intent"), maxPages: maxPagesOf(values) };
291
+ case "receipt":
292
+ noSub(sub);
293
+ return {
294
+ name: "receipt",
295
+ ...remote,
296
+ owner: key(values, "owner"),
297
+ nonce: u64(values, "nonce"),
298
+ sha256: values.sha256 === undefined ? undefined : sha256Of(values.sha256),
299
+ ...releaseOption(values),
300
+ };
301
+ case "record-delivery":
302
+ noSub(sub);
303
+ return {
304
+ name: "record-delivery",
305
+ ...remote,
306
+ keypair: required(values, "keypair"),
307
+ yes: values.yes === true,
308
+ owner: key(values, "owner"),
309
+ nonce: u64(values, "nonce"),
310
+ sha256: sha256Of(required(values, "sha256")),
311
+ ...releaseOption(values),
312
+ };
313
+ case "judge": {
1152
314
  noSub(sub);
315
+ const sandbox = sandboxOf(values);
1153
316
  return {
1154
317
  name: "judge",
1155
318
  ...remote,
@@ -1159,14 +322,22 @@ export function parse(argv, env = {}) {
1159
322
  nonce: u64(values, "nonce"),
1160
323
  spec: required(values, "spec"),
1161
324
  artifact: required(values, "artifact"),
1162
- run: runOf(required(values, "run")),
325
+ run: sandbox.kind === "viper" ? undefined : runOf(required(values, "run")),
1163
326
  payTo: values["pay-to"] === undefined ? undefined : key(values, "pay-to"),
327
+ result: values.result === undefined ? undefined : u64(values, "result"),
1164
328
  timeout: parseBounded(values.timeout ?? String(JUDGE_TIMEOUT), "timeout", MAX_JUDGE_TIMEOUT, 1),
1165
329
  verdict: values.verdict,
330
+ maxPages: maxPagesOf(values),
331
+ check: values.check,
332
+ sandbox,
1166
333
  };
334
+ }
1167
335
  case "solver-table":
1168
336
  noSub(sub);
1169
337
  return { name: "solver-table", ...remote, solver: key(values, "solver"), mints: mintList(required(values, "mints")) };
338
+ case "monitor":
339
+ noSub(sub);
340
+ return monitorOf(remote, values);
1170
341
  case "crank":
1171
342
  noSub(sub);
1172
343
  return {
@@ -1183,7 +354,7 @@ export function parse(argv, env = {}) {
1183
354
  flow: "create",
1184
355
  keypair: required(values, "keypair"),
1185
356
  yes: values.yes === true,
1186
- input: terms(sub, values),
357
+ input: createTerms(sub, values),
1187
358
  };
1188
359
  case "list":
1189
360
  noSub(sub);
@@ -1199,6 +370,12 @@ export function parse(argv, env = {}) {
1199
370
  };
1200
371
  case "mandate":
1201
372
  return mandate(sub, third, remote, values);
373
+ case "committee":
374
+ return committeeOf(sub, remote, values);
375
+ case "reputation":
376
+ return reputationOf(sub, remote, values);
377
+ case "feedback":
378
+ return feedbackOf(sub, remote, values);
1202
379
  case "approve":
1203
380
  case "revoke-approval":
1204
381
  noSub(sub);