@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/index.cjs
CHANGED
|
@@ -5879,6 +5879,20 @@ var EscroConfirmError = class extends EscroError {
|
|
|
5879
5879
|
this.name = "EscroConfirmError";
|
|
5880
5880
|
}
|
|
5881
5881
|
};
|
|
5882
|
+
var ClaimBindingError = class extends EscroError {
|
|
5883
|
+
constructor(refusal2, options) {
|
|
5884
|
+
super(refusal2.message, "CLAIM_BINDING_REFUSED", void 0, options);
|
|
5885
|
+
__publicField(this, "address");
|
|
5886
|
+
__publicField(this, "claimSignature");
|
|
5887
|
+
__publicField(this, "field");
|
|
5888
|
+
__publicField(this, "retryable");
|
|
5889
|
+
this.name = "ClaimBindingError";
|
|
5890
|
+
this.address = refusal2.address;
|
|
5891
|
+
this.claimSignature = refusal2.claimSignature;
|
|
5892
|
+
this.field = refusal2.field;
|
|
5893
|
+
this.retryable = refusal2.retryable;
|
|
5894
|
+
}
|
|
5895
|
+
};
|
|
5882
5896
|
var UnauthorizedError = class extends EscroError {
|
|
5883
5897
|
constructor(message = "Unauthorized") {
|
|
5884
5898
|
super(message, "UNAUTHORIZED");
|
|
@@ -7483,6 +7497,205 @@ async function readOpenEscrowAccount(rpc, address, cluster) {
|
|
|
7483
7497
|
}
|
|
7484
7498
|
return ownedAccount(at, account.owner, account.data, programId);
|
|
7485
7499
|
}
|
|
7500
|
+
var CLAIM_CHECK_ATTEMPTS = 5;
|
|
7501
|
+
var CLAIM_CHECK_INTERVAL_MS = 500;
|
|
7502
|
+
var U64_MAX = 2n ** 64n - 1n;
|
|
7503
|
+
var IPFS_PREFIX = "ipfs://";
|
|
7504
|
+
var withoutIpfs = (hash) => hash.startsWith(IPFS_PREFIX) ? hash.slice(IPFS_PREFIX.length) : hash;
|
|
7505
|
+
var invalidTerms = (message) => new EscroError(message, "VALIDATION_ERROR");
|
|
7506
|
+
function claimTermsOf(accepted) {
|
|
7507
|
+
if (!isCanonicalPubkey(accepted.buyer)) {
|
|
7508
|
+
throw invalidTerms("accepted.buyer is not a base58 public key");
|
|
7509
|
+
}
|
|
7510
|
+
const raw = accepted.amountUsdc;
|
|
7511
|
+
if (typeof raw === "string" && !/^[0-9]+$/.test(raw)) {
|
|
7512
|
+
throw invalidTerms("accepted.amountUsdc is not a decimal string of micro-USDC digits");
|
|
7513
|
+
}
|
|
7514
|
+
const amount = BigInt(raw);
|
|
7515
|
+
if (amount < 0n || amount > U64_MAX) {
|
|
7516
|
+
throw invalidTerms("accepted.amountUsdc is outside the u64 range");
|
|
7517
|
+
}
|
|
7518
|
+
const window = typeof accepted.deadline === "number" ? { min: accepted.deadline, max: accepted.deadline } : accepted.deadline;
|
|
7519
|
+
if (!Number.isSafeInteger(window.min) || !Number.isSafeInteger(window.max)) {
|
|
7520
|
+
throw invalidTerms("accepted.deadline is not whole Unix seconds");
|
|
7521
|
+
}
|
|
7522
|
+
if (window.min > window.max) {
|
|
7523
|
+
throw invalidTerms("accepted.deadline's window has min greater than max");
|
|
7524
|
+
}
|
|
7525
|
+
return {
|
|
7526
|
+
buyer: accepted.buyer,
|
|
7527
|
+
amount,
|
|
7528
|
+
specHash: withoutIpfs(accepted.specHash),
|
|
7529
|
+
min: window.min,
|
|
7530
|
+
max: window.max
|
|
7531
|
+
};
|
|
7532
|
+
}
|
|
7533
|
+
function shown(value) {
|
|
7534
|
+
if (value === null || value === void 0) return "none";
|
|
7535
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
7536
|
+
if (typeof value === "number" || typeof value === "bigint") return String(value);
|
|
7537
|
+
return typeof value;
|
|
7538
|
+
}
|
|
7539
|
+
function firstMismatch(record, tail, terms, worker, stage) {
|
|
7540
|
+
const state = stage === "before" ? "Funded" : "InProgress";
|
|
7541
|
+
const expectations = {
|
|
7542
|
+
buyer: { holds: (found) => found === terms.buyer, expected: terms.buyer },
|
|
7543
|
+
assigned_worker: {
|
|
7544
|
+
holds: (found) => found === worker || stage === "before" && found === null,
|
|
7545
|
+
expected: stage === "before" ? `${worker} or none` : worker
|
|
7546
|
+
},
|
|
7547
|
+
amount_usdc: { holds: (found) => found === terms.amount, expected: terms.amount.toString() },
|
|
7548
|
+
deadline: {
|
|
7549
|
+
holds: (found) => typeof found === "number" && found >= terms.min && found <= terms.max,
|
|
7550
|
+
expected: terms.min === terms.max ? String(terms.min) : `from ${String(terms.min)} to ${String(terms.max)}`
|
|
7551
|
+
},
|
|
7552
|
+
spec_hash: {
|
|
7553
|
+
holds: (found) => typeof found === "string" && withoutIpfs(found) === terms.specHash,
|
|
7554
|
+
expected: JSON.stringify(terms.specHash)
|
|
7555
|
+
},
|
|
7556
|
+
state: { holds: (found) => found === state, expected: state },
|
|
7557
|
+
marketplace_id: { holds: (found) => found === null, expected: "none" },
|
|
7558
|
+
referrer_wallet: { holds: (found) => found === null, expected: "none" },
|
|
7559
|
+
referrer_bps: { holds: (found) => found === 0, expected: "0" }
|
|
7560
|
+
};
|
|
7561
|
+
for (const { name } of ESCROW_ACCOUNT_V1_FIELDS) {
|
|
7562
|
+
const expectation = expectations[name];
|
|
7563
|
+
const found = record[name];
|
|
7564
|
+
if (expectation === void 0 || expectation.holds(found)) continue;
|
|
7565
|
+
return {
|
|
7566
|
+
field: name,
|
|
7567
|
+
expected: expectation.expected,
|
|
7568
|
+
found: shown(found),
|
|
7569
|
+
indeterminate: stage === "after" && name === "state" && found === "Funded"
|
|
7570
|
+
};
|
|
7571
|
+
}
|
|
7572
|
+
const term = tail.names.find((name) => name !== "marketplace_id");
|
|
7573
|
+
if (term === void 0) return void 0;
|
|
7574
|
+
return {
|
|
7575
|
+
field: term,
|
|
7576
|
+
expected: "the default job's",
|
|
7577
|
+
found: shown(tail.values.get(camelCase(term))),
|
|
7578
|
+
indeterminate: false
|
|
7579
|
+
};
|
|
7580
|
+
}
|
|
7581
|
+
function refusal(address, claimSignature, mismatch, reads, cause) {
|
|
7582
|
+
const claim = claimSignature === void 0 ? "" : ` (claim ${claimSignature})`;
|
|
7583
|
+
const detail = `${mismatch.field} expected ${mismatch.expected}, found ${mismatch.found}`;
|
|
7584
|
+
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`;
|
|
7585
|
+
return new ClaimBindingError(
|
|
7586
|
+
{
|
|
7587
|
+
address,
|
|
7588
|
+
claimSignature,
|
|
7589
|
+
field: mismatch.field,
|
|
7590
|
+
retryable: mismatch.indeterminate,
|
|
7591
|
+
message
|
|
7592
|
+
},
|
|
7593
|
+
cause === void 0 ? void 0 : { cause }
|
|
7594
|
+
);
|
|
7595
|
+
}
|
|
7596
|
+
async function readClaimed(rpc, address, programId, worker, terms) {
|
|
7597
|
+
const unreadable2 = (expected, found, indeterminate) => ({
|
|
7598
|
+
field: "account",
|
|
7599
|
+
expected,
|
|
7600
|
+
found,
|
|
7601
|
+
indeterminate
|
|
7602
|
+
});
|
|
7603
|
+
let info;
|
|
7604
|
+
try {
|
|
7605
|
+
info = await rpc.getAccountInfo(address, { commitment: "confirmed" });
|
|
7606
|
+
} catch (cause) {
|
|
7607
|
+
return { mismatch: unreadable2("a readable account", "the read failed", true), cause };
|
|
7608
|
+
}
|
|
7609
|
+
if (info === null || info.owner.equals(import_web38.SystemProgram.programId) && info.data.length === 0) {
|
|
7610
|
+
return { mismatch: unreadable2("an open escrow account", "no account", true) };
|
|
7611
|
+
}
|
|
7612
|
+
if (!info.owner.equals(programId)) {
|
|
7613
|
+
return {
|
|
7614
|
+
mismatch: unreadable2(
|
|
7615
|
+
`an account of the program ${programId.toBase58()}`,
|
|
7616
|
+
`an account owned by ${info.owner.toBase58()}`,
|
|
7617
|
+
false
|
|
7618
|
+
)
|
|
7619
|
+
};
|
|
7620
|
+
}
|
|
7621
|
+
let account;
|
|
7622
|
+
let record;
|
|
7623
|
+
try {
|
|
7624
|
+
account = decodeEscrowAccount(info.data, { v1ReviewWindowSeconds: ONCHAIN_TIMEOUT_SECONDS2 });
|
|
7625
|
+
record = recordOf(account);
|
|
7626
|
+
} catch (err) {
|
|
7627
|
+
if (err instanceof EscrowAccountDecodeError || err instanceof AccountProblem) {
|
|
7628
|
+
return {
|
|
7629
|
+
mismatch: unreadable2(
|
|
7630
|
+
"a current EscrowAccount",
|
|
7631
|
+
`bytes that do not decode (${err.reason})`,
|
|
7632
|
+
false
|
|
7633
|
+
)
|
|
7634
|
+
};
|
|
7635
|
+
}
|
|
7636
|
+
throw err;
|
|
7637
|
+
}
|
|
7638
|
+
const mismatch = firstMismatch(
|
|
7639
|
+
record,
|
|
7640
|
+
{ names: nonDefaultJobTerms(account), values: new Map(Object.entries(account.terms)) },
|
|
7641
|
+
terms,
|
|
7642
|
+
worker,
|
|
7643
|
+
"after"
|
|
7644
|
+
);
|
|
7645
|
+
return mismatch === void 0 ? { record } : { mismatch };
|
|
7646
|
+
}
|
|
7647
|
+
function claimKey(value, what) {
|
|
7648
|
+
if (!isCanonicalPubkey(value)) throw invalidTerms(`The ${what} is not a base58 public key`);
|
|
7649
|
+
return new import_web38.PublicKey(value);
|
|
7650
|
+
}
|
|
7651
|
+
async function verifyClaimedEscrow(rpc, params) {
|
|
7652
|
+
const terms = claimTermsOf(params.accepted);
|
|
7653
|
+
const address = claimKey(params.address, "address");
|
|
7654
|
+
claimKey(params.worker, "worker");
|
|
7655
|
+
const intervalMs = params.intervalMs ?? CLAIM_CHECK_INTERVAL_MS;
|
|
7656
|
+
if (!Number.isSafeInteger(intervalMs) || intervalMs < 0) {
|
|
7657
|
+
throw invalidTerms("intervalMs must be a non-negative integer of milliseconds");
|
|
7658
|
+
}
|
|
7659
|
+
const programId = clusterProgramId(params.cluster);
|
|
7660
|
+
for (let reads = 1; ; reads += 1) {
|
|
7661
|
+
const outcome = await readClaimed(rpc, address, programId, params.worker, terms);
|
|
7662
|
+
if ("record" in outcome) return outcome.record;
|
|
7663
|
+
const { mismatch } = outcome;
|
|
7664
|
+
if (!mismatch.indeterminate || reads >= CLAIM_CHECK_ATTEMPTS) {
|
|
7665
|
+
throw refusal(params.address, params.claimSignature, mismatch, reads, outcome.cause);
|
|
7666
|
+
}
|
|
7667
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
7668
|
+
}
|
|
7669
|
+
}
|
|
7670
|
+
function assertAcceptedTerms(accepted) {
|
|
7671
|
+
claimTermsOf(accepted);
|
|
7672
|
+
}
|
|
7673
|
+
function assertClaimable(address, record, worker, accepted) {
|
|
7674
|
+
const mismatch = firstMismatch(
|
|
7675
|
+
record,
|
|
7676
|
+
{ names: [], values: /* @__PURE__ */ new Map() },
|
|
7677
|
+
claimTermsOf(accepted),
|
|
7678
|
+
worker,
|
|
7679
|
+
"before"
|
|
7680
|
+
);
|
|
7681
|
+
if (mismatch === void 0) return;
|
|
7682
|
+
const detail = `${mismatch.field} expected ${mismatch.expected}, found ${mismatch.found}`;
|
|
7683
|
+
throw new ClaimBindingError({
|
|
7684
|
+
address,
|
|
7685
|
+
claimSignature: void 0,
|
|
7686
|
+
field: mismatch.field,
|
|
7687
|
+
retryable: false,
|
|
7688
|
+
message: `The escrow at ${address} is not the escrow accepted (${detail}): nothing was claimed`
|
|
7689
|
+
});
|
|
7690
|
+
}
|
|
7691
|
+
function acceptedTermsOf(record) {
|
|
7692
|
+
return {
|
|
7693
|
+
buyer: stringOf(record, "buyer"),
|
|
7694
|
+
amountUsdc: bigintOf(record, "amount_usdc"),
|
|
7695
|
+
specHash: stringOf(record, "spec_hash"),
|
|
7696
|
+
deadline: numberOf(record, "deadline")
|
|
7697
|
+
};
|
|
7698
|
+
}
|
|
7486
7699
|
function readAccount(address, owner, data, programId, cluster) {
|
|
7487
7700
|
const at = address.toBase58();
|
|
7488
7701
|
const decoded2 = ownedAccount(at, owner, data, programId);
|
|
@@ -10927,25 +11140,70 @@ var Escro = class {
|
|
|
10927
11140
|
* account decodes as {@link decodeEscrowAccount} reads it (version 1, or version 2 on the
|
|
10928
11141
|
* default job's terms).
|
|
10929
11142
|
* Signs and submits the `claim_task` on-chain tx, then confirms it with the API.
|
|
10930
|
-
*
|
|
11143
|
+
*
|
|
11144
|
+
* From 0.5.4 the claim binds the escrow the worker read. A buyer can cancel a Funded escrow and
|
|
11145
|
+
* create another at the same address before the claim lands, and the claim then lands on the new
|
|
11146
|
+
* one. With `options.accepted` (the terms the caller priced: a listing row's `maker`, `amount`,
|
|
11147
|
+
* `taskSpecHash` and `deadline`) the pre-claim read must be Funded, assigned to this wallet or to
|
|
11148
|
+
* none, and hold those terms, or a `ClaimBindingError` is thrown before anything is
|
|
11149
|
+
* requested or sent. Once the claim confirms, {@link verifyClaimedEscrow} reads the account again
|
|
11150
|
+
* with the claim's signature, against `accepted` or, absent, against the pre-claim read; the API
|
|
11151
|
+
* is asked to record the claim only after it passes. A definitive refusal (`retryable: false`)
|
|
11152
|
+
* leaves this wallet holding an IN_PROGRESS escrow it must not work. Without `accepted` a swap made
|
|
11153
|
+
* before the pre-claim read (a listing that lags the chain) passes: pass `accepted` to close it.
|
|
11154
|
+
*
|
|
11155
|
+
* Run `verifyClaimedEscrow` with the claim's signature yourself, before any work, after a claim
|
|
11156
|
+
* with `{ wait: false }` (which returns once the claim is sent and checks nothing; with `accepted`
|
|
11157
|
+
* it is refused, `VALIDATION_ERROR`, before any request), after a caught send error that carries
|
|
11158
|
+
* `signature` (the claim may have landed), and after a `retryable` refusal. See
|
|
11159
|
+
* {@link SendOptions.wait}.
|
|
10931
11160
|
*
|
|
10932
11161
|
* @throws From 0.5.3, {@link ChainReadError} before any API request:
|
|
10933
11162
|
* `CHAIN_ESCROW_NOT_FOUND` with no open account at `address`, `CHAIN_ACCOUNT_INVALID` for another
|
|
10934
11163
|
* owner's account or one the decode refuses (reason `version` names a version-2 escrow's terms
|
|
10935
11164
|
* other than the default job's), `CHAIN_RPC_FAILED` when the read fails. Before 0.5.3 a missing
|
|
10936
|
-
* escrow is an {@link EscrowNotFoundError} from the API.
|
|
11165
|
+
* escrow is an {@link EscrowNotFoundError} from the API. From 0.5.4, `ClaimBindingError`
|
|
11166
|
+
* before the claim (with `accepted`) or after it lands, and {@link EscroConfirmError} only after
|
|
11167
|
+
* the post-claim check passed.
|
|
10937
11168
|
* @returns Solana transaction signature.
|
|
10938
11169
|
*/
|
|
10939
11170
|
async claimTask(address, options) {
|
|
10940
11171
|
assertPublicKey("address", address);
|
|
10941
|
-
|
|
11172
|
+
const wait = options?.wait ?? true;
|
|
11173
|
+
const accepted = options?.accepted;
|
|
11174
|
+
if (accepted !== void 0) {
|
|
11175
|
+
if (!wait) {
|
|
11176
|
+
throw new EscroError(
|
|
11177
|
+
"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",
|
|
11178
|
+
"VALIDATION_ERROR"
|
|
11179
|
+
);
|
|
11180
|
+
}
|
|
11181
|
+
assertAcceptedTerms(accepted);
|
|
11182
|
+
}
|
|
11183
|
+
const worker = this.options.wallet.publicKey.toBase58();
|
|
11184
|
+
const before = await readOpenEscrowAccount(
|
|
11185
|
+
this.connection,
|
|
11186
|
+
new import_web35.PublicKey(address),
|
|
11187
|
+
this.cluster
|
|
11188
|
+
);
|
|
11189
|
+
if (accepted !== void 0) assertClaimable(address, before, worker, accepted);
|
|
10942
11190
|
const { unsignedTx } = await this.api.claimTask(address);
|
|
10943
|
-
|
|
10944
|
-
address,
|
|
11191
|
+
const signature = await this.send(
|
|
10945
11192
|
unsignedTx,
|
|
10946
11193
|
{ name: "claim_task", escrowPda: address },
|
|
10947
|
-
|
|
11194
|
+
void 0,
|
|
11195
|
+
wait
|
|
10948
11196
|
);
|
|
11197
|
+
if (!wait) return signature;
|
|
11198
|
+
await verifyClaimedEscrow(this.connection, {
|
|
11199
|
+
address,
|
|
11200
|
+
cluster: this.cluster,
|
|
11201
|
+
worker,
|
|
11202
|
+
claimSignature: signature,
|
|
11203
|
+
accepted: accepted ?? acceptedTermsOf(before)
|
|
11204
|
+
});
|
|
11205
|
+
await this.confirm(address, signature);
|
|
11206
|
+
return signature;
|
|
10949
11207
|
}
|
|
10950
11208
|
/**
|
|
10951
11209
|
* Submit a deliverable for the buyer to review. Worker must be the wallet.
|
|
@@ -11385,7 +11643,7 @@ function sha256Hex8(content) {
|
|
|
11385
11643
|
return (0, import_crypto4.createHash)("sha256").update(content).digest("hex");
|
|
11386
11644
|
}
|
|
11387
11645
|
var ZKML_DEMO_MODEL_COMMITMENT = sha256Hex8("zkml-demo-classifier-v1");
|
|
11388
|
-
var
|
|
11646
|
+
var U64_MAX2 = 2n ** 64n - 1n;
|
|
11389
11647
|
var ED25519_L = 2n ** 252n + 27742317777372353535851937790883648493n;
|
|
11390
11648
|
|
|
11391
11649
|
// src/env.ts
|
|
@@ -11529,8 +11787,20 @@ var createEscrowSchema = {
|
|
|
11529
11787
|
"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."
|
|
11530
11788
|
)
|
|
11531
11789
|
};
|
|
11790
|
+
var acceptedRow = {
|
|
11791
|
+
maker: import_zod.z.string().superRefine(refinePublicKey).describe("The row's maker, the buyer's wallet"),
|
|
11792
|
+
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"),
|
|
11793
|
+
taskSpecHash: import_zod.z.string().regex(
|
|
11794
|
+
/^(?:ipfs:\/\/)?[0-9a-f]{64}$/,
|
|
11795
|
+
"taskSpecHash must be the row's 64-hex hash, bare or ipfs://"
|
|
11796
|
+
).describe("The row's taskSpecHash"),
|
|
11797
|
+
deadline: import_zod.z.number().int().positive().describe("The row's deadline, Unix seconds")
|
|
11798
|
+
};
|
|
11532
11799
|
var claimTaskSchema = {
|
|
11533
|
-
address: import_zod.z.string().superRefine(refinePublicKey).describe("Base-58 escrow PDA address")
|
|
11800
|
+
address: import_zod.z.string().superRefine(refinePublicKey).describe("Base-58 escrow PDA address"),
|
|
11801
|
+
accepted: import_zod.z.object(acceptedRow).optional().describe(
|
|
11802
|
+
"The maker, amount, taskSpecHash and deadline of the escrow as you read it; the claim is refused if the escrow is not that one"
|
|
11803
|
+
)
|
|
11534
11804
|
};
|
|
11535
11805
|
var submitDeliverableSchema = {
|
|
11536
11806
|
address: import_zod.z.string().superRefine(refinePublicKey).describe("Base-58 escrow PDA address"),
|
|
@@ -11753,12 +12023,12 @@ var PAY_402_HOST_REFUSALS = {
|
|
|
11753
12023
|
};
|
|
11754
12024
|
var allowsPrivateHosts = (options) => options.allowPrivateHosts === true;
|
|
11755
12025
|
async function checkPay402Url(url, options) {
|
|
11756
|
-
const
|
|
12026
|
+
const refusal2 = await payUrlRefusal(url, {
|
|
11757
12027
|
cluster: options.cluster,
|
|
11758
12028
|
allowPrivateHosts: allowsPrivateHosts(options),
|
|
11759
12029
|
lookup: import_promises2.lookup
|
|
11760
12030
|
});
|
|
11761
|
-
if (
|
|
12031
|
+
if (refusal2 !== null) throw new Error(PAY_402_HOST_REFUSALS[refusal2]);
|
|
11762
12032
|
}
|
|
11763
12033
|
function hostRefusalError(err, options, url) {
|
|
11764
12034
|
if (!(err instanceof Error)) return null;
|
|
@@ -11801,7 +12071,15 @@ function makeWriteHandlers(escro, options = {}) {
|
|
|
11801
12071
|
}
|
|
11802
12072
|
},
|
|
11803
12073
|
claim_task: async (args) => {
|
|
11804
|
-
const
|
|
12074
|
+
const { accepted } = args;
|
|
12075
|
+
const signature = accepted === void 0 ? await escro.claimTask(args.address) : await escro.claimTask(args.address, {
|
|
12076
|
+
accepted: {
|
|
12077
|
+
buyer: accepted.maker,
|
|
12078
|
+
amountUsdc: accepted.amount,
|
|
12079
|
+
specHash: accepted.taskSpecHash,
|
|
12080
|
+
deadline: accepted.deadline
|
|
12081
|
+
}
|
|
12082
|
+
});
|
|
11805
12083
|
return ok({ signature });
|
|
11806
12084
|
},
|
|
11807
12085
|
submit_deliverable: async (args) => {
|
|
@@ -11886,7 +12164,7 @@ function makeWriteHandlers(escro, options = {}) {
|
|
|
11886
12164
|
}
|
|
11887
12165
|
|
|
11888
12166
|
// src/server.ts
|
|
11889
|
-
var SERVER_VERSION = "0.1.
|
|
12167
|
+
var SERVER_VERSION = "0.1.6";
|
|
11890
12168
|
var READ = {
|
|
11891
12169
|
readOnlyHint: true,
|
|
11892
12170
|
destructiveHint: false,
|
|
@@ -11905,6 +12183,7 @@ var WRITE_STATE = {
|
|
|
11905
12183
|
idempotentHint: false,
|
|
11906
12184
|
openWorldHint: true
|
|
11907
12185
|
};
|
|
12186
|
+
var LIST_ESCROWS_CLAIM = "To claim one, pass its maker, amount, taskSpecHash and deadline to claim_task as accepted.";
|
|
11908
12187
|
var MAX_TOOL_INPUT_ELEMENTS = 64;
|
|
11909
12188
|
function buildServer(env) {
|
|
11910
12189
|
const server = new import_mcp.McpServer(
|
|
@@ -11917,11 +12196,11 @@ function buildServer(env) {
|
|
|
11917
12196
|
api,
|
|
11918
12197
|
env.wallet ? { wallet: env.wallet.publicKey.toBase58() } : {}
|
|
11919
12198
|
);
|
|
11920
|
-
server.registerTool(
|
|
12199
|
+
const listEscrows = server.registerTool(
|
|
11921
12200
|
"list_escrows",
|
|
11922
12201
|
{
|
|
11923
12202
|
title: "List escrows",
|
|
11924
|
-
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.",
|
|
12203
|
+
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.",
|
|
11925
12204
|
inputSchema: listEscrowsSchema,
|
|
11926
12205
|
annotations: READ
|
|
11927
12206
|
},
|
|
@@ -11970,6 +12249,16 @@ function buildServer(env) {
|
|
|
11970
12249
|
chain.verify_escrow_onchain
|
|
11971
12250
|
);
|
|
11972
12251
|
}
|
|
12252
|
+
if (!env.wallet) {
|
|
12253
|
+
const description = listEscrows.description ?? "";
|
|
12254
|
+
const claim = ` ${LIST_ESCROWS_CLAIM}`;
|
|
12255
|
+
if (!description.includes(claim)) {
|
|
12256
|
+
throw new Error(
|
|
12257
|
+
`list_escrows' description no longer carries the sentence: ${LIST_ESCROWS_CLAIM}`
|
|
12258
|
+
);
|
|
12259
|
+
}
|
|
12260
|
+
listEscrows.update({ description: description.replace(claim, "") });
|
|
12261
|
+
}
|
|
11973
12262
|
if (!env.wallet) return server;
|
|
11974
12263
|
const escro = new Escro({
|
|
11975
12264
|
cluster: env.cluster,
|
|
@@ -11998,7 +12287,7 @@ function buildServer(env) {
|
|
|
11998
12287
|
"claim_task",
|
|
11999
12288
|
{
|
|
12000
12289
|
title: "Claim task",
|
|
12001
|
-
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.",
|
|
12290
|
+
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.",
|
|
12002
12291
|
inputSchema: claimTaskSchema,
|
|
12003
12292
|
annotations: WRITE_STATE
|
|
12004
12293
|
},
|