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,645 @@
1
+ import { zeroAddress } from 'viem';
2
+ import { DIAMOND_ABI } from '@pepay-streams/abi/diamond';
3
+
4
+ // src/campaigns/index.ts
5
+ var CampaignKind = /* @__PURE__ */ ((CampaignKind2) => {
6
+ CampaignKind2[CampaignKind2["INSTANT"] = 0] = "INSTANT";
7
+ CampaignKind2[CampaignKind2["VESTED"] = 1] = "VESTED";
8
+ CampaignKind2[CampaignKind2["LOCK"] = 2] = "LOCK";
9
+ CampaignKind2[CampaignKind2["VESTING"] = 3] = "VESTING";
10
+ return CampaignKind2;
11
+ })(CampaignKind || {});
12
+ var ChangePolicy = /* @__PURE__ */ ((ChangePolicy2) => {
13
+ ChangePolicy2[ChangePolicy2["ONLY_RECIPIENT"] = 0] = "ONLY_RECIPIENT";
14
+ ChangePolicy2[ChangePolicy2["ONLY_CREATOR"] = 1] = "ONLY_CREATOR";
15
+ ChangePolicy2[ChangePolicy2["BOTH"] = 2] = "BOTH";
16
+ ChangePolicy2[ChangePolicy2["NO_ONE"] = 3] = "NO_ONE";
17
+ return ChangePolicy2;
18
+ })(ChangePolicy || {});
19
+ var CampaignsModule = class {
20
+ constructor(publicClient, walletClient, diamondAddress) {
21
+ this.publicClient = publicClient;
22
+ this.walletClient = walletClient;
23
+ this.diamondAddress = diamondAddress;
24
+ }
25
+ // ============================================================================
26
+ // Campaign Creation
27
+ // ============================================================================
28
+ /**
29
+ * Create an Instant Airdrop campaign
30
+ *
31
+ * Tokens are immediately claimable by recipients after funding.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const result = await sdk.campaigns.createInstantAirdrop({
36
+ * token: '0x...',
37
+ * recipients: [
38
+ * { address: '0x...', amount: parseEther('100') },
39
+ * { address: '0x...', amount: parseEther('50') },
40
+ * ],
41
+ * });
42
+ * console.log('Campaign created, tx:', result.hash);
43
+ * ```
44
+ */
45
+ async createInstantAirdrop(params) {
46
+ const wallet = this.requireWallet();
47
+ const recipients = params.recipients.map((r) => r.address);
48
+ const amounts = params.recipients.map((r) => r.amount);
49
+ const now = BigInt(Math.floor(Date.now() / 1e3));
50
+ const args = {
51
+ kind: 0 /* INSTANT */,
52
+ token: params.token,
53
+ start: now,
54
+ end: now,
55
+ // Instant airdrop - same start/end
56
+ step: 0n,
57
+ cliffReleaseTime: 0n,
58
+ cliffBps: 0,
59
+ autoClaimIncentiveBps: params.autoClaimIncentiveBps ?? 0,
60
+ cancelable: params.cancelable ?? true,
61
+ claimOnce: params.claimOnce ?? true,
62
+ changePolicy: this.changePolicyToEnum(params.changePolicy),
63
+ claimGrace: BigInt(params.claimGrace ?? 0),
64
+ recipients,
65
+ amounts,
66
+ feeBuffer: params.feeBuffer ?? 0n,
67
+ attachDefaultRegistry: params.attachDefaultRegistry ?? false,
68
+ unwrapWETH: params.unwrapWETH ?? false,
69
+ weth: params.weth ?? zeroAddress
70
+ };
71
+ const hash = await wallet.writeContract({
72
+ chain: wallet.chain,
73
+ account: wallet.account,
74
+ address: this.diamondAddress,
75
+ abi: DIAMOND_ABI,
76
+ functionName: "createCampaign",
77
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
+ args: [args]
79
+ });
80
+ return this.createTransactionResult(hash);
81
+ }
82
+ /**
83
+ * Create a Vested Airdrop campaign
84
+ *
85
+ * Tokens vest linearly over time with optional cliff period.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const result = await sdk.campaigns.createVestedAirdrop({
90
+ * token: '0x...',
91
+ * recipients: [
92
+ * { address: '0x...', amount: parseEther('1000') },
93
+ * ],
94
+ * startTime: Math.floor(Date.now() / 1000), // Start now
95
+ * duration: 365 * 24 * 60 * 60, // 1 year
96
+ * cliffDuration: 90 * 24 * 60 * 60, // 3 month cliff
97
+ * steps: 12, // Monthly releases
98
+ * });
99
+ * ```
100
+ */
101
+ async createVestedAirdrop(params) {
102
+ const wallet = this.requireWallet();
103
+ const recipients = params.recipients.map((r) => r.address);
104
+ const amounts = params.recipients.map((r) => r.amount);
105
+ const startTime = BigInt(params.startTime);
106
+ const endTime = startTime + BigInt(params.duration);
107
+ const steps = params.steps ?? 1;
108
+ const step = steps > 1 ? BigInt(params.duration) / BigInt(steps) : 0n;
109
+ const cliffReleaseTime = params.cliffDuration ? startTime + BigInt(params.cliffDuration) : 0n;
110
+ const args = {
111
+ kind: 1 /* VESTED */,
112
+ token: params.token,
113
+ start: startTime,
114
+ end: endTime,
115
+ step,
116
+ cliffReleaseTime,
117
+ cliffBps: params.cliffBps ?? 0,
118
+ autoClaimIncentiveBps: params.autoClaimIncentiveBps ?? 0,
119
+ cancelable: params.cancelable ?? true,
120
+ claimOnce: false,
121
+ // Vested can claim multiple times
122
+ changePolicy: this.changePolicyToEnum(params.changePolicy),
123
+ claimGrace: BigInt(params.claimGrace ?? 0),
124
+ recipients,
125
+ amounts,
126
+ feeBuffer: params.feeBuffer ?? 0n,
127
+ attachDefaultRegistry: params.attachDefaultRegistry ?? false,
128
+ unwrapWETH: params.unwrapWETH ?? false,
129
+ weth: params.weth ?? zeroAddress
130
+ };
131
+ const hash = await wallet.writeContract({
132
+ chain: wallet.chain,
133
+ account: wallet.account,
134
+ address: this.diamondAddress,
135
+ abi: DIAMOND_ABI,
136
+ functionName: "createCampaign",
137
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
138
+ args: [args]
139
+ });
140
+ return this.createTransactionResult(hash);
141
+ }
142
+ /**
143
+ * Create a Token Lock
144
+ *
145
+ * Tokens are locked until a specific unlock time, then fully releasable.
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * const result = await sdk.campaigns.createLock({
150
+ * token: '0x...',
151
+ * recipient: '0x...',
152
+ * amount: parseEther('1000000'),
153
+ * unlockTime: Math.floor(Date.now() / 1000) + 180 * 24 * 60 * 60, // 6 months
154
+ * });
155
+ * ```
156
+ */
157
+ async createLock(params) {
158
+ const wallet = this.requireWallet();
159
+ const now = BigInt(Math.floor(Date.now() / 1e3));
160
+ const unlockTime = BigInt(params.unlockTime);
161
+ const args = {
162
+ kind: 2 /* LOCK */,
163
+ token: params.token,
164
+ start: now,
165
+ end: unlockTime,
166
+ step: 0n,
167
+ cliffReleaseTime: unlockTime,
168
+ // Lock releases at this time
169
+ cliffBps: 1e4,
170
+ // 100% released at cliff
171
+ autoClaimIncentiveBps: 0,
172
+ cancelable: params.cancelable ?? false,
173
+ claimOnce: true,
174
+ changePolicy: this.changePolicyToEnum(params.changePolicy),
175
+ claimGrace: 0n,
176
+ recipients: [params.recipient],
177
+ amounts: [params.amount],
178
+ feeBuffer: params.feeBuffer ?? 0n,
179
+ attachDefaultRegistry: false,
180
+ unwrapWETH: params.unwrapWETH ?? false,
181
+ weth: params.weth ?? zeroAddress
182
+ };
183
+ const hash = await wallet.writeContract({
184
+ chain: wallet.chain,
185
+ account: wallet.account,
186
+ address: this.diamondAddress,
187
+ abi: DIAMOND_ABI,
188
+ functionName: "createCampaign",
189
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
190
+ args: [args]
191
+ });
192
+ return this.createTransactionResult(hash);
193
+ }
194
+ /**
195
+ * Create a Vesting Stream (Payment)
196
+ *
197
+ * Single-recipient vesting with optional automation.
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * const result = await sdk.campaigns.createVesting({
202
+ * token: '0x...',
203
+ * recipient: '0x...',
204
+ * amount: parseEther('120000'), // 120k tokens
205
+ * startTime: Math.floor(Date.now() / 1000),
206
+ * duration: 365 * 24 * 60 * 60, // 1 year
207
+ * cliffDuration: 0, // No cliff
208
+ * steps: 12, // Monthly
209
+ * });
210
+ * ```
211
+ */
212
+ async createVesting(params) {
213
+ const wallet = this.requireWallet();
214
+ const startTime = BigInt(params.startTime);
215
+ const endTime = startTime + BigInt(params.duration);
216
+ const steps = params.steps ?? 1;
217
+ const step = steps > 1 ? BigInt(params.duration) / BigInt(steps) : 0n;
218
+ const cliffReleaseTime = params.cliffDuration ? startTime + BigInt(params.cliffDuration) : 0n;
219
+ const args = {
220
+ kind: 3 /* VESTING */,
221
+ token: params.token,
222
+ start: startTime,
223
+ end: endTime,
224
+ step,
225
+ cliffReleaseTime,
226
+ cliffBps: params.cliffBps ?? 0,
227
+ autoClaimIncentiveBps: params.autoClaimIncentiveBps ?? 0,
228
+ cancelable: params.cancelable ?? true,
229
+ claimOnce: false,
230
+ changePolicy: this.changePolicyToEnum(params.changePolicy),
231
+ claimGrace: BigInt(params.claimGrace ?? 0),
232
+ recipients: [params.recipient],
233
+ amounts: [params.amount],
234
+ feeBuffer: params.feeBuffer ?? 0n,
235
+ attachDefaultRegistry: false,
236
+ unwrapWETH: params.unwrapWETH ?? false,
237
+ weth: params.weth ?? zeroAddress
238
+ };
239
+ const hash = await wallet.writeContract({
240
+ chain: wallet.chain,
241
+ account: wallet.account,
242
+ address: this.diamondAddress,
243
+ abi: DIAMOND_ABI,
244
+ functionName: "createCampaign",
245
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
246
+ args: [args]
247
+ });
248
+ return this.createTransactionResult(hash);
249
+ }
250
+ /**
251
+ * Create a campaign with raw CreateArgs
252
+ *
253
+ * Low-level function for full control over campaign parameters.
254
+ */
255
+ async createCampaign(args) {
256
+ const wallet = this.requireWallet();
257
+ const hash = await wallet.writeContract({
258
+ chain: wallet.chain,
259
+ account: wallet.account,
260
+ address: this.diamondAddress,
261
+ abi: DIAMOND_ABI,
262
+ functionName: "createCampaign",
263
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
264
+ args: [args]
265
+ });
266
+ return this.createTransactionResult(hash);
267
+ }
268
+ // ============================================================================
269
+ // Campaign Funding
270
+ // ============================================================================
271
+ /**
272
+ * Fund a campaign using EIP-2612 Permit (gasless approval)
273
+ *
274
+ * @example
275
+ * ```typescript
276
+ * const result = await sdk.campaigns.fundWithPermit({
277
+ * campaignId,
278
+ * amount: parseEther('1000'),
279
+ * deadline: Math.floor(Date.now() / 1000) + 3600,
280
+ * v: 28,
281
+ * r: '0x...',
282
+ * s: '0x...',
283
+ * });
284
+ * ```
285
+ */
286
+ async fundWithPermit(params) {
287
+ const wallet = this.requireWallet();
288
+ const hash = await wallet.writeContract({
289
+ chain: wallet.chain,
290
+ account: wallet.account,
291
+ address: this.diamondAddress,
292
+ abi: DIAMOND_ABI,
293
+ functionName: "fundWithPermit",
294
+ args: [
295
+ params.campaignId,
296
+ params.amount,
297
+ params.deadline,
298
+ params.v,
299
+ params.r,
300
+ params.s
301
+ ]
302
+ });
303
+ return this.createTransactionResult(hash);
304
+ }
305
+ /**
306
+ * Fund a campaign using Permit2 (gasless approval)
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * const result = await sdk.campaigns.fundWithPermit2({
311
+ * campaignId,
312
+ * from: userAddress,
313
+ * amount: parseEther('1000'),
314
+ * permit2Data: encodedPermit2Data,
315
+ * });
316
+ * ```
317
+ */
318
+ async fundWithPermit2(params) {
319
+ const wallet = this.requireWallet();
320
+ const hash = await wallet.writeContract({
321
+ chain: wallet.chain,
322
+ account: wallet.account,
323
+ address: this.diamondAddress,
324
+ abi: DIAMOND_ABI,
325
+ functionName: "fundWithPermit2",
326
+ args: [
327
+ params.campaignId,
328
+ params.from,
329
+ params.amount,
330
+ params.permit2Data
331
+ ]
332
+ });
333
+ return this.createTransactionResult(hash);
334
+ }
335
+ /**
336
+ * Return leftover tokens to creator
337
+ *
338
+ * @example
339
+ * ```typescript
340
+ * const result = await sdk.campaigns.returnLeftover(campaignId, parseEther('100'));
341
+ * ```
342
+ */
343
+ async returnLeftover(campaignId, amountToReturn) {
344
+ const wallet = this.requireWallet();
345
+ const hash = await wallet.writeContract({
346
+ chain: wallet.chain,
347
+ account: wallet.account,
348
+ address: this.diamondAddress,
349
+ abi: DIAMOND_ABI,
350
+ functionName: "returnLeftover",
351
+ args: [campaignId, amountToReturn]
352
+ });
353
+ return this.createTransactionResult(hash);
354
+ }
355
+ /**
356
+ * Add native tips to a campaign for automation
357
+ */
358
+ async addNativeTips(campaignId, tipAmount) {
359
+ const wallet = this.requireWallet();
360
+ const hash = await wallet.writeContract({
361
+ chain: wallet.chain,
362
+ account: wallet.account,
363
+ address: this.diamondAddress,
364
+ abi: DIAMOND_ABI,
365
+ functionName: "addNativeTips",
366
+ args: [campaignId, tipAmount],
367
+ value: tipAmount
368
+ });
369
+ return this.createTransactionResult(hash);
370
+ }
371
+ // ============================================================================
372
+ // Campaign Queries
373
+ // ============================================================================
374
+ /**
375
+ * Get campaign summary by ID
376
+ *
377
+ * Returns full campaign configuration and state.
378
+ *
379
+ * @example
380
+ * ```typescript
381
+ * const campaign = await sdk.campaigns.getCampaign(1n);
382
+ * console.log('Campaign token:', campaign.token);
383
+ * console.log('Total claimed:', campaign.totalClaimed);
384
+ * ```
385
+ */
386
+ async getCampaign(campaignId) {
387
+ const result = await this.publicClient.readContract({
388
+ address: this.diamondAddress,
389
+ abi: DIAMOND_ABI,
390
+ functionName: "campaignSummary",
391
+ args: [campaignId]
392
+ });
393
+ return this.parseCampaignSummary(campaignId, result);
394
+ }
395
+ /**
396
+ * Get campaign configuration only
397
+ */
398
+ async getCampaignConfig(campaignId) {
399
+ const result = await this.publicClient.readContract({
400
+ address: this.diamondAddress,
401
+ abi: DIAMOND_ABI,
402
+ functionName: "campaignConfig",
403
+ args: [campaignId]
404
+ });
405
+ return {
406
+ kind: Number(result.kind),
407
+ cancelable: Boolean(result.cancelable),
408
+ claimOnce: Boolean(result.claimOnce),
409
+ canceled: Boolean(result.canceled),
410
+ changePolicy: Number(result.changePolicy),
411
+ token: result.token,
412
+ creator: result.creator,
413
+ cliffBps: Number(result.cliffBps),
414
+ autoClaimIncentiveBps: Number(result.autoClaimIncentiveBps),
415
+ start: Number(result.start),
416
+ end: Number(result.end),
417
+ step: Number(result.step),
418
+ canceledAt: Number(result.canceledAt),
419
+ cliffReleaseTime: Number(result.cliffReleaseTime),
420
+ claimGrace: Number(result.claimGrace),
421
+ unwrapWETH: Boolean(result.unwrapWETH),
422
+ weth: result.weth
423
+ };
424
+ }
425
+ /**
426
+ * Get campaign state (totals and accounting)
427
+ */
428
+ async getCampaignState(campaignId) {
429
+ const result = await this.publicClient.readContract({
430
+ address: this.diamondAddress,
431
+ abi: DIAMOND_ABI,
432
+ functionName: "campaignState",
433
+ args: [campaignId]
434
+ });
435
+ return {
436
+ totalAllocated: result.totalAllocated,
437
+ totalClaimed: result.totalClaimed,
438
+ nativeTips: result.nativeTips,
439
+ returned: result.returned,
440
+ feeBuffer: result.feeBuffer,
441
+ feeLoss: result.feeLoss,
442
+ totalFunded: result.totalFunded,
443
+ statusBits: Number(result.statusBits),
444
+ uniqueRecipients: result.uniqueRecipients
445
+ };
446
+ }
447
+ /**
448
+ * Get campaign status bits
449
+ */
450
+ async getCampaignStatus(campaignId) {
451
+ const result = await this.publicClient.readContract({
452
+ address: this.diamondAddress,
453
+ abi: DIAMOND_ABI,
454
+ functionName: "campaignStatus",
455
+ args: [campaignId]
456
+ });
457
+ return Number(result);
458
+ }
459
+ // ============================================================================
460
+ // Campaign Administration
461
+ // ============================================================================
462
+ /**
463
+ * Pause a campaign (creator or admin only)
464
+ *
465
+ * @param campaignId - Campaign ID
466
+ * @param reason - Pause reason as status bits (e.g., 1 for creator pause)
467
+ */
468
+ async pause(campaignId, reason = 1) {
469
+ const wallet = this.requireWallet();
470
+ const hash = await wallet.writeContract({
471
+ chain: wallet.chain,
472
+ account: wallet.account,
473
+ address: this.diamondAddress,
474
+ abi: DIAMOND_ABI,
475
+ functionName: "pauseCampaign",
476
+ args: [campaignId, reason]
477
+ });
478
+ return this.createTransactionResult(hash);
479
+ }
480
+ /**
481
+ * Resume a paused campaign
482
+ *
483
+ * @param campaignId - Campaign ID
484
+ * @param clearBits - Status bits to clear (e.g., 1 for creator pause)
485
+ */
486
+ async resume(campaignId, clearBits = 1) {
487
+ const wallet = this.requireWallet();
488
+ const hash = await wallet.writeContract({
489
+ chain: wallet.chain,
490
+ account: wallet.account,
491
+ address: this.diamondAddress,
492
+ abi: DIAMOND_ABI,
493
+ functionName: "resumeCampaign",
494
+ args: [campaignId, clearBits]
495
+ });
496
+ return this.createTransactionResult(hash);
497
+ }
498
+ /**
499
+ * Finalize a campaign (no more claims possible)
500
+ */
501
+ async finalize(campaignId) {
502
+ const wallet = this.requireWallet();
503
+ const hash = await wallet.writeContract({
504
+ chain: wallet.chain,
505
+ account: wallet.account,
506
+ address: this.diamondAddress,
507
+ abi: DIAMOND_ABI,
508
+ functionName: "finalizeCampaign",
509
+ args: [campaignId]
510
+ });
511
+ return this.createTransactionResult(hash);
512
+ }
513
+ /**
514
+ * Cancel a campaign and return funds to creator
515
+ */
516
+ async cancel(campaignId) {
517
+ const wallet = this.requireWallet();
518
+ const hash = await wallet.writeContract({
519
+ chain: wallet.chain,
520
+ account: wallet.account,
521
+ address: this.diamondAddress,
522
+ abi: DIAMOND_ABI,
523
+ functionName: "cancel",
524
+ args: [campaignId]
525
+ });
526
+ return this.createTransactionResult(hash);
527
+ }
528
+ /**
529
+ * Change a recipient address (for blocked recipients)
530
+ */
531
+ async changeRecipient(campaignId, fromAddress, toAddress) {
532
+ const wallet = this.requireWallet();
533
+ const hash = await wallet.writeContract({
534
+ chain: wallet.chain,
535
+ account: wallet.account,
536
+ address: this.diamondAddress,
537
+ abi: DIAMOND_ABI,
538
+ functionName: "changeRecipient",
539
+ args: [campaignId, fromAddress, toAddress]
540
+ });
541
+ return this.createTransactionResult(hash);
542
+ }
543
+ /**
544
+ * Add recipients to an existing campaign
545
+ */
546
+ async addRecipients(campaignId, recipients, amounts, additionalBuffer = 0n) {
547
+ const wallet = this.requireWallet();
548
+ const hash = await wallet.writeContract({
549
+ chain: wallet.chain,
550
+ account: wallet.account,
551
+ address: this.diamondAddress,
552
+ abi: DIAMOND_ABI,
553
+ functionName: "addRecipients",
554
+ args: [campaignId, recipients, amounts, additionalBuffer]
555
+ });
556
+ return this.createTransactionResult(hash);
557
+ }
558
+ // ============================================================================
559
+ // Helpers
560
+ // ============================================================================
561
+ requireWallet() {
562
+ if (!this.walletClient) {
563
+ throw new Error(
564
+ "Wallet client required for write operations. Initialize SDK with a signer."
565
+ );
566
+ }
567
+ return this.walletClient;
568
+ }
569
+ changePolicyToEnum(policy) {
570
+ switch (policy) {
571
+ case "only_recipient":
572
+ return 0 /* ONLY_RECIPIENT */;
573
+ case "only_creator":
574
+ return 1 /* ONLY_CREATOR */;
575
+ case "both":
576
+ return 2 /* BOTH */;
577
+ case "no_one":
578
+ return 3 /* NO_ONE */;
579
+ default:
580
+ return 0 /* ONLY_RECIPIENT */;
581
+ }
582
+ }
583
+ parseCampaignSummary(id, data) {
584
+ const cfg = data.cfg;
585
+ const state = data.state;
586
+ const kindMap = {
587
+ 0: "instant_airdrop",
588
+ 1: "vested_airdrop",
589
+ 2: "lock",
590
+ 3: "vesting"
591
+ };
592
+ const kind = Number(cfg.kind);
593
+ const result = {
594
+ id,
595
+ kind: kindMap[kind] ?? "instant_airdrop",
596
+ token: cfg.token,
597
+ creator: cfg.creator,
598
+ name: "",
599
+ // Not stored on-chain
600
+ totalAllocated: state.totalAllocated,
601
+ totalFunded: state.totalFunded,
602
+ totalClaimed: state.totalClaimed,
603
+ totalReturned: state.returned,
604
+ feeLoss: state.feeLoss,
605
+ feeBuffer: state.feeBuffer,
606
+ startTime: Number(cfg.start),
607
+ endTime: Number(cfg.end),
608
+ cliffTime: Number(cfg.cliffReleaseTime),
609
+ steps: Number(cfg.step) > 0 ? Math.ceil((Number(cfg.end) - Number(cfg.start)) / Number(cfg.step)) : 1,
610
+ recipientCount: Number(state.uniqueRecipients),
611
+ statusBits: Number(state.statusBits),
612
+ changePolicy: Number(cfg.changePolicy),
613
+ hasAutomation: (Number(state.statusBits) & 1 << 5) !== 0
614
+ };
615
+ if (data.hasRegistry) {
616
+ result.hasRegistry = true;
617
+ }
618
+ if (data.merkleRoot) {
619
+ result.merkleRoot = data.merkleRoot;
620
+ }
621
+ return result;
622
+ }
623
+ createTransactionResult(hash) {
624
+ return {
625
+ hash,
626
+ wait: async () => {
627
+ const receipt = await this.publicClient.waitForTransactionReceipt({
628
+ hash
629
+ });
630
+ return {
631
+ blockNumber: receipt.blockNumber,
632
+ transactionHash: receipt.transactionHash,
633
+ gasUsed: receipt.gasUsed,
634
+ status: receipt.status,
635
+ logs: receipt.logs
636
+ };
637
+ }
638
+ };
639
+ }
640
+ };
641
+ var campaigns_default = CampaignsModule;
642
+
643
+ export { CampaignKind, CampaignsModule, ChangePolicy, campaigns_default as default };
644
+ //# sourceMappingURL=index.mjs.map
645
+ //# sourceMappingURL=index.mjs.map