pepay-streams-sdk 0.1.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 (62) hide show
  1. package/README.md +405 -0
  2. package/dist/api/index.d.mts +321 -0
  3. package/dist/api/index.d.ts +321 -0
  4. package/dist/api/index.js +312 -0
  5. package/dist/api/index.js.map +1 -0
  6. package/dist/api/index.mjs +306 -0
  7. package/dist/api/index.mjs.map +1 -0
  8. package/dist/automation/index.d.mts +140 -0
  9. package/dist/automation/index.d.ts +140 -0
  10. package/dist/automation/index.js +331 -0
  11. package/dist/automation/index.js.map +1 -0
  12. package/dist/automation/index.mjs +326 -0
  13. package/dist/automation/index.mjs.map +1 -0
  14. package/dist/campaigns/index.d.mts +286 -0
  15. package/dist/campaigns/index.d.ts +286 -0
  16. package/dist/campaigns/index.js +652 -0
  17. package/dist/campaigns/index.js.map +1 -0
  18. package/dist/campaigns/index.mjs +645 -0
  19. package/dist/campaigns/index.mjs.map +1 -0
  20. package/dist/claims/index.d.mts +190 -0
  21. package/dist/claims/index.d.ts +190 -0
  22. package/dist/claims/index.js +414 -0
  23. package/dist/claims/index.js.map +1 -0
  24. package/dist/claims/index.mjs +409 -0
  25. package/dist/claims/index.mjs.map +1 -0
  26. package/dist/index-BTG0TRJt.d.mts +555 -0
  27. package/dist/index-BTG0TRJt.d.ts +555 -0
  28. package/dist/index.d.mts +170 -0
  29. package/dist/index.d.ts +170 -0
  30. package/dist/index.js +2926 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/index.mjs +2888 -0
  33. package/dist/index.mjs.map +1 -0
  34. package/dist/marketplace/index.d.mts +225 -0
  35. package/dist/marketplace/index.d.ts +225 -0
  36. package/dist/marketplace/index.js +529 -0
  37. package/dist/marketplace/index.js.map +1 -0
  38. package/dist/marketplace/index.mjs +524 -0
  39. package/dist/marketplace/index.mjs.map +1 -0
  40. package/dist/react/index.d.mts +185 -0
  41. package/dist/react/index.d.ts +185 -0
  42. package/dist/react/index.js +340 -0
  43. package/dist/react/index.js.map +1 -0
  44. package/dist/react/index.mjs +333 -0
  45. package/dist/react/index.mjs.map +1 -0
  46. package/dist/staking/index.d.mts +158 -0
  47. package/dist/staking/index.d.ts +158 -0
  48. package/dist/staking/index.js +359 -0
  49. package/dist/staking/index.js.map +1 -0
  50. package/dist/staking/index.mjs +354 -0
  51. package/dist/staking/index.mjs.map +1 -0
  52. package/package.json +106 -0
  53. package/src/api/index.ts +577 -0
  54. package/src/automation/index.ts +436 -0
  55. package/src/campaigns/index.ts +835 -0
  56. package/src/claims/index.ts +530 -0
  57. package/src/client.ts +518 -0
  58. package/src/index.ts +101 -0
  59. package/src/marketplace/index.ts +730 -0
  60. package/src/react/index.ts +498 -0
  61. package/src/staking/index.ts +449 -0
  62. package/src/types/index.ts +631 -0
@@ -0,0 +1,414 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var viem = require('viem');
6
+ var diamond = require('@pepay-streams/abi/diamond');
7
+
8
+ // src/claims/index.ts
9
+ var ClaimsModule = class {
10
+ constructor(publicClient, walletClient, diamondAddress, chainId) {
11
+ this.publicClient = publicClient;
12
+ this.walletClient = walletClient;
13
+ this.diamondAddress = diamondAddress;
14
+ this.chainId = chainId;
15
+ }
16
+ // ============================================================================
17
+ // Standard Claims
18
+ // ============================================================================
19
+ /**
20
+ * Claim vested tokens from a campaign
21
+ *
22
+ * For merkle-tree campaigns, requires allocation and proof.
23
+ * For direct campaigns, allocation should be 0 and proof empty.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * // Direct campaign claim
28
+ * const result = await sdk.claims.claim({
29
+ * campaignId: 1n,
30
+ * allocation: 0n,
31
+ * proof: [],
32
+ * });
33
+ *
34
+ * // Merkle campaign claim
35
+ * const result = await sdk.claims.claim({
36
+ * campaignId: 1n,
37
+ * allocation: parseEther('100'),
38
+ * proof: ['0x...', '0x...'],
39
+ * });
40
+ * ```
41
+ */
42
+ async claim(params) {
43
+ const wallet = this.requireWallet();
44
+ let hash;
45
+ if (params.claimTo) {
46
+ hash = await wallet.writeContract({
47
+ chain: wallet.chain,
48
+ account: wallet.account,
49
+ address: this.diamondAddress,
50
+ abi: diamond.DIAMOND_ABI,
51
+ functionName: "claimTo",
52
+ args: [
53
+ params.campaignId,
54
+ params.claimTo,
55
+ params.allocation ?? 0n,
56
+ params.proof ?? []
57
+ ]
58
+ });
59
+ } else {
60
+ hash = await wallet.writeContract({
61
+ chain: wallet.chain,
62
+ account: wallet.account,
63
+ address: this.diamondAddress,
64
+ abi: diamond.DIAMOND_ABI,
65
+ functionName: "claim",
66
+ args: [
67
+ params.campaignId,
68
+ params.allocation ?? 0n,
69
+ params.proof ?? []
70
+ ]
71
+ });
72
+ }
73
+ return this.createTransactionResult(hash);
74
+ }
75
+ /**
76
+ * Claim from a campaign for multiple recipients in a single transaction
77
+ *
78
+ * More gas efficient than multiple individual claims.
79
+ * For direct allocation campaigns only.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const result = await sdk.claims.claimBatch({
84
+ * campaignId: 1n,
85
+ * recipients: ['0x...', '0x...', '0x...'],
86
+ * });
87
+ * ```
88
+ */
89
+ async claimBatch(params) {
90
+ const wallet = this.requireWallet();
91
+ const hash = await wallet.writeContract({
92
+ chain: wallet.chain,
93
+ account: wallet.account,
94
+ address: this.diamondAddress,
95
+ abi: diamond.DIAMOND_ABI,
96
+ functionName: "claimMany",
97
+ args: [params.campaignId, params.recipients]
98
+ });
99
+ return this.createTransactionResult(hash);
100
+ }
101
+ /**
102
+ * Release locked tokens (for Lock campaigns)
103
+ *
104
+ * Can only be called after the unlock time has passed.
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const result = await sdk.claims.releaseLock(campaignId, [recipient1, recipient2]);
109
+ * ```
110
+ */
111
+ async releaseLock(campaignId, recipients) {
112
+ const wallet = this.requireWallet();
113
+ const hash = await wallet.writeContract({
114
+ chain: wallet.chain,
115
+ account: wallet.account,
116
+ address: this.diamondAddress,
117
+ abi: diamond.DIAMOND_ABI,
118
+ functionName: "releaseLock",
119
+ args: [campaignId, recipients]
120
+ });
121
+ return this.createTransactionResult(hash);
122
+ }
123
+ // ============================================================================
124
+ // Meta-Transaction Claims (Gasless)
125
+ // ============================================================================
126
+ /**
127
+ * Claim via meta-transaction (gasless for recipient)
128
+ *
129
+ * A relayer submits the transaction on behalf of the recipient.
130
+ * The recipient signs an EIP-712 message off-chain.
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * // Recipient signs off-chain
135
+ * const signedAuth = await sdk.claims.signClaimMessage({
136
+ * campaignId,
137
+ * allocation: parseEther('100'),
138
+ * proof: ['0x...'],
139
+ * deadline: Math.floor(Date.now() / 1000) + 3600, // 1 hour
140
+ * });
141
+ *
142
+ * // Relayer submits
143
+ * const result = await sdk.claims.claimWithSig(signedAuth);
144
+ * ```
145
+ */
146
+ async claimWithSig(params) {
147
+ const wallet = this.requireWallet();
148
+ const auth = {
149
+ id: params.campaignId,
150
+ claimant: params.claimant,
151
+ payoutTo: params.payoutTo ?? params.claimant,
152
+ allocation: params.allocation,
153
+ proofHash: this.computeProofHash(params.proof),
154
+ deadline: BigInt(params.deadline),
155
+ nonce: params.nonce
156
+ };
157
+ const hash = await wallet.writeContract({
158
+ chain: wallet.chain,
159
+ account: wallet.account,
160
+ address: this.diamondAddress,
161
+ abi: diamond.DIAMOND_ABI,
162
+ functionName: "claimWithSig",
163
+ args: [auth, params.proof, params.signature]
164
+ });
165
+ return this.createTransactionResult(hash);
166
+ }
167
+ /**
168
+ * Generate the EIP-712 typed data for a claim signature
169
+ *
170
+ * The recipient signs this message off-chain.
171
+ */
172
+ getClaimTypedData(campaignId, claimant, payoutTo, allocation, proofHash, nonce, deadline) {
173
+ return {
174
+ domain: {
175
+ name: "PepayStreams",
176
+ version: "1",
177
+ chainId: this.chainId,
178
+ verifyingContract: this.diamondAddress
179
+ },
180
+ types: {
181
+ ClaimAuth: [
182
+ { name: "id", type: "uint256" },
183
+ { name: "claimant", type: "address" },
184
+ { name: "payoutTo", type: "address" },
185
+ { name: "allocation", type: "uint128" },
186
+ { name: "proofHash", type: "bytes32" },
187
+ { name: "deadline", type: "uint64" },
188
+ { name: "nonce", type: "uint256" }
189
+ ]
190
+ },
191
+ primaryType: "ClaimAuth",
192
+ message: {
193
+ id: campaignId,
194
+ claimant,
195
+ payoutTo,
196
+ allocation,
197
+ proofHash,
198
+ deadline: BigInt(deadline),
199
+ nonce
200
+ }
201
+ };
202
+ }
203
+ /**
204
+ * Sign a claim message for meta-transaction
205
+ *
206
+ * Returns the signature that can be submitted by a relayer.
207
+ */
208
+ async signClaimMessage(params) {
209
+ const wallet = this.requireWallet();
210
+ const claimant = wallet.account.address;
211
+ const payoutTo = params.payoutTo ?? claimant;
212
+ const nonce = await this.getClaimNonce(params.campaignId, claimant);
213
+ const proofHash = this.computeProofHash(params.proof);
214
+ const typedData = this.getClaimTypedData(
215
+ params.campaignId,
216
+ claimant,
217
+ payoutTo,
218
+ params.allocation,
219
+ proofHash,
220
+ nonce,
221
+ params.deadline
222
+ );
223
+ const signature = await wallet.signTypedData({
224
+ account: wallet.account,
225
+ domain: typedData.domain,
226
+ types: typedData.types,
227
+ primaryType: typedData.primaryType,
228
+ message: typedData.message
229
+ });
230
+ return {
231
+ signature,
232
+ nonce,
233
+ deadline: params.deadline,
234
+ claimant,
235
+ payoutTo,
236
+ allocation: params.allocation,
237
+ proof: params.proof,
238
+ campaignId: params.campaignId
239
+ };
240
+ }
241
+ /**
242
+ * Get the current nonce for claim meta-transactions
243
+ */
244
+ async getClaimNonce(campaignId, address) {
245
+ const result = await this.publicClient.readContract({
246
+ address: this.diamondAddress,
247
+ abi: diamond.DIAMOND_ABI,
248
+ functionName: "noncesClaim",
249
+ args: [campaignId, address]
250
+ });
251
+ return result;
252
+ }
253
+ // ============================================================================
254
+ // Claim Status Queries
255
+ // ============================================================================
256
+ /**
257
+ * Get the amount currently claimable for a recipient
258
+ *
259
+ * @example
260
+ * ```typescript
261
+ * const claimable = await sdk.claims.getClaimable(campaignId, recipientAddress);
262
+ * console.log('Claimable:', formatEther(claimable));
263
+ * ```
264
+ */
265
+ async getClaimable(campaignId, recipient) {
266
+ const result = await this.publicClient.readContract({
267
+ address: this.diamondAddress,
268
+ abi: diamond.DIAMOND_ABI,
269
+ functionName: "claimableOf",
270
+ args: [campaignId, recipient]
271
+ });
272
+ return result;
273
+ }
274
+ /**
275
+ * Check if a recipient is blocked from claiming
276
+ */
277
+ async isBlocked(campaignId, recipient) {
278
+ const result = await this.publicClient.readContract({
279
+ address: this.diamondAddress,
280
+ abi: diamond.DIAMOND_ABI,
281
+ functionName: "isBlocked",
282
+ args: [campaignId, recipient]
283
+ });
284
+ return result;
285
+ }
286
+ /**
287
+ * Get vested amount for a recipient (how much has vested so far)
288
+ */
289
+ async getVestedAmount(campaignId, recipient, allocation) {
290
+ const result = await this.publicClient.readContract({
291
+ address: this.diamondAddress,
292
+ abi: diamond.DIAMOND_ABI,
293
+ functionName: "vestedAmount",
294
+ args: [campaignId, recipient, allocation]
295
+ });
296
+ return result;
297
+ }
298
+ /**
299
+ * Get merkle claimed shares for a recipient
300
+ */
301
+ async getMerkleClaimedShares(campaignId, recipient) {
302
+ const result = await this.publicClient.readContract({
303
+ address: this.diamondAddress,
304
+ abi: diamond.DIAMOND_ABI,
305
+ functionName: "merkleClaimedShares",
306
+ args: [campaignId, recipient]
307
+ });
308
+ return result;
309
+ }
310
+ /**
311
+ * Get detailed recipient status for a campaign
312
+ */
313
+ async getRecipientStatus(campaignId, recipient, allocation) {
314
+ const [claimable, blocked, vested, claimed] = await Promise.all([
315
+ this.getClaimable(campaignId, recipient),
316
+ this.isBlocked(campaignId, recipient),
317
+ this.getVestedAmount(campaignId, recipient, allocation),
318
+ this.getMerkleClaimedShares(campaignId, recipient)
319
+ ]);
320
+ return {
321
+ allocated: allocation,
322
+ claimed,
323
+ due: claimable,
324
+ blocked,
325
+ fullyVested: vested >= allocation
326
+ };
327
+ }
328
+ /**
329
+ * Check if a recipient can claim from a campaign
330
+ */
331
+ async canClaim(campaignId, recipient) {
332
+ try {
333
+ const [claimable, blocked] = await Promise.all([
334
+ this.getClaimable(campaignId, recipient),
335
+ this.isBlocked(campaignId, recipient)
336
+ ]);
337
+ return claimable > 0n && !blocked;
338
+ } catch {
339
+ return false;
340
+ }
341
+ }
342
+ // ============================================================================
343
+ // Merkle Proof Helpers
344
+ // ============================================================================
345
+ /**
346
+ * Verify a Merkle proof locally
347
+ *
348
+ * Useful for validating proofs before submitting transactions.
349
+ */
350
+ verifyMerkleProof(root, leaf, proof) {
351
+ let computedHash = leaf;
352
+ for (const proofElement of proof) {
353
+ if (computedHash < proofElement) {
354
+ computedHash = viem.keccak256(
355
+ viem.encodePacked(["bytes32", "bytes32"], [computedHash, proofElement])
356
+ );
357
+ } else {
358
+ computedHash = viem.keccak256(
359
+ viem.encodePacked(["bytes32", "bytes32"], [proofElement, computedHash])
360
+ );
361
+ }
362
+ }
363
+ return computedHash === root;
364
+ }
365
+ /**
366
+ * Compute Merkle leaf for an allocation
367
+ */
368
+ computeMerkleLeaf(address, amount) {
369
+ return viem.keccak256(viem.encodePacked(["address", "uint256"], [address, amount]));
370
+ }
371
+ /**
372
+ * Compute proof hash for meta-transaction
373
+ */
374
+ computeProofHash(proof) {
375
+ if (proof.length === 0) {
376
+ return "0x0000000000000000000000000000000000000000000000000000000000000000";
377
+ }
378
+ return viem.keccak256(viem.encodePacked(["bytes32[]"], [proof]));
379
+ }
380
+ // ============================================================================
381
+ // Helpers
382
+ // ============================================================================
383
+ requireWallet() {
384
+ if (!this.walletClient) {
385
+ throw new Error(
386
+ "Wallet client required for write operations. Initialize SDK with a signer."
387
+ );
388
+ }
389
+ return this.walletClient;
390
+ }
391
+ createTransactionResult(hash) {
392
+ return {
393
+ hash,
394
+ wait: async () => {
395
+ const receipt = await this.publicClient.waitForTransactionReceipt({
396
+ hash
397
+ });
398
+ return {
399
+ blockNumber: receipt.blockNumber,
400
+ transactionHash: receipt.transactionHash,
401
+ gasUsed: receipt.gasUsed,
402
+ status: receipt.status,
403
+ logs: receipt.logs
404
+ };
405
+ }
406
+ };
407
+ }
408
+ };
409
+ var claims_default = ClaimsModule;
410
+
411
+ exports.ClaimsModule = ClaimsModule;
412
+ exports.default = claims_default;
413
+ //# sourceMappingURL=index.js.map
414
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/claims/index.ts"],"names":["DIAMOND_ABI","keccak256","encodePacked"],"mappings":";;;;;;;;AAwCO,IAAM,eAAN,MAAmB;AAAA,EACxB,WAAA,CACmB,YAAA,EACA,YAAA,EACA,cAAA,EACA,OAAA,EACjB;AAJiB,IAAA,IAAA,CAAA,YAAA,GAAA,YAAA;AACA,IAAA,IAAA,CAAA,YAAA,GAAA,YAAA;AACA,IAAA,IAAA,CAAA,cAAA,GAAA,cAAA;AACA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA6BH,MAAM,MAAM,MAAA,EAAiD;AAC3D,IAAA,MAAM,MAAA,GAAS,KAAK,aAAA,EAAc;AAElC,IAAA,IAAI,IAAA;AAEJ,IAAA,IAAI,OAAO,OAAA,EAAS;AAClB,MAAA,IAAA,GAAO,MAAM,OAAO,aAAA,CAAc;AAAA,QAChC,OAAO,MAAA,CAAO,KAAA;AAAA,QACd,SAAS,MAAA,CAAO,OAAA;AAAA,QAChB,SAAS,IAAA,CAAK,cAAA;AAAA,QACd,GAAA,EAAKA,mBAAA;AAAA,QACL,YAAA,EAAc,SAAA;AAAA,QACd,IAAA,EAAM;AAAA,UACJ,MAAA,CAAO,UAAA;AAAA,UACP,MAAA,CAAO,OAAA;AAAA,UACP,OAAO,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AK,YAAA,EAAc;AACtB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AACA,IAAA,OAAO,IAAA,CAAK,YAAA;AAAA,EACd;AAAA,EAEQ,wBAAwB,IAAA,EAA+B;AAC7D,IAAA,OAAO;AAAA,MACL,IAAA;AAAA,MACA,MAAM,YAAY;AAChB,QAAA,MAAM,OAAA,GAAU,MAAM,IAAA,CAAK,YAAA,CAAa,yBAAA,CAA0B;AAAA,UAChE;AAAA,SACD,CAAA;AACD,QAAA,OAAO;AAAA,UACL,aAAa,OAAA,CAAQ,WAAA;AAAA,UACrB,iBAAiB,OAAA,CAAQ,eAAA;AAAA,UACzB,SAAS,OAAA,CAAQ,OAAA;AAAA,UACjB,QAAQ,OAAA,CAAQ,MAAA;AAAA,UAChB,MAAM,OAAA,CAAQ;AAAA,SAChB;AAAA,MACF;AAAA,KACF;AAAA,EACF;AACF;AAEA,IAAO,cAAA,GAAQ","file":"index.js","sourcesContent":["/**\r\n * Claims Module\r\n *\r\n * Provides methods for claiming tokens from campaigns:\r\n * - Single claims (with merkle proof)\r\n * - Batch claims\r\n * - Meta-transaction (gasless) claims\r\n * - Lock releases\r\n */\r\nimport {\r\n type PublicClient,\r\n type WalletClient,\r\n type Address,\r\n type Hash,\r\n type Hex,\r\n keccak256,\r\n encodePacked,\r\n} from 'viem';\r\nimport { DIAMOND_ABI } from '@pepay-streams/abi/diamond';\r\nimport type {\r\n ClaimParams,\r\n BatchClaimParams,\r\n MetaClaimParams,\r\n RecipientStatus,\r\n TransactionResult,\r\n} from '../types';\r\n\r\n/**\r\n * EIP-712 domain for meta-transaction signatures\r\n */\r\ninterface EIP712Domain {\r\n name: string;\r\n version: string;\r\n chainId: number;\r\n verifyingContract: Address;\r\n}\r\n\r\n/**\r\n * Claims module for claiming tokens from distribution campaigns\r\n */\r\nexport class ClaimsModule {\r\n constructor(\r\n private readonly publicClient: PublicClient,\r\n private readonly walletClient: WalletClient | undefined,\r\n private readonly diamondAddress: Address,\r\n private readonly chainId: number\r\n ) {}\r\n\r\n // ============================================================================\r\n // Standard Claims\r\n // ============================================================================\r\n\r\n /**\r\n * Claim vested tokens from a campaign\r\n *\r\n * For merkle-tree campaigns, requires allocation and proof.\r\n * For direct campaigns, allocation should be 0 and proof empty.\r\n *\r\n * @example\r\n * ```typescript\r\n * // Direct campaign claim\r\n * const result = await sdk.claims.claim({\r\n * campaignId: 1n,\r\n * allocation: 0n,\r\n * proof: [],\r\n * });\r\n *\r\n * // Merkle campaign claim\r\n * const result = await sdk.claims.claim({\r\n * campaignId: 1n,\r\n * allocation: parseEther('100'),\r\n * proof: ['0x...', '0x...'],\r\n * });\r\n * ```\r\n */\r\n async claim(params: ClaimParams): Promise<TransactionResult> {\r\n const wallet = this.requireWallet();\r\n\r\n let hash: Hash;\r\n\r\n if (params.claimTo) {\r\n hash = await wallet.writeContract({\r\n chain: wallet.chain,\r\n account: wallet.account!,\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'claimTo',\r\n args: [\r\n params.campaignId,\r\n params.claimTo,\r\n params.allocation ?? 0n,\r\n params.proof ?? [],\r\n ],\r\n });\r\n } else {\r\n hash = await wallet.writeContract({\r\n chain: wallet.chain,\r\n account: wallet.account!,\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'claim',\r\n args: [\r\n params.campaignId,\r\n params.allocation ?? 0n,\r\n params.proof ?? [],\r\n ],\r\n });\r\n }\r\n\r\n return this.createTransactionResult(hash);\r\n }\r\n\r\n /**\r\n * Claim from a campaign for multiple recipients in a single transaction\r\n *\r\n * More gas efficient than multiple individual claims.\r\n * For direct allocation campaigns only.\r\n *\r\n * @example\r\n * ```typescript\r\n * const result = await sdk.claims.claimBatch({\r\n * campaignId: 1n,\r\n * recipients: ['0x...', '0x...', '0x...'],\r\n * });\r\n * ```\r\n */\r\n async claimBatch(params: BatchClaimParams): Promise<TransactionResult> {\r\n const wallet = this.requireWallet();\r\n\r\n const hash = await wallet.writeContract({\r\n chain: wallet.chain,\r\n account: wallet.account!,\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'claimMany',\r\n args: [params.campaignId, params.recipients],\r\n });\r\n\r\n return this.createTransactionResult(hash);\r\n }\r\n\r\n /**\r\n * Release locked tokens (for Lock campaigns)\r\n *\r\n * Can only be called after the unlock time has passed.\r\n *\r\n * @example\r\n * ```typescript\r\n * const result = await sdk.claims.releaseLock(campaignId, [recipient1, recipient2]);\r\n * ```\r\n */\r\n async releaseLock(\r\n campaignId: bigint,\r\n recipients: Address[]\r\n ): Promise<TransactionResult> {\r\n const wallet = this.requireWallet();\r\n\r\n const hash = await wallet.writeContract({\r\n chain: wallet.chain,\r\n account: wallet.account!,\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'releaseLock',\r\n args: [campaignId, recipients],\r\n });\r\n\r\n return this.createTransactionResult(hash);\r\n }\r\n\r\n // ============================================================================\r\n // Meta-Transaction Claims (Gasless)\r\n // ============================================================================\r\n\r\n /**\r\n * Claim via meta-transaction (gasless for recipient)\r\n *\r\n * A relayer submits the transaction on behalf of the recipient.\r\n * The recipient signs an EIP-712 message off-chain.\r\n *\r\n * @example\r\n * ```typescript\r\n * // Recipient signs off-chain\r\n * const signedAuth = await sdk.claims.signClaimMessage({\r\n * campaignId,\r\n * allocation: parseEther('100'),\r\n * proof: ['0x...'],\r\n * deadline: Math.floor(Date.now() / 1000) + 3600, // 1 hour\r\n * });\r\n *\r\n * // Relayer submits\r\n * const result = await sdk.claims.claimWithSig(signedAuth);\r\n * ```\r\n */\r\n async claimWithSig(params: MetaClaimParams): Promise<TransactionResult> {\r\n const wallet = this.requireWallet();\r\n\r\n const auth = {\r\n id: params.campaignId,\r\n claimant: params.claimant,\r\n payoutTo: params.payoutTo ?? params.claimant,\r\n allocation: params.allocation,\r\n proofHash: this.computeProofHash(params.proof),\r\n deadline: BigInt(params.deadline),\r\n nonce: params.nonce,\r\n };\r\n\r\n const hash = await wallet.writeContract({\r\n chain: wallet.chain,\r\n account: wallet.account!,\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'claimWithSig',\r\n args: [auth, params.proof, params.signature] as const,\r\n });\r\n\r\n return this.createTransactionResult(hash);\r\n }\r\n\r\n /**\r\n * Generate the EIP-712 typed data for a claim signature\r\n *\r\n * The recipient signs this message off-chain.\r\n */\r\n getClaimTypedData(\r\n campaignId: bigint,\r\n claimant: Address,\r\n payoutTo: Address,\r\n allocation: bigint,\r\n proofHash: Hex,\r\n nonce: bigint,\r\n deadline: number\r\n ): {\r\n domain: EIP712Domain;\r\n types: Record<string, { name: string; type: string }[]>;\r\n primaryType: string;\r\n message: Record<string, unknown>;\r\n } {\r\n return {\r\n domain: {\r\n name: 'PepayStreams',\r\n version: '1',\r\n chainId: this.chainId,\r\n verifyingContract: this.diamondAddress,\r\n },\r\n types: {\r\n ClaimAuth: [\r\n { name: 'id', type: 'uint256' },\r\n { name: 'claimant', type: 'address' },\r\n { name: 'payoutTo', type: 'address' },\r\n { name: 'allocation', type: 'uint128' },\r\n { name: 'proofHash', type: 'bytes32' },\r\n { name: 'deadline', type: 'uint64' },\r\n { name: 'nonce', type: 'uint256' },\r\n ],\r\n },\r\n primaryType: 'ClaimAuth',\r\n message: {\r\n id: campaignId,\r\n claimant,\r\n payoutTo,\r\n allocation,\r\n proofHash,\r\n deadline: BigInt(deadline),\r\n nonce,\r\n },\r\n };\r\n }\r\n\r\n /**\r\n * Sign a claim message for meta-transaction\r\n *\r\n * Returns the signature that can be submitted by a relayer.\r\n */\r\n async signClaimMessage(params: {\r\n campaignId: bigint;\r\n allocation: bigint;\r\n proof: Hex[];\r\n deadline: number;\r\n payoutTo?: Address;\r\n }): Promise<{\r\n signature: Hex;\r\n nonce: bigint;\r\n deadline: number;\r\n claimant: Address;\r\n payoutTo: Address;\r\n allocation: bigint;\r\n proof: Hex[];\r\n campaignId: bigint;\r\n }> {\r\n const wallet = this.requireWallet();\r\n const claimant = wallet.account!.address;\r\n const payoutTo = params.payoutTo ?? claimant;\r\n\r\n // Get current nonce\r\n const nonce = await this.getClaimNonce(params.campaignId, claimant);\r\n const proofHash = this.computeProofHash(params.proof);\r\n\r\n const typedData = this.getClaimTypedData(\r\n params.campaignId,\r\n claimant,\r\n payoutTo,\r\n params.allocation,\r\n proofHash,\r\n nonce,\r\n params.deadline\r\n );\r\n\r\n const signature = await wallet.signTypedData({\r\n account: wallet.account!,\r\n domain: typedData.domain,\r\n types: typedData.types,\r\n primaryType: typedData.primaryType as 'ClaimAuth',\r\n message: typedData.message,\r\n });\r\n\r\n return {\r\n signature,\r\n nonce,\r\n deadline: params.deadline,\r\n claimant,\r\n payoutTo,\r\n allocation: params.allocation,\r\n proof: params.proof,\r\n campaignId: params.campaignId,\r\n };\r\n }\r\n\r\n /**\r\n * Get the current nonce for claim meta-transactions\r\n */\r\n async getClaimNonce(campaignId: bigint, address: Address): Promise<bigint> {\r\n const result = await this.publicClient.readContract({\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'noncesClaim',\r\n args: [campaignId, address],\r\n });\r\n\r\n return result as bigint;\r\n }\r\n\r\n // ============================================================================\r\n // Claim Status Queries\r\n // ============================================================================\r\n\r\n /**\r\n * Get the amount currently claimable for a recipient\r\n *\r\n * @example\r\n * ```typescript\r\n * const claimable = await sdk.claims.getClaimable(campaignId, recipientAddress);\r\n * console.log('Claimable:', formatEther(claimable));\r\n * ```\r\n */\r\n async getClaimable(campaignId: bigint, recipient: Address): Promise<bigint> {\r\n const result = await this.publicClient.readContract({\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'claimableOf',\r\n args: [campaignId, recipient],\r\n });\r\n\r\n return result as bigint;\r\n }\r\n\r\n /**\r\n * Check if a recipient is blocked from claiming\r\n */\r\n async isBlocked(campaignId: bigint, recipient: Address): Promise<boolean> {\r\n const result = await this.publicClient.readContract({\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'isBlocked',\r\n args: [campaignId, recipient],\r\n });\r\n\r\n return result as boolean;\r\n }\r\n\r\n /**\r\n * Get vested amount for a recipient (how much has vested so far)\r\n */\r\n async getVestedAmount(\r\n campaignId: bigint,\r\n recipient: Address,\r\n allocation: bigint\r\n ): Promise<bigint> {\r\n const result = await this.publicClient.readContract({\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'vestedAmount',\r\n args: [campaignId, recipient, allocation],\r\n });\r\n\r\n return result as bigint;\r\n }\r\n\r\n /**\r\n * Get merkle claimed shares for a recipient\r\n */\r\n async getMerkleClaimedShares(\r\n campaignId: bigint,\r\n recipient: Address\r\n ): Promise<bigint> {\r\n const result = await this.publicClient.readContract({\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'merkleClaimedShares',\r\n args: [campaignId, recipient],\r\n });\r\n\r\n return result as bigint;\r\n }\r\n\r\n /**\r\n * Get detailed recipient status for a campaign\r\n */\r\n async getRecipientStatus(\r\n campaignId: bigint,\r\n recipient: Address,\r\n allocation: bigint\r\n ): Promise<RecipientStatus> {\r\n const [claimable, blocked, vested, claimed] = await Promise.all([\r\n this.getClaimable(campaignId, recipient),\r\n this.isBlocked(campaignId, recipient),\r\n this.getVestedAmount(campaignId, recipient, allocation),\r\n this.getMerkleClaimedShares(campaignId, recipient),\r\n ]);\r\n\r\n return {\r\n allocated: allocation,\r\n claimed,\r\n due: claimable,\r\n blocked,\r\n fullyVested: vested >= allocation,\r\n };\r\n }\r\n\r\n /**\r\n * Check if a recipient can claim from a campaign\r\n */\r\n async canClaim(campaignId: bigint, recipient: Address): Promise<boolean> {\r\n try {\r\n const [claimable, blocked] = await Promise.all([\r\n this.getClaimable(campaignId, recipient),\r\n this.isBlocked(campaignId, recipient),\r\n ]);\r\n return claimable > 0n && !blocked;\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n // ============================================================================\r\n // Merkle Proof Helpers\r\n // ============================================================================\r\n\r\n /**\r\n * Verify a Merkle proof locally\r\n *\r\n * Useful for validating proofs before submitting transactions.\r\n */\r\n verifyMerkleProof(root: Hex, leaf: Hex, proof: Hex[]): boolean {\r\n let computedHash = leaf;\r\n\r\n for (const proofElement of proof) {\r\n if (computedHash < proofElement) {\r\n computedHash = keccak256(\r\n encodePacked(['bytes32', 'bytes32'], [computedHash, proofElement])\r\n );\r\n } else {\r\n computedHash = keccak256(\r\n encodePacked(['bytes32', 'bytes32'], [proofElement, computedHash])\r\n );\r\n }\r\n }\r\n\r\n return computedHash === root;\r\n }\r\n\r\n /**\r\n * Compute Merkle leaf for an allocation\r\n */\r\n computeMerkleLeaf(address: Address, amount: bigint): Hex {\r\n return keccak256(encodePacked(['address', 'uint256'], [address, amount]));\r\n }\r\n\r\n /**\r\n * Compute proof hash for meta-transaction\r\n */\r\n computeProofHash(proof: Hex[]): Hex {\r\n if (proof.length === 0) {\r\n return '0x0000000000000000000000000000000000000000000000000000000000000000';\r\n }\r\n return keccak256(encodePacked(['bytes32[]'], [proof]));\r\n }\r\n\r\n // ============================================================================\r\n // Helpers\r\n // ============================================================================\r\n\r\n private requireWallet(): WalletClient {\r\n if (!this.walletClient) {\r\n throw new Error(\r\n 'Wallet client required for write operations. Initialize SDK with a signer.'\r\n );\r\n }\r\n return this.walletClient;\r\n }\r\n\r\n private createTransactionResult(hash: Hash): TransactionResult {\r\n return {\r\n hash,\r\n wait: async () => {\r\n const receipt = await this.publicClient.waitForTransactionReceipt({\r\n hash,\r\n });\r\n return {\r\n blockNumber: receipt.blockNumber,\r\n transactionHash: receipt.transactionHash,\r\n gasUsed: receipt.gasUsed,\r\n status: receipt.status,\r\n logs: receipt.logs,\r\n };\r\n },\r\n };\r\n }\r\n}\r\n\r\nexport default ClaimsModule;\r\n"]}