@esseyonsui/sui-mcp-v3 0.1.9 → 0.2.1

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 (49) hide show
  1. package/README.md +37 -7
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +2 -2
  4. package/dist/args.d.ts +11 -2
  5. package/dist/args.d.ts.map +1 -1
  6. package/dist/args.js +37 -10
  7. package/dist/client.d.ts +1 -1
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +5 -3
  10. package/dist/config.d.ts +2 -0
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +5 -0
  13. package/dist/fund.d.ts.map +1 -1
  14. package/dist/fund.js +2 -2
  15. package/dist/handles.d.ts +23 -0
  16. package/dist/handles.d.ts.map +1 -0
  17. package/dist/handles.js +142 -0
  18. package/dist/http.d.ts +6 -0
  19. package/dist/http.d.ts.map +1 -0
  20. package/dist/http.js +5 -0
  21. package/dist/init.d.ts +1 -0
  22. package/dist/init.d.ts.map +1 -1
  23. package/dist/init.js +10 -5
  24. package/dist/io.d.ts +19 -11
  25. package/dist/io.d.ts.map +1 -1
  26. package/dist/io.js +192 -138
  27. package/dist/keys.d.ts +2 -0
  28. package/dist/keys.d.ts.map +1 -1
  29. package/dist/keys.js +14 -1
  30. package/dist/main.js +19 -8
  31. package/dist/records.d.ts +17 -1
  32. package/dist/records.d.ts.map +1 -1
  33. package/dist/records.js +39 -5
  34. package/dist/reveal.d.ts +7 -0
  35. package/dist/reveal.d.ts.map +1 -0
  36. package/dist/reveal.js +40 -0
  37. package/dist/snapshot.d.ts +13 -0
  38. package/dist/snapshot.d.ts.map +1 -0
  39. package/dist/snapshot.js +29 -0
  40. package/dist/tools-badge.js +3 -3
  41. package/dist/tools-more.d.ts +9 -5
  42. package/dist/tools-more.d.ts.map +1 -1
  43. package/dist/tools-more.js +56 -12
  44. package/dist/tools-sales.d.ts.map +1 -1
  45. package/dist/tools-sales.js +34 -24
  46. package/dist/tools.d.ts +3 -0
  47. package/dist/tools.d.ts.map +1 -1
  48. package/dist/tools.js +64 -30
  49. package/package.json +4 -3
package/dist/main.js CHANGED
@@ -6,28 +6,33 @@ import { graphqlExecute, itemHandOver } from "./agent.js";
6
6
  import { clientOf, withInvite } from "./client.js";
7
7
  import { ConfigError, parseConfig } from "./config.js";
8
8
  import { agentDepositIo } from "./fund.js";
9
+ import { handlesFor } from "./handles.js";
10
+ import { plainFetch } from "./http.js";
9
11
  import { chainIo } from "./io.js";
10
- import { loadAgentKey, loadNoteSeed } from "./keys.js";
12
+ import { keyInside, loadAgentKey, loadNoteSeed } from "./keys.js";
11
13
  import { toolPace } from "./pace.js";
12
14
  import { serve } from "./protocol.js";
13
- import { fileRecords, recordKey } from "./records.js";
15
+ import { fileRecords, recordKey, stateKey } from "./records.js";
14
16
  import { bind } from "./tools.js";
15
17
  const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"))
16
18
  .version;
17
19
  const INSTRUCTIONS = "Essey V3 private testnet tools. Note and agent keys are files on this server, never tool arguments, and no tool " +
18
20
  "returns a key, seed, or spend secret. The invite, when there is one, is ESSEY_INVITE. Amounts are whole-number " +
19
- "strings in the coin's smallest unit. The server builds every proof itself and keeps loan terms, offer, seller " +
21
+ "strings in the coin's smallest unit. Unless the operator set ESSEY_MCP_OUTPUT=clear, results name ids, digests " +
22
+ "and amounts by handles (h_ and 16 hex digits); pass a handle wherever a tool takes that value. " +
23
+ "The server builds every proof itself and keeps loan terms, offer, seller " +
20
24
  "and bid records in its own files; no tool returns them. Borrow: essey_loan_open, wait for the window, " +
21
25
  "essey_loan_settle, essey_loan_repay, essey_loan_release. Lend: essey_loan_list, essey_loan_request, " +
22
26
  "essey_loan_offer, then essey_loan_collect after repay or essey_loan_reclaim if the offer lost. Refinance: " +
23
27
  "essey_loan_refi_open, lenders offer, essey_loan_refi_settle; the old lender calls essey_loan_collect. Keeper: " +
24
28
  "essey_keeper_judge, then essey_keeper_liquidate or essey_keeper_fault, after which the lender calls " +
25
- "essey_loan_fault_liquidate. essey_notes_deposit is paid from the agent wallet. Sell: put the item at " +
26
- "essey_agent_address, essey_sale_open, after close essey_sale_finish (essey_sale_slash each bid it names " +
29
+ "essey_loan_fault_liquidate. essey_notes_deposit is paid from the agent wallet. Sell: put the item at a fresh " +
30
+ "essey_item_address (essey_badge_grant does), essey_sale_open, after close essey_sale_finish (essey_sale_slash each bid it names " +
27
31
  "first); or essey_sale_cancel before any bid, or essey_sale_expire after the finish window, then " +
28
32
  "essey_sale_claim as seller. Buy: essey_sale_list, essey_sale_bid, and once the room ended essey_sale_claim as " +
29
33
  "bidder if won and essey_sale_reclaim (residual if won, else the deposit). A proved call may answer NOT_BEFORE " +
30
- "with notBeforeMs: nothing was sent; make the same call again at or after that time.";
34
+ "with notBeforeMs: nothing was sent; make the same call again at or after that time. A split essey_notes_withdraw " +
35
+ "or essey_notes_exit pays one piece; call essey_notes_withdraw_continue at or after notBeforeMs until left is 0.";
31
36
  /**
32
37
  * `source` is what `Essey.connect` takes: the URL, which names the v3api, or the parsed file. The io reads the
33
38
  * same record as JSON (Seal set, pools, circuit pins).
@@ -40,7 +45,7 @@ async function deploymentOf(cfg) {
40
45
  }
41
46
  async function fetchJson(url) {
42
47
  try {
43
- const res = await fetch(url);
48
+ const res = await plainFetch(url);
44
49
  if (res.status !== 200)
45
50
  throw new Error("status");
46
51
  return await res.json();
@@ -76,6 +81,8 @@ async function start() {
76
81
  const cfg = parseConfig(process.env);
77
82
  const agent = loadAgentKey(cfg.agentKeyFile);
78
83
  const seed = loadNoteSeed(cfg.noteKeyFile);
84
+ if (keyInside(cfg.noteKeyFile, cfg.stateFile))
85
+ process.stderr.write("essey-v3-mcp: ESSEY_NOTE_KEY_FILE is inside the state directory, so a copy of that directory opens the records; move it apart\n");
79
86
  try {
80
87
  const { source, raw } = await deploymentOf(cfg);
81
88
  const io = chainIo(raw, { graphql: cfg.graphql, artifactDir: `${dirname(cfg.stateFile)}/artifacts` });
@@ -90,17 +97,21 @@ async function start() {
90
97
  statePath: cfg.stateFile,
91
98
  config: source,
92
99
  seed,
100
+ stateKey: stateKey(seed),
93
101
  relayer: cfg.relayer,
94
102
  delays: cfg.delays,
95
103
  }, { ...io, ...agentDepositIo(raw, cfg.agentKeyFile, cfg.graphql), deliverSaleItem, pace: toolPace() });
96
104
  const sale = { agentAddress: agent.toSuiAddress(), vaultOf: io.readVaultOf };
97
105
  const client = withInvite(clientOf(essey, sale), cfg.invite);
106
+ const dir = dirname(cfg.stateFile);
107
+ const key = recordKey(seed);
98
108
  const tools = bind({
99
109
  client,
100
- records: fileRecords(dirname(cfg.stateFile), recordKey(seed)),
110
+ records: fileRecords(dir, key),
101
111
  redact: cfg.invite ? [cfg.invite] : [],
102
112
  onError: (line) => process.stderr.write(`essey-v3-mcp: ${line}\n`),
103
113
  waitIndexed: io.waitIndexed,
114
+ handles: handlesFor(cfg.output, dir, key),
104
115
  });
105
116
  process.stderr.write("essey-v3-mcp: testnet, note key and agent key files accepted\n");
106
117
  await serve(tools, { name: "essey-v3", version: VERSION, instructions: INSTRUCTIONS }, process.stdin, process.stdout);
package/dist/records.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Essey, SaleRecord } from "@esseyonsui/sui-sdk-v3";
1
+ import type { Essey, Pending, SaleRecord } from "@esseyonsui/sui-sdk-v3";
2
2
  export type Terms = Parameters<Essey["loans"]["payBack"]>[0]["terms"];
3
3
  export type OfferRecord = Awaited<ReturnType<Essey["loans"]["lend"]>>["offer"];
4
4
  export type BidRecord = Awaited<ReturnType<Essey["sales"]["bid"]>>["bid"];
@@ -24,6 +24,12 @@ export type Records = {
24
24
  saveSale(room: string, record: SaleRecord): void;
25
25
  bid(room: string): BidRecord;
26
26
  saveBid(room: string, record: BidRecord): void;
27
+ /** Every record held, opened. Only the local reveal CLI prints it; no tool returns it. */
28
+ all(): {
29
+ kind: string;
30
+ id: string;
31
+ record: Record<string, unknown> | null;
32
+ }[];
27
33
  /** Every record into one new sealed mode-600 file at `path`. Returns how many it holds. */
28
34
  exportTo(path: string): number;
29
35
  /** The records of an `exportTo` file. One this server already holds is kept, not overwritten. */
@@ -31,8 +37,18 @@ export type Records = {
31
37
  imported: number;
32
38
  kept: number;
33
39
  };
40
+ /** PRV-11: a split payout's unpaid pieces, sealed in `payouts.json`; null when none is pending. */
41
+ payouts(): Pending | null;
42
+ /** null deletes the file. */
43
+ savePayouts(pending: Pending | null): void;
34
44
  };
35
45
  /** The records key: HKDF-SHA256 of the note seed under a fixed label, so the seed itself never leaves `main.ts`. */
36
46
  export declare function recordKey(seed: Uint8Array): Uint8Array;
47
+ /** PRV-36a: the SDK state file's sealing key, under its own label so it never equals the records key. */
48
+ export declare function stateKey(seed: Uint8Array): Uint8Array;
49
+ /** `label` is the AAD: a sealed file opens only under the name it was written for. */
50
+ export declare function seal(key: Uint8Array, label: string, v: unknown): string;
51
+ export declare function unseal(key: Uint8Array, label: string, sealed: string): Record<string, unknown>;
52
+ export declare function writePrivate(target: string, text: string): void;
37
53
  export declare function fileRecords(dir: string, key: Uint8Array): Records;
38
54
  //# sourceMappingURL=records.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../src/records.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAQhE,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AACtE,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AAC/E,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,CA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+1,12 @@
1
1
  import { randomBytes } from "node:crypto";
2
- import { chmodSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from "node:fs";
2
+ import { chmodSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, unlinkSync, writeFileSync, } from "node:fs";
3
3
  import { isAbsolute, join } from "node:path";
4
4
  import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
5
5
  import { hkdf } from "@noble/hashes/hkdf.js";
6
6
  import { hmac } from "@noble/hashes/hmac.js";
7
7
  import { sha256 } from "@noble/hashes/sha2.js";
8
8
  import { ToolRefusal } from "./failure.js";
9
+ const PAYOUTS = "payouts.json";
9
10
  const LOAN_ID = /^0x[0-9a-f]{64}$/;
10
11
  const NAMED_FILE = /^(loan|offer|sale|bid)-(0x[0-9a-f]{64})\.json$/;
11
12
  const BLIND_FILE = /^r-[0-9a-f]{32}\.json$/;
@@ -28,18 +29,22 @@ function noRecord(kind) {
28
29
  export function recordKey(seed) {
29
30
  return hkdf(sha256, seed, undefined, utf8("essey-v3-mcp records v1"), 32);
30
31
  }
32
+ /** PRV-36a: the SDK state file's sealing key, under its own label so it never equals the records key. */
33
+ export function stateKey(seed) {
34
+ return hkdf(sha256, seed, undefined, utf8("essey-v3-mcp state v1"), 32);
35
+ }
31
36
  /** `label` is the AAD: a sealed file opens only under the name it was written for. */
32
- function seal(key, label, v) {
37
+ export function seal(key, label, v) {
33
38
  const nonce = randomBytes(NONCE);
34
39
  const box = xchacha20poly1305(key, nonce, utf8(label)).encrypt(utf8(plain(v)));
35
40
  return JSON.stringify({ sealed: Buffer.concat([nonce, box]).toString("base64") });
36
41
  }
37
- function unseal(key, label, sealed) {
42
+ export function unseal(key, label, sealed) {
38
43
  const bytes = Buffer.from(sealed, "base64");
39
44
  const text = xchacha20poly1305(key, bytes.subarray(0, NONCE), utf8(label)).decrypt(bytes.subarray(NONCE));
40
45
  return JSON.parse(new TextDecoder().decode(text));
41
46
  }
42
- function writePrivate(target, text) {
47
+ export function writePrivate(target, text) {
43
48
  const tmp = `${target}.${randomBytes(6).toString("hex")}.tmp`;
44
49
  writeFileSync(tmp, text, { mode: 0o600, flag: "wx" });
45
50
  chmodSync(tmp, 0o600);
@@ -110,6 +115,7 @@ export function fileRecords(dir, key) {
110
115
  const row = BLIND_FILE.test(n) ? opened(n) : null;
111
116
  return row ? [{ kind: row.kind, id: row.id }] : [];
112
117
  });
118
+ const all = () => held().map(({ kind, id }) => ({ kind, id, record: read(kind, id) }));
113
119
  for (const n of names()) {
114
120
  const m = NAMED_FILE.exec(n);
115
121
  if (!m)
@@ -168,8 +174,9 @@ export function fileRecords(dir, key) {
168
174
  };
169
175
  },
170
176
  saveBid: (room, record) => write("bid", room, record),
177
+ all,
171
178
  exportTo: (target) => {
172
- const records = held().map(({ kind, id }) => ({ kind, id, record: read(kind, id) }));
179
+ const records = all();
173
180
  try {
174
181
  writeFileSync(absolute(target), seal(key, EXPORT_LABEL, { records }), { mode: 0o600, flag: "wx" });
175
182
  }
@@ -201,5 +208,32 @@ export function fileRecords(dir, key) {
201
208
  }
202
209
  return { imported, kept: rows.length - imported };
203
210
  },
211
+ payouts: () => {
212
+ let text;
213
+ try {
214
+ text = readFileSync(join(dir, PAYOUTS), "utf8");
215
+ }
216
+ catch (err) {
217
+ if (err.code === "ENOENT")
218
+ return null;
219
+ throw err;
220
+ }
221
+ const r = unseal(key, PAYOUTS, JSON.parse(text).sealed);
222
+ return {
223
+ coin: r.coin,
224
+ pieces: r.pieces.map((p) => ({
225
+ amount: BigInt(p.amount),
226
+ to: p.to,
227
+ })),
228
+ notBeforeMs: r.notBeforeMs,
229
+ spent: r.spent,
230
+ };
231
+ },
232
+ savePayouts: (pending) => {
233
+ if (pending === null)
234
+ return rmSync(join(dir, PAYOUTS), { force: true });
235
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
236
+ writePrivate(join(dir, PAYOUTS), seal(key, PAYOUTS, pending));
237
+ },
204
238
  };
205
239
  }
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * PRV-36d: the operator's own view of the sealed records and of the PRV-04 handle table (what each `h_` handle a
4
+ * tool returned stands for), printed on this terminal and never through MCP, so the model never sees it.
5
+ */
6
+ export declare function reveal(env: NodeJS.ProcessEnv): string;
7
+ //# sourceMappingURL=reveal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reveal.d.ts","sourceRoot":"","sources":["../src/reveal.ts"],"names":[],"mappings":";AAUA;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAarD"}
package/dist/reveal.js ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+ import { realpathSync } from "node:fs";
3
+ import { dirname } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { ConfigError } from "./config.js";
6
+ import { handleRows } from "./handles.js";
7
+ import { loadNoteSeed } from "./keys.js";
8
+ import { fileRecords, recordKey } from "./records.js";
9
+ /**
10
+ * PRV-36d: the operator's own view of the sealed records and of the PRV-04 handle table (what each `h_` handle a
11
+ * tool returned stands for), printed on this terminal and never through MCP, so the model never sees it.
12
+ */
13
+ export function reveal(env) {
14
+ const stateFile = env.ESSEY_STATE_FILE;
15
+ const keyFile = env.ESSEY_NOTE_KEY_FILE;
16
+ if (!stateFile || !keyFile)
17
+ throw new ConfigError("ESSEY_STATE_FILE and ESSEY_NOTE_KEY_FILE are required");
18
+ const seed = loadNoteSeed(keyFile);
19
+ try {
20
+ const dir = dirname(stateFile);
21
+ const key = recordKey(seed);
22
+ const shown = { records: fileRecords(dir, key).all(), handles: handleRows(dir, key) };
23
+ return JSON.stringify(shown, (_k, v) => (typeof v === "bigint" ? v.toString() : v), 2);
24
+ }
25
+ finally {
26
+ seed.fill(0);
27
+ }
28
+ }
29
+ function main() {
30
+ try {
31
+ process.stdout.write(`${reveal(process.env)}\n`);
32
+ }
33
+ catch (err) {
34
+ const why = err instanceof ConfigError ? err.message : "the records did not open under this note key";
35
+ process.stderr.write(`essey-sui-mcp-v3-reveal: ${why}\n`);
36
+ process.exit(1);
37
+ }
38
+ }
39
+ if (process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url))
40
+ main();
@@ -0,0 +1,13 @@
1
+ export type Snapshot<T> = {
2
+ /** The held walk while younger than `ttlMs`, otherwise a fresh one. */
3
+ get(): Promise<T>;
4
+ /** `pick` over the held walk; on a miss over an older walk, once more over a fresh one. */
5
+ find<R>(pick: (set: T) => R | undefined): Promise<R | undefined>;
6
+ drop(): void;
7
+ };
8
+ /**
9
+ * PRV-32: one full walk of a public set serves every lookup for `ttlMs`, so no read names the object it wants.
10
+ * A failed walk is not held.
11
+ */
12
+ export declare function snapshot<T>(walk: () => Promise<T>, ttlMs: number, now?: () => number): Snapshot<T>;
13
+ //# sourceMappingURL=snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;IACxB,uEAAuE;IACvE,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAClB,2FAA2F;IAC3F,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IACjE,IAAI,IAAI,IAAI,CAAC;CACd,CAAC;AAEF;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACtB,KAAK,EAAE,MAAM,EACb,GAAG,GAAE,MAAM,MAAiB,GAC3B,QAAQ,CAAC,CAAC,CAAC,CAuBb"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * PRV-32: one full walk of a public set serves every lookup for `ttlMs`, so no read names the object it wants.
3
+ * A failed walk is not held.
4
+ */
5
+ export function snapshot(walk, ttlMs, now = Date.now) {
6
+ let held;
7
+ const fresh = () => held !== undefined && now() - held.at < ttlMs;
8
+ const load = () => {
9
+ const set = walk();
10
+ held = { at: now(), set };
11
+ set.catch(() => {
12
+ if (held?.set === set)
13
+ held = undefined;
14
+ });
15
+ return set;
16
+ };
17
+ const get = () => (fresh() ? held.set : load());
18
+ return {
19
+ get,
20
+ async find(pick) {
21
+ const wasHeld = fresh();
22
+ const hit = pick(await get());
23
+ return hit !== undefined || !wasHeld ? hit : pick(await load());
24
+ },
25
+ drop: () => {
26
+ held = undefined;
27
+ },
28
+ };
29
+ }
@@ -5,13 +5,13 @@ export const BADGE_TOOLS = [
5
5
  {
6
6
  name: "essey_badge_grant",
7
7
  kind: "call",
8
- description: "Seller, testnet: ask the service for one demo Badge to sell, minted to essey_agent_address with the gas " +
9
- "SUI its hand-over needs. Needs a credential; one grant per credential per UTC day. The agent address is " +
8
+ description: "Seller, testnet: ask the service for one demo Badge to sell, minted with a little gas SUI to a fresh " +
9
+ "single-use essey_item_address. Needs a credential; one grant per credential per UTC day. The address is " +
10
10
  "public on chain and the service sees it beside this credential's day-tag. Returns the digest and the " +
11
11
  "itemId and itemType to pass to essey_sale_open.",
12
12
  inputSchema: objectSchema({}, []),
13
13
  run: async (ctx) => {
14
- const { digest, badge } = await ctx.client.sales.badgeGrant(ctx.client.sales.agentAddress);
14
+ const { digest, badge } = await ctx.client.sales.badgeGrant();
15
15
  return { ok: true, digest, itemId: badge, itemType: TESTNET_BADGE_TYPE };
16
16
  },
17
17
  },
@@ -1,16 +1,20 @@
1
- import { type Payout } from "@esseyonsui/sui-sdk-v3";
2
- import type { Tool } from "./tools.ts";
3
- /** The top-level digest is the last piece's, the one `bind` waits to see indexed. */
4
- export declare function paidOut(rows: Payout[]): {
1
+ import { type Staged } from "@esseyonsui/sui-sdk-v3";
2
+ import type { Tool, ToolContext } from "./tools.ts";
3
+ export declare const SPLIT: string;
4
+ /** PRV-11: a pending split is saved before the result returns. No piece amount is returned. */
5
+ export declare function staged(ctx: ToolContext, s: Staged): {
6
+ notBeforeMs?: number | undefined;
5
7
  ok: true;
6
8
  digest: string;
7
9
  payouts: {
8
10
  digest: string;
9
11
  ticket: string;
10
- amount: string;
11
12
  to: string;
12
13
  }[];
14
+ left: number;
13
15
  };
16
+ /** A new plan would spend notes the pending pieces were planned against (`refuseUncovered`). */
17
+ export declare function refuseWhilePaying(ctx: ToolContext): void;
14
18
  /** No SDK call behind either, so they sit outside `MORE`. */
15
19
  export declare const RECORD_TOOLS: Tool[];
16
20
  export declare const MORE: Tool[];
@@ -1 +1 @@
1
- {"version":3,"file":"tools-more.d.ts","sourceRoot":"","sources":["../src/tools-more.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,MAAM,EAAkB,MAAM,wBAAwB,CAAC;AAgB5F,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,YAAY,CAAC;AAsCpD,qFAAqF;AACrF,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE;;;;;;;;;EAMrC;AAiPD,6DAA6D;AAC7D,eAAO,MAAM,YAAY,EAAE,IAAI,EAoB9B,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,IAAI,EAA6C,CAAC"}
1
+ {"version":3,"file":"tools-more.d.ts","sourceRoot":"","sources":["../src/tools-more.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuD,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAiB1G,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAsCpD,eAAO,MAAM,KAAK,QAI0B,CAAC;AAE7C,+FAA+F;AAC/F,wBAAgB,MAAM,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM;;;;;;;;;;EASjD;AAED,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,CAGxD;AAgRD,6DAA6D;AAC7D,eAAO,MAAM,YAAY,EAAE,IAAI,EAoB9B,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,IAAI,EAA6C,CAAC"}
@@ -1,7 +1,7 @@
1
- import { COINS } from "@esseyonsui/sui-sdk-v3";
2
- import { FORCE, LOAN_SCHEMA, OPEN_SCHEMA, PAYEES, int, parseAmount, parseCoin, parseForce, parseLoanId, parsePayees, } from "./args.js";
1
+ import { COINS, isEsseyError } from "@esseyonsui/sui-sdk-v3";
2
+ import { ALLOW_REUSE, FORCE, LOAN_SCHEMA, OPEN_SCHEMA, PAYEES, int, parseAmount, parseCoin, parseLoanId, parsePayees, parseSpend, } from "./args.js";
3
3
  import { isSdkCode, ToolRefusal } from "./failure.js";
4
- import { WAITS_LONG, WAITS_MEDIUM, WAITS_SHORT } from "./pace.js";
4
+ import { NotBefore, WAITS_LONG, WAITS_MEDIUM, WAITS_SHORT } from "./pace.js";
5
5
  /** `move/v3/loan/sources/loan.move:40` MAX_OFFERS = 16. */
6
6
  const MAX_SEQ = 15;
7
7
  const MAX_MS = Number.MAX_SAFE_INTEGER;
@@ -27,14 +27,46 @@ function bad(msg) {
27
27
  function landed(row) {
28
28
  return { ok: true, digest: row.digest, ticket: row.ticket };
29
29
  }
30
- /** The top-level digest is the last piece's, the one `bind` waits to see indexed. */
31
- export function paidOut(rows) {
30
+ export const SPLIT = " With more than one piece the call pays the first and keeps the rest in a sealed file beside the state file; " +
31
+ "essey_notes_withdraw_continue pays each next one a random 2 to 30 min after the last. A listed address this " +
32
+ "server already paid is refused unless allowReuse is true. Spend each piece from its own address: funding or " +
33
+ "sweeping them together joins them again.";
34
+ /** PRV-11: a pending split is saved before the result returns. No piece amount is returned. */
35
+ export function staged(ctx, s) {
36
+ ctx.records.savePayouts(s.pending);
32
37
  return {
33
38
  ok: true,
34
- digest: rows[rows.length - 1].digest,
35
- payouts: rows.map((r) => ({ digest: r.digest, ticket: r.ticket, amount: r.amount.toString(), to: r.to })),
39
+ digest: s.paid.digest,
40
+ payouts: [{ digest: s.paid.digest, ticket: s.paid.ticket, to: s.paid.to }],
41
+ left: s.pending?.pieces.length ?? 0,
42
+ ...(s.pending ? { notBeforeMs: s.pending.notBeforeMs } : {}),
36
43
  };
37
44
  }
45
+ /** A new plan would spend notes the pending pieces were planned against (`refuseUncovered`). */
46
+ export function refuseWhilePaying(ctx) {
47
+ if (ctx.records.payouts())
48
+ bad("a split withdraw or exit is still paying out: call essey_notes_withdraw_continue until left is 0");
49
+ }
50
+ /**
51
+ * Write-ahead: the next piece leaves the file before it is sent, so a crash never pays it twice. A failure puts it
52
+ * back, except an unknown outcome, which may have landed.
53
+ */
54
+ async function continuePayout(ctx) {
55
+ const due = ctx.records.payouts() ?? bad("no split withdraw or exit is paying out");
56
+ if (Date.now() < due.notBeforeMs)
57
+ throw new NotBefore(due.notBeforeMs);
58
+ ctx.records.savePayouts(due.pieces.length > 1 ? { ...due, pieces: due.pieces.slice(1) } : null);
59
+ let paid;
60
+ try {
61
+ paid = await ctx.client.notes.payNext(due);
62
+ }
63
+ catch (err) {
64
+ if (!isEsseyError(err, "RELAY_OUTCOME_UNKNOWN"))
65
+ ctx.records.savePayouts(due);
66
+ throw err;
67
+ }
68
+ return staged(ctx, paid);
69
+ }
38
70
  function keeperArgs(args) {
39
71
  const loan = parseLoanId(args);
40
72
  if (args.via === undefined)
@@ -65,7 +97,7 @@ const REFI = [
65
97
  kind: "call",
66
98
  description: "Borrower of an active loan settled from this server: open a refinance round for a new principal that pays the " +
67
99
  "current lender what is owed. Lenders offer with essey_loan_request and essey_loan_offer as on a new loan. " +
68
- "Returns the digest, ticket, round and when offers close.",
100
+ "Returns the digest, round and when offers close.",
69
101
  inputSchema: obj({
70
102
  loan: LOAN,
71
103
  principal: {
@@ -97,7 +129,7 @@ const REFI = [
97
129
  name: "essey_loan_refi_settle",
98
130
  kind: "call",
99
131
  description: "Borrower, after the refinance window: take the lowest eligible offer. The old lender is paid and collects with " +
100
- `essey_loan_collect; this server keeps the new terms. Returns the digest, ticket, rate, amount owed and maturity.${WAITS_MEDIUM}`,
132
+ `essey_loan_collect; this server keeps the new terms. Returns the digest, rate, amount owed and maturity.${WAITS_MEDIUM}`,
101
133
  inputSchema: LOAN_SCHEMA,
102
134
  run: async (ctx, args) => {
103
135
  const settled = own(ctx, parseLoanId(args));
@@ -222,17 +254,29 @@ const NOTES = [
222
254
  description: "Withdraw the notes of a coin, at most two. With denominations, the largest denomination sum they cover with " +
223
255
  "every piece's fees goes out as pieces, each to its own address in to, and kept stays in a note; a refusal " +
224
256
  "names how many addresses it needs. force: true, or a coin without denominations: everything less fees to " +
225
- `one address. Returns each piece's digest, ticket, amount and address.${WAITS_LONG}`,
257
+ `one address. Returns the piece's digest and address, left and notBeforeMs.${SPLIT}${WAITS_LONG}`,
226
258
  inputSchema: obj({
227
259
  coin: { type: "string", enum: [...COINS] },
228
260
  to: PAYEES,
229
261
  force: FORCE,
262
+ allowReuse: ALLOW_REUSE,
230
263
  }, ["coin", "to"]),
231
264
  run: async (ctx, args) => {
232
- const out = await ctx.client.notes.exit(parseCoin(args), parsePayees(args), parseForce(args));
233
- return { ...paidOut(out.payouts), kept: out.kept.toString() };
265
+ const [coin, to, o] = [parseCoin(args), parsePayees(args), parseSpend(args)];
266
+ refuseWhilePaying(ctx);
267
+ const out = await ctx.client.notes.exitFirst(coin, to, o);
268
+ return { ...staged(ctx, out), kept: out.kept.toString() };
234
269
  },
235
270
  },
271
+ {
272
+ name: "essey_notes_withdraw_continue",
273
+ kind: "call",
274
+ description: "Pay the next piece of the split withdraw or exit this server is paying out. Before its time it answers " +
275
+ "NOT_BEFORE with notBeforeMs. Returns the piece's digest and address, left (pieces still to pay) and, " +
276
+ "while left is above 0, notBeforeMs for the next. The schedule is a sealed file, so it survives a restart.",
277
+ inputSchema: obj(),
278
+ run: (ctx) => continuePayout(ctx),
279
+ },
236
280
  {
237
281
  name: "essey_notes_recover",
238
282
  kind: "call",
@@ -1 +1 @@
1
- {"version":3,"file":"tools-sales.d.ts","sourceRoot":"","sources":["../src/tools-sales.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,YAAY,CAAC;AAwQpD,eAAO,MAAM,UAAU,EAAE,IAAI,EAA2B,CAAC"}
1
+ {"version":3,"file":"tools-sales.d.ts","sourceRoot":"","sources":["../src/tools-sales.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,YAAY,CAAC;AAqRpD,eAAO,MAAM,UAAU,EAAE,IAAI,EAA2B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { isEsseyError, v3 } from "@esseyonsui/sui-sdk-v3";
2
- import { ADDRESS, AMOUNT, COIN, MS, address, int, objectSchema, optBool, parseAmount, parseCoin, payee, } from "./args.js";
2
+ import { ADDRESS, AMOUNT, COIN, MS, address, int, objectSchema, optBool, orHandle, parseAmount, parseCoin, payee, } from "./args.js";
3
3
  import { ToolRefusal } from "./failure.js";
4
4
  import { WAITS_LONG, WAITS_MEDIUM } from "./pace.js";
5
5
  const SLOTS = v3.sales.SLOTS;
@@ -22,7 +22,7 @@ function summary(row) {
22
22
  const state = ROOM_STATES[row.state] ?? "unknown";
23
23
  return { id: row.id, coin: row.coin, state, closeMs: row.closeMs, bids: row.bids };
24
24
  }
25
- function parseSaleOpen(args, nowMs) {
25
+ function parseSaleOpen(args) {
26
26
  const minPrice = parseAmount(args, "minPrice");
27
27
  const maxPrice = parseAmount(args, "maxPrice");
28
28
  if (minPrice > maxPrice)
@@ -30,16 +30,13 @@ function parseSaleOpen(args, nowMs) {
30
30
  const itemType = args.itemType;
31
31
  if (typeof itemType !== "string" || !new RegExp(STRUCT_TAG).test(itemType))
32
32
  bad("itemType must be a non-generic struct tag, 0x<package>::<module>::<Type>");
33
- const closeMs = nowMs + int(args, "bidWindowMs", 1, Number.MAX_SAFE_INTEGER);
34
- if (!Number.isSafeInteger(closeMs))
35
- bad("bidWindowMs is too long");
36
33
  return {
37
34
  itemId: address(args, "itemId"),
38
35
  itemType,
39
36
  coin: parseCoin(args),
40
37
  minPrice,
41
38
  maxPrice,
42
- closeMs,
39
+ bidWindowMs: int(args, "bidWindowMs", 1, Number.MAX_SAFE_INTEGER),
43
40
  finishWindowMs: int(args, "finishWindowMs", 1, Number.MAX_SAFE_INTEGER),
44
41
  maxBids: int(args, "maxBids", 1, SLOTS),
45
42
  sponsored: true,
@@ -52,10 +49,10 @@ function parseBid(args) {
52
49
  bad("price must be at most deposit");
53
50
  return { room: parseRoom(args), v, amount };
54
51
  }
55
- function parseClaim(ctx, args) {
52
+ function parseClaim(args) {
56
53
  if (args.as !== "seller" && args.as !== "bidder")
57
54
  bad("as must be seller or bidder");
58
- const to = args.to === undefined ? ctx.client.sales.agentAddress : payee(args, "to");
55
+ const to = args.to === undefined ? undefined : payee(args, "to");
59
56
  return { room: parseRoom(args), as: args.as, to };
60
57
  }
61
58
  async function finish(ctx, room) {
@@ -79,23 +76,32 @@ const SELLER = [
79
76
  {
80
77
  name: "essey_agent_address",
81
78
  kind: "read",
82
- description: "The Sui address of this server's agent key. Send it the item to sell and testnet SUI for gas. The key signs " +
83
- "one kind of transaction: the item hand-over inside essey_sale_open.",
79
+ description: "The Sui address of this server's agent key, which funds deposits. An item to sell goes to " +
80
+ "essey_item_address instead; one sent here is handed over by this key inside essey_sale_open, which links " +
81
+ "the sale to this address.",
84
82
  inputSchema: objectSchema({}, []),
85
83
  run: async (ctx) => ({ ok: true, address: ctx.client.sales.agentAddress }),
86
84
  },
85
+ {
86
+ name: "essey_item_address",
87
+ kind: "call",
88
+ description: "A fresh single-use Sui address derived from the note key. Send one item to sell to it; essey_sale_open " +
89
+ "then opens from that address with no hand-over. Use a new one per item.",
90
+ inputSchema: objectSchema({}, []),
91
+ run: async (ctx) => ({ ok: true, address: ctx.client.sales.itemAddress() }),
92
+ },
87
93
  {
88
94
  name: "essey_sale_open",
89
95
  kind: "call",
90
- description: "Seller: open a sealed sale of an item essey_agent_address holds. The agent key hands the item to a fresh " +
91
- "sender derived from the note key and the relayer pays the open. Bids close bidWindowMs from now; the seller " +
92
- "finishes within finishWindowMs after that. The seller keys and price bounds stay in a mode-600 file. " +
93
- "Returns the room id, digest and ticket.",
96
+ description: "Seller: open a sealed sale of an item at an essey_item_address, which signs the open while the relayer pays. " +
97
+ "An item at essey_agent_address is first handed to a fresh sender by the agent key. Bids close bidWindowMs " +
98
+ "from now; the seller finishes within finishWindowMs after that. The seller keys and price bounds stay in a " +
99
+ "mode-600 file. Returns the room id and digest.",
94
100
  inputSchema: objectSchema({
95
- itemId: { ...ADDRESS, description: "the item's object id, owned by essey_agent_address" },
101
+ itemId: { ...ADDRESS, description: "the item's object id, at an essey_item_address" },
96
102
  itemType: {
97
103
  type: "string",
98
- pattern: STRUCT_TAG,
104
+ pattern: orHandle(STRUCT_TAG),
99
105
  maxLength: 200,
100
106
  description: "the item's struct tag, 0x<package>::<module>::<Type>",
101
107
  },
@@ -104,13 +110,16 @@ const SELLER = [
104
110
  maxPrice: { ...AMOUNT, description: "highest price settled at; sealed, never shown to bidders" },
105
111
  bidWindowMs: {
106
112
  ...MS,
107
- description: "how long bids are taken from now, milliseconds; the close rounds up to the deployment's close step (an hour unless the deployment sets closeStepMs)",
113
+ description: "how long bids are taken from now, milliseconds: 1, 6, 24 or 72 close steps (1 h, 6 h, 24 h or 72 h at the default hour step; 5 min, 30 min, 2 h or 6 h at a 5-minute closeStepMs, as on testnet); the close rounds up to the next step, and any other window is refused",
114
+ },
115
+ finishWindowMs: {
116
+ ...MS,
117
+ description: "how long after close the seller may finish, milliseconds: 6, 24 or 72 close steps (6 h, 24 h or 72 h at the default hour step; 30 min, 2 h or 6 h at a 5-minute closeStepMs); any other window is refused",
108
118
  },
109
- finishWindowMs: { ...MS, description: "how long after close the seller may finish, milliseconds" },
110
119
  maxBids: { type: "integer", minimum: 1, maximum: SLOTS, description: `1 to ${SLOTS}` },
111
120
  }, ["itemId", "itemType", "coin", "minPrice", "maxPrice", "bidWindowMs", "finishWindowMs", "maxBids"]),
112
121
  run: async (ctx, args) => {
113
- const r = await ctx.client.sales.open(parseSaleOpen(args, Date.now()));
122
+ const r = await ctx.client.sales.open(parseSaleOpen(args));
114
123
  ctx.records.saveSale(r.id, r.sale);
115
124
  return { ...landed(r), room: r.id };
116
125
  },
@@ -173,7 +182,7 @@ const BIDDER = [
173
182
  name: "essey_sale_bid",
174
183
  kind: "call",
175
184
  description: "Bidder: lock deposit from own notes of the room's coin behind a sealed bid of price. Only the seller opens " +
176
- `it, after close. The bid record stays in a mode-600 file. Returns the digest and ticket.${WAITS_MEDIUM}`,
185
+ `it, after close. The bid record stays in a mode-600 file. Returns the digest.${WAITS_MEDIUM}`,
177
186
  inputSchema: objectSchema({
178
187
  room: ROOM,
179
188
  price: { ...AMOUNT, description: "the sealed bid, in the room coin's smallest unit" },
@@ -209,17 +218,18 @@ const BIDDER = [
209
218
  name: "essey_sale_claim",
210
219
  kind: "call",
211
220
  description: "Send the room's item to an address: as bidder when this server's bid won, or as seller after a cancel or " +
212
- "expiry. to defaults to essey_agent_address.",
221
+ "expiry. to defaults to a fresh essey_item_address, from which the item can be sold again.",
213
222
  inputSchema: objectSchema({
214
223
  room: ROOM,
215
224
  as: { type: "string", enum: ["seller", "bidder"], description: "which record of this server claims" },
216
- to: { type: "string", pattern: "^0x[0-9a-fA-F]{64}$", description: "recipient address" },
225
+ to: { type: "string", pattern: orHandle("^0x[0-9a-fA-F]{64}$"), description: "recipient address" },
217
226
  }, ["room", "as"]),
218
227
  run: async (ctx, args) => {
219
- const { room, as, to } = parseClaim(ctx, args);
228
+ const { room, as, to } = parseClaim(args);
220
229
  const holder = as === "seller" ? { seller: ctx.records.sale(room).seller } : { bid: ctx.records.bid(room) };
221
230
  const vault = await ctx.client.sales.vaultOf(room);
222
- return { ...landed(await ctx.client.sales.claim({ vault, recipient: to, ...holder })), to };
231
+ const r = await ctx.client.sales.claim({ vault, ...(to ? { recipient: to } : {}), ...holder });
232
+ return { ...landed(r), to: r.to };
223
233
  },
224
234
  },
225
235
  ];