@oobe-protocol-labs/synapse-sap-sdk 0.7.0 → 0.8.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 (70) hide show
  1. package/dist/cjs/constants/seeds.js +2 -0
  2. package/dist/cjs/constants/seeds.js.map +1 -1
  3. package/dist/cjs/core/client.js +13 -0
  4. package/dist/cjs/core/client.js.map +1 -1
  5. package/dist/cjs/idl/synapse_agent_sap.json +1050 -629
  6. package/dist/cjs/index.js +7 -3
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/cjs/modules/escrow-v2.js +17 -38
  9. package/dist/cjs/modules/escrow-v2.js.map +1 -1
  10. package/dist/cjs/modules/index.js +3 -1
  11. package/dist/cjs/modules/index.js.map +1 -1
  12. package/dist/cjs/modules/receipt.js +144 -0
  13. package/dist/cjs/modules/receipt.js.map +1 -0
  14. package/dist/cjs/pda/index.js +24 -1
  15. package/dist/cjs/pda/index.js.map +1 -1
  16. package/dist/cjs/types/enums.js +47 -2
  17. package/dist/cjs/types/enums.js.map +1 -1
  18. package/dist/cjs/types/index.js +3 -1
  19. package/dist/cjs/types/index.js.map +1 -1
  20. package/dist/esm/constants/seeds.js +2 -0
  21. package/dist/esm/constants/seeds.js.map +1 -1
  22. package/dist/esm/core/client.js +13 -0
  23. package/dist/esm/core/client.js.map +1 -1
  24. package/dist/esm/idl/synapse_agent_sap.json +1050 -629
  25. package/dist/esm/index.js +3 -3
  26. package/dist/esm/index.js.map +1 -1
  27. package/dist/esm/modules/escrow-v2.js +18 -39
  28. package/dist/esm/modules/escrow-v2.js.map +1 -1
  29. package/dist/esm/modules/index.js +1 -0
  30. package/dist/esm/modules/index.js.map +1 -1
  31. package/dist/esm/modules/receipt.js +140 -0
  32. package/dist/esm/modules/receipt.js.map +1 -0
  33. package/dist/esm/pda/index.js +22 -0
  34. package/dist/esm/pda/index.js.map +1 -1
  35. package/dist/esm/types/enums.js +46 -1
  36. package/dist/esm/types/enums.js.map +1 -1
  37. package/dist/esm/types/index.js +1 -1
  38. package/dist/esm/types/index.js.map +1 -1
  39. package/dist/types/constants/seeds.d.ts +2 -0
  40. package/dist/types/constants/seeds.d.ts.map +1 -1
  41. package/dist/types/core/client.d.ts +10 -0
  42. package/dist/types/core/client.d.ts.map +1 -1
  43. package/dist/types/index.d.ts +4 -4
  44. package/dist/types/index.d.ts.map +1 -1
  45. package/dist/types/modules/escrow-v2.d.ts +13 -6
  46. package/dist/types/modules/escrow-v2.d.ts.map +1 -1
  47. package/dist/types/modules/index.d.ts +1 -0
  48. package/dist/types/modules/index.d.ts.map +1 -1
  49. package/dist/types/modules/receipt.d.ts +77 -0
  50. package/dist/types/modules/receipt.d.ts.map +1 -0
  51. package/dist/types/pda/index.d.ts +15 -0
  52. package/dist/types/pda/index.d.ts.map +1 -1
  53. package/dist/types/types/accounts.d.ts +46 -2
  54. package/dist/types/types/accounts.d.ts.map +1 -1
  55. package/dist/types/types/enums.d.ts +52 -1
  56. package/dist/types/types/enums.d.ts.map +1 -1
  57. package/dist/types/types/index.d.ts +3 -3
  58. package/dist/types/types/index.d.ts.map +1 -1
  59. package/package.json +2 -2
  60. package/src/constants/seeds.ts +2 -0
  61. package/src/core/client.ts +14 -0
  62. package/src/idl/synapse_agent_sap.json +1050 -629
  63. package/src/index.ts +7 -0
  64. package/src/modules/escrow-v2.ts +21 -42
  65. package/src/modules/index.ts +1 -0
  66. package/src/modules/receipt.ts +207 -0
  67. package/src/pda/index.ts +32 -0
  68. package/src/types/accounts.ts +51 -2
  69. package/src/types/enums.ts +55 -1
  70. package/src/types/index.ts +5 -0
package/src/index.ts CHANGED
@@ -62,6 +62,8 @@ export type {
62
62
  SettlementSecurityKind,
63
63
  DisputeOutcomeKind,
64
64
  BillingIntervalKind,
65
+ DisputeTypeValue,
66
+ ResolutionLayerKind,
65
67
  // Helper structs
66
68
  Capability,
67
69
  VolumeCurveBreakpoint,
@@ -90,6 +92,7 @@ export type {
90
92
  EscrowAccountV2Data,
91
93
  PendingSettlementData,
92
94
  DisputeRecordData,
95
+ ReceiptBatchData,
93
96
  AgentStakeData,
94
97
  SubscriptionData,
95
98
  CounterShardData,
@@ -129,6 +132,8 @@ export {
129
132
  SettlementSecurity,
130
133
  DisputeOutcome,
131
134
  BillingInterval,
135
+ DisputeType,
136
+ ResolutionLayer,
132
137
  } from "./types";
133
138
 
134
139
  // ── Constants ────────────────────────────────────────
@@ -178,6 +183,7 @@ export {
178
183
  deriveAttestation,
179
184
  deriveLedger,
180
185
  deriveLedgerPage,
186
+ deriveReceiptBatch,
181
187
  } from "./pda";
182
188
 
183
189
  // ── Utilities ────────────────────────────────────────
@@ -297,6 +303,7 @@ export {
297
303
  VaultModule,
298
304
  EscrowModule,
299
305
  EscrowV2Module,
306
+ ReceiptModule,
300
307
  StakingModule,
301
308
  SubscriptionModule,
302
309
  AttestationModule,
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @module escrow-v2
3
3
  * @description V2 escrow settlement layer — supports settlement security
4
- * modes (SelfReport, CoSigned, DisputeWindow), dispute resolution,
5
- * pending settlements, and migration from V1.
4
+ * modes (CoSigned, DisputeWindow), receipt-based dispute resolution,
5
+ * pending settlements, and automatic resolution via merkle proofs.
6
6
  *
7
7
  * @category Modules
8
8
  * @since v0.7.0
@@ -20,7 +20,6 @@ import { BaseModule } from "./base";
20
20
  import {
21
21
  deriveAgent,
22
22
  deriveAgentStats,
23
- deriveEscrow,
24
23
  deriveEscrowV2,
25
24
  derivePendingSettlement as derivePendingPda,
26
25
  deriveDispute as deriveDisputePda,
@@ -173,6 +172,7 @@ export class EscrowV2Module extends BaseModule {
173
172
  callsToSettle: BN | number | bigint,
174
173
  amount: BN | number | bigint,
175
174
  serviceHash: number[],
175
+ receiptMerkleRoot: number[] = new Array(32).fill(0),
176
176
  ): Promise<TransactionSignature> {
177
177
  const [agentPda] = deriveAgent(agentWallet);
178
178
  const [escrowPda] = this.deriveEscrow(agentPda, depositorWallet, nonce);
@@ -184,6 +184,7 @@ export class EscrowV2Module extends BaseModule {
184
184
  this.bn(callsToSettle),
185
185
  this.bn(amount),
186
186
  serviceHash,
187
+ receiptMerkleRoot,
187
188
  )
188
189
  .accounts({
189
190
  wallet: this.walletPubkey,
@@ -223,6 +224,7 @@ export class EscrowV2Module extends BaseModule {
223
224
  nonce: BN | number | bigint,
224
225
  settlementIndex: BN | number | bigint,
225
226
  evidenceHash: number[],
227
+ disputeType: number = 0,
226
228
  ): Promise<TransactionSignature> {
227
229
  const [agentPda] = deriveAgent(agentWallet);
228
230
  const [escrowPda] = this.deriveEscrow(agentPda, undefined, nonce);
@@ -230,7 +232,7 @@ export class EscrowV2Module extends BaseModule {
230
232
  const [disputePda] = this.deriveDispute(pendingPda);
231
233
 
232
234
  return this.methods
233
- .fileDispute(evidenceHash)
235
+ .fileDispute(evidenceHash, disputeType)
234
236
  .accounts({
235
237
  depositor: this.walletPubkey,
236
238
  escrow: escrowPda,
@@ -241,31 +243,18 @@ export class EscrowV2Module extends BaseModule {
241
243
  .rpc();
242
244
  }
243
245
 
246
+ /**
247
+ * @deprecated Since v0.7.0 — Arbiter-based resolution removed.
248
+ * Use {@link ReceiptModule.submitReceiptProof} + {@link ReceiptModule.autoResolveDispute} instead.
249
+ */
244
250
  async resolveDispute(
245
- depositorWallet: PublicKey,
246
- agentWallet: PublicKey,
247
- nonce: BN | number | bigint,
248
- settlementIndex: BN | number | bigint,
249
- outcome: number,
251
+ _depositorWallet: PublicKey,
252
+ _agentWallet: PublicKey,
253
+ _nonce: BN | number | bigint,
254
+ _settlementIndex: BN | number | bigint,
255
+ _outcome: number,
250
256
  ): Promise<TransactionSignature> {
251
- const [agentPda] = deriveAgent(agentWallet);
252
- const [escrowPda] = this.deriveEscrow(agentPda, depositorWallet, nonce);
253
- const [pendingPda] = this.derivePendingSettlement(escrowPda, settlementIndex);
254
- const [disputePda] = this.deriveDispute(pendingPda);
255
- const [statsPda] = deriveAgentStats(agentPda);
256
-
257
- return this.methods
258
- .resolveDispute(outcome)
259
- .accounts({
260
- arbiter: this.walletPubkey,
261
- depositor: depositorWallet,
262
- agentWallet,
263
- escrow: escrowPda,
264
- pendingSettlement: pendingPda,
265
- dispute: disputePda,
266
- agentStats: statsPda,
267
- })
268
- .rpc();
257
+ throw new Error("resolveDispute removed in v0.7.0 — use ReceiptModule.autoResolveDispute");
269
258
  }
270
259
 
271
260
  async closeDispute(
@@ -327,23 +316,13 @@ export class EscrowV2Module extends BaseModule {
327
316
  .rpc();
328
317
  }
329
318
 
319
+ /**
320
+ * @deprecated Since v0.7.0 — Migration instruction removed from program.
321
+ */
330
322
  async migrateFromV1(
331
- agentWallet: PublicKey,
323
+ _agentWallet: PublicKey,
332
324
  ): Promise<TransactionSignature> {
333
- const [agentPda] = deriveAgent(agentWallet);
334
- const [escrowV1Pda] = deriveEscrow(agentPda, this.walletPubkey);
335
- const [escrowV2Pda] = this.deriveEscrow(agentPda, undefined, 0);
336
-
337
- return this.methods
338
- .migrateEscrowV1ToV2()
339
- .accounts({
340
- depositor: this.walletPubkey,
341
- agent: agentPda,
342
- escrowV1: escrowV1Pda,
343
- escrowV2: escrowV2Pda,
344
- systemProgram: SystemProgram.programId,
345
- })
346
- .rpc();
325
+ throw new Error("migrateFromV1 removed in v0.7.0 — migration instruction was deleted");
347
326
  }
348
327
 
349
328
  // ── Fetchers ─────────────────────────────────────────
@@ -19,6 +19,7 @@ export { ToolsModule } from "./tools";
19
19
  export { VaultModule } from "./vault";
20
20
  export { EscrowModule } from "./escrow";
21
21
  export { EscrowV2Module } from "./escrow-v2";
22
+ export { ReceiptModule } from "./receipt";
22
23
  export { StakingModule } from "./staking";
23
24
  export { SubscriptionModule } from "./subscription";
24
25
  export { AttestationModule } from "./attestation";
@@ -0,0 +1,207 @@
1
+ /**
2
+ * @module receipt
3
+ * @description Receipt-based trustless dispute resolution (v0.7).
4
+ *
5
+ * Agents inscribe merkle roots of call receipt batches on-chain.
6
+ * During disputes, agents submit merkle inclusion proofs to prove delivery.
7
+ * After the proof deadline, anyone can trigger automatic proportional resolution.
8
+ *
9
+ * @category Modules
10
+ * @since v0.7.0
11
+ * @packageDocumentation
12
+ */
13
+
14
+ import {
15
+ SystemProgram,
16
+ type PublicKey,
17
+ type TransactionSignature,
18
+ } from "@solana/web3.js";
19
+ import { BN } from "@coral-xyz/anchor";
20
+ import { BaseModule } from "./base";
21
+ import {
22
+ deriveAgent,
23
+ deriveAgentStats,
24
+ deriveEscrowV2,
25
+ derivePendingSettlement as derivePendingPda,
26
+ deriveDispute as deriveDisputePda,
27
+ deriveReceiptBatch as deriveReceiptPda,
28
+ } from "../pda";
29
+ import type { ReceiptBatchData } from "../types";
30
+
31
+ /**
32
+ * @name ReceiptModule
33
+ * @description Manages receipt batch inscriptions, merkle proof submissions,
34
+ * and automatic dispute resolution for the v0.7 trustless settlement layer.
35
+ *
36
+ * @category Modules
37
+ * @since v0.7.0
38
+ * @extends BaseModule
39
+ */
40
+ export class ReceiptModule extends BaseModule {
41
+ // ── Helpers ──────────────────────────────────────────
42
+
43
+ private toNum(v: BN | number | bigint): number {
44
+ return BN.isBN(v) ? v.toNumber() : Number(v);
45
+ }
46
+
47
+ // ── PDA helpers ──────────────────────────────────────
48
+
49
+ deriveReceiptBatch(
50
+ escrowV2Pda: PublicKey,
51
+ batchIndex: number,
52
+ ): readonly [PublicKey, number] {
53
+ return deriveReceiptPda(escrowV2Pda, batchIndex);
54
+ }
55
+
56
+ // ── Instructions ─────────────────────────────────────
57
+
58
+ /**
59
+ * Inscribe a receipt batch merkle root on-chain.
60
+ *
61
+ * Called by the **agent** to commit a cryptographic proof of calls delivered.
62
+ * The `merkleRoot` is the root of a merkle tree whose leaves are individual
63
+ * call receipt hashes.
64
+ *
65
+ * @param depositorWallet - The depositor's wallet (needed for escrow PDA derivation).
66
+ * @param nonce - Escrow nonce.
67
+ * @param batchIndex - Zero-based batch index (must equal escrow.receipt_batch_count).
68
+ * @param merkleRoot - 32-byte merkle root of the receipt batch.
69
+ * @param callCount - Number of calls in the batch.
70
+ * @param periodStart - Unix timestamp for the start of the covered period.
71
+ * @param periodEnd - Unix timestamp for the end of the covered period.
72
+ */
73
+ async inscribeReceiptBatch(
74
+ depositorWallet: PublicKey,
75
+ nonce: BN | number | bigint,
76
+ batchIndex: number,
77
+ merkleRoot: number[],
78
+ callCount: BN | number | bigint,
79
+ periodStart: BN | number | bigint,
80
+ periodEnd: BN | number | bigint,
81
+ ): Promise<TransactionSignature> {
82
+ const [agentPda] = deriveAgent(this.walletPubkey);
83
+ const [escrowPda] = deriveEscrowV2(agentPda, depositorWallet, this.toNum(nonce));
84
+ const [receiptPda] = this.deriveReceiptBatch(escrowPda, batchIndex);
85
+
86
+ return this.methods
87
+ .inscribeReceiptBatch(
88
+ batchIndex,
89
+ merkleRoot,
90
+ this.bn(callCount),
91
+ this.bn(periodStart),
92
+ this.bn(periodEnd),
93
+ )
94
+ .accounts({
95
+ wallet: this.walletPubkey,
96
+ agent: agentPda,
97
+ escrow: escrowPda,
98
+ receiptBatch: receiptPda,
99
+ systemProgram: SystemProgram.programId,
100
+ })
101
+ .rpc();
102
+ }
103
+
104
+ /**
105
+ * Submit a merkle inclusion proof during a dispute.
106
+ *
107
+ * Called by the **agent** to prove delivery of specific calls.
108
+ * Each proof verifies that a set of receipt hashes are included
109
+ * in the previously inscribed merkle root.
110
+ *
111
+ * @param depositorWallet - The depositor's wallet.
112
+ * @param nonce - Escrow nonce.
113
+ * @param settlementIndex - Index of the disputed pending settlement.
114
+ * @param batchIndex - Receipt batch index containing the proof.
115
+ * @param provenCount - Number of calls proven in this proof submission.
116
+ * @param proof - Array of 32-byte merkle proof hashes.
117
+ * @param leaf - The 32-byte leaf hash being proven.
118
+ */
119
+ async submitReceiptProof(
120
+ depositorWallet: PublicKey,
121
+ nonce: BN | number | bigint,
122
+ settlementIndex: BN | number | bigint,
123
+ batchIndex: number,
124
+ provenCount: BN | number | bigint,
125
+ proof: number[][],
126
+ leaf: number[],
127
+ ): Promise<TransactionSignature> {
128
+ const [agentPda] = deriveAgent(this.walletPubkey);
129
+ const [escrowPda] = deriveEscrowV2(agentPda, depositorWallet, this.toNum(nonce));
130
+ const [pendingPda] = derivePendingPda(escrowPda, this.toNum(settlementIndex));
131
+ const [disputePda] = deriveDisputePda(pendingPda);
132
+ const [receiptPda] = this.deriveReceiptBatch(escrowPda, batchIndex);
133
+
134
+ return this.methods
135
+ .submitReceiptProof(
136
+ batchIndex,
137
+ this.bn(provenCount),
138
+ proof,
139
+ leaf,
140
+ )
141
+ .accounts({
142
+ wallet: this.walletPubkey,
143
+ agent: agentPda,
144
+ escrow: escrowPda,
145
+ pendingSettlement: pendingPda,
146
+ dispute: disputePda,
147
+ receiptBatch: receiptPda,
148
+ })
149
+ .rpc();
150
+ }
151
+
152
+ /**
153
+ * Trigger automatic dispute resolution after the proof deadline.
154
+ *
155
+ * Permissionless crank — anyone can call this once the deadline has passed.
156
+ * Resolution is proportional: if the agent proved N of M claimed calls,
157
+ * N/M of the settlement amount goes to the agent, the rest is refunded.
158
+ *
159
+ * @param agentWallet - The agent's wallet.
160
+ * @param depositorWallet - The depositor's wallet.
161
+ * @param nonce - Escrow nonce.
162
+ * @param settlementIndex - Index of the disputed pending settlement.
163
+ */
164
+ async autoResolveDispute(
165
+ agentWallet: PublicKey,
166
+ depositorWallet: PublicKey,
167
+ nonce: BN | number | bigint,
168
+ settlementIndex: BN | number | bigint,
169
+ ): Promise<TransactionSignature> {
170
+ const [agentPda] = deriveAgent(agentWallet);
171
+ const [escrowPda] = deriveEscrowV2(agentPda, depositorWallet, this.toNum(nonce));
172
+ const [pendingPda] = derivePendingPda(escrowPda, this.toNum(settlementIndex));
173
+ const [disputePda] = deriveDisputePda(pendingPda);
174
+ const [statsPda] = deriveAgentStats(agentPda);
175
+
176
+ return this.methods
177
+ .autoResolveDispute()
178
+ .accounts({
179
+ payer: this.walletPubkey,
180
+ depositor: depositorWallet,
181
+ agentWallet,
182
+ escrow: escrowPda,
183
+ pendingSettlement: pendingPda,
184
+ dispute: disputePda,
185
+ agentStats: statsPda,
186
+ })
187
+ .rpc();
188
+ }
189
+
190
+ // ── Fetchers ─────────────────────────────────────────
191
+
192
+ async fetchReceiptBatch(
193
+ escrowV2Pda: PublicKey,
194
+ batchIndex: number,
195
+ ): Promise<ReceiptBatchData> {
196
+ const [pda] = this.deriveReceiptBatch(escrowV2Pda, batchIndex);
197
+ return this.fetchAccount<ReceiptBatchData>("receiptBatch", pda);
198
+ }
199
+
200
+ async fetchReceiptBatchNullable(
201
+ escrowV2Pda: PublicKey,
202
+ batchIndex: number,
203
+ ): Promise<ReceiptBatchData | null> {
204
+ const [pda] = this.deriveReceiptBatch(escrowV2Pda, batchIndex);
205
+ return this.fetchAccountNullable<ReceiptBatchData>("receiptBatch", pda);
206
+ }
207
+ }
package/src/pda/index.ts CHANGED
@@ -846,3 +846,35 @@ export const deriveIndexPage = (
846
846
  ],
847
847
  programId,
848
848
  );
849
+
850
+ // ═════════════════════════════════════════════
851
+ // Receipt Batch (v0.7)
852
+ // ═════════════════════════════════════════════
853
+
854
+ /**
855
+ * Derive the **ReceiptBatch** PDA.
856
+ *
857
+ * Seeds: `["sap_receipt", escrow_v2_pda, batch_index_u32_le]`
858
+ *
859
+ * @name deriveReceiptBatch
860
+ * @description Computes the receipt batch PDA storing a merkle root of call receipts.
861
+ * @param escrowV2Pda - The parent V2 escrow PDA.
862
+ * @param batchIndex - Zero-based batch index (u32).
863
+ * @param programId - Override program ID.
864
+ * @returns {PdaResult} `[pda, bump]` tuple.
865
+ * @category PDA
866
+ * @since v0.7.0
867
+ */
868
+ export const deriveReceiptBatch = (
869
+ escrowV2Pda: PublicKey,
870
+ batchIndex: number,
871
+ programId = SAP_PROGRAM_ID,
872
+ ): PdaResult =>
873
+ findPda(
874
+ [
875
+ toSeedBuf(SEEDS.RECEIPT),
876
+ escrowV2Pda.toBuffer(),
877
+ u32le(batchIndex),
878
+ ],
879
+ programId,
880
+ );
@@ -11,7 +11,7 @@
11
11
 
12
12
  import type { PublicKey } from "@solana/web3.js";
13
13
  import type BN from "bn.js";
14
- import type { ToolHttpMethodKind, ToolCategoryKind, SettlementSecurityKind, DisputeOutcomeKind, BillingIntervalKind } from "./enums";
14
+ import type { ToolHttpMethodKind, ToolCategoryKind, SettlementSecurityKind, DisputeOutcomeKind, BillingIntervalKind, ResolutionLayerKind } from "./enums";
15
15
  import type { Capability, PricingTier, PluginRef, VolumeCurveBreakpoint } from "./common";
16
16
 
17
17
  // ═══════════════════════════════════════════════════════════════════
@@ -652,9 +652,12 @@ export interface EscrowAccountV2Data {
652
652
  readonly disputeWindowSlots: BN;
653
653
  readonly settlementIndex: BN;
654
654
  readonly coSigner: PublicKey | null;
655
+ /** @deprecated Since v0.7.0 — arbiter role replaced by automatic receipt verification */
655
656
  readonly arbiter: PublicKey | null;
656
657
  readonly pendingAmount: BN;
657
658
  readonly pendingCalls: BN;
659
+ /** @since v0.7.0 — Number of receipt batches inscribed against this escrow */
660
+ readonly receiptBatchCount: number;
658
661
  }
659
662
 
660
663
  // ═══════════════════════════════════════════════════════════════════
@@ -682,6 +685,8 @@ export interface PendingSettlementData {
682
685
  readonly isFinalized: boolean;
683
686
  readonly isDisputed: boolean;
684
687
  readonly outcome: DisputeOutcomeKind;
688
+ /** @since v0.7.0 — Merkle root of receipts backing this settlement */
689
+ readonly receiptMerkleRoot: number[]; // [u8; 32]
685
690
  }
686
691
 
687
692
  // ═══════════════════════════════════════════════════════════════════
@@ -690,7 +695,7 @@ export interface PendingSettlementData {
690
695
 
691
696
  /**
692
697
  * @interface DisputeRecordData
693
- * @description On-chain dispute with arbiter resolution.
698
+ * @description On-chain dispute with automatic receipt-based resolution (v0.7).
694
699
  * @category Types
695
700
  * @since v0.5.0
696
701
  */
@@ -702,12 +707,56 @@ export interface DisputeRecordData {
702
707
  readonly agent: PublicKey;
703
708
  readonly evidenceHash: number[]; // [u8; 32]
704
709
  readonly agentEvidenceHash: number[]; // [u8; 32]
710
+ /** @deprecated Since v0.7.0 — arbiter role replaced by automatic resolution */
705
711
  readonly arbiter: PublicKey;
706
712
  readonly outcome: DisputeOutcomeKind;
707
713
  readonly createdAt: BN;
708
714
  readonly resolvedAt: BN;
709
715
  readonly resolutionHash: number[]; // [u8; 32]
710
716
  readonly slashAmount: BN;
717
+ /** @since v0.7.0 — Category of dispute (NonDelivery=0, PartialDelivery=1, Overcharge=2, Quality=3) */
718
+ readonly disputeType: number;
719
+ /** @since v0.7.0 — How the dispute was resolved (Pending/Auto/Governance) */
720
+ readonly resolutionLayer: ResolutionLayerKind;
721
+ /** @since v0.7.0 — Bond deposited by the disputer (lamports) */
722
+ readonly disputeBond: BN;
723
+ /** @since v0.7.0 — Number of calls the agent proved via merkle proofs */
724
+ readonly provenCalls: BN;
725
+ /** @since v0.7.0 — Number of calls the agent originally claimed */
726
+ readonly claimedCalls: BN;
727
+ /** @since v0.7.0 — Unix timestamp by which agent must submit proof */
728
+ readonly proofDeadline: BN;
729
+ }
730
+
731
+ // ═══════════════════════════════════════════════════════════════════
732
+ // Receipt Batch (v0.7)
733
+ // ═══════════════════════════════════════════════════════════════════
734
+
735
+ /**
736
+ * @interface ReceiptBatchData
737
+ * @description Merkle root of a batch of call receipts inscribed by an agent.
738
+ *
739
+ * Seeds: `["sap_receipt", escrow_v2_pda, batch_index_u32_le]`
740
+ *
741
+ * @category Types
742
+ * @since v0.7.0
743
+ */
744
+ export interface ReceiptBatchData {
745
+ readonly bump: number;
746
+ /** Parent escrow V2 PDA */
747
+ readonly escrow: PublicKey;
748
+ /** Zero-based batch index */
749
+ readonly batchIndex: number;
750
+ /** Merkle root of the receipt batch */
751
+ readonly merkleRoot: number[]; // [u8; 32]
752
+ /** Number of calls in the batch */
753
+ readonly callCount: BN;
754
+ /** Unix timestamp for the start of the period covered */
755
+ readonly periodStart: BN;
756
+ /** Unix timestamp for the end of the period covered */
757
+ readonly periodEnd: BN;
758
+ /** Unix timestamp when the batch was inscribed */
759
+ readonly inscribedAt: BN;
711
760
  }
712
761
 
713
762
  // ═══════════════════════════════════════════════════════════════════
@@ -221,7 +221,7 @@ export type ToolCategoryKind =
221
221
  * @name SettlementSecurity
222
222
  * @description Anchor-compatible enum variants for V2 escrow settlement security levels.
223
223
  *
224
- * - `SelfReport` — Agent settles unilaterally (v1 compatible).
224
+ * - `SelfReport` — **DEPRECATED in v0.7** — Agent settles unilaterally (abuse vector).
225
225
  * - `CoSigned` — Agent + client must co-sign every settlement.
226
226
  * - `DisputeWindow` — Settlement enters pending state, depositor can dispute.
227
227
  *
@@ -229,6 +229,7 @@ export type ToolCategoryKind =
229
229
  * @since v0.5.0
230
230
  */
231
231
  export const SettlementSecurity = {
232
+ /** @deprecated Removed in v0.7 — returns SelfReportDeprecated error */
232
233
  SelfReport: { selfReport: {} },
233
234
  CoSigned: { coSigned: {} },
234
235
  DisputeWindow: { disputeWindow: {} },
@@ -253,11 +254,64 @@ export const DisputeOutcome = {
253
254
  AutoReleased: { autoReleased: {} },
254
255
  DepositorWins: { depositorWins: {} },
255
256
  AgentWins: { agentWins: {} },
257
+ /** @since v0.7.0 — Proportional refund based on proven vs claimed calls */
258
+ PartialRefund: { partialRefund: {} },
259
+ /** @since v0.7.0 — 50/50 split for irresolvable quality disputes */
260
+ Split: { split: {} },
256
261
  } as const;
257
262
 
258
263
  export type DisputeOutcomeKind =
259
264
  (typeof DisputeOutcome)[keyof typeof DisputeOutcome];
260
265
 
266
+ // ═══════════════════════════════════════════════════════════════════
267
+ // Dispute Type (v0.7)
268
+ // ═══════════════════════════════════════════════════════════════════
269
+
270
+ /**
271
+ * @name DisputeType
272
+ * @description Categories of disputes that can be filed against a pending settlement.
273
+ *
274
+ * - `NonDelivery` — Agent took payment but delivered nothing.
275
+ * - `PartialDelivery` — Agent delivered fewer calls than claimed.
276
+ * - `Overcharge` — Agent charged more than the agreed price.
277
+ * - `Quality` — Agent delivered but output quality is disputed.
278
+ *
279
+ * @category Types
280
+ * @since v0.7.0
281
+ */
282
+ export const DisputeType = {
283
+ NonDelivery: 0,
284
+ PartialDelivery: 1,
285
+ Overcharge: 2,
286
+ Quality: 3,
287
+ } as const;
288
+
289
+ export type DisputeTypeValue = (typeof DisputeType)[keyof typeof DisputeType];
290
+
291
+ // ═══════════════════════════════════════════════════════════════════
292
+ // Resolution Layer (v0.7)
293
+ // ═══════════════════════════════════════════════════════════════════
294
+
295
+ /**
296
+ * @name ResolutionLayer
297
+ * @description How a dispute was resolved.
298
+ *
299
+ * - `Pending` — Not yet resolved.
300
+ * - `Auto` — Resolved automatically via receipt merkle proofs.
301
+ * - `Governance` — Resolved via protocol governance (quality disputes).
302
+ *
303
+ * @category Types
304
+ * @since v0.7.0
305
+ */
306
+ export const ResolutionLayer = {
307
+ Pending: { pending: {} },
308
+ Auto: { auto: {} },
309
+ Governance: { governance: {} },
310
+ } as const;
311
+
312
+ export type ResolutionLayerKind =
313
+ (typeof ResolutionLayer)[keyof typeof ResolutionLayer];
314
+
261
315
  // ═══════════════════════════════════════════════════════════════════
262
316
  // Billing Interval (V2.1)
263
317
  // ═══════════════════════════════════════════════════════════════════
@@ -30,6 +30,8 @@ export {
30
30
  SettlementSecurity,
31
31
  DisputeOutcome,
32
32
  BillingInterval,
33
+ DisputeType,
34
+ ResolutionLayer,
33
35
  } from "./enums";
34
36
 
35
37
  export type {
@@ -41,6 +43,8 @@ export type {
41
43
  SettlementSecurityKind,
42
44
  DisputeOutcomeKind,
43
45
  BillingIntervalKind,
46
+ DisputeTypeValue,
47
+ ResolutionLayerKind,
44
48
  } from "./enums";
45
49
 
46
50
  // ── Common Structs ───────────────────────────────────
@@ -74,6 +78,7 @@ export type {
74
78
  EscrowAccountV2Data,
75
79
  PendingSettlementData,
76
80
  DisputeRecordData,
81
+ ReceiptBatchData,
77
82
  AgentStakeData,
78
83
  SubscriptionData,
79
84
  CounterShardData,