@primuslabs/fund-js-sdk 0.1.12 → 0.1.13

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