@esseyonsui/sui-mcp-v3 0.1.0 → 0.1.2

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
@@ -21,9 +21,13 @@ The server speaks the same hand-written stdio subset as `packages/mcp`: `initial
21
21
  ## Keys
22
22
 
23
23
  `ESSEY_NOTE_KEY_FILE` and `ESSEY_AGENT_KEY_FILE` are mode-600 paths. The note file is 32 raw bytes or 64 hex
24
- digits; the server passes it to `Essey.connect` and does not put it on the tool context. The agent key file is
25
- checked at startup and never read: V3 loan and note calls go through the SDK, which does not take that key, and
26
- this server does not sign. No tool argument is a key, a seed, or the invite. `ESSEY_INVITE`, when set, is the
24
+ digits; the server passes it to `Essey.connect` and does not put it on the tool context. The agent key file holds
25
+ the `suiprivkey` text `essey-sui-mcp-v3-init` writes; the server loads it at startup (`src/keys.ts`) and signs one
26
+ kind of transaction with it: inside `essey_sale_open`, a transfer of the item being sold from the agent address to
27
+ the fresh sender the SDK derives from the note key, which then opens the room while the relayer pays
28
+ (`src/agent.ts`). The agent address pays that transfer's gas. No tool argument names the recipient, and the key
29
+ signs nothing else; loan, note and every other sale call go through the SDK's relayer. No tool argument is a key,
30
+ a seed, or the invite. `ESSEY_INVITE`, when set, is the
27
31
  invite gate for `essey_credential_obtain`. Results drop secret names (`borrowerSk`, `loanKey`, `salt`, and the same words inside a larger name), raw bytes,
28
32
  `suiprivkey` text, bare 64-hex seeds, and the invite. An SDK failure returns its error code and a fixed hint,
29
33
  not the SDK's message; a service refusal adds the service's own all-capitals code as `reason` (`RATE_LIMITED`,
@@ -50,6 +54,21 @@ needs and no chain read gives back (the borrower's terms, key and locked amount;
50
54
  written to `loan-<id>.json` and `offer-<id>.json`, mode 600, in the state file's directory, the same files
51
55
  `scripts/v3/live/run.mts` writes. No tool returns them. Give each server its own state directory.
52
56
 
57
+ Seller: `essey_agent_address` (the address to send the item and testnet SUI to), `essey_sale_open` (item id and
58
+ struct tag, coin, sealed min and max price, bid window, finish window, max bids), `essey_sale_finish`,
59
+ `essey_sale_slash` (a bid `essey_sale_finish` names as not opening), `essey_sale_cancel` (before any bid),
60
+ `essey_sale_expire` (anyone, after the finish window).
61
+
62
+ Bidder: `essey_sale_list`, `essey_sale_view`, `essey_sale_bid` (room, sealed price, deposit),
63
+ `essey_sale_reclaim` (the deposit, or with `residual` the winner's change), `essey_sale_claim` (as `bidder` when
64
+ the bid won, or as `seller` after a cancel or expiry; `to` defaults to the agent address).
65
+
66
+ The seller's keys and price bounds and the bidder's bid record go to `sale-<room>.json` and `bid-<room>.json`,
67
+ mode 600, beside the loan records, the same files `scripts/v3/live/run.mts` writes. No tool returns them. The
68
+ item vault is found on chain by its room. The sellable item type on testnet is the demo
69
+ `0x48db0307be9b6aadbf9f29c28561e1b450348ab2786ea4853a8d7249c22979a1::demo::Badge`, which anyone can mint with
70
+ its public `demo::mint` and transfer to the agent address.
71
+
53
72
  `essey_loan_status` reads one loan's public fields from chain. `essey_loan_view` runs the SDK's `localHealth`
54
73
  and `covered` on the public fields in its arguments and reads nothing.
55
74
 
@@ -65,7 +84,7 @@ Amounts are whole-number strings in the coin's smallest unit.
65
84
  | `ESSEY_V3_CONFIG` | `https` URL of `GET /v3/config`, or `http` on localhost, or a path to that JSON (required). A URL is what lets the SDK name the v3api. A file has no API origin. |
66
85
  | `ESSEY_STATE_FILE` | mode-600 state path the SDK keeps the credential in (required) |
67
86
  | `ESSEY_NOTE_KEY_FILE` | mode-600 note seed (required) |
68
- | `ESSEY_AGENT_KEY_FILE` | mode-600 agent key file (required; not read) |
87
+ | `ESSEY_AGENT_KEY_FILE` | mode-600 agent key file (required; signs only the sale item hand-over, see Keys) |
69
88
  | `ESSEY_INVITE` | optional invite token, 1..256 characters without whitespace |
70
89
  | `ESSEY_RELAYER` | `clear` (default) or `onion` |
71
90
  | `ESSEY_GRAPHQL` | Sui GraphQL URL, `https` or `http` on localhost (default `https://graphql.testnet.sui.io/graphql`) |
@@ -0,0 +1,19 @@
1
+ import type { Signer } from "@mysten/sui/cryptography";
2
+ import { Transaction } from "@mysten/sui/transactions";
3
+ import type { EsseyIo } from "@esseyonsui/sui-sdk-v3";
4
+ export type DeliverSaleItem = NonNullable<EsseyIo["deliverSaleItem"]>;
5
+ /** Signs, executes and resolves once the transaction succeeded. */
6
+ export type Execute = (tx: Transaction) => Promise<void>;
7
+ export type HandOver = {
8
+ signer: Signer;
9
+ execute: Execute;
10
+ readObjectRef: NonNullable<EsseyIo["readObjectRef"]>;
11
+ wait?: (ms: number) => Promise<void>;
12
+ };
13
+ export declare function graphqlExecute(url: string, signer: Signer): Execute;
14
+ /**
15
+ * The only transaction the agent key signs: one object to the sponsored sale open's sender. The SDK derives that
16
+ * sender from the note seed (`essey.ts` saleSponsor), so no tool argument names a recipient.
17
+ */
18
+ export declare function itemHandOver({ signer, execute, readObjectRef, wait }: HandOver): DeliverSaleItem;
19
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAItD,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAEtE,mEAAmE;AACnE,MAAM,MAAM,OAAO,GAAG,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzD,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,WAAW,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC;IACrD,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC,CAAC;AAEF,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAMnE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,IAAY,EAAE,EAAE,QAAQ,GAAG,eAAe,CAcxG"}
package/dist/agent.js ADDED
@@ -0,0 +1,33 @@
1
+ import { SuiGraphQLClient } from "@mysten/sui/graphql";
2
+ import { Transaction } from "@mysten/sui/transactions";
3
+ import { normalizeSuiAddress } from "@mysten/sui/utils";
4
+ const INDEX_RETRIES = 15;
5
+ export function graphqlExecute(url, signer) {
6
+ const client = new SuiGraphQLClient({ url, network: "testnet" });
7
+ return async (tx) => {
8
+ const r = await signer.signAndExecuteTransaction({ transaction: tx, client });
9
+ if (r.$kind !== "Transaction")
10
+ throw new Error("the item hand-over failed on chain");
11
+ };
12
+ }
13
+ /**
14
+ * The only transaction the agent key signs: one object to the sponsored sale open's sender. The SDK derives that
15
+ * sender from the note seed (`essey.ts` saleSponsor), so no tool argument names a recipient.
16
+ */
17
+ export function itemHandOver({ signer, execute, readObjectRef, wait = sleep }) {
18
+ return async ({ item, sender }) => {
19
+ const to = normalizeSuiAddress(sender);
20
+ const tx = new Transaction();
21
+ tx.setSender(signer.toSuiAddress());
22
+ tx.transferObjects([tx.object(item.id)], to);
23
+ await execute(tx);
24
+ for (let i = 0; i < INDEX_RETRIES; i++) {
25
+ const { owner } = await readObjectRef(item.id);
26
+ if (owner !== null && normalizeSuiAddress(owner) === to)
27
+ return;
28
+ await wait(2000);
29
+ }
30
+ throw new Error("the handed-over item is not indexed at the sale sender yet");
31
+ };
32
+ }
33
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
package/dist/args.d.ts CHANGED
@@ -2,7 +2,16 @@ import { type CoinKey } from "@esseyonsui/sui-sdk-v3";
2
2
  import type { OpenParams } from "./client.ts";
3
3
  import type { PublicLoan } from "./loan-view.ts";
4
4
  type Rec = Record<string, unknown>;
5
- type JsonSchema = Record<string, unknown>;
5
+ export type JsonSchema = Record<string, unknown>;
6
+ export declare const AMOUNT: JsonSchema;
7
+ export declare const COIN: JsonSchema;
8
+ export declare const ADDRESS: JsonSchema;
9
+ export declare const MS: JsonSchema;
10
+ export declare const objectSchema: (properties: Record<string, JsonSchema>, required: string[]) => JsonSchema;
11
+ export declare function address(a: Rec, k: string): string;
12
+ export declare function payee(a: Rec, k: string): string;
13
+ export declare function optBool(a: Rec, k: string): boolean | undefined;
14
+ export declare function int(a: Rec, k: string, min: number, max: number): number;
6
15
  export declare function parseRole(args: Rec): "member" | "keeper" | undefined;
7
16
  export declare function parseCoin(args: Rec, k?: string): CoinKey;
8
17
  export declare function parseAmount(args: Rec, k?: string): bigint;
@@ -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,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAoF1C,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAIpE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,SAAS,GAAG,OAAO,CAExD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,SAAW,GAAG,MAAM,CAI3D;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,GAA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64",
13
13
  };
14
- const AMOUNT = {
14
+ export const AMOUNT = {
15
15
  type: "string",
16
16
  pattern: "^[1-9][0-9]*$",
17
17
  description: "whole-number string in the coin's smallest unit",
18
18
  };
19
- const COIN = { type: "string", enum: [...COINS], description: "tusdsui, usdc or sui" };
20
- const ADDRESS = {
19
+ export const COIN = { type: "string", enum: [...COINS], description: "tusdsui, usdc or sui" };
20
+ export const ADDRESS = {
21
21
  type: "string",
22
22
  pattern: "^0x[0-9a-fA-F]{1,64}$",
23
23
  description: "0x object id",
@@ -27,8 +27,8 @@ const LOAN = {
27
27
  description: "loan id, as essey_loan_open or essey_loan_list returns it",
28
28
  };
29
29
  const BPS = { type: "integer", minimum: 0, maximum: MAX_BPS, description: "basis points" };
30
- const MS = { type: "integer", minimum: 1, maximum: Number.MAX_SAFE_INTEGER };
31
- const objectSchema = (properties, required) => ({
30
+ export const MS = { type: "integer", minimum: 1, maximum: Number.MAX_SAFE_INTEGER };
31
+ export const objectSchema = (properties, required) => ({
32
32
  type: "object",
33
33
  properties,
34
34
  required,
@@ -56,7 +56,7 @@ function coin(a, k) {
56
56
  bad(`${k} must be tusdsui, usdc or sui`);
57
57
  return v;
58
58
  }
59
- function address(a, k) {
59
+ export function address(a, k) {
60
60
  const v = a[k];
61
61
  if (typeof v !== "string")
62
62
  bad(`${k} must be an 0x address`);
@@ -65,7 +65,7 @@ function address(a, k) {
65
65
  bad(`${k} must be an 0x address`);
66
66
  return `0x${hex.padStart(64, "0")}`;
67
67
  }
68
- function payee(a, k) {
68
+ export function payee(a, k) {
69
69
  const v = a[k];
70
70
  if (typeof v !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(v))
71
71
  bad(`${k} must be 0x and 64 hex digits`);
@@ -74,14 +74,14 @@ function payee(a, k) {
74
74
  bad(`${k} is the zero address`);
75
75
  return out;
76
76
  }
77
- function optBool(a, k) {
77
+ export function optBool(a, k) {
78
78
  if (a[k] === undefined)
79
79
  return undefined;
80
80
  if (typeof a[k] !== "boolean")
81
81
  bad(`${k} must be true or false`);
82
82
  return a[k];
83
83
  }
84
- function int(a, k, min, max) {
84
+ export function int(a, k, min, max) {
85
85
  const v = a[k];
86
86
  if (typeof v !== "number" || !Number.isInteger(v) || v < min || v > max)
87
87
  bad(`${k} must be an integer from ${min} to ${max}`);
package/dist/client.d.ts CHANGED
@@ -18,8 +18,14 @@ export type DemoClient = {
18
18
  } & Landed>;
19
19
  health(loan: PublicLoan): Promise<LoanStatus>;
20
20
  };
21
+ sales: Essey["sales"] & SaleChain;
21
22
  };
22
- export declare function clientOf(essey: Essey, health?: DemoClient["loans"]["health"]): DemoClient;
23
+ /** The agent key's public address and the vault lookup; the key itself stays in `agent.ts`. */
24
+ export type SaleChain = {
25
+ agentAddress: string;
26
+ vaultOf(room: string): Promise<string>;
27
+ };
28
+ export declare function clientOf(essey: Essey, chain: SaleChain, health?: DemoClient["loans"]["health"]): DemoClient;
23
29
  /** The invite stays in the server process. Tool arguments cannot replace it or read it back. */
24
30
  export declare function withInvite(client: DemoClient, invite: string | null): DemoClient;
25
31
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG7D,KAAK,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;AAC5B,KAAK,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAEtF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,UAAU,EAA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,GAAG,UAAU,CAShF"}
package/dist/client.js CHANGED
@@ -6,8 +6,8 @@ async function openPlanned(essey, p) {
6
6
  throw new Error("loan open returned no id");
7
7
  return r;
8
8
  }
9
- export function clientOf(essey, health = (loan) => Promise.resolve(statusOf(loan))) {
10
- const { loans, notes } = essey;
9
+ export function clientOf(essey, chain, health = (loan) => Promise.resolve(statusOf(loan))) {
10
+ const { loans, notes, sales } = essey;
11
11
  return {
12
12
  credential: essey.credential,
13
13
  notes: {
@@ -37,6 +37,21 @@ export function clientOf(essey, health = (loan) => Promise.resolve(statusOf(loan
37
37
  view: (id) => loans.view(id),
38
38
  health,
39
39
  },
40
+ sales: {
41
+ open: (p) => sales.open(p),
42
+ list: () => sales.list(),
43
+ view: (id) => sales.view(id),
44
+ bid: (p) => sales.bid(p),
45
+ finish: (p) => sales.finish(p),
46
+ slash: (p) => sales.slash(p),
47
+ expire: (p) => sales.expire(p),
48
+ reclaim: (p) => sales.reclaim(p),
49
+ claim: (p) => sales.claim(p),
50
+ cancel: (p) => sales.cancel(p),
51
+ badgeGrant: (to) => sales.badgeGrant(to),
52
+ agentAddress: chain.agentAddress,
53
+ vaultOf: (room) => chain.vaultOf(room),
54
+ },
40
55
  };
41
56
  }
42
57
  /** The invite stays in the server process. Tool arguments cannot replace it or read it back. */
package/dist/config.d.ts CHANGED
@@ -14,7 +14,7 @@ export type McpConfig = {
14
14
  graphql: string;
15
15
  /** Mode-600 note seed. The server passes it to the SDK and does not keep a copy on the tool context. */
16
16
  noteKeyFile: string;
17
- /** Mode-600 agent key file. Checked at startup and never read, signed with, or accepted as a tool argument. */
17
+ /** Mode-600 agent key file. Signs only the sale item hand-over (`agent.ts`); never a tool argument. */
18
18
  agentKeyFile: string;
19
19
  /** Invite gate token. Unset: credential obtain uses the proof-of-work challenge. Never a tool argument. */
20
20
  invite: string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,M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,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,eAAe,2CAA2C,CAAC;AAaxE,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,oBAAoB;CAClC;AAWD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,SAAS,CA0B7D"}
package/dist/failure.d.ts CHANGED
@@ -5,6 +5,10 @@ export type Failure = {
5
5
  error: string;
6
6
  hint: string;
7
7
  reason?: string;
8
+ abort?: {
9
+ module: string;
10
+ code: number;
11
+ };
8
12
  };
9
13
  /**
10
14
  * A refusal this server words itself. The hint is a rule, never a value the caller sent.
@@ -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;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAKlF;;;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,CAQhF;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,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"}
package/dist/failure.js CHANGED
@@ -3,6 +3,27 @@ import { redactText, secretArgument } from "./redact.js";
3
3
  export const WITHHELD = "The tool failed inside a library; its error is withheld.";
4
4
  /** Only an all-capitals code is passed on (RATE_LIMITED, E_INSOLVENT): no digits, so no key text fits it. */
5
5
  const SERVICE_CODE = /^(?:v3api|relayer) refused: ([A-Z_]{3,40})$/;
6
+ const CODE = /^[A-Z_]{3,40}$/;
7
+ const MODULE = /^[a-z0-9_]{1,40}::[a-z0-9_]{1,40}$/;
8
+ /** The relayer's own code (`ServiceDetail.error`) and Move abort, both a fixed shape a key cannot take. */
9
+ function relayReason(err) {
10
+ const { error, abort } = err.detail ?? {};
11
+ const reason = typeof error === "string" && CODE.test(error) ? error : undefined;
12
+ const moved = abort && MODULE.test(abort.module) && Number.isSafeInteger(abort.code) && abort.code >= 0;
13
+ return {
14
+ ...(reason ? { reason } : {}),
15
+ ...(moved ? { abort: { module: abort.module, code: abort.code } } : {}),
16
+ };
17
+ }
18
+ function reasonOf(err) {
19
+ if (err.code === "RELAY_REFUSED" || err.code === "RELAY_FAILED")
20
+ return relayReason(err);
21
+ if (err.code !== "SERVICE_REFUSED")
22
+ return {};
23
+ const reason = SERVICE_CODE.exec(err.message)?.[1] ??
24
+ (err.message.startsWith("unknown object: ") ? "UNKNOWN_OBJECT" : undefined);
25
+ return reason ? { reason } : {};
26
+ }
6
27
  /**
7
28
  * A refusal this server words itself. The hint is a rule, never a value the caller sent.
8
29
  * Adapted from the VPS draft at 882f9eec (claude/v3-054-mcp-wip).
@@ -23,9 +44,8 @@ export function failureOf(err, secrets = []) {
23
44
  if (err instanceof ToolRefusal)
24
45
  return { ok: false, error: err.code, hint: redactText(err.hint, secrets) };
25
46
  if (isEsseyError(err) && ESSEY_ERROR_CODES.includes(err.code)) {
26
- const reason = err.code === "SERVICE_REFUSED" ? SERVICE_CODE.exec(err.message)?.[1] : undefined;
27
47
  const hint = `Look up ${err.code} in the sdk/errors reference.`;
28
- return { ok: false, error: err.code, hint, ...(reason ? { reason } : {}) };
48
+ return { ok: false, error: err.code, hint, ...reasonOf(err) };
29
49
  }
30
50
  return { ok: false, error: "UNEXPECTED", hint: WITHHELD };
31
51
  }
package/dist/io.d.ts CHANGED
@@ -54,7 +54,7 @@ export declare function chainIo(config: Json, o: ChainIoOptions): {
54
54
  publishS: bigint;
55
55
  }>;
56
56
  readSeizure: (loanId: string) => Promise<{
57
- readonly mode: "liquidate" | "fault" | "default";
57
+ readonly mode: "default" | "liquidate" | "fault";
58
58
  readonly pSpot: bigint;
59
59
  }>;
60
60
  readSettleTime: (loanId: string) => Promise<bigint>;
@@ -81,6 +81,8 @@ export declare function chainIo(config: Json, o: ChainIoOptions): {
81
81
  rooms: any;
82
82
  next: string | null;
83
83
  }>;
84
+ readVaultOf: (room: string) => Promise<string>;
85
+ readAddressUsed: (address: string) => Promise<boolean>;
84
86
  readVault: (id: string) => Promise<{
85
87
  json: any;
86
88
  }>;
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;AAKvD,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;AA+OD,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAkCnC,KAAK,OAAO,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AAG;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;;wBAY/B,MAAM;;;;;0BACJ,MAAM;gBAvWR,MAAM;gBACL,MAAM;;;;;;0BAuWL,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;2CAnG5B;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;mBA2ChC,MAAM;;;;wBACD,MAAM,GAAG,IAAI;;;;;;;;;;0BAGL,MAAM;4BAEJ,MAAM;qBACb,MAAM;;;;;;;;EAkBhC"}
package/dist/io.js CHANGED
@@ -6,6 +6,7 @@ import { DemType, SealClient, SessionKey } from "@mysten/seal";
6
6
  import { SuiGraphQLClient } from "@mysten/sui/graphql";
7
7
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
8
8
  import { Transaction } from "@mysten/sui/transactions";
9
+ import { normalizeSuiAddress } from "@mysten/sui/utils";
9
10
  import { v3 } from "@esseyonsui/sui-sdk-v3";
10
11
  export { TESTNET_GRAPHQL } from "./config.js";
11
12
  const require = createRequire(import.meta.url);
@@ -275,6 +276,25 @@ async function readRooms(gql, origin, cursor) {
275
276
  next: d.objects.pageInfo.hasNextPage ? d.objects.pageInfo.endCursor : null,
276
277
  };
277
278
  }
279
+ /** A `SaleRoom` does not name its vault (`sale_room.move:115-143`); the `ItemVault` names its room. */
280
+ async function readVaultOf(gql, origin, room) {
281
+ const want = normalizeSuiAddress(room);
282
+ let after = null;
283
+ for (;;) {
284
+ const d = await gql(`query($t: String!, $a: String) { objects(first: ${LOAN_PAGE}, after: $a, filter: { type: $t }) { nodes { address asMoveObject { contents { json } } } pageInfo { hasNextPage endCursor } } }`, { t: `${origin}::vault::ItemVault`, a: after });
285
+ const hit = d.objects.nodes.find((n) => normalizeSuiAddress(String(n.asMoveObject.contents.json.room_id)) === want);
286
+ if (hit)
287
+ return hit.address;
288
+ if (!d.objects.pageInfo.hasNextPage)
289
+ throw new Error(`room ${room} has no item vault`);
290
+ after = d.objects.pageInfo.endCursor;
291
+ }
292
+ }
293
+ /** A sponsored sender must be one the chain has never seen: any transaction touching it, or a balance it holds. */
294
+ async function readAddressUsed(gql, address) {
295
+ const d = await gql(`query($a: SuiAddress!) { address(address: $a) { balances(first: 1) { nodes { totalBalance } } transactions(first: 1, relation: AFFECTED) { nodes { digest } } } }`, { a: address });
296
+ return (d.address?.balances?.nodes?.length ?? 0) > 0 || (d.address?.transactions?.nodes?.length ?? 0) > 0;
297
+ }
278
298
  function sealClient(config, url) {
279
299
  return new SealClient({
280
300
  suiClient: new SuiGraphQLClient({ url, network: "testnet" }),
@@ -374,6 +394,8 @@ export function chainIo(config, o) {
374
394
  readObjectRef: (id) => readObjectRef(gql, id),
375
395
  readRoom: (id) => readRoom(gql, id),
376
396
  readRooms: async (cursor) => readRooms(gql, originOf(config, "sale"), cursor),
397
+ readVaultOf: async (room) => readVaultOf(gql, originOf(config, "sale"), room),
398
+ readAddressUsed: (address) => readAddressUsed(gql, address),
377
399
  readVault: async (id) => ({ json: (await objectOf(gql, id)).asMoveObject.contents.json }),
378
400
  readMarket: async (id) => (await objectOf(gql, id)).asMoveObject.contents.json,
379
401
  sealEncrypt: sealerFor(config, o.graphql, o.garble ?? (() => false)),
package/dist/keys.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- /** The agent key is never loaded. Startup only checks that the file is a private key file. */
2
- export declare function assertAgentKeyFile(path: string): void;
1
+ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
2
+ /** The `suiprivkey` text `essey-sui-mcp-v3-init` writes. A refusal names the variable and not the file's text. */
3
+ export declare function loadAgentKey(path: string): Ed25519Keypair;
3
4
  /**
4
5
  * 32 raw bytes, or 64 hex digits. The caller zeros the returned buffer after `Essey.connect` copies it.
5
6
  * A refusal names the variable and not the file's bytes.
@@ -1 +1 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAqBA,8FAA8F;AAC9F,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAErD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAYrD"}
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAqB9D,kHAAkH;AAClH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAczD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAYrD"}
package/dist/keys.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { lstatSync, readFileSync } from "node:fs";
2
+ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
2
3
  import { ConfigError } from "./config.js";
3
4
  function fail(msg) {
4
5
  throw new ConfigError(msg);
@@ -19,9 +20,23 @@ function statKey(path, what, max) {
19
20
  if (st.size < 1 || st.size > max)
20
21
  fail(`${what} must be a key file`);
21
22
  }
22
- /** The agent key is never loaded. Startup only checks that the file is a private key file. */
23
- export function assertAgentKeyFile(path) {
23
+ /** The `suiprivkey` text `essey-sui-mcp-v3-init` writes. A refusal names the variable and not the file's text. */
24
+ export function loadAgentKey(path) {
24
25
  statKey(path, "ESSEY_AGENT_KEY_FILE", 4096);
26
+ let text;
27
+ try {
28
+ text = readFileSync(path, "utf8").trim();
29
+ }
30
+ catch {
31
+ fail("ESSEY_AGENT_KEY_FILE is not a mode-600 file");
32
+ }
33
+ try {
34
+ // 0.1.x accepted any mode-600 file; agent wallets made before init hold 64 hex digits, not a suiprivkey.
35
+ return Ed25519Keypair.fromSecretKey(/^[0-9a-fA-F]{64}$/.test(text) ? Buffer.from(text, "hex") : text);
36
+ }
37
+ catch {
38
+ fail("ESSEY_AGENT_KEY_FILE must hold an Ed25519 suiprivkey or 64 hex digits");
39
+ }
25
40
  }
26
41
  /**
27
42
  * 32 raw bytes, or 64 hex digits. The caller zeros the returned buffer after `Essey.connect` copies it.
package/dist/main.js CHANGED
@@ -2,10 +2,11 @@
2
2
  import { readFileSync } from "node:fs";
3
3
  import { dirname } from "node:path";
4
4
  import { ESSEY_ERROR_CODES, Essey, isEsseyError, parseConfig as parseDeployment, } from "@esseyonsui/sui-sdk-v3";
5
+ import { graphqlExecute, itemHandOver } from "./agent.js";
5
6
  import { clientOf, withInvite } from "./client.js";
6
7
  import { ConfigError, parseConfig } from "./config.js";
7
8
  import { chainIo } from "./io.js";
8
- import { assertAgentKeyFile, loadNoteSeed } from "./keys.js";
9
+ import { loadAgentKey, loadNoteSeed } from "./keys.js";
9
10
  import { serve } from "./protocol.js";
10
11
  import { fileRecords } from "./records.js";
11
12
  import { bind } from "./tools.js";
@@ -13,10 +14,14 @@ const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.u
13
14
  .version;
14
15
  const INSTRUCTIONS = "Essey V3 private testnet tools. Note and agent keys are files on this server, never tool arguments, and no tool " +
15
16
  "returns a key, seed, or spend secret. The invite, when there is one, is ESSEY_INVITE. Amounts are whole-number " +
16
- "strings in the coin's smallest unit. The server builds every proof itself and keeps loan terms and offer " +
17
- "records in its own files; no tool returns them. Borrow: essey_loan_open, wait for the window, essey_loan_settle, " +
18
- "essey_loan_repay, essey_loan_release. Lend: essey_loan_list, essey_loan_request, essey_loan_offer, then " +
19
- "essey_loan_collect after repay or essey_loan_reclaim if the offer lost. There is no refinance tool.";
17
+ "strings in the coin's smallest unit. The server builds every proof itself and keeps loan terms, offer, seller " +
18
+ "and bid records in its own files; no tool returns them. Borrow: essey_loan_open, wait for the window, " +
19
+ "essey_loan_settle, essey_loan_repay, essey_loan_release. Lend: essey_loan_list, essey_loan_request, " +
20
+ "essey_loan_offer, then essey_loan_collect after repay or essey_loan_reclaim if the offer lost. There is no " +
21
+ "refinance tool. Sell: put the item at essey_agent_address, essey_sale_open, after close essey_sale_finish " +
22
+ "(essey_sale_slash each bid it names first); or essey_sale_cancel before any bid, or essey_sale_expire after the " +
23
+ "finish window, then essey_sale_claim as seller. Buy: essey_sale_list, essey_sale_bid, and once the room ended " +
24
+ "essey_sale_claim as bidder if won and essey_sale_reclaim (residual if won, else the deposit).";
20
25
  /**
21
26
  * `source` is what `Essey.connect` takes: the URL, which names the v3api, or the parsed file. The io reads the
22
27
  * same record as JSON (Seal set, pools, circuit pins).
@@ -63,12 +68,19 @@ function startupCode(err) {
63
68
  /** Refuses to run, on stderr, when the config or a key file is wrong. stdout carries only MCP. */
64
69
  async function start() {
65
70
  const cfg = parseConfig(process.env);
66
- assertAgentKeyFile(cfg.agentKeyFile);
71
+ const agent = loadAgentKey(cfg.agentKeyFile);
67
72
  const seed = loadNoteSeed(cfg.noteKeyFile);
68
73
  try {
69
74
  const { source, raw } = await deploymentOf(cfg);
70
- const essey = await Essey.connect({ network: "testnet", statePath: cfg.stateFile, config: source, seed, relayer: cfg.relayer }, chainIo(raw, { graphql: cfg.graphql }));
71
- const client = withInvite(clientOf(essey), cfg.invite);
75
+ const io = chainIo(raw, { graphql: cfg.graphql });
76
+ const deliverSaleItem = itemHandOver({
77
+ signer: agent,
78
+ execute: graphqlExecute(cfg.graphql, agent),
79
+ readObjectRef: io.readObjectRef,
80
+ });
81
+ const essey = await Essey.connect({ network: "testnet", statePath: cfg.stateFile, config: source, seed, relayer: cfg.relayer }, { ...io, deliverSaleItem });
82
+ const sale = { agentAddress: agent.toSuiAddress(), vaultOf: io.readVaultOf };
83
+ const client = withInvite(clientOf(essey, sale), cfg.invite);
72
84
  const tools = bind({
73
85
  client,
74
86
  records: fileRecords(dirname(cfg.stateFile)),
package/dist/records.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import type { Essey } from "@esseyonsui/sui-sdk-v3";
1
+ import type { Essey, 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
+ export type BidRecord = Awaited<ReturnType<Essey["sales"]["bid"]>>["bid"];
5
+ export type { SaleRecord };
4
6
  /** A borrower's own loan. `terms` and `borrowerPk` arrive with settle; until then only the locked amount is known. */
5
7
  export type LoanRecord = {
6
8
  collAmt: bigint;
@@ -9,13 +11,18 @@ export type LoanRecord = {
9
11
  };
10
12
  /**
11
13
  * What a cycle step needs from an earlier one and no chain read gives back. Same files and JSON as
12
- * `scripts/v3/live/run.mts` (`loan-<id>.json`, `offer-<id>.json`), mode 600, beside the state file.
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
16
  */
14
17
  export type Records = {
15
18
  loan(id: string): LoanRecord;
16
19
  saveLoan(id: string, record: LoanRecord): void;
17
20
  offer(id: string): OfferRecord;
18
21
  saveOffer(id: string, record: OfferRecord): void;
22
+ sale(room: string): SaleRecord;
23
+ saveSale(room: string, record: SaleRecord): void;
24
+ bid(room: string): BidRecord;
25
+ saveBid(room: string, record: BidRecord): void;
19
26
  };
20
27
  export declare function fileRecords(dir: string): Records;
21
28
  //# 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,MAAM,wBAAwB,CAAC;AAIpD,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;AAE/E,sHAAsH;AACtH,MAAM,MAAM,UAAU,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAC/C,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,CAAC;IAC/B,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;CAClD,CAAC;AAeF,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CA4ChD"}
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,C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
5
5
  const LOAN_ID = /^0x[0-9a-f]{64}$/;
6
6
  const plain = (v) => JSON.stringify(v, (_k, x) => (typeof x === "bigint" ? x.toString() : x));
7
7
  const big = (v) => (v === undefined ? undefined : BigInt(v));
8
+ const MISSING = {
9
+ loan: "this server holds no borrower record for that loan: open it from this server first",
10
+ offer: "this server holds no offer record for that loan: offer on it from this server first",
11
+ sale: "this server holds no seller record for that room: open the sale from this server first",
12
+ bid: "this server holds no bid record for that room: bid on it from this server first",
13
+ };
8
14
  function noRecord(kind) {
9
- throw new ToolRefusal(kind === "loan"
10
- ? "this server holds no borrower record for that loan: open it from this server first"
11
- : "this server holds no offer record for that loan: offer on it from this server first");
15
+ throw new ToolRefusal(MISSING[kind]);
12
16
  }
13
17
  export function fileRecords(dir) {
14
18
  const path = (kind, id) => {
@@ -56,5 +60,27 @@ export function fileRecords(dir) {
56
60
  };
57
61
  },
58
62
  saveOffer: (id, record) => write("offer", id, record),
63
+ sale: (room) => {
64
+ const r = read("sale", room) ?? noRecord("sale");
65
+ const seller = r.seller;
66
+ const bounds = r.bounds;
67
+ return {
68
+ room: r.room,
69
+ noteIndex: r.noteIndex,
70
+ seller: { sellerSk: BigInt(seller.sellerSk), sellerSecret: BigInt(seller.sellerSecret) },
71
+ bounds: { lo: BigInt(bounds.lo), hi: BigInt(bounds.hi), salt: BigInt(bounds.salt) },
72
+ };
73
+ },
74
+ saveSale: (room, record) => write("sale", room, record),
75
+ bid: (room) => {
76
+ const r = read("bid", room) ?? noRecord("bid");
77
+ return {
78
+ room: r.room,
79
+ noteIndex: r.noteIndex,
80
+ v: BigInt(r.v),
81
+ amount: BigInt(r.amount),
82
+ };
83
+ },
84
+ saveBid: (room, record) => write("bid", room, record),
59
85
  };
60
86
  }
@@ -0,0 +1,5 @@
1
+ import type { Tool } from "./tools.ts";
2
+ /** The one sale item the testnet KeyRegistry allows (`scripts/v3/live/io.ts:23`), the type the grant mints. */
3
+ export declare const TESTNET_BADGE_TYPE = "0x48db0307be9b6aadbf9f29c28561e1b450348ab2786ea4853a8d7249c22979a1::demo::Badge";
4
+ export declare const BADGE_TOOLS: Tool[];
5
+ //# sourceMappingURL=tools-badge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools-badge.d.ts","sourceRoot":"","sources":["../src/tools-badge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,+GAA+G;AAC/G,eAAO,MAAM,kBAAkB,oFACoD,CAAC;AAEpF,eAAO,MAAM,WAAW,EAAE,IAAI,EAe7B,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { objectSchema } from "./args.js";
2
+ /** The one sale item the testnet KeyRegistry allows (`scripts/v3/live/io.ts:23`), the type the grant mints. */
3
+ export const TESTNET_BADGE_TYPE = "0x48db0307be9b6aadbf9f29c28561e1b450348ab2786ea4853a8d7249c22979a1::demo::Badge";
4
+ export const BADGE_TOOLS = [
5
+ {
6
+ name: "essey_badge_grant",
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 " +
10
+ "public on chain and the service sees it beside this credential's day-tag. Returns the digest and the " +
11
+ "itemId and itemType to pass to essey_sale_open.",
12
+ inputSchema: objectSchema({}, []),
13
+ run: async (ctx) => {
14
+ const { digest, badge } = await ctx.client.sales.badgeGrant(ctx.client.sales.agentAddress);
15
+ return { ok: true, digest, itemId: badge, itemType: TESTNET_BADGE_TYPE };
16
+ },
17
+ },
18
+ ];
@@ -0,0 +1,3 @@
1
+ import type { Tool } from "./tools.ts";
2
+ export declare const SALE_TOOLS: Tool[];
3
+ //# sourceMappingURL=tools-sales.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,222 @@
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";
3
+ import { ToolRefusal } from "./failure.js";
4
+ const SLOTS = v3.sales.SLOTS;
5
+ /** `sale_room.move:30-33`. */
6
+ const ROOM_STATES = ["open", "settled", "expired", "cancelled"];
7
+ /** `v3/sales/seller.ts` STRUCT_TAG: a non-generic struct tag. */
8
+ const STRUCT_TAG = "^0x[0-9a-fA-F]{1,64}::[A-Za-z_][A-Za-z0-9_]*::[A-Za-z_][A-Za-z0-9_]*$";
9
+ /** The SDK's own finish refusal (`essey.ts` finishSale). Only its digits reach the caller. */
10
+ const SLASH_FIRST = /^refused: slash bids ([0-9]+(?:, [0-9]+)*) first$/;
11
+ const ROOM = { ...ADDRESS, description: "sale room id, as essey_sale_open or essey_sale_list returns it" };
12
+ const ROOM_SCHEMA = objectSchema({ room: ROOM }, ["room"]);
13
+ function bad(msg) {
14
+ throw new ToolRefusal(msg);
15
+ }
16
+ function landed(row) {
17
+ return { ok: true, digest: row.digest, ticket: row.ticket };
18
+ }
19
+ const parseRoom = (args) => address(args, "room");
20
+ function summary(row) {
21
+ const state = ROOM_STATES[row.state] ?? "unknown";
22
+ return { id: row.id, coin: row.coin, state, closeMs: row.closeMs, bids: row.bids };
23
+ }
24
+ function parseSaleOpen(args, nowMs) {
25
+ const minPrice = parseAmount(args, "minPrice");
26
+ const maxPrice = parseAmount(args, "maxPrice");
27
+ if (minPrice > maxPrice)
28
+ bad("minPrice must be at most maxPrice");
29
+ const itemType = args.itemType;
30
+ if (typeof itemType !== "string" || !new RegExp(STRUCT_TAG).test(itemType))
31
+ bad("itemType must be a non-generic struct tag, 0x<package>::<module>::<Type>");
32
+ const closeMs = nowMs + int(args, "bidWindowMs", 1, Number.MAX_SAFE_INTEGER);
33
+ if (!Number.isSafeInteger(closeMs))
34
+ bad("bidWindowMs is too long");
35
+ return {
36
+ itemId: address(args, "itemId"),
37
+ itemType,
38
+ coin: parseCoin(args),
39
+ minPrice,
40
+ maxPrice,
41
+ closeMs,
42
+ finishWindowMs: int(args, "finishWindowMs", 1, Number.MAX_SAFE_INTEGER),
43
+ maxBids: int(args, "maxBids", 1, SLOTS),
44
+ sponsored: true,
45
+ };
46
+ }
47
+ function parseBid(args) {
48
+ const v = parseAmount(args, "price");
49
+ const amount = parseAmount(args, "deposit");
50
+ if (v > amount)
51
+ bad("price must be at most deposit");
52
+ return { room: parseRoom(args), v, amount };
53
+ }
54
+ function parseClaim(ctx, args) {
55
+ if (args.as !== "seller" && args.as !== "bidder")
56
+ bad("as must be seller or bidder");
57
+ const to = args.to === undefined ? ctx.client.sales.agentAddress : payee(args, "to");
58
+ return { room: parseRoom(args), as: args.as, to };
59
+ }
60
+ async function finish(ctx, room) {
61
+ const { seller, bounds } = ctx.records.sale(room);
62
+ const vault = await ctx.client.sales.vaultOf(room);
63
+ try {
64
+ return await ctx.client.sales.finish({ room, vault, seller, bounds });
65
+ }
66
+ catch (err) {
67
+ const seqs = isEsseyError(err) ? SLASH_FIRST.exec(err.message)?.[1] : undefined;
68
+ if (seqs)
69
+ bad(`bids ${seqs} do not open to their locks: call essey_sale_slash for each, then finish`);
70
+ throw err;
71
+ }
72
+ }
73
+ async function withVault(ctx, args) {
74
+ const room = parseRoom(args);
75
+ return { room, vault: await ctx.client.sales.vaultOf(room) };
76
+ }
77
+ const SELLER = [
78
+ {
79
+ name: "essey_agent_address",
80
+ kind: "read",
81
+ description: "The Sui address of this server's agent key. Send it the item to sell and testnet SUI for gas. The key signs " +
82
+ "one kind of transaction: the item hand-over inside essey_sale_open.",
83
+ inputSchema: objectSchema({}, []),
84
+ run: async (ctx) => ({ ok: true, address: ctx.client.sales.agentAddress }),
85
+ },
86
+ {
87
+ name: "essey_sale_open",
88
+ kind: "call",
89
+ description: "Seller: open a sealed sale of an item essey_agent_address holds. The agent key hands the item to a fresh " +
90
+ "sender derived from the note key and the relayer pays the open. Bids close bidWindowMs from now; the seller " +
91
+ "finishes within finishWindowMs after that. The seller keys and price bounds stay in a mode-600 file. " +
92
+ "Returns the room id, digest and ticket.",
93
+ inputSchema: objectSchema({
94
+ itemId: { ...ADDRESS, description: "the item's object id, owned by essey_agent_address" },
95
+ itemType: {
96
+ type: "string",
97
+ pattern: STRUCT_TAG,
98
+ maxLength: 200,
99
+ description: "the item's struct tag, 0x<package>::<module>::<Type>",
100
+ },
101
+ coin: { ...COIN, description: "the coin bids are paid in" },
102
+ minPrice: { ...AMOUNT, description: "lowest price accepted; sealed, never shown to bidders" },
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" },
105
+ finishWindowMs: { ...MS, description: "how long after close the seller may finish, milliseconds" },
106
+ maxBids: { type: "integer", minimum: 1, maximum: SLOTS, description: `1 to ${SLOTS}` },
107
+ }, ["itemId", "itemType", "coin", "minPrice", "maxPrice", "bidWindowMs", "finishWindowMs", "maxBids"]),
108
+ run: async (ctx, args) => {
109
+ const r = await ctx.client.sales.open(parseSaleOpen(args, Date.now()));
110
+ ctx.records.saveSale(r.id, r.sale);
111
+ return { ...landed(r), room: r.id };
112
+ },
113
+ },
114
+ {
115
+ name: "essey_sale_finish",
116
+ kind: "call",
117
+ description: "Seller, after close and before the finish deadline: open every sealed bid and settle on the highest within " +
118
+ "the bounds; the price arrives as an own note. A bid that does not open is named: slash it first.",
119
+ inputSchema: ROOM_SCHEMA,
120
+ run: async (ctx, args) => landed(await finish(ctx, parseRoom(args))),
121
+ },
122
+ {
123
+ name: "essey_sale_slash",
124
+ kind: "call",
125
+ description: "After close and before the finish deadline: mark bid seq inactive when its sealed price does not open its " +
126
+ "commit and lock. essey_sale_finish names the bids to slash.",
127
+ inputSchema: objectSchema({ room: ROOM, seq: { type: "integer", minimum: 0, maximum: SLOTS - 1, description: "bid position" } }, ["room", "seq"]),
128
+ run: async (ctx, args) => landed(await ctx.client.sales.slash({ room: parseRoom(args), seq: int(args, "seq", 0, SLOTS - 1) })),
129
+ },
130
+ {
131
+ name: "essey_sale_cancel",
132
+ kind: "call",
133
+ description: "Seller, before any bid: cancel the sale. Then essey_sale_claim as seller takes the item back.",
134
+ inputSchema: ROOM_SCHEMA,
135
+ run: async (ctx, args) => landed(await ctx.client.sales.cancel(await withVault(ctx, args))),
136
+ },
137
+ {
138
+ name: "essey_sale_expire",
139
+ kind: "call",
140
+ description: "Anyone, once the finish deadline passed unsettled: end the room. The seller then claims the item back and " +
141
+ "every bidder reclaims its deposit.",
142
+ inputSchema: ROOM_SCHEMA,
143
+ run: async (ctx, args) => landed(await ctx.client.sales.expire(await withVault(ctx, args))),
144
+ },
145
+ ];
146
+ const BIDDER = [
147
+ {
148
+ name: "essey_sale_list",
149
+ kind: "read",
150
+ description: "Sale rooms on chain: id, coin, state, close time and bid count. Only open rooms unless all is true.",
151
+ inputSchema: objectSchema({ all: { type: "boolean", description: "every room, not only open ones" } }, []),
152
+ run: async (ctx, args) => {
153
+ const all = optBool(args, "all") ?? false;
154
+ const rows = (await ctx.client.sales.list()).filter((row) => all || row.state === 0);
155
+ return { ok: true, rooms: rows.map(summary) };
156
+ },
157
+ },
158
+ {
159
+ name: "essey_sale_view",
160
+ kind: "read",
161
+ description: "One sale room's public fields: coin, state, close time, finish deadline, bid count and max bids.",
162
+ inputSchema: ROOM_SCHEMA,
163
+ run: async (ctx, args) => {
164
+ const v = await ctx.client.sales.view(parseRoom(args));
165
+ return { ok: true, ...summary(v), finishByMs: v.finishByMs, maxBids: v.maxBids };
166
+ },
167
+ },
168
+ {
169
+ name: "essey_sale_bid",
170
+ kind: "call",
171
+ description: "Bidder: lock deposit from own notes of the room's coin behind a sealed bid of price. Only the seller opens " +
172
+ "it, after close. The bid record stays in a mode-600 file. Returns the digest and ticket.",
173
+ inputSchema: objectSchema({
174
+ room: ROOM,
175
+ price: { ...AMOUNT, description: "the sealed bid, in the room coin's smallest unit" },
176
+ deposit: {
177
+ ...AMOUNT,
178
+ description: "locked from own notes, at least price; the winner's change comes back",
179
+ },
180
+ }, ["room", "price", "deposit"]),
181
+ run: async (ctx, args) => {
182
+ const p = parseBid(args);
183
+ const { bid, ...r } = await ctx.client.sales.bid(p);
184
+ ctx.records.saveBid(p.room, bid);
185
+ return landed(r);
186
+ },
187
+ },
188
+ {
189
+ name: "essey_sale_reclaim",
190
+ kind: "call",
191
+ description: "Bidder, once the room settled or expired: a losing bid's deposit back to an own note, or with residual true " +
192
+ "the winner's change. Returns the value.",
193
+ inputSchema: objectSchema({
194
+ room: ROOM,
195
+ residual: { type: "boolean", description: "the winner's change instead of the deposit" },
196
+ }, ["room"]),
197
+ run: async (ctx, args) => {
198
+ const room = parseRoom(args);
199
+ const what = optBool(args, "residual") ? "residual" : "lock";
200
+ const r = await ctx.client.sales.reclaim({ room, bid: ctx.records.bid(room), what });
201
+ return { ...landed(r), value: r.value };
202
+ },
203
+ },
204
+ {
205
+ name: "essey_sale_claim",
206
+ kind: "call",
207
+ description: "Send the room's item to an address: as bidder when this server's bid won, or as seller after a cancel or " +
208
+ "expiry. to defaults to essey_agent_address.",
209
+ inputSchema: objectSchema({
210
+ room: ROOM,
211
+ as: { type: "string", enum: ["seller", "bidder"], description: "which record of this server claims" },
212
+ to: { type: "string", pattern: "^0x[0-9a-fA-F]{64}$", description: "recipient address" },
213
+ }, ["room", "as"]),
214
+ run: async (ctx, args) => {
215
+ const { room, as, to } = parseClaim(ctx, args);
216
+ const holder = as === "seller" ? { seller: ctx.records.sale(room).seller } : { bid: ctx.records.bid(room) };
217
+ const vault = await ctx.client.sales.vaultOf(room);
218
+ return { ...landed(await ctx.client.sales.claim({ vault, recipient: to, ...holder })), to };
219
+ },
220
+ },
221
+ ];
222
+ export const SALE_TOOLS = [...SELLER, ...BIDDER];
@@ -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;AAG5C,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,EAAgE,CAAC;AAUzF,+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":"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;AAK5C,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,EAQvB,CAAC;AAUF,+GAA+G;AAC/G,wBAAgB,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,GAAE,IAAI,EAAU,GAAG,OAAO,EAAE,CAmBvE"}
package/dist/tools.js CHANGED
@@ -2,6 +2,8 @@ import { COINS, v3 } from "@esseyonsui/sui-sdk-v3";
2
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";
3
3
  import { assertNoSecrets, failureOf, ToolRefusal } from "./failure.js";
4
4
  import { redact } from "./redact.js";
5
+ import { BADGE_TOOLS } from "./tools-badge.js";
6
+ import { SALE_TOOLS } from "./tools-sales.js";
5
7
  const UNITS = "whole-number string in the coin's smallest unit";
6
8
  const BIDDING = v3.LOAN_LIFECYCLE.indexOf("bidding");
7
9
  const obj = (properties = {}, required = []) => ({
@@ -368,7 +370,15 @@ const VIEWS = [
368
370
  },
369
371
  },
370
372
  ];
371
- export const TOOLS = [...CREDENTIAL, ...NOTES, ...BORROWER, ...LENDER, ...VIEWS];
373
+ export const TOOLS = [
374
+ ...CREDENTIAL,
375
+ ...NOTES,
376
+ ...BORROWER,
377
+ ...LENDER,
378
+ ...VIEWS,
379
+ ...SALE_TOOLS,
380
+ ...BADGE_TOOLS,
381
+ ];
372
382
  function assertKnownArgs(tool, args) {
373
383
  const schema = tool.inputSchema;
374
384
  if (schema.additionalProperties !== false)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esseyonsui/sui-mcp-v3",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "typecheck": "tsc --noEmit -p tsconfig.json"
30
30
  },
31
31
  "dependencies": {
32
- "@esseyonsui/sui-sdk-v3": "0.1.0",
32
+ "@esseyonsui/sui-sdk-v3": "0.1.2",
33
33
  "@mysten/seal": "1.5.1",
34
34
  "@mysten/sui": "2.37.0",
35
35
  "snarkjs": "0.7.6"