@escro/mcp 0.1.5 → 0.1.6
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/dist/env.cjs +2 -1
- package/dist/env.cjs.map +1 -1
- package/dist/index.cjs +304 -15
- package/dist/index.cjs.map +1 -1
- package/dist/server.cjs +304 -15
- package/dist/server.cjs.map +1 -1
- package/dist/tools.cjs +24 -3
- package/dist/tools.cjs.map +1 -1
- package/package.json +3 -3
- package/types/server.d.ts +1 -1
- package/types/tools.d.ts +6 -1
package/dist/server.cjs
CHANGED
|
@@ -5804,6 +5804,20 @@ var EscroConfirmError = class extends EscroError {
|
|
|
5804
5804
|
this.name = "EscroConfirmError";
|
|
5805
5805
|
}
|
|
5806
5806
|
};
|
|
5807
|
+
var ClaimBindingError = class extends EscroError {
|
|
5808
|
+
constructor(refusal2, options) {
|
|
5809
|
+
super(refusal2.message, "CLAIM_BINDING_REFUSED", void 0, options);
|
|
5810
|
+
__publicField(this, "address");
|
|
5811
|
+
__publicField(this, "claimSignature");
|
|
5812
|
+
__publicField(this, "field");
|
|
5813
|
+
__publicField(this, "retryable");
|
|
5814
|
+
this.name = "ClaimBindingError";
|
|
5815
|
+
this.address = refusal2.address;
|
|
5816
|
+
this.claimSignature = refusal2.claimSignature;
|
|
5817
|
+
this.field = refusal2.field;
|
|
5818
|
+
this.retryable = refusal2.retryable;
|
|
5819
|
+
}
|
|
5820
|
+
};
|
|
5807
5821
|
var UnauthorizedError = class extends EscroError {
|
|
5808
5822
|
constructor(message = "Unauthorized") {
|
|
5809
5823
|
super(message, "UNAUTHORIZED");
|
|
@@ -7397,6 +7411,205 @@ async function readOpenEscrowAccount(rpc, address, cluster) {
|
|
|
7397
7411
|
}
|
|
7398
7412
|
return ownedAccount(at, account.owner, account.data, programId);
|
|
7399
7413
|
}
|
|
7414
|
+
var CLAIM_CHECK_ATTEMPTS = 5;
|
|
7415
|
+
var CLAIM_CHECK_INTERVAL_MS = 500;
|
|
7416
|
+
var U64_MAX = 2n ** 64n - 1n;
|
|
7417
|
+
var IPFS_PREFIX = "ipfs://";
|
|
7418
|
+
var withoutIpfs = (hash) => hash.startsWith(IPFS_PREFIX) ? hash.slice(IPFS_PREFIX.length) : hash;
|
|
7419
|
+
var invalidTerms = (message) => new EscroError(message, "VALIDATION_ERROR");
|
|
7420
|
+
function claimTermsOf(accepted) {
|
|
7421
|
+
if (!isCanonicalPubkey(accepted.buyer)) {
|
|
7422
|
+
throw invalidTerms("accepted.buyer is not a base58 public key");
|
|
7423
|
+
}
|
|
7424
|
+
const raw = accepted.amountUsdc;
|
|
7425
|
+
if (typeof raw === "string" && !/^[0-9]+$/.test(raw)) {
|
|
7426
|
+
throw invalidTerms("accepted.amountUsdc is not a decimal string of micro-USDC digits");
|
|
7427
|
+
}
|
|
7428
|
+
const amount = BigInt(raw);
|
|
7429
|
+
if (amount < 0n || amount > U64_MAX) {
|
|
7430
|
+
throw invalidTerms("accepted.amountUsdc is outside the u64 range");
|
|
7431
|
+
}
|
|
7432
|
+
const window = typeof accepted.deadline === "number" ? { min: accepted.deadline, max: accepted.deadline } : accepted.deadline;
|
|
7433
|
+
if (!Number.isSafeInteger(window.min) || !Number.isSafeInteger(window.max)) {
|
|
7434
|
+
throw invalidTerms("accepted.deadline is not whole Unix seconds");
|
|
7435
|
+
}
|
|
7436
|
+
if (window.min > window.max) {
|
|
7437
|
+
throw invalidTerms("accepted.deadline's window has min greater than max");
|
|
7438
|
+
}
|
|
7439
|
+
return {
|
|
7440
|
+
buyer: accepted.buyer,
|
|
7441
|
+
amount,
|
|
7442
|
+
specHash: withoutIpfs(accepted.specHash),
|
|
7443
|
+
min: window.min,
|
|
7444
|
+
max: window.max
|
|
7445
|
+
};
|
|
7446
|
+
}
|
|
7447
|
+
function shown(value) {
|
|
7448
|
+
if (value === null || value === void 0) return "none";
|
|
7449
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
7450
|
+
if (typeof value === "number" || typeof value === "bigint") return String(value);
|
|
7451
|
+
return typeof value;
|
|
7452
|
+
}
|
|
7453
|
+
function firstMismatch(record, tail, terms, worker, stage) {
|
|
7454
|
+
const state = stage === "before" ? "Funded" : "InProgress";
|
|
7455
|
+
const expectations = {
|
|
7456
|
+
buyer: { holds: (found) => found === terms.buyer, expected: terms.buyer },
|
|
7457
|
+
assigned_worker: {
|
|
7458
|
+
holds: (found) => found === worker || stage === "before" && found === null,
|
|
7459
|
+
expected: stage === "before" ? `${worker} or none` : worker
|
|
7460
|
+
},
|
|
7461
|
+
amount_usdc: { holds: (found) => found === terms.amount, expected: terms.amount.toString() },
|
|
7462
|
+
deadline: {
|
|
7463
|
+
holds: (found) => typeof found === "number" && found >= terms.min && found <= terms.max,
|
|
7464
|
+
expected: terms.min === terms.max ? String(terms.min) : `from ${String(terms.min)} to ${String(terms.max)}`
|
|
7465
|
+
},
|
|
7466
|
+
spec_hash: {
|
|
7467
|
+
holds: (found) => typeof found === "string" && withoutIpfs(found) === terms.specHash,
|
|
7468
|
+
expected: JSON.stringify(terms.specHash)
|
|
7469
|
+
},
|
|
7470
|
+
state: { holds: (found) => found === state, expected: state },
|
|
7471
|
+
marketplace_id: { holds: (found) => found === null, expected: "none" },
|
|
7472
|
+
referrer_wallet: { holds: (found) => found === null, expected: "none" },
|
|
7473
|
+
referrer_bps: { holds: (found) => found === 0, expected: "0" }
|
|
7474
|
+
};
|
|
7475
|
+
for (const { name } of ESCROW_ACCOUNT_V1_FIELDS) {
|
|
7476
|
+
const expectation = expectations[name];
|
|
7477
|
+
const found = record[name];
|
|
7478
|
+
if (expectation === void 0 || expectation.holds(found)) continue;
|
|
7479
|
+
return {
|
|
7480
|
+
field: name,
|
|
7481
|
+
expected: expectation.expected,
|
|
7482
|
+
found: shown(found),
|
|
7483
|
+
indeterminate: stage === "after" && name === "state" && found === "Funded"
|
|
7484
|
+
};
|
|
7485
|
+
}
|
|
7486
|
+
const term = tail.names.find((name) => name !== "marketplace_id");
|
|
7487
|
+
if (term === void 0) return void 0;
|
|
7488
|
+
return {
|
|
7489
|
+
field: term,
|
|
7490
|
+
expected: "the default job's",
|
|
7491
|
+
found: shown(tail.values.get(camelCase(term))),
|
|
7492
|
+
indeterminate: false
|
|
7493
|
+
};
|
|
7494
|
+
}
|
|
7495
|
+
function refusal(address, claimSignature, mismatch, reads, cause) {
|
|
7496
|
+
const claim = claimSignature === void 0 ? "" : ` (claim ${claimSignature})`;
|
|
7497
|
+
const detail = `${mismatch.field} expected ${mismatch.expected}, found ${mismatch.found}`;
|
|
7498
|
+
const message = mismatch.indeterminate ? `The escrow at ${address}${claim} could not be checked in ${String(reads)} reads (${detail}): check it again before any work` : `The escrow at ${address}${claim} is not the escrow accepted (${detail}): start no work on it`;
|
|
7499
|
+
return new ClaimBindingError(
|
|
7500
|
+
{
|
|
7501
|
+
address,
|
|
7502
|
+
claimSignature,
|
|
7503
|
+
field: mismatch.field,
|
|
7504
|
+
retryable: mismatch.indeterminate,
|
|
7505
|
+
message
|
|
7506
|
+
},
|
|
7507
|
+
cause === void 0 ? void 0 : { cause }
|
|
7508
|
+
);
|
|
7509
|
+
}
|
|
7510
|
+
async function readClaimed(rpc, address, programId, worker, terms) {
|
|
7511
|
+
const unreadable2 = (expected, found, indeterminate) => ({
|
|
7512
|
+
field: "account",
|
|
7513
|
+
expected,
|
|
7514
|
+
found,
|
|
7515
|
+
indeterminate
|
|
7516
|
+
});
|
|
7517
|
+
let info;
|
|
7518
|
+
try {
|
|
7519
|
+
info = await rpc.getAccountInfo(address, { commitment: "confirmed" });
|
|
7520
|
+
} catch (cause) {
|
|
7521
|
+
return { mismatch: unreadable2("a readable account", "the read failed", true), cause };
|
|
7522
|
+
}
|
|
7523
|
+
if (info === null || info.owner.equals(import_web38.SystemProgram.programId) && info.data.length === 0) {
|
|
7524
|
+
return { mismatch: unreadable2("an open escrow account", "no account", true) };
|
|
7525
|
+
}
|
|
7526
|
+
if (!info.owner.equals(programId)) {
|
|
7527
|
+
return {
|
|
7528
|
+
mismatch: unreadable2(
|
|
7529
|
+
`an account of the program ${programId.toBase58()}`,
|
|
7530
|
+
`an account owned by ${info.owner.toBase58()}`,
|
|
7531
|
+
false
|
|
7532
|
+
)
|
|
7533
|
+
};
|
|
7534
|
+
}
|
|
7535
|
+
let account;
|
|
7536
|
+
let record;
|
|
7537
|
+
try {
|
|
7538
|
+
account = decodeEscrowAccount(info.data, { v1ReviewWindowSeconds: ONCHAIN_TIMEOUT_SECONDS });
|
|
7539
|
+
record = recordOf(account);
|
|
7540
|
+
} catch (err) {
|
|
7541
|
+
if (err instanceof EscrowAccountDecodeError || err instanceof AccountProblem) {
|
|
7542
|
+
return {
|
|
7543
|
+
mismatch: unreadable2(
|
|
7544
|
+
"a current EscrowAccount",
|
|
7545
|
+
`bytes that do not decode (${err.reason})`,
|
|
7546
|
+
false
|
|
7547
|
+
)
|
|
7548
|
+
};
|
|
7549
|
+
}
|
|
7550
|
+
throw err;
|
|
7551
|
+
}
|
|
7552
|
+
const mismatch = firstMismatch(
|
|
7553
|
+
record,
|
|
7554
|
+
{ names: nonDefaultJobTerms(account), values: new Map(Object.entries(account.terms)) },
|
|
7555
|
+
terms,
|
|
7556
|
+
worker,
|
|
7557
|
+
"after"
|
|
7558
|
+
);
|
|
7559
|
+
return mismatch === void 0 ? { record } : { mismatch };
|
|
7560
|
+
}
|
|
7561
|
+
function claimKey(value, what) {
|
|
7562
|
+
if (!isCanonicalPubkey(value)) throw invalidTerms(`The ${what} is not a base58 public key`);
|
|
7563
|
+
return new import_web38.PublicKey(value);
|
|
7564
|
+
}
|
|
7565
|
+
async function verifyClaimedEscrow(rpc, params) {
|
|
7566
|
+
const terms = claimTermsOf(params.accepted);
|
|
7567
|
+
const address = claimKey(params.address, "address");
|
|
7568
|
+
claimKey(params.worker, "worker");
|
|
7569
|
+
const intervalMs = params.intervalMs ?? CLAIM_CHECK_INTERVAL_MS;
|
|
7570
|
+
if (!Number.isSafeInteger(intervalMs) || intervalMs < 0) {
|
|
7571
|
+
throw invalidTerms("intervalMs must be a non-negative integer of milliseconds");
|
|
7572
|
+
}
|
|
7573
|
+
const programId = clusterProgramId(params.cluster);
|
|
7574
|
+
for (let reads = 1; ; reads += 1) {
|
|
7575
|
+
const outcome = await readClaimed(rpc, address, programId, params.worker, terms);
|
|
7576
|
+
if ("record" in outcome) return outcome.record;
|
|
7577
|
+
const { mismatch } = outcome;
|
|
7578
|
+
if (!mismatch.indeterminate || reads >= CLAIM_CHECK_ATTEMPTS) {
|
|
7579
|
+
throw refusal(params.address, params.claimSignature, mismatch, reads, outcome.cause);
|
|
7580
|
+
}
|
|
7581
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
7582
|
+
}
|
|
7583
|
+
}
|
|
7584
|
+
function assertAcceptedTerms(accepted) {
|
|
7585
|
+
claimTermsOf(accepted);
|
|
7586
|
+
}
|
|
7587
|
+
function assertClaimable(address, record, worker, accepted) {
|
|
7588
|
+
const mismatch = firstMismatch(
|
|
7589
|
+
record,
|
|
7590
|
+
{ names: [], values: /* @__PURE__ */ new Map() },
|
|
7591
|
+
claimTermsOf(accepted),
|
|
7592
|
+
worker,
|
|
7593
|
+
"before"
|
|
7594
|
+
);
|
|
7595
|
+
if (mismatch === void 0) return;
|
|
7596
|
+
const detail = `${mismatch.field} expected ${mismatch.expected}, found ${mismatch.found}`;
|
|
7597
|
+
throw new ClaimBindingError({
|
|
7598
|
+
address,
|
|
7599
|
+
claimSignature: void 0,
|
|
7600
|
+
field: mismatch.field,
|
|
7601
|
+
retryable: false,
|
|
7602
|
+
message: `The escrow at ${address} is not the escrow accepted (${detail}): nothing was claimed`
|
|
7603
|
+
});
|
|
7604
|
+
}
|
|
7605
|
+
function acceptedTermsOf(record) {
|
|
7606
|
+
return {
|
|
7607
|
+
buyer: stringOf(record, "buyer"),
|
|
7608
|
+
amountUsdc: bigintOf(record, "amount_usdc"),
|
|
7609
|
+
specHash: stringOf(record, "spec_hash"),
|
|
7610
|
+
deadline: numberOf(record, "deadline")
|
|
7611
|
+
};
|
|
7612
|
+
}
|
|
7400
7613
|
function readAccount(address, owner, data, programId, cluster) {
|
|
7401
7614
|
const at = address.toBase58();
|
|
7402
7615
|
const decoded2 = ownedAccount(at, owner, data, programId);
|
|
@@ -10841,25 +11054,70 @@ var Escro = class {
|
|
|
10841
11054
|
* account decodes as {@link decodeEscrowAccount} reads it (version 1, or version 2 on the
|
|
10842
11055
|
* default job's terms).
|
|
10843
11056
|
* Signs and submits the `claim_task` on-chain tx, then confirms it with the API.
|
|
10844
|
-
*
|
|
11057
|
+
*
|
|
11058
|
+
* From 0.5.4 the claim binds the escrow the worker read. A buyer can cancel a Funded escrow and
|
|
11059
|
+
* create another at the same address before the claim lands, and the claim then lands on the new
|
|
11060
|
+
* one. With `options.accepted` (the terms the caller priced: a listing row's `maker`, `amount`,
|
|
11061
|
+
* `taskSpecHash` and `deadline`) the pre-claim read must be Funded, assigned to this wallet or to
|
|
11062
|
+
* none, and hold those terms, or a `ClaimBindingError` is thrown before anything is
|
|
11063
|
+
* requested or sent. Once the claim confirms, {@link verifyClaimedEscrow} reads the account again
|
|
11064
|
+
* with the claim's signature, against `accepted` or, absent, against the pre-claim read; the API
|
|
11065
|
+
* is asked to record the claim only after it passes. A definitive refusal (`retryable: false`)
|
|
11066
|
+
* leaves this wallet holding an IN_PROGRESS escrow it must not work. Without `accepted` a swap made
|
|
11067
|
+
* before the pre-claim read (a listing that lags the chain) passes: pass `accepted` to close it.
|
|
11068
|
+
*
|
|
11069
|
+
* Run `verifyClaimedEscrow` with the claim's signature yourself, before any work, after a claim
|
|
11070
|
+
* with `{ wait: false }` (which returns once the claim is sent and checks nothing; with `accepted`
|
|
11071
|
+
* it is refused, `VALIDATION_ERROR`, before any request), after a caught send error that carries
|
|
11072
|
+
* `signature` (the claim may have landed), and after a `retryable` refusal. See
|
|
11073
|
+
* {@link SendOptions.wait}.
|
|
10845
11074
|
*
|
|
10846
11075
|
* @throws From 0.5.3, {@link ChainReadError} before any API request:
|
|
10847
11076
|
* `CHAIN_ESCROW_NOT_FOUND` with no open account at `address`, `CHAIN_ACCOUNT_INVALID` for another
|
|
10848
11077
|
* owner's account or one the decode refuses (reason `version` names a version-2 escrow's terms
|
|
10849
11078
|
* other than the default job's), `CHAIN_RPC_FAILED` when the read fails. Before 0.5.3 a missing
|
|
10850
|
-
* escrow is an {@link EscrowNotFoundError} from the API.
|
|
11079
|
+
* escrow is an {@link EscrowNotFoundError} from the API. From 0.5.4, `ClaimBindingError`
|
|
11080
|
+
* before the claim (with `accepted`) or after it lands, and {@link EscroConfirmError} only after
|
|
11081
|
+
* the post-claim check passed.
|
|
10851
11082
|
* @returns Solana transaction signature.
|
|
10852
11083
|
*/
|
|
10853
11084
|
async claimTask(address, options) {
|
|
10854
11085
|
assertPublicKey("address", address);
|
|
10855
|
-
|
|
11086
|
+
const wait = options?.wait ?? true;
|
|
11087
|
+
const accepted = options?.accepted;
|
|
11088
|
+
if (accepted !== void 0) {
|
|
11089
|
+
if (!wait) {
|
|
11090
|
+
throw new EscroError(
|
|
11091
|
+
"accepted is checked after the claim confirms, which a claim with { wait: false } does not wait for: claim with { wait: false } and no accepted, then run verifyClaimedEscrow with the claim's signature before any work",
|
|
11092
|
+
"VALIDATION_ERROR"
|
|
11093
|
+
);
|
|
11094
|
+
}
|
|
11095
|
+
assertAcceptedTerms(accepted);
|
|
11096
|
+
}
|
|
11097
|
+
const worker = this.options.wallet.publicKey.toBase58();
|
|
11098
|
+
const before = await readOpenEscrowAccount(
|
|
11099
|
+
this.connection,
|
|
11100
|
+
new import_web35.PublicKey(address),
|
|
11101
|
+
this.cluster
|
|
11102
|
+
);
|
|
11103
|
+
if (accepted !== void 0) assertClaimable(address, before, worker, accepted);
|
|
10856
11104
|
const { unsignedTx } = await this.api.claimTask(address);
|
|
10857
|
-
|
|
10858
|
-
address,
|
|
11105
|
+
const signature = await this.send(
|
|
10859
11106
|
unsignedTx,
|
|
10860
11107
|
{ name: "claim_task", escrowPda: address },
|
|
10861
|
-
|
|
11108
|
+
void 0,
|
|
11109
|
+
wait
|
|
10862
11110
|
);
|
|
11111
|
+
if (!wait) return signature;
|
|
11112
|
+
await verifyClaimedEscrow(this.connection, {
|
|
11113
|
+
address,
|
|
11114
|
+
cluster: this.cluster,
|
|
11115
|
+
worker,
|
|
11116
|
+
claimSignature: signature,
|
|
11117
|
+
accepted: accepted ?? acceptedTermsOf(before)
|
|
11118
|
+
});
|
|
11119
|
+
await this.confirm(address, signature);
|
|
11120
|
+
return signature;
|
|
10863
11121
|
}
|
|
10864
11122
|
/**
|
|
10865
11123
|
* Submit a deliverable for the buyer to review. Worker must be the wallet.
|
|
@@ -11299,7 +11557,7 @@ function sha256Hex8(content) {
|
|
|
11299
11557
|
return (0, import_crypto4.createHash)("sha256").update(content).digest("hex");
|
|
11300
11558
|
}
|
|
11301
11559
|
var ZKML_DEMO_MODEL_COMMITMENT = sha256Hex8("zkml-demo-classifier-v1");
|
|
11302
|
-
var
|
|
11560
|
+
var U64_MAX2 = 2n ** 64n - 1n;
|
|
11303
11561
|
var ED25519_L = 2n ** 252n + 27742317777372353535851937790883648493n;
|
|
11304
11562
|
|
|
11305
11563
|
// src/server.ts
|
|
@@ -11465,8 +11723,20 @@ var createEscrowSchema = {
|
|
|
11465
11723
|
"An https: link where the buyer serves the TaskSpec, for the worker to read and check against the escrow's spec hash. Public: every escrow read serves it."
|
|
11466
11724
|
)
|
|
11467
11725
|
};
|
|
11726
|
+
var acceptedRow = {
|
|
11727
|
+
maker: import_zod.z.string().superRefine(refinePublicKey).describe("The row's maker, the buyer's wallet"),
|
|
11728
|
+
amount: import_zod.z.string().regex(/^[1-9][0-9]{0,19}$/, "amount must be the row's micro-USDC amount, a decimal string").describe("The row's amount, micro-USDC as a decimal string"),
|
|
11729
|
+
taskSpecHash: import_zod.z.string().regex(
|
|
11730
|
+
/^(?:ipfs:\/\/)?[0-9a-f]{64}$/,
|
|
11731
|
+
"taskSpecHash must be the row's 64-hex hash, bare or ipfs://"
|
|
11732
|
+
).describe("The row's taskSpecHash"),
|
|
11733
|
+
deadline: import_zod.z.number().int().positive().describe("The row's deadline, Unix seconds")
|
|
11734
|
+
};
|
|
11468
11735
|
var claimTaskSchema = {
|
|
11469
|
-
address: import_zod.z.string().superRefine(refinePublicKey).describe("Base-58 escrow PDA address")
|
|
11736
|
+
address: import_zod.z.string().superRefine(refinePublicKey).describe("Base-58 escrow PDA address"),
|
|
11737
|
+
accepted: import_zod.z.object(acceptedRow).optional().describe(
|
|
11738
|
+
"The maker, amount, taskSpecHash and deadline of the escrow as you read it; the claim is refused if the escrow is not that one"
|
|
11739
|
+
)
|
|
11470
11740
|
};
|
|
11471
11741
|
var submitDeliverableSchema = {
|
|
11472
11742
|
address: import_zod.z.string().superRefine(refinePublicKey).describe("Base-58 escrow PDA address"),
|
|
@@ -11689,12 +11959,12 @@ var PAY_402_HOST_REFUSALS = {
|
|
|
11689
11959
|
};
|
|
11690
11960
|
var allowsPrivateHosts = (options) => options.allowPrivateHosts === true;
|
|
11691
11961
|
async function checkPay402Url(url, options) {
|
|
11692
|
-
const
|
|
11962
|
+
const refusal2 = await payUrlRefusal(url, {
|
|
11693
11963
|
cluster: options.cluster,
|
|
11694
11964
|
allowPrivateHosts: allowsPrivateHosts(options),
|
|
11695
11965
|
lookup: import_promises2.lookup
|
|
11696
11966
|
});
|
|
11697
|
-
if (
|
|
11967
|
+
if (refusal2 !== null) throw new Error(PAY_402_HOST_REFUSALS[refusal2]);
|
|
11698
11968
|
}
|
|
11699
11969
|
function hostRefusalError(err, options, url) {
|
|
11700
11970
|
if (!(err instanceof Error)) return null;
|
|
@@ -11737,7 +12007,15 @@ function makeWriteHandlers(escro, options = {}) {
|
|
|
11737
12007
|
}
|
|
11738
12008
|
},
|
|
11739
12009
|
claim_task: async (args) => {
|
|
11740
|
-
const
|
|
12010
|
+
const { accepted } = args;
|
|
12011
|
+
const signature = accepted === void 0 ? await escro.claimTask(args.address) : await escro.claimTask(args.address, {
|
|
12012
|
+
accepted: {
|
|
12013
|
+
buyer: accepted.maker,
|
|
12014
|
+
amountUsdc: accepted.amount,
|
|
12015
|
+
specHash: accepted.taskSpecHash,
|
|
12016
|
+
deadline: accepted.deadline
|
|
12017
|
+
}
|
|
12018
|
+
});
|
|
11741
12019
|
return ok({ signature });
|
|
11742
12020
|
},
|
|
11743
12021
|
submit_deliverable: async (args) => {
|
|
@@ -11822,7 +12100,7 @@ function makeWriteHandlers(escro, options = {}) {
|
|
|
11822
12100
|
}
|
|
11823
12101
|
|
|
11824
12102
|
// src/server.ts
|
|
11825
|
-
var SERVER_VERSION = "0.1.
|
|
12103
|
+
var SERVER_VERSION = "0.1.6";
|
|
11826
12104
|
var READ = {
|
|
11827
12105
|
readOnlyHint: true,
|
|
11828
12106
|
destructiveHint: false,
|
|
@@ -11841,6 +12119,7 @@ var WRITE_STATE = {
|
|
|
11841
12119
|
idempotentHint: false,
|
|
11842
12120
|
openWorldHint: true
|
|
11843
12121
|
};
|
|
12122
|
+
var LIST_ESCROWS_CLAIM = "To claim one, pass its maker, amount, taskSpecHash and deadline to claim_task as accepted.";
|
|
11844
12123
|
var MAX_TOOL_INPUT_ELEMENTS = 64;
|
|
11845
12124
|
function buildServer(env) {
|
|
11846
12125
|
const server = new import_mcp.McpServer(
|
|
@@ -11853,11 +12132,11 @@ function buildServer(env) {
|
|
|
11853
12132
|
api,
|
|
11854
12133
|
env.wallet ? { wallet: env.wallet.publicKey.toBase58() } : {}
|
|
11855
12134
|
);
|
|
11856
|
-
server.registerTool(
|
|
12135
|
+
const listEscrows = server.registerTool(
|
|
11857
12136
|
"list_escrows",
|
|
11858
12137
|
{
|
|
11859
12138
|
title: "List escrows",
|
|
11860
|
-
description: "List escrows on escro.ai with optional filters: state (one of the seven served states, or a non-empty list of them; CREATED is never served), worker (base-58 worker wallet: every escrow assigned to it, in any served state, DISPUTED and settled included), assignedTo (the legacy form of worker: only that worker's escrows in FUNDED, IN_PROGRESS or SUBMITTED; with any other state it returns nothing; refused beside a worker naming another wallet), mine (true: only escrows this server's wallet created as the buyer; refused on a server with no wallet), limit (1-100; the API returns 20 by default) and offset for pagination. Call get_escrow for a single escrow. Claim a FUNDED escrow assigned to you before doing its work: until the claim the buyer may cancel it and take the deposit back, so work done before the claim can go unpaid. Read-only; needs no wallet except for mine.",
|
|
12139
|
+
description: "List escrows on escro.ai with optional filters: state (one of the seven served states, or a non-empty list of them; CREATED is never served), worker (base-58 worker wallet: every escrow assigned to it, in any served state, DISPUTED and settled included), assignedTo (the legacy form of worker: only that worker's escrows in FUNDED, IN_PROGRESS or SUBMITTED; with any other state it returns nothing; refused beside a worker naming another wallet), mine (true: only escrows this server's wallet created as the buyer; refused on a server with no wallet), limit (1-100; the API returns 20 by default) and offset for pagination. Call get_escrow for a single escrow. Claim a FUNDED escrow assigned to you before doing its work: until the claim the buyer may cancel it and take the deposit back, so work done before the claim can go unpaid. To claim one, pass its maker, amount, taskSpecHash and deadline to claim_task as accepted. Read-only; needs no wallet except for mine.",
|
|
11861
12140
|
inputSchema: listEscrowsSchema,
|
|
11862
12141
|
annotations: READ
|
|
11863
12142
|
},
|
|
@@ -11906,6 +12185,16 @@ function buildServer(env) {
|
|
|
11906
12185
|
chain.verify_escrow_onchain
|
|
11907
12186
|
);
|
|
11908
12187
|
}
|
|
12188
|
+
if (!env.wallet) {
|
|
12189
|
+
const description = listEscrows.description ?? "";
|
|
12190
|
+
const claim = ` ${LIST_ESCROWS_CLAIM}`;
|
|
12191
|
+
if (!description.includes(claim)) {
|
|
12192
|
+
throw new Error(
|
|
12193
|
+
`list_escrows' description no longer carries the sentence: ${LIST_ESCROWS_CLAIM}`
|
|
12194
|
+
);
|
|
12195
|
+
}
|
|
12196
|
+
listEscrows.update({ description: description.replace(claim, "") });
|
|
12197
|
+
}
|
|
11909
12198
|
if (!env.wallet) return server;
|
|
11910
12199
|
const escro = new Escro({
|
|
11911
12200
|
cluster: env.cluster,
|
|
@@ -11934,7 +12223,7 @@ function buildServer(env) {
|
|
|
11934
12223
|
"claim_task",
|
|
11935
12224
|
{
|
|
11936
12225
|
title: "Claim task",
|
|
11937
|
-
description: "Accept an escrow as its assigned worker, moving it from FUNDED to IN_PROGRESS. The configured wallet must be the escrow's assignedWorker; anyone else is rejected on-chain. Once claimed, the buyer can no longer cancel. Submit before the deadline: from 15 minutes after it, anyone can refund the buyer.",
|
|
12226
|
+
description: "Accept an escrow as its assigned worker, moving it from FUNDED to IN_PROGRESS. The configured wallet must be the escrow's assignedWorker; anyone else is rejected on-chain. Once claimed, the buyer can no longer cancel. Submit before the deadline: from 15 minutes after it, anyone can refund the buyer. Pass accepted with the maker, amount, taskSpecHash and deadline you read from list_escrows or get_escrow: the claim is refused before it is sent if the escrow no longer matches, and if it lands on an escrow that does not match, the call fails with ClaimBindingError and you must not start the work.",
|
|
11938
12227
|
inputSchema: claimTaskSchema,
|
|
11939
12228
|
annotations: WRITE_STATE
|
|
11940
12229
|
},
|