@oobe-protocol-labs/synapse-sap-sdk 0.12.8 → 0.13.0

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.
Files changed (60) hide show
  1. package/dist/cjs/modules/base.js +61 -0
  2. package/dist/cjs/modules/base.js.map +1 -1
  3. package/dist/cjs/modules/escrow-v2.js +250 -0
  4. package/dist/cjs/modules/escrow-v2.js.map +1 -1
  5. package/dist/cjs/modules/escrow.js +36 -0
  6. package/dist/cjs/modules/escrow.js.map +1 -1
  7. package/dist/cjs/modules/staking.js +35 -0
  8. package/dist/cjs/modules/staking.js.map +1 -1
  9. package/dist/cjs/modules/tools.js +26 -0
  10. package/dist/cjs/modules/tools.js.map +1 -1
  11. package/dist/cjs/modules/vault.js +17 -0
  12. package/dist/cjs/modules/vault.js.map +1 -1
  13. package/dist/cjs/utils/anchor-errors.js +453 -0
  14. package/dist/cjs/utils/anchor-errors.js.map +1 -0
  15. package/dist/cjs/utils/index.js +12 -1
  16. package/dist/cjs/utils/index.js.map +1 -1
  17. package/dist/cjs/utils/volume-curve.js +117 -0
  18. package/dist/cjs/utils/volume-curve.js.map +1 -0
  19. package/dist/esm/modules/base.js +61 -0
  20. package/dist/esm/modules/base.js.map +1 -1
  21. package/dist/esm/modules/escrow-v2.js +250 -0
  22. package/dist/esm/modules/escrow-v2.js.map +1 -1
  23. package/dist/esm/modules/escrow.js +36 -0
  24. package/dist/esm/modules/escrow.js.map +1 -1
  25. package/dist/esm/modules/staking.js +35 -0
  26. package/dist/esm/modules/staking.js.map +1 -1
  27. package/dist/esm/modules/tools.js +26 -0
  28. package/dist/esm/modules/tools.js.map +1 -1
  29. package/dist/esm/modules/vault.js +17 -0
  30. package/dist/esm/modules/vault.js.map +1 -1
  31. package/dist/esm/utils/anchor-errors.js +447 -0
  32. package/dist/esm/utils/anchor-errors.js.map +1 -0
  33. package/dist/esm/utils/index.js +4 -0
  34. package/dist/esm/utils/index.js.map +1 -1
  35. package/dist/esm/utils/volume-curve.js +114 -0
  36. package/dist/esm/utils/volume-curve.js.map +1 -0
  37. package/dist/types/modules/base.d.ts +35 -0
  38. package/dist/types/modules/base.d.ts.map +1 -1
  39. package/dist/types/modules/escrow-v2.d.ts +98 -1
  40. package/dist/types/modules/escrow-v2.d.ts.map +1 -1
  41. package/dist/types/modules/escrow.d.ts.map +1 -1
  42. package/dist/types/modules/staking.d.ts.map +1 -1
  43. package/dist/types/modules/tools.d.ts.map +1 -1
  44. package/dist/types/modules/vault.d.ts.map +1 -1
  45. package/dist/types/utils/anchor-errors.d.ts +61 -0
  46. package/dist/types/utils/anchor-errors.d.ts.map +1 -0
  47. package/dist/types/utils/index.d.ts +3 -0
  48. package/dist/types/utils/index.d.ts.map +1 -1
  49. package/dist/types/utils/volume-curve.d.ts +60 -0
  50. package/dist/types/utils/volume-curve.d.ts.map +1 -0
  51. package/package.json +1 -1
  52. package/src/modules/base.ts +89 -0
  53. package/src/modules/escrow-v2.ts +327 -1
  54. package/src/modules/escrow.ts +56 -0
  55. package/src/modules/staking.ts +66 -0
  56. package/src/modules/tools.ts +43 -0
  57. package/src/modules/vault.ts +25 -0
  58. package/src/utils/anchor-errors.ts +461 -0
  59. package/src/utils/index.ts +16 -0
  60. package/src/utils/volume-curve.ts +131 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchor-errors.js","sourceRoot":"","sources":["../../../src/utils/anchor-errors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAoWH,8CAwBC;AAgED,wCAMC;AA/bY,QAAA,UAAU,GAA4C,MAAM,CAAC,MAAM,CAAC;IAC/E,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,SAAS,EAAE;IACzD,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,oBAAoB,EAAE,GAAG,EAAE,UAAU,EAAE;IACjE,IAAI,EAAE,EAAE,IAAI,EAAE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AC,CAAC,CAAC;IACrD,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,kBAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACvD,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAc,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC;IAC9F,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,QAAQ,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC;IACvD,MAAM,IAAI,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,IAAc,EAAE,IAAI,CAAC,CAAC;AAChE,CAAC"}
@@ -15,7 +15,8 @@
15
15
  * ```
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getX402DirectPayments = exports.parseX402Headers = exports.SapMerchantValidator = exports.MissingEscrowAtaError = exports.toAccountMetas = exports.attachSplAccounts = exports.validateEscrowState = exports.computeBatchSettleCu = exports.DEFAULT_BATCH_SETTLE_COMPUTE_UNITS = exports.DEFAULT_SETTLE_COMPUTE_UNITS = exports.DEFAULT_SETTLE_PRIORITY_FEE = exports.FAST_BATCH_SETTLE_OPTIONS = exports.FAST_SETTLE_OPTIONS = exports.buildRpcOptions = exports.buildPriorityFeeIxs = exports.validateOrThrow = exports.createCallArgsSchema = exports.createRegisterAgentSchema = exports.createPreparePaymentSchema = exports.createAgentManifestSchema = exports.createToolManifestEntrySchema = exports.createHealthCheckSchema = exports.createEndpointDescriptorSchema = exports.createEnvSchema = exports.extractAnchorErrorCode = exports.classifyAnchorError = exports.findATA = exports.createDualConnection = exports.getFallbackRpcUrl = exports.getRpcUrl = exports.validateAgentEndpoints = exports.validateHealthCheck = exports.validateEndpointDescriptor = exports.validateEndpoint = exports.isKnownNetwork = exports.getNetworkClusterName = exports.getNetworkGenesisHash = exports.isNetworkEquivalent = exports.normalizeNetworkId = exports.serializeValue = exports.serializeAccount = exports.assert = exports.computeBatchRoot = exports.hashToArray = exports.sha256 = void 0;
18
+ exports.throwPredicted = exports.SapPreflightError = exports.decodeAnchorError = exports.SAP_ERROR_BY_NAME = exports.SAP_ERRORS = exports.getX402DirectPayments = exports.parseX402Headers = exports.SapMerchantValidator = exports.MissingEscrowAtaError = exports.toAccountMetas = exports.attachSplAccounts = exports.validateEscrowState = exports.computeBatchSettleCu = exports.DEFAULT_BATCH_SETTLE_COMPUTE_UNITS = exports.DEFAULT_SETTLE_COMPUTE_UNITS = exports.DEFAULT_SETTLE_PRIORITY_FEE = exports.FAST_BATCH_SETTLE_OPTIONS = exports.FAST_SETTLE_OPTIONS = exports.buildRpcOptions = exports.buildPriorityFeeIxs = exports.validateOrThrow = exports.createCallArgsSchema = exports.createRegisterAgentSchema = exports.createPreparePaymentSchema = exports.createAgentManifestSchema = exports.createToolManifestEntrySchema = exports.createHealthCheckSchema = exports.createEndpointDescriptorSchema = exports.createEnvSchema = exports.extractAnchorErrorCode = exports.classifyAnchorError = exports.findATA = exports.createDualConnection = exports.getFallbackRpcUrl = exports.getRpcUrl = exports.validateAgentEndpoints = exports.validateHealthCheck = exports.validateEndpointDescriptor = exports.validateEndpoint = exports.isKnownNetwork = exports.getNetworkClusterName = exports.getNetworkGenesisHash = exports.isNetworkEquivalent = exports.normalizeNetworkId = exports.serializeValue = exports.serializeAccount = exports.assert = exports.computeBatchRoot = exports.hashToArray = exports.sha256 = void 0;
19
+ exports.calculateSettleAmount = void 0;
19
20
  var hash_1 = require("./hash");
20
21
  Object.defineProperty(exports, "sha256", { enumerable: true, get: function () { return hash_1.sha256; } });
21
22
  Object.defineProperty(exports, "hashToArray", { enumerable: true, get: function () { return hash_1.hashToArray; } });
@@ -75,4 +76,14 @@ Object.defineProperty(exports, "SapMerchantValidator", { enumerable: true, get:
75
76
  Object.defineProperty(exports, "parseX402Headers", { enumerable: true, get: function () { return merchant_validator_1.parseX402Headers; } });
76
77
  var x402_direct_1 = require("./x402-direct");
77
78
  Object.defineProperty(exports, "getX402DirectPayments", { enumerable: true, get: function () { return x402_direct_1.getX402DirectPayments; } });
79
+ // ── v0.13.0 Full SAP error table + preflight helpers ─
80
+ var anchor_errors_1 = require("./anchor-errors");
81
+ Object.defineProperty(exports, "SAP_ERRORS", { enumerable: true, get: function () { return anchor_errors_1.SAP_ERRORS; } });
82
+ Object.defineProperty(exports, "SAP_ERROR_BY_NAME", { enumerable: true, get: function () { return anchor_errors_1.SAP_ERROR_BY_NAME; } });
83
+ Object.defineProperty(exports, "decodeAnchorError", { enumerable: true, get: function () { return anchor_errors_1.decodeAnchorError; } });
84
+ Object.defineProperty(exports, "SapPreflightError", { enumerable: true, get: function () { return anchor_errors_1.SapPreflightError; } });
85
+ Object.defineProperty(exports, "throwPredicted", { enumerable: true, get: function () { return anchor_errors_1.throwPredicted; } });
86
+ // ── v0.13.0 Volume-curve mirror for client-side amount preview ──
87
+ var volume_curve_1 = require("./volume-curve");
88
+ Object.defineProperty(exports, "calculateSettleAmount", { enumerable: true, get: function () { return volume_curve_1.calculateSettleAmount; } });
78
89
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,+BAA+D;AAAtD,8FAAA,MAAM,OAAA;AAAE,mGAAA,WAAW,OAAA;AAAE,wGAAA,gBAAgB,OAAA;AAC9C,2CAAsC;AAA7B,oGAAA,MAAM,OAAA;AACf,iDAAmE;AAA1D,iHAAA,gBAAgB,OAAA;AAAE,+GAAA,cAAc,OAAA;AAEzC,uDAAuD;AACvD,2DAM8B;AAL5B,wHAAA,kBAAkB,OAAA;AAClB,yHAAA,mBAAmB,OAAA;AACnB,2HAAA,qBAAqB,OAAA;AACrB,2HAAA,qBAAqB,OAAA;AACrB,oHAAA,cAAc,OAAA;AAGhB,2DAK8B;AAJ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qBAAqB,OAAA;AAOvB,2DAG8B;AAF5B,0HAAA,oBAAoB,OAAA;AACpB,sHAAA,gBAAgB,OAAA;AAOlB,6CAAsD;AAA7C,oHAAA,qBAAqB,OAAA;AAO9B,yDAAyD;AACzD,iDAMyB;AALvB,2GAAA,UAAU,OAAA;AACV,kHAAA,iBAAiB,OAAA;AACjB,kHAAA,iBAAiB,OAAA;AACjB,kHAAA,iBAAiB,OAAA;AACjB,+GAAA,cAAc,OAAA;AAOhB,oEAAoE;AACpE,+CAAuD;AAA9C,qHAAA,qBAAqB,OAAA"}
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ /**
3
+ * @module volume-curve
4
+ * @description Client-side mirror of the on-chain `calculate_settle_amount`
5
+ * function from `programs/synapse-agent-sap/src/instructions/escrow_v2.rs`.
6
+ *
7
+ * Used by {@link EscrowV2Module.settle} to pre-compute the settlement
8
+ * `amount` so it can chain `createPendingSettlement` in the same transaction
9
+ * as `settleCallsV2` (DisputeWindow flow). Keeping the math in one place
10
+ * here ensures the SDK stays byte-for-byte aligned with the program; if the
11
+ * on-chain curve algorithm ever changes, this file is the single source of
12
+ * truth on the client.
13
+ *
14
+ * @category Utilities
15
+ * @since v0.13.0
16
+ * @packageDocumentation
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.calculateSettleAmount = calculateSettleAmount;
20
+ const anchor_1 = require("@coral-xyz/anchor");
21
+ const U64_MAX = new anchor_1.BN("18446744073709551615");
22
+ function checkedMul(a, b) {
23
+ const r = a.mul(b);
24
+ if (r.gt(U64_MAX)) {
25
+ throw new Error(`volume-curve: u64 overflow on multiply (${a.toString()} * ${b.toString()})`);
26
+ }
27
+ return r;
28
+ }
29
+ function checkedAdd(a, b) {
30
+ const r = a.add(b);
31
+ if (r.gt(U64_MAX)) {
32
+ throw new Error(`volume-curve: u64 overflow on add (${a.toString()} + ${b.toString()})`);
33
+ }
34
+ return r;
35
+ }
36
+ /**
37
+ * @function calculateSettleAmount
38
+ * @description Compute the lamport (or token base-unit) amount the on-chain
39
+ * `settle_calls_v2` handler will charge for `calls` calls, given the escrow's
40
+ * `pricePerCall`, `volumeCurve`, and the current settled+pending counter.
41
+ *
42
+ * Mirrors the exact algorithm of `calculate_settle_amount` in
43
+ * `escrow_v2.rs` (v0.7+):
44
+ *
45
+ * ```rust
46
+ * if curve.is_empty() { calls * base_price } else { walk-the-curve }
47
+ * ```
48
+ *
49
+ * Walks the curve from `cursor = totalCallsBefore` and at each cursor
50
+ * position picks the breakpoint price whose `afterCalls` threshold the
51
+ * cursor has passed. Calls are charged at the active price up to the next
52
+ * threshold, then the cursor advances and the loop repeats until all
53
+ * `calls` are accounted for.
54
+ *
55
+ * @param basePrice - Escrow's `pricePerCall` (BN, u64 lamports/base-units).
56
+ * @param curve - The escrow's `volumeCurve` array (may be empty).
57
+ * @param totalCallsBefore - `escrow.totalCallsSettled + escrow.pendingCalls`
58
+ * AT THE MOMENT `settleCallsV2` runs on-chain.
59
+ * @param calls - Number of calls being settled in this batch.
60
+ * @returns The amount the on-chain handler will compute (BN, u64).
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * import { calculateSettleAmount } from "@oobe-protocol-labs/synapse-sap-sdk";
65
+ *
66
+ * const amount = calculateSettleAmount(
67
+ * escrow.pricePerCall,
68
+ * escrow.volumeCurve,
69
+ * escrow.totalCallsSettled.add(escrow.pendingCalls),
70
+ * new BN(5),
71
+ * );
72
+ * ```
73
+ *
74
+ * @since v0.13.0
75
+ */
76
+ function calculateSettleAmount(basePrice, curve, totalCallsBefore, calls) {
77
+ if (calls.isZero())
78
+ return new anchor_1.BN(0);
79
+ if (!curve || curve.length === 0) {
80
+ return checkedMul(calls, basePrice);
81
+ }
82
+ let amount = new anchor_1.BN(0);
83
+ let remaining = calls.clone();
84
+ let cursor = totalCallsBefore.clone();
85
+ while (remaining.gtn(0)) {
86
+ let currentPrice = basePrice;
87
+ let nextThreshold = null;
88
+ for (const bp of curve) {
89
+ const threshold = new anchor_1.BN(bp.afterCalls);
90
+ if (cursor.gte(threshold)) {
91
+ currentPrice = bp.pricePerCall;
92
+ }
93
+ else {
94
+ nextThreshold = threshold;
95
+ break;
96
+ }
97
+ }
98
+ let callsAtPrice;
99
+ if (nextThreshold) {
100
+ const room = nextThreshold.sub(cursor);
101
+ callsAtPrice = anchor_1.BN.min(remaining, room.isNeg() ? new anchor_1.BN(0) : room);
102
+ if (callsAtPrice.isZero()) {
103
+ // Defensive: shouldn't happen because cursor < nextThreshold by
104
+ // the `else` branch above, but guard anyway.
105
+ callsAtPrice = remaining;
106
+ }
107
+ }
108
+ else {
109
+ callsAtPrice = remaining;
110
+ }
111
+ amount = checkedAdd(amount, checkedMul(callsAtPrice, currentPrice));
112
+ remaining = remaining.sub(callsAtPrice);
113
+ cursor = cursor.add(callsAtPrice);
114
+ }
115
+ return amount;
116
+ }
117
+ //# sourceMappingURL=volume-curve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"volume-curve.js","sourceRoot":"","sources":["../../../src/utils/volume-curve.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;AAmEH,sDAgDC;AAjHD,8CAAuC;AAGvC,MAAM,OAAO,GAAG,IAAI,WAAE,CAAC,sBAAsB,CAAC,CAAC;AAE/C,SAAS,UAAU,CAAC,CAAK,EAAE,CAAK;IAC9B,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACnB,IAAI,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,2CAA2C,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,QAAQ,EAAE,GAAG,CAC7E,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,UAAU,CAAC,CAAK,EAAE,CAAK;IAC9B,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACnB,IAAI,CAA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AClB,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACvC,YAAY,GAAG,WAAE,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,WAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAClE,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC;gBAC1B,gEAAgE;gBAChE,6CAA6C;gBAC7C,YAAY,GAAG,SAAS,CAAC;YAC3B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,YAAY,GAAG,SAAS,CAAC;QAC3B,CAAC;QAED,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC;QACpE,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACxC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -10,6 +10,7 @@
10
10
  * @packageDocumentation
11
11
  */
12
12
  import { BN } from "@coral-xyz/anchor";
13
+ import { decodeAnchorError, SapPreflightError, throwPredicted, } from "../utils/anchor-errors";
13
14
  /**
14
15
  * @name BaseModule
15
16
  * @description Abstract base module inherited by every domain module in the SDK.
@@ -120,5 +121,65 @@ export class BaseModule {
120
121
  return value;
121
122
  return new BN(value.toString());
122
123
  }
124
+ // ── v0.13.0 preflight helpers ─────────────────────────
125
+ /**
126
+ * @name requireAccountExists
127
+ * @description Fetch a required account; throw a {@link SapPreflightError}
128
+ * with an actionable message if it does not exist.
129
+ * @typeParam T - Expected account type.
130
+ * @param accountName - Anchor account discriminator name.
131
+ * @param address - PDA to fetch.
132
+ * @param onMissing - `{ predicted, hint }` describing the on-chain rejection
133
+ * that would otherwise occur.
134
+ * @protected
135
+ * @since v0.13.0
136
+ */
137
+ async requireAccountExists(accountName, address, onMissing) {
138
+ const acc = await this.fetchAccountNullable(accountName, address);
139
+ if (acc == null) {
140
+ throwPredicted(onMissing.predicted, onMissing.hint ?? `${accountName} ${address.toBase58()} not found`);
141
+ }
142
+ return acc;
143
+ }
144
+ /**
145
+ * @name requireAccountAbsent
146
+ * @description Verify a PDA does not yet exist on-chain. Used before any
147
+ * `init` instruction to catch `account already in use` early.
148
+ * @protected
149
+ * @since v0.13.0
150
+ */
151
+ async requireAccountAbsent(accountName, address, hint) {
152
+ const acc = await this.provider.connection.getAccountInfo(address);
153
+ if (acc !== null) {
154
+ throw new SapPreflightError(`${accountName} ${address.toBase58()} already exists. ${hint}`, 0, "AccountAlreadyInUse", hint);
155
+ }
156
+ }
157
+ /**
158
+ * @name simulateOrThrow
159
+ * @description Run `simulate()` on a method builder. If the simulation
160
+ * reports a SAP program error, throw it as a {@link SapPreflightError}
161
+ * with the decoded name + friendly hint *before* the user pays fees.
162
+ * Returns the simulation logs on success for inspection.
163
+ * @protected
164
+ * @since v0.13.0
165
+ */
166
+ async simulateOrThrow(
167
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
+ builder, label) {
169
+ try {
170
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
171
+ const sim = await builder.simulate();
172
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
173
+ const logs = (sim?.raw ?? sim?.logs ?? []);
174
+ return logs;
175
+ }
176
+ catch (err) {
177
+ const decoded = decodeAnchorError(err);
178
+ if (decoded) {
179
+ throw new SapPreflightError(`[${label}] simulation failed: ${decoded.friendly}`, decoded.code, decoded.name, decoded.logs?.slice(0, 6).join(" | "));
180
+ }
181
+ throw err;
182
+ }
183
+ }
123
184
  }
124
185
  //# sourceMappingURL=base.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/modules/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO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I,KAAK,wBAAwB,OAAO,CAAC,QAAQ,EAAE,EACnD,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CACtC,CAAC;YACJ,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CACF"}
@@ -14,6 +14,8 @@ import { BaseModule } from "./base";
14
14
  import { deriveAgent, deriveAgentStats, deriveEscrowV2, derivePendingSettlement as derivePendingPda, deriveDispute as deriveDisputePda, deriveStake, deriveSettlementReceipt, } from "../pda";
15
15
  import { buildPriorityFeeIxs, buildRpcOptions, } from "../utils/priority-fee";
16
16
  import { isAcceptedPaymentToken, computeRequiredStakeLamports } from "../constants/payments";
17
+ import { throwPredicted } from "../utils/anchor-errors";
18
+ import { calculateSettleAmount } from "../utils/volume-curve";
17
19
  /**
18
20
  * @name EscrowV2Module
19
21
  * @description Manages V2 escrow accounts with settlement security modes,
@@ -140,6 +142,18 @@ export class EscrowV2Module extends BaseModule {
140
142
  async deposit(agentWallet, nonce, amount, splAccounts = []) {
141
143
  const [agentPda] = deriveAgent(agentWallet);
142
144
  const [escrowPda] = this.deriveEscrow(agentPda, undefined, nonce);
145
+ // v0.13.0 preflights — escrow exists, token shape matches, amount > 0
146
+ const escrow = await this.requireAccountExists("escrowAccountV2", escrowPda, { predicted: "NotAuthority", hint: "Escrow V2 PDA not found — call createEscrow first" });
147
+ const want = BigInt(this.bn(amount).toString());
148
+ if (want <= 0n)
149
+ throwPredicted("InsufficientEscrowBalance", "Deposit amount must be > 0");
150
+ const isSpl = escrow.tokenMint != null;
151
+ if (isSpl && splAccounts.length < 4) {
152
+ throwPredicted("SplTokenRequired", "Pass [depositorAta, escrowAta, tokenMint, tokenProgram]");
153
+ }
154
+ if (!isSpl && splAccounts.length > 0) {
155
+ throwPredicted("InvalidTokenAccount", "SOL escrow does not accept splAccounts");
156
+ }
143
157
  return this.methods
144
158
  .depositEscrowV2(this.bn(nonce), this.bn(amount))
145
159
  .accounts({
@@ -150,6 +164,43 @@ export class EscrowV2Module extends BaseModule {
150
164
  .remainingAccounts(splAccounts)
151
165
  .rpc();
152
166
  }
167
+ /**
168
+ * Settle a batch of calls against a V2 escrow.
169
+ *
170
+ * **v0.13.0 — Auto-bundle DisputeWindow:** when the escrow's
171
+ * `settlementSecurity` is `DisputeWindow`, this method now bundles
172
+ * **`settleCallsV2` + `createPendingSettlement`** into the SAME
173
+ * transaction. This eliminates the foot-gun where a caller would call
174
+ * `createPendingSettlement` directly without a preceding `settleCallsV2`,
175
+ * leaving `escrow.pending_amount = 0` and causing `finalizeSettlement`
176
+ * to abort with `ArithmeticOverflow` (6075).
177
+ *
178
+ * Flow per security mode:
179
+ * - **CoSigned** — single IX (`settleCallsV2`) with co-signer in
180
+ * remaining accounts; funds move immediately.
181
+ * - **DisputeWindow** — two IXs in one tx:
182
+ * 1. `settleCallsV2` — bumps `pending_amount` and `settlement_index`
183
+ * 2. `createPendingSettlement(idx)` — locks the dispute tracker PDA
184
+ *
185
+ * After this tx confirms, wait `escrow.disputeWindowSlots` slots and
186
+ * call {@link finalizeSettlement} with the index returned via
187
+ * `SettlementPendingEvent` or readable from `escrow.settlement_index - 1`.
188
+ *
189
+ * Pass `opts.skipAutoPending = true` to opt out of the auto-bundle (e.g.
190
+ * if you want to drive `createPendingSettlement` separately for advanced
191
+ * flows like batched off-chain receipt aggregation).
192
+ *
193
+ * @param depositorWallet - Depositor of the escrow being settled.
194
+ * @param nonce - Escrow nonce (default 0 for the canonical escrow).
195
+ * @param callsToSettle - Number of calls to settle in this batch.
196
+ * @param serviceHash - 32-byte sha256 of the service payload.
197
+ * @param splAccounts - Optional remaining accounts (SPL transfer + co-signer).
198
+ * @param opts - Priority-fee + auto-pending options.
199
+ * @param coSigner - Required for CoSigned escrows.
200
+ * @returns The transaction signature.
201
+ * @since v0.7.0 — initial release
202
+ * @since v0.13.0 — auto-bundles `createPendingSettlement` for DisputeWindow
203
+ */
153
204
  async settle(depositorWallet, nonce, callsToSettle, serviceHash, splAccounts = [], opts, coSigner) {
154
205
  const [agentPda] = deriveAgent(this.walletPubkey);
155
206
  const [escrowPda] = this.deriveEscrow(agentPda, depositorWallet, nonce);
@@ -167,6 +218,20 @@ export class EscrowV2Module extends BaseModule {
167
218
  { pubkey: coSigner.publicKey, isSigner: true, isWritable: false },
168
219
  ]
169
220
  : splAccounts;
221
+ // ── v0.13.0 preflight: fetch escrow once to drive both branches ──
222
+ // We need it to (a) detect DisputeWindow vs CoSigned, (b) read the
223
+ // current `settlement_index` to feed `createPendingSettlement`, and
224
+ // (c) compute `amount` via the volume curve so the bundled IX matches
225
+ // what `settle_calls_v2` will compute on-chain.
226
+ const escrowAcc = await this.fetchAccountNullable("escrowAccountV2", escrowPda);
227
+ if (!escrowAcc) {
228
+ throw new Error(`escrowV2.settle: escrow PDA ${escrowPda.toBase58()} not found on-chain ` +
229
+ `(agent=${agentPda.toBase58()}, depositor=${depositorWallet.toBase58()}, nonce=${this.bn(nonce).toString()}). ` +
230
+ `Did the depositor call escrowV2.create() yet?`);
231
+ }
232
+ const isDisputeWindow = typeof escrowAcc.settlementSecurity === "object" &&
233
+ escrowAcc.settlementSecurity !== null &&
234
+ "disputeWindow" in escrowAcc.settlementSecurity;
170
235
  let builder = this.methods
171
236
  .settleCallsV2(this.bn(nonce), this.bn(callsToSettle), serviceHash)
172
237
  .accountsPartial({
@@ -184,6 +249,52 @@ export class EscrowV2Module extends BaseModule {
184
249
  if (preIxs.length > 0) {
185
250
  builder = builder.preInstructions(preIxs);
186
251
  }
252
+ // ── v0.13.0: auto-bundle createPendingSettlement on DisputeWindow ──
253
+ // The on-chain `settle_calls_v2_handler` (DisputeWindow branch) only
254
+ // bumps `escrow.pending_amount` and `escrow.settlement_index` — it
255
+ // does NOT create the PendingSettlement PDA. Without the followup
256
+ // `createPendingSettlement` IX in the SAME tx, a buggy caller can
257
+ // (a) call `createPendingSettlement` later with a stale index, or
258
+ // (b) skip `settleCallsV2` entirely on a fresh escrow → orphan PDA
259
+ // whose `amount > escrow.pending_amount` → finalize aborts forever
260
+ // with `ArithmeticOverflow` (6075). Bundling is the only way to
261
+ // make that race impossible.
262
+ const skipAutoPending = opts?.skipAutoPending === true;
263
+ if (isDisputeWindow && !skipAutoPending) {
264
+ // PRE-increment settlement_index — settle_calls_v2 will bump it
265
+ // to (current + 1) AFTER our IX runs, but the PDA seed used by
266
+ // create_pending_settlement is the PRE-increment value (matches
267
+ // `SettlementPendingEvent.settlement_index`).
268
+ const settlementIndex = escrowAcc.settlementIndex;
269
+ // Mirror the on-chain volume-curve math so `pending.amount`
270
+ // matches what `escrow.pending_amount` was bumped by.
271
+ const totalCallsBefore = escrowAcc.totalCallsSettled.add(escrowAcc.pendingCalls);
272
+ const amount = calculateSettleAmount(escrowAcc.pricePerCall, escrowAcc.volumeCurve, totalCallsBefore, this.bn(callsToSettle));
273
+ const [pendingPda] = this.derivePendingSettlement(escrowPda, settlementIndex);
274
+ // Defensive: if a stale pending PDA exists at this index (orphan
275
+ // from an aborted prior run), refuse to send — otherwise the IX
276
+ // will fail with `Allocate: account already in use` (custom 0x0).
277
+ const existing = await this.provider.connection.getAccountInfo(pendingPda);
278
+ if (existing) {
279
+ throw new Error(`escrowV2.settle (auto-bundle): pending PDA ${pendingPda.toBase58()} ` +
280
+ `already exists for settlementIndex=${settlementIndex.toString()}. ` +
281
+ `An earlier run created it but did not finalize. Either finalize ` +
282
+ `that index first or skip it permanently. (Pass skipAutoPending=true ` +
283
+ `to bypass this guard and emit only settleCallsV2.)`);
284
+ }
285
+ const receiptMerkleRoot = opts?.receiptMerkleRoot ?? new Array(32).fill(0);
286
+ const pendingIx = await this.methods
287
+ .createPendingSettlement(settlementIndex, this.bn(callsToSettle), amount, serviceHash, receiptMerkleRoot)
288
+ .accounts({
289
+ wallet: this.walletPubkey,
290
+ agent: agentPda,
291
+ escrow: escrowPda,
292
+ pendingSettlement: pendingPda,
293
+ systemProgram: SystemProgram.programId,
294
+ })
295
+ .instruction();
296
+ builder = builder.postInstructions([pendingIx]);
297
+ }
187
298
  return builder.rpc(rpcOpts);
188
299
  }
189
300
  /**
@@ -208,6 +319,24 @@ export class EscrowV2Module extends BaseModule {
208
319
  }
209
320
  return BigInt(escrow.settlementIndex.toString());
210
321
  }
322
+ /**
323
+ * Create the PendingSettlement PDA for a DisputeWindow batch.
324
+ *
325
+ * **v0.13.0 NOTE:** in almost all cases you should call
326
+ * {@link settle} instead — it auto-bundles `settleCallsV2 +
327
+ * createPendingSettlement` in a single transaction so the two
328
+ * cannot drift out of sync. Use this method standalone ONLY when
329
+ * you intentionally pass `skipAutoPending: true` to `settle()`
330
+ * (e.g. batched receipt-merkle aggregation across multiple
331
+ * `settleCallsV2` runs).
332
+ *
333
+ * Calling this without a preceding `settleCallsV2` (which bumps
334
+ * `escrow.pending_amount`) creates an orphan PDA whose
335
+ * `pending.amount > escrow.pending_amount` — `finalizeSettlement`
336
+ * will then abort with `ArithmeticOverflow` (6075) forever.
337
+ *
338
+ * @since v0.7.0
339
+ */
211
340
  async createPendingSettlement(agentWallet, depositorWallet, nonce, settlementIndex, callsToSettle, amount, serviceHash, receiptMerkleRoot = new Array(32).fill(0)) {
212
341
  const [agentPda] = deriveAgent(agentWallet);
213
342
  const [escrowPda] = this.deriveEscrow(agentPda, depositorWallet, nonce);
@@ -244,6 +373,42 @@ export class EscrowV2Module extends BaseModule {
244
373
  const [escrowPda] = this.deriveEscrow(agentPda, depositorWallet, nonce);
245
374
  const [pendingPda] = this.derivePendingSettlement(escrowPda, settlementIndex);
246
375
  const [statsPda] = deriveAgentStats(agentPda);
376
+ // v0.12.9: preflight against ArithmeticOverflow at finalize.
377
+ //
378
+ // The on-chain handler subtracts `pending_settlement.amount` from BOTH
379
+ // `escrow.balance` AND `escrow.pending_amount`. If the PendingSettlement
380
+ // PDA was created without a preceding `settle_calls_v2` (orphan PDA from
381
+ // legacy probe loops, or a buggy caller that skipped the settle step),
382
+ // `escrow.pending_amount` is smaller than `pending_settlement.amount`
383
+ // and the program aborts with ArithmeticOverflow (error 6075) at
384
+ // escrow_v2.rs:633. Each retry burns ~5 000 lamports of base fee.
385
+ //
386
+ // Detect this BEFORE signing and throw with a clear, actionable message
387
+ // pointing at the orphan-recovery path.
388
+ const [escrowAcc, pendingAcc] = await Promise.all([
389
+ this.fetchAccountNullable("escrowAccountV2", escrowPda),
390
+ this.fetchAccountNullable("pendingSettlement", pendingPda),
391
+ ]);
392
+ if (!escrowAcc) {
393
+ throw new Error(`finalizeSettlement: escrow PDA ${escrowPda.toBase58()} not found on-chain.`);
394
+ }
395
+ if (!pendingAcc) {
396
+ throw new Error(`finalizeSettlement: pending PDA ${pendingPda.toBase58()} not found on-chain ` +
397
+ `(settlementIndex=${settlementIndex.toString()}). Nothing to finalize.`);
398
+ }
399
+ const psAmount = BigInt(pendingAcc.amount.toString());
400
+ const escrowPendingAmount = BigInt(escrowAcc.pendingAmount.toString());
401
+ const escrowBalance = BigInt(escrowAcc.balance.toString());
402
+ if (psAmount > escrowPendingAmount || psAmount > escrowBalance) {
403
+ throw new Error(`finalizeSettlement: orphan/inconsistent PendingSettlement detected ` +
404
+ `at ${pendingPda.toBase58()} (settlementIndex=${settlementIndex.toString()}). ` +
405
+ `pending.amount=${psAmount} but escrow.pending_amount=${escrowPendingAmount}, ` +
406
+ `escrow.balance=${escrowBalance}. The on-chain finalize would abort with ` +
407
+ `ArithmeticOverflow (6075). This PDA was almost certainly created by a ` +
408
+ `caller that skipped settle_calls_v2 (legacy probe loop). It cannot be ` +
409
+ `finalized and cannot be closed (close_pending_settlement requires ` +
410
+ `is_finalized=true). Skip this index permanently in your settle queue.`);
411
+ }
247
412
  return this.methods
248
413
  .finalizeSettlement()
249
414
  .accounts({
@@ -255,6 +420,67 @@ export class EscrowV2Module extends BaseModule {
255
420
  })
256
421
  .rpc();
257
422
  }
423
+ /**
424
+ * Identify orphan PendingSettlement PDAs that cannot be finalized.
425
+ *
426
+ * @returns `null` if the PDA is finalizable (or already finalized / disputed).
427
+ * Otherwise an object describing the inconsistency, suitable for
428
+ * logging or feeding into a quarantine list. Use this from a
429
+ * recovery script to scan a range of `settlement_index` values:
430
+ *
431
+ * ```ts
432
+ * for (let idx = 0n; idx < currentIdx; idx++) {
433
+ * const orphan = await sap.escrowV2.diagnoseOrphanPending(
434
+ * agentWallet, depositorWallet, nonce, idx,
435
+ * );
436
+ * if (orphan) log.warn({ idx, ...orphan }, "skip orphan");
437
+ * }
438
+ * ```
439
+ *
440
+ * @since v0.12.9
441
+ */
442
+ async diagnoseOrphanPending(agentWallet, depositorWallet, nonce, settlementIndex) {
443
+ const [agentPda] = deriveAgent(agentWallet);
444
+ const [escrowPda] = this.deriveEscrow(agentPda, depositorWallet, nonce);
445
+ const [pendingPda] = this.derivePendingSettlement(escrowPda, settlementIndex);
446
+ const [escrowAcc, pendingAcc] = await Promise.all([
447
+ this.fetchAccountNullable("escrowAccountV2", escrowPda),
448
+ this.fetchAccountNullable("pendingSettlement", pendingPda),
449
+ ]);
450
+ if (!escrowAcc)
451
+ return null;
452
+ if (!pendingAcc) {
453
+ return {
454
+ pendingPda,
455
+ psAmount: 0n,
456
+ escrowPendingAmount: BigInt(escrowAcc.pendingAmount.toString()),
457
+ escrowBalance: BigInt(escrowAcc.balance.toString()),
458
+ isFinalized: false,
459
+ isDisputed: false,
460
+ reason: "missing",
461
+ };
462
+ }
463
+ const psAmount = BigInt(pendingAcc.amount.toString());
464
+ const escrowPendingAmount = BigInt(escrowAcc.pendingAmount.toString());
465
+ const escrowBalance = BigInt(escrowAcc.balance.toString());
466
+ const base = {
467
+ pendingPda,
468
+ psAmount,
469
+ escrowPendingAmount,
470
+ escrowBalance,
471
+ isFinalized: pendingAcc.isFinalized,
472
+ isDisputed: pendingAcc.isDisputed,
473
+ };
474
+ if (pendingAcc.isFinalized)
475
+ return { ...base, reason: "already_finalized" };
476
+ if (pendingAcc.isDisputed)
477
+ return { ...base, reason: "disputed" };
478
+ if (psAmount > escrowPendingAmount)
479
+ return { ...base, reason: "amount_exceeds_pending" };
480
+ if (psAmount > escrowBalance)
481
+ return { ...base, reason: "amount_exceeds_balance" };
482
+ return null;
483
+ }
258
484
  async fileDispute(agentWallet, nonce, settlementIndex, evidenceHash, disputeType = 0) {
259
485
  const [agentPda] = deriveAgent(agentWallet);
260
486
  const [escrowPda] = this.deriveEscrow(agentPda, undefined, nonce);
@@ -300,6 +526,18 @@ export class EscrowV2Module extends BaseModule {
300
526
  async withdraw(agentWallet, nonce, amount) {
301
527
  const [agentPda] = deriveAgent(agentWallet);
302
528
  const [escrowPda] = this.deriveEscrow(agentPda, undefined, nonce);
529
+ // v0.13.0 preflight — amount must fit (balance - pendingAmount); the
530
+ // on-chain handler subtracts pending_amount from withdrawable funds.
531
+ const escrow = await this.requireAccountExists("escrowAccountV2", escrowPda, { predicted: "NotAuthority", hint: "Escrow V2 PDA not found" });
532
+ const want = BigInt(this.bn(amount).toString());
533
+ if (want <= 0n)
534
+ throwPredicted("InsufficientEscrowBalance", "Withdraw amount must be > 0");
535
+ const balance = BigInt(escrow.balance.toString());
536
+ const pending = BigInt(escrow.pendingAmount.toString());
537
+ const free = balance > pending ? balance - pending : 0n;
538
+ if (want > free) {
539
+ throwPredicted("InsufficientEscrowBalance", `requested ${want}, withdrawable ${free} (balance ${balance} − pending ${pending})`);
540
+ }
303
541
  return this.methods
304
542
  .withdrawEscrowV2(this.bn(amount))
305
543
  .accounts({
@@ -311,6 +549,18 @@ export class EscrowV2Module extends BaseModule {
311
549
  async close(agentWallet, nonce = 0) {
312
550
  const [agentPda] = deriveAgent(agentWallet);
313
551
  const [escrowPda] = this.deriveEscrow(agentPda, undefined, nonce);
552
+ // v0.13.0 preflight — close fails if balance != 0 OR pending_amount != 0.
553
+ // Pending != 0 commonly indicates orphan PendingSettlement PDAs;
554
+ // run diagnoseOrphanPending() across the index range to identify them.
555
+ const escrow = await this.requireAccountExists("escrowAccountV2", escrowPda, { predicted: "NotAuthority", hint: "Escrow V2 PDA already closed" });
556
+ const balance = BigInt(escrow.balance.toString());
557
+ const pending = BigInt(escrow.pendingAmount.toString());
558
+ if (balance !== 0n) {
559
+ throwPredicted("EscrowNotEmpty", `balance ${balance} > 0 — withdraw first`);
560
+ }
561
+ if (pending !== 0n) {
562
+ throwPredicted("EscrowNotClosed", `pending_amount ${pending} > 0 — finalize all PendingSettlements first or quarantine orphans via diagnoseOrphanPending`);
563
+ }
314
564
  return this.methods
315
565
  .closeEscrowV2()
316
566
  .accounts({