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.
- package/README.md +405 -0
- package/dist/api/index.d.mts +321 -0
- package/dist/api/index.d.ts +321 -0
- package/dist/api/index.js +312 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/index.mjs +306 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/automation/index.d.mts +140 -0
- package/dist/automation/index.d.ts +140 -0
- package/dist/automation/index.js +331 -0
- package/dist/automation/index.js.map +1 -0
- package/dist/automation/index.mjs +326 -0
- package/dist/automation/index.mjs.map +1 -0
- package/dist/campaigns/index.d.mts +286 -0
- package/dist/campaigns/index.d.ts +286 -0
- package/dist/campaigns/index.js +652 -0
- package/dist/campaigns/index.js.map +1 -0
- package/dist/campaigns/index.mjs +645 -0
- package/dist/campaigns/index.mjs.map +1 -0
- package/dist/claims/index.d.mts +190 -0
- package/dist/claims/index.d.ts +190 -0
- package/dist/claims/index.js +414 -0
- package/dist/claims/index.js.map +1 -0
- package/dist/claims/index.mjs +409 -0
- package/dist/claims/index.mjs.map +1 -0
- package/dist/index-BTG0TRJt.d.mts +555 -0
- package/dist/index-BTG0TRJt.d.ts +555 -0
- package/dist/index.d.mts +170 -0
- package/dist/index.d.ts +170 -0
- package/dist/index.js +2926 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2888 -0
- package/dist/index.mjs.map +1 -0
- package/dist/marketplace/index.d.mts +225 -0
- package/dist/marketplace/index.d.ts +225 -0
- package/dist/marketplace/index.js +529 -0
- package/dist/marketplace/index.js.map +1 -0
- package/dist/marketplace/index.mjs +524 -0
- package/dist/marketplace/index.mjs.map +1 -0
- package/dist/react/index.d.mts +185 -0
- package/dist/react/index.d.ts +185 -0
- package/dist/react/index.js +340 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +333 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/staking/index.d.mts +158 -0
- package/dist/staking/index.d.ts +158 -0
- package/dist/staking/index.js +359 -0
- package/dist/staking/index.js.map +1 -0
- package/dist/staking/index.mjs +354 -0
- package/dist/staking/index.mjs.map +1 -0
- package/package.json +106 -0
- package/src/api/index.ts +577 -0
- package/src/automation/index.ts +436 -0
- package/src/campaigns/index.ts +835 -0
- package/src/claims/index.ts +530 -0
- package/src/client.ts +518 -0
- package/src/index.ts +101 -0
- package/src/marketplace/index.ts +730 -0
- package/src/react/index.ts +498 -0
- package/src/staking/index.ts +449 -0
- package/src/types/index.ts +631 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { DIAMOND_ABI } from '@pepay-streams/abi/diamond';
|
|
2
|
+
|
|
3
|
+
// src/automation/index.ts
|
|
4
|
+
var AutomationModule = class {
|
|
5
|
+
constructor(publicClient, walletClient, diamondAddress) {
|
|
6
|
+
this.publicClient = publicClient;
|
|
7
|
+
this.walletClient = walletClient;
|
|
8
|
+
this.diamondAddress = diamondAddress;
|
|
9
|
+
}
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Auto-Withdraw (for Vesting campaigns)
|
|
12
|
+
// ============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Enable auto-withdraw for a vesting campaign
|
|
15
|
+
*
|
|
16
|
+
* Keepers will automatically claim vested tokens on behalf of recipients.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const result = await sdk.automation.enableAutoWithdraw({
|
|
21
|
+
* campaignId: 1n,
|
|
22
|
+
* frequency: 7 * 24 * 60 * 60, // Weekly
|
|
23
|
+
* tipAmount: parseEther('0.1'), // 0.1 ETH for keeper
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
async enableAutoWithdraw(params) {
|
|
28
|
+
const wallet = this.requireWallet();
|
|
29
|
+
const hash = await wallet.writeContract({
|
|
30
|
+
chain: wallet.chain,
|
|
31
|
+
account: wallet.account,
|
|
32
|
+
address: this.diamondAddress,
|
|
33
|
+
abi: DIAMOND_ABI,
|
|
34
|
+
functionName: "enableAutoWithdraw",
|
|
35
|
+
args: [params.campaignId, BigInt(params.frequency)],
|
|
36
|
+
value: params.tipAmount ?? 0n
|
|
37
|
+
});
|
|
38
|
+
return this.createTransactionResult(hash);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Disable auto-withdraw for a campaign
|
|
42
|
+
*
|
|
43
|
+
* Returns remaining tip balance to caller.
|
|
44
|
+
*/
|
|
45
|
+
async disableAutoWithdraw(campaignId) {
|
|
46
|
+
const wallet = this.requireWallet();
|
|
47
|
+
const hash = await wallet.writeContract({
|
|
48
|
+
chain: wallet.chain,
|
|
49
|
+
account: wallet.account,
|
|
50
|
+
address: this.diamondAddress,
|
|
51
|
+
abi: DIAMOND_ABI,
|
|
52
|
+
functionName: "disableAutoWithdraw",
|
|
53
|
+
args: [campaignId]
|
|
54
|
+
});
|
|
55
|
+
return this.createTransactionResult(hash);
|
|
56
|
+
}
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// Auto-Release (for Lock campaigns)
|
|
59
|
+
// ============================================================================
|
|
60
|
+
/**
|
|
61
|
+
* Enable auto-release for a lock campaign
|
|
62
|
+
*
|
|
63
|
+
* Keepers will automatically release tokens when unlock time passes.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const result = await sdk.automation.enableAutoRelease({
|
|
68
|
+
* campaignId: 5n,
|
|
69
|
+
* frequency: 3600, // Check every hour
|
|
70
|
+
* tipAmount: parseEther('0.05'), // 0.05 ETH for keeper
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
async enableAutoRelease(params) {
|
|
75
|
+
const wallet = this.requireWallet();
|
|
76
|
+
const frequency = params.frequency ?? 3600;
|
|
77
|
+
const hash = await wallet.writeContract({
|
|
78
|
+
chain: wallet.chain,
|
|
79
|
+
account: wallet.account,
|
|
80
|
+
address: this.diamondAddress,
|
|
81
|
+
abi: DIAMOND_ABI,
|
|
82
|
+
functionName: "enableAutoReleaseLock",
|
|
83
|
+
args: [params.campaignId, BigInt(frequency)],
|
|
84
|
+
value: params.tipAmount ?? 0n
|
|
85
|
+
});
|
|
86
|
+
return this.createTransactionResult(hash);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Disable auto-release for a lock campaign
|
|
90
|
+
*/
|
|
91
|
+
async disableAutoRelease(campaignId) {
|
|
92
|
+
const wallet = this.requireWallet();
|
|
93
|
+
const hash = await wallet.writeContract({
|
|
94
|
+
chain: wallet.chain,
|
|
95
|
+
account: wallet.account,
|
|
96
|
+
address: this.diamondAddress,
|
|
97
|
+
abi: DIAMOND_ABI,
|
|
98
|
+
functionName: "disableAutoReleaseLock",
|
|
99
|
+
args: [campaignId]
|
|
100
|
+
});
|
|
101
|
+
return this.createTransactionResult(hash);
|
|
102
|
+
}
|
|
103
|
+
// ============================================================================
|
|
104
|
+
// Automation Status Queries
|
|
105
|
+
// ============================================================================
|
|
106
|
+
/**
|
|
107
|
+
* Get auto-withdraw status for a campaign
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const status = await sdk.automation.getAutoWithdrawStatus(campaignId);
|
|
112
|
+
* console.log('Enabled:', status.enabled);
|
|
113
|
+
* console.log('Next run:', new Date(status.nextRun * 1000));
|
|
114
|
+
* console.log('Tip balance:', formatEther(status.tipBalance));
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
async getAutoWithdrawStatus(campaignId) {
|
|
118
|
+
const [config, pendingCount, cursor] = await Promise.all([
|
|
119
|
+
this.publicClient.readContract({
|
|
120
|
+
address: this.diamondAddress,
|
|
121
|
+
abi: DIAMOND_ABI,
|
|
122
|
+
functionName: "automationConfig",
|
|
123
|
+
args: [campaignId]
|
|
124
|
+
}),
|
|
125
|
+
this.publicClient.readContract({
|
|
126
|
+
address: this.diamondAddress,
|
|
127
|
+
abi: DIAMOND_ABI,
|
|
128
|
+
functionName: "recipientsPending",
|
|
129
|
+
args: [campaignId]
|
|
130
|
+
}),
|
|
131
|
+
this.publicClient.readContract({
|
|
132
|
+
address: this.diamondAddress,
|
|
133
|
+
abi: DIAMOND_ABI,
|
|
134
|
+
functionName: "regCursor",
|
|
135
|
+
args: [campaignId]
|
|
136
|
+
})
|
|
137
|
+
]);
|
|
138
|
+
const [enabled, frequency, lastRun] = config;
|
|
139
|
+
const nextRun = Number(lastRun) + Number(frequency);
|
|
140
|
+
return {
|
|
141
|
+
enabled,
|
|
142
|
+
lastRun: Number(lastRun),
|
|
143
|
+
nextRun,
|
|
144
|
+
frequency: Number(frequency),
|
|
145
|
+
tipBalance: 0n,
|
|
146
|
+
// Tip balance is managed internally
|
|
147
|
+
recipientsProcessed: Number(cursor),
|
|
148
|
+
totalRecipients: Number(pendingCount) + Number(cursor)
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get auto-release status for a lock campaign
|
|
153
|
+
*/
|
|
154
|
+
async getAutoReleaseStatus(campaignId) {
|
|
155
|
+
const config = await this.publicClient.readContract({
|
|
156
|
+
address: this.diamondAddress,
|
|
157
|
+
abi: DIAMOND_ABI,
|
|
158
|
+
functionName: "automationLockConfig",
|
|
159
|
+
args: [campaignId]
|
|
160
|
+
});
|
|
161
|
+
const [enabled, frequency, lastRun] = config;
|
|
162
|
+
const nextRun = Number(lastRun) + Number(frequency);
|
|
163
|
+
return {
|
|
164
|
+
enabled,
|
|
165
|
+
frequency: Number(frequency),
|
|
166
|
+
lastRun: Number(lastRun),
|
|
167
|
+
nextRun
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Preview automation for specific recipients
|
|
172
|
+
*/
|
|
173
|
+
async previewAutomation(campaignId, recipients) {
|
|
174
|
+
const result = await this.publicClient.readContract({
|
|
175
|
+
address: this.diamondAddress,
|
|
176
|
+
abi: DIAMOND_ABI,
|
|
177
|
+
functionName: "automationPreviewFor",
|
|
178
|
+
args: [campaignId, recipients]
|
|
179
|
+
});
|
|
180
|
+
return {
|
|
181
|
+
pendingCount: result[0],
|
|
182
|
+
nextFeeWei: result[1],
|
|
183
|
+
escrowWei: result[2]
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Get automation run statistics
|
|
188
|
+
*/
|
|
189
|
+
async getAutomationStats(campaignId, lockMode = false) {
|
|
190
|
+
const result = await this.publicClient.readContract({
|
|
191
|
+
address: this.diamondAddress,
|
|
192
|
+
abi: DIAMOND_ABI,
|
|
193
|
+
functionName: "automationRunStats",
|
|
194
|
+
args: [campaignId, lockMode]
|
|
195
|
+
});
|
|
196
|
+
return {
|
|
197
|
+
runsObserved: Number(result.runsObserved),
|
|
198
|
+
avgRecipientsPerRun: Number(result.avgRecipientsPerRun),
|
|
199
|
+
lastRecipientsProcessed: Number(result.lastRecipientsProcessed),
|
|
200
|
+
maxRecipientsPerRun: Number(result.maxRecipientsPerRun)
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Check if auto-withdraw is currently runnable
|
|
205
|
+
*
|
|
206
|
+
* Returns true if cooldown has passed and there are pending recipients.
|
|
207
|
+
*/
|
|
208
|
+
async isAutoWithdrawRunnable(campaignId) {
|
|
209
|
+
const status = await this.getAutoWithdrawStatus(campaignId);
|
|
210
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
211
|
+
return status.enabled && now >= status.nextRun && status.recipientsProcessed < status.totalRecipients;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Check if auto-release is currently runnable
|
|
215
|
+
*/
|
|
216
|
+
async isAutoReleaseRunnable(campaignId) {
|
|
217
|
+
const status = await this.getAutoReleaseStatus(campaignId);
|
|
218
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
219
|
+
return status.enabled && now >= status.nextRun;
|
|
220
|
+
}
|
|
221
|
+
// ============================================================================
|
|
222
|
+
// Keeper Functions (for automation operators)
|
|
223
|
+
// ============================================================================
|
|
224
|
+
/**
|
|
225
|
+
* Execute auto-withdraw for specific recipients (keeper only)
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```typescript
|
|
229
|
+
* // Get recipients from registry or external source
|
|
230
|
+
* const recipients = ['0x...', '0x...', '0x...'];
|
|
231
|
+
* await sdk.automation.executeAutoWithdraw(campaignId, recipients);
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
async executeAutoWithdraw(campaignId, recipients) {
|
|
235
|
+
const wallet = this.requireWallet();
|
|
236
|
+
const hash = await wallet.writeContract({
|
|
237
|
+
chain: wallet.chain,
|
|
238
|
+
account: wallet.account,
|
|
239
|
+
address: this.diamondAddress,
|
|
240
|
+
abi: DIAMOND_ABI,
|
|
241
|
+
functionName: "autoWithdraw",
|
|
242
|
+
args: [campaignId, recipients]
|
|
243
|
+
});
|
|
244
|
+
return this.createTransactionResult(hash);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Execute auto-withdraw using registry cursor (keeper only)
|
|
248
|
+
*
|
|
249
|
+
* Processes up to batchSize recipients from the registry.
|
|
250
|
+
*/
|
|
251
|
+
async executeAutoWithdrawNext(campaignId, batchSize = 50) {
|
|
252
|
+
const wallet = this.requireWallet();
|
|
253
|
+
const hash = await wallet.writeContract({
|
|
254
|
+
chain: wallet.chain,
|
|
255
|
+
account: wallet.account,
|
|
256
|
+
address: this.diamondAddress,
|
|
257
|
+
abi: DIAMOND_ABI,
|
|
258
|
+
functionName: "autoWithdrawNext",
|
|
259
|
+
args: [campaignId, BigInt(batchSize)]
|
|
260
|
+
});
|
|
261
|
+
return this.createTransactionResult(hash);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Execute auto-release for specific recipients (keeper only)
|
|
265
|
+
*/
|
|
266
|
+
async executeAutoRelease(campaignId, recipients) {
|
|
267
|
+
const wallet = this.requireWallet();
|
|
268
|
+
const hash = await wallet.writeContract({
|
|
269
|
+
chain: wallet.chain,
|
|
270
|
+
account: wallet.account,
|
|
271
|
+
address: this.diamondAddress,
|
|
272
|
+
abi: DIAMOND_ABI,
|
|
273
|
+
functionName: "autoReleaseLock",
|
|
274
|
+
args: [campaignId, recipients]
|
|
275
|
+
});
|
|
276
|
+
return this.createTransactionResult(hash);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Execute auto-release using registry cursor (keeper only)
|
|
280
|
+
*/
|
|
281
|
+
async executeAutoReleaseNext(campaignId, batchSize = 50) {
|
|
282
|
+
const wallet = this.requireWallet();
|
|
283
|
+
const hash = await wallet.writeContract({
|
|
284
|
+
chain: wallet.chain,
|
|
285
|
+
account: wallet.account,
|
|
286
|
+
address: this.diamondAddress,
|
|
287
|
+
abi: DIAMOND_ABI,
|
|
288
|
+
functionName: "autoReleaseLockNext",
|
|
289
|
+
args: [campaignId, BigInt(batchSize)]
|
|
290
|
+
});
|
|
291
|
+
return this.createTransactionResult(hash);
|
|
292
|
+
}
|
|
293
|
+
// ============================================================================
|
|
294
|
+
// Helpers
|
|
295
|
+
// ============================================================================
|
|
296
|
+
requireWallet() {
|
|
297
|
+
if (!this.walletClient) {
|
|
298
|
+
throw new Error(
|
|
299
|
+
"Wallet client required for write operations. Initialize SDK with a signer."
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
return this.walletClient;
|
|
303
|
+
}
|
|
304
|
+
createTransactionResult(hash) {
|
|
305
|
+
return {
|
|
306
|
+
hash,
|
|
307
|
+
wait: async () => {
|
|
308
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({
|
|
309
|
+
hash
|
|
310
|
+
});
|
|
311
|
+
return {
|
|
312
|
+
blockNumber: receipt.blockNumber,
|
|
313
|
+
transactionHash: receipt.transactionHash,
|
|
314
|
+
gasUsed: receipt.gasUsed,
|
|
315
|
+
status: receipt.status,
|
|
316
|
+
logs: receipt.logs
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
var automation_default = AutomationModule;
|
|
323
|
+
|
|
324
|
+
export { AutomationModule, automation_default as default };
|
|
325
|
+
//# sourceMappingURL=index.mjs.map
|
|
326
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/automation/index.ts"],"names":[],"mappings":";;;AAyBO,IAAM,mBAAN,MAAuB;AAAA,EAC5B,WAAA,CACmB,YAAA,EACA,YAAA,EACA,cAAA,EACjB;AAHiB,IAAA,IAAA,CAAA,YAAA,GAAA,YAAA;AACA,IAAA,IAAA,CAAA,YAAA,GAAA,YAAA;AACA,IAAA,IAAA,CAAA,cAAA,GAAA,cAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBH,MAAM,mBACJ,MAAA,EAC4B;AAC5B,IAAA,MAAM,MAAA,GAAS,KAAK,aAAA,EAAc;AAElC,IAAA,MAAM,IAAA,GAAO,MAAM,MAAA,CAAO,aAAA,CAAc;AAAA,MACtC,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,SAAS,MAAA,CAAO,OAAA;AAAA,MAChB,SAAS,IAAA,CAAK,cAAA;AAAA,MACd,GAAA,EAAK,WAAA;AAAA,MACL,YAAA,EAAc,oBAAA;AAAA,MACd,MAAM,CAAC,MAAA,CAAO,YAAY,MAAA,CAAO,MAAA,CAAO,SAAS,CAAC,CAAA;AAAA,MAClD,KAAA,EAAO,OAAO,SAAA,IAAa;AAAA,KAC5B,CAAA;AAED,IAAA,OAAO,IAAA,CAAK,wBAAwB,IAAI,CAAA;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,oBAAoB,UAAA,EAAgD;AACxE,IAAA,MAAM,MAAA,GAAS,KAAK,aAAA,EAAc;AAElC,IA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a,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,kBAAA,GAAQ","file":"index.mjs","sourcesContent":["/**\r\n * Automation Module\r\n *\r\n * Provides methods for keeper automation:\r\n * - Enable/disable auto-withdraw for vesting campaigns\r\n * - Enable/disable auto-release for locks\r\n * - Query automation status\r\n */\r\nimport {\r\n type PublicClient,\r\n type WalletClient,\r\n type Address,\r\n type Hash,\r\n} from 'viem';\r\nimport { DIAMOND_ABI } from '@pepay-streams/abi/diamond';\r\nimport type {\r\n EnableAutoWithdrawParams,\r\n EnableAutoReleaseParams,\r\n AutomationStatus,\r\n TransactionResult,\r\n} from '../types';\r\n\r\n/**\r\n * Automation module for keeper-powered operations\r\n */\r\nexport class AutomationModule {\r\n constructor(\r\n private readonly publicClient: PublicClient,\r\n private readonly walletClient: WalletClient | undefined,\r\n private readonly diamondAddress: Address\r\n ) {}\r\n\r\n // ============================================================================\r\n // Auto-Withdraw (for Vesting campaigns)\r\n // ============================================================================\r\n\r\n /**\r\n * Enable auto-withdraw for a vesting campaign\r\n *\r\n * Keepers will automatically claim vested tokens on behalf of recipients.\r\n *\r\n * @example\r\n * ```typescript\r\n * const result = await sdk.automation.enableAutoWithdraw({\r\n * campaignId: 1n,\r\n * frequency: 7 * 24 * 60 * 60, // Weekly\r\n * tipAmount: parseEther('0.1'), // 0.1 ETH for keeper\r\n * });\r\n * ```\r\n */\r\n async enableAutoWithdraw(\r\n params: EnableAutoWithdrawParams\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: 'enableAutoWithdraw',\r\n args: [params.campaignId, BigInt(params.frequency)],\r\n value: params.tipAmount ?? 0n,\r\n });\r\n\r\n return this.createTransactionResult(hash);\r\n }\r\n\r\n /**\r\n * Disable auto-withdraw for a campaign\r\n *\r\n * Returns remaining tip balance to caller.\r\n */\r\n async disableAutoWithdraw(campaignId: bigint): 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: 'disableAutoWithdraw',\r\n args: [campaignId],\r\n });\r\n\r\n return this.createTransactionResult(hash);\r\n }\r\n\r\n // ============================================================================\r\n // Auto-Release (for Lock campaigns)\r\n // ============================================================================\r\n\r\n /**\r\n * Enable auto-release for a lock campaign\r\n *\r\n * Keepers will automatically release tokens when unlock time passes.\r\n *\r\n * @example\r\n * ```typescript\r\n * const result = await sdk.automation.enableAutoRelease({\r\n * campaignId: 5n,\r\n * frequency: 3600, // Check every hour\r\n * tipAmount: parseEther('0.05'), // 0.05 ETH for keeper\r\n * });\r\n * ```\r\n */\r\n async enableAutoRelease(\r\n params: EnableAutoReleaseParams & { frequency?: number }\r\n ): Promise<TransactionResult> {\r\n const wallet = this.requireWallet();\r\n\r\n // Default frequency of 1 hour if not specified\r\n const frequency = params.frequency ?? 3600;\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: 'enableAutoReleaseLock',\r\n args: [params.campaignId, BigInt(frequency)],\r\n value: params.tipAmount ?? 0n,\r\n });\r\n\r\n return this.createTransactionResult(hash);\r\n }\r\n\r\n /**\r\n * Disable auto-release for a lock campaign\r\n */\r\n async disableAutoRelease(campaignId: bigint): 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: 'disableAutoReleaseLock',\r\n args: [campaignId],\r\n });\r\n\r\n return this.createTransactionResult(hash);\r\n }\r\n\r\n // ============================================================================\r\n // Automation Status Queries\r\n // ============================================================================\r\n\r\n /**\r\n * Get auto-withdraw status for a campaign\r\n *\r\n * @example\r\n * ```typescript\r\n * const status = await sdk.automation.getAutoWithdrawStatus(campaignId);\r\n * console.log('Enabled:', status.enabled);\r\n * console.log('Next run:', new Date(status.nextRun * 1000));\r\n * console.log('Tip balance:', formatEther(status.tipBalance));\r\n * ```\r\n */\r\n async getAutoWithdrawStatus(campaignId: bigint): Promise<AutomationStatus> {\r\n const [config, pendingCount, cursor] = await Promise.all([\r\n this.publicClient.readContract({\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'automationConfig',\r\n args: [campaignId],\r\n }) as Promise<[boolean, bigint, bigint]>,\r\n this.publicClient.readContract({\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'recipientsPending',\r\n args: [campaignId],\r\n }) as Promise<bigint>,\r\n this.publicClient.readContract({\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'regCursor',\r\n args: [campaignId],\r\n }) as Promise<bigint>,\r\n ]);\r\n\r\n const [enabled, frequency, lastRun] = config;\r\n const nextRun = Number(lastRun) + Number(frequency);\r\n\r\n return {\r\n enabled,\r\n lastRun: Number(lastRun),\r\n nextRun,\r\n frequency: Number(frequency),\r\n tipBalance: 0n, // Tip balance is managed internally\r\n recipientsProcessed: Number(cursor),\r\n totalRecipients: Number(pendingCount) + Number(cursor),\r\n };\r\n }\r\n\r\n /**\r\n * Get auto-release status for a lock campaign\r\n */\r\n async getAutoReleaseStatus(campaignId: bigint): Promise<{\r\n enabled: boolean;\r\n frequency: number;\r\n lastRun: number;\r\n nextRun: number;\r\n }> {\r\n const config = await this.publicClient.readContract({\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'automationLockConfig',\r\n args: [campaignId],\r\n }) as [boolean, bigint, bigint];\r\n\r\n const [enabled, frequency, lastRun] = config;\r\n const nextRun = Number(lastRun) + Number(frequency);\r\n\r\n return {\r\n enabled,\r\n frequency: Number(frequency),\r\n lastRun: Number(lastRun),\r\n nextRun,\r\n };\r\n }\r\n\r\n /**\r\n * Preview automation for specific recipients\r\n */\r\n async previewAutomation(\r\n campaignId: bigint,\r\n recipients: Address[]\r\n ): Promise<{\r\n pendingCount: bigint;\r\n nextFeeWei: bigint;\r\n escrowWei: bigint;\r\n }> {\r\n const result = await this.publicClient.readContract({\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'automationPreviewFor',\r\n args: [campaignId, recipients],\r\n }) as [bigint, bigint, bigint];\r\n\r\n return {\r\n pendingCount: result[0],\r\n nextFeeWei: result[1],\r\n escrowWei: result[2],\r\n };\r\n }\r\n\r\n /**\r\n * Get automation run statistics\r\n */\r\n async getAutomationStats(\r\n campaignId: bigint,\r\n lockMode = false\r\n ): Promise<{\r\n runsObserved: number;\r\n avgRecipientsPerRun: number;\r\n lastRecipientsProcessed: number;\r\n maxRecipientsPerRun: number;\r\n }> {\r\n const result = await this.publicClient.readContract({\r\n address: this.diamondAddress,\r\n abi: DIAMOND_ABI,\r\n functionName: 'automationRunStats',\r\n args: [campaignId, lockMode],\r\n }) as {\r\n runsObserved: bigint;\r\n avgRecipientsPerRun: bigint;\r\n lastRecipientsProcessed: bigint;\r\n maxRecipientsPerRun: bigint;\r\n };\r\n\r\n return {\r\n runsObserved: Number(result.runsObserved),\r\n avgRecipientsPerRun: Number(result.avgRecipientsPerRun),\r\n lastRecipientsProcessed: Number(result.lastRecipientsProcessed),\r\n maxRecipientsPerRun: Number(result.maxRecipientsPerRun),\r\n };\r\n }\r\n\r\n /**\r\n * Check if auto-withdraw is currently runnable\r\n *\r\n * Returns true if cooldown has passed and there are pending recipients.\r\n */\r\n async isAutoWithdrawRunnable(campaignId: bigint): Promise<boolean> {\r\n const status = await this.getAutoWithdrawStatus(campaignId);\r\n const now = Math.floor(Date.now() / 1000);\r\n\r\n return (\r\n status.enabled &&\r\n now >= status.nextRun &&\r\n status.recipientsProcessed < status.totalRecipients\r\n );\r\n }\r\n\r\n /**\r\n * Check if auto-release is currently runnable\r\n */\r\n async isAutoReleaseRunnable(campaignId: bigint): Promise<boolean> {\r\n const status = await this.getAutoReleaseStatus(campaignId);\r\n const now = Math.floor(Date.now() / 1000);\r\n\r\n return status.enabled && now >= status.nextRun;\r\n }\r\n\r\n // ============================================================================\r\n // Keeper Functions (for automation operators)\r\n // ============================================================================\r\n\r\n /**\r\n * Execute auto-withdraw for specific recipients (keeper only)\r\n *\r\n * @example\r\n * ```typescript\r\n * // Get recipients from registry or external source\r\n * const recipients = ['0x...', '0x...', '0x...'];\r\n * await sdk.automation.executeAutoWithdraw(campaignId, recipients);\r\n * ```\r\n */\r\n async executeAutoWithdraw(\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: 'autoWithdraw',\r\n args: [campaignId, recipients],\r\n });\r\n\r\n return this.createTransactionResult(hash);\r\n }\r\n\r\n /**\r\n * Execute auto-withdraw using registry cursor (keeper only)\r\n *\r\n * Processes up to batchSize recipients from the registry.\r\n */\r\n async executeAutoWithdrawNext(\r\n campaignId: bigint,\r\n batchSize = 50\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: 'autoWithdrawNext',\r\n args: [campaignId, BigInt(batchSize)],\r\n });\r\n\r\n return this.createTransactionResult(hash);\r\n }\r\n\r\n /**\r\n * Execute auto-release for specific recipients (keeper only)\r\n */\r\n async executeAutoRelease(\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: 'autoReleaseLock',\r\n args: [campaignId, recipients],\r\n });\r\n\r\n return this.createTransactionResult(hash);\r\n }\r\n\r\n /**\r\n * Execute auto-release using registry cursor (keeper only)\r\n */\r\n async executeAutoReleaseNext(\r\n campaignId: bigint,\r\n batchSize = 50\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: 'autoReleaseLockNext',\r\n args: [campaignId, BigInt(batchSize)],\r\n });\r\n\r\n return this.createTransactionResult(hash);\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 AutomationModule;\r\n"]}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { PublicClient, WalletClient, Address, Hex } from 'viem';
|
|
2
|
+
import { I as InstantAirdropParams, T as TransactionResult, V as VestedAirdropParams, L as LockParams, a as VestingParams, C as CampaignInfo } from '../index-BTG0TRJt.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Campaign Creation Module
|
|
6
|
+
*
|
|
7
|
+
* Provides methods for creating all campaign types:
|
|
8
|
+
* - Instant Airdrops (Kind.INSTANT = 0)
|
|
9
|
+
* - Vested Airdrops (Kind.VESTED = 1)
|
|
10
|
+
* - Token Locks (Kind.LOCK = 2)
|
|
11
|
+
* - Vesting Streams (Kind.VESTING = 3)
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Campaign Kind enum matching the contract
|
|
16
|
+
*/
|
|
17
|
+
declare enum CampaignKind {
|
|
18
|
+
INSTANT = 0,
|
|
19
|
+
VESTED = 1,
|
|
20
|
+
LOCK = 2,
|
|
21
|
+
VESTING = 3
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Change policy enum matching the contract
|
|
25
|
+
*/
|
|
26
|
+
declare enum ChangePolicy {
|
|
27
|
+
ONLY_RECIPIENT = 0,
|
|
28
|
+
ONLY_CREATOR = 1,
|
|
29
|
+
BOTH = 2,
|
|
30
|
+
NO_ONE = 3
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* CreateArgs struct matching the contract
|
|
34
|
+
*/
|
|
35
|
+
interface CreateArgs {
|
|
36
|
+
kind: number;
|
|
37
|
+
token: Address;
|
|
38
|
+
start: bigint;
|
|
39
|
+
end: bigint;
|
|
40
|
+
step: bigint;
|
|
41
|
+
cliffReleaseTime: bigint;
|
|
42
|
+
cliffBps: number;
|
|
43
|
+
autoClaimIncentiveBps: number;
|
|
44
|
+
cancelable: boolean;
|
|
45
|
+
claimOnce: boolean;
|
|
46
|
+
changePolicy: number;
|
|
47
|
+
claimGrace: bigint;
|
|
48
|
+
recipients: Address[];
|
|
49
|
+
amounts: bigint[];
|
|
50
|
+
feeBuffer: bigint;
|
|
51
|
+
attachDefaultRegistry: boolean;
|
|
52
|
+
unwrapWETH: boolean;
|
|
53
|
+
weth: Address;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Campaigns module for creating and managing token distribution campaigns
|
|
57
|
+
*/
|
|
58
|
+
declare class CampaignsModule {
|
|
59
|
+
private readonly publicClient;
|
|
60
|
+
private readonly walletClient;
|
|
61
|
+
private readonly diamondAddress;
|
|
62
|
+
constructor(publicClient: PublicClient, walletClient: WalletClient | undefined, diamondAddress: Address);
|
|
63
|
+
/**
|
|
64
|
+
* Create an Instant Airdrop campaign
|
|
65
|
+
*
|
|
66
|
+
* Tokens are immediately claimable by recipients after funding.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const result = await sdk.campaigns.createInstantAirdrop({
|
|
71
|
+
* token: '0x...',
|
|
72
|
+
* recipients: [
|
|
73
|
+
* { address: '0x...', amount: parseEther('100') },
|
|
74
|
+
* { address: '0x...', amount: parseEther('50') },
|
|
75
|
+
* ],
|
|
76
|
+
* });
|
|
77
|
+
* console.log('Campaign created, tx:', result.hash);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
createInstantAirdrop(params: InstantAirdropParams): Promise<TransactionResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Create a Vested Airdrop campaign
|
|
83
|
+
*
|
|
84
|
+
* Tokens vest linearly over time with optional cliff period.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const result = await sdk.campaigns.createVestedAirdrop({
|
|
89
|
+
* token: '0x...',
|
|
90
|
+
* recipients: [
|
|
91
|
+
* { address: '0x...', amount: parseEther('1000') },
|
|
92
|
+
* ],
|
|
93
|
+
* startTime: Math.floor(Date.now() / 1000), // Start now
|
|
94
|
+
* duration: 365 * 24 * 60 * 60, // 1 year
|
|
95
|
+
* cliffDuration: 90 * 24 * 60 * 60, // 3 month cliff
|
|
96
|
+
* steps: 12, // Monthly releases
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
createVestedAirdrop(params: VestedAirdropParams): Promise<TransactionResult>;
|
|
101
|
+
/**
|
|
102
|
+
* Create a Token Lock
|
|
103
|
+
*
|
|
104
|
+
* Tokens are locked until a specific unlock time, then fully releasable.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const result = await sdk.campaigns.createLock({
|
|
109
|
+
* token: '0x...',
|
|
110
|
+
* recipient: '0x...',
|
|
111
|
+
* amount: parseEther('1000000'),
|
|
112
|
+
* unlockTime: Math.floor(Date.now() / 1000) + 180 * 24 * 60 * 60, // 6 months
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
createLock(params: LockParams): Promise<TransactionResult>;
|
|
117
|
+
/**
|
|
118
|
+
* Create a Vesting Stream (Payment)
|
|
119
|
+
*
|
|
120
|
+
* Single-recipient vesting with optional automation.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const result = await sdk.campaigns.createVesting({
|
|
125
|
+
* token: '0x...',
|
|
126
|
+
* recipient: '0x...',
|
|
127
|
+
* amount: parseEther('120000'), // 120k tokens
|
|
128
|
+
* startTime: Math.floor(Date.now() / 1000),
|
|
129
|
+
* duration: 365 * 24 * 60 * 60, // 1 year
|
|
130
|
+
* cliffDuration: 0, // No cliff
|
|
131
|
+
* steps: 12, // Monthly
|
|
132
|
+
* });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
createVesting(params: VestingParams): Promise<TransactionResult>;
|
|
136
|
+
/**
|
|
137
|
+
* Create a campaign with raw CreateArgs
|
|
138
|
+
*
|
|
139
|
+
* Low-level function for full control over campaign parameters.
|
|
140
|
+
*/
|
|
141
|
+
createCampaign(args: CreateArgs): Promise<TransactionResult>;
|
|
142
|
+
/**
|
|
143
|
+
* Fund a campaign using EIP-2612 Permit (gasless approval)
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const result = await sdk.campaigns.fundWithPermit({
|
|
148
|
+
* campaignId,
|
|
149
|
+
* amount: parseEther('1000'),
|
|
150
|
+
* deadline: Math.floor(Date.now() / 1000) + 3600,
|
|
151
|
+
* v: 28,
|
|
152
|
+
* r: '0x...',
|
|
153
|
+
* s: '0x...',
|
|
154
|
+
* });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
fundWithPermit(params: {
|
|
158
|
+
campaignId: bigint;
|
|
159
|
+
amount: bigint;
|
|
160
|
+
deadline: bigint;
|
|
161
|
+
v: number;
|
|
162
|
+
r: Hex;
|
|
163
|
+
s: Hex;
|
|
164
|
+
}): Promise<TransactionResult>;
|
|
165
|
+
/**
|
|
166
|
+
* Fund a campaign using Permit2 (gasless approval)
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const result = await sdk.campaigns.fundWithPermit2({
|
|
171
|
+
* campaignId,
|
|
172
|
+
* from: userAddress,
|
|
173
|
+
* amount: parseEther('1000'),
|
|
174
|
+
* permit2Data: encodedPermit2Data,
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
fundWithPermit2(params: {
|
|
179
|
+
campaignId: bigint;
|
|
180
|
+
from: Address;
|
|
181
|
+
amount: bigint;
|
|
182
|
+
permit2Data: Hex;
|
|
183
|
+
}): Promise<TransactionResult>;
|
|
184
|
+
/**
|
|
185
|
+
* Return leftover tokens to creator
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const result = await sdk.campaigns.returnLeftover(campaignId, parseEther('100'));
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
returnLeftover(campaignId: bigint, amountToReturn: bigint): Promise<TransactionResult>;
|
|
193
|
+
/**
|
|
194
|
+
* Add native tips to a campaign for automation
|
|
195
|
+
*/
|
|
196
|
+
addNativeTips(campaignId: bigint, tipAmount: bigint): Promise<TransactionResult>;
|
|
197
|
+
/**
|
|
198
|
+
* Get campaign summary by ID
|
|
199
|
+
*
|
|
200
|
+
* Returns full campaign configuration and state.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const campaign = await sdk.campaigns.getCampaign(1n);
|
|
205
|
+
* console.log('Campaign token:', campaign.token);
|
|
206
|
+
* console.log('Total claimed:', campaign.totalClaimed);
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
getCampaign(campaignId: bigint): Promise<CampaignInfo>;
|
|
210
|
+
/**
|
|
211
|
+
* Get campaign configuration only
|
|
212
|
+
*/
|
|
213
|
+
getCampaignConfig(campaignId: bigint): Promise<{
|
|
214
|
+
kind: number;
|
|
215
|
+
cancelable: boolean;
|
|
216
|
+
claimOnce: boolean;
|
|
217
|
+
canceled: boolean;
|
|
218
|
+
changePolicy: number;
|
|
219
|
+
token: Address;
|
|
220
|
+
creator: Address;
|
|
221
|
+
cliffBps: number;
|
|
222
|
+
autoClaimIncentiveBps: number;
|
|
223
|
+
start: number;
|
|
224
|
+
end: number;
|
|
225
|
+
step: number;
|
|
226
|
+
canceledAt: number;
|
|
227
|
+
cliffReleaseTime: number;
|
|
228
|
+
claimGrace: number;
|
|
229
|
+
unwrapWETH: boolean;
|
|
230
|
+
weth: Address;
|
|
231
|
+
}>;
|
|
232
|
+
/**
|
|
233
|
+
* Get campaign state (totals and accounting)
|
|
234
|
+
*/
|
|
235
|
+
getCampaignState(campaignId: bigint): Promise<{
|
|
236
|
+
totalAllocated: bigint;
|
|
237
|
+
totalClaimed: bigint;
|
|
238
|
+
nativeTips: bigint;
|
|
239
|
+
returned: bigint;
|
|
240
|
+
feeBuffer: bigint;
|
|
241
|
+
feeLoss: bigint;
|
|
242
|
+
totalFunded: bigint;
|
|
243
|
+
statusBits: number;
|
|
244
|
+
uniqueRecipients: bigint;
|
|
245
|
+
}>;
|
|
246
|
+
/**
|
|
247
|
+
* Get campaign status bits
|
|
248
|
+
*/
|
|
249
|
+
getCampaignStatus(campaignId: bigint): Promise<number>;
|
|
250
|
+
/**
|
|
251
|
+
* Pause a campaign (creator or admin only)
|
|
252
|
+
*
|
|
253
|
+
* @param campaignId - Campaign ID
|
|
254
|
+
* @param reason - Pause reason as status bits (e.g., 1 for creator pause)
|
|
255
|
+
*/
|
|
256
|
+
pause(campaignId: bigint, reason?: number): Promise<TransactionResult>;
|
|
257
|
+
/**
|
|
258
|
+
* Resume a paused campaign
|
|
259
|
+
*
|
|
260
|
+
* @param campaignId - Campaign ID
|
|
261
|
+
* @param clearBits - Status bits to clear (e.g., 1 for creator pause)
|
|
262
|
+
*/
|
|
263
|
+
resume(campaignId: bigint, clearBits?: number): Promise<TransactionResult>;
|
|
264
|
+
/**
|
|
265
|
+
* Finalize a campaign (no more claims possible)
|
|
266
|
+
*/
|
|
267
|
+
finalize(campaignId: bigint): Promise<TransactionResult>;
|
|
268
|
+
/**
|
|
269
|
+
* Cancel a campaign and return funds to creator
|
|
270
|
+
*/
|
|
271
|
+
cancel(campaignId: bigint): Promise<TransactionResult>;
|
|
272
|
+
/**
|
|
273
|
+
* Change a recipient address (for blocked recipients)
|
|
274
|
+
*/
|
|
275
|
+
changeRecipient(campaignId: bigint, fromAddress: Address, toAddress: Address): Promise<TransactionResult>;
|
|
276
|
+
/**
|
|
277
|
+
* Add recipients to an existing campaign
|
|
278
|
+
*/
|
|
279
|
+
addRecipients(campaignId: bigint, recipients: Address[], amounts: bigint[], additionalBuffer?: bigint): Promise<TransactionResult>;
|
|
280
|
+
private requireWallet;
|
|
281
|
+
private changePolicyToEnum;
|
|
282
|
+
private parseCampaignSummary;
|
|
283
|
+
private createTransactionResult;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export { CampaignKind, CampaignsModule, ChangePolicy, CampaignsModule as default };
|