@primuslabs/fund-js-sdk 0.1.12 → 0.1.14

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/dist/index.js CHANGED
@@ -23,11 +23,10 @@ __export(index_exports, {
23
23
  PrimusFund: () => PrimusFund
24
24
  });
25
25
  module.exports = __toCommonJS(index_exports);
26
- var import_ethers3 = require("ethers");
26
+ var import_ethers5 = require("ethers");
27
27
 
28
28
  // src/classes/Fund.ts
29
- var import_ethers2 = require("ethers");
30
- var import_zktls_js_sdk = require("@primuslabs/zktls-js-sdk");
29
+ var import_ethers3 = require("ethers");
31
30
 
32
31
  // src/config/constants.ts
33
32
  var DATASOURCETEMPLATESMAP = {
@@ -58,7 +57,8 @@ var SUPPORTEDCHAINIDSMAP = {
58
57
  symbol: "MON",
59
58
  decimals: 18
60
59
  },
61
- contractAddress: "0xcd1Ed9C1595A7e9DADe76808dd5e66aA95940A92"
60
+ contractAddress: "0xcd1Ed9C1595A7e9DADe76808dd5e66aA95940A92",
61
+ redPacketContractAddress: "0x5508fC45d930B5dE36647Dbbe5B9414e43C4F614"
62
62
  },
63
63
  // monad testnet
64
64
  97: {
@@ -69,7 +69,8 @@ var SUPPORTEDCHAINIDSMAP = {
69
69
  name: "tBNB",
70
70
  symbol: "tBNB"
71
71
  },
72
- contractAddress: "0x1C5bfc91789DB3130A07a06407E02745945C3218"
72
+ contractAddress: "0x1C5bfc91789DB3130A07a06407E02745945C3218",
73
+ redPacketContractAddress: "0xC75901570dB65070caDEBB74d6702E299Ac8e019"
73
74
  },
74
75
  56: {
75
76
  chainId: 56,
@@ -79,7 +80,8 @@ var SUPPORTEDCHAINIDSMAP = {
79
80
  name: "BNB",
80
81
  symbol: "BNB"
81
82
  },
82
- contractAddress: "0x1fb86db904caF7c12100EA64024E5dfd7505E484"
83
+ contractAddress: "0x1fb86db904caF7c12100EA64024E5dfd7505E484",
84
+ redPacketContractAddress: "0x083693C148e30b3A231D325366E76b38293FCa10"
83
85
  },
84
86
  688688: {
85
87
  chainId: 688688,
@@ -89,7 +91,8 @@ var SUPPORTEDCHAINIDSMAP = {
89
91
  name: "PHRS",
90
92
  symbol: "PHRS"
91
93
  },
92
- contractAddress: "0xD17512B7EC12880Bd94Eca9d774089fF89805F02"
94
+ contractAddress: "0xD17512B7EC12880Bd94Eca9d774089fF89805F02",
95
+ redPacketContractAddress: "0x673D74d95A35B26804475066d9cD1DA3947f4eC3"
93
96
  },
94
97
  84532: {
95
98
  chainId: 84532,
@@ -99,7 +102,8 @@ var SUPPORTEDCHAINIDSMAP = {
99
102
  name: "Sepolia Ether",
100
103
  symbol: "ETH"
101
104
  },
102
- contractAddress: "0x4E78940F0019EbAEDc6F4995D7B8ABf060F7a341"
105
+ contractAddress: "0x4E78940F0019EbAEDc6F4995D7B8ABf060F7a341",
106
+ redPacketContractAddress: "0xA33Ed35460C3d06094693956B2d7Cd1a9e7A39a8"
103
107
  },
104
108
  8453: {
105
109
  chainId: 8453,
@@ -109,7 +113,8 @@ var SUPPORTEDCHAINIDSMAP = {
109
113
  name: "Ether",
110
114
  symbol: "ETH"
111
115
  },
112
- contractAddress: "0xa2e0700a269Be3158c81E4739518b324d4398588"
116
+ contractAddress: "0xa2e0700a269Be3158c81E4739518b324d4398588",
117
+ redPacketContractAddress: "0x50bd377EB8D4236Bb587AB3FB1eeafd888AEeC58"
113
118
  }
114
119
  };
115
120
  var NATIVETOKENS = Object.values(SUPPORTEDCHAINIDSMAP).reduce((prev, curr) => {
@@ -131,6 +136,17 @@ var Fund_CONTRACTS = Object.values(SUPPORTEDCHAINIDSMAP).reduce((prev, curr) =>
131
136
  };
132
137
  }, {});
133
138
  var SUPPORTEDCHAINIDS = Object.keys(Fund_CONTRACTS).map((i) => Number(i));
139
+ var FundForRedPacket_CONTRACTS = Object.values(SUPPORTEDCHAINIDSMAP).filter(
140
+ (item) => {
141
+ return item.redPacketContractAddress;
142
+ }
143
+ ).reduce((prev, curr) => {
144
+ return {
145
+ ...prev,
146
+ [curr.chainId]: curr.redPacketContractAddress
147
+ };
148
+ }, {});
149
+ var SUPPORTEDCHAINIDSForRedPacket = Object.keys(FundForRedPacket_CONTRACTS).map((i) => Number(i));
134
150
 
135
151
  // src/classes/Contract.ts
136
152
  var import_ethers = require("ethers");
@@ -158,14 +174,7 @@ var Contract = class {
158
174
  }
159
175
  this.address = address;
160
176
  this.provider = provider;
161
- let formatProvider;
162
- if (provider instanceof import_ethers.ethers.providers.JsonRpcProvider) {
163
- formatProvider = provider;
164
- } else {
165
- const web3Provider = new import_ethers.ethers.providers.Web3Provider(provider);
166
- formatProvider = web3Provider.getSigner();
167
- }
168
- this.contractInstance = new import_ethers.ethers.Contract(this.address, abiJson, formatProvider);
177
+ this.contractInstance = new import_ethers.ethers.Contract(this.address, abiJson, this.provider);
169
178
  }
170
179
  // Example method to read from the contract
171
180
  async callMethod(functionName, functionParams) {
@@ -190,9 +199,7 @@ var Contract = class {
190
199
  try {
191
200
  console.log("sendTransaction params:", functionName, ...functionParams);
192
201
  const tx = await this.contractInstance[functionName](...functionParams);
193
- const txreceipt = await tx.wait();
194
- console.log("txreceipt", txreceipt);
195
- resolve(txreceipt);
202
+ resolve(tx.hash);
196
203
  } catch (error) {
197
204
  console.log("sendTransaction error:", error);
198
205
  const errStr = error?.message || error?.toString()?.toLowerCase() || "";
@@ -208,11 +215,21 @@ var Contract = class {
208
215
  if (isNoPendingWithdrawals) {
209
216
  return reject("no pending withdrawals");
210
217
  }
211
- const insufficientBalanceErrStrArr = ["insufficient balance", "unpredictable_gas_limit", "INSUFFICIENT_FUNDS"];
218
+ const insufficientBalanceErrStrArr = ["insufficient balance", "INSUFFICIENT_FUNDS", "The caller does not have enough funds for value transfer."];
212
219
  const isInsufficientBalance = hasErrorFlagFn(curErrorStrArr, insufficientBalanceErrStrArr);
213
220
  if (isInsufficientBalance) {
214
221
  return reject("insufficient balance");
215
222
  }
223
+ const alreadyClaimedErrStrArr = ["Already claimed"];
224
+ const isAlreadyClaimed = hasErrorFlagFn(curErrorStrArr, alreadyClaimedErrStrArr);
225
+ if (isAlreadyClaimed) {
226
+ return reject("already claimed");
227
+ }
228
+ const allClaimedErrStrArr = ["All claimed"];
229
+ const isAllClaimed = hasErrorFlagFn(curErrorStrArr, allClaimedErrStrArr);
230
+ if (isAllClaimed) {
231
+ return reject("all claimed");
232
+ }
216
233
  return reject(error);
217
234
  }
218
235
  });
@@ -220,1432 +237,2370 @@ var Contract = class {
220
237
  };
221
238
  var Contract_default = Contract;
222
239
 
223
- // src/config/abi.json
224
- var abi_default = [
240
+ // src/classes/Erc20Contract.ts
241
+ var import_ethers2 = require("ethers");
242
+
243
+ // src/config/erc20Abi.json
244
+ var erc20Abi_default = [
225
245
  {
226
246
  type: "function",
227
- name: "addBatchIdSource",
247
+ name: "allowance",
228
248
  inputs: [
229
- { name: "sourceName_", type: "string[]", internalType: "string[]" },
230
- { name: "url_", type: "string[]", internalType: "string[]" },
231
- { name: "jsonPath_", type: "string[]", internalType: "string[]" }
249
+ {
250
+ name: "owner",
251
+ type: "address",
252
+ internalType: "address"
253
+ },
254
+ {
255
+ name: "spender",
256
+ type: "address",
257
+ internalType: "address"
258
+ }
232
259
  ],
233
- outputs: [],
234
- stateMutability: "nonpayable"
260
+ outputs: [
261
+ {
262
+ name: "",
263
+ type: "uint256",
264
+ internalType: "uint256"
265
+ }
266
+ ],
267
+ stateMutability: "view"
235
268
  },
236
269
  {
237
270
  type: "function",
238
- name: "claimByMultiSource",
271
+ name: "approve",
239
272
  inputs: [
240
- { name: "idSources", type: "string[]", internalType: "string[]" },
241
273
  {
242
- name: "att",
243
- type: "tuple[]",
244
- internalType: "struct Attestation[]",
245
- components: [
246
- { name: "recipient", type: "address", internalType: "address" },
247
- {
248
- name: "request",
249
- type: "tuple",
250
- internalType: "struct AttNetworkRequest",
251
- components: [
252
- { name: "url", type: "string", internalType: "string" },
253
- { name: "header", type: "string", internalType: "string" },
254
- { name: "method", type: "string", internalType: "string" },
255
- { name: "body", type: "string", internalType: "string" }
256
- ]
257
- },
258
- {
259
- name: "reponseResolve",
260
- type: "tuple[]",
261
- internalType: "struct AttNetworkResponseResolve[]",
262
- components: [
263
- { name: "keyName", type: "string", internalType: "string" },
264
- {
265
- name: "parseType",
266
- type: "string",
267
- internalType: "string"
268
- },
269
- {
270
- name: "parsePath",
271
- type: "string",
272
- internalType: "string"
273
- }
274
- ]
275
- },
276
- { name: "data", type: "string", internalType: "string" },
277
- {
278
- name: "attConditions",
279
- type: "string",
280
- internalType: "string"
281
- },
282
- { name: "timestamp", type: "uint64", internalType: "uint64" },
283
- {
284
- name: "additionParams",
285
- type: "string",
286
- internalType: "string"
287
- },
288
- {
289
- name: "attestors",
290
- type: "tuple[]",
291
- internalType: "struct Attestor[]",
292
- components: [
293
- {
294
- name: "attestorAddr",
295
- type: "address",
296
- internalType: "address"
297
- },
298
- { name: "url", type: "string", internalType: "string" }
299
- ]
300
- },
301
- { name: "signatures", type: "bytes[]", internalType: "bytes[]" }
302
- ]
274
+ name: "spender",
275
+ type: "address",
276
+ internalType: "address"
277
+ },
278
+ {
279
+ name: "value",
280
+ type: "uint256",
281
+ internalType: "uint256"
303
282
  }
304
283
  ],
305
- outputs: [],
306
- stateMutability: "payable"
284
+ outputs: [
285
+ {
286
+ name: "",
287
+ type: "bool",
288
+ internalType: "bool"
289
+ }
290
+ ],
291
+ stateMutability: "nonpayable"
307
292
  },
308
293
  {
309
294
  type: "function",
310
- name: "claimBySource",
295
+ name: "balanceOf",
311
296
  inputs: [
312
- { name: "idSource", type: "string", internalType: "string" },
313
297
  {
314
- name: "att",
315
- type: "tuple",
316
- internalType: "struct Attestation",
317
- components: [
318
- { name: "recipient", type: "address", internalType: "address" },
319
- {
320
- name: "request",
321
- type: "tuple",
322
- internalType: "struct AttNetworkRequest",
323
- components: [
324
- { name: "url", type: "string", internalType: "string" },
325
- { name: "header", type: "string", internalType: "string" },
326
- { name: "method", type: "string", internalType: "string" },
327
- { name: "body", type: "string", internalType: "string" }
328
- ]
329
- },
330
- {
331
- name: "reponseResolve",
332
- type: "tuple[]",
333
- internalType: "struct AttNetworkResponseResolve[]",
334
- components: [
335
- { name: "keyName", type: "string", internalType: "string" },
336
- {
337
- name: "parseType",
338
- type: "string",
339
- internalType: "string"
340
- },
341
- {
342
- name: "parsePath",
343
- type: "string",
344
- internalType: "string"
345
- }
346
- ]
347
- },
348
- { name: "data", type: "string", internalType: "string" },
349
- {
350
- name: "attConditions",
351
- type: "string",
352
- internalType: "string"
353
- },
354
- { name: "timestamp", type: "uint64", internalType: "uint64" },
355
- {
356
- name: "additionParams",
357
- type: "string",
358
- internalType: "string"
359
- },
360
- {
361
- name: "attestors",
362
- type: "tuple[]",
363
- internalType: "struct Attestor[]",
364
- components: [
365
- {
366
- name: "attestorAddr",
367
- type: "address",
368
- internalType: "address"
369
- },
370
- { name: "url", type: "string", internalType: "string" }
371
- ]
372
- },
373
- { name: "signatures", type: "bytes[]", internalType: "bytes[]" }
374
- ]
298
+ name: "account",
299
+ type: "address",
300
+ internalType: "address"
375
301
  }
376
302
  ],
377
- outputs: [],
378
- stateMutability: "payable"
303
+ outputs: [
304
+ {
305
+ name: "",
306
+ type: "uint256",
307
+ internalType: "uint256"
308
+ }
309
+ ],
310
+ stateMutability: "view"
379
311
  },
380
312
  {
381
313
  type: "function",
382
- name: "claimBySourceAndTipIndex",
383
- inputs: [
384
- { name: "idSource", type: "string", internalType: "string" },
314
+ name: "decimals",
315
+ inputs: [],
316
+ outputs: [
385
317
  {
386
- name: "att",
387
- type: "tuple",
388
- internalType: "struct Attestation",
389
- components: [
390
- { name: "recipient", type: "address", internalType: "address" },
391
- {
392
- name: "request",
393
- type: "tuple",
394
- internalType: "struct AttNetworkRequest",
395
- components: [
396
- { name: "url", type: "string", internalType: "string" },
397
- { name: "header", type: "string", internalType: "string" },
398
- { name: "method", type: "string", internalType: "string" },
399
- { name: "body", type: "string", internalType: "string" }
400
- ]
401
- },
402
- {
403
- name: "reponseResolve",
404
- type: "tuple[]",
405
- internalType: "struct AttNetworkResponseResolve[]",
406
- components: [
407
- { name: "keyName", type: "string", internalType: "string" },
408
- {
409
- name: "parseType",
410
- type: "string",
411
- internalType: "string"
412
- },
413
- {
414
- name: "parsePath",
415
- type: "string",
416
- internalType: "string"
417
- }
418
- ]
419
- },
420
- { name: "data", type: "string", internalType: "string" },
421
- {
422
- name: "attConditions",
423
- type: "string",
424
- internalType: "string"
425
- },
426
- { name: "timestamp", type: "uint64", internalType: "uint64" },
427
- {
428
- name: "additionParams",
429
- type: "string",
430
- internalType: "string"
431
- },
432
- {
433
- name: "attestors",
434
- type: "tuple[]",
435
- internalType: "struct Attestor[]",
436
- components: [
437
- {
438
- name: "attestorAddr",
439
- type: "address",
440
- internalType: "address"
441
- },
442
- { name: "url", type: "string", internalType: "string" }
443
- ]
444
- },
445
- { name: "signatures", type: "bytes[]", internalType: "bytes[]" }
446
- ]
447
- },
448
- { name: "index", type: "uint32", internalType: "uint32" }
318
+ name: "",
319
+ type: "uint8",
320
+ internalType: "uint8"
321
+ }
449
322
  ],
450
- outputs: [],
451
- stateMutability: "payable"
452
- },
453
- {
454
- type: "function",
455
- name: "claimFee",
456
- inputs: [],
457
- outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
458
323
  stateMutability: "view"
459
324
  },
460
325
  {
461
326
  type: "function",
462
- name: "feeRecipient",
327
+ name: "name",
463
328
  inputs: [],
464
- outputs: [{ name: "", type: "address", internalType: "address" }],
329
+ outputs: [
330
+ {
331
+ name: "",
332
+ type: "string",
333
+ internalType: "string"
334
+ }
335
+ ],
465
336
  stateMutability: "view"
466
337
  },
467
338
  {
468
339
  type: "function",
469
- name: "getTipRecords",
470
- inputs: [
471
- {
472
- name: "tipRecipient",
473
- type: "tuple",
474
- internalType: "struct TipRecipient",
475
- components: [
476
- { name: "idSource", type: "string", internalType: "string" },
477
- { name: "id", type: "string", internalType: "string" }
478
- ]
479
- }
480
- ],
340
+ name: "symbol",
341
+ inputs: [],
481
342
  outputs: [
482
343
  {
483
344
  name: "",
484
- type: "tuple[]",
485
- internalType: "struct TipRecord[]",
486
- components: [
487
- { name: "amount", type: "uint256", internalType: "uint256" },
488
- {
489
- name: "tipToken",
490
- type: "tuple",
491
- internalType: "struct TipToken",
492
- components: [
493
- {
494
- name: "tokenType",
495
- type: "uint32",
496
- internalType: "uint32"
497
- },
498
- {
499
- name: "tokenAddress",
500
- type: "address",
501
- internalType: "address"
502
- }
503
- ]
504
- },
505
- { name: "timestamp", type: "uint64", internalType: "uint64" },
506
- { name: "tipper", type: "address", internalType: "address" },
507
- { name: "nftIds", type: "uint256[]", internalType: "uint256[]" }
508
- ]
345
+ type: "string",
346
+ internalType: "string"
509
347
  }
510
348
  ],
511
349
  stateMutability: "view"
512
350
  },
513
351
  {
514
352
  type: "function",
515
- name: "idSourceCache",
516
- inputs: [{ name: "", type: "string", internalType: "string" }],
353
+ name: "totalSupply",
354
+ inputs: [],
517
355
  outputs: [
518
- { name: "url", type: "string", internalType: "string" },
519
- { name: "jsonPath", type: "string", internalType: "string" }
356
+ {
357
+ name: "",
358
+ type: "uint256",
359
+ internalType: "uint256"
360
+ }
520
361
  ],
521
362
  stateMutability: "view"
522
363
  },
523
364
  {
524
365
  type: "function",
525
- name: "initialize",
366
+ name: "transfer",
526
367
  inputs: [
527
- { name: "owner", type: "address", internalType: "address" },
528
368
  {
529
- name: "primusZKTLS_",
369
+ name: "to",
530
370
  type: "address",
531
- internalType: "contract IPrimusZKTLS"
371
+ internalType: "address"
532
372
  },
533
- { name: "feeRecipient_", type: "address", internalType: "address" },
534
- { name: "claimFee_", type: "uint256", internalType: "uint256" }
373
+ {
374
+ name: "value",
375
+ type: "uint256",
376
+ internalType: "uint256"
377
+ }
535
378
  ],
536
- outputs: [],
537
- stateMutability: "nonpayable"
538
- },
539
- {
540
- type: "function",
541
- name: "owner",
542
- inputs: [],
543
- outputs: [{ name: "", type: "address", internalType: "address" }],
544
- stateMutability: "view"
545
- },
546
- {
547
- type: "function",
548
- name: "primusZKTLS",
549
- inputs: [],
550
379
  outputs: [
551
- { name: "", type: "address", internalType: "contract IPrimusZKTLS" }
380
+ {
381
+ name: "",
382
+ type: "bool",
383
+ internalType: "bool"
384
+ }
552
385
  ],
553
- stateMutability: "view"
554
- },
555
- {
556
- type: "function",
557
- name: "renounceOwnership",
558
- inputs: [],
559
- outputs: [],
560
386
  stateMutability: "nonpayable"
561
387
  },
562
388
  {
563
389
  type: "function",
564
- name: "setClaimFee",
390
+ name: "transferFrom",
565
391
  inputs: [
566
- { name: "claimFee_", type: "uint256", internalType: "uint256" }
392
+ {
393
+ name: "from",
394
+ type: "address",
395
+ internalType: "address"
396
+ },
397
+ {
398
+ name: "to",
399
+ type: "address",
400
+ internalType: "address"
401
+ },
402
+ {
403
+ name: "value",
404
+ type: "uint256",
405
+ internalType: "uint256"
406
+ }
567
407
  ],
568
- outputs: [],
569
- stateMutability: "nonpayable"
570
- },
571
- {
572
- type: "function",
573
- name: "setFeeRecipient",
574
- inputs: [
575
- { name: "feeRecipient_", type: "address", internalType: "address" }
408
+ outputs: [
409
+ {
410
+ name: "",
411
+ type: "bool",
412
+ internalType: "bool"
413
+ }
576
414
  ],
577
- outputs: [],
578
415
  stateMutability: "nonpayable"
579
416
  },
580
417
  {
581
- type: "function",
582
- name: "setPrimusZKTLS",
418
+ type: "event",
419
+ name: "Approval",
583
420
  inputs: [
584
421
  {
585
- name: "primusZKTLS_",
422
+ name: "owner",
586
423
  type: "address",
587
- internalType: "contract IPrimusZKTLS"
424
+ indexed: true,
425
+ internalType: "address"
426
+ },
427
+ {
428
+ name: "spender",
429
+ type: "address",
430
+ indexed: true,
431
+ internalType: "address"
432
+ },
433
+ {
434
+ name: "value",
435
+ type: "uint256",
436
+ indexed: false,
437
+ internalType: "uint256"
588
438
  }
589
439
  ],
590
- outputs: [],
591
- stateMutability: "nonpayable"
440
+ anonymous: false
592
441
  },
593
442
  {
594
- type: "function",
595
- name: "setWithdrawDelay",
443
+ type: "event",
444
+ name: "Transfer",
596
445
  inputs: [
597
- { name: "delay", type: "uint256", internalType: "uint256" }
446
+ {
447
+ name: "from",
448
+ type: "address",
449
+ indexed: true,
450
+ internalType: "address"
451
+ },
452
+ {
453
+ name: "to",
454
+ type: "address",
455
+ indexed: true,
456
+ internalType: "address"
457
+ },
458
+ {
459
+ name: "value",
460
+ type: "uint256",
461
+ indexed: false,
462
+ internalType: "uint256"
463
+ }
598
464
  ],
599
- outputs: [],
600
- stateMutability: "nonpayable"
465
+ anonymous: false
601
466
  },
602
467
  {
603
- type: "function",
604
- name: "tip",
468
+ type: "error",
469
+ name: "ERC20InsufficientAllowance",
605
470
  inputs: [
606
471
  {
607
- name: "token",
608
- type: "tuple",
609
- internalType: "struct TipToken",
610
- components: [
611
- { name: "tokenType", type: "uint32", internalType: "uint32" },
612
- {
613
- name: "tokenAddress",
614
- type: "address",
615
- internalType: "address"
616
- }
617
- ]
472
+ name: "spender",
473
+ type: "address",
474
+ internalType: "address"
618
475
  },
619
476
  {
620
- name: "recipient",
621
- type: "tuple",
622
- internalType: "struct TipRecipientInfo",
623
- components: [
624
- { name: "idSource", type: "string", internalType: "string" },
625
- { name: "id", type: "string", internalType: "string" },
626
- { name: "amount", type: "uint256", internalType: "uint256" },
627
- { name: "nftIds", type: "uint256[]", internalType: "uint256[]" }
628
- ]
477
+ name: "allowance",
478
+ type: "uint256",
479
+ internalType: "uint256"
480
+ },
481
+ {
482
+ name: "needed",
483
+ type: "uint256",
484
+ internalType: "uint256"
629
485
  }
630
- ],
631
- outputs: [],
632
- stateMutability: "payable"
486
+ ]
633
487
  },
634
488
  {
635
- type: "function",
636
- name: "tipBatch",
489
+ type: "error",
490
+ name: "ERC20InsufficientBalance",
637
491
  inputs: [
638
492
  {
639
- name: "token",
640
- type: "tuple",
641
- internalType: "struct TipToken",
642
- components: [
643
- { name: "tokenType", type: "uint32", internalType: "uint32" },
644
- {
645
- name: "tokenAddress",
646
- type: "address",
647
- internalType: "address"
648
- }
649
- ]
650
- },
651
- {
652
- name: "recipients",
653
- type: "tuple[]",
654
- internalType: "struct TipRecipientInfo[]",
655
- components: [
656
- { name: "idSource", type: "string", internalType: "string" },
657
- { name: "id", type: "string", internalType: "string" },
658
- { name: "amount", type: "uint256", internalType: "uint256" },
659
- { name: "nftIds", type: "uint256[]", internalType: "uint256[]" }
660
- ]
661
- }
662
- ],
663
- outputs: [],
664
- stateMutability: "payable"
665
- },
666
- {
667
- type: "function",
668
- name: "tipperWithdraw",
669
- inputs: [
670
- {
671
- name: "tipRecipients",
672
- type: "tuple[]",
673
- internalType: "struct TipWithdrawInfo[]",
674
- components: [
675
- { name: "idSource", type: "string", internalType: "string" },
676
- { name: "id", type: "string", internalType: "string" },
677
- { name: "tipTimestamp", type: "uint64", internalType: "uint64" }
678
- ]
679
- }
680
- ],
681
- outputs: [],
682
- stateMutability: "nonpayable"
683
- },
684
- {
685
- type: "function",
686
- name: "transferOwnership",
687
- inputs: [
688
- { name: "newOwner", type: "address", internalType: "address" }
689
- ],
690
- outputs: [],
691
- stateMutability: "nonpayable"
692
- },
693
- {
694
- type: "function",
695
- name: "withdrawDelay",
696
- inputs: [],
697
- outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
698
- stateMutability: "view"
699
- },
700
- {
701
- type: "event",
702
- name: "ClaimEvent",
703
- inputs: [
704
- {
705
- name: "recipient",
706
- type: "address",
707
- indexed: true,
708
- internalType: "address"
709
- },
710
- {
711
- name: "claimTime",
712
- type: "uint64",
713
- indexed: false,
714
- internalType: "uint64"
715
- },
716
- {
717
- name: "idSource",
718
- type: "string",
719
- indexed: false,
720
- internalType: "string"
721
- },
722
- {
723
- name: "id",
724
- type: "string",
725
- indexed: false,
726
- internalType: "string"
727
- },
728
- {
729
- name: "tipper",
730
- type: "address",
731
- indexed: false,
732
- internalType: "address"
733
- },
734
- {
735
- name: "tokenAddr",
493
+ name: "sender",
736
494
  type: "address",
737
- indexed: false,
738
495
  internalType: "address"
739
496
  },
740
497
  {
741
- name: "amount",
498
+ name: "balance",
742
499
  type: "uint256",
743
- indexed: false,
744
500
  internalType: "uint256"
745
501
  },
746
502
  {
747
- name: "tipTime",
748
- type: "uint64",
749
- indexed: false,
750
- internalType: "uint64"
751
- }
752
- ],
753
- anonymous: false
754
- },
755
- {
756
- type: "event",
757
- name: "Initialized",
758
- inputs: [
759
- {
760
- name: "version",
761
- type: "uint64",
762
- indexed: false,
763
- internalType: "uint64"
503
+ name: "needed",
504
+ type: "uint256",
505
+ internalType: "uint256"
764
506
  }
765
- ],
766
- anonymous: false
507
+ ]
767
508
  },
768
509
  {
769
- type: "event",
770
- name: "OwnershipTransferred",
510
+ type: "error",
511
+ name: "ERC20InvalidApprover",
771
512
  inputs: [
772
513
  {
773
- name: "previousOwner",
774
- type: "address",
775
- indexed: true,
776
- internalType: "address"
777
- },
778
- {
779
- name: "newOwner",
514
+ name: "approver",
780
515
  type: "address",
781
- indexed: true,
782
516
  internalType: "address"
783
517
  }
784
- ],
785
- anonymous: false
518
+ ]
786
519
  },
787
520
  {
788
- type: "event",
789
- name: "TipEvent",
521
+ type: "error",
522
+ name: "ERC20InvalidReceiver",
790
523
  inputs: [
791
524
  {
792
- name: "idSource",
793
- type: "string",
794
- indexed: false,
795
- internalType: "string"
796
- },
797
- {
798
- name: "id",
799
- type: "string",
800
- indexed: false,
801
- internalType: "string"
802
- },
803
- {
804
- name: "tipper",
805
- type: "address",
806
- indexed: false,
807
- internalType: "address"
808
- },
809
- {
810
- name: "tokenAddr",
525
+ name: "receiver",
811
526
  type: "address",
812
- indexed: false,
813
527
  internalType: "address"
814
- },
815
- {
816
- name: "amount",
817
- type: "uint256",
818
- indexed: false,
819
- internalType: "uint256"
820
- },
821
- {
822
- name: "tipTime",
823
- type: "uint64",
824
- indexed: false,
825
- internalType: "uint64"
826
528
  }
827
- ],
828
- anonymous: false
529
+ ]
829
530
  },
830
531
  {
831
- type: "event",
832
- name: "WithdrawEvent",
532
+ type: "error",
533
+ name: "ERC20InvalidSender",
833
534
  inputs: [
834
535
  {
835
- name: "withdrawTime",
836
- type: "uint64",
837
- indexed: false,
838
- internalType: "uint64"
839
- },
840
- {
841
- name: "idSource",
842
- type: "string",
843
- indexed: false,
844
- internalType: "string"
845
- },
846
- {
847
- name: "id",
848
- type: "string",
849
- indexed: false,
850
- internalType: "string"
851
- },
852
- {
853
- name: "tipper",
854
- type: "address",
855
- indexed: false,
856
- internalType: "address"
857
- },
858
- {
859
- name: "tokenAddr",
536
+ name: "sender",
860
537
  type: "address",
861
- indexed: false,
862
538
  internalType: "address"
863
- },
864
- {
865
- name: "amount",
866
- type: "uint256",
867
- indexed: false,
868
- internalType: "uint256"
869
- },
870
- {
871
- name: "tipTime",
872
- type: "uint64",
873
- indexed: false,
874
- internalType: "uint64"
875
539
  }
876
- ],
877
- anonymous: false
878
- },
879
- { type: "error", name: "InvalidInitialization", inputs: [] },
880
- { type: "error", name: "NotInitializing", inputs: [] },
881
- {
882
- type: "error",
883
- name: "OwnableInvalidOwner",
884
- inputs: [
885
- { name: "owner", type: "address", internalType: "address" }
886
540
  ]
887
541
  },
888
542
  {
889
543
  type: "error",
890
- name: "OwnableUnauthorizedAccount",
544
+ name: "ERC20InvalidSpender",
891
545
  inputs: [
892
- { name: "account", type: "address", internalType: "address" }
546
+ {
547
+ name: "spender",
548
+ type: "address",
549
+ internalType: "address"
550
+ }
893
551
  ]
894
- },
895
- { type: "error", name: "ReentrancyGuardReentrantCall", inputs: [] }
552
+ }
896
553
  ];
897
554
 
898
- // src/config/erc20Abi.json
899
- var erc20Abi_default = [
900
- {
901
- type: "function",
902
- name: "allowance",
555
+ // src/classes/Erc20Contract.ts
556
+ var { parseUnits, formatUnits } = import_ethers2.ethers.utils;
557
+ var Erc20Contract = class {
558
+ provider;
559
+ contractInstance;
560
+ constructor(provider, address) {
561
+ if (!provider || !address) {
562
+ throw new Error("provider, address are required");
563
+ }
564
+ this.provider = provider;
565
+ this.contractInstance = new import_ethers2.ethers.Contract(address, erc20Abi_default, provider);
566
+ }
567
+ async decimals() {
568
+ const res = await this.contractInstance.decimals();
569
+ return res;
570
+ }
571
+ async symbol() {
572
+ const res = await this.contractInstance.symbol();
573
+ return res;
574
+ }
575
+ async allowance(userAddress, spenderAddress) {
576
+ const res = await this.contractInstance.allowance(userAddress, spenderAddress);
577
+ return res;
578
+ }
579
+ async getAddress() {
580
+ const address = await this.provider.getAddress();
581
+ return address;
582
+ }
583
+ async approve(approveParams) {
584
+ const { spenderAddress, approveAmount, otherParams } = approveParams;
585
+ return new Promise(async (resolve, reject) => {
586
+ try {
587
+ const userAddress = await this.getAddress();
588
+ const allowance = await this.allowance(userAddress, spenderAddress);
589
+ const decimals = await this.decimals();
590
+ const formatApproveAmount = parseUnits(approveAmount.toString(), decimals);
591
+ const formatAllowance = formatUnits(allowance.toString(), decimals);
592
+ console.log("allowance:", formatAllowance);
593
+ if (allowance.lt(formatApproveAmount)) {
594
+ let params = [spenderAddress, formatApproveAmount];
595
+ if (otherParams) {
596
+ params.push(otherParams);
597
+ }
598
+ const tx = await this.contractInstance.approve(...params);
599
+ await tx.wait();
600
+ console.log(`Approved: ${approveAmount.toString()}`);
601
+ } else {
602
+ console.log(`Already approved`);
603
+ }
604
+ resolve("Approved");
605
+ } catch (error) {
606
+ console.error("Approval failed:", error);
607
+ return reject(error);
608
+ }
609
+ });
610
+ }
611
+ };
612
+ var Erc20Contract_default = Erc20Contract;
613
+
614
+ // src/config/abi.json
615
+ var abi_default = [
616
+ {
617
+ type: "function",
618
+ name: "addBatchIdSource",
619
+ inputs: [
620
+ { name: "sourceName_", type: "string[]", internalType: "string[]" },
621
+ { name: "url_", type: "string[]", internalType: "string[]" },
622
+ { name: "jsonPath_", type: "string[]", internalType: "string[]" }
623
+ ],
624
+ outputs: [],
625
+ stateMutability: "nonpayable"
626
+ },
627
+ {
628
+ type: "function",
629
+ name: "claimByMultiSource",
630
+ inputs: [
631
+ { name: "idSources", type: "string[]", internalType: "string[]" },
632
+ {
633
+ name: "att",
634
+ type: "tuple[]",
635
+ internalType: "struct Attestation[]",
636
+ components: [
637
+ { name: "recipient", type: "address", internalType: "address" },
638
+ {
639
+ name: "request",
640
+ type: "tuple",
641
+ internalType: "struct AttNetworkRequest",
642
+ components: [
643
+ { name: "url", type: "string", internalType: "string" },
644
+ { name: "header", type: "string", internalType: "string" },
645
+ { name: "method", type: "string", internalType: "string" },
646
+ { name: "body", type: "string", internalType: "string" }
647
+ ]
648
+ },
649
+ {
650
+ name: "reponseResolve",
651
+ type: "tuple[]",
652
+ internalType: "struct AttNetworkResponseResolve[]",
653
+ components: [
654
+ { name: "keyName", type: "string", internalType: "string" },
655
+ {
656
+ name: "parseType",
657
+ type: "string",
658
+ internalType: "string"
659
+ },
660
+ {
661
+ name: "parsePath",
662
+ type: "string",
663
+ internalType: "string"
664
+ }
665
+ ]
666
+ },
667
+ { name: "data", type: "string", internalType: "string" },
668
+ {
669
+ name: "attConditions",
670
+ type: "string",
671
+ internalType: "string"
672
+ },
673
+ { name: "timestamp", type: "uint64", internalType: "uint64" },
674
+ {
675
+ name: "additionParams",
676
+ type: "string",
677
+ internalType: "string"
678
+ },
679
+ {
680
+ name: "attestors",
681
+ type: "tuple[]",
682
+ internalType: "struct Attestor[]",
683
+ components: [
684
+ {
685
+ name: "attestorAddr",
686
+ type: "address",
687
+ internalType: "address"
688
+ },
689
+ { name: "url", type: "string", internalType: "string" }
690
+ ]
691
+ },
692
+ { name: "signatures", type: "bytes[]", internalType: "bytes[]" }
693
+ ]
694
+ }
695
+ ],
696
+ outputs: [],
697
+ stateMutability: "payable"
698
+ },
699
+ {
700
+ type: "function",
701
+ name: "claimBySource",
702
+ inputs: [
703
+ { name: "idSource", type: "string", internalType: "string" },
704
+ {
705
+ name: "att",
706
+ type: "tuple",
707
+ internalType: "struct Attestation",
708
+ components: [
709
+ { name: "recipient", type: "address", internalType: "address" },
710
+ {
711
+ name: "request",
712
+ type: "tuple",
713
+ internalType: "struct AttNetworkRequest",
714
+ components: [
715
+ { name: "url", type: "string", internalType: "string" },
716
+ { name: "header", type: "string", internalType: "string" },
717
+ { name: "method", type: "string", internalType: "string" },
718
+ { name: "body", type: "string", internalType: "string" }
719
+ ]
720
+ },
721
+ {
722
+ name: "reponseResolve",
723
+ type: "tuple[]",
724
+ internalType: "struct AttNetworkResponseResolve[]",
725
+ components: [
726
+ { name: "keyName", type: "string", internalType: "string" },
727
+ {
728
+ name: "parseType",
729
+ type: "string",
730
+ internalType: "string"
731
+ },
732
+ {
733
+ name: "parsePath",
734
+ type: "string",
735
+ internalType: "string"
736
+ }
737
+ ]
738
+ },
739
+ { name: "data", type: "string", internalType: "string" },
740
+ {
741
+ name: "attConditions",
742
+ type: "string",
743
+ internalType: "string"
744
+ },
745
+ { name: "timestamp", type: "uint64", internalType: "uint64" },
746
+ {
747
+ name: "additionParams",
748
+ type: "string",
749
+ internalType: "string"
750
+ },
751
+ {
752
+ name: "attestors",
753
+ type: "tuple[]",
754
+ internalType: "struct Attestor[]",
755
+ components: [
756
+ {
757
+ name: "attestorAddr",
758
+ type: "address",
759
+ internalType: "address"
760
+ },
761
+ { name: "url", type: "string", internalType: "string" }
762
+ ]
763
+ },
764
+ { name: "signatures", type: "bytes[]", internalType: "bytes[]" }
765
+ ]
766
+ }
767
+ ],
768
+ outputs: [],
769
+ stateMutability: "payable"
770
+ },
771
+ {
772
+ type: "function",
773
+ name: "claimBySourceAndTipIndex",
774
+ inputs: [
775
+ { name: "idSource", type: "string", internalType: "string" },
776
+ {
777
+ name: "att",
778
+ type: "tuple",
779
+ internalType: "struct Attestation",
780
+ components: [
781
+ { name: "recipient", type: "address", internalType: "address" },
782
+ {
783
+ name: "request",
784
+ type: "tuple",
785
+ internalType: "struct AttNetworkRequest",
786
+ components: [
787
+ { name: "url", type: "string", internalType: "string" },
788
+ { name: "header", type: "string", internalType: "string" },
789
+ { name: "method", type: "string", internalType: "string" },
790
+ { name: "body", type: "string", internalType: "string" }
791
+ ]
792
+ },
793
+ {
794
+ name: "reponseResolve",
795
+ type: "tuple[]",
796
+ internalType: "struct AttNetworkResponseResolve[]",
797
+ components: [
798
+ { name: "keyName", type: "string", internalType: "string" },
799
+ {
800
+ name: "parseType",
801
+ type: "string",
802
+ internalType: "string"
803
+ },
804
+ {
805
+ name: "parsePath",
806
+ type: "string",
807
+ internalType: "string"
808
+ }
809
+ ]
810
+ },
811
+ { name: "data", type: "string", internalType: "string" },
812
+ {
813
+ name: "attConditions",
814
+ type: "string",
815
+ internalType: "string"
816
+ },
817
+ { name: "timestamp", type: "uint64", internalType: "uint64" },
818
+ {
819
+ name: "additionParams",
820
+ type: "string",
821
+ internalType: "string"
822
+ },
823
+ {
824
+ name: "attestors",
825
+ type: "tuple[]",
826
+ internalType: "struct Attestor[]",
827
+ components: [
828
+ {
829
+ name: "attestorAddr",
830
+ type: "address",
831
+ internalType: "address"
832
+ },
833
+ { name: "url", type: "string", internalType: "string" }
834
+ ]
835
+ },
836
+ { name: "signatures", type: "bytes[]", internalType: "bytes[]" }
837
+ ]
838
+ },
839
+ { name: "index", type: "uint32", internalType: "uint32" }
840
+ ],
841
+ outputs: [],
842
+ stateMutability: "payable"
843
+ },
844
+ {
845
+ type: "function",
846
+ name: "claimFee",
847
+ inputs: [],
848
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
849
+ stateMutability: "view"
850
+ },
851
+ {
852
+ type: "function",
853
+ name: "feeRecipient",
854
+ inputs: [],
855
+ outputs: [{ name: "", type: "address", internalType: "address" }],
856
+ stateMutability: "view"
857
+ },
858
+ {
859
+ type: "function",
860
+ name: "getTipRecords",
861
+ inputs: [
862
+ {
863
+ name: "tipRecipient",
864
+ type: "tuple",
865
+ internalType: "struct TipRecipient",
866
+ components: [
867
+ { name: "idSource", type: "string", internalType: "string" },
868
+ { name: "id", type: "string", internalType: "string" }
869
+ ]
870
+ }
871
+ ],
872
+ outputs: [
873
+ {
874
+ name: "",
875
+ type: "tuple[]",
876
+ internalType: "struct TipRecord[]",
877
+ components: [
878
+ { name: "amount", type: "uint256", internalType: "uint256" },
879
+ {
880
+ name: "tipToken",
881
+ type: "tuple",
882
+ internalType: "struct TipToken",
883
+ components: [
884
+ {
885
+ name: "tokenType",
886
+ type: "uint32",
887
+ internalType: "uint32"
888
+ },
889
+ {
890
+ name: "tokenAddress",
891
+ type: "address",
892
+ internalType: "address"
893
+ }
894
+ ]
895
+ },
896
+ { name: "timestamp", type: "uint64", internalType: "uint64" },
897
+ { name: "tipper", type: "address", internalType: "address" },
898
+ { name: "nftIds", type: "uint256[]", internalType: "uint256[]" }
899
+ ]
900
+ }
901
+ ],
902
+ stateMutability: "view"
903
+ },
904
+ {
905
+ type: "function",
906
+ name: "idSourceCache",
907
+ inputs: [{ name: "", type: "string", internalType: "string" }],
908
+ outputs: [
909
+ { name: "url", type: "string", internalType: "string" },
910
+ { name: "jsonPath", type: "string", internalType: "string" }
911
+ ],
912
+ stateMutability: "view"
913
+ },
914
+ {
915
+ type: "function",
916
+ name: "initialize",
917
+ inputs: [
918
+ { name: "owner", type: "address", internalType: "address" },
919
+ {
920
+ name: "primusZKTLS_",
921
+ type: "address",
922
+ internalType: "contract IPrimusZKTLS"
923
+ },
924
+ { name: "feeRecipient_", type: "address", internalType: "address" },
925
+ { name: "claimFee_", type: "uint256", internalType: "uint256" }
926
+ ],
927
+ outputs: [],
928
+ stateMutability: "nonpayable"
929
+ },
930
+ {
931
+ type: "function",
932
+ name: "owner",
933
+ inputs: [],
934
+ outputs: [{ name: "", type: "address", internalType: "address" }],
935
+ stateMutability: "view"
936
+ },
937
+ {
938
+ type: "function",
939
+ name: "primusZKTLS",
940
+ inputs: [],
941
+ outputs: [
942
+ { name: "", type: "address", internalType: "contract IPrimusZKTLS" }
943
+ ],
944
+ stateMutability: "view"
945
+ },
946
+ {
947
+ type: "function",
948
+ name: "renounceOwnership",
949
+ inputs: [],
950
+ outputs: [],
951
+ stateMutability: "nonpayable"
952
+ },
953
+ {
954
+ type: "function",
955
+ name: "setClaimFee",
956
+ inputs: [
957
+ { name: "claimFee_", type: "uint256", internalType: "uint256" }
958
+ ],
959
+ outputs: [],
960
+ stateMutability: "nonpayable"
961
+ },
962
+ {
963
+ type: "function",
964
+ name: "setFeeRecipient",
965
+ inputs: [
966
+ { name: "feeRecipient_", type: "address", internalType: "address" }
967
+ ],
968
+ outputs: [],
969
+ stateMutability: "nonpayable"
970
+ },
971
+ {
972
+ type: "function",
973
+ name: "setPrimusZKTLS",
974
+ inputs: [
975
+ {
976
+ name: "primusZKTLS_",
977
+ type: "address",
978
+ internalType: "contract IPrimusZKTLS"
979
+ }
980
+ ],
981
+ outputs: [],
982
+ stateMutability: "nonpayable"
983
+ },
984
+ {
985
+ type: "function",
986
+ name: "setWithdrawDelay",
987
+ inputs: [
988
+ { name: "delay", type: "uint256", internalType: "uint256" }
989
+ ],
990
+ outputs: [],
991
+ stateMutability: "nonpayable"
992
+ },
993
+ {
994
+ type: "function",
995
+ name: "tip",
996
+ inputs: [
997
+ {
998
+ name: "token",
999
+ type: "tuple",
1000
+ internalType: "struct TipToken",
1001
+ components: [
1002
+ { name: "tokenType", type: "uint32", internalType: "uint32" },
1003
+ {
1004
+ name: "tokenAddress",
1005
+ type: "address",
1006
+ internalType: "address"
1007
+ }
1008
+ ]
1009
+ },
1010
+ {
1011
+ name: "recipient",
1012
+ type: "tuple",
1013
+ internalType: "struct TipRecipientInfo",
1014
+ components: [
1015
+ { name: "idSource", type: "string", internalType: "string" },
1016
+ { name: "id", type: "string", internalType: "string" },
1017
+ { name: "amount", type: "uint256", internalType: "uint256" },
1018
+ { name: "nftIds", type: "uint256[]", internalType: "uint256[]" }
1019
+ ]
1020
+ }
1021
+ ],
1022
+ outputs: [],
1023
+ stateMutability: "payable"
1024
+ },
1025
+ {
1026
+ type: "function",
1027
+ name: "tipBatch",
1028
+ inputs: [
1029
+ {
1030
+ name: "token",
1031
+ type: "tuple",
1032
+ internalType: "struct TipToken",
1033
+ components: [
1034
+ { name: "tokenType", type: "uint32", internalType: "uint32" },
1035
+ {
1036
+ name: "tokenAddress",
1037
+ type: "address",
1038
+ internalType: "address"
1039
+ }
1040
+ ]
1041
+ },
1042
+ {
1043
+ name: "recipients",
1044
+ type: "tuple[]",
1045
+ internalType: "struct TipRecipientInfo[]",
1046
+ components: [
1047
+ { name: "idSource", type: "string", internalType: "string" },
1048
+ { name: "id", type: "string", internalType: "string" },
1049
+ { name: "amount", type: "uint256", internalType: "uint256" },
1050
+ { name: "nftIds", type: "uint256[]", internalType: "uint256[]" }
1051
+ ]
1052
+ }
1053
+ ],
1054
+ outputs: [],
1055
+ stateMutability: "payable"
1056
+ },
1057
+ {
1058
+ type: "function",
1059
+ name: "tipperWithdraw",
1060
+ inputs: [
1061
+ {
1062
+ name: "tipRecipients",
1063
+ type: "tuple[]",
1064
+ internalType: "struct TipWithdrawInfo[]",
1065
+ components: [
1066
+ { name: "idSource", type: "string", internalType: "string" },
1067
+ { name: "id", type: "string", internalType: "string" },
1068
+ { name: "tipTimestamp", type: "uint64", internalType: "uint64" }
1069
+ ]
1070
+ }
1071
+ ],
1072
+ outputs: [],
1073
+ stateMutability: "nonpayable"
1074
+ },
1075
+ {
1076
+ type: "function",
1077
+ name: "transferOwnership",
1078
+ inputs: [
1079
+ { name: "newOwner", type: "address", internalType: "address" }
1080
+ ],
1081
+ outputs: [],
1082
+ stateMutability: "nonpayable"
1083
+ },
1084
+ {
1085
+ type: "function",
1086
+ name: "withdrawDelay",
1087
+ inputs: [],
1088
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
1089
+ stateMutability: "view"
1090
+ },
1091
+ {
1092
+ type: "event",
1093
+ name: "ClaimEvent",
1094
+ inputs: [
1095
+ {
1096
+ name: "recipient",
1097
+ type: "address",
1098
+ indexed: true,
1099
+ internalType: "address"
1100
+ },
1101
+ {
1102
+ name: "claimTime",
1103
+ type: "uint64",
1104
+ indexed: false,
1105
+ internalType: "uint64"
1106
+ },
1107
+ {
1108
+ name: "idSource",
1109
+ type: "string",
1110
+ indexed: false,
1111
+ internalType: "string"
1112
+ },
1113
+ {
1114
+ name: "id",
1115
+ type: "string",
1116
+ indexed: false,
1117
+ internalType: "string"
1118
+ },
1119
+ {
1120
+ name: "tipper",
1121
+ type: "address",
1122
+ indexed: false,
1123
+ internalType: "address"
1124
+ },
1125
+ {
1126
+ name: "tokenAddr",
1127
+ type: "address",
1128
+ indexed: false,
1129
+ internalType: "address"
1130
+ },
1131
+ {
1132
+ name: "amount",
1133
+ type: "uint256",
1134
+ indexed: false,
1135
+ internalType: "uint256"
1136
+ },
1137
+ {
1138
+ name: "tipTime",
1139
+ type: "uint64",
1140
+ indexed: false,
1141
+ internalType: "uint64"
1142
+ }
1143
+ ],
1144
+ anonymous: false
1145
+ },
1146
+ {
1147
+ type: "event",
1148
+ name: "Initialized",
1149
+ inputs: [
1150
+ {
1151
+ name: "version",
1152
+ type: "uint64",
1153
+ indexed: false,
1154
+ internalType: "uint64"
1155
+ }
1156
+ ],
1157
+ anonymous: false
1158
+ },
1159
+ {
1160
+ type: "event",
1161
+ name: "OwnershipTransferred",
1162
+ inputs: [
1163
+ {
1164
+ name: "previousOwner",
1165
+ type: "address",
1166
+ indexed: true,
1167
+ internalType: "address"
1168
+ },
1169
+ {
1170
+ name: "newOwner",
1171
+ type: "address",
1172
+ indexed: true,
1173
+ internalType: "address"
1174
+ }
1175
+ ],
1176
+ anonymous: false
1177
+ },
1178
+ {
1179
+ type: "event",
1180
+ name: "TipEvent",
1181
+ inputs: [
1182
+ {
1183
+ name: "idSource",
1184
+ type: "string",
1185
+ indexed: false,
1186
+ internalType: "string"
1187
+ },
1188
+ {
1189
+ name: "id",
1190
+ type: "string",
1191
+ indexed: false,
1192
+ internalType: "string"
1193
+ },
1194
+ {
1195
+ name: "tipper",
1196
+ type: "address",
1197
+ indexed: false,
1198
+ internalType: "address"
1199
+ },
1200
+ {
1201
+ name: "tokenAddr",
1202
+ type: "address",
1203
+ indexed: false,
1204
+ internalType: "address"
1205
+ },
1206
+ {
1207
+ name: "amount",
1208
+ type: "uint256",
1209
+ indexed: false,
1210
+ internalType: "uint256"
1211
+ },
1212
+ {
1213
+ name: "tipTime",
1214
+ type: "uint64",
1215
+ indexed: false,
1216
+ internalType: "uint64"
1217
+ }
1218
+ ],
1219
+ anonymous: false
1220
+ },
1221
+ {
1222
+ type: "event",
1223
+ name: "WithdrawEvent",
1224
+ inputs: [
1225
+ {
1226
+ name: "withdrawTime",
1227
+ type: "uint64",
1228
+ indexed: false,
1229
+ internalType: "uint64"
1230
+ },
1231
+ {
1232
+ name: "idSource",
1233
+ type: "string",
1234
+ indexed: false,
1235
+ internalType: "string"
1236
+ },
1237
+ {
1238
+ name: "id",
1239
+ type: "string",
1240
+ indexed: false,
1241
+ internalType: "string"
1242
+ },
1243
+ {
1244
+ name: "tipper",
1245
+ type: "address",
1246
+ indexed: false,
1247
+ internalType: "address"
1248
+ },
1249
+ {
1250
+ name: "tokenAddr",
1251
+ type: "address",
1252
+ indexed: false,
1253
+ internalType: "address"
1254
+ },
1255
+ {
1256
+ name: "amount",
1257
+ type: "uint256",
1258
+ indexed: false,
1259
+ internalType: "uint256"
1260
+ },
1261
+ {
1262
+ name: "tipTime",
1263
+ type: "uint64",
1264
+ indexed: false,
1265
+ internalType: "uint64"
1266
+ }
1267
+ ],
1268
+ anonymous: false
1269
+ },
1270
+ { type: "error", name: "InvalidInitialization", inputs: [] },
1271
+ { type: "error", name: "NotInitializing", inputs: [] },
1272
+ {
1273
+ type: "error",
1274
+ name: "OwnableInvalidOwner",
1275
+ inputs: [
1276
+ { name: "owner", type: "address", internalType: "address" }
1277
+ ]
1278
+ },
1279
+ {
1280
+ type: "error",
1281
+ name: "OwnableUnauthorizedAccount",
1282
+ inputs: [
1283
+ { name: "account", type: "address", internalType: "address" }
1284
+ ]
1285
+ },
1286
+ { type: "error", name: "ReentrancyGuardReentrantCall", inputs: [] }
1287
+ ];
1288
+
1289
+ // src/config/erc721Abi.json
1290
+ var erc721Abi_default = [
1291
+ {
1292
+ type: "function",
1293
+ name: "supportsInterface",
1294
+ stateMutability: "view",
1295
+ inputs: [
1296
+ { internalType: "bytes4", name: "interfaceId", type: "bytes4" }
1297
+ ],
1298
+ outputs: [{ internalType: "bool", name: "", type: "bool" }]
1299
+ },
1300
+ {
1301
+ type: "function",
1302
+ name: "balanceOf",
1303
+ stateMutability: "view",
1304
+ inputs: [
1305
+ { internalType: "address", name: "owner", type: "address" }
1306
+ ],
1307
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }]
1308
+ },
1309
+ {
1310
+ type: "function",
1311
+ name: "ownerOf",
1312
+ stateMutability: "view",
1313
+ inputs: [
1314
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1315
+ ],
1316
+ outputs: [{ internalType: "address", name: "", type: "address" }]
1317
+ },
1318
+ {
1319
+ type: "function",
1320
+ name: "tokenURI",
1321
+ stateMutability: "view",
1322
+ inputs: [
1323
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1324
+ ],
1325
+ outputs: [{ internalType: "string", name: "", type: "string" }]
1326
+ },
1327
+ {
1328
+ type: "function",
1329
+ name: "approve",
1330
+ stateMutability: "nonpayable",
1331
+ inputs: [
1332
+ { internalType: "address", name: "to", type: "address" },
1333
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1334
+ ],
1335
+ outputs: []
1336
+ },
1337
+ {
1338
+ type: "function",
1339
+ name: "getApproved",
1340
+ stateMutability: "view",
1341
+ inputs: [
1342
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1343
+ ],
1344
+ outputs: [{ internalType: "address", name: "", type: "address" }]
1345
+ },
1346
+ {
1347
+ type: "function",
1348
+ name: "setApprovalForAll",
1349
+ stateMutability: "nonpayable",
1350
+ inputs: [
1351
+ { internalType: "address", name: "operator", type: "address" },
1352
+ { internalType: "bool", name: "approved", type: "bool" }
1353
+ ],
1354
+ outputs: []
1355
+ },
1356
+ {
1357
+ type: "function",
1358
+ name: "isApprovedForAll",
1359
+ stateMutability: "view",
1360
+ inputs: [
1361
+ { internalType: "address", name: "owner", type: "address" },
1362
+ { internalType: "address", name: "operator", type: "address" }
1363
+ ],
1364
+ outputs: [{ internalType: "bool", name: "", type: "bool" }]
1365
+ },
1366
+ {
1367
+ type: "function",
1368
+ name: "transferFrom",
1369
+ stateMutability: "nonpayable",
1370
+ inputs: [
1371
+ { internalType: "address", name: "from", type: "address" },
1372
+ { internalType: "address", name: "to", type: "address" },
1373
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1374
+ ],
1375
+ outputs: []
1376
+ },
1377
+ {
1378
+ type: "function",
1379
+ name: "safeTransferFrom",
1380
+ stateMutability: "nonpayable",
1381
+ inputs: [
1382
+ { internalType: "address", name: "from", type: "address" },
1383
+ { internalType: "address", name: "to", type: "address" },
1384
+ { internalType: "uint256", name: "tokenId", type: "uint256" }
1385
+ ],
1386
+ outputs: []
1387
+ },
1388
+ {
1389
+ type: "function",
1390
+ name: "name",
1391
+ stateMutability: "view",
1392
+ inputs: [],
1393
+ outputs: [{ internalType: "string", name: "", type: "string" }]
1394
+ },
1395
+ {
1396
+ type: "function",
1397
+ name: "symbol",
1398
+ stateMutability: "view",
1399
+ inputs: [],
1400
+ outputs: [{ internalType: "string", name: "", type: "string" }]
1401
+ }
1402
+ ];
1403
+
1404
+ // src/classes/Erc721Contract.ts
1405
+ var Erc721Contract = class {
1406
+ contractInstance;
1407
+ constructor(provider, address) {
1408
+ if (!provider || !address) {
1409
+ throw new Error("provider, address are required");
1410
+ }
1411
+ this.contractInstance = new Contract_default(provider, address, erc721Abi_default);
1412
+ }
1413
+ async approve(address, tokenId) {
1414
+ return new Promise(async (resolve, reject) => {
1415
+ try {
1416
+ const approver = await this.contractInstance.callMethod("getApproved", [tokenId]);
1417
+ if (approver === address) {
1418
+ console.log(`Already approved:: ${approver}`);
1419
+ resolve("Approved");
1420
+ } else {
1421
+ await this.contractInstance.sendTransaction("approve", [address, tokenId]);
1422
+ console.log(`Approved`);
1423
+ resolve("Approved");
1424
+ }
1425
+ } catch (error) {
1426
+ console.error("Approval failed:", error);
1427
+ return reject(error);
1428
+ }
1429
+ });
1430
+ }
1431
+ // ownerAddress: string,
1432
+ async setApprovalForAll(operatorAddress) {
1433
+ return new Promise(async (resolve, reject) => {
1434
+ try {
1435
+ await this.contractInstance.sendTransaction("setApprovalForAll", [operatorAddress, true]);
1436
+ console.log(`Approved`);
1437
+ resolve("Approved");
1438
+ } catch (error) {
1439
+ console.error("Approval failed:", error);
1440
+ return reject(error);
1441
+ }
1442
+ });
1443
+ }
1444
+ async fetchMetaData(nftContractAddress, tokenId) {
1445
+ return new Promise(async (resolve, reject) => {
1446
+ try {
1447
+ let url = await this.contractInstance.callMethod("tokenURI", [tokenId]);
1448
+ if (url.startsWith("ipfs://")) {
1449
+ url = url.replace("ipfs://", "https://ipfs.io/ipfs/");
1450
+ }
1451
+ const res = await fetch(url);
1452
+ if (!res.ok) {
1453
+ return reject(`Failed to fetch metadata from ${url}`);
1454
+ }
1455
+ let metadata = await res.json();
1456
+ if (metadata.image && metadata.image.startsWith("ipfs://")) {
1457
+ metadata.image = metadata.image.replace(
1458
+ "ipfs://",
1459
+ "https://ipfs.io/ipfs/"
1460
+ );
1461
+ }
1462
+ metadata.address = nftContractAddress;
1463
+ metadata.tokenId = tokenId;
1464
+ return resolve(metadata);
1465
+ } catch (error) {
1466
+ return reject(error);
1467
+ }
1468
+ });
1469
+ }
1470
+ };
1471
+ var Erc721Contract_default = Erc721Contract;
1472
+
1473
+ // src/classes/Fund.ts
1474
+ var { parseUnits: parseUnits2, formatUnits: formatUnits2 } = import_ethers3.ethers.utils;
1475
+ var Fund = class {
1476
+ fundContract;
1477
+ provider;
1478
+ formatProvider;
1479
+ chainId;
1480
+ constructor() {
1481
+ }
1482
+ async init(provider, chainId) {
1483
+ return new Promise(async (resolve, reject) => {
1484
+ try {
1485
+ const fundContractAddress = Fund_CONTRACTS[chainId];
1486
+ if (!fundContractAddress) {
1487
+ return reject(`Unsupported chainId:${chainId}`);
1488
+ }
1489
+ this.fundContract = new Contract_default(provider, fundContractAddress, abi_default);
1490
+ this.provider = provider;
1491
+ this.chainId = chainId;
1492
+ resolve("success");
1493
+ } catch (error) {
1494
+ return reject(error);
1495
+ }
1496
+ });
1497
+ }
1498
+ async fund(tokenInfo, recipientInfo) {
1499
+ return new Promise(async (resolve, reject) => {
1500
+ try {
1501
+ const recipientInfos = [];
1502
+ recipientInfos[0] = recipientInfo;
1503
+ let decimals = 18;
1504
+ let params = [];
1505
+ if (tokenInfo.tokenType === 0) {
1506
+ await this.approve(tokenInfo, recipientInfos);
1507
+ console.log("after approve in fund fn");
1508
+ const tokenContract = new Erc20Contract_default(this.provider, tokenInfo.tokenAddress);
1509
+ decimals = await tokenContract.decimals();
1510
+ } else if (tokenInfo.tokenType === 2) {
1511
+ decimals = 0;
1512
+ const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenInfo.tokenAddress);
1513
+ await erc721ContractInstance.approve(this.fundContract.address, recipientInfo.nftIds[0]);
1514
+ }
1515
+ const tokenAmount = parseUnits2(recipientInfo.tokenAmount.toString(), decimals);
1516
+ const newFundRecipientInfo = {
1517
+ idSource: recipientInfo.socialPlatform,
1518
+ id: recipientInfo.userIdentifier,
1519
+ amount: tokenAmount,
1520
+ nftIds: recipientInfo.nftIds
1521
+ };
1522
+ if (tokenInfo.tokenType === 1) {
1523
+ params = [tokenInfo, newFundRecipientInfo, { value: tokenAmount }];
1524
+ } else {
1525
+ params = [tokenInfo, newFundRecipientInfo];
1526
+ }
1527
+ if ([97, 56].includes(this.chainId)) {
1528
+ const gasPrice = await this.provider.getGasPrice();
1529
+ params[2] = params[2] ? { ...params[2], gasPrice } : { gasPrice };
1530
+ }
1531
+ console.log("tip-params", params, this.chainId);
1532
+ const result = await this.fundContract.sendTransaction("tip", params);
1533
+ resolve(result);
1534
+ } catch (error) {
1535
+ return reject(error);
1536
+ }
1537
+ });
1538
+ }
1539
+ async onlyFund(tokenInfo, recipientInfo) {
1540
+ return new Promise(async (resolve, reject) => {
1541
+ try {
1542
+ const recipientInfos = [];
1543
+ recipientInfos[0] = recipientInfo;
1544
+ let decimals = 18;
1545
+ let params = [];
1546
+ if (tokenInfo.tokenType === 0) {
1547
+ const tokenContract = new Erc20Contract_default(this.provider, tokenInfo.tokenAddress);
1548
+ decimals = await tokenContract.decimals();
1549
+ } else if (tokenInfo.tokenType === 2) {
1550
+ decimals = 0;
1551
+ const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenInfo.tokenAddress);
1552
+ await erc721ContractInstance.approve(this.fundContract.address, recipientInfo.nftIds[0]);
1553
+ }
1554
+ const tokenAmount = parseUnits2(recipientInfo.tokenAmount.toString(), decimals);
1555
+ const newFundRecipientInfo = {
1556
+ idSource: recipientInfo.socialPlatform,
1557
+ id: recipientInfo.userIdentifier,
1558
+ amount: tokenAmount,
1559
+ nftIds: recipientInfo.nftIds
1560
+ };
1561
+ if (tokenInfo.tokenType === 1) {
1562
+ params = [tokenInfo, newFundRecipientInfo, { value: tokenAmount }];
1563
+ } else {
1564
+ params = [tokenInfo, newFundRecipientInfo];
1565
+ }
1566
+ if ([97, 56].includes(this.chainId)) {
1567
+ const gasPrice = await this.provider.getGasPrice();
1568
+ params[2] = params[2] ? { ...params[2], gasPrice } : { gasPrice };
1569
+ }
1570
+ console.log("tip-params", params, this.chainId);
1571
+ const result = await this.fundContract.sendTransaction("tip", params);
1572
+ resolve(result);
1573
+ } catch (error) {
1574
+ return reject(error);
1575
+ }
1576
+ });
1577
+ }
1578
+ async refund(recipients) {
1579
+ return new Promise(async (resolve, reject) => {
1580
+ try {
1581
+ const newRecipients = recipients.map((i) => {
1582
+ return {
1583
+ idSource: i.socialPlatform,
1584
+ id: i.userIdentifier,
1585
+ tipTimestamp: i.tipTimestamp
1586
+ };
1587
+ });
1588
+ let params = [newRecipients];
1589
+ if ([97, 56].includes(this.chainId)) {
1590
+ const gasPrice = await this.provider.getGasPrice();
1591
+ params.push({
1592
+ gasPrice
1593
+ });
1594
+ }
1595
+ const result = await this.fundContract.sendTransaction("tipperWithdraw", params);
1596
+ return resolve(result);
1597
+ } catch (error) {
1598
+ return reject(error);
1599
+ }
1600
+ });
1601
+ }
1602
+ async fundBatch(tokenInfo, recipientInfoList) {
1603
+ return new Promise(async (resolve, reject) => {
1604
+ try {
1605
+ let decimals = 18;
1606
+ let params = [];
1607
+ if (tokenInfo.tokenType === 0) {
1608
+ await this.approve(tokenInfo, recipientInfoList);
1609
+ const tokenContract = new Erc20Contract_default(this.provider, tokenInfo.tokenAddress);
1610
+ decimals = await tokenContract.decimals();
1611
+ } else if (tokenInfo.tokenType === 2) {
1612
+ decimals = 0;
1613
+ const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenInfo.tokenAddress);
1614
+ await erc721ContractInstance.setApprovalForAll(this.fundContract.address);
1615
+ }
1616
+ let totalFormatAmount = recipientInfoList.reduce((acc, cur) => acc.add(parseUnits2(cur.tokenAmount.toString(), decimals)), import_ethers3.ethers.BigNumber.from(0));
1617
+ const newRecipientInfoList = recipientInfoList.map((i) => {
1618
+ const formatAmount = parseUnits2(i.tokenAmount.toString(), decimals);
1619
+ return {
1620
+ idSource: i.socialPlatform,
1621
+ id: i.userIdentifier,
1622
+ amount: formatAmount,
1623
+ nftIds: i.nftIds
1624
+ };
1625
+ });
1626
+ if (tokenInfo.tokenType === 1) {
1627
+ params = [tokenInfo, newRecipientInfoList, { value: totalFormatAmount }];
1628
+ } else {
1629
+ params = [tokenInfo, newRecipientInfoList];
1630
+ }
1631
+ if ([97, 56].includes(this.chainId)) {
1632
+ const gasPrice = await this.provider.getGasPrice();
1633
+ params[2] = params[2] ? { ...params[2], gasPrice } : { gasPrice };
1634
+ }
1635
+ const result = await this.fundContract.sendTransaction("tipBatch", params);
1636
+ return resolve(result);
1637
+ } catch (error) {
1638
+ return reject(error);
1639
+ }
1640
+ });
1641
+ }
1642
+ // TODO-nft
1643
+ async approve(tokenInfo, recipientInfoList) {
1644
+ return new Promise(async (resolve, reject) => {
1645
+ try {
1646
+ const approveAmount = recipientInfoList.reduce((acc, cur) => acc.add(parseUnits2(cur.tokenAmount.toString(), 0)), import_ethers3.ethers.BigNumber.from(0)).toString();
1647
+ let approveParams = {
1648
+ spenderAddress: this.fundContract.address,
1649
+ approveAmount
1650
+ };
1651
+ if ([97, 56].includes(this.chainId)) {
1652
+ const gasPrice = await this.provider.getGasPrice();
1653
+ approveParams.otherParams = { gasPrice };
1654
+ }
1655
+ const tokenContract = new Erc20Contract_default(this.provider, tokenInfo.tokenAddress);
1656
+ await tokenContract.approve(approveParams);
1657
+ resolve("Approved");
1658
+ } catch (error) {
1659
+ return reject(error);
1660
+ }
1661
+ });
1662
+ }
1663
+ // TODO-nft
1664
+ // async approve(tokenInfo: TokenInfo, recipientInfoList: RecipientInfo[]) {
1665
+ // return new Promise(async (resolve, reject) => {
1666
+ // try {
1667
+ // const web3Provider = new ethers.providers.Web3Provider(this.provider)
1668
+ // const signer = web3Provider.getSigner();
1669
+ // const address = await signer.getAddress();
1670
+ // const erc20Contract = new ethers.Contract(tokenInfo.tokenAddress as string, erc20Abi, signer);
1671
+ // const allowance = await erc20Contract.allowance(address, this.fundContract.address);
1672
+ // const decimals = await erc20Contract.decimals();
1673
+ // console.log('allowance', formatUnits(allowance.toString(), decimals))
1674
+ // // Compute total amount
1675
+ // const requiredAllowance = recipientInfoList.reduce((acc, cur) =>
1676
+ // acc.add(parseUnits(cur.tokenAmount.toString(), decimals)), ethers.BigNumber.from(0))
1677
+ // if (allowance.lt(requiredAllowance)) {
1678
+ // let params = [this.fundContract.address, requiredAllowance]
1679
+ // if ([97, 56].includes(this.chainId)) {
1680
+ // const gasPrice = await this.formatProvider.getGasPrice();
1681
+ // params.push({ gasPrice })
1682
+ // }
1683
+ // const tx = await erc20Contract.approve(...params);
1684
+ // // Wait for the transaction to be mined
1685
+ // await tx.wait();
1686
+ // console.log(`Approved: ${requiredAllowance.toString()}`);
1687
+ // } else {
1688
+ // console.log(`Already approved: ${allowance.toString()}`);
1689
+ // }
1690
+ // resolve('Approved');
1691
+ // } catch (error: any) {
1692
+ // console.error('Approval failed:', error);
1693
+ // if (error?.code === 'ACTION_REJECTED') {
1694
+ // return reject('user rejected transaction')
1695
+ // }
1696
+ // return reject(error);
1697
+ // }
1698
+ // });
1699
+ // }
1700
+ async claimBySource(socialPlatform, userIdentifier, attestation) {
1701
+ return new Promise(async (resolve, reject) => {
1702
+ try {
1703
+ const claimFee = await this.fundContract.callMethod("claimFee", []);
1704
+ const fundRecords = await this.fundContract.callMethod("getTipRecords", [{ idSource: socialPlatform, id: userIdentifier }]);
1705
+ console.log("fundRecords", fundRecords);
1706
+ const recordCount = fundRecords.length;
1707
+ if (recordCount <= 0) {
1708
+ return reject(`No fund records.`);
1709
+ } else {
1710
+ const totalFee = claimFee.mul(recordCount);
1711
+ let params = [socialPlatform, attestation, { value: totalFee }];
1712
+ if ([97, 56].includes(this.chainId)) {
1713
+ const gasPrice = await this.provider.getGasPrice();
1714
+ params[2].gasPrice = gasPrice;
1715
+ }
1716
+ const txreceipt = await this.fundContract.sendTransaction("claimBySource", params);
1717
+ return resolve(txreceipt);
1718
+ }
1719
+ } catch (error) {
1720
+ return reject(error);
1721
+ }
1722
+ });
1723
+ }
1724
+ async claimByMultiSource(socialPlatforms, userIdentifiers, attestationList) {
1725
+ return new Promise(async (resolve, reject) => {
1726
+ try {
1727
+ if (socialPlatforms.length !== userIdentifiers.length || socialPlatforms.length !== attestationList.length) {
1728
+ return reject(`socialPlatforms, userIdentifiers, attestationList length must be equal.`);
1729
+ }
1730
+ const claimFee = await this.fundContract.callMethod("claimFee", []);
1731
+ let allFundRecords = [];
1732
+ let recordCount = 0;
1733
+ for (const [index, value] of socialPlatforms.entries()) {
1734
+ const fundRecords = await this.fundContract.callMethod("getTipRecords", [{ idSource: value, id: userIdentifiers[index] }]);
1735
+ allFundRecords.push(...fundRecords);
1736
+ recordCount += fundRecords.length;
1737
+ }
1738
+ if (recordCount <= 0) {
1739
+ return reject(`No fund records.`);
1740
+ } else {
1741
+ const totalFee = claimFee.mul(recordCount);
1742
+ let params = [socialPlatforms, userIdentifiers, attestationList, { value: totalFee }];
1743
+ if ([97, 56].includes(this.chainId)) {
1744
+ const gasPrice = await this.provider.getGasPrice();
1745
+ params[3].gasPrice = gasPrice;
1746
+ }
1747
+ const txreceipt = await this.fundContract.sendTransaction("claimByMultiSource", params);
1748
+ return resolve(txreceipt);
1749
+ }
1750
+ } catch (error) {
1751
+ console.error("claimByMultiSource", error);
1752
+ return reject(error);
1753
+ }
1754
+ });
1755
+ }
1756
+ async getTipRecords(getFundRecordsParams) {
1757
+ return new Promise(async (resolve, reject) => {
1758
+ try {
1759
+ const formatGetFundRecordsParams = getFundRecordsParams.map((item) => {
1760
+ return {
1761
+ idSource: item.socialPlatform,
1762
+ id: item.userIdentifier
1763
+ };
1764
+ });
1765
+ const fundRecords = await this.fundContract.callMethod("getTipRecords", formatGetFundRecordsParams);
1766
+ console.log("fundRecords", fundRecords);
1767
+ let formatRecords = [];
1768
+ for (const record of fundRecords) {
1769
+ const { tipper, timestamp, tipToken: [tokenType, tokenAddress], amount, nftIds } = record;
1770
+ let decimals = 18;
1771
+ let symbol = "";
1772
+ let tokenId = null;
1773
+ let nftInfo = null;
1774
+ if (tokenType === 0) {
1775
+ const tokenContract = new Erc20Contract_default(this.provider, tokenAddress);
1776
+ decimals = await tokenContract.decimals();
1777
+ symbol = await tokenContract.symbol();
1778
+ } else if (tokenType === 1) {
1779
+ symbol = NATIVETOKENS[this.chainId];
1780
+ } else if (tokenType === 2) {
1781
+ decimals = 0;
1782
+ tokenId = parseInt(nftIds[0]);
1783
+ const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenAddress);
1784
+ nftInfo = await erc721ContractInstance.fetchMetaData(tokenAddress, tokenId);
1785
+ }
1786
+ let fundToken = {
1787
+ tokenType,
1788
+ // tokenAmount: formatUnits(amount, decimals),
1789
+ decimals,
1790
+ symbol,
1791
+ chainName: CHAINNAMES[this.chainId],
1792
+ chainId: this.chainId
1793
+ };
1794
+ if (tokenType === 0) {
1795
+ fundToken.tokenAddress = tokenAddress;
1796
+ }
1797
+ if (tokenType === 2) {
1798
+ Object.assign(fundToken, nftInfo ?? {});
1799
+ }
1800
+ formatRecords.push({
1801
+ funder: tipper,
1802
+ fundToken,
1803
+ amount: formatUnits2(amount, decimals),
1804
+ timestamp: timestamp.toNumber()
1805
+ });
1806
+ }
1807
+ console.log("formatRecords", formatRecords);
1808
+ return resolve(formatRecords);
1809
+ } catch (error) {
1810
+ return reject(error);
1811
+ }
1812
+ });
1813
+ }
1814
+ };
1815
+
1816
+ // src/classes/FundForRedPacket.ts
1817
+ var import_ethers4 = require("ethers");
1818
+
1819
+ // src/config/abiForRedPacket.json
1820
+ var abiForRedPacket_default = [
1821
+ {
1822
+ type: "function",
1823
+ name: "claimFee",
1824
+ inputs: [],
1825
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
1826
+ stateMutability: "view"
1827
+ },
1828
+ {
1829
+ type: "function",
1830
+ name: "feeRecipient",
1831
+ inputs: [],
1832
+ outputs: [{ name: "", type: "address", internalType: "address" }],
1833
+ stateMutability: "view"
1834
+ },
1835
+ {
1836
+ type: "function",
1837
+ name: "getClaimed",
1838
+ inputs: [
1839
+ { name: "reId", type: "bytes32", internalType: "bytes32" },
1840
+ { name: "userid", type: "string", internalType: "string" }
1841
+ ],
1842
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
1843
+ stateMutability: "view"
1844
+ },
1845
+ {
1846
+ type: "function",
1847
+ name: "getPrev",
1848
+ inputs: [],
1849
+ outputs: [
1850
+ { name: "", type: "uint256", internalType: "uint256" },
1851
+ { name: "", type: "uint256", internalType: "uint256" }
1852
+ ],
1853
+ stateMutability: "view"
1854
+ },
1855
+ {
1856
+ type: "function",
1857
+ name: "getREInfo",
1858
+ inputs: [
1859
+ { name: "reId", type: "bytes32", internalType: "bytes32" }
1860
+ ],
1861
+ outputs: [
1862
+ {
1863
+ name: "",
1864
+ type: "tuple",
1865
+ internalType: "struct RERecord",
1866
+ components: [
1867
+ { name: "id", type: "bytes32", internalType: "bytes32" },
1868
+ { name: "tokenType", type: "uint32", internalType: "uint32" },
1869
+ { name: "reType", type: "uint32", internalType: "uint32" },
1870
+ { name: "number", type: "uint32", internalType: "uint32" },
1871
+ {
1872
+ name: "remainingNumber",
1873
+ type: "uint32",
1874
+ internalType: "uint32"
1875
+ },
1876
+ { name: "timestamp", type: "uint64", internalType: "uint64" },
1877
+ {
1878
+ name: "tokenAddress",
1879
+ type: "address",
1880
+ internalType: "address"
1881
+ },
1882
+ { name: "reSender", type: "address", internalType: "address" },
1883
+ {
1884
+ name: "checkContract",
1885
+ type: "address",
1886
+ internalType: "address"
1887
+ },
1888
+ { name: "amount", type: "uint256", internalType: "uint256" },
1889
+ {
1890
+ name: "remainingAmount",
1891
+ type: "uint256",
1892
+ internalType: "uint256"
1893
+ },
1894
+ { name: "checkParams", type: "bytes", internalType: "bytes" }
1895
+ ]
1896
+ }
1897
+ ],
1898
+ stateMutability: "view"
1899
+ },
1900
+ {
1901
+ type: "function",
1902
+ name: "idCounter",
1903
+ inputs: [],
1904
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
1905
+ stateMutability: "view"
1906
+ },
1907
+ {
1908
+ type: "function",
1909
+ name: "initialize",
903
1910
  inputs: [
1911
+ { name: "owner", type: "address", internalType: "address" },
904
1912
  {
905
- name: "owner",
1913
+ name: "primusZKTLS_",
906
1914
  type: "address",
907
- internalType: "address"
1915
+ internalType: "contract IPrimusZKTLS"
908
1916
  },
909
- {
910
- name: "spender",
911
- type: "address",
912
- internalType: "address"
913
- }
1917
+ { name: "feeRecipient_", type: "address", internalType: "address" },
1918
+ { name: "claimFee_", type: "uint256", internalType: "uint256" }
914
1919
  ],
1920
+ outputs: [],
1921
+ stateMutability: "nonpayable"
1922
+ },
1923
+ {
1924
+ type: "function",
1925
+ name: "owner",
1926
+ inputs: [],
1927
+ outputs: [{ name: "", type: "address", internalType: "address" }],
1928
+ stateMutability: "view"
1929
+ },
1930
+ {
1931
+ type: "function",
1932
+ name: "primusZKTLS",
1933
+ inputs: [],
915
1934
  outputs: [
916
- {
917
- name: "",
918
- type: "uint256",
919
- internalType: "uint256"
920
- }
1935
+ { name: "", type: "address", internalType: "contract IPrimusZKTLS" }
921
1936
  ],
922
1937
  stateMutability: "view"
923
1938
  },
924
1939
  {
925
1940
  type: "function",
926
- name: "approve",
1941
+ name: "reCheckClaim",
927
1942
  inputs: [
928
1943
  {
929
- name: "spender",
930
- type: "address",
931
- internalType: "address"
1944
+ name: "att",
1945
+ type: "tuple",
1946
+ internalType: "struct Attestation",
1947
+ components: [
1948
+ { name: "recipient", type: "address", internalType: "address" },
1949
+ {
1950
+ name: "request",
1951
+ type: "tuple",
1952
+ internalType: "struct AttNetworkRequest",
1953
+ components: [
1954
+ { name: "url", type: "string", internalType: "string" },
1955
+ { name: "header", type: "string", internalType: "string" },
1956
+ { name: "method", type: "string", internalType: "string" },
1957
+ { name: "body", type: "string", internalType: "string" }
1958
+ ]
1959
+ },
1960
+ {
1961
+ name: "reponseResolve",
1962
+ type: "tuple[]",
1963
+ internalType: "struct AttNetworkResponseResolve[]",
1964
+ components: [
1965
+ { name: "keyName", type: "string", internalType: "string" },
1966
+ {
1967
+ name: "parseType",
1968
+ type: "string",
1969
+ internalType: "string"
1970
+ },
1971
+ {
1972
+ name: "parsePath",
1973
+ type: "string",
1974
+ internalType: "string"
1975
+ }
1976
+ ]
1977
+ },
1978
+ { name: "data", type: "string", internalType: "string" },
1979
+ {
1980
+ name: "attConditions",
1981
+ type: "string",
1982
+ internalType: "string"
1983
+ },
1984
+ { name: "timestamp", type: "uint64", internalType: "uint64" },
1985
+ {
1986
+ name: "additionParams",
1987
+ type: "string",
1988
+ internalType: "string"
1989
+ },
1990
+ {
1991
+ name: "attestors",
1992
+ type: "tuple[]",
1993
+ internalType: "struct Attestor[]",
1994
+ components: [
1995
+ {
1996
+ name: "attestorAddr",
1997
+ type: "address",
1998
+ internalType: "address"
1999
+ },
2000
+ { name: "url", type: "string", internalType: "string" }
2001
+ ]
2002
+ },
2003
+ { name: "signatures", type: "bytes[]", internalType: "bytes[]" }
2004
+ ]
932
2005
  },
933
- {
934
- name: "value",
935
- type: "uint256",
936
- internalType: "uint256"
937
- }
2006
+ { name: "checkParams", type: "bytes", internalType: "bytes" }
938
2007
  ],
939
2008
  outputs: [
940
- {
941
- name: "",
942
- type: "bool",
943
- internalType: "bool"
944
- }
2009
+ { name: "", type: "string", internalType: "string" },
2010
+ { name: "", type: "address", internalType: "address" }
945
2011
  ],
946
- stateMutability: "nonpayable"
2012
+ stateMutability: "view"
947
2013
  },
948
2014
  {
949
2015
  type: "function",
950
- name: "balanceOf",
2016
+ name: "reClaim",
951
2017
  inputs: [
2018
+ { name: "reId", type: "bytes32", internalType: "bytes32" },
952
2019
  {
953
- name: "account",
954
- type: "address",
955
- internalType: "address"
2020
+ name: "att",
2021
+ type: "tuple",
2022
+ internalType: "struct Attestation",
2023
+ components: [
2024
+ { name: "recipient", type: "address", internalType: "address" },
2025
+ {
2026
+ name: "request",
2027
+ type: "tuple",
2028
+ internalType: "struct AttNetworkRequest",
2029
+ components: [
2030
+ { name: "url", type: "string", internalType: "string" },
2031
+ { name: "header", type: "string", internalType: "string" },
2032
+ { name: "method", type: "string", internalType: "string" },
2033
+ { name: "body", type: "string", internalType: "string" }
2034
+ ]
2035
+ },
2036
+ {
2037
+ name: "reponseResolve",
2038
+ type: "tuple[]",
2039
+ internalType: "struct AttNetworkResponseResolve[]",
2040
+ components: [
2041
+ { name: "keyName", type: "string", internalType: "string" },
2042
+ {
2043
+ name: "parseType",
2044
+ type: "string",
2045
+ internalType: "string"
2046
+ },
2047
+ {
2048
+ name: "parsePath",
2049
+ type: "string",
2050
+ internalType: "string"
2051
+ }
2052
+ ]
2053
+ },
2054
+ { name: "data", type: "string", internalType: "string" },
2055
+ {
2056
+ name: "attConditions",
2057
+ type: "string",
2058
+ internalType: "string"
2059
+ },
2060
+ { name: "timestamp", type: "uint64", internalType: "uint64" },
2061
+ {
2062
+ name: "additionParams",
2063
+ type: "string",
2064
+ internalType: "string"
2065
+ },
2066
+ {
2067
+ name: "attestors",
2068
+ type: "tuple[]",
2069
+ internalType: "struct Attestor[]",
2070
+ components: [
2071
+ {
2072
+ name: "attestorAddr",
2073
+ type: "address",
2074
+ internalType: "address"
2075
+ },
2076
+ { name: "url", type: "string", internalType: "string" }
2077
+ ]
2078
+ },
2079
+ { name: "signatures", type: "bytes[]", internalType: "bytes[]" }
2080
+ ]
956
2081
  }
957
2082
  ],
2083
+ outputs: [],
2084
+ stateMutability: "payable"
2085
+ },
2086
+ {
2087
+ type: "function",
2088
+ name: "reRecords",
2089
+ inputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
958
2090
  outputs: [
959
- {
960
- name: "",
2091
+ { name: "id", type: "bytes32", internalType: "bytes32" },
2092
+ { name: "tokenType", type: "uint32", internalType: "uint32" },
2093
+ { name: "reType", type: "uint32", internalType: "uint32" },
2094
+ { name: "number", type: "uint32", internalType: "uint32" },
2095
+ { name: "remainingNumber", type: "uint32", internalType: "uint32" },
2096
+ { name: "timestamp", type: "uint64", internalType: "uint64" },
2097
+ { name: "tokenAddress", type: "address", internalType: "address" },
2098
+ { name: "reSender", type: "address", internalType: "address" },
2099
+ { name: "checkContract", type: "address", internalType: "address" },
2100
+ { name: "amount", type: "uint256", internalType: "uint256" },
2101
+ {
2102
+ name: "remainingAmount",
961
2103
  type: "uint256",
962
2104
  internalType: "uint256"
963
- }
2105
+ },
2106
+ { name: "checkParams", type: "bytes", internalType: "bytes" }
964
2107
  ],
965
2108
  stateMutability: "view"
966
2109
  },
967
2110
  {
968
2111
  type: "function",
969
- name: "decimals",
970
- inputs: [],
971
- outputs: [
2112
+ name: "reSend",
2113
+ inputs: [
972
2114
  {
973
- name: "",
974
- type: "uint8",
975
- internalType: "uint8"
2115
+ name: "token",
2116
+ type: "tuple",
2117
+ internalType: "struct TipToken",
2118
+ components: [
2119
+ { name: "tokenType", type: "uint32", internalType: "uint32" },
2120
+ {
2121
+ name: "tokenAddress",
2122
+ type: "address",
2123
+ internalType: "address"
2124
+ }
2125
+ ]
2126
+ },
2127
+ {
2128
+ name: "sendParam",
2129
+ type: "tuple",
2130
+ internalType: "struct RESendParam",
2131
+ components: [
2132
+ { name: "reType", type: "uint32", internalType: "uint32" },
2133
+ { name: "number", type: "uint32", internalType: "uint32" },
2134
+ { name: "amount", type: "uint256", internalType: "uint256" },
2135
+ {
2136
+ name: "checkContract",
2137
+ type: "address",
2138
+ internalType: "address"
2139
+ },
2140
+ { name: "checkParams", type: "bytes", internalType: "bytes" }
2141
+ ]
976
2142
  }
977
2143
  ],
978
- stateMutability: "view"
2144
+ outputs: [],
2145
+ stateMutability: "payable"
979
2146
  },
980
2147
  {
981
2148
  type: "function",
982
- name: "name",
983
- inputs: [],
984
- outputs: [
985
- {
986
- name: "",
987
- type: "string",
988
- internalType: "string"
989
- }
2149
+ name: "reSenderWithdraw",
2150
+ inputs: [
2151
+ { name: "reId", type: "bytes32", internalType: "bytes32" }
990
2152
  ],
991
- stateMutability: "view"
2153
+ outputs: [],
2154
+ stateMutability: "nonpayable"
992
2155
  },
993
2156
  {
994
2157
  type: "function",
995
- name: "symbol",
2158
+ name: "renounceOwnership",
996
2159
  inputs: [],
997
- outputs: [
998
- {
999
- name: "",
1000
- type: "string",
1001
- internalType: "string"
1002
- }
2160
+ outputs: [],
2161
+ stateMutability: "nonpayable"
2162
+ },
2163
+ {
2164
+ type: "function",
2165
+ name: "setClaimFee",
2166
+ inputs: [
2167
+ { name: "claimFee_", type: "uint256", internalType: "uint256" }
1003
2168
  ],
1004
- stateMutability: "view"
2169
+ outputs: [],
2170
+ stateMutability: "nonpayable"
1005
2171
  },
1006
2172
  {
1007
2173
  type: "function",
1008
- name: "totalSupply",
1009
- inputs: [],
1010
- outputs: [
1011
- {
1012
- name: "",
1013
- type: "uint256",
1014
- internalType: "uint256"
1015
- }
2174
+ name: "setFeeRecipient",
2175
+ inputs: [
2176
+ { name: "feeRecipient_", type: "address", internalType: "address" }
1016
2177
  ],
1017
- stateMutability: "view"
2178
+ outputs: [],
2179
+ stateMutability: "nonpayable"
1018
2180
  },
1019
2181
  {
1020
2182
  type: "function",
1021
- name: "transfer",
2183
+ name: "setPrimusZKTLS",
1022
2184
  inputs: [
1023
2185
  {
1024
- name: "to",
2186
+ name: "primusZKTLS_",
1025
2187
  type: "address",
1026
- internalType: "address"
1027
- },
1028
- {
1029
- name: "value",
1030
- type: "uint256",
1031
- internalType: "uint256"
1032
- }
1033
- ],
1034
- outputs: [
1035
- {
1036
- name: "",
1037
- type: "bool",
1038
- internalType: "bool"
2188
+ internalType: "contract IPrimusZKTLS"
1039
2189
  }
1040
2190
  ],
2191
+ outputs: [],
1041
2192
  stateMutability: "nonpayable"
1042
2193
  },
1043
2194
  {
1044
2195
  type: "function",
1045
- name: "transferFrom",
2196
+ name: "setWithdrawDelay",
1046
2197
  inputs: [
1047
- {
1048
- name: "from",
1049
- type: "address",
1050
- internalType: "address"
1051
- },
1052
- {
1053
- name: "to",
1054
- type: "address",
1055
- internalType: "address"
1056
- },
1057
- {
1058
- name: "value",
1059
- type: "uint256",
1060
- internalType: "uint256"
1061
- }
2198
+ { name: "delay", type: "uint256", internalType: "uint256" }
1062
2199
  ],
1063
- outputs: [
1064
- {
1065
- name: "",
1066
- type: "bool",
1067
- internalType: "bool"
1068
- }
2200
+ outputs: [],
2201
+ stateMutability: "nonpayable"
2202
+ },
2203
+ {
2204
+ type: "function",
2205
+ name: "transferOwnership",
2206
+ inputs: [
2207
+ { name: "newOwner", type: "address", internalType: "address" }
1069
2208
  ],
2209
+ outputs: [],
1070
2210
  stateMutability: "nonpayable"
1071
2211
  },
2212
+ {
2213
+ type: "function",
2214
+ name: "withdrawDelay",
2215
+ inputs: [],
2216
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2217
+ stateMutability: "view"
2218
+ },
1072
2219
  {
1073
2220
  type: "event",
1074
- name: "Approval",
2221
+ name: "Initialized",
1075
2222
  inputs: [
1076
2223
  {
1077
- name: "owner",
1078
- type: "address",
1079
- indexed: true,
1080
- internalType: "address"
1081
- },
1082
- {
1083
- name: "spender",
1084
- type: "address",
1085
- indexed: true,
1086
- internalType: "address"
1087
- },
1088
- {
1089
- name: "value",
1090
- type: "uint256",
2224
+ name: "version",
2225
+ type: "uint64",
1091
2226
  indexed: false,
1092
- internalType: "uint256"
2227
+ internalType: "uint64"
1093
2228
  }
1094
2229
  ],
1095
2230
  anonymous: false
1096
2231
  },
1097
2232
  {
1098
2233
  type: "event",
1099
- name: "Transfer",
2234
+ name: "OwnershipTransferred",
1100
2235
  inputs: [
1101
2236
  {
1102
- name: "from",
2237
+ name: "previousOwner",
1103
2238
  type: "address",
1104
2239
  indexed: true,
1105
2240
  internalType: "address"
1106
2241
  },
1107
2242
  {
1108
- name: "to",
2243
+ name: "newOwner",
1109
2244
  type: "address",
1110
2245
  indexed: true,
1111
2246
  internalType: "address"
1112
- },
1113
- {
1114
- name: "value",
1115
- type: "uint256",
1116
- indexed: false,
1117
- internalType: "uint256"
1118
2247
  }
1119
2248
  ],
1120
2249
  anonymous: false
1121
2250
  },
1122
2251
  {
1123
- type: "error",
1124
- name: "ERC20InsufficientAllowance",
2252
+ type: "event",
2253
+ name: "REClaimEvent",
1125
2254
  inputs: [
1126
2255
  {
1127
- name: "spender",
1128
- type: "address",
1129
- internalType: "address"
1130
- },
1131
- {
1132
- name: "allowance",
1133
- type: "uint256",
1134
- internalType: "uint256"
2256
+ name: "id",
2257
+ type: "bytes32",
2258
+ indexed: true,
2259
+ internalType: "bytes32"
1135
2260
  },
1136
2261
  {
1137
- name: "needed",
1138
- type: "uint256",
1139
- internalType: "uint256"
1140
- }
1141
- ]
1142
- },
1143
- {
1144
- type: "error",
1145
- name: "ERC20InsufficientBalance",
1146
- inputs: [
1147
- {
1148
- name: "sender",
2262
+ name: "recipient",
1149
2263
  type: "address",
2264
+ indexed: false,
1150
2265
  internalType: "address"
1151
2266
  },
1152
2267
  {
1153
- name: "balance",
1154
- type: "uint256",
1155
- internalType: "uint256"
2268
+ name: "userId",
2269
+ type: "string",
2270
+ indexed: false,
2271
+ internalType: "string"
1156
2272
  },
1157
2273
  {
1158
- name: "needed",
2274
+ name: "claimAmount",
1159
2275
  type: "uint256",
2276
+ indexed: false,
1160
2277
  internalType: "uint256"
1161
- }
1162
- ]
1163
- },
1164
- {
1165
- type: "error",
1166
- name: "ERC20InvalidApprover",
1167
- inputs: [
1168
- {
1169
- name: "approver",
1170
- type: "address",
1171
- internalType: "address"
1172
- }
1173
- ]
1174
- },
1175
- {
1176
- type: "error",
1177
- name: "ERC20InvalidReceiver",
1178
- inputs: [
1179
- {
1180
- name: "receiver",
1181
- type: "address",
1182
- internalType: "address"
1183
- }
1184
- ]
1185
- },
1186
- {
1187
- type: "error",
1188
- name: "ERC20InvalidSender",
1189
- inputs: [
2278
+ },
1190
2279
  {
1191
- name: "sender",
1192
- type: "address",
1193
- internalType: "address"
1194
- }
1195
- ]
1196
- },
1197
- {
1198
- type: "error",
1199
- name: "ERC20InvalidSpender",
1200
- inputs: [
2280
+ name: "reIndex",
2281
+ type: "uint32",
2282
+ indexed: false,
2283
+ internalType: "uint32"
2284
+ },
1201
2285
  {
1202
- name: "spender",
1203
- type: "address",
1204
- internalType: "address"
1205
- }
1206
- ]
1207
- }
1208
- ];
1209
-
1210
- // src/config/erc721Abi.json
1211
- var erc721Abi_default = [
1212
- {
1213
- type: "function",
1214
- name: "supportsInterface",
1215
- stateMutability: "view",
1216
- inputs: [
1217
- { internalType: "bytes4", name: "interfaceId", type: "bytes4" }
1218
- ],
1219
- outputs: [{ internalType: "bool", name: "", type: "bool" }]
1220
- },
1221
- {
1222
- type: "function",
1223
- name: "balanceOf",
1224
- stateMutability: "view",
1225
- inputs: [
1226
- { internalType: "address", name: "owner", type: "address" }
1227
- ],
1228
- outputs: [{ internalType: "uint256", name: "", type: "uint256" }]
1229
- },
1230
- {
1231
- type: "function",
1232
- name: "ownerOf",
1233
- stateMutability: "view",
1234
- inputs: [
1235
- { internalType: "uint256", name: "tokenId", type: "uint256" }
1236
- ],
1237
- outputs: [{ internalType: "address", name: "", type: "address" }]
1238
- },
1239
- {
1240
- type: "function",
1241
- name: "tokenURI",
1242
- stateMutability: "view",
1243
- inputs: [
1244
- { internalType: "uint256", name: "tokenId", type: "uint256" }
1245
- ],
1246
- outputs: [{ internalType: "string", name: "", type: "string" }]
1247
- },
1248
- {
1249
- type: "function",
1250
- name: "approve",
1251
- stateMutability: "nonpayable",
1252
- inputs: [
1253
- { internalType: "address", name: "to", type: "address" },
1254
- { internalType: "uint256", name: "tokenId", type: "uint256" }
1255
- ],
1256
- outputs: []
1257
- },
1258
- {
1259
- type: "function",
1260
- name: "getApproved",
1261
- stateMutability: "view",
1262
- inputs: [
1263
- { internalType: "uint256", name: "tokenId", type: "uint256" }
1264
- ],
1265
- outputs: [{ internalType: "address", name: "", type: "address" }]
1266
- },
1267
- {
1268
- type: "function",
1269
- name: "setApprovalForAll",
1270
- stateMutability: "nonpayable",
1271
- inputs: [
1272
- { internalType: "address", name: "operator", type: "address" },
1273
- { internalType: "bool", name: "approved", type: "bool" }
1274
- ],
1275
- outputs: []
1276
- },
1277
- {
1278
- type: "function",
1279
- name: "isApprovedForAll",
1280
- stateMutability: "view",
1281
- inputs: [
1282
- { internalType: "address", name: "owner", type: "address" },
1283
- { internalType: "address", name: "operator", type: "address" }
2286
+ name: "timestamp",
2287
+ type: "uint64",
2288
+ indexed: false,
2289
+ internalType: "uint64"
2290
+ }
1284
2291
  ],
1285
- outputs: [{ internalType: "bool", name: "", type: "bool" }]
2292
+ anonymous: false
1286
2293
  },
1287
2294
  {
1288
- type: "function",
1289
- name: "transferFrom",
1290
- stateMutability: "nonpayable",
2295
+ type: "event",
2296
+ name: "RESWithdrawEvent",
1291
2297
  inputs: [
1292
- { internalType: "address", name: "from", type: "address" },
1293
- { internalType: "address", name: "to", type: "address" },
1294
- { internalType: "uint256", name: "tokenId", type: "uint256" }
2298
+ {
2299
+ name: "id",
2300
+ type: "bytes32",
2301
+ indexed: true,
2302
+ internalType: "bytes32"
2303
+ },
2304
+ {
2305
+ name: "reSender",
2306
+ type: "address",
2307
+ indexed: false,
2308
+ internalType: "address"
2309
+ },
2310
+ {
2311
+ name: "amount",
2312
+ type: "uint256",
2313
+ indexed: false,
2314
+ internalType: "uint256"
2315
+ },
2316
+ {
2317
+ name: "remainingNumber",
2318
+ type: "uint32",
2319
+ indexed: false,
2320
+ internalType: "uint32"
2321
+ },
2322
+ {
2323
+ name: "timestamp",
2324
+ type: "uint64",
2325
+ indexed: false,
2326
+ internalType: "uint64"
2327
+ }
1295
2328
  ],
1296
- outputs: []
2329
+ anonymous: false
1297
2330
  },
1298
2331
  {
1299
- type: "function",
1300
- name: "safeTransferFrom",
1301
- stateMutability: "nonpayable",
2332
+ type: "event",
2333
+ name: "RESendEvent",
1302
2334
  inputs: [
1303
- { internalType: "address", name: "from", type: "address" },
1304
- { internalType: "address", name: "to", type: "address" },
1305
- { internalType: "uint256", name: "tokenId", type: "uint256" }
2335
+ {
2336
+ name: "id",
2337
+ type: "bytes32",
2338
+ indexed: true,
2339
+ internalType: "bytes32"
2340
+ },
2341
+ {
2342
+ name: "reSender",
2343
+ type: "address",
2344
+ indexed: false,
2345
+ internalType: "address"
2346
+ },
2347
+ {
2348
+ name: "tokenType",
2349
+ type: "uint32",
2350
+ indexed: false,
2351
+ internalType: "uint32"
2352
+ },
2353
+ {
2354
+ name: "tokenAddress",
2355
+ type: "address",
2356
+ indexed: false,
2357
+ internalType: "address"
2358
+ },
2359
+ {
2360
+ name: "amount",
2361
+ type: "uint256",
2362
+ indexed: false,
2363
+ internalType: "uint256"
2364
+ },
2365
+ {
2366
+ name: "reType",
2367
+ type: "uint32",
2368
+ indexed: false,
2369
+ internalType: "uint32"
2370
+ },
2371
+ {
2372
+ name: "number",
2373
+ type: "uint32",
2374
+ indexed: false,
2375
+ internalType: "uint32"
2376
+ },
2377
+ {
2378
+ name: "timestamp",
2379
+ type: "uint64",
2380
+ indexed: false,
2381
+ internalType: "uint64"
2382
+ }
1306
2383
  ],
1307
- outputs: []
2384
+ anonymous: false
1308
2385
  },
2386
+ { type: "error", name: "InvalidInitialization", inputs: [] },
2387
+ { type: "error", name: "NotInitializing", inputs: [] },
1309
2388
  {
1310
- type: "function",
1311
- name: "name",
1312
- stateMutability: "view",
1313
- inputs: [],
1314
- outputs: [{ internalType: "string", name: "", type: "string" }]
2389
+ type: "error",
2390
+ name: "OwnableInvalidOwner",
2391
+ inputs: [
2392
+ { name: "owner", type: "address", internalType: "address" }
2393
+ ]
1315
2394
  },
1316
2395
  {
1317
- type: "function",
1318
- name: "symbol",
1319
- stateMutability: "view",
1320
- inputs: [],
1321
- outputs: [{ internalType: "string", name: "", type: "string" }]
2396
+ type: "error",
2397
+ name: "OwnableUnauthorizedAccount",
2398
+ inputs: [
2399
+ { name: "account", type: "address", internalType: "address" }
2400
+ ]
1322
2401
  }
1323
2402
  ];
1324
2403
 
1325
- // src/classes/Erc721Contract.ts
1326
- var Erc721Contract = class {
1327
- contractInstance;
1328
- constructor(provider, address) {
1329
- if (!provider || !address) {
1330
- throw new Error("provider, address are required");
1331
- }
1332
- this.contractInstance = new Contract_default(provider, address, erc721Abi_default);
1333
- }
1334
- async approve(address, tokenId) {
1335
- return new Promise(async (resolve, reject) => {
1336
- try {
1337
- const approver = await this.contractInstance.callMethod("getApproved", [tokenId]);
1338
- if (approver === address) {
1339
- console.log(`Already approved:: ${approver}`);
1340
- resolve("Approved");
1341
- } else {
1342
- await this.contractInstance.sendTransaction("approve", [address, tokenId]);
1343
- console.log(`Approved`);
1344
- resolve("Approved");
1345
- }
1346
- } catch (error) {
1347
- console.error("Approval failed:", error);
1348
- return reject(error);
1349
- }
1350
- });
1351
- }
1352
- // ownerAddress: string,
1353
- async setApprovalForAll(operatorAddress) {
1354
- return new Promise(async (resolve, reject) => {
1355
- try {
1356
- await this.contractInstance.sendTransaction("setApprovalForAll", [operatorAddress, true]);
1357
- console.log(`Approved`);
1358
- resolve("Approved");
1359
- } catch (error) {
1360
- console.error("Approval failed:", error);
1361
- return reject(error);
1362
- }
1363
- });
1364
- }
1365
- async fetchMetaData(nftContractAddress, tokenId) {
1366
- return new Promise(async (resolve, reject) => {
1367
- try {
1368
- let url = await this.contractInstance.callMethod("tokenURI", [tokenId]);
1369
- if (url.startsWith("ipfs://")) {
1370
- url = url.replace("ipfs://", "https://ipfs.io/ipfs/");
1371
- }
1372
- const res = await fetch(url);
1373
- if (!res.ok) {
1374
- return reject(`Failed to fetch metadata from ${url}`);
1375
- }
1376
- let metadata = await res.json();
1377
- if (metadata.image && metadata.image.startsWith("ipfs://")) {
1378
- metadata.image = metadata.image.replace(
1379
- "ipfs://",
1380
- "https://ipfs.io/ipfs/"
1381
- );
1382
- }
1383
- metadata.address = nftContractAddress;
1384
- metadata.tokenId = tokenId;
1385
- return resolve(metadata);
1386
- } catch (error) {
1387
- return reject(error);
1388
- }
1389
- });
1390
- }
1391
- };
1392
- var Erc721Contract_default = Erc721Contract;
1393
-
1394
- // src/classes/Fund.ts
1395
- var { parseUnits, formatUnits } = import_ethers2.ethers.utils;
1396
- var Fund = class {
1397
- zkTlsSdk;
2404
+ // src/classes/FundForRedPacket.ts
2405
+ var { parseUnits: parseUnits3 } = import_ethers4.ethers.utils;
2406
+ var FundForRedPacket = class {
1398
2407
  fundContract;
1399
2408
  provider;
1400
2409
  formatProvider;
1401
2410
  chainId;
1402
- _dataSourceTemplateMap = DATASOURCETEMPLATESMAP;
1403
2411
  constructor() {
1404
2412
  }
1405
- getZkTlsSdk() {
1406
- return this.zkTlsSdk;
1407
- }
1408
- async init(provider, chainId, appId) {
2413
+ async init(provider, chainId) {
1409
2414
  return new Promise(async (resolve, reject) => {
1410
2415
  try {
1411
- let formatProvider;
1412
- if (provider instanceof import_ethers2.ethers.providers.JsonRpcProvider) {
1413
- formatProvider = provider;
1414
- } else {
1415
- formatProvider = new import_ethers2.ethers.providers.Web3Provider(provider);
1416
- }
1417
- const gasPrice = await formatProvider.getGasPrice();
1418
- console.log("getGasPrice=", gasPrice);
1419
- await formatProvider.ready;
1420
- const network = await formatProvider.getNetwork();
1421
- const providerChainId = network.chainId;
1422
- console.log("init provider", provider, network);
1423
- console.log("init providerChainId", providerChainId, chainId);
1424
- if (providerChainId !== chainId) {
1425
- return reject(`Please connect to the chain with ID ${chainId} first.`);
1426
- }
1427
- const fundContractAddress = Fund_CONTRACTS[chainId];
2416
+ const fundContractAddress = FundForRedPacket_CONTRACTS[chainId];
1428
2417
  if (!fundContractAddress) {
1429
2418
  return reject(`Unsupported chainId:${chainId}`);
1430
2419
  }
1431
- this.fundContract = new Contract_default(provider, fundContractAddress, abi_default);
2420
+ this.fundContract = new Contract_default(provider, fundContractAddress, abiForRedPacket_default);
1432
2421
  this.provider = provider;
1433
- this.formatProvider = formatProvider;
1434
2422
  this.chainId = chainId;
1435
- if (appId) {
1436
- this.zkTlsSdk = new import_zktls_js_sdk.PrimusZKTLS();
1437
- let platformDevice = "pc";
1438
- const isIpad = () => {
1439
- const userAgent = navigator.userAgent.toLowerCase();
1440
- const isTabletSize = window.innerWidth > 768 && window.innerWidth < 1366;
1441
- return /ipad/.test(userAgent) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 0 && isTabletSize;
1442
- };
1443
- if (navigator.userAgent.toLocaleLowerCase().includes("android")) {
1444
- platformDevice = "android";
1445
- } else if (navigator.userAgent.toLocaleLowerCase().includes("iphone") || isIpad()) {
1446
- platformDevice = "ios";
1447
- }
1448
- console.log("init appId", appId, platformDevice);
1449
- const extensionVersion = await this.zkTlsSdk.init(
1450
- appId,
1451
- "",
1452
- { platform: platformDevice }
1453
- );
1454
- resolve(extensionVersion);
1455
- } else {
1456
- resolve("success");
1457
- }
2423
+ resolve("success");
1458
2424
  } catch (error) {
1459
2425
  return reject(error);
1460
2426
  }
1461
2427
  });
1462
2428
  }
1463
- async fund(tokenInfo, recipientInfo) {
2429
+ async fundForRedPacket(tokenInfo, sendParam) {
1464
2430
  return new Promise(async (resolve, reject) => {
1465
2431
  try {
1466
- const recipientInfos = [];
1467
- recipientInfos[0] = recipientInfo;
1468
2432
  let decimals = 18;
1469
2433
  let params = [];
1470
2434
  if (tokenInfo.tokenType === 0) {
1471
- await this.approve(tokenInfo, recipientInfos);
2435
+ await this.approveForRedPacket(tokenInfo, sendParam.amount);
1472
2436
  console.log("after approve in fund fn");
1473
- const web3Provider = new import_ethers2.ethers.providers.Web3Provider(this.provider);
1474
- const erc20Contract = new import_ethers2.ethers.Contract(tokenInfo.tokenAddress, erc20Abi_default, web3Provider);
1475
- decimals = await erc20Contract.decimals();
1476
- } else if (tokenInfo.tokenType === 2) {
1477
- decimals = 0;
1478
- const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenInfo.tokenAddress);
1479
- await erc721ContractInstance.approve(this.fundContract.address, recipientInfo.nftIds[0]);
2437
+ const tokenContract = new Erc20Contract_default(this.provider, tokenInfo.tokenAddress);
2438
+ decimals = await tokenContract.decimals();
1480
2439
  }
1481
- const tokenAmount = parseUnits(recipientInfo.tokenAmount.toString(), decimals);
1482
- const newFundRecipientInfo = {
1483
- idSource: recipientInfo.socialPlatform,
1484
- id: recipientInfo.userIdentifier,
1485
- amount: tokenAmount,
1486
- nftIds: recipientInfo.nftIds
2440
+ if (tokenInfo.tokenType === 1) {
2441
+ tokenInfo.tokenAddress = import_ethers4.ethers.constants.AddressZero;
2442
+ }
2443
+ const formatSendAmount = parseUnits3(sendParam.amount.toString(), decimals);
2444
+ const formatSendParam = {
2445
+ ...sendParam,
2446
+ amount: formatSendAmount
1487
2447
  };
1488
2448
  if (tokenInfo.tokenType === 1) {
1489
- params = [tokenInfo, newFundRecipientInfo, { value: tokenAmount }];
2449
+ params = [tokenInfo, formatSendParam, { value: formatSendAmount }];
1490
2450
  } else {
1491
- params = [tokenInfo, newFundRecipientInfo];
2451
+ params = [tokenInfo, formatSendParam];
1492
2452
  }
1493
2453
  if ([97, 56].includes(this.chainId)) {
1494
- const gasPrice = await this.formatProvider.getGasPrice();
2454
+ const gasPrice = await this.provider.getGasPrice();
1495
2455
  params[2] = params[2] ? { ...params[2], gasPrice } : { gasPrice };
1496
2456
  }
1497
- console.log("tip-params", params, this.chainId);
1498
- const result = await this.fundContract.sendTransaction("tip", params);
2457
+ console.log("tipForRedPacket-params", params, this.chainId);
2458
+ const result = await this.fundContract.sendTransaction("reSend", params);
1499
2459
  resolve(result);
1500
2460
  } catch (error) {
1501
2461
  return reject(error);
1502
2462
  }
1503
2463
  });
1504
2464
  }
1505
- async onlyFund(tokenInfo, recipientInfo) {
2465
+ async onlyFundForRedPacket(tokenInfo, sendParam) {
1506
2466
  return new Promise(async (resolve, reject) => {
1507
2467
  try {
1508
- const recipientInfos = [];
1509
- recipientInfos[0] = recipientInfo;
1510
2468
  let decimals = 18;
1511
2469
  let params = [];
1512
2470
  if (tokenInfo.tokenType === 0) {
1513
- const web3Provider = new import_ethers2.ethers.providers.Web3Provider(this.provider);
1514
- const erc20Contract = new import_ethers2.ethers.Contract(tokenInfo.tokenAddress, erc20Abi_default, web3Provider);
1515
- decimals = await erc20Contract.decimals();
1516
- } else if (tokenInfo.tokenType === 2) {
1517
- decimals = 0;
1518
- const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenInfo.tokenAddress);
1519
- await erc721ContractInstance.approve(this.fundContract.address, recipientInfo.nftIds[0]);
2471
+ const tokenContract = new Erc20Contract_default(this.provider, tokenInfo.tokenAddress);
2472
+ decimals = await tokenContract.decimals();
1520
2473
  }
1521
- const tokenAmount = parseUnits(recipientInfo.tokenAmount.toString(), decimals);
1522
- const newFundRecipientInfo = {
1523
- idSource: recipientInfo.socialPlatform,
1524
- id: recipientInfo.userIdentifier,
1525
- amount: tokenAmount,
1526
- nftIds: recipientInfo.nftIds
2474
+ if (tokenInfo.tokenType === 1) {
2475
+ tokenInfo.tokenAddress = import_ethers4.ethers.constants.AddressZero;
2476
+ }
2477
+ const formatSendAmount = parseUnits3(sendParam.amount.toString(), decimals);
2478
+ const formatSendParam = {
2479
+ ...sendParam,
2480
+ amount: formatSendAmount
1527
2481
  };
1528
2482
  if (tokenInfo.tokenType === 1) {
1529
- params = [tokenInfo, newFundRecipientInfo, { value: tokenAmount }];
2483
+ params = [tokenInfo, formatSendParam, { value: formatSendAmount }];
1530
2484
  } else {
1531
- params = [tokenInfo, newFundRecipientInfo];
2485
+ params = [tokenInfo, formatSendParam];
1532
2486
  }
1533
2487
  if ([97, 56].includes(this.chainId)) {
1534
- const gasPrice = await this.formatProvider.getGasPrice();
2488
+ const gasPrice = await this.provider.getGasPrice();
1535
2489
  params[2] = params[2] ? { ...params[2], gasPrice } : { gasPrice };
1536
2490
  }
1537
- console.log("tip-params", params, this.chainId);
1538
- const result = await this.fundContract.sendTransaction("tip", params);
2491
+ console.log("onlytipForRedPacket-params", params, this.chainId);
2492
+ const result = await this.fundContract.sendTransaction("reSend", params);
1539
2493
  resolve(result);
1540
2494
  } catch (error) {
1541
2495
  return reject(error);
1542
2496
  }
1543
2497
  });
1544
2498
  }
1545
- async refund(recipients) {
2499
+ async withdrawForRedPacket(redPacketId) {
1546
2500
  return new Promise(async (resolve, reject) => {
1547
2501
  try {
1548
- const newRecipients = recipients.map((i) => {
1549
- return {
1550
- idSource: i.socialPlatform,
1551
- id: i.userIdentifier,
1552
- tipTimestamp: i.tipTimestamp
1553
- };
1554
- });
1555
- let params = [newRecipients];
2502
+ let params = [redPacketId];
2503
+ if ([97, 56].includes(this.chainId)) {
2504
+ const gasPrice = await this.provider.getGasPrice();
2505
+ params.push({
2506
+ gasPrice
2507
+ });
2508
+ }
2509
+ const result = await this.fundContract.sendTransaction("reSenderWithdraw", params);
2510
+ return resolve(result);
2511
+ } catch (error) {
2512
+ return reject(error);
2513
+ }
2514
+ });
2515
+ }
2516
+ async approveForRedPacket(tokenInfo, approveAmount) {
2517
+ return new Promise(async (resolve, reject) => {
2518
+ try {
2519
+ let approveParams = {
2520
+ spenderAddress: this.fundContract.address,
2521
+ approveAmount
2522
+ };
1556
2523
  if ([97, 56].includes(this.chainId)) {
1557
- const gasPrice = await this.formatProvider.getGasPrice();
1558
- params.push({
1559
- gasPrice
1560
- });
2524
+ const gasPrice = await this.provider.getGasPrice();
2525
+ approveParams.otherParams = { gasPrice };
1561
2526
  }
1562
- const result = await this.fundContract.sendTransaction("tipperWithdraw", params);
1563
- return resolve(result);
2527
+ const tokenContract = new Erc20Contract_default(this.provider, tokenInfo.tokenAddress);
2528
+ await tokenContract.approve(approveParams);
2529
+ resolve("Approved");
1564
2530
  } catch (error) {
1565
2531
  return reject(error);
1566
2532
  }
1567
2533
  });
1568
2534
  }
1569
- async fundBatch(tokenInfo, recipientInfoList) {
2535
+ async claimForRedPacket(redPacketId, attestation) {
1570
2536
  return new Promise(async (resolve, reject) => {
1571
2537
  try {
1572
- let decimals = 18;
1573
- let params = [];
1574
- if (tokenInfo.tokenType === 0) {
1575
- await this.approve(tokenInfo, recipientInfoList);
1576
- const web3Provider = new import_ethers2.ethers.providers.Web3Provider(this.provider);
1577
- const erc20Contract = new import_ethers2.ethers.Contract(tokenInfo.tokenAddress, erc20Abi_default, web3Provider);
1578
- decimals = await erc20Contract.decimals();
1579
- } else if (tokenInfo.tokenType === 2) {
1580
- decimals = 0;
1581
- const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenInfo.tokenAddress);
1582
- await erc721ContractInstance.setApprovalForAll(this.fundContract.address);
1583
- }
1584
- let totalFormatAmount = recipientInfoList.reduce((acc, cur) => acc.add(parseUnits(cur.tokenAmount.toString(), decimals)), import_ethers2.ethers.BigNumber.from(0));
1585
- const newRecipientInfoList = recipientInfoList.map((i) => {
1586
- const formatAmount = parseUnits(i.tokenAmount.toString(), decimals);
1587
- return {
1588
- idSource: i.socialPlatform,
1589
- id: i.userIdentifier,
1590
- amount: formatAmount,
1591
- nftIds: i.nftIds
1592
- };
1593
- });
1594
- if (tokenInfo.tokenType === 1) {
1595
- params = [tokenInfo, newRecipientInfoList, { value: totalFormatAmount }];
1596
- } else {
1597
- params = [tokenInfo, newRecipientInfoList];
1598
- }
2538
+ const claimFee = await this.fundContract.callMethod("claimFee", []);
2539
+ let params = [redPacketId, attestation, { value: claimFee }];
1599
2540
  if ([97, 56].includes(this.chainId)) {
1600
- const gasPrice = await this.formatProvider.getGasPrice();
1601
- params[2] = params[2] ? { ...params[2], gasPrice } : { gasPrice };
2541
+ const gasPrice = await this.provider.getGasPrice();
2542
+ params[2].gasPrice = gasPrice;
1602
2543
  }
1603
- const result = await this.fundContract.sendTransaction("tipBatch", params);
1604
- return resolve(result);
2544
+ const txreceipt = await this.fundContract.sendTransaction("reClaim", params);
2545
+ return resolve(txreceipt);
1605
2546
  } catch (error) {
1606
2547
  return reject(error);
1607
2548
  }
1608
2549
  });
1609
2550
  }
1610
- // TODO-nft
1611
- async approve(tokenInfo, recipientInfoList) {
2551
+ async getRedPacketInfo(redPacketId) {
1612
2552
  return new Promise(async (resolve, reject) => {
1613
2553
  try {
1614
- const web3Provider = new import_ethers2.ethers.providers.Web3Provider(this.provider);
1615
- const signer = web3Provider.getSigner();
1616
- const address = await signer.getAddress();
1617
- const erc20Contract = new import_ethers2.ethers.Contract(tokenInfo.tokenAddress, erc20Abi_default, signer);
1618
- const allowance = await erc20Contract.allowance(address, this.fundContract.address);
1619
- const decimals = await erc20Contract.decimals();
1620
- console.log("allowance", formatUnits(allowance.toString(), decimals));
1621
- const requiredAllowance = recipientInfoList.reduce((acc, cur) => acc.add(parseUnits(cur.tokenAmount.toString(), decimals)), import_ethers2.ethers.BigNumber.from(0));
1622
- if (allowance.lt(requiredAllowance)) {
1623
- let params = [this.fundContract.address, requiredAllowance];
1624
- if ([97, 56].includes(this.chainId)) {
1625
- const gasPrice = await this.formatProvider.getGasPrice();
1626
- params.push({ gasPrice });
1627
- }
1628
- const tx = await erc20Contract.approve(...params);
1629
- await tx.wait();
1630
- console.log(`Approved: ${requiredAllowance.toString()}`);
1631
- } else {
1632
- console.log(`Already approved: ${allowance.toString()}`);
1633
- }
1634
- resolve("Approved");
2554
+ const redpacketInfo = await this.fundContract.callMethod("getREInfo", [redPacketId]);
2555
+ return resolve(redpacketInfo);
1635
2556
  } catch (error) {
1636
- console.error("Approval failed:", error);
1637
- if (error?.code === "ACTION_REJECTED") {
1638
- return reject("user rejected transaction");
2557
+ return reject(error);
2558
+ }
2559
+ });
2560
+ }
2561
+ };
2562
+
2563
+ // src/classes/ZktlsSdk.ts
2564
+ var import_zktls_js_sdk = require("@primuslabs/zktls-js-sdk");
2565
+ var ZktlsSdk = class {
2566
+ zkTlsSdk;
2567
+ constructor() {
2568
+ }
2569
+ getZkTlsSdk() {
2570
+ return this.zkTlsSdk;
2571
+ }
2572
+ async init(appId) {
2573
+ return new Promise(async (resolve, reject) => {
2574
+ try {
2575
+ this.zkTlsSdk = new import_zktls_js_sdk.PrimusZKTLS();
2576
+ let platformDevice = "pc";
2577
+ const isIpad = () => {
2578
+ const userAgent = navigator.userAgent.toLowerCase();
2579
+ const isTabletSize = window.innerWidth > 768 && window.innerWidth < 1366;
2580
+ return /ipad/.test(userAgent) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 0 && isTabletSize;
2581
+ };
2582
+ if (navigator.userAgent.toLocaleLowerCase().includes("android")) {
2583
+ platformDevice = "android";
2584
+ } else if (navigator.userAgent.toLocaleLowerCase().includes("iphone") || isIpad()) {
2585
+ platformDevice = "ios";
1639
2586
  }
2587
+ console.log("init appId", appId, platformDevice);
2588
+ const extensionVersion = await this.zkTlsSdk.init(
2589
+ appId,
2590
+ "",
2591
+ { platform: platformDevice }
2592
+ );
2593
+ resolve(extensionVersion);
2594
+ } catch (error) {
1640
2595
  return reject(error);
1641
2596
  }
1642
2597
  });
1643
2598
  }
1644
- async attest(attestParams, genAppSignature, backUrl) {
2599
+ async attest(attestParams, signFn, backUrl) {
1645
2600
  return new Promise(async (resolve, reject) => {
1646
2601
  console.log("this.zkTlsSdk", this.zkTlsSdk);
1647
2602
  const { socialPlatform, userIdentifier, address } = attestParams;
1648
- const { id: templateId, field } = this._dataSourceTemplateMap[socialPlatform];
2603
+ const { id: templateId, field } = DATASOURCETEMPLATESMAP[socialPlatform];
1649
2604
  const attRequest = this.zkTlsSdk.generateRequestParams(
1650
2605
  templateId,
1651
2606
  address
@@ -1664,7 +2619,7 @@ var Fund = class {
1664
2619
  ]
1665
2620
  ]);
1666
2621
  const signParams = attRequest.toJsonString();
1667
- const signature = await genAppSignature(signParams);
2622
+ const signature = await signFn(signParams);
1668
2623
  if (!signature) {
1669
2624
  return reject(`appSignature is empty!`);
1670
2625
  }
@@ -1684,121 +2639,41 @@ var Fund = class {
1684
2639
  }
1685
2640
  });
1686
2641
  }
1687
- async claimBySource(socialPlatform, userIdentifier, attestation) {
2642
+ async attestCommon(attestParams) {
2643
+ const { templateId, address, signFn, conditions, additionParams, backUrl } = attestParams;
1688
2644
  return new Promise(async (resolve, reject) => {
1689
- try {
1690
- const claimFee = await this.fundContract.callMethod("claimFee", []);
1691
- const fundRecords = await this.fundContract.callMethod("getTipRecords", [{ idSource: socialPlatform, id: userIdentifier }]);
1692
- console.log("fundRecords", fundRecords);
1693
- const recordCount = fundRecords.length;
1694
- if (recordCount <= 0) {
1695
- return reject(`No fund records.`);
1696
- } else {
1697
- const totalFee = claimFee.mul(recordCount);
1698
- let params = [socialPlatform, attestation, { value: totalFee }];
1699
- if ([97, 56].includes(this.chainId)) {
1700
- const gasPrice = await this.formatProvider.getGasPrice();
1701
- params[2].gasPrice = gasPrice;
1702
- }
1703
- const txreceipt = await this.fundContract.sendTransaction("claimBySource", params);
1704
- return resolve(txreceipt);
1705
- }
1706
- } catch (error) {
1707
- return reject(error);
2645
+ console.log("this.zkTlsSdk", this.zkTlsSdk);
2646
+ const attRequest = this.zkTlsSdk.generateRequestParams(
2647
+ templateId,
2648
+ address
2649
+ );
2650
+ if (backUrl) {
2651
+ attRequest.setBackUrl(backUrl);
1708
2652
  }
1709
- });
1710
- }
1711
- async claimByMultiSource(socialPlatforms, userIdentifiers, attestationList) {
1712
- return new Promise(async (resolve, reject) => {
1713
- try {
1714
- if (socialPlatforms.length !== userIdentifiers.length || socialPlatforms.length !== attestationList.length) {
1715
- return reject(`socialPlatforms, userIdentifiers, attestationList length must be equal.`);
1716
- }
1717
- const claimFee = await this.fundContract.callMethod("claimFee", []);
1718
- let allFundRecords = [];
1719
- let recordCount = 0;
1720
- for (const [index, value] of socialPlatforms.entries()) {
1721
- const fundRecords = await this.fundContract.callMethod("getTipRecords", [{ idSource: value, id: userIdentifiers[index] }]);
1722
- allFundRecords.push(...fundRecords);
1723
- recordCount += fundRecords.length;
1724
- }
1725
- if (recordCount <= 0) {
1726
- return reject(`No fund records.`);
1727
- } else {
1728
- const totalFee = claimFee.mul(recordCount);
1729
- let params = [socialPlatforms, userIdentifiers, attestationList, { value: totalFee }];
1730
- if ([97, 56].includes(this.chainId)) {
1731
- const gasPrice = await this.formatProvider.getGasPrice();
1732
- params[3].gasPrice = gasPrice;
1733
- }
1734
- const txreceipt = await this.fundContract.sendTransaction("claimByMultiSource", params);
1735
- return resolve(txreceipt);
1736
- }
1737
- } catch (error) {
1738
- console.error("claimByMultiSource", error);
1739
- return reject(error);
2653
+ console.log(`attRequest: ${JSON.stringify(attRequest)}`);
2654
+ if (conditions) {
2655
+ attRequest.setAttConditions(conditions);
2656
+ }
2657
+ if (additionParams) {
2658
+ console.log("setAdditionParams--", additionParams);
2659
+ attRequest.setAdditionParams(additionParams);
2660
+ }
2661
+ const signParams = attRequest.toJsonString();
2662
+ const signature = await signFn(signParams);
2663
+ if (!signature) {
2664
+ return reject(`appSignature is empty!`);
1740
2665
  }
1741
- });
1742
- }
1743
- async getTipRecords(getFundRecordsParams) {
1744
- return new Promise(async (resolve, reject) => {
1745
2666
  try {
1746
- const formatGetFundRecordsParams = getFundRecordsParams.map((item) => {
1747
- return {
1748
- idSource: item.socialPlatform,
1749
- id: item.userIdentifier
1750
- };
1751
- });
1752
- const fundRecords = await this.fundContract.callMethod("getTipRecords", formatGetFundRecordsParams);
1753
- console.log("fundRecords", fundRecords);
1754
- let formatRecords = [];
1755
- for (const record of fundRecords) {
1756
- const { tipper, timestamp, tipToken: [tokenType, tokenAddress], amount, nftIds } = record;
1757
- let decimals = 18;
1758
- let symbol = "";
1759
- let tokenId = null;
1760
- let nftInfo = null;
1761
- if (tokenType === 0) {
1762
- let formatProvider;
1763
- if (this.provider instanceof import_ethers2.ethers.providers.JsonRpcProvider) {
1764
- formatProvider = this.provider;
1765
- } else {
1766
- formatProvider = new import_ethers2.ethers.providers.Web3Provider(this.provider);
1767
- }
1768
- const erc20Contract = new import_ethers2.ethers.Contract(tokenAddress, erc20Abi_default, formatProvider);
1769
- decimals = await erc20Contract.decimals();
1770
- symbol = await erc20Contract.symbol();
1771
- } else if (tokenType === 1) {
1772
- symbol = NATIVETOKENS[this.chainId];
1773
- } else if (tokenType === 2) {
1774
- decimals = 0;
1775
- tokenId = parseInt(nftIds[0]);
1776
- const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenAddress);
1777
- nftInfo = await erc721ContractInstance.fetchMetaData(tokenAddress, tokenId);
1778
- }
1779
- let fundToken = {
1780
- tokenType,
1781
- // tokenAmount: formatUnits(amount, decimals),
1782
- decimals,
1783
- symbol,
1784
- chainName: CHAINNAMES[this.chainId],
1785
- chainId: this.chainId
1786
- };
1787
- if (tokenType === 0) {
1788
- fundToken.tokenAddress = tokenAddress;
1789
- }
1790
- if (tokenType === 2) {
1791
- Object.assign(fundToken, nftInfo ?? {});
1792
- }
1793
- formatRecords.push({
1794
- funder: tipper,
1795
- fundToken,
1796
- amount: formatUnits(amount, decimals),
1797
- timestamp: timestamp.toNumber()
1798
- });
1799
- }
1800
- console.log("formatRecords", formatRecords);
1801
- return resolve(formatRecords);
2667
+ const formatAttestParams = {
2668
+ attRequest: {
2669
+ ...JSON.parse(signParams)
2670
+ },
2671
+ appSignature: signature
2672
+ };
2673
+ const attestation = await this.zkTlsSdk.startAttestation(
2674
+ JSON.stringify(formatAttestParams)
2675
+ );
2676
+ return resolve(attestation);
1802
2677
  } catch (error) {
1803
2678
  return reject(error);
1804
2679
  }
@@ -1810,15 +2685,41 @@ var Fund = class {
1810
2685
  var PrimusFund = class {
1811
2686
  supportedChainIds = SUPPORTEDCHAINIDS;
1812
2687
  supportedSocialPlatforms = SUPPORTEDSOCIALPLATFORMS;
2688
+ provider;
1813
2689
  _fund;
2690
+ _fundForRedPacket;
2691
+ _zkTlsSdk;
1814
2692
  async init(provider, chainId, appId) {
1815
2693
  return new Promise(async (resolve, reject) => {
1816
2694
  try {
1817
2695
  if (!this.supportedChainIds.includes(chainId)) {
1818
2696
  return reject("chainId is not supported");
1819
2697
  }
2698
+ let formatProvider;
2699
+ let signer;
2700
+ if (provider instanceof import_ethers5.ethers.providers.JsonRpcProvider) {
2701
+ formatProvider = provider;
2702
+ } else {
2703
+ formatProvider = new import_ethers5.ethers.providers.Web3Provider(provider);
2704
+ signer = formatProvider.getSigner();
2705
+ }
2706
+ await formatProvider.ready;
2707
+ const network = await formatProvider.getNetwork();
2708
+ const providerChainId = network.chainId;
2709
+ console.log("init provider", provider, network);
2710
+ console.log("init providerChainId", providerChainId, chainId);
2711
+ if (providerChainId !== chainId) {
2712
+ return reject(`Please connect to the chain with ID ${chainId} first.`);
2713
+ }
2714
+ this.provider = signer ?? formatProvider;
1820
2715
  this._fund = new Fund();
1821
- const result = await this._fund.init(provider, chainId, appId);
2716
+ const result = await this._fund.init(this.provider, chainId);
2717
+ this._fundForRedPacket = new FundForRedPacket();
2718
+ await this._fundForRedPacket.init(this.provider, chainId);
2719
+ if (appId) {
2720
+ this._zkTlsSdk = new ZktlsSdk();
2721
+ await this._zkTlsSdk.init(appId);
2722
+ }
1822
2723
  return resolve(result);
1823
2724
  } catch (error) {
1824
2725
  return reject(error);
@@ -1837,7 +2738,7 @@ var PrimusFund = class {
1837
2738
  return reject("socialPlatform is not supported");
1838
2739
  }
1839
2740
  if (tokenInfo.tokenType === 1) {
1840
- tokenInfo.tokenAddress = import_ethers3.ethers.constants.AddressZero;
2741
+ tokenInfo.tokenAddress = import_ethers5.ethers.constants.AddressZero;
1841
2742
  }
1842
2743
  const newFundRecipientInfos = recipientInfos.map((i) => {
1843
2744
  const formatSocialPlatform = i.socialPlatform.toLowerCase();
@@ -1876,7 +2777,7 @@ var PrimusFund = class {
1876
2777
  return reject("socialPlatform is not supported");
1877
2778
  }
1878
2779
  if (tokenInfo.tokenType === 1) {
1879
- tokenInfo.tokenAddress = import_ethers3.ethers.constants.AddressZero;
2780
+ tokenInfo.tokenAddress = import_ethers5.ethers.constants.AddressZero;
1880
2781
  }
1881
2782
  const newFundRecipientInfos = recipientInfos.map((i) => {
1882
2783
  const formatSocialPlatform = i.socialPlatform.toLowerCase();
@@ -1910,7 +2811,7 @@ var PrimusFund = class {
1910
2811
  return reject("socialPlatform is not supported");
1911
2812
  }
1912
2813
  if (tokenInfo.tokenType === 1) {
1913
- tokenInfo.tokenAddress = import_ethers3.ethers.constants.AddressZero;
2814
+ tokenInfo.tokenAddress = import_ethers5.ethers.constants.AddressZero;
1914
2815
  }
1915
2816
  const newFundRecipientInfos = recipientInfos.map((i) => {
1916
2817
  const formatSocialPlatform = i.socialPlatform.toLowerCase();
@@ -1952,15 +2853,15 @@ var PrimusFund = class {
1952
2853
  }
1953
2854
  });
1954
2855
  }
1955
- async attest(attestParams, genAppSignature, backUrl) {
2856
+ async attest(attestParams, signFn, backUrl) {
1956
2857
  return new Promise(async (resolve, reject) => {
1957
2858
  try {
1958
2859
  const { socialPlatform } = attestParams;
1959
2860
  const lcSocialPlatform = socialPlatform.toLowerCase();
1960
- const attestation = await this._fund?.attest({
2861
+ const attestation = await this._zkTlsSdk?.attest({
1961
2862
  ...attestParams,
1962
2863
  socialPlatform: lcSocialPlatform
1963
- }, genAppSignature, backUrl);
2864
+ }, signFn, backUrl);
1964
2865
  return resolve(attestation);
1965
2866
  } catch (error) {
1966
2867
  return reject(error);
@@ -2028,6 +2929,79 @@ var PrimusFund = class {
2028
2929
  }
2029
2930
  });
2030
2931
  }
2932
+ async fundForRedPacket(fundParam) {
2933
+ return new Promise(async (resolve, reject) => {
2934
+ try {
2935
+ const { tokenInfo, sendParam } = fundParam;
2936
+ const result = await this._fundForRedPacket?.fundForRedPacket(tokenInfo, sendParam);
2937
+ return resolve(result);
2938
+ } catch (error) {
2939
+ return reject(error);
2940
+ }
2941
+ });
2942
+ }
2943
+ async onlyFundForRedPacket(fundParam) {
2944
+ return new Promise(async (resolve, reject) => {
2945
+ try {
2946
+ const { tokenInfo, sendParam } = fundParam;
2947
+ const result = await this._fundForRedPacket?.onlyFundForRedPacket(tokenInfo, sendParam);
2948
+ return resolve(result);
2949
+ } catch (error) {
2950
+ return reject(error);
2951
+ }
2952
+ });
2953
+ }
2954
+ async withdrawForRedPacket(redPacketId) {
2955
+ return new Promise(async (resolve, reject) => {
2956
+ try {
2957
+ const result = await this._fundForRedPacket?.withdrawForRedPacket(redPacketId);
2958
+ return resolve(result);
2959
+ } catch (error) {
2960
+ return reject(error);
2961
+ }
2962
+ });
2963
+ }
2964
+ async getRedPacketInfo(redPacketId) {
2965
+ return new Promise(async (resolve, reject) => {
2966
+ try {
2967
+ const result = await this._fundForRedPacket?.getRedPacketInfo(redPacketId);
2968
+ return resolve(result);
2969
+ } catch (error) {
2970
+ return reject(error);
2971
+ }
2972
+ });
2973
+ }
2974
+ async approveForRedPacket(fundParam) {
2975
+ return new Promise(async (resolve, reject) => {
2976
+ try {
2977
+ const { tokenInfo, sendParam: { amount } } = fundParam;
2978
+ const result = await this._fundForRedPacket?.approveForRedPacket(tokenInfo, amount);
2979
+ return resolve(result);
2980
+ } catch (error) {
2981
+ return reject(error);
2982
+ }
2983
+ });
2984
+ }
2985
+ async claimForRedPacket(redPacketId, attestation) {
2986
+ return new Promise(async (resolve, reject) => {
2987
+ try {
2988
+ const result = await this._fundForRedPacket?.claimForRedPacket(redPacketId, attestation);
2989
+ return resolve(result);
2990
+ } catch (error) {
2991
+ return reject(error);
2992
+ }
2993
+ });
2994
+ }
2995
+ async attestCommon(attestParams) {
2996
+ return new Promise(async (resolve, reject) => {
2997
+ try {
2998
+ const attestation = await this._zkTlsSdk?.attestCommon(attestParams);
2999
+ return resolve(attestation);
3000
+ } catch (error) {
3001
+ return reject(error);
3002
+ }
3003
+ });
3004
+ }
2031
3005
  };
2032
3006
  // Annotate the CommonJS export names for ESM import in node:
2033
3007
  0 && (module.exports = {