@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
@@ -0,0 +1,243 @@
1
+ import { formatAmount, formatTime, LONG_LIVED_SECONDS, WARN_LONG_LIVED } from "@intent-engine/core";
2
+ import { chainTime, mintOf } from "@intent-engine/client";
3
+ import { TOKEN_NAMES } from "../../tokens.js";
4
+ import { define } from "../actions.js";
5
+ import { MAX_EXPIRES_IN, MIN_EXPIRES_IN } from "../create.js";
6
+ import { tool } from "../names.js";
7
+ import { problemOf } from "../problems.js";
8
+ import { InvalidInput, account, amount, flag, integer, list, object, optional, text, time } from "../schema.js";
9
+ import { ESTIMATE_SCAN, ESTIMATE_FILLS, DEFAULT_EXPIRES_IN, LANDING_SECONDS, access, testCluster, mintNamed, raw, salesOf, checkSale, checkHour, refusedBeforeSending, } from "./guard.js";
10
+ import { offerFields, offerOutput, offered } from "./offer.js";
11
+ import { recentFills, bestOf, medianOf, openingAsk } from "./fills.js";
12
+ export const SWAP_FALLS_OVER = 120;
13
+ export const PAY_TO = "the wallet that receives what is bought, such as someone this wallet pays; default this wallet. This wallet pays for its token account if it has none";
14
+ export const walletSwap = define({
15
+ name: tool("wallet_swap"),
16
+ title: "Swap from the wallet",
17
+ description: `Sell an exact amount of one token for at least min_receive of another, from this server's wallet: the tokens are escrowed in an intent that a solver fills or that the wallet gets back. Solvers pay the least an intent asks, so by default the ask starts at start_receive, a little above the median of recent fills but at least a quarter above min_receive and at most twice it, and falls to min_receive over falls_over seconds (default ${SWAP_FALLS_OVER}): a solver takes it near the most it can pay. exact: true asks min_receive from the start instead. Amounts are whole tokens such as 0.05. Selling SOL wraps it first. Without send it only previews; show the user the summary, then call again with send: true and the start_receive the preview returned once they approve.`,
18
+ effect: "submit",
19
+ repeats: true,
20
+ input: object({
21
+ sell: text("SOL, TEST or a mint address"),
22
+ buy: text("SOL, TEST or a mint address"),
23
+ amount: text("whole tokens to sell, such as 0.05"),
24
+ min_receive: text("least whole tokens to receive for all of it"),
25
+ start_receive: optional(text("whole tokens asked when the offer lands; default a little above the median recent fill, between 1.25 and 2 times min_receive")),
26
+ falls_over: optional(integer(MIN_EXPIRES_IN, MAX_EXPIRES_IN, `seconds the ask takes to fall to min_receive; default ${SWAP_FALLS_OVER}`)),
27
+ exact: optional(flag("true asks min_receive from the start, with no falling ask")),
28
+ pay_to: optional(account(PAY_TO)),
29
+ expires_in: optional(integer(MIN_EXPIRES_IN, MAX_EXPIRES_IN, `least seconds the offer stays open once sent; default ${DEFAULT_EXPIRES_IN}`)),
30
+ send: optional(flag("true signs and sends; leave out to preview")),
31
+ }),
32
+ output: object({ ...offerFields, start_receive: optional(text("whole tokens asked when the offer lands; pass it back when sending")) }),
33
+ run: async (ctx, input, call) => {
34
+ let opening;
35
+ const result = await offered(ctx, call, input, async (sold, bought, now, inputMint, outputMint) => {
36
+ const amountIn = raw(input.amount, sold.decimals, "amount");
37
+ const floor = raw(input.min_receive, bought.decimals, "min_receive");
38
+ const expiresIn = BigInt(input.expires_in ?? DEFAULT_EXPIRES_IN);
39
+ const ask = input.exact === true
40
+ ? floor
41
+ : input.start_receive === undefined
42
+ ? openingAsk(await recentFills(ctx.transport, inputMint, outputMint), amountIn, floor)
43
+ : raw(input.start_receive, bought.decimals, "start_receive");
44
+ if (ask <= floor) {
45
+ return { order: { kind: "swap", amount_in: amountIn, min_out: floor }, expires_at: now + expiresIn + BigInt(LANDING_SECONDS) };
46
+ }
47
+ opening = formatAmount(ask, bought.decimals);
48
+ const start = now + BigInt(LANDING_SECONDS);
49
+ const falls = BigInt(input.falls_over ?? SWAP_FALLS_OVER);
50
+ return {
51
+ order: { kind: "dutch", amount_in: amountIn, start_out: ask, end_out: floor, start_time: start, end_time: start + falls },
52
+ expires_at: start + (expiresIn > falls ? expiresIn : falls),
53
+ };
54
+ });
55
+ return opening === undefined ? result : { ...result, start_receive: opening };
56
+ },
57
+ });
58
+ export const MAX_RECURRING = 12;
59
+ export const mayHaveLanded = (sent, times, problem) => `${sent} of ${times} orders were sent and the next may have landed too (${problem}); check ${tool("wallet_intents")} before sending any again, and do not repeat this call`;
60
+ export const partlySent = (sent, times, problem) => `${sent} of ${times} orders were sent; the next failed with ${problem}. To finish, schedule only the ${times - sent} remaining orders; do not repeat this call`;
61
+ export const WARN_EARLY = "an order fills before its turn if a solver can already pay its start_receive";
62
+ export const NO_FALL = "must be more than 0, or the orders have no ask to fall";
63
+ export const MAX_EVERY = 30 * 24 * 60 * 60;
64
+ export const walletRecurring = define({
65
+ name: tool("wallet_recurring"),
66
+ title: "Repeat a swap on a schedule",
67
+ description: `Sell the same amount of one token for another several times, every so many seconds, from this server's wallet, with no bot left running: all orders are sent now and escrowed now. Each order holds its ask at start_receive until its turn, then lets it fall to min_receive over falls_over seconds; it expires when the next one opens, or falls_over seconds after its own opening if that is later, and anyone can then return its escrow. An order fills before its turn if a solver can already pay start_receive, so set it above what solvers pay now to hold the orders. Any order can be cancelled with ${tool("wallet_cancel")}. Each order pays the create fee and rent, and the rent returns when it closes. Amounts are whole tokens per order. Without send it only previews; show the user the summary, then call again with send: true and the start_receive the preview returned once they approve.`,
68
+ effect: "submit",
69
+ repeats: true,
70
+ input: object({
71
+ sell: text("SOL, TEST or a mint address"),
72
+ buy: text("SOL, TEST or a mint address"),
73
+ amount: text("whole tokens each order sells, such as 0.05"),
74
+ min_receive: text("least whole tokens each order receives"),
75
+ every: integer(MIN_EXPIRES_IN, MAX_EVERY, "seconds between one order opening and the next"),
76
+ times: integer(2, MAX_RECURRING, "how many orders"),
77
+ start_receive: optional(text("whole tokens each order asks until and when it opens; default a little above the median recent fill, between 1.25 and 2 times min_receive")),
78
+ falls_over: optional(integer(MIN_EXPIRES_IN, MAX_EVERY, `seconds each order's ask takes to fall to min_receive; default ${SWAP_FALLS_OVER}`)),
79
+ pay_to: optional(account(PAY_TO)),
80
+ send: optional(flag("true signs and sends every order; leave out to preview")),
81
+ }),
82
+ output: object({
83
+ orders: list(object({ opens_at: time("when the order's ask starts to fall"), intent: optional(account()), nonce: optional(amount()), signature: optional(text()) }), MAX_RECURRING),
84
+ summary: list(text(), 24, "the whole plan, then the first order"),
85
+ warnings: list(text(), 16),
86
+ start_receive: text("whole tokens each order asks when it opens; pass it back when sending"),
87
+ sent: flag(),
88
+ next: optional(text()),
89
+ }),
90
+ run: async (ctx, input, call) => {
91
+ const wallet = access(ctx);
92
+ const inputMint = mintNamed(input.sell, wallet.url, "sell");
93
+ const outputMint = mintNamed(input.buy, wallet.url, "buy");
94
+ const [inputToken, outputToken, now] = await Promise.all([
95
+ mintOf(ctx.transport, inputMint),
96
+ mintOf(ctx.transport, outputMint),
97
+ chainTime(ctx.transport),
98
+ ]);
99
+ const amountIn = raw(input.amount, inputToken.decimals, "amount");
100
+ const floor = raw(input.min_receive, outputToken.decimals, "min_receive");
101
+ const ask = input.start_receive === undefined
102
+ ? openingAsk(await recentFills(ctx.transport, inputMint, outputMint), amountIn, floor)
103
+ : raw(input.start_receive, outputToken.decimals, "start_receive");
104
+ if (ask <= floor) {
105
+ throw new InvalidInput([
106
+ input.start_receive === undefined ? { path: "min_receive", message: NO_FALL } : { path: "start_receive", message: "must be more than min_receive, or the order has no ask to fall" },
107
+ ]);
108
+ }
109
+ const sales = await salesOf(wallet, now);
110
+ checkSale(wallet.limits, inputMint, inputToken.decimals, amountIn, now, sales);
111
+ checkHour(wallet.limits, inputMint, inputToken.decimals, amountIn * BigInt(input.times), now, sales);
112
+ const falls = BigInt(input.falls_over ?? SWAP_FALLS_OVER);
113
+ const every = BigInt(input.every);
114
+ const life = falls > every ? falls : every;
115
+ const opens = Array.from({ length: input.times }, (_, k) => now + BigInt(LANDING_SECONDS) + every * BigInt(k));
116
+ const terms = (open) => () => ({
117
+ order: { kind: "dutch", amount_in: amountIn, start_out: ask, end_out: floor, start_time: open, end_time: open + falls },
118
+ expires_at: open + life,
119
+ });
120
+ const shown = { start_receive: formatAmount(ask, outputToken.decimals) };
121
+ const last = opens[opens.length - 1];
122
+ const first = (await offered(ctx, call, { ...input, send: input.send }, terms(opens[0])));
123
+ const sold = TOKEN_NAMES[inputMint] ?? inputMint;
124
+ const plan = [
125
+ `Plan: ${input.times} orders of ${formatAmount(amountIn, inputToken.decimals)} of ${sold}, ${formatAmount(amountIn * BigInt(input.times), inputToken.decimals)} of ${sold} in all, escrowed now`,
126
+ `Schedule: the orders open from ${formatTime(opens[0])} to ${formatTime(last)}; the last expires ${formatTime(last + life)}`,
127
+ ...first["summary"],
128
+ ];
129
+ const warned = first["warnings"];
130
+ const warnings = [
131
+ ...warned,
132
+ WARN_EARLY,
133
+ ...(last + life - now > LONG_LIVED_SECONDS && !warned.includes(WARN_LONG_LIVED) ? [WARN_LONG_LIVED] : []),
134
+ ];
135
+ if (input.send !== true) {
136
+ return { orders: opens.map((opens_at) => ({ opens_at })), summary: plan, warnings, ...shown, sent: false, next: first["next"] };
137
+ }
138
+ const orders = [{ opens_at: opens[0], intent: first["intent"], nonce: first["nonce"], signature: first["signature"] }];
139
+ for (const open of opens.slice(1)) {
140
+ try {
141
+ const made = (await offered(ctx, call, { ...input, send: true }, terms(open)));
142
+ orders.push({ opens_at: open, intent: made["intent"], nonce: made["nonce"], signature: made["signature"] });
143
+ }
144
+ catch (error) {
145
+ for (const undo of call.undo.splice(0)) {
146
+ undo();
147
+ }
148
+ const problem = problemOf(error);
149
+ return {
150
+ orders: [...orders, ...opens.slice(orders.length).map((opens_at) => ({ opens_at }))],
151
+ summary: plan,
152
+ warnings,
153
+ ...shown,
154
+ sent: true,
155
+ next: refusedBeforeSending(error)
156
+ ? partlySent(orders.length, input.times, `${problem.code}: ${problem.hint}`)
157
+ : mayHaveLanded(orders.length, input.times, `${problem.code}: ${problem.hint}`),
158
+ };
159
+ }
160
+ }
161
+ return { orders, summary: plan, warnings, ...shown, sent: true };
162
+ },
163
+ });
164
+ export const walletAuction = define({
165
+ name: tool("wallet_auction"),
166
+ title: "Auction from the wallet",
167
+ description: "Offer an exact amount of one token in a Dutch auction from this server's wallet: the least it accepts starts at start_receive once the offer lands, falls in a straight line to end_receive over falls_over seconds, then stays there until it expires, so a solver fills it as soon as the asked amount meets what it can pay. Amounts are whole tokens such as 0.05. Selling SOL wraps it first. Without send it only previews; show the user the summary and call again with send: true once they approve.",
168
+ effect: "submit",
169
+ repeats: true,
170
+ input: object({
171
+ sell: text("SOL, TEST or a mint address"),
172
+ buy: text("SOL, TEST or a mint address"),
173
+ amount: text("whole tokens to sell, such as 0.05"),
174
+ start_receive: text("whole tokens asked when the auction starts; at least end_receive"),
175
+ end_receive: text("least whole tokens accepted once the asked amount stops falling"),
176
+ falls_over: integer(MIN_EXPIRES_IN, MAX_EXPIRES_IN, "seconds the asked amount takes to fall from start_receive to end_receive"),
177
+ expires_in: optional(integer(MIN_EXPIRES_IN, MAX_EXPIRES_IN, `least seconds the offer stays open once sent, never less than falls_over; default ${DEFAULT_EXPIRES_IN}`)),
178
+ pay_to: optional(account(PAY_TO)),
179
+ send: optional(flag("true signs and sends; leave out to preview")),
180
+ }),
181
+ output: offerOutput,
182
+ run: async (ctx, input, call) => offered(ctx, call, input, (sold, bought, now) => {
183
+ const start = now + BigInt(LANDING_SECONDS);
184
+ return {
185
+ order: {
186
+ kind: "dutch",
187
+ amount_in: raw(input.amount, sold.decimals, "amount"),
188
+ start_out: raw(input.start_receive, bought.decimals, "start_receive"),
189
+ end_out: raw(input.end_receive, bought.decimals, "end_receive"),
190
+ start_time: start,
191
+ end_time: start + BigInt(input.falls_over),
192
+ },
193
+ expires_at: start + BigInt(Math.max(input.expires_in ?? DEFAULT_EXPIRES_IN, input.falls_over)),
194
+ };
195
+ }),
196
+ });
197
+ export const ESTIMATE_NEXT = "solvers pay the least an intent asks, so these fills show what owners asked and got, not the most a solver would pay; ask a minimum near receive_at_median, since a single fill can be staged by one party on both sides, or auction from a little above it down to the least the user accepts to find the price";
198
+ export const NO_FILLS = `no recent fill sold this token for that one; auction from a high ask down to the least the user accepts with ${tool("wallet_auction")} to find the price`;
199
+ export const walletEstimate = define({
200
+ name: tool("wallet_estimate"),
201
+ title: "Estimate a swap from recent fills",
202
+ description: `Estimate what selling an amount of one token for another gets now, from the rates of recent fills of the same pair on this cluster. It reads the engine's last ${ESTIMATE_SCAN} transactions and sends nothing. Use it before ${tool("wallet_swap")} or ${tool("wallet_auction")} to pick min_receive or the auction's start and end.`,
203
+ effect: "read",
204
+ input: object({
205
+ sell: text("SOL, TEST or a mint address"),
206
+ buy: text("SOL, TEST or a mint address"),
207
+ amount: text("whole tokens to sell, such as 0.05"),
208
+ }),
209
+ output: object({
210
+ fills: list(object({
211
+ sold: text("whole tokens of the sold token"),
212
+ received: text("whole tokens the owner received"),
213
+ at: optional(time("when the fill landed")),
214
+ signature: text(),
215
+ }), ESTIMATE_FILLS, "newest first"),
216
+ receive_at_best: optional(text("whole tokens amount would get at the best recent rate; one fill can be staged by its own two sides")),
217
+ receive_at_median: optional(text("whole tokens amount would get at the median recent rate")),
218
+ receive_at_latest: optional(text("whole tokens amount would get at the newest fill's rate")),
219
+ next: text(),
220
+ }),
221
+ run: async (ctx, input) => {
222
+ const wallet = await testCluster(ctx);
223
+ const inputMint = mintNamed(input.sell, wallet.url, "sell");
224
+ const outputMint = mintNamed(input.buy, wallet.url, "buy");
225
+ const [inputToken, outputToken] = await Promise.all([mintOf(ctx.transport, inputMint), mintOf(ctx.transport, outputMint)]);
226
+ const amount = raw(input.amount, inputToken.decimals, "amount");
227
+ const matching = await recentFills(ctx.transport, inputMint, outputMint);
228
+ const shown = matching.map((f) => ({
229
+ sold: formatAmount(f.amountIn, inputToken.decimals),
230
+ received: formatAmount(f.delivered, outputToken.decimals),
231
+ ...(f.blockTime === null ? {} : { at: f.blockTime }),
232
+ signature: f.signature,
233
+ }));
234
+ const [latest] = matching;
235
+ if (latest === undefined) {
236
+ return { fills: shown, next: NO_FILLS };
237
+ }
238
+ const best = bestOf(matching) ?? latest;
239
+ const at = (f) => formatAmount((amount * f.delivered) / f.amountIn, outputToken.decimals);
240
+ return { fills: shown, receive_at_best: at(best), receive_at_median: at(medianOf(matching) ?? latest), receive_at_latest: at(latest), next: ESTIMATE_NEXT };
241
+ },
242
+ });
243
+ //# sourceMappingURL=trade.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trade.js","sourceRoot":"","sources":["../../../../src/agent/wallet/trade.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAqB,MAAM,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAChH,OAAO,EACL,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,MAAM,EACN,WAAW,EACX,SAAS,EACT,GAAG,EACH,OAAO,EACP,SAAS,EACT,SAAS,EACT,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM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,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC1C,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC;QACxC,MAAM,EAAE,GAAG,CAAC,CAAO,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;QAChG,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,iBAAiB,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,EAAE,iBAAiB,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;IAC9J,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const WAIT_STATUS: readonly ["open", "filling", "filled", "cancelled", "expired", "closed"];
2
+ export declare const UNREAD: string;
3
+ export declare const FILL_UNKNOWN: string;
4
+ export declare const stillWaiting: (status: string) => string;
5
+ export declare const walletWait: import("../actions.js").AnyAction;
@@ -0,0 +1,99 @@
1
+ import { findIntentPda, formatAmount, getIntentDecoder } from "@intent-engine/core";
2
+ import { mintOf, unmemoized } from "@intent-engine/client";
3
+ import { define } from "../actions.js";
4
+ import { tool } from "../names.js";
5
+ import { account, amount, choice, integer, object, optional, text } from "../schema.js";
6
+ import { STATUS } from "../../accounts.js";
7
+ import { WAIT_DEFAULT, WAIT_MAX, access, signerOf, nameOf } from "./guard.js";
8
+ import { historyIn } from "./fills.js";
9
+ import { HISTORY_PAGES, releaseLookup, releasedMint, createdMint } from "./releases.js";
10
+ export const WAIT_STATUS = ["open", "filling", "filled", "cancelled", "expired", "closed"];
11
+ export const UNREAD = `the node could not yet return all of this intent's transactions, so whether it filled is unknown; call ${tool("wallet_wait")} again in a few seconds before acting on it`;
12
+ export const FILL_UNKNOWN = `this intent's history could not be read in full, so what its fills delivered is unknown: it is longer than the ${HISTORY_PAGES} pages read or the RPC node's ledger does not reach back to its creation; ${tool("wallet_balance")} shows what the wallet holds now`;
13
+ export const stillWaiting = (status) => `still ${status}; call ${tool("wallet_wait")} again to keep waiting, or ${tool("wallet_cancel")} to take the escrow back`;
14
+ export const walletWait = define({
15
+ name: tool("wallet_wait"),
16
+ title: "Wait for a wallet intent",
17
+ description: `Wait until an intent of this server's wallet is filled, cancelled or expired, or until within seconds pass, then say which and, for a fill, how much it delivered to this wallet or to the pay_to it named, or for a released escrow, how much it paid out. Use it after sending instead of asking the user to check again; call it again while the status is still open.`,
18
+ effect: "read",
19
+ input: object({
20
+ nonce: amount("the intent's nonce, from the send or wallet_intents"),
21
+ within: optional(integer(1, WAIT_MAX, `most seconds to wait; default ${WAIT_DEFAULT}`)),
22
+ }),
23
+ output: object({
24
+ intent: account(),
25
+ status: choice(WAIT_STATUS, "closed means the account is gone and its recent transactions name no fill, cancel or expiry"),
26
+ waited: integer(0, WAIT_MAX, "seconds waited"),
27
+ received: optional(text("whole tokens the fills of a swap delivered, to this wallet or the pay_to it named")),
28
+ paid_out: optional(text("whole tokens the release of this wallet's escrow paid to its payee or split recipients, out of what the escrow held")),
29
+ token: optional(text("the token received or paid out")),
30
+ signature: optional(text("the fill's or release's transaction")),
31
+ next: optional(text()),
32
+ }),
33
+ run: async (ctx, input) => {
34
+ const wallet = access(ctx);
35
+ const owner = (await signerOf(ctx)).address;
36
+ const [intent] = await findIntentPda({ owner, nonce: input.nonce });
37
+ const within = input.within ?? WAIT_DEFAULT;
38
+ const fresh = unmemoized(ctx.transport);
39
+ const deadline = wallet.now() + BigInt(within);
40
+ let waited = 0;
41
+ let pair = null;
42
+ let status = "closed";
43
+ for (;;) {
44
+ const view = await fresh.getAccount(intent);
45
+ if (view === null) {
46
+ status = "closed";
47
+ break;
48
+ }
49
+ const decoded = getIntentDecoder().decode(view.data);
50
+ pair = { inputMint: decoded.inputMint, outputMint: decoded.outputMint };
51
+ status = STATUS[decoded.status] ?? "open";
52
+ if ((status !== "open" && status !== "filling") || waited >= within || wallet.now() >= deadline || !(await wallet.sleep(1))) {
53
+ break;
54
+ }
55
+ waited += 1;
56
+ }
57
+ if (status === "open" || status === "filling") {
58
+ return { intent, status, waited, next: stillWaiting(status) };
59
+ }
60
+ if (status === "cancelled" || status === "expired") {
61
+ return { intent, status, waited };
62
+ }
63
+ const { release, transactions, complete, bound } = await releaseLookup(ctx.transport, intent);
64
+ const history = historyIn(transactions);
65
+ if (release !== null && !bound) {
66
+ return { intent, status, waited, next: FILL_UNKNOWN };
67
+ }
68
+ if (release !== null) {
69
+ const fields = release.event.fields;
70
+ const mint = pair?.inputMint ?? createdMint(transactions, intent) ?? releasedMint(release.tx, intent, fields["payee"]);
71
+ const decimals = mint === undefined ? undefined : (await mintOf(ctx.transport, mint)).decimals;
72
+ return {
73
+ intent,
74
+ status: "filled",
75
+ waited,
76
+ paid_out: formatAmount(fields["net"], decimals),
77
+ ...(mint === undefined ? {} : { token: nameOf(mint) }),
78
+ signature: release.tx.signature,
79
+ };
80
+ }
81
+ const fills = history.fills.filter((f) => f.intent === intent);
82
+ if (fills.length === 0) {
83
+ const ended = status === "closed" ? (history.ended.get(intent) ?? status) : status;
84
+ const unknown = ended === "closed" || ended === "filled";
85
+ return { intent, status: ended, waited, ...(unknown && history.unread > 0 ? { next: UNREAD } : unknown && !complete ? { next: FILL_UNKNOWN } : {}) };
86
+ }
87
+ pair ??= history.created.get(intent) ?? null;
88
+ const decimals = pair === null ? undefined : (await mintOf(ctx.transport, pair.outputMint)).decimals;
89
+ return {
90
+ intent,
91
+ status: "filled",
92
+ waited,
93
+ received: formatAmount(fills.reduce((sum, f) => sum + f.delivered, 0n), decimals),
94
+ ...(pair === null ? {} : { token: nameOf(pair.outputMint) }),
95
+ signature: fills[0]?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AC,EAAE,QAAQ,CAAC;YACjF,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC5D,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS;SAC/B,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -1,74 +1,20 @@
1
- import { type Address } from "@solana/kit";
2
- import { type Env, type WalletLimits } from "../args.js";
3
- import { type Files } from "../wallet.js";
4
- import { type AnyAction } from "./actions.js";
5
- type Sale = {
6
- mint: Address;
7
- at: bigint;
8
- amount: bigint;
9
- };
10
- export type WalletGuard = {
11
- limits: WalletLimits;
12
- sales: Sale[];
13
- };
14
- export declare const walletGuard: (limits: WalletLimits) => WalletGuard;
15
- export type WalletAccess = {
16
- url: string;
17
- files: Files;
18
- env: Env;
19
- sleep(seconds: number): Promise<boolean>;
20
- now(): bigint;
21
- limits: WalletGuard;
22
- };
23
- export declare const SALE_WINDOW = 3600n;
24
- export declare const ESTIMATE_SCAN = 12;
25
- export declare const ESTIMATE_FILLS = 5;
26
- export declare const WAIT_DEFAULT = 30;
27
- export declare const WAIT_MAX = 40;
28
- export declare const WAIT_SCAN = 10;
29
- export declare const DEFAULT_EXPIRES_IN = 3600;
30
- export declare const LANDING_SECONDS = 10;
31
- export declare const MAINNET_GENESIS = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
32
- export declare const WALLET_NOTICE: string[];
33
- export declare const walletEmpty: (address: string) => string;
34
- export declare const NO_WALLET: string;
35
- export declare const WALLET_OFF = "this server runs without a wallet; start it with mcp --wallet to let it sign";
36
- export declare const PREVIEW_ONLY = "nothing was sent; show the summary to the user and call again with send: true only after they approve";
37
- export declare function limitLines(limits: WalletLimits): string[];
38
- export declare const walletBalance: AnyAction;
39
- export declare const SWAP_FALLS_OVER = 120;
40
- export declare const PAY_TO = "the wallet that receives what is bought, such as someone this wallet pays; default this wallet. This wallet pays for its token account if it has none";
41
- export declare const SWAP_HEADROOM_BPS = 200n;
42
- export declare const SWAP_BLIND_BPS = 2500n;
43
- export declare const SWAP_CAP_BPS = 20000n;
44
- export declare const ESCROW_EXPIRES_IN = 86400;
45
- export declare const RECORD_MINT_NEEDED = "selling SOL on this RPC needs record_mint: any other token's mint, which only labels the escrow";
46
- export declare const MAX_PIECES = 12;
47
- export declare const piecesPartlySent: (sent: number, total: number, problem: string) => string;
48
- export declare const piecesMayHaveLanded: (sent: number, total: number, problem: string) => string;
49
- export declare const PAYEE_MOVED = "this wallet's token account for the escrowed token now belongs to someone else, so a release would not reach it; ask the payee for another wallet";
50
- export declare const RELEASE_CHANGED = "this release differs from its preview: the payee, amount, result, fee or the escrow itself changed, or no approval was given; preview it again and show the user";
51
- export declare const approvalOf: (message: Uint8Array, memo?: string) => string;
52
- export declare const notEarliest: (worker: string, sha256: string) => string;
53
- export declare const DELIVERY_LIST: number;
54
- export declare const notAttestor: (attestor: string) => string;
55
- export declare const PACKET_DATA_SIZE = 1232;
56
- export declare const splitTooLarge: (size: number, recipients: number, withTable: boolean) => string;
57
- export declare const SPLIT_WEIGHTS_WRONG = "the weights must be whole basis points that add up to 10000";
58
- export declare const SPLIT_SIG_NEEDED = "every co-author must sign the split before send: true; preview returns the envelope each one signs";
59
- export declare const SIGNATURE_PATTERN = "^[0-9a-fA-F]{128}$";
60
- export declare const WARN_COAUTHORS = "every co-author must sign the exact split; a release pays only the recipients and weights they all signed";
61
- export declare const MAX_RECURRING = 12;
62
- export declare const mayHaveLanded: (sent: number, times: number, problem: string) => string;
63
- export declare const partlySent: (sent: number, times: number, problem: string) => string;
64
- export declare const WARN_EARLY = "an order fills before its turn if a solver can already pay its start_receive";
65
- export declare const NO_FALL = "must be more than 0, or the orders have no ask to fall";
66
- export declare const MAX_EVERY: number;
67
- export declare const ESTIMATE_NEXT = "solvers pay the least an intent asks, so these fills show what owners asked and got, not the most a solver would pay; ask a minimum near receive_at_median, since a single fill can be staged by one party on both sides, or auction from a little above it down to the least the user accepts to find the price";
68
- export declare const NO_FILLS: string;
69
- export declare const WAIT_STATUS: readonly ["open", "filling", "filled", "cancelled", "expired", "closed"];
70
- export declare const UNREAD: string;
71
- export declare const stillWaiting: (status: string) => string;
72
- export declare const NOT_RELEASED: string;
1
+ import type { AnyAction } from "./actions.js";
2
+ export { walletGuard, SALE_WINDOW, ESTIMATE_SCAN, ESTIMATE_FILLS, WAIT_DEFAULT, WAIT_MAX, WAIT_SCAN, DEFAULT_EXPIRES_IN, LANDING_SECONDS, MAINNET_GENESIS, WALLET_NOTICE, walletEmpty, NO_WALLET, WALLET_OFF, PREVIEW_ONLY, limitLines, rpcRefused, } from "./wallet/guard.js";
3
+ export type { WalletGuard, WalletAccess } from "./wallet/guard.js";
4
+ export { walletBalance } from "./wallet/account.js";
5
+ export { nonceTaken } from "./wallet/offer.js";
6
+ export { SWAP_HEADROOM_BPS, SWAP_BLIND_BPS, SWAP_CAP_BPS } from "./wallet/fills.js";
7
+ export { SWAP_FALLS_OVER, PAY_TO, MAX_RECURRING, mayHaveLanded, partlySent, WARN_EARLY, NO_FALL, MAX_EVERY, ESTIMATE_NEXT, NO_FILLS, } from "./wallet/trade.js";
8
+ export { ESCROW_EXPIRES_IN, RECORD_MINT_NEEDED, MAX_PIECES, piecesPartlySent, piecesMayHaveLanded } from "./wallet/escrow.js";
9
+ export { PAYEE_MOVED, RELEASE_CHANGED, approvalOf } from "./wallet/attest.js";
10
+ export { NOT_A_MEMBER, VOTE_CHANGED } from "./wallet/committee.js";
11
+ export { notEarliest, notInSplit, DELIVERY_LIST, DELIVERED_NEEDED, ATTEST_PAGES, MAX_ATTEST_PAGES, HISTORY_TOO_LONG, checkDelivery, prepareDeliver, notAttestor, } from "./wallet/delivery.js";
12
+ export { SPLIT_FITS, SPLIT_FITS_WITH_TABLE, splitTooLarge, RECORDS_SPLIT, followUpFailed, SPLIT_WEIGHTS_WRONG, SPLIT_SIG_NEEDED, SIGNATURE_PATTERN, WARN_COAUTHORS, } from "./wallet/split.js";
13
+ export { RELEASE_INPUT, RELEASE_SIGNATURE, releaseOf, notReleasedYet, alreadyRecorded, releasedBy, escrowGone, creationUnread, notAProofEscrow, neverAnnounced, paidOther, splitPaidOthers, recipientsUnread, followUpsUnknown, historyLagging, otherLifecycle, COVERAGE_UNPROVABLE, coverageOf, recordingOf, } from "./wallet/record.js";
14
+ export type { Recording } from "./wallet/record.js";
15
+ export { releaseNotOf, releaseUnread, HISTORY_PAGES, escrowHistory, RELEASE_PAGES, RELEASE_UNKNOWN, LIFECYCLE_FETCHES, outlives, releaseLookup, aroundRelease, namedRelease, releasedMint, SPLIT_INTENT_ACCOUNT, splitRecipients, } from "./wallet/releases.js";
16
+ export type { ReleaseLookup, AroundRelease } from "./wallet/releases.js";
17
+ export { WAIT_STATUS, UNREAD, FILL_UNKNOWN, stillWaiting } from "./wallet/wait.js";
18
+ export { NOT_RELEASED, RECEIPT_PARTIAL, getReceipt, escrowReceipt } from "./wallet/receipt.js";
19
+ export { PACKET_DATA_SIZE } from "@intent-engine/client";
73
20
  export declare const WALLET_ACTIONS: readonly AnyAction[];
74
- export {};