@esseyonsui/sui-mcp-v3 0.1.1 → 0.1.3
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 +42 -10
- package/dist/agent.d.ts +19 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +33 -0
- package/dist/args.d.ts +10 -1
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +9 -9
- package/dist/client.d.ts +10 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +33 -2
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/failure.d.ts +4 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +22 -2
- package/dist/fund.d.ts +21 -0
- package/dist/fund.d.ts.map +1 -0
- package/dist/fund.js +44 -0
- package/dist/io.d.ts +3 -1
- package/dist/io.d.ts.map +1 -1
- package/dist/io.js +22 -0
- package/dist/keys.d.ts +3 -2
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +17 -2
- package/dist/main.js +24 -8
- package/dist/records.d.ts +9 -2
- package/dist/records.d.ts.map +1 -1
- package/dist/records.js +29 -3
- package/dist/tools-badge.d.ts +5 -0
- package/dist/tools-badge.d.ts.map +1 -0
- package/dist/tools-badge.js +18 -0
- package/dist/tools-more.d.ts +3 -0
- package/dist/tools-more.d.ts.map +1 -0
- package/dist/tools-more.js +227 -0
- package/dist/tools-sales.d.ts +3 -0
- package/dist/tools-sales.d.ts.map +1 -0
- package/dist/tools-sales.js +222 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +14 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,9 +21,16 @@ 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
|
|
25
|
-
|
|
26
|
-
|
|
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 (or 64 hex digits, as 0.1.x wallets hold); the server loads
|
|
26
|
+
it at startup (`src/keys.ts`) and signs two kinds of transaction with it. Inside `essey_sale_open`, a transfer of
|
|
27
|
+
the item being sold from the agent address to the fresh sender the SDK derives from the note key, which then opens
|
|
28
|
+
the room while the relayer pays (`src/agent.ts`); no tool argument names the recipient. Inside
|
|
29
|
+
`essey_notes_deposit`, `0x2::coin::send_funds` of each deposit piece's value from the agent's own wallet to that
|
|
30
|
+
piece's fresh deposit sender (`src/fund.ts`), which reads the file again for each piece and returns a fixed error
|
|
31
|
+
with no key text when funding fails. The agent address pays the gas of both, so fund it with the coin and some SUI
|
|
32
|
+
before depositing. Every other loan, note and sale call goes through the SDK's relayer. No tool argument is a key,
|
|
33
|
+
a seed, or the invite. `ESSEY_INVITE`, when set, is the
|
|
27
34
|
invite gate for `essey_credential_obtain`. Results drop secret names (`borrowerSk`, `loanKey`, `salt`, and the same words inside a larger name), raw bytes,
|
|
28
35
|
`suiprivkey` text, bare 64-hex seeds, and the invite. An SDK failure returns its error code and a fixed hint,
|
|
29
36
|
not the SDK's message; a service refusal adds the service's own all-capitals code as `reason` (`RATE_LIMITED`,
|
|
@@ -34,15 +41,27 @@ not the SDK's message; a service refusal adds the service's own all-capitals cod
|
|
|
34
41
|
Credential: `essey_credential_obtain`, `essey_credential_status`, `essey_credential_renew`.
|
|
35
42
|
|
|
36
43
|
Notes: `essey_faucet`, `essey_notes_deposit`, `essey_notes_balance` (scan; balance and note count only),
|
|
37
|
-
`essey_notes_withdraw`, `essey_notes_receive_address`, `essey_notes_transfer
|
|
38
|
-
|
|
44
|
+
`essey_notes_withdraw`, `essey_notes_receive_address`, `essey_notes_transfer`, `essey_notes_exit` (every note
|
|
45
|
+
of a coin, at most two, less fees), `essey_notes_recover` (retries a deposit that stopped before it landed).
|
|
46
|
+
`essey_notes_deposit` is paid from the agent wallet (see Keys).
|
|
39
47
|
|
|
40
48
|
Borrower: `essey_loan_open` (collateral coin and amount, loan coin, principal, max rate, term, offer window),
|
|
41
49
|
`essey_loan_settle`, `essey_loan_repay`, `essey_loan_release`, `essey_loan_cancel`, `essey_loan_reclaim_coll`,
|
|
42
|
-
`essey_loan_heartbeat`, `essey_loan_topup`, `essey_loan_collect_surplus
|
|
50
|
+
`essey_loan_heartbeat`, `essey_loan_topup`, `essey_loan_collect_surplus`, `essey_loan_slash` (an offer whose
|
|
51
|
+
sealed copy does not open its commit), `essey_loan_liquidate` and `essey_loan_seize_default` (from this server's
|
|
52
|
+
own terms).
|
|
53
|
+
|
|
54
|
+
Refinance: the borrower calls `essey_loan_refi_open` (new principal, max rate, term, offer window); lenders use
|
|
55
|
+
`essey_loan_request` and `essey_loan_offer`; after the window the borrower calls `essey_loan_refi_settle`, or
|
|
56
|
+
`essey_loan_refi_cancel` to keep the current terms. The old lender takes its payoff with `essey_loan_collect`.
|
|
43
57
|
|
|
44
58
|
Lender: `essey_loan_list`, `essey_loan_request`, `essey_loan_offer` (loan id, rate), `essey_loan_collect`,
|
|
45
|
-
`essey_loan_reclaim`, `essey_loan_collect_seized
|
|
59
|
+
`essey_loan_reclaim`, `essey_loan_collect_seized`, `essey_loan_fault_liquidate` (a loan a keeper marked FAULT).
|
|
60
|
+
|
|
61
|
+
Keeper (a credential from `essey_credential_obtain` with role `keeper`): `essey_keeper_judge` (liquidate, fault
|
|
62
|
+
or skip, sending nothing), `essey_keeper_liquidate`, `essey_keeper_fault`, `essey_keeper_mint_badge`,
|
|
63
|
+
`essey_keeper_badge`. The judge, liquidate and fault tools take `via: "badge"` to use the minted badge instead
|
|
64
|
+
of the keeper pass.
|
|
46
65
|
|
|
47
66
|
Each loan tool calls the SDK's own planner, so the server builds every proof with the circuits `/v3/config`
|
|
48
67
|
pins, reads the chain over Sui GraphQL and seals with the deployment's Seal set (`src/io.ts`). What a later step
|
|
@@ -50,11 +69,24 @@ needs and no chain read gives back (the borrower's terms, key and locked amount;
|
|
|
50
69
|
written to `loan-<id>.json` and `offer-<id>.json`, mode 600, in the state file's directory, the same files
|
|
51
70
|
`scripts/v3/live/run.mts` writes. No tool returns them. Give each server its own state directory.
|
|
52
71
|
|
|
72
|
+
Seller: `essey_agent_address` (the address to send the item and testnet SUI to), `essey_sale_open` (item id and
|
|
73
|
+
struct tag, coin, sealed min and max price, bid window, finish window, max bids), `essey_sale_finish`,
|
|
74
|
+
`essey_sale_slash` (a bid `essey_sale_finish` names as not opening), `essey_sale_cancel` (before any bid),
|
|
75
|
+
`essey_sale_expire` (anyone, after the finish window).
|
|
76
|
+
|
|
77
|
+
Bidder: `essey_sale_list`, `essey_sale_view`, `essey_sale_bid` (room, sealed price, deposit),
|
|
78
|
+
`essey_sale_reclaim` (the deposit, or with `residual` the winner's change), `essey_sale_claim` (as `bidder` when
|
|
79
|
+
the bid won, or as `seller` after a cancel or expiry; `to` defaults to the agent address).
|
|
80
|
+
|
|
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
|
|
84
|
+
`0x48db0307be9b6aadbf9f29c28561e1b450348ab2786ea4853a8d7249c22979a1::demo::Badge`, which anyone can mint with
|
|
85
|
+
its public `demo::mint` and transfer to the agent address.
|
|
86
|
+
|
|
53
87
|
`essey_loan_status` reads one loan's public fields from chain. `essey_loan_view` runs the SDK's `localHealth`
|
|
54
88
|
and `covered` on the public fields in its arguments and reads nothing.
|
|
55
89
|
|
|
56
|
-
There is no refinance tool.
|
|
57
|
-
|
|
58
90
|
Amounts are whole-number strings in the coin's smallest unit.
|
|
59
91
|
|
|
60
92
|
## Configuration
|
|
@@ -65,7 +97,7 @@ Amounts are whole-number strings in the coin's smallest unit.
|
|
|
65
97
|
| `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
98
|
| `ESSEY_STATE_FILE` | mode-600 state path the SDK keeps the credential in (required) |
|
|
67
99
|
| `ESSEY_NOTE_KEY_FILE` | mode-600 note seed (required) |
|
|
68
|
-
| `ESSEY_AGENT_KEY_FILE` | mode-600 agent key file (required;
|
|
100
|
+
| `ESSEY_AGENT_KEY_FILE` | mode-600 agent key file (required; signs only the sale item hand-over and deposit funding, see Keys) |
|
|
69
101
|
| `ESSEY_INVITE` | optional invite token, 1..256 characters without whitespace |
|
|
70
102
|
| `ESSEY_RELAYER` | `clear` (default) or `onion` |
|
|
71
103
|
| `ESSEY_GRAPHQL` | Sui GraphQL URL, `https` or `http` on localhost (default `https://graphql.testnet.sui.io/graphql`) |
|
package/dist/agent.d.ts
ADDED
|
@@ -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;
|
package/dist/args.d.ts.map
CHANGED
|
@@ -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,
|
|
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,U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AG,GAAG,MAAM,CAK/C;AAED,eAAO,MAAM,WAAW,YAWvB,CAAC;AAEF,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,UAAU,CAa/C;AAED,eAAO,MAAM,YAAY,YAGvB,CAAC;AAEH,wBAAgB,cAAc,CAAC,IAAI,EAAE,GAAG,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAE3E;AAED,eAAO,MAAM,gBAAgB,YAM5B,CAAC;AAEF,wBAAgB,cAAc,CAAC,IAAI,EAAE,GAAG,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAGtE;AAED,eAAO,MAAM,YAAY,YAOxB,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,EAAE,GAAG,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
|
@@ -11,13 +11,13 @@ const U64S = {
|
|
|
11
11
|
pattern: "^(0|[1-9][0-9]*)$",
|
|
12
12
|
description: "canonical decimal u64",
|
|
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
|
@@ -11,15 +11,22 @@ export type OpenParams = Extract<Parameters<Loans["open"]>[0], {
|
|
|
11
11
|
*/
|
|
12
12
|
export type DemoClient = {
|
|
13
13
|
credential: Essey["credential"];
|
|
14
|
-
notes: Pick<Essey["notes"], "faucet" | "deposit" | "scan" | "withdraw" | "transfer" | "receiveAddress">;
|
|
15
|
-
loans: Pick<Loans, "request" | "lend" | "accept" | "payBack" | "release" | "collect" | "cancelOwn" | "reclaimCollateral" | "reclaimOffer" | "collectSeized" | "collectSurplus" | "heartbeat" | "topup" | "list" | "view"> & {
|
|
14
|
+
notes: Pick<Essey["notes"], "faucet" | "deposit" | "scan" | "withdraw" | "transfer" | "receiveAddress" | "exit" | "recoverStranded">;
|
|
15
|
+
loans: Pick<Loans, "request" | "lend" | "accept" | "payBack" | "release" | "collect" | "cancelOwn" | "reclaimCollateral" | "reclaimOffer" | "collectSeized" | "collectSurplus" | "heartbeat" | "topup" | "list" | "view" | "openRefi" | "settleRefi" | "cancelRefi" | "slash" | "fault" | "liquidate" | "seizeDefault" | "faultLiquidate" | "keeperLiquidate"> & {
|
|
16
16
|
open(p: OpenParams): Promise<{
|
|
17
17
|
id: string;
|
|
18
18
|
} & Landed>;
|
|
19
19
|
health(loan: PublicLoan): Promise<LoanStatus>;
|
|
20
20
|
};
|
|
21
|
+
sales: Essey["sales"] & SaleChain;
|
|
22
|
+
keeper: Pick<Essey["keeper"], "mintBadge" | "badge" | "judge">;
|
|
21
23
|
};
|
|
22
|
-
|
|
24
|
+
/** The agent key's public address and the vault lookup; the key itself stays in `agent.ts`. */
|
|
25
|
+
export type SaleChain = {
|
|
26
|
+
agentAddress: string;
|
|
27
|
+
vaultOf(room: string): Promise<string>;
|
|
28
|
+
};
|
|
29
|
+
export declare function clientOf(essey: Essey, chain: SaleChain, health?: DemoClient["loans"]["health"]): DemoClient;
|
|
23
30
|
/** The invite stays in the server process. Tool arguments cannot replace it or read it back. */
|
|
24
31
|
export declare function withInvite(client: DemoClient, invite: string | null): DemoClient;
|
|
25
32
|
export {};
|
package/dist/client.d.ts.map
CHANGED
|
@@ -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,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAChC,KAAK,EAAE,IAAI,
|
|
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,C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,OAAO,CAAC,CAAC;CAChE,CAAC;AAEF,+FAA+F;AAC/F,MAAM,MAAM,SAAS,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AASzF,wBAAgB,QAAQ,CACtB,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,SAAS,EAChB,MAAM,GAAE,UAAU,CAAC,OAAO,CAAC,CAAC,QAAQ,CAA6C,GAChF,UAAU,CA+DZ;AAED,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,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 { keeper, loans, notes, sales } = essey;
|
|
11
11
|
return {
|
|
12
12
|
credential: essey.credential,
|
|
13
13
|
notes: {
|
|
@@ -17,6 +17,8 @@ export function clientOf(essey, health = (loan) => Promise.resolve(statusOf(loan
|
|
|
17
17
|
withdraw: (coin, amount, to) => notes.withdraw(coin, amount, to),
|
|
18
18
|
transfer: (coin, amount, to) => notes.transfer(coin, amount, to),
|
|
19
19
|
receiveAddress: () => notes.receiveAddress(),
|
|
20
|
+
exit: (coin, to) => notes.exit(coin, to),
|
|
21
|
+
recoverStranded: () => notes.recoverStranded(),
|
|
20
22
|
},
|
|
21
23
|
loans: {
|
|
22
24
|
open: (p) => openPlanned(essey, p),
|
|
@@ -35,8 +37,37 @@ export function clientOf(essey, health = (loan) => Promise.resolve(statusOf(loan
|
|
|
35
37
|
topup: (p) => loans.topup(p),
|
|
36
38
|
list: () => loans.list(),
|
|
37
39
|
view: (id) => loans.view(id),
|
|
40
|
+
openRefi: (p) => loans.openRefi(p),
|
|
41
|
+
settleRefi: (p) => loans.settleRefi(p),
|
|
42
|
+
cancelRefi: (id) => loans.cancelRefi(id),
|
|
43
|
+
slash: (p) => loans.slash(p),
|
|
44
|
+
fault: (p) => loans.fault(p),
|
|
45
|
+
liquidate: (p) => loans.liquidate(p),
|
|
46
|
+
seizeDefault: (p) => loans.seizeDefault(p),
|
|
47
|
+
faultLiquidate: (p) => loans.faultLiquidate(p),
|
|
48
|
+
keeperLiquidate: (p) => loans.keeperLiquidate(p),
|
|
38
49
|
health,
|
|
39
50
|
},
|
|
51
|
+
sales: {
|
|
52
|
+
open: (p) => sales.open(p),
|
|
53
|
+
list: () => sales.list(),
|
|
54
|
+
view: (id) => sales.view(id),
|
|
55
|
+
bid: (p) => sales.bid(p),
|
|
56
|
+
finish: (p) => sales.finish(p),
|
|
57
|
+
slash: (p) => sales.slash(p),
|
|
58
|
+
expire: (p) => sales.expire(p),
|
|
59
|
+
reclaim: (p) => sales.reclaim(p),
|
|
60
|
+
claim: (p) => sales.claim(p),
|
|
61
|
+
cancel: (p) => sales.cancel(p),
|
|
62
|
+
badgeGrant: (to) => sales.badgeGrant(to),
|
|
63
|
+
agentAddress: chain.agentAddress,
|
|
64
|
+
vaultOf: (room) => chain.vaultOf(room),
|
|
65
|
+
},
|
|
66
|
+
keeper: {
|
|
67
|
+
mintBadge: () => keeper.mintBadge(),
|
|
68
|
+
badge: () => keeper.badge(),
|
|
69
|
+
judge: (p) => keeper.judge(p),
|
|
70
|
+
},
|
|
40
71
|
};
|
|
41
72
|
}
|
|
42
73
|
/** 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.
|
|
17
|
+
/** Mode-600 agent key file. Signs the sale item hand-over (`agent.ts`) and a deposit's funding transfer (`fund.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;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,SAAS,CAAC;IACnB,4EAA4E;IAC5E,MAAM,EAAE;QAAE,IAAI,EAAE,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,iHAAiH;IACjH,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,wGAAwG;IACxG,WAAW,EAAE,MAAM,CAAC;IACpB,+
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,SAAS,CAAC;IACnB,4EAA4E;IAC5E,MAAM,EAAE;QAAE,IAAI,EAAE,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,iHAAiH;IACjH,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,wGAAwG;IACxG,WAAW,EAAE,MAAM,CAAC;IACpB,+IAA+I;IAC/I,YAAY,EAAE,MAAM,CAAC;IACrB,2GAA2G;IAC3G,MAAM,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
package/dist/failure.d.ts.map
CHANGED
|
@@ -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;
|
|
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, ...(
|
|
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/fund.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
2
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
3
|
+
import type { CoinKey, EsseyIo } from "@esseyonsui/sui-sdk-v3";
|
|
4
|
+
/** Fixed text: whatever the signing or the chain threw is dropped, so no failure can carry the key file. */
|
|
5
|
+
export declare const FUND_FAILED = "the agent wallet did not fund the deposit";
|
|
6
|
+
/** Executes the signed transaction and resolves once it is final. Tests replace it. */
|
|
7
|
+
export type Send = (tx: Transaction, signer: Ed25519Keypair) => Promise<void>;
|
|
8
|
+
export declare function chainSend(url: string): Send;
|
|
9
|
+
/**
|
|
10
|
+
* The only transaction the agent key signs: `0x2::coin::send_funds` of one deposit piece to its fresh sender, as
|
|
11
|
+
* `scripts/v3/live/io.ts` depositFunder does from the sui CLI payer. The key is read for each piece and not kept.
|
|
12
|
+
*/
|
|
13
|
+
export declare function agentFunder(keyFile: string, coinType: (coin: CoinKey) => string | undefined, send: Send): NonNullable<EsseyIo["fundDeposit"]>;
|
|
14
|
+
export declare function agentDepositIo(raw: unknown, keyFile: string, url: string, send?: Send): {
|
|
15
|
+
fundDeposit: (p: {
|
|
16
|
+
coin: CoinKey;
|
|
17
|
+
value: bigint;
|
|
18
|
+
sender: string;
|
|
19
|
+
}) => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=fund.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fund.d.ts","sourceRoot":"","sources":["../src/fund.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAmB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAExE,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAI/D,4GAA4G;AAC5G,eAAO,MAAM,WAAW,8CAA8C,CAAC;AAEvE,uFAAuF;AACvF,MAAM,MAAM,IAAI,GAAG,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE9E,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAO3C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,EAC/C,IAAI,EAAE,IAAI,GACT,WAAW,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAmBrC;AAID,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,IAAqB;;;;;;EAGrG"}
|
package/dist/fund.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SuiGraphQLClient } from "@mysten/sui/graphql";
|
|
2
|
+
import { coinWithBalance, Transaction } from "@mysten/sui/transactions";
|
|
3
|
+
import { loadAgentKey } from "./keys.js";
|
|
4
|
+
/** Fixed text: whatever the signing or the chain threw is dropped, so no failure can carry the key file. */
|
|
5
|
+
export const FUND_FAILED = "the agent wallet did not fund the deposit";
|
|
6
|
+
export function chainSend(url) {
|
|
7
|
+
const client = new SuiGraphQLClient({ url, network: "testnet" });
|
|
8
|
+
return async (transaction, signer) => {
|
|
9
|
+
const r = await client.signAndExecuteTransaction({ transaction, signer });
|
|
10
|
+
if (r.$kind !== "Transaction")
|
|
11
|
+
throw new Error("failed");
|
|
12
|
+
await client.waitForTransaction({ result: r });
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The only transaction the agent key signs: `0x2::coin::send_funds` of one deposit piece to its fresh sender, as
|
|
17
|
+
* `scripts/v3/live/io.ts` depositFunder does from the sui CLI payer. The key is read for each piece and not kept.
|
|
18
|
+
*/
|
|
19
|
+
export function agentFunder(keyFile, coinType, send) {
|
|
20
|
+
return async ({ coin, value, sender }) => {
|
|
21
|
+
try {
|
|
22
|
+
const type = coinType(coin);
|
|
23
|
+
if (!type)
|
|
24
|
+
throw new Error("coin");
|
|
25
|
+
const signer = loadAgentKey(keyFile);
|
|
26
|
+
const tx = new Transaction();
|
|
27
|
+
tx.setSender(signer.toSuiAddress());
|
|
28
|
+
const funds = tx.add(coinWithBalance({ type, balance: value }));
|
|
29
|
+
tx.moveCall({
|
|
30
|
+
target: "0x2::coin::send_funds",
|
|
31
|
+
typeArguments: [type],
|
|
32
|
+
arguments: [funds, tx.pure.address(sender)],
|
|
33
|
+
});
|
|
34
|
+
await send(tx, signer);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
throw new Error(FUND_FAILED);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function agentDepositIo(raw, keyFile, url, send = chainSend(url)) {
|
|
42
|
+
const coins = raw.coins ?? {};
|
|
43
|
+
return { fundDeposit: agentFunder(keyFile, (coin) => coins[coin]?.type, send) };
|
|
44
|
+
}
|
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: "
|
|
57
|
+
readonly mode: "default" | "fault" | "liquidate";
|
|
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;
|
|
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,CAA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ACH,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
|
-
|
|
2
|
-
|
|
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.
|
package/dist/keys.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"
|
|
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
|
|
23
|
-
export function
|
|
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.
|