@escro/mcp 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tools.cjs CHANGED
@@ -2297,8 +2297,8 @@ var import_bs583 = __toESM(require("bs58"), 1);
2297
2297
  var import_web32 = require("@solana/web3.js");
2298
2298
  var import_bs584 = __toESM(require("bs58"), 1);
2299
2299
  var import_web33 = require("@solana/web3.js");
2300
- var import_bs585 = __toESM(require("bs58"), 1);
2301
2300
  var import_web34 = require("@solana/web3.js");
2301
+ var import_bs585 = __toESM(require("bs58"), 1);
2302
2302
  var import_bs586 = __toESM(require("bs58"), 1);
2303
2303
  var import_bs587 = __toESM(require("bs58"), 1);
2304
2304
  var import_web35 = require("@solana/web3.js");
@@ -2337,7 +2337,6 @@ var SOLANA_CAIP2_DEVNET = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
2337
2337
  function escrowFee(amount, feeBps) {
2338
2338
  return amount * BigInt(feeBps) / 10000n;
2339
2339
  }
2340
- var CURRENT_ACCOUNT_VERSION = 1;
2341
2340
  var ONCHAIN_REFUND_GRACE_SECONDS = 900;
2342
2341
  var ONCHAIN_TIMEOUT_SECONDS = 86400;
2343
2342
  var CLOCK_SKEW_SECONDS = 60;
@@ -2390,6 +2389,27 @@ var ESCROW_INSTRUCTIONS = {
2390
2389
  arbitration_release: spec([118, 157, 141, 26, 104, 117, 94, 229], 4, "ARBITRATION_RELEASE"),
2391
2390
  arbitration_refund: spec([255, 194, 84, 248, 185, 249, 120, 122], 4, "ARBITRATION_REFUND")
2392
2391
  };
2392
+ var NON_ESCROW_INSTRUCTIONS = {
2393
+ initialize_platform: Uint8Array.from([119, 201, 101, 45, 75, 122, 89, 3]),
2394
+ initialize_admin_config: Uint8Array.from([133, 214, 35, 2, 50, 232, 95, 164]),
2395
+ close_platform: Uint8Array.from([27, 145, 216, 122, 13, 15, 46, 201]),
2396
+ update_platform: Uint8Array.from([46, 78, 138, 189, 47, 163, 120, 85]),
2397
+ set_admin_authority: Uint8Array.from([72, 49, 37, 167, 149, 98, 49, 174]),
2398
+ migrate_escrow_v1_to_v2: Uint8Array.from([70, 76, 99, 21, 154, 50, 111, 221])
2399
+ };
2400
+ var RETIRED_INSTRUCTIONS = {
2401
+ claim_open_task: Uint8Array.from([31, 61, 16, 69, 194, 74, 72, 148])
2402
+ };
2403
+ var ANCHOR_IDL_INSTRUCTION_TAG = Uint8Array.from([
2404
+ 64,
2405
+ 244,
2406
+ 188,
2407
+ 120,
2408
+ 167,
2409
+ 233,
2410
+ 105,
2411
+ 10
2412
+ ]);
2393
2413
  var utf8 = (s) => new TextEncoder().encode(s);
2394
2414
  function deriveEscrowPda(programId, buyer, taskId) {
2395
2415
  return import_web32.PublicKey.findProgramAddressSync(
@@ -2450,6 +2470,7 @@ var SPEND_CAP_ERROR_CODES = {
2450
2470
  /** The outstanding deposits could not be read. */
2451
2471
  unreadable: "SPEND_CAP_UNREADABLE"
2452
2472
  };
2473
+ var ESCROW_READABLE_VERSIONS = [1, 2];
2453
2474
  var ONCHAIN_REFUND_GRACE_SECONDS2 = 900;
2454
2475
  var ONCHAIN_TIMEOUT_SECONDS2 = 86400;
2455
2476
  var CLOCK_SKEW_SECONDS2 = 60;
@@ -2574,7 +2595,7 @@ var Reader2 = class {
2574
2595
  }
2575
2596
  switch (type) {
2576
2597
  case "pubkey":
2577
- return import_bs586.default.encode(this.take(32));
2598
+ return import_bs585.default.encode(this.take(32));
2578
2599
  case "string": {
2579
2600
  const length = this.view(4).getUint32(0, true);
2580
2601
  return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(this.take(length));
@@ -2642,7 +2663,8 @@ function build(name, f) {
2642
2663
  deadline: num(f, "deadline"),
2643
2664
  specHash: str(f, "spec_hash"),
2644
2665
  createdAt: num(f, "created_at"),
2645
- assignedWorker: optStr(f, "assigned_worker")
2666
+ assignedWorker: optStr(f, "assigned_worker"),
2667
+ marketplaceId: optStr(f, "marketplace_id")
2646
2668
  };
2647
2669
  case "TaskClaimed":
2648
2670
  return {
@@ -2714,6 +2736,9 @@ function decodeEscroEvent(data) {
2714
2736
  reader.end();
2715
2737
  return build(name, fields);
2716
2738
  }
2739
+ function isMarketStamped(created) {
2740
+ return created.marketplaceId !== null;
2741
+ }
2717
2742
  var INVOKE = /^Program (\w+) invoke \[(\d+)\]$/;
2718
2743
  var EXIT = /^Program (\w+) (?:success|failed)/;
2719
2744
  var DATA = "Program data: ";
@@ -2784,6 +2809,27 @@ var ESCROW_INSTRUCTIONS2 = {
2784
2809
  arbitration_release: spec2([118, 157, 141, 26, 104, 117, 94, 229], 4, "ARBITRATION_RELEASE"),
2785
2810
  arbitration_refund: spec2([255, 194, 84, 248, 185, 249, 120, 122], 4, "ARBITRATION_REFUND")
2786
2811
  };
2812
+ var NON_ESCROW_INSTRUCTIONS2 = {
2813
+ initialize_platform: Uint8Array.from([119, 201, 101, 45, 75, 122, 89, 3]),
2814
+ initialize_admin_config: Uint8Array.from([133, 214, 35, 2, 50, 232, 95, 164]),
2815
+ close_platform: Uint8Array.from([27, 145, 216, 122, 13, 15, 46, 201]),
2816
+ update_platform: Uint8Array.from([46, 78, 138, 189, 47, 163, 120, 85]),
2817
+ set_admin_authority: Uint8Array.from([72, 49, 37, 167, 149, 98, 49, 174]),
2818
+ migrate_escrow_v1_to_v2: Uint8Array.from([70, 76, 99, 21, 154, 50, 111, 221])
2819
+ };
2820
+ var RETIRED_INSTRUCTIONS2 = {
2821
+ claim_open_task: Uint8Array.from([31, 61, 16, 69, 194, 74, 72, 148])
2822
+ };
2823
+ var ANCHOR_IDL_INSTRUCTION_TAG2 = Uint8Array.from([
2824
+ 64,
2825
+ 244,
2826
+ 188,
2827
+ 120,
2828
+ 167,
2829
+ 233,
2830
+ 105,
2831
+ 10
2832
+ ]);
2787
2833
  var MAX_SUPPORTED_TRANSACTION_VERSION = 1;
2788
2834
  var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2789
2835
  function parsedJson(text) {
@@ -2831,20 +2877,20 @@ function transactionVersionFetch(fetchFn) {
2831
2877
  );
2832
2878
  };
2833
2879
  }
2834
- var ChainReadError = class extends EscroError {
2835
- constructor(code, message, options = {}) {
2836
- super(message, code, void 0, "cause" in options ? { cause: options.cause } : void 0);
2837
- __publicField(this, "reason");
2838
- this.name = "ChainReadError";
2839
- this.reason = options.reason;
2840
- }
2841
- };
2842
- var ARCHIVAL_RPC_NOTE = "A settled escrow is closed on chain and survives only in transaction history; if it is older than this RPC's history, read it through an archival RPC.";
2843
- var CHAIN_READ_MAX_TRANSACTIONS = 50;
2844
- var CHAIN_READ_MAX_SIGNATURE_PAGES = 5;
2845
- var SIGNATURE_PAGE = 1e3;
2880
+ var ESCROW_ACCOUNT_ALLOCATIONS = { 1: 537, 2: 672 };
2881
+ var PRE_VERSION_ESCROW_ACCOUNT_SIZES = [463, 536];
2882
+ var E2E_SHORT_TIMEOUT_SECONDS = 8;
2846
2883
  var ESCROW_ACCOUNT_DISCRIMINATOR = [36, 69, 48, 18, 128, 225, 125, 135];
2847
- var ESCROW_ACCOUNT_LAYOUT = [
2884
+ var ESCROW_ACCOUNT_STATES = [
2885
+ "Created",
2886
+ "Funded",
2887
+ "InProgress",
2888
+ "Submitted",
2889
+ "Completed",
2890
+ "Disputed",
2891
+ "Refunded"
2892
+ ];
2893
+ var ESCROW_ACCOUNT_V1_FIELDS = [
2848
2894
  { name: "version", kind: "u8" },
2849
2895
  { name: "buyer", kind: "pubkey" },
2850
2896
  { name: "assigned_worker", kind: "option<pubkey>" },
@@ -2855,7 +2901,7 @@ var ESCROW_ACCOUNT_LAYOUT = [
2855
2901
  { name: "spec_hash", kind: "string" },
2856
2902
  { name: "deliverable_hash", kind: "option<string>" },
2857
2903
  { name: "proof_uri", kind: "option<string>" },
2858
- { name: "state", kind: "enum" },
2904
+ { name: "state", kind: "state" },
2859
2905
  { name: "created_at", kind: "i64" },
2860
2906
  { name: "updated_at", kind: "i64" },
2861
2907
  { name: "submitted_at", kind: "option<i64>" },
@@ -2865,125 +2911,372 @@ var ESCROW_ACCOUNT_LAYOUT = [
2865
2911
  { name: "referrer_wallet", kind: "option<pubkey>" },
2866
2912
  { name: "referrer_bps", kind: "u16" }
2867
2913
  ];
2868
- var ESCROW_ACCOUNT_SIZE = 537;
2869
- var STATE_VARIANTS = [
2870
- "Created",
2871
- "Funded",
2872
- "InProgress",
2873
- "Submitted",
2874
- "Completed",
2875
- "Disputed",
2876
- "Refunded"
2914
+ var ESCROW_TERMS_FIELDS = [
2915
+ { name: "settlement_mode", kind: "settlement_mode" },
2916
+ { name: "review_window_seconds", kind: "u32" },
2917
+ { name: "evaluator", kind: "pubkey" },
2918
+ { name: "payout_network", kind: "bytes32" },
2919
+ { name: "operator", kind: "pubkey" },
2920
+ { name: "operator_fee_bps", kind: "u16" },
2921
+ { name: "arbitrator", kind: "pubkey" }
2877
2922
  ];
2878
- var STATE_OF = {
2879
- Created: EscrowState.CREATED,
2880
- Funded: EscrowState.FUNDED,
2881
- InProgress: EscrowState.IN_PROGRESS,
2882
- Submitted: EscrowState.SUBMITTED,
2883
- Completed: EscrowState.COMPLETED,
2884
- Disputed: EscrowState.DISPUTED,
2885
- Refunded: EscrowState.REFUNDED
2886
- };
2887
- var MAX_TASK_ID_BYTES = 32;
2888
- var AccountProblem = class extends Error {
2889
- constructor(reason, detail) {
2890
- super(detail);
2891
- __publicField(this, "reason", reason);
2892
- __publicField(this, "detail", detail);
2923
+ var SETTLEMENT_MODE_BYTES = { release: 0, refund: 1 };
2924
+ var ZERO_KEY = import_bs587.default.encode(new Uint8Array(32));
2925
+ var ZERO_HEX32 = "0".repeat(64);
2926
+ var MAX_U32 = 4294967295;
2927
+ function v1DefaultTerms(buyer, v1ReviewWindowSeconds) {
2928
+ if (!Number.isInteger(v1ReviewWindowSeconds) || v1ReviewWindowSeconds < 1 || v1ReviewWindowSeconds > MAX_U32) {
2929
+ throw new RangeError(
2930
+ `version-1 review window ${String(v1ReviewWindowSeconds)} is not an integer in 1..${String(MAX_U32)}`
2931
+ );
2932
+ }
2933
+ return {
2934
+ settlementMode: "release",
2935
+ reviewWindowSeconds: v1ReviewWindowSeconds,
2936
+ evaluator: buyer,
2937
+ payoutNetwork: ZERO_HEX32,
2938
+ operator: ZERO_KEY,
2939
+ operatorFeeBps: 0,
2940
+ arbitrator: ZERO_KEY
2941
+ };
2942
+ }
2943
+ var EscrowAccountDecodeError = class extends Error {
2944
+ constructor(reason, dataLength, version, field2, detail) {
2945
+ const at = [
2946
+ `${String(dataLength)} bytes`,
2947
+ ...version === null ? [] : [`version ${String(version)}`],
2948
+ ...field2 === null ? [] : [`field ${field2}`]
2949
+ ].join(", ");
2950
+ super(`${reason}: ${at}: ${detail}`);
2951
+ __publicField(this, "reason");
2952
+ __publicField(this, "dataLength");
2953
+ __publicField(this, "version");
2954
+ __publicField(this, "field");
2955
+ this.name = "EscrowAccountDecodeError";
2956
+ this.reason = reason;
2957
+ this.dataLength = dataLength;
2958
+ this.version = version;
2959
+ this.field = field2;
2893
2960
  }
2894
2961
  };
2895
- var AccountReader = class {
2896
- constructor(data) {
2897
- __publicField(this, "data", data);
2898
- __publicField(this, "at", 0);
2962
+ var Walk = class {
2963
+ constructor(data, version) {
2964
+ __publicField(this, "at", 8);
2965
+ __publicField(this, "values", /* @__PURE__ */ new Map());
2966
+ __publicField(this, "utf8", new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }));
2967
+ __publicField(this, "data");
2968
+ __publicField(this, "version");
2969
+ this.data = data;
2970
+ this.version = version;
2899
2971
  }
2900
- take(n) {
2972
+ fields(list) {
2973
+ for (const { name, kind } of list) this.values.set(name, this.read(name, kind));
2974
+ }
2975
+ refuse(field2, detail) {
2976
+ return new EscrowAccountDecodeError("layout", this.data.length, this.version, field2, detail);
2977
+ }
2978
+ take(field2, n) {
2901
2979
  if (this.at + n > this.data.length) {
2902
- throw new AccountProblem("layout", "a field reads past the content");
2980
+ throw this.refuse(
2981
+ field2,
2982
+ `${String(n)} bytes at offset ${String(this.at)} run past the account`
2983
+ );
2903
2984
  }
2904
2985
  const bytes = this.data.subarray(this.at, this.at + n);
2905
2986
  this.at += n;
2906
2987
  return bytes;
2907
2988
  }
2908
- view(n) {
2909
- const bytes = this.take(n);
2989
+ view(field2, n) {
2990
+ const bytes = this.take(field2, n);
2910
2991
  return new DataView(bytes.buffer, bytes.byteOffset, n);
2911
2992
  }
2912
- skip(n) {
2913
- this.take(n);
2914
- }
2915
- scalar(kind) {
2916
- if (kind === "pubkey") return import_bs585.default.encode(this.take(32));
2917
- if (kind === "string") {
2918
- const length = this.view(4).getUint32(0, true);
2919
- try {
2920
- return new TextDecoder("utf-8", { fatal: true }).decode(this.take(length));
2921
- } catch (err) {
2922
- if (err instanceof AccountProblem) throw err;
2923
- throw new AccountProblem("layout", "a string field is not UTF-8");
2924
- }
2925
- }
2926
- const value = this.view(8).getBigInt64(0, true);
2927
- if (value > BigInt(Number.MAX_SAFE_INTEGER) || value < BigInt(Number.MIN_SAFE_INTEGER)) {
2928
- throw new AccountProblem("layout", "an i64 field is outside the safe integer range");
2929
- }
2930
- return Number(value);
2993
+ optionTag(field2) {
2994
+ const tag = this.view(field2, 1).getUint8(0);
2995
+ if (tag > 1) throw this.refuse(field2, `option tag ${String(tag)} is neither 0 nor 1`);
2996
+ return tag === 1;
2931
2997
  }
2932
- read(kind) {
2998
+ read(field2, kind) {
2933
2999
  switch (kind) {
2934
3000
  case "u8":
2935
- return this.view(1).getUint8(0);
3001
+ return this.view(field2, 1).getUint8(0);
2936
3002
  case "u16":
2937
- return this.view(2).getUint16(0, true);
3003
+ return this.view(field2, 2).getUint16(0, true);
3004
+ case "u32":
3005
+ return this.view(field2, 4).getUint32(0, true);
2938
3006
  case "u64":
2939
- return this.view(8).getBigUint64(0, true);
2940
- case "pubkey":
2941
- case "string":
3007
+ return this.view(field2, 8).getBigUint64(0, true);
2942
3008
  case "i64":
2943
- return this.scalar(kind);
2944
- case "enum": {
2945
- const index = this.view(1).getUint8(0);
2946
- const variant = STATE_VARIANTS[index];
2947
- if (variant === void 0) {
2948
- throw new AccountProblem("layout", `state ${String(index)} is no EscrowState variant`);
3009
+ return this.view(field2, 8).getBigInt64(0, true);
3010
+ case "pubkey":
3011
+ return import_bs587.default.encode(this.take(field2, 32));
3012
+ case "bytes32":
3013
+ return Array.from(this.take(field2, 32), (b) => b.toString(16).padStart(2, "0")).join("");
3014
+ case "string": {
3015
+ const length = this.view(field2, 4).getUint32(0, true);
3016
+ const bytes = this.take(field2, length);
3017
+ try {
3018
+ return this.utf8.decode(bytes);
3019
+ } catch {
3020
+ throw this.refuse(field2, "the string is not valid UTF-8");
2949
3021
  }
2950
- return variant;
2951
3022
  }
2952
3023
  case "option<pubkey>":
3024
+ return this.optionTag(field2) ? this.read(field2, "pubkey") : null;
2953
3025
  case "option<string>":
2954
- case "option<i64>": {
2955
- const tag = this.view(1).getUint8(0);
2956
- if (tag === 0) return null;
2957
- if (tag !== 1) throw new AccountProblem("layout", `an option tag is ${String(tag)}`);
2958
- return this.scalar(
2959
- kind === "option<pubkey>" ? "pubkey" : kind === "option<string>" ? "string" : "i64"
2960
- );
3026
+ return this.optionTag(field2) ? this.read(field2, "string") : null;
3027
+ case "option<i64>":
3028
+ return this.optionTag(field2) ? this.read(field2, "i64") : null;
3029
+ case "state": {
3030
+ const byte = this.view(field2, 1).getUint8(0);
3031
+ const state = ESCROW_ACCOUNT_STATES[byte];
3032
+ if (state === void 0) throw this.refuse(field2, `state byte ${String(byte)}`);
3033
+ return state;
3034
+ }
3035
+ case "settlement_mode": {
3036
+ const byte = this.view(field2, 1).getUint8(0);
3037
+ if (byte === SETTLEMENT_MODE_BYTES.release) return "release";
3038
+ if (byte === SETTLEMENT_MODE_BYTES.refund) return "refund";
3039
+ throw this.refuse(field2, `settlement mode byte ${String(byte)}`);
2961
3040
  }
2962
3041
  }
2963
3042
  }
3043
+ value(name) {
3044
+ if (!this.values.has(name)) throw new Error(`EscrowAccount field ${name} was not read`);
3045
+ return this.values.get(name) ?? null;
3046
+ }
3047
+ num(name) {
3048
+ const v = this.value(name);
3049
+ if (typeof v !== "number") throw new Error(`EscrowAccount field ${name} is not a number`);
3050
+ return v;
3051
+ }
3052
+ big(name) {
3053
+ const v = this.value(name);
3054
+ if (typeof v !== "bigint")
3055
+ throw new Error(`EscrowAccount field ${name} is not a 64-bit integer`);
3056
+ return v;
3057
+ }
3058
+ str(name) {
3059
+ const v = this.value(name);
3060
+ if (typeof v !== "string") throw new Error(`EscrowAccount field ${name} is not a string`);
3061
+ return v;
3062
+ }
3063
+ optStr(name) {
3064
+ return this.value(name) === null ? null : this.str(name);
3065
+ }
3066
+ optBig(name) {
3067
+ return this.value(name) === null ? null : this.big(name);
3068
+ }
3069
+ state() {
3070
+ const v = this.str("state");
3071
+ const state = ESCROW_ACCOUNT_STATES.find((s) => s === v);
3072
+ if (state === void 0) throw new Error(`EscrowAccount state ${v} is not a variant`);
3073
+ return state;
3074
+ }
3075
+ settlementMode() {
3076
+ const v = this.str("settlement_mode");
3077
+ if (v !== "release" && v !== "refund") {
3078
+ throw new Error(`EscrowAccount settlement mode ${v} is not a variant`);
3079
+ }
3080
+ return v;
3081
+ }
2964
3082
  };
2965
- function decodeAccount(data) {
2966
- if (data.length < ESCROW_ACCOUNT_DISCRIMINATOR.length || ESCROW_ACCOUNT_DISCRIMINATOR.some((byte, i) => data[i] !== byte)) {
2967
- throw new AccountProblem("discriminator", "its discriminator is not EscrowAccount's");
3083
+ function isReadableVersion(byte) {
3084
+ return ESCROW_READABLE_VERSIONS.includes(byte);
3085
+ }
3086
+ function decodeEscrowAccount(data, opts) {
3087
+ const length = data.length;
3088
+ if (length < 8 || ESCROW_ACCOUNT_DISCRIMINATOR.some((byte, i) => data[i] !== byte)) {
3089
+ throw new EscrowAccountDecodeError(
3090
+ "discriminator",
3091
+ length,
3092
+ null,
3093
+ null,
3094
+ "not the EscrowAccount discriminator"
3095
+ );
2968
3096
  }
2969
- const version = data[ESCROW_ACCOUNT_DISCRIMINATOR.length];
2970
- if (version !== void 0 && version !== CURRENT_ACCOUNT_VERSION) {
2971
- throw new AccountProblem(
3097
+ if (PRE_VERSION_ESCROW_ACCOUNT_SIZES.includes(length)) {
3098
+ throw new EscrowAccountDecodeError(
3099
+ "pre-version",
3100
+ length,
3101
+ null,
3102
+ null,
3103
+ "a layout that predates the version byte"
3104
+ );
3105
+ }
3106
+ const versionByte = data[8];
3107
+ if (versionByte === void 0) {
3108
+ throw new EscrowAccountDecodeError("size", length, null, null, "no version byte");
3109
+ }
3110
+ if (!isReadableVersion(versionByte)) {
3111
+ throw new EscrowAccountDecodeError(
2972
3112
  "version",
2973
- `its version is ${String(version)}; this reader reads version ${String(CURRENT_ACCOUNT_VERSION)}`
3113
+ length,
3114
+ versionByte,
3115
+ null,
3116
+ `not a readable version (${ESCROW_READABLE_VERSIONS.join(", ")})`
2974
3117
  );
2975
3118
  }
2976
- if (data.length !== ESCROW_ACCOUNT_SIZE) {
3119
+ const allocation = ESCROW_ACCOUNT_ALLOCATIONS[versionByte];
3120
+ if (length !== allocation) {
3121
+ throw new EscrowAccountDecodeError(
3122
+ "size",
3123
+ length,
3124
+ versionByte,
3125
+ null,
3126
+ `version ${String(versionByte)} is allocated ${String(allocation)} bytes`
3127
+ );
3128
+ }
3129
+ const walk = new Walk(data, versionByte);
3130
+ walk.fields(ESCROW_ACCOUNT_V1_FIELDS);
3131
+ if (versionByte === 2) walk.fields(ESCROW_TERMS_FIELDS);
3132
+ const buyer = walk.str("buyer");
3133
+ const terms = versionByte === 1 ? v1DefaultTerms(buyer, opts.v1ReviewWindowSeconds) : {
3134
+ settlementMode: walk.settlementMode(),
3135
+ reviewWindowSeconds: walk.num("review_window_seconds"),
3136
+ evaluator: walk.str("evaluator"),
3137
+ payoutNetwork: walk.str("payout_network"),
3138
+ operator: walk.str("operator"),
3139
+ operatorFeeBps: walk.num("operator_fee_bps"),
3140
+ arbitrator: walk.str("arbitrator")
3141
+ };
3142
+ return {
3143
+ version: versionByte,
3144
+ buyer,
3145
+ assignedWorker: walk.optStr("assigned_worker"),
3146
+ taskId: walk.str("task_id"),
3147
+ amountUsdc: walk.big("amount_usdc"),
3148
+ feeBps: walk.num("fee_bps"),
3149
+ deadline: walk.big("deadline"),
3150
+ specHash: walk.str("spec_hash"),
3151
+ deliverableHash: walk.optStr("deliverable_hash"),
3152
+ proofUri: walk.optStr("proof_uri"),
3153
+ state: walk.state(),
3154
+ createdAt: walk.big("created_at"),
3155
+ updatedAt: walk.big("updated_at"),
3156
+ submittedAt: walk.optBig("submitted_at"),
3157
+ minAmount: walk.big("min_amount"),
3158
+ bump: walk.num("bump"),
3159
+ marketplaceId: walk.optStr("marketplace_id"),
3160
+ referrerWallet: walk.optStr("referrer_wallet"),
3161
+ referrerBps: walk.num("referrer_bps"),
3162
+ terms
3163
+ };
3164
+ }
3165
+ var DEFAULT_JOB_REVIEW_WINDOWS = [
3166
+ ONCHAIN_TIMEOUT_SECONDS2,
3167
+ E2E_SHORT_TIMEOUT_SECONDS
3168
+ ];
3169
+ var TERM_KEYS = [
3170
+ ["settlement_mode", "settlementMode"],
3171
+ ["review_window_seconds", "reviewWindowSeconds"],
3172
+ ["evaluator", "evaluator"],
3173
+ ["payout_network", "payoutNetwork"],
3174
+ ["operator", "operator"],
3175
+ ["operator_fee_bps", "operatorFeeBps"],
3176
+ ["arbitrator", "arbitrator"]
3177
+ ];
3178
+ function nonDefaultJobTerms(account) {
3179
+ if (account.version === 1) return [];
3180
+ const { terms } = account;
3181
+ const window = DEFAULT_JOB_REVIEW_WINDOWS.includes(terms.reviewWindowSeconds) ? terms.reviewWindowSeconds : ONCHAIN_TIMEOUT_SECONDS2;
3182
+ const expected = v1DefaultTerms(account.buyer, window);
3183
+ const found = TERM_KEYS.filter(([, key]) => terms[key] !== expected[key]).map(([name]) => name);
3184
+ return account.marketplaceId === null ? found : [...found, "marketplace_id"];
3185
+ }
3186
+ var ChainReadError = class extends EscroError {
3187
+ constructor(code, message, options = {}) {
3188
+ super(message, code, void 0, "cause" in options ? { cause: options.cause } : void 0);
3189
+ __publicField(this, "reason");
3190
+ this.name = "ChainReadError";
3191
+ this.reason = options.reason;
3192
+ }
3193
+ };
3194
+ var ARCHIVAL_RPC_NOTE = "A settled escrow is closed on chain and survives only in transaction history; if it is older than this RPC's history, read it through an archival RPC.";
3195
+ var CHAIN_READ_MAX_TRANSACTIONS = 50;
3196
+ var CHAIN_READ_MAX_SIGNATURE_PAGES = 5;
3197
+ var SIGNATURE_PAGE = 1e3;
3198
+ var FIELD_KINDS = [
3199
+ "pubkey",
3200
+ "u8",
3201
+ "u16",
3202
+ "u64",
3203
+ "i64",
3204
+ "string",
3205
+ "option<pubkey>",
3206
+ "option<string>",
3207
+ "option<i64>"
3208
+ ];
3209
+ function fieldKind(kind) {
3210
+ if (kind === "state") return "enum";
3211
+ const found = FIELD_KINDS.find((k) => k === kind);
3212
+ if (found === void 0) throw new Error(`no version-1 EscrowAccount field is of kind ${kind}`);
3213
+ return found;
3214
+ }
3215
+ var ESCROW_ACCOUNT_LAYOUT = ESCROW_ACCOUNT_V1_FIELDS.map(({ name, kind }) => ({ name, kind: fieldKind(kind) }));
3216
+ var ESCROW_ACCOUNT_SIZE = ESCROW_ACCOUNT_ALLOCATIONS[1];
3217
+ var STATE_OF = {
3218
+ Created: EscrowState.CREATED,
3219
+ Funded: EscrowState.FUNDED,
3220
+ InProgress: EscrowState.IN_PROGRESS,
3221
+ Submitted: EscrowState.SUBMITTED,
3222
+ Completed: EscrowState.COMPLETED,
3223
+ Disputed: EscrowState.DISPUTED,
3224
+ Refunded: EscrowState.REFUNDED
3225
+ };
3226
+ var MAX_TASK_ID_BYTES = 32;
3227
+ var AccountProblem = class extends Error {
3228
+ constructor(reason, detail) {
3229
+ super(detail);
3230
+ __publicField(this, "reason", reason);
3231
+ __publicField(this, "detail", detail);
3232
+ }
3233
+ };
3234
+ var REASON_OF = {
3235
+ discriminator: "discriminator",
3236
+ "pre-version": "version",
3237
+ version: "version",
3238
+ size: "layout",
3239
+ layout: "layout"
3240
+ };
3241
+ function safeInteger(name, value) {
3242
+ if (value > BigInt(Number.MAX_SAFE_INTEGER) || value < BigInt(Number.MIN_SAFE_INTEGER)) {
3243
+ throw new AccountProblem("layout", `${name} is outside the safe integer range`);
3244
+ }
3245
+ return Number(value);
3246
+ }
3247
+ var camelCase = (name) => name.replace(/_([a-z])/g, (_match, letter) => letter.toUpperCase());
3248
+ function recordOf(account) {
3249
+ const decoded2 = new Map(Object.entries(account));
3250
+ const record = {};
3251
+ for (const { name, kind } of ESCROW_ACCOUNT_V1_FIELDS) {
3252
+ const value = decoded2.get(camelCase(name));
3253
+ if (typeof value === "bigint" && (kind === "i64" || kind === "option<i64>")) {
3254
+ record[name] = safeInteger(name, value);
3255
+ } else if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "bigint") {
3256
+ record[name] = value;
3257
+ } else {
3258
+ throw new Error(`the decoded EscrowAccount carries no ${name}`);
3259
+ }
3260
+ }
3261
+ return record;
3262
+ }
3263
+ function decodeAccount(data) {
3264
+ let account;
3265
+ try {
3266
+ account = decodeEscrowAccount(data, { v1ReviewWindowSeconds: ONCHAIN_TIMEOUT_SECONDS });
3267
+ } catch (err) {
3268
+ if (!(err instanceof EscrowAccountDecodeError)) throw err;
3269
+ throw new AccountProblem(REASON_OF[err.reason], err.message);
3270
+ }
3271
+ const record = recordOf(account);
3272
+ const terms = nonDefaultJobTerms(account);
3273
+ if (terms.length > 0) {
2977
3274
  throw new AccountProblem(
2978
- "layout",
2979
- `it is ${String(data.length)} bytes; an EscrowAccount is ${String(ESCROW_ACCOUNT_SIZE)}`
3275
+ "version",
3276
+ `version ${String(account.version)} with terms other than the default job's (${terms.join(", ")}); this reader reads a version-2 escrow only on the default job's terms`
2980
3277
  );
2981
3278
  }
2982
- const reader = new AccountReader(data);
2983
- reader.skip(ESCROW_ACCOUNT_DISCRIMINATOR.length);
2984
- const decoded2 = {};
2985
- for (const field2 of ESCROW_ACCOUNT_LAYOUT) decoded2[field2.name] = reader.read(field2.kind);
2986
- return decoded2;
3279
+ return record;
2987
3280
  }
2988
3281
  function invalidInput(message) {
2989
3282
  return new ChainReadError("INVALID_INPUT", message);
@@ -3079,36 +3372,48 @@ function figures(base) {
3079
3372
  const feeMicro = escrowFee(base.amountMicro, base.feeBps);
3080
3373
  return { ...base, feeMicro, depositMicro: base.amountMicro + feeMicro };
3081
3374
  }
3082
- function readAccount(address, owner, data, programId, cluster) {
3083
- const at = address.toBase58();
3084
- const refuse5 = (problem) => new ChainReadError(
3375
+ function clusterProgramId(cluster) {
3376
+ const id = getProgramId(cluster);
3377
+ assertProgramIdNotPlaceholder(id, cluster);
3378
+ return new import_web34.PublicKey(id);
3379
+ }
3380
+ function refusedAt(at, problem) {
3381
+ return new ChainReadError(
3085
3382
  "CHAIN_ACCOUNT_INVALID",
3086
3383
  `The account at ${at} is not a current EscrowAccount: ${problem.detail}`,
3087
3384
  { reason: problem.reason }
3088
3385
  );
3386
+ }
3387
+ function ownedAccount(at, owner, data, programId) {
3089
3388
  if (!owner.equals(programId)) {
3090
- throw refuse5(
3389
+ throw refusedAt(
3390
+ at,
3091
3391
  new AccountProblem(
3092
3392
  "owner",
3093
3393
  `it is owned by ${owner.toBase58()}, not the program ${programId.toBase58()}`
3094
3394
  )
3095
3395
  );
3096
3396
  }
3097
- let decoded2;
3098
3397
  try {
3099
- decoded2 = decodeAccount(data);
3398
+ return decodeAccount(data);
3100
3399
  } catch (err) {
3101
- if (err instanceof AccountProblem) throw refuse5(err);
3400
+ if (err instanceof AccountProblem) throw refusedAt(at, err);
3102
3401
  throw err;
3103
3402
  }
3403
+ }
3404
+ function readAccount(address, owner, data, programId, cluster) {
3405
+ const at = address.toBase58();
3406
+ const decoded2 = ownedAccount(at, owner, data, programId);
3104
3407
  const buyer = stringOf(decoded2, "buyer");
3105
3408
  const taskId = stringOf(decoded2, "task_id");
3106
3409
  const derived = new TextEncoder().encode(taskId).length <= MAX_TASK_ID_BYTES ? deriveEscrowPda(programId, new import_web34.PublicKey(buyer), taskId) : null;
3107
3410
  if (!derived?.equals(address)) {
3108
- throw refuse5(new AccountProblem("pda", "its buyer and task id do not derive this address"));
3411
+ throw refusedAt(
3412
+ at,
3413
+ new AccountProblem("pda", "its buyer and task id do not derive this address")
3414
+ );
3109
3415
  }
3110
- const variant = stringOf(decoded2, "state");
3111
- const state = STATE_OF[variant];
3416
+ const state = STATE_OF[stringOf(decoded2, "state")];
3112
3417
  return {
3113
3418
  source: "account",
3114
3419
  cluster,
@@ -3246,6 +3551,13 @@ function readHistory(lifecycle, address, programId, cluster) {
3246
3551
  if (create?.name !== "EscrowCreated" || last === void 0) {
3247
3552
  throw new Error(`the lifecycle of ${address} does not open with EscrowCreated`);
3248
3553
  }
3554
+ if (isMarketStamped(create)) {
3555
+ throw new ChainReadError(
3556
+ "CHAIN_ACCOUNT_INVALID",
3557
+ `The escrow at ${address} was created in a market (its EscrowCreated carries a marketplace_id); this reader reads a closed escrow only without a market stamp`,
3558
+ { reason: "version" }
3559
+ );
3560
+ }
3249
3561
  let settlement;
3250
3562
  let state;
3251
3563
  const settled = last.event;
@@ -3313,9 +3625,8 @@ async function readEscrowFromChain(target, options) {
3313
3625
  if (!Number.isSafeInteger(maxTransactions) || maxTransactions < 1) {
3314
3626
  throw invalidInput("maxTransactions must be a positive integer");
3315
3627
  }
3316
- const id = getProgramId(options.cluster);
3317
- assertProgramIdNotPlaceholder(id, options.cluster);
3318
- const programId = new import_web34.PublicKey(id);
3628
+ const programId = clusterProgramId(options.cluster);
3629
+ const id = programId.toBase58();
3319
3630
  const address = resolveTarget(target, programId);
3320
3631
  const rpc = options.rpc;
3321
3632
  const account = await call(
@@ -4397,6 +4708,7 @@ var EscrowState2 = /* @__PURE__ */ ((EscrowState22) => {
4397
4708
  })(EscrowState2 || {});
4398
4709
  var MIN_ESCROW_AMOUNT = 5e6;
4399
4710
  var MAX_DISPUTE_REASON_BYTES = 200;
4711
+ var MAX_PROOF_URI_BYTES = 128;
4400
4712
  var ONCHAIN_REFUND_GRACE_SECONDS3 = 900;
4401
4713
  var ONCHAIN_TIMEOUT_SECONDS3 = 86400;
4402
4714
  var CLOCK_SKEW_SECONDS3 = 60;
@@ -4434,6 +4746,27 @@ var ESCROW_INSTRUCTIONS3 = {
4434
4746
  arbitration_release: spec3([118, 157, 141, 26, 104, 117, 94, 229], 4, "ARBITRATION_RELEASE"),
4435
4747
  arbitration_refund: spec3([255, 194, 84, 248, 185, 249, 120, 122], 4, "ARBITRATION_REFUND")
4436
4748
  };
4749
+ var NON_ESCROW_INSTRUCTIONS3 = {
4750
+ initialize_platform: Uint8Array.from([119, 201, 101, 45, 75, 122, 89, 3]),
4751
+ initialize_admin_config: Uint8Array.from([133, 214, 35, 2, 50, 232, 95, 164]),
4752
+ close_platform: Uint8Array.from([27, 145, 216, 122, 13, 15, 46, 201]),
4753
+ update_platform: Uint8Array.from([46, 78, 138, 189, 47, 163, 120, 85]),
4754
+ set_admin_authority: Uint8Array.from([72, 49, 37, 167, 149, 98, 49, 174]),
4755
+ migrate_escrow_v1_to_v2: Uint8Array.from([70, 76, 99, 21, 154, 50, 111, 221])
4756
+ };
4757
+ var RETIRED_INSTRUCTIONS3 = {
4758
+ claim_open_task: Uint8Array.from([31, 61, 16, 69, 194, 74, 72, 148])
4759
+ };
4760
+ var ANCHOR_IDL_INSTRUCTION_TAG3 = Uint8Array.from([
4761
+ 64,
4762
+ 244,
4763
+ 188,
4764
+ 120,
4765
+ 167,
4766
+ 233,
4767
+ 105,
4768
+ 10
4769
+ ]);
4437
4770
 
4438
4771
  // ../shared/dist/solana.js
4439
4772
  var import_web310 = require("@solana/web3.js");
@@ -4467,8 +4800,17 @@ function refinePublicKey(value, ctx) {
4467
4800
  ctx.addIssue({ code: import_zod.z.ZodIssueCode.custom, message: PUBLIC_KEY_ISSUE });
4468
4801
  }
4469
4802
  var listEscrowsSchema = {
4470
- state: import_zod.z.nativeEnum(EscrowState2).optional().describe("Return only escrows in this lifecycle state"),
4471
- assignedTo: import_zod.z.string().superRefine(refinePublicKey).optional().describe("Base-58 wallet; return only escrows assigned to this worker"),
4803
+ // Two enum instances, not one shared: a schema reused inside one tool's input is advertised as a
4804
+ // `$ref`, which some MCP clients do not resolve.
4805
+ state: import_zod.z.union([import_zod.z.nativeEnum(EscrowState2), import_zod.z.array(import_zod.z.nativeEnum(EscrowState2)).min(1)]).optional().describe(
4806
+ "Return only escrows in this state, or in any state of a non-empty list; CREATED is never served"
4807
+ ),
4808
+ worker: import_zod.z.string().superRefine(refinePublicKey).optional().describe(
4809
+ "Base-58 wallet; return every escrow assigned to this worker, in any served state. 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."
4810
+ ),
4811
+ assignedTo: import_zod.z.string().superRefine(refinePublicKey).optional().describe(
4812
+ "Base-58 wallet; the legacy form of worker: return only this worker's escrows in FUNDED, IN_PROGRESS or SUBMITTED. 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."
4813
+ ),
4472
4814
  limit: import_zod.z.number().int().positive().max(100).optional().describe("Page size, 1-100; the API returns 20 when omitted"),
4473
4815
  offset: import_zod.z.number().int().nonnegative().optional().describe("Number of escrows to skip"),
4474
4816
  mine: import_zod.z.boolean().optional().describe("true: only escrows this server's wallet created (it is the buyer)")
@@ -4508,9 +4850,9 @@ var claimTaskSchema = {
4508
4850
  };
4509
4851
  var submitDeliverableSchema = {
4510
4852
  address: import_zod.z.string().superRefine(refinePublicKey).describe("Base-58 escrow PDA address"),
4511
- contentHash: import_zod.z.string().describe("SHA-256 hex digest of the deliverable"),
4853
+ contentHash: import_zod.z.string().describe("SHA-256 hex digest of the deliverable; at most 64 bytes, which a hex digest fills"),
4512
4854
  proofUri: import_zod.z.string().optional().describe(
4513
- "Optional URL (ipfs://, ar:// or https://) where the buyer can retrieve the deliverable"
4855
+ `Optional http(s), ipfs or ar URL, at most ${String(MAX_PROOF_URI_BYTES)} UTF-8 bytes, where the buyer can retrieve the deliverable`
4514
4856
  )
4515
4857
  };
4516
4858
  var releasePaymentSchema = {
@@ -4556,6 +4898,7 @@ function makeReadHandlers(api, options = {}) {
4556
4898
  const result = await api.listEscrows({
4557
4899
  ...maker !== void 0 && { maker },
4558
4900
  ...args.state !== void 0 && { state: args.state },
4901
+ ...args.worker !== void 0 && { worker: args.worker },
4559
4902
  ...args.assignedTo !== void 0 && { assignedTo: args.assignedTo },
4560
4903
  ...args.limit !== void 0 && { limit: args.limit },
4561
4904
  ...args.offset !== void 0 && { offset: args.offset }