@esseyonsui/sui-mcp-v3 0.1.3 → 0.1.5

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.
package/README.md CHANGED
@@ -79,8 +79,10 @@ Bidder: `essey_sale_list`, `essey_sale_view`, `essey_sale_bid` (room, sealed pri
79
79
  the bid won, or as `seller` after a cancel or expiry; `to` defaults to the agent address).
80
80
 
81
81
  The seller's keys and price bounds and the bidder's bid record go to `sale-<room>.json` and `bid-<room>.json`,
82
- mode 600, beside the loan records, the same files `scripts/v3/live/run.mts` writes. No tool returns them. The
83
- item vault is found on chain by its room. The sellable item type on testnet is the demo
82
+ mode 600, beside the loan records. Every record file is sealed (XChaCha20-Poly1305) under a key derived from the
83
+ note key; a plaintext file `scripts/v3/live/run.mts` wrote is still read, and sealed on its next save. No tool
84
+ returns them. `essey_records_export` copies them all into one sealed mode-600 file at an absolute path, and
85
+ `essey_records_import` reads it back under the same note key, keeping any record already held. The item vault is found on chain by its room. The sellable item type on testnet is the demo
84
86
  `0x48db0307be9b6aadbf9f29c28561e1b450348ab2786ea4853a8d7249c22979a1::demo::Badge`, which anyone can mint with
85
87
  its public `demo::mint` and transfer to the agent address.
86
88
 
package/dist/args.d.ts CHANGED
@@ -4,6 +4,7 @@ import type { PublicLoan } from "./loan-view.ts";
4
4
  type Rec = Record<string, unknown>;
5
5
  export type JsonSchema = Record<string, unknown>;
6
6
  export declare const AMOUNT: JsonSchema;
7
+ export declare const FORCE: JsonSchema;
7
8
  export declare const COIN: JsonSchema;
8
9
  export declare const ADDRESS: JsonSchema;
9
10
  export declare const MS: JsonSchema;
@@ -11,6 +12,9 @@ export declare const objectSchema: (properties: Record<string, JsonSchema>, requ
11
12
  export declare function address(a: Rec, k: string): string;
12
13
  export declare function payee(a: Rec, k: string): string;
13
14
  export declare function optBool(a: Rec, k: string): boolean | undefined;
15
+ export declare function parseForce(args: Rec): {
16
+ force: boolean;
17
+ } | undefined;
14
18
  export declare function int(a: Rec, k: string, min: number, max: number): number;
15
19
  export declare function parseRole(args: Rec): "member" | "keeper" | undefined;
16
20
  export declare function parseCoin(args: Rec, k?: string): CoinKey;
@@ -1 +1 @@
1
- {"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAMjD,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAMnC,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAOjD,eAAO,MAAM,MAAM,EAAE,UAIpB,CAAC;AACF,eAAO,MAAM,IAAI,EAAE,UAAsF,CAAC;AAC1G,eAAO,MAAM,OAAO,EAAE,UAIrB,CAAC;AAMF,eAAO,MAAM,EAAE,EAAE,UAA8E,CAAC;AAEhG,eAAO,MAAM,YAAY,GAAI,YAAY,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,UAAU,MAAM,EAAE,KAAG,UAKxF,CAAC;AAyBH,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAMjD;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAM/C;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAI9D;AAED,wBAAgB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAKvE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE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G,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,CAKzF;AAED,eAAO,MAAM,WAAW,YAGvB,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,MAAM,GAAG,KAAG,OAAwC,CAAC;AA2BlF,eAAO,MAAM,WAAW,YAmBvB,CAAC;AAEF,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,UAAU,CAmB/C"}
package/dist/args.js CHANGED
@@ -2,7 +2,7 @@ import { COINS, v3 } from "@esseyonsui/sui-sdk-v3";
2
2
  import { ToolRefusal } from "./failure.js";
3
3
  const U64 = 1n << 64n;
4
4
  const MAX_BPS = 10_000;
5
- const { K_MIN, K_MAX } = v3.collateral;
5
+ const { HEARTBEAT_KS } = v3.collateral;
6
6
  function bad(msg) {
7
7
  throw new ToolRefusal(msg);
8
8
  }
@@ -16,6 +16,10 @@ export const AMOUNT = {
16
16
  pattern: "^[1-9][0-9]*$",
17
17
  description: "whole-number string in the coin's smallest unit",
18
18
  };
19
+ export const FORCE = {
20
+ type: "boolean",
21
+ description: "send even when the amount equals a faucet grant or an own note's exact value or deposit, which links them on chain; default false",
22
+ };
19
23
  export const COIN = { type: "string", enum: [...COINS], description: "tusdsui, usdc or sui" };
20
24
  export const ADDRESS = {
21
25
  type: "string",
@@ -81,6 +85,10 @@ export function optBool(a, k) {
81
85
  bad(`${k} must be true or false`);
82
86
  return a[k];
83
87
  }
88
+ export function parseForce(args) {
89
+ const force = optBool(args, "force");
90
+ return force === undefined ? undefined : { force };
91
+ }
84
92
  export function int(a, k, min, max) {
85
93
  const v = a[k];
86
94
  if (typeof v !== "number" || !Number.isInteger(v) || v < min || v > max)
@@ -133,7 +141,10 @@ export const OPEN_SCHEMA = objectSchema({
133
141
  principal: { ...AMOUNT, description: "principal to borrow, in the loan coin's smallest unit" },
134
142
  maxRateBps: { ...BPS, description: "highest rate accepted, basis points" },
135
143
  termMs: { ...MS, description: "loan term after settle, milliseconds" },
136
- offerWindowMs: { ...MS, description: "how long lenders may offer, milliseconds" },
144
+ offerWindowMs: {
145
+ ...MS,
146
+ description: "how long lenders may offer, milliseconds; the close rounds up to the next whole UTC hour",
147
+ },
137
148
  }, ["collateralCoin", "collateral", "loanCoin", "principal", "maxRateBps", "termMs", "offerWindowMs"]);
138
149
  export function parseOpen(args) {
139
150
  const collateralCoin = coin(args, "collateralCoin");
@@ -159,11 +170,19 @@ export function parseOfferArgs(args) {
159
170
  }
160
171
  export const HEARTBEAT_SCHEMA = objectSchema({
161
172
  loan: LOAN,
162
- k: { type: "integer", minimum: K_MIN, maximum: K_MAX, description: "health bucket, default 1" },
173
+ k: {
174
+ type: "integer",
175
+ enum: [...HEARTBEAT_KS],
176
+ description: "health bucket: 1 (floor 95 % of the price, the default), 4 (80 %) or 8 (60 %)",
177
+ },
163
178
  }, ["loan"]);
164
179
  export function parseHeartbeat(args) {
165
180
  const loan = parseLoanId(args);
166
- return args.k === undefined ? { loan } : { loan, k: int(args, "k", K_MIN, K_MAX) };
181
+ if (args.k === undefined)
182
+ return { loan };
183
+ if (!HEARTBEAT_KS.includes(args.k))
184
+ bad("k must be 1, 4 or 8");
185
+ return { loan, k: args.k };
167
186
  }
168
187
  export const TOPUP_SCHEMA = objectSchema({
169
188
  loan: LOAN,
package/dist/client.js CHANGED
@@ -14,10 +14,10 @@ export function clientOf(essey, chain, health = (loan) => Promise.resolve(status
14
14
  faucet: (coin) => notes.faucet(coin),
15
15
  deposit: (coin, amount, o) => notes.deposit(coin, amount, o),
16
16
  scan: (coin) => notes.scan(coin),
17
- withdraw: (coin, amount, to) => notes.withdraw(coin, amount, to),
17
+ withdraw: (coin, amount, to, o) => notes.withdraw(coin, amount, to, o),
18
18
  transfer: (coin, amount, to) => notes.transfer(coin, amount, to),
19
19
  receiveAddress: () => notes.receiveAddress(),
20
- exit: (coin, to) => notes.exit(coin, to),
20
+ exit: (coin, to, o) => notes.exit(coin, to, o),
21
21
  recoverStranded: () => notes.recoverStranded(),
22
22
  },
23
23
  loans: {
package/dist/failure.d.ts CHANGED
@@ -5,6 +5,7 @@ export type Failure = {
5
5
  error: string;
6
6
  hint: string;
7
7
  reason?: string;
8
+ message?: string;
8
9
  abort?: {
9
10
  module: string;
10
11
  code: number;
@@ -20,8 +21,9 @@ export declare class ToolRefusal extends Error {
20
21
  constructor(hint: string);
21
22
  }
22
23
  /**
23
- * An SDK message can quote a service reply. Only a code from the SDK's own list is returned, with a fixed hint.
24
- * Anything else, including a lookalike `{ code }` on a plain Error, is withheld.
24
+ * An SDK message can quote a service reply. A code from the SDK's own list is returned with a fixed hint, and its
25
+ * message only when it is plain prose (`PROSE`). Anything else, including a lookalike `{ code }` on a plain Error,
26
+ * is withheld.
25
27
  */
26
28
  export declare function failureOf(err: unknown, secrets?: readonly string[]): Failure;
27
29
  export declare const isSdkCode: (err: unknown) => err is EsseyError;
@@ -1 +1 @@
1
- {"version":3,"file":"failure.d.ts","sourceRoot":"","sources":["../src/failure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,UAAU,EAAgB,MAAM,wBAAwB,CAAC;AAIrF,eAAO,MAAM,QAAQ,6DAA6D,CAAC;AAEnF,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1C,CAAC;AA2BF;;;GAGG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAExB,QAAQ,CAAC,IAAI,EAAE,MAAM;IADjC,QAAQ,CAAC,IAAI,sBAAsB;gBACd,IAAI,EAAE,MAAM;CAGlC;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,SAAS,MAAM,EAAO,GAAG,OAAO,CAOhF;AAED,eAAO,MAAM,SAAS,GAAI,KAAK,OAAO,KAAG,GAAG,IAAI,UACkC,CAAC;AAEnF,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAcpD"}
1
+ {"version":3,"file":"failure.d.ts","sourceRoot":"","sources":["../src/failure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,UAAU,EAAgB,MAAM,wBAAwB,CAAC;AAIrF,eAAO,MAAM,QAAQ,6DAA6D,CAAC;AAEnF,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1C,CAAC;AAuCF;;;GAGG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAExB,QAAQ,CAAC,IAAI,EAAE,MAAM;IADjC,QAAQ,CAAC,IAAI,sBAAsB;gBACd,IAAI,EAAE,MAAM;CAGlC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,SAAS,MAAM,EAAO,GAAG,OAAO,CAOhF;AAED,eAAO,MAAM,SAAS,GAAI,KAAK,OAAO,KAAG,GAAG,IAAI,UACkC,CAAC;AAEnF,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAcpD"}
package/dist/failure.js CHANGED
@@ -5,6 +5,17 @@ export const WITHHELD = "The tool failed inside a library; its error is withheld
5
5
  const SERVICE_CODE = /^(?:v3api|relayer) refused: ([A-Z_]{3,40})$/;
6
6
  const CODE = /^[A-Z_]{3,40}$/;
7
7
  const MODULE = /^[a-z0-9_]{1,40}::[a-z0-9_]{1,40}$/;
8
+ /** The SDK's own refusal wording: lowercase prose, no long token, so no key, salt, id or digest fits it. */
9
+ const PROSE = /^[a-z0-9 :;,.'()/_-]{3,240}$/;
10
+ const LONG_TOKEN = /[a-z0-9]{25,}|[0-9]{7,}/;
11
+ /** These can quote a service reply; their code reaches the caller as `reason` instead. */
12
+ const SERVICE_WORDED = new Set(["SERVICE_REFUSED", "RELAY_REFUSED", "RELAY_FAILED", "RELAY_OUTCOME_UNKNOWN"]);
13
+ function messageOf(err, secrets) {
14
+ if (SERVICE_WORDED.has(err.code))
15
+ return {};
16
+ const text = redactText(err.message, secrets);
17
+ return PROSE.test(text) && !LONG_TOKEN.test(text) ? { message: text } : {};
18
+ }
8
19
  /** The relayer's own code (`ServiceDetail.error`) and Move abort, both a fixed shape a key cannot take. */
9
20
  function relayReason(err) {
10
21
  const { error, abort } = err.detail ?? {};
@@ -37,15 +48,16 @@ export class ToolRefusal extends Error {
37
48
  }
38
49
  }
39
50
  /**
40
- * An SDK message can quote a service reply. Only a code from the SDK's own list is returned, with a fixed hint.
41
- * Anything else, including a lookalike `{ code }` on a plain Error, is withheld.
51
+ * An SDK message can quote a service reply. A code from the SDK's own list is returned with a fixed hint, and its
52
+ * message only when it is plain prose (`PROSE`). Anything else, including a lookalike `{ code }` on a plain Error,
53
+ * is withheld.
42
54
  */
43
55
  export function failureOf(err, secrets = []) {
44
56
  if (err instanceof ToolRefusal)
45
57
  return { ok: false, error: err.code, hint: redactText(err.hint, secrets) };
46
58
  if (isEsseyError(err) && ESSEY_ERROR_CODES.includes(err.code)) {
47
59
  const hint = `Look up ${err.code} in the sdk/errors reference.`;
48
- return { ok: false, error: err.code, hint, ...reasonOf(err) };
60
+ return { ok: false, error: err.code, hint, ...reasonOf(err), ...messageOf(err, secrets) };
49
61
  }
50
62
  return { ok: false, error: "UNEXPECTED", hint: WITHHELD };
51
63
  }
package/dist/io.d.ts CHANGED
@@ -3,9 +3,12 @@ import { v3, type EsseyIo } from "@esseyonsui/sui-sdk-v3";
3
3
  export { TESTNET_GRAPHQL } from "./config.ts";
4
4
  type Json = any;
5
5
  type Fetch = (url: string, init?: RequestInit) => Promise<Response>;
6
+ type Gql = (query: string, variables: Record<string, unknown>) => Promise<Json>;
6
7
  export type ChainIoOptions = {
7
8
  graphql: string;
8
9
  fetch?: Fetch;
10
+ /** Pause between index polls after a step lands; tests pass 0. */
11
+ indexPauseMs?: number;
9
12
  /** Circuit name to local `{ wasm, zkey }` paths, for a circuit `/v3/config` does not serve yet. */
10
13
  localArtifacts?: Record<string, {
11
14
  wasm: string;
@@ -21,6 +24,13 @@ export declare function invertReading(spot: bigint, ema: bigint, spotExpo: bigin
21
24
  ema: bigint;
22
25
  expo: bigint;
23
26
  };
27
+ /**
28
+ * True once public GraphQL's latest checkpoint is stamped at or after `landedAtMs`, so every read it serves sees
29
+ * a step that landed by then. Stress run 2: loan reads lagged a landed step by about 4 s and repay, release,
30
+ * heartbeat and refi_open were refused against the old state. Asking by the step's digest would tell GraphQL
31
+ * which transaction is the member's (NET-05). False after `INDEX_POLLS` polls.
32
+ */
33
+ export declare function waitIndexed(gql: Gql, landedAtMs: number, pauseMs: number): Promise<boolean>;
24
34
  type SealPackage = "loan" | "sale";
25
35
  type SealArg = {
26
36
  pure: "vector<u8>" | "u256" | "u64";
@@ -39,6 +49,7 @@ type SealRequest = {
39
49
  signer?: Signer;
40
50
  };
41
51
  export declare function chainIo(config: Json, o: ChainIoOptions): {
52
+ waitIndexed: (landedAtMs: number) => Promise<boolean>;
42
53
  prover: v3.Prover;
43
54
  readPrice: (market: string) => Promise<{
44
55
  spot: bigint;
@@ -99,7 +110,7 @@ export declare function chainIo(config: Json, o: ChainIoOptions): {
99
110
  sealDerivedKeys: (r: SealRequest & {
100
111
  id: Uint8Array;
101
112
  }) => Promise<Map<string, Uint8Array<ArrayBuffer>>>;
102
- readLoan: (id: string) => Promise<{
113
+ readLoan: (id: string, round?: bigint) => Promise<{
103
114
  json: any;
104
115
  round: any;
105
116
  }>;
package/dist/io.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAMvD,OAAO,EAAE,EAAE,EAAE,KAAK,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAQ9C,KAAK,IAAI,GAAG,GAAG,CAAC;AAChB,KAAK,KAAK,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAGpE,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,mGAAmG;IACnG,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChE,mFAAmF;IACnF,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CACtC,CAAC;AAsFF,2IAA2I;AAC3I,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;;;;EAMzF;AA0QD,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAkCnC,KAAK,OAAO,GAAG;IAAE,IAAI,EAAE,YAAY,GAAG,MAAM,GAAG,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAA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AM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC3F,KAAK,WAAW,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC;AAEhF,KAAK,WAAW,GAAG;IAAE,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IAAC,GAAG,CAAC,EAAE,WAAW,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAmD7G,wBAAgB,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,cAAc;8BAWzB,MAAM;;wBAEZ,MAAM;;;;;0BACJ,MAAM;gBAzXR,MAAM;gBACL,MAAM;;;;;;0BAyXL,MAAM;;;;6BACH,MAAM;gCACH,MAAM;2BACX,MAAM;0BACP,MAAM;wBACR,MAAM;;;;6BACD,MAAM;;;;wBACX,MAAM;;;;;mBACX,MAAM;;;wBACK,MAAM,GAAG,IAAI;;;;wBACb,MAAM;+BACL,MAAM;oBACX,MAAM;;;qBACL,MAAM;2CApG5B;QACD,EAAE,EAAE,UAAU,CAAC;QACf,IAAI,EAAE,UAAU,CAAC;QACjB,GAAG,CAAC,EAAE,UAAU,CAAC;QACjB,GAAG,CAAC,EAAE,WAAW,CAAC;KACnB;qBAgDgB,WAAW,GAAG;QAAE,MAAM,EAAE,UAAU,CAAA;KAAE;yBAOpC,WAAW,GAAG;QAAE,EAAE,EAAE,UAAU,CAAA;KAAE;mBA4ChC,MAAM,UAAU,MAAM;;;;wBACjB,MAAM,GAAG,IAAI;;;;;;;;;;0BAGL,MAAM;4BAEJ,MAAM;qBACb,MAAM;;;;;;;;EAkBhC"}
package/dist/io.js CHANGED
@@ -218,11 +218,27 @@ async function readSaleOpened(gql, digest) {
218
218
  throw new Error(`transaction ${digest} created no sale room and vault`);
219
219
  return { room, vault };
220
220
  }
221
- /** The loan and its current `Round`, a `Table<u64, Round>` entry under `rounds`. */
222
- async function readLoan(gql, id) {
221
+ const INDEX_POLLS = 20;
222
+ /**
223
+ * True once public GraphQL's latest checkpoint is stamped at or after `landedAtMs`, so every read it serves sees
224
+ * a step that landed by then. Stress run 2: loan reads lagged a landed step by about 4 s and repay, release,
225
+ * heartbeat and refi_open were refused against the old state. Asking by the step's digest would tell GraphQL
226
+ * which transaction is the member's (NET-05). False after `INDEX_POLLS` polls.
227
+ */
228
+ export async function waitIndexed(gql, landedAtMs, pauseMs) {
229
+ const pause = () => new Promise((r) => setTimeout(r, pauseMs));
230
+ for (let i = 0; i < INDEX_POLLS; i++, await pause()) {
231
+ const d = await gql(`query { checkpoint { timestamp } }`, {});
232
+ if (Date.parse(d.checkpoint?.timestamp) >= landedAtMs)
233
+ return true;
234
+ }
235
+ return false;
236
+ }
237
+ /** The loan and its `Round` `round` (the current one when omitted), a `Table<u64, Round>` entry under `rounds`. */
238
+ async function readLoan(gql, id, round) {
223
239
  const json = (await objectOf(gql, id)).asMoveObject.contents.json;
224
240
  const key = Buffer.alloc(8);
225
- key.writeBigUInt64LE(BigInt(json.round));
241
+ key.writeBigUInt64LE(round ?? BigInt(json.round));
226
242
  const d = await gql(`query($t: SuiAddress!, $k: Base64!) { address(address: $t) { dynamicField(name: { type: "u64", bcs: $k }) { value { ... on MoveValue { json } } } } }`, { t: json.rounds.id, k: key.toString("base64") });
227
243
  return { json, round: d.address?.dynamicField?.value?.json };
228
244
  }
@@ -381,6 +397,7 @@ export function chainIo(config, o) {
381
397
  return v3.loadCircuitArtifacts(fetch, config.circuits, circuit);
382
398
  };
383
399
  return {
400
+ waitIndexed: (landedAtMs) => waitIndexed(gql, landedAtMs, o.indexPauseMs ?? 1500),
384
401
  prover: v3.groth16Prover(snarkjs.groth16, artifacts),
385
402
  readPrice: (market) => readPrice(gql, market),
386
403
  readReading: (market) => readReading(gql, market),
@@ -401,7 +418,7 @@ export function chainIo(config, o) {
401
418
  sealEncrypt: sealerFor(config, o.graphql, o.garble ?? (() => false)),
402
419
  sealDecrypt: unsealerFor(config, o.graphql),
403
420
  sealDerivedKeys: deriverFor(config, o.graphql),
404
- readLoan: (id) => readLoan(gql, id),
421
+ readLoan: (id, round) => readLoan(gql, id, round),
405
422
  readLoans: (cursor) => readLoans(gql, config.packageOrigins.loan, cursor),
406
423
  priceUpdate: async () => Uint8Array.of(0),
407
424
  fundDeposit: o.fundDeposit,
package/dist/main.js CHANGED
@@ -9,7 +9,7 @@ import { agentDepositIo } from "./fund.js";
9
9
  import { chainIo } from "./io.js";
10
10
  import { loadAgentKey, loadNoteSeed } from "./keys.js";
11
11
  import { serve } from "./protocol.js";
12
- import { fileRecords } from "./records.js";
12
+ import { fileRecords, recordKey } from "./records.js";
13
13
  import { bind } from "./tools.js";
14
14
  const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"))
15
15
  .version;
@@ -87,9 +87,10 @@ async function start() {
87
87
  const client = withInvite(clientOf(essey, sale), cfg.invite);
88
88
  const tools = bind({
89
89
  client,
90
- records: fileRecords(dirname(cfg.stateFile)),
90
+ records: fileRecords(dirname(cfg.stateFile), recordKey(seed)),
91
91
  redact: cfg.invite ? [cfg.invite] : [],
92
92
  onError: (line) => process.stderr.write(`essey-v3-mcp: ${line}\n`),
93
+ waitIndexed: io.waitIndexed,
93
94
  });
94
95
  process.stderr.write("essey-v3-mcp: testnet, note key and agent key files accepted\n");
95
96
  await serve(tools, { name: "essey-v3", version: VERSION, instructions: INSTRUCTIONS }, process.stdin, process.stdout);
package/dist/records.d.ts CHANGED
@@ -10,9 +10,9 @@ export type LoanRecord = {
10
10
  borrowerPk?: bigint;
11
11
  };
12
12
  /**
13
- * What a cycle step needs from an earlier one and no chain read gives back. Same files and JSON as
14
- * `scripts/v3/live/run.mts` (`loan-<id>.json`, `offer-<id>.json`, `sale-<room>.json`, `bid-<room>.json`), mode 600,
15
- * beside the state file.
13
+ * What a cycle step needs from an earlier one and no chain read gives back: `loan-<id>.json`, `offer-<id>.json`,
14
+ * `sale-<room>.json`, `bid-<room>.json`, mode 600 beside the state file, sealed under `recordKey`. A file written
15
+ * before sealing (the JSON `scripts/v3/live/run.mts` writes) is still read, and sealed on its next save.
16
16
  */
17
17
  export type Records = {
18
18
  loan(id: string): LoanRecord;
@@ -23,6 +23,15 @@ export type Records = {
23
23
  saveSale(room: string, record: SaleRecord): void;
24
24
  bid(room: string): BidRecord;
25
25
  saveBid(room: string, record: BidRecord): void;
26
+ /** Every record into one new sealed mode-600 file at `path`. Returns how many it holds. */
27
+ exportTo(path: string): number;
28
+ /** The records of an `exportTo` file. One this server already holds is kept, not overwritten. */
29
+ importFrom(path: string): {
30
+ imported: number;
31
+ kept: number;
32
+ };
26
33
  };
27
- export declare function fileRecords(dir: string): Records;
34
+ /** The records key: HKDF-SHA256 of the note seed under a fixed label, so the seed itself never leaves `main.ts`. */
35
+ export declare function recordKey(seed: Uint8Array): Uint8Array;
36
+ export declare function fileRecords(dir: string, key: Uint8Array): Records;
28
37
  //# sourceMappingURL=records.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../src/records.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIhE,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,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC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,UAAU,CAEtD;AA2CD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CA+GjE"}
package/dist/records.js CHANGED
@@ -1,10 +1,18 @@
1
1
  import { randomBytes } from "node:crypto";
2
- import { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
3
- import { join } from "node:path";
2
+ import { chmodSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
3
+ import { isAbsolute, join } from "node:path";
4
+ import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
5
+ import { hkdf } from "@noble/hashes/hkdf.js";
6
+ import { sha256 } from "@noble/hashes/sha2.js";
4
7
  import { ToolRefusal } from "./failure.js";
5
8
  const LOAN_ID = /^0x[0-9a-f]{64}$/;
9
+ const RECORD_FILE = /^(loan|offer|sale|bid)-(0x[0-9a-f]{64})\.json$/;
10
+ const KINDS = ["loan", "offer", "sale", "bid"];
11
+ const EXPORT_LABEL = "export";
12
+ const NONCE = 24;
6
13
  const plain = (v) => JSON.stringify(v, (_k, x) => (typeof x === "bigint" ? x.toString() : x));
7
14
  const big = (v) => (v === undefined ? undefined : BigInt(v));
15
+ const utf8 = (s) => new TextEncoder().encode(s);
8
16
  const MISSING = {
9
17
  loan: "this server holds no borrower record for that loan: open it from this server first",
10
18
  offer: "this server holds no offer record for that loan: offer on it from this server first",
@@ -14,29 +22,88 @@ const MISSING = {
14
22
  function noRecord(kind) {
15
23
  throw new ToolRefusal(MISSING[kind]);
16
24
  }
17
- export function fileRecords(dir) {
25
+ /** The records key: HKDF-SHA256 of the note seed under a fixed label, so the seed itself never leaves `main.ts`. */
26
+ export function recordKey(seed) {
27
+ return hkdf(sha256, seed, undefined, utf8("essey-v3-mcp records v1"), 32);
28
+ }
29
+ /** `label` is the AAD: a sealed file opens only under the name it was written for. */
30
+ function seal(key, label, v) {
31
+ const nonce = randomBytes(NONCE);
32
+ const box = xchacha20poly1305(key, nonce, utf8(label)).encrypt(utf8(plain(v)));
33
+ return JSON.stringify({ sealed: Buffer.concat([nonce, box]).toString("base64") });
34
+ }
35
+ function unseal(key, label, sealed) {
36
+ const bytes = Buffer.from(sealed, "base64");
37
+ const text = xchacha20poly1305(key, bytes.subarray(0, NONCE), utf8(label)).decrypt(bytes.subarray(NONCE));
38
+ return JSON.parse(new TextDecoder().decode(text));
39
+ }
40
+ function writePrivate(target, text) {
41
+ const tmp = `${target}.${randomBytes(6).toString("hex")}.tmp`;
42
+ writeFileSync(tmp, text, { mode: 0o600, flag: "wx" });
43
+ chmodSync(tmp, 0o600);
44
+ renameSync(tmp, target);
45
+ }
46
+ function exportRows(text, key) {
47
+ let rows;
48
+ try {
49
+ rows = unseal(key, EXPORT_LABEL, JSON.parse(text).sealed).records;
50
+ }
51
+ catch {
52
+ throw new ToolRefusal("that file is not a records export sealed by this note key");
53
+ }
54
+ if (!Array.isArray(rows))
55
+ throw new ToolRefusal("that file is not a records export sealed by this note key");
56
+ return rows.map((r) => {
57
+ if (!KINDS.includes(r?.kind) ||
58
+ !LOAN_ID.test(r?.id) ||
59
+ typeof r?.record !== "object" ||
60
+ r.record === null)
61
+ throw new ToolRefusal("that records export holds a malformed row");
62
+ return r;
63
+ });
64
+ }
65
+ export function fileRecords(dir, key) {
18
66
  const path = (kind, id) => {
19
67
  if (!LOAN_ID.test(id))
20
68
  throw new ToolRefusal("loan must be 0x and 64 hex digits");
21
69
  return join(dir, `${kind}-${id}.json`);
22
70
  };
23
71
  const read = (kind, id) => {
72
+ let v;
24
73
  try {
25
- return JSON.parse(readFileSync(path(kind, id), "utf8"));
74
+ v = JSON.parse(readFileSync(path(kind, id), "utf8"));
26
75
  }
27
76
  catch (err) {
28
77
  if (err.code === "ENOENT")
29
78
  return null;
30
79
  throw err;
31
80
  }
81
+ return typeof v.sealed === "string" ? unseal(key, `${kind}-${id}`, v.sealed) : v;
32
82
  };
33
83
  const write = (kind, id, v) => {
34
84
  const target = path(kind, id);
35
- const tmp = `${target}.${randomBytes(6).toString("hex")}.tmp`;
36
85
  mkdirSync(dir, { recursive: true, mode: 0o700 });
37
- writeFileSync(tmp, plain(v), { mode: 0o600, flag: "wx" });
38
- chmodSync(tmp, 0o600);
39
- renameSync(tmp, target);
86
+ writePrivate(target, seal(key, `${kind}-${id}`, v));
87
+ };
88
+ const held = () => {
89
+ let names;
90
+ try {
91
+ names = readdirSync(dir);
92
+ }
93
+ catch (err) {
94
+ if (err.code === "ENOENT")
95
+ return [];
96
+ throw err;
97
+ }
98
+ return names.flatMap((n) => {
99
+ const m = RECORD_FILE.exec(n);
100
+ return m ? [{ kind: m[1], id: m[2] }] : [];
101
+ });
102
+ };
103
+ const absolute = (p) => {
104
+ if (!isAbsolute(p))
105
+ throw new ToolRefusal("path must be absolute");
106
+ return p;
40
107
  };
41
108
  return {
42
109
  loan: (id) => {
@@ -82,5 +149,38 @@ export function fileRecords(dir) {
82
149
  };
83
150
  },
84
151
  saveBid: (room, record) => write("bid", room, record),
152
+ exportTo: (target) => {
153
+ const records = held().map(({ kind, id }) => ({ kind, id, record: read(kind, id) }));
154
+ try {
155
+ writeFileSync(absolute(target), seal(key, EXPORT_LABEL, { records }), { mode: 0o600, flag: "wx" });
156
+ }
157
+ catch (err) {
158
+ if (err.code === "EEXIST")
159
+ throw new ToolRefusal("a file already exists at path");
160
+ throw err;
161
+ }
162
+ chmodSync(target, 0o600);
163
+ return records.length;
164
+ },
165
+ importFrom: (source) => {
166
+ let text;
167
+ try {
168
+ text = readFileSync(absolute(source), "utf8");
169
+ }
170
+ catch (err) {
171
+ if (err.code === "ENOENT")
172
+ throw new ToolRefusal("no file at path");
173
+ throw err;
174
+ }
175
+ const rows = exportRows(text, key);
176
+ let imported = 0;
177
+ for (const { kind, id, record } of rows) {
178
+ if (read(kind, id))
179
+ continue;
180
+ write(kind, id, record);
181
+ imported++;
182
+ }
183
+ return { imported, kept: rows.length - imported };
184
+ },
85
185
  };
86
186
  }
@@ -1,3 +1,5 @@
1
1
  import type { Tool } from "./tools.ts";
2
+ /** No SDK call behind either, so they sit outside `MORE`. */
3
+ export declare const RECORD_TOOLS: Tool[];
2
4
  export declare const MORE: Tool[];
3
5
  //# sourceMappingURL=tools-more.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tools-more.d.ts","sourceRoot":"","sources":["../src/tools-more.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,YAAY,CAAC;AAkQpD,eAAO,MAAM,IAAI,EAAE,IAAI,EAA6C,CAAC"}
1
+ {"version":3,"file":"tools-more.d.ts","sourceRoot":"","sources":["../src/tools-more.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,YAAY,CAAC;AAiRpD,6DAA6D;AAC7D,eAAO,MAAM,YAAY,EAAE,IAAI,EAoB9B,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,IAAI,EAA6C,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { COINS } from "@esseyonsui/sui-sdk-v3";
2
- import { LOAN_SCHEMA, OPEN_SCHEMA, int, parseAmount, parseCoin, parseLoanId, parsePayee } from "./args.js";
2
+ import { FORCE, LOAN_SCHEMA, OPEN_SCHEMA, int, parseAmount, parseCoin, parseForce, parseLoanId, parsePayee, } from "./args.js";
3
3
  import { isSdkCode, ToolRefusal } from "./failure.js";
4
4
  /** `move/v3/loan/sources/loan.move:40` MAX_OFFERS = 16. */
5
5
  const MAX_SEQ = 15;
@@ -59,18 +59,24 @@ const REFI = [
59
59
  "Returns the digest, ticket, round and when offers close.",
60
60
  inputSchema: obj({
61
61
  loan: LOAN,
62
- principal: { ...REQUEST.principal, description: "new principal; it must cover what is owed now" },
62
+ principal: {
63
+ ...REQUEST.principal,
64
+ description: "new principal; above what is owed now, which it pays with the fee",
65
+ },
63
66
  maxRateBps: REQUEST.maxRateBps,
64
67
  termMs: REQUEST.termMs,
65
68
  offerWindowMs: REQUEST.offerWindowMs,
66
69
  }, ["loan", "principal", "maxRateBps", "termMs", "offerWindowMs"]),
67
70
  run: async (ctx, args) => {
68
- const { loan, borrowerPk, collAmt } = own(ctx, parseLoanId(args));
71
+ const { loan, borrowerPk, collAmt, terms } = own(ctx, parseLoanId(args));
72
+ const principal = parseAmount(args, "principal");
73
+ if (principal <= terms.owed)
74
+ bad("principal must be above what the loan owes now: it pays the current lender and the fee");
69
75
  const r = await ctx.client.loans.openRefi({
70
76
  loan,
71
77
  borrowerPk,
72
78
  collAmt,
73
- principal: parseAmount(args, "principal"),
79
+ principal,
74
80
  maxRateBps: int(args, "maxRateBps", 0, 10_000),
75
81
  termMs: int(args, "termMs", 1, MAX_MS),
76
82
  offerWindowMs: int(args, "offerWindowMs", 1, MAX_MS),
@@ -209,8 +215,9 @@ const NOTES = [
209
215
  inputSchema: obj({
210
216
  coin: { type: "string", enum: [...COINS] },
211
217
  to: { type: "string", pattern: "^0x[0-9a-fA-F]{64}$", description: "recipient address" },
218
+ force: FORCE,
212
219
  }, ["coin", "to"]),
213
- run: async (ctx, args) => landed(await ctx.client.notes.exit(parseCoin(args), parsePayee(args))),
220
+ run: async (ctx, args) => landed(await ctx.client.notes.exit(parseCoin(args), parsePayee(args), parseForce(args))),
214
221
  },
215
222
  {
216
223
  name: "essey_notes_recover",
@@ -224,4 +231,30 @@ const NOTES = [
224
231
  }),
225
232
  },
226
233
  ];
234
+ const PATH = { type: "string", description: "absolute file path on this server" };
235
+ function parsePath(args) {
236
+ if (typeof args.path !== "string" || args.path === "")
237
+ bad("path must be an absolute file path");
238
+ return args.path;
239
+ }
240
+ /** No SDK call behind either, so they sit outside `MORE`. */
241
+ export const RECORD_TOOLS = [
242
+ {
243
+ name: "essey_records_export",
244
+ kind: "read",
245
+ description: "Copy every loan, offer, seller and bid record this server holds into one new mode-600 file at path, sealed " +
246
+ "under a key derived from the note key, so a lost server can be rebuilt with essey_records_import. Returns " +
247
+ "how many records it holds.",
248
+ inputSchema: obj({ path: PATH }, ["path"]),
249
+ run: async (ctx, args) => ({ ok: true, records: ctx.records.exportTo(parsePath(args)) }),
250
+ },
251
+ {
252
+ name: "essey_records_import",
253
+ kind: "call",
254
+ description: "Read a file essey_records_export wrote under the same note key and save its records here. A record this " +
255
+ "server already holds is kept. Returns how many were imported and kept.",
256
+ inputSchema: obj({ path: PATH }, ["path"]),
257
+ run: async (ctx, args) => ({ ok: true, ...ctx.records.importFrom(parsePath(args)) }),
258
+ },
259
+ ];
227
260
  export const MORE = [...REFI, ...SEIZE, ...KEEPER, ...NOTES];
@@ -1 +1 @@
1
- {"version":3,"file":"tools-sales.d.ts","sourceRoot":"","sources":["../src/tools-sales.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,YAAY,CAAC;AAoQpD,eAAO,MAAM,UAAU,EAAE,IAAI,EAA2B,CAAC"}
1
+ {"version":3,"file":"tools-sales.d.ts","sourceRoot":"","sources":["../src/tools-sales.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,YAAY,CAAC;AAwQpD,eAAO,MAAM,UAAU,EAAE,IAAI,EAA2B,CAAC"}
@@ -101,7 +101,10 @@ const SELLER = [
101
101
  coin: { ...COIN, description: "the coin bids are paid in" },
102
102
  minPrice: { ...AMOUNT, description: "lowest price accepted; sealed, never shown to bidders" },
103
103
  maxPrice: { ...AMOUNT, description: "highest price settled at; sealed, never shown to bidders" },
104
- bidWindowMs: { ...MS, description: "how long bids are taken from now, milliseconds" },
104
+ bidWindowMs: {
105
+ ...MS,
106
+ description: "how long bids are taken from now, milliseconds; the close rounds up to the next whole UTC hour",
107
+ },
105
108
  finishWindowMs: { ...MS, description: "how long after close the seller may finish, milliseconds" },
106
109
  maxBids: { type: "integer", minimum: 1, maximum: SLOTS, description: `1 to ${SLOTS}` },
107
110
  }, ["itemId", "itemType", "coin", "minPrice", "maxPrice", "bidWindowMs", "finishWindowMs", "maxBids"]),
package/dist/tools.d.ts CHANGED
@@ -9,6 +9,11 @@ export type ToolContext = {
9
9
  redact: readonly string[];
10
10
  /** Tool name and error code only. The callback must not be given the error's message. */
11
11
  onError?(line: string): void;
12
+ /**
13
+ * After a call lands: true once chain reads reflect the moment it landed (`io.ts` waitIndexed). A failed read
14
+ * counts as false: the step landed, so it is never reported as an error.
15
+ */
16
+ waitIndexed?(landedAtMs: number): Promise<boolean>;
12
17
  };
13
18
  type Args = Record<string, unknown>;
14
19
  type ToolKind = "read" | "call";
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,OAAO,EAAc,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAM5C,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,UAAU,CAAC;IACnB,gGAAgG;IAChG,OAAO,EAAE,OAAO,CAAC;IACjB,8FAA8F;IAC9F,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,yFAAyF;IACzF,OAAO,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACpC,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAChC,MAAM,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG;IACzC,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACrD,CAAC;AA2ZF,eAAO,MAAM,KAAK,EAAE,IAAI,EASvB,CAAC;AAUF,+GAA+G;AAC/G,wBAAgB,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,GAAE,IAAI,EAAU,GAAG,OAAO,EAAE,CAmBvE"}
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,OAAO,EAAc,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAM5C,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,UAAU,CAAC;IACnB,gGAAgG;IAChG,OAAO,EAAE,OAAO,CAAC;IACjB,8FAA8F;IAC9F,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,yFAAyF;IACzF,OAAO,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B;;;OAGG;IACH,WAAW,CAAC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACpD,CAAC;AAEF,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACpC,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAChC,MAAM,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG;IACzC,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACrD,CAAC;AA4aF,eAAO,MAAM,KAAK,EAAE,IAAI,EAUvB,CAAC;AAUF,+GAA+G;AAC/G,wBAAgB,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,GAAE,IAAI,EAAU,GAAG,OAAO,EAAE,CA0BvE"}
package/dist/tools.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { COINS, v3 } from "@esseyonsui/sui-sdk-v3";
2
- import { HEARTBEAT_SCHEMA, LIST_SCHEMA, LOAN_SCHEMA, OFFER_SCHEMA, OPEN_SCHEMA, TOPUP_SCHEMA, TRANSFER_SCHEMA, VIEW_SCHEMA, parseAmount, parseCoin, parseDenominations, parseHeartbeat, parseListAll, parseLoanId, parseOfferArgs, parseOpen, parsePayee, parseReceiver, parseRole, parseTopup, parseView, } from "./args.js";
2
+ import { FORCE, HEARTBEAT_SCHEMA, LIST_SCHEMA, LOAN_SCHEMA, OFFER_SCHEMA, OPEN_SCHEMA, TOPUP_SCHEMA, TRANSFER_SCHEMA, VIEW_SCHEMA, parseAmount, parseCoin, parseDenominations, parseForce, parseHeartbeat, parseListAll, parseLoanId, parseOfferArgs, parseOpen, parsePayee, parseReceiver, parseRole, parseTopup, parseView, } from "./args.js";
3
3
  import { assertNoSecrets, failureOf, ToolRefusal } from "./failure.js";
4
4
  import { redact } from "./redact.js";
5
5
  import { BADGE_TOOLS } from "./tools-badge.js";
6
- import { MORE } from "./tools-more.js";
6
+ import { MORE, RECORD_TOOLS } from "./tools-more.js";
7
7
  import { SALE_TOOLS } from "./tools-sales.js";
8
8
  const UNITS = "whole-number string in the coin's smallest unit";
9
9
  const BIDDING = v3.LOAN_LIFECYCLE.indexOf("bidding");
@@ -66,9 +66,16 @@ const CREDENTIAL = [
66
66
  {
67
67
  name: "essey_credential_renew",
68
68
  kind: "call",
69
- description: "Renew the credential already in the state file. Returns role, expiry and epoch only.",
69
+ description: "Renew the credential already in the state file. Returns role, expiry, epoch and renewed; when the issuer " +
70
+ "kept the held expiry, renewed is false and message says when renew opens.",
70
71
  inputSchema: obj(),
71
- run: async (ctx) => credential(await ctx.client.credential.renew()),
72
+ run: async (ctx) => {
73
+ const r = await ctx.client.credential.renew();
74
+ if (r.renewed)
75
+ return { ...credential(r), renewed: true };
76
+ const opens = new Date(Number(r.renewOpensMs)).toISOString();
77
+ return { ...credential(r), renewed: false, message: `renew opens at ${opens}` };
78
+ },
72
79
  },
73
80
  ];
74
81
  const NOTES = [
@@ -119,8 +126,9 @@ const NOTES = [
119
126
  coin: { type: "string", enum: [...COINS] },
120
127
  amount: { type: "string", pattern: "^[1-9][0-9]*$", description: UNITS },
121
128
  to: { type: "string", pattern: "^0x[0-9a-fA-F]{64}$", description: "recipient address" },
129
+ force: FORCE,
122
130
  }, ["coin", "amount", "to"]),
123
- run: async (ctx, args) => landed(await ctx.client.notes.withdraw(parseCoin(args), parseAmount(args), parsePayee(args))),
131
+ run: async (ctx, args) => landed(await ctx.client.notes.withdraw(parseCoin(args), parseAmount(args), parsePayee(args), parseForce(args))),
124
132
  },
125
133
  {
126
134
  name: "essey_notes_receive_address",
@@ -355,7 +363,8 @@ const VIEWS = [
355
363
  name: "essey_loan_view",
356
364
  kind: "read",
357
365
  description: "Read-only loan status and health from public fields: state, whether the floor still covers, LTV, " +
358
- "underwater, liquidation price and the best heartbeat bucket. Does not read a key and does not send a transaction.",
366
+ "underwater, liquidation price and whether a heartbeat at the default bucket (k 1) proves it healthy. Does not " +
367
+ "read a key and does not send a transaction.",
359
368
  inputSchema: VIEW_SCHEMA,
360
369
  run: async (ctx, args) => {
361
370
  const status = await ctx.client.loans.health(parseView(args));
@@ -366,7 +375,8 @@ const VIEWS = [
366
375
  ltvBps: status.ltvBps,
367
376
  underwater: status.underwater,
368
377
  liquidationPrice: status.liquidationPrice,
369
- bestBucketK: status.bestBucketK,
378
+ // LOAN-06: k 1 has the highest floor, so any healthy bucket means k 1 is healthy; the deepest k is not shown.
379
+ coveredAtDefaultK: status.bestBucketK !== null,
370
380
  };
371
381
  },
372
382
  },
@@ -380,6 +390,7 @@ export const TOOLS = [
380
390
  ...SALE_TOOLS,
381
391
  ...BADGE_TOOLS,
382
392
  ...MORE,
393
+ ...RECORD_TOOLS,
383
394
  ];
384
395
  function assertKnownArgs(tool, args) {
385
396
  const schema = tool.inputSchema;
@@ -401,9 +412,15 @@ export function bind(ctx, tools = TOOLS) {
401
412
  assertNoSecrets(args);
402
413
  assertKnownArgs(tool, args ?? {});
403
414
  const fields = redact(await tool.run(ctx, args ?? {}), ctx.redact);
415
+ const landedAtMs = Date.now();
404
416
  if (fields === null || typeof fields !== "object" || Array.isArray(fields))
405
417
  throw new Error("result");
406
- return { text: JSON.stringify({ ...fields, ok: true }, null, 2), isError: false };
418
+ const lagging = tool.kind === "call" &&
419
+ typeof fields.digest === "string" &&
420
+ ctx.waitIndexed &&
421
+ !(await ctx.waitIndexed(landedAtMs).catch(() => false));
422
+ const out = lagging ? { ...fields, indexed: false } : fields;
423
+ return { text: JSON.stringify({ ...out, ok: true }, null, 2), isError: false };
407
424
  }
408
425
  catch (err) {
409
426
  const reply = failureOf(err, ctx.redact);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esseyonsui/sui-mcp-v3",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -29,9 +29,11 @@
29
29
  "typecheck": "tsc --noEmit -p tsconfig.json"
30
30
  },
31
31
  "dependencies": {
32
- "@esseyonsui/sui-sdk-v3": "0.1.3",
32
+ "@esseyonsui/sui-sdk-v3": "0.1.5",
33
33
  "@mysten/seal": "1.5.1",
34
34
  "@mysten/sui": "2.37.0",
35
+ "@noble/ciphers": "2.4.0",
36
+ "@noble/hashes": "2.4.0",
35
37
  "snarkjs": "0.7.6"
36
38
  }
37
39
  }