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,555 @@
1
+ import { Address, Hash, Hex } from 'viem';
2
+
3
+ /**
4
+ * Core types for Pepay Streams SDK
5
+ */
6
+
7
+ /**
8
+ * SDK configuration options
9
+ */
10
+ interface PepayStreamsConfig {
11
+ /** RPC URL for blockchain connection */
12
+ rpcUrl: string;
13
+ /** Diamond contract address */
14
+ diamondAddress: Address;
15
+ /** Chain ID (e.g., 1 for Ethereum, 56 for BSC, 31337 for local) */
16
+ chainId: number;
17
+ /** API base URL for indexed data (optional) */
18
+ apiBaseUrl?: string;
19
+ /** WETH address (auto-detected if not provided) */
20
+ wethAddress?: Address;
21
+ /** Permit2 address (canonical if not provided) */
22
+ permit2Address?: Address;
23
+ }
24
+ /**
25
+ * Transaction result from SDK operations
26
+ */
27
+ interface TransactionResult {
28
+ /** Transaction hash */
29
+ hash: Hash;
30
+ /** Wait for transaction confirmation */
31
+ wait: () => Promise<TransactionReceipt>;
32
+ }
33
+ /**
34
+ * Transaction receipt after confirmation
35
+ */
36
+ interface TransactionReceipt {
37
+ /** Block number */
38
+ blockNumber: bigint;
39
+ /** Transaction hash */
40
+ transactionHash: Hash;
41
+ /** Gas used */
42
+ gasUsed: bigint;
43
+ /** Status (1 = success, 0 = failed) */
44
+ status: 'success' | 'reverted';
45
+ /** Decoded logs/events */
46
+ logs: unknown[];
47
+ }
48
+ /**
49
+ * Recipient allocation in a campaign
50
+ */
51
+ interface Recipient {
52
+ /** Recipient wallet address */
53
+ address: Address;
54
+ /** Allocated amount in wei */
55
+ amount: bigint;
56
+ }
57
+ /**
58
+ * Recipient with cliff override for vested campaigns
59
+ */
60
+ interface RecipientWithCliff extends Recipient {
61
+ /** Optional cliff duration override in seconds */
62
+ cliffDuration?: number;
63
+ }
64
+ /**
65
+ * Recipient status from contract
66
+ */
67
+ interface RecipientStatus {
68
+ /** Total allocated to recipient */
69
+ allocated: bigint;
70
+ /** Amount already claimed */
71
+ claimed: bigint;
72
+ /** Amount currently due (claimable now) */
73
+ due: bigint;
74
+ /** Whether recipient is blocked */
75
+ blocked: boolean;
76
+ /** Whether recipient has claimed all */
77
+ fullyVested: boolean;
78
+ }
79
+ /**
80
+ * Base parameters for all campaign types
81
+ */
82
+ interface BaseCampaignParams {
83
+ /** Token to distribute */
84
+ token: Address;
85
+ /** Campaign name (max 32 bytes) - not stored on-chain */
86
+ name?: string;
87
+ /** Fee buffer for fee-on-transfer tokens in wei */
88
+ feeBuffer?: bigint;
89
+ /** Change policy for recipient updates */
90
+ changePolicy?: 'only_recipient' | 'only_creator' | 'both' | 'no_one';
91
+ /** Enable trading on marketplace */
92
+ attachDefaultRegistry?: boolean;
93
+ /** Whether campaign can be canceled */
94
+ cancelable?: boolean;
95
+ /** Whether recipients can only claim once */
96
+ claimOnce?: boolean;
97
+ /** Auto-claim incentive in basis points (for keepers) */
98
+ autoClaimIncentiveBps?: number;
99
+ /** Claim grace period in seconds */
100
+ claimGrace?: number;
101
+ /** Whether to unwrap WETH to native on claim */
102
+ unwrapWETH?: boolean;
103
+ /** WETH contract address (for unwrap feature) */
104
+ weth?: Address;
105
+ }
106
+ /**
107
+ * Parameters for creating an Instant Airdrop
108
+ */
109
+ interface InstantAirdropParams extends BaseCampaignParams {
110
+ /** List of recipients and amounts */
111
+ recipients: Recipient[];
112
+ }
113
+ /**
114
+ * Parameters for creating a Vested Airdrop
115
+ */
116
+ interface VestedAirdropParams extends BaseCampaignParams {
117
+ /** List of recipients and amounts */
118
+ recipients: RecipientWithCliff[];
119
+ /** Vesting start timestamp (Unix seconds) */
120
+ startTime: number;
121
+ /** Total vesting duration in seconds */
122
+ duration: number;
123
+ /** Cliff duration in seconds (tokens locked until cliff passes) */
124
+ cliffDuration?: number;
125
+ /** Number of vesting steps (releases are linear between steps) */
126
+ steps?: number;
127
+ /** Cliff release percentage in basis points (0-10000) */
128
+ cliffBps?: number;
129
+ }
130
+ /**
131
+ * Parameters for creating a Token Lock
132
+ */
133
+ interface LockParams extends BaseCampaignParams {
134
+ /** Recipient of the locked tokens */
135
+ recipient: Address;
136
+ /** Amount to lock in wei */
137
+ amount: bigint;
138
+ /** Unlock timestamp (Unix seconds) */
139
+ unlockTime: number;
140
+ }
141
+ /**
142
+ * Parameters for creating a Vesting stream (Payment)
143
+ */
144
+ interface VestingParams extends BaseCampaignParams {
145
+ /** Recipient of the vesting stream */
146
+ recipient: Address;
147
+ /** Total amount to vest in wei */
148
+ amount: bigint;
149
+ /** Vesting start timestamp (Unix seconds) */
150
+ startTime: number;
151
+ /** Total vesting duration in seconds */
152
+ duration: number;
153
+ /** Cliff duration in seconds */
154
+ cliffDuration?: number;
155
+ /** Number of vesting steps */
156
+ steps?: number;
157
+ /** Cliff release percentage in basis points (0-10000) */
158
+ cliffBps?: number;
159
+ /** Enable auto-withdraw automation */
160
+ enableAutoWithdraw?: boolean;
161
+ /** Auto-withdraw frequency in seconds */
162
+ autoWithdrawFrequency?: number;
163
+ }
164
+ /**
165
+ * Campaign info from contract
166
+ */
167
+ interface CampaignInfo {
168
+ /** Campaign ID */
169
+ id: bigint;
170
+ /** Campaign kind/type */
171
+ kind: 'instant_airdrop' | 'vested_airdrop' | 'lock' | 'vesting';
172
+ /** Token being distributed */
173
+ token: Address;
174
+ /** Campaign creator */
175
+ creator: Address;
176
+ /** Campaign name (not stored on-chain, may be empty) */
177
+ name: string;
178
+ /** Total allocated amount */
179
+ totalAllocated: bigint;
180
+ /** Total funded amount */
181
+ totalFunded: bigint;
182
+ /** Total claimed amount */
183
+ totalClaimed: bigint;
184
+ /** Total returned to creator */
185
+ totalReturned: bigint;
186
+ /** Fee loss from transfers */
187
+ feeLoss: bigint;
188
+ /** Fee buffer remaining */
189
+ feeBuffer: bigint;
190
+ /** Vesting start time */
191
+ startTime: number;
192
+ /** Vesting end time */
193
+ endTime: number;
194
+ /** Cliff end time */
195
+ cliffTime: number;
196
+ /** Number of vesting steps */
197
+ steps: number;
198
+ /** Number of recipients */
199
+ recipientCount: number;
200
+ /** Status bits (paused, finalized, etc.) */
201
+ statusBits: number;
202
+ /** Change policy */
203
+ changePolicy: number;
204
+ /** Whether automation is enabled */
205
+ hasAutomation: boolean;
206
+ /** Whether campaign has a trading registry attached */
207
+ hasRegistry?: boolean;
208
+ /** Merkle root for merkle-based campaigns */
209
+ merkleRoot?: Hex;
210
+ }
211
+ /**
212
+ * Parameters for creating a staking pool
213
+ */
214
+ interface CreatePoolParams {
215
+ /** Token users stake */
216
+ stakeToken: Address;
217
+ /** Token users earn as rewards */
218
+ rewardToken: Address;
219
+ /** Total reward budget in wei */
220
+ rewardBudget: bigint;
221
+ /** Pool duration in seconds */
222
+ duration: number;
223
+ /** Minimum stake amount (optional) */
224
+ minStake?: bigint;
225
+ /** Maximum stake per user (optional, 0 = unlimited) */
226
+ maxStake?: bigint;
227
+ /** Pool name for identification */
228
+ name?: string;
229
+ }
230
+ /**
231
+ * Staking pool info from contract
232
+ */
233
+ interface PoolInfo {
234
+ /** Pool ID */
235
+ id: bigint;
236
+ /** Token being staked */
237
+ stakeToken: Address;
238
+ /** Reward token */
239
+ rewardToken: Address;
240
+ /** Pool creator */
241
+ creator: Address;
242
+ /** Total staked amount */
243
+ totalStaked: bigint;
244
+ /** Total reward budget */
245
+ rewardBudget: bigint;
246
+ /** Rewards distributed so far */
247
+ rewardsDistributed: bigint;
248
+ /** Pool start time */
249
+ startTime: number;
250
+ /** Pool end time */
251
+ endTime: number;
252
+ /** Minimum stake amount */
253
+ minStake: bigint;
254
+ /** Maximum stake per user */
255
+ maxStake: bigint;
256
+ /** Number of stakers */
257
+ stakerCount: number;
258
+ /** Whether pool is active */
259
+ isActive: boolean;
260
+ /** Whether pool is finalized */
261
+ isFinalized: boolean;
262
+ }
263
+ /**
264
+ * User stake info
265
+ */
266
+ interface UserStake {
267
+ /** Amount staked */
268
+ amount: bigint;
269
+ /** Pending rewards */
270
+ pendingRewards: bigint;
271
+ /** Last claim timestamp */
272
+ lastClaimTime: number;
273
+ /** Stake start time */
274
+ stakeTime: number;
275
+ }
276
+ /**
277
+ * Order type for marketplace
278
+ */
279
+ type OrderType = 'instant' | 'vested' | 'tradable';
280
+ /**
281
+ * Parameters for creating an INSTANT order
282
+ */
283
+ interface CreateInstantOrderParams {
284
+ /** Token to sell */
285
+ sellToken: Address;
286
+ /** Amount to sell in wei */
287
+ sellAmount: bigint;
288
+ /** Token to receive as payment */
289
+ payToken: Address;
290
+ /** Price per token in pay token wei */
291
+ pricePerToken: bigint;
292
+ /** Private buyers (empty = public) */
293
+ privateBuyers?: Address[];
294
+ /** Order expiry TTL in seconds */
295
+ expiryTTL?: number;
296
+ }
297
+ /**
298
+ * Parameters for creating a VESTED order
299
+ */
300
+ interface CreateVestedOrderParams extends CreateInstantOrderParams {
301
+ /** Vesting duration in seconds */
302
+ vestingDuration: number;
303
+ /** Cliff duration in seconds */
304
+ cliffDuration?: number;
305
+ /** Start mode: when vesting starts */
306
+ startMode?: 'upon_fill' | 'fixed_timestamp';
307
+ /** Fixed start timestamp (if startMode is fixed_timestamp) */
308
+ fixedStartTime?: number;
309
+ }
310
+ /**
311
+ * Parameters for creating a TRADABLE order (listing unvested position)
312
+ */
313
+ interface CreateTradableOrderParams {
314
+ /** Campaign ID to list position from */
315
+ campaignId: bigint;
316
+ /** Price per token in pay token wei */
317
+ pricePerToken: bigint;
318
+ /** Token to receive as payment (use zero address for native) */
319
+ payToken: Address;
320
+ /** Private buyers (empty = public) */
321
+ privateBuyers?: Address[];
322
+ /** Order expiry TTL in seconds */
323
+ expiryTTL?: number;
324
+ }
325
+ /**
326
+ * Marketplace order info
327
+ */
328
+ interface OrderInfo {
329
+ /** Order ID */
330
+ id: bigint;
331
+ /** Order type */
332
+ orderType: OrderType;
333
+ /** Seller address */
334
+ seller: Address;
335
+ /** Token being sold */
336
+ sellToken: Address;
337
+ /** Amount being sold */
338
+ sellAmount: bigint;
339
+ /** Payment token */
340
+ payToken: Address;
341
+ /** Total price */
342
+ totalPrice: bigint;
343
+ /** Price per token */
344
+ pricePerToken: bigint;
345
+ /** Order status */
346
+ status: 'open' | 'filled' | 'canceled' | 'expired';
347
+ /** Buyer (if filled) */
348
+ buyer?: Address;
349
+ /** Creation timestamp */
350
+ createdAt: number;
351
+ /** Expiry timestamp */
352
+ expiresAt: number;
353
+ /** Associated campaign ID (for tradable) */
354
+ campaignId?: bigint;
355
+ /** Vesting params (for vested orders) */
356
+ vestingDuration?: number;
357
+ cliffDuration?: number;
358
+ }
359
+ /**
360
+ * Quote for filling an order
361
+ */
362
+ interface OrderQuote {
363
+ /** Order ID */
364
+ orderId: bigint;
365
+ /** Total price to pay */
366
+ totalPrice: bigint;
367
+ /** Protocol fee */
368
+ protocolFee: bigint;
369
+ /** Amount buyer receives */
370
+ buyerReceives: bigint;
371
+ /** Amount seller receives after fees */
372
+ sellerReceives: bigint;
373
+ /** Whether order is still valid */
374
+ isValid: boolean;
375
+ /** Expiry timestamp */
376
+ expiresAt: number;
377
+ }
378
+ /**
379
+ * Parameters for enabling auto-withdraw
380
+ */
381
+ interface EnableAutoWithdrawParams {
382
+ /** Campaign ID */
383
+ campaignId: bigint;
384
+ /** Frequency in seconds between auto-withdraws */
385
+ frequency: number;
386
+ /** Tip amount in native wei for keeper */
387
+ tipAmount?: bigint;
388
+ }
389
+ /**
390
+ * Parameters for enabling auto-release (locks)
391
+ */
392
+ interface EnableAutoReleaseParams {
393
+ /** Campaign ID (must be a Lock) */
394
+ campaignId: bigint;
395
+ /** Tip amount in native wei for keeper */
396
+ tipAmount?: bigint;
397
+ }
398
+ /**
399
+ * Automation status for a campaign
400
+ */
401
+ interface AutomationStatus {
402
+ /** Whether automation is enabled */
403
+ enabled: boolean;
404
+ /** Last run timestamp */
405
+ lastRun: number;
406
+ /** Next eligible run timestamp */
407
+ nextRun: number;
408
+ /** Frequency between runs */
409
+ frequency: number;
410
+ /** Remaining tip balance */
411
+ tipBalance: bigint;
412
+ /** Number of recipients processed */
413
+ recipientsProcessed: number;
414
+ /** Total recipients */
415
+ totalRecipients: number;
416
+ }
417
+ /**
418
+ * Claim parameters
419
+ *
420
+ * For direct campaigns, allocation should be 0n and proof should be empty [].
421
+ * For merkle campaigns, provide allocation and proof.
422
+ */
423
+ interface ClaimParams {
424
+ /** Campaign ID */
425
+ campaignId: bigint;
426
+ /** Allocation amount for merkle claims (0 for direct campaigns) */
427
+ allocation?: bigint;
428
+ /** Merkle proof (empty array for direct campaigns) */
429
+ proof?: Hex[];
430
+ /** Claim to specific address (optional, defaults to caller) */
431
+ claimTo?: Address;
432
+ }
433
+ /**
434
+ * Batch claim parameters - claims for multiple recipients in a single campaign
435
+ */
436
+ interface BatchClaimParams {
437
+ /** Campaign ID */
438
+ campaignId: bigint;
439
+ /** List of recipients to claim for */
440
+ recipients: Address[];
441
+ }
442
+ /**
443
+ * Meta-transaction claim parameters (gasless)
444
+ *
445
+ * All fields from the ClaimAuth struct required for signature verification.
446
+ */
447
+ interface MetaClaimParams {
448
+ /** Campaign ID */
449
+ campaignId: bigint;
450
+ /** Claimant address (who is claiming) */
451
+ claimant: Address;
452
+ /** Payout destination (optional, defaults to claimant) */
453
+ payoutTo?: Address;
454
+ /** Allocation amount */
455
+ allocation: bigint;
456
+ /** Merkle proof (empty array for direct campaigns) */
457
+ proof: Hex[];
458
+ /** EIP-712 signature from claimant */
459
+ signature: Hex;
460
+ /** Signature deadline timestamp (Unix seconds) */
461
+ deadline: number;
462
+ /** Nonce for replay protection */
463
+ nonce: bigint;
464
+ }
465
+ /**
466
+ * Merkle claim parameters
467
+ */
468
+ interface MerkleClaimParams {
469
+ /** Campaign ID */
470
+ campaignId: bigint;
471
+ /** Claimable amount */
472
+ amount: bigint;
473
+ /** Merkle proof */
474
+ proof: Hex[];
475
+ }
476
+ /**
477
+ * Claim result
478
+ */
479
+ interface ClaimResult {
480
+ /** Transaction hash */
481
+ hash: Hash;
482
+ /** Amount claimed (gross) */
483
+ grossAmount: bigint;
484
+ /** Amount received (net, after any token fees) */
485
+ netAmount: bigint;
486
+ /** Whether fee was waived due to token issues */
487
+ feeWaived: boolean;
488
+ }
489
+ /**
490
+ * Paginated response wrapper
491
+ */
492
+ interface PaginatedResponse<T> {
493
+ /** Data items */
494
+ data: T[];
495
+ /** Total count */
496
+ total: number;
497
+ /** Current page */
498
+ page: number;
499
+ /** Items per page */
500
+ pageSize: number;
501
+ /** Whether more pages exist */
502
+ hasMore: boolean;
503
+ }
504
+ /**
505
+ * API campaign response (from indexed data)
506
+ */
507
+ interface ApiCampaign {
508
+ id: string;
509
+ chainId: number;
510
+ kind: string;
511
+ token: Address;
512
+ creator: Address;
513
+ name: string;
514
+ totalAllocated: string;
515
+ totalClaimed: string;
516
+ recipientCount: number;
517
+ startTime: string;
518
+ endTime: string;
519
+ createdAt: string;
520
+ status: string;
521
+ }
522
+ /**
523
+ * API order response (from indexed data)
524
+ */
525
+ interface ApiOrder {
526
+ id: string;
527
+ chainId: number;
528
+ orderType: string;
529
+ seller: Address;
530
+ sellToken: Address;
531
+ sellAmount: string;
532
+ payToken: Address;
533
+ totalPrice: string;
534
+ status: string;
535
+ createdAt: string;
536
+ expiresAt: string;
537
+ }
538
+ /**
539
+ * API staking pool response (from indexed data)
540
+ */
541
+ interface ApiStakingPool {
542
+ id: string;
543
+ chainId: number;
544
+ stakeToken: Address;
545
+ rewardToken: Address;
546
+ creator: Address;
547
+ totalStaked: string;
548
+ rewardBudget: string;
549
+ startTime: string;
550
+ endTime: string;
551
+ isActive: boolean;
552
+ stakerCount: number;
553
+ }
554
+
555
+ export type { AutomationStatus as A, BatchClaimParams as B, CampaignInfo as C, EnableAutoWithdrawParams as E, InstantAirdropParams as I, LockParams as L, MetaClaimParams as M, OrderInfo as O, PepayStreamsConfig as P, RecipientStatus as R, TransactionResult as T, UserStake as U, VestedAirdropParams as V, VestingParams as a, ClaimParams as b, PoolInfo as c, CreateInstantOrderParams as d, CreateVestedOrderParams as e, CreateTradableOrderParams as f, OrderQuote as g, EnableAutoReleaseParams as h, PaginatedResponse as i, ApiCampaign as j, ApiOrder as k, ApiStakingPool as l, TransactionReceipt as m, Recipient as n, RecipientWithCliff as o, BaseCampaignParams as p, CreatePoolParams as q, OrderType as r, MerkleClaimParams as s, ClaimResult as t };