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