@primuslabs/fund-js-sdk 0.1.11 → 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,30 @@ var SUPPORTEDCHAINIDSMAP = {
65
67
  name: "PHRS",
66
68
  symbol: "PHRS"
67
69
  },
68
- contractAddress: "0xD17512B7EC12880Bd94Eca9d774089fF89805F02"
70
+ contractAddress: "0xD17512B7EC12880Bd94Eca9d774089fF89805F02",
71
+ redPacketContractAddress: "0x673D74d95A35B26804475066d9cD1DA3947f4eC3"
72
+ },
73
+ 84532: {
74
+ chainId: 84532,
75
+ chainName: "Base Sepolia",
76
+ nativeCurrency: {
77
+ decimals: 18,
78
+ name: "Sepolia Ether",
79
+ symbol: "ETH"
80
+ },
81
+ contractAddress: "0x4E78940F0019EbAEDc6F4995D7B8ABf060F7a341",
82
+ redPacketContractAddress: "0xA33Ed35460C3d06094693956B2d7Cd1a9e7A39a8"
83
+ },
84
+ 8453: {
85
+ chainId: 8453,
86
+ chainName: "Base",
87
+ nativeCurrency: {
88
+ decimals: 18,
89
+ name: "Ether",
90
+ symbol: "ETH"
91
+ },
92
+ contractAddress: "0xa2e0700a269Be3158c81E4739518b324d4398588",
93
+ redPacketContractAddress: "0x50bd377EB8D4236Bb587AB3FB1eeafd888AEeC58"
69
94
  }
70
95
  };
71
96
  var NATIVETOKENS = Object.values(SUPPORTEDCHAINIDSMAP).reduce((prev, curr) => {
@@ -87,6 +112,17 @@ var Fund_CONTRACTS = Object.values(SUPPORTEDCHAINIDSMAP).reduce((prev, curr) =>
87
112
  };
88
113
  }, {});
89
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));
90
126
 
91
127
  // src/classes/Contract.ts
92
128
  import { ethers } from "ethers";
@@ -114,14 +150,7 @@ var Contract = class {
114
150
  }
115
151
  this.address = address;
116
152
  this.provider = provider;
117
- let formatProvider;
118
- if (provider instanceof ethers.providers.JsonRpcProvider) {
119
- formatProvider = provider;
120
- } else {
121
- const web3Provider = new ethers.providers.Web3Provider(provider);
122
- formatProvider = web3Provider.getSigner();
123
- }
124
- this.contractInstance = new ethers.Contract(this.address, abiJson, formatProvider);
153
+ this.contractInstance = new ethers.Contract(this.address, abiJson, this.provider);
125
154
  }
126
155
  // Example method to read from the contract
127
156
  async callMethod(functionName, functionParams) {
@@ -164,11 +193,21 @@ var Contract = class {
164
193
  if (isNoPendingWithdrawals) {
165
194
  return reject("no pending withdrawals");
166
195
  }
167
- const insufficientBalanceErrStrArr = ["insufficient balance", "unpredictable_gas_limit", "INSUFFICIENT_FUNDS"];
196
+ const insufficientBalanceErrStrArr = ["insufficient balance", "INSUFFICIENT_FUNDS"];
168
197
  const isInsufficientBalance = hasErrorFlagFn(curErrorStrArr, insufficientBalanceErrStrArr);
169
198
  if (isInsufficientBalance) {
170
199
  return reject("insufficient balance");
171
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
+ }
172
211
  return reject(error);
173
212
  }
174
213
  });
@@ -176,1432 +215,2370 @@ var Contract = class {
176
215
  };
177
216
  var Contract_default = Contract;
178
217
 
179
- // src/config/abi.json
180
- 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 = [
181
223
  {
182
224
  type: "function",
183
- name: "addBatchIdSource",
225
+ name: "allowance",
184
226
  inputs: [
185
- { name: "sourceName_", type: "string[]", internalType: "string[]" },
186
- { name: "url_", type: "string[]", internalType: "string[]" },
187
- { 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
+ }
188
237
  ],
189
- outputs: [],
190
- stateMutability: "nonpayable"
238
+ outputs: [
239
+ {
240
+ name: "",
241
+ type: "uint256",
242
+ internalType: "uint256"
243
+ }
244
+ ],
245
+ stateMutability: "view"
191
246
  },
192
247
  {
193
248
  type: "function",
194
- name: "claimByMultiSource",
249
+ name: "approve",
195
250
  inputs: [
196
- { name: "idSources", type: "string[]", internalType: "string[]" },
197
251
  {
198
- name: "att",
199
- type: "tuple[]",
200
- internalType: "struct Attestation[]",
201
- components: [
202
- { name: "recipient", type: "address", internalType: "address" },
203
- {
204
- name: "request",
205
- type: "tuple",
206
- internalType: "struct AttNetworkRequest",
207
- components: [
208
- { name: "url", type: "string", internalType: "string" },
209
- { name: "header", type: "string", internalType: "string" },
210
- { name: "method", type: "string", internalType: "string" },
211
- { name: "body", type: "string", internalType: "string" }
212
- ]
213
- },
214
- {
215
- name: "reponseResolve",
216
- type: "tuple[]",
217
- internalType: "struct AttNetworkResponseResolve[]",
218
- components: [
219
- { name: "keyName", type: "string", internalType: "string" },
220
- {
221
- name: "parseType",
222
- type: "string",
223
- internalType: "string"
224
- },
225
- {
226
- name: "parsePath",
227
- type: "string",
228
- internalType: "string"
229
- }
230
- ]
231
- },
232
- { name: "data", type: "string", internalType: "string" },
233
- {
234
- name: "attConditions",
235
- type: "string",
236
- internalType: "string"
237
- },
238
- { name: "timestamp", type: "uint64", internalType: "uint64" },
239
- {
240
- name: "additionParams",
241
- type: "string",
242
- internalType: "string"
243
- },
244
- {
245
- name: "attestors",
246
- type: "tuple[]",
247
- internalType: "struct Attestor[]",
248
- components: [
249
- {
250
- name: "attestorAddr",
251
- type: "address",
252
- internalType: "address"
253
- },
254
- { name: "url", type: "string", internalType: "string" }
255
- ]
256
- },
257
- { name: "signatures", type: "bytes[]", internalType: "bytes[]" }
258
- ]
252
+ name: "spender",
253
+ type: "address",
254
+ internalType: "address"
255
+ },
256
+ {
257
+ name: "value",
258
+ type: "uint256",
259
+ internalType: "uint256"
259
260
  }
260
261
  ],
261
- outputs: [],
262
- stateMutability: "payable"
262
+ outputs: [
263
+ {
264
+ name: "",
265
+ type: "bool",
266
+ internalType: "bool"
267
+ }
268
+ ],
269
+ stateMutability: "nonpayable"
263
270
  },
264
271
  {
265
272
  type: "function",
266
- name: "claimBySource",
273
+ name: "balanceOf",
267
274
  inputs: [
268
- { name: "idSource", type: "string", internalType: "string" },
269
275
  {
270
- name: "att",
271
- type: "tuple",
272
- internalType: "struct Attestation",
273
- components: [
274
- { name: "recipient", type: "address", internalType: "address" },
275
- {
276
- name: "request",
277
- type: "tuple",
278
- internalType: "struct AttNetworkRequest",
279
- components: [
280
- { name: "url", type: "string", internalType: "string" },
281
- { name: "header", type: "string", internalType: "string" },
282
- { name: "method", type: "string", internalType: "string" },
283
- { name: "body", type: "string", internalType: "string" }
284
- ]
285
- },
286
- {
287
- name: "reponseResolve",
288
- type: "tuple[]",
289
- internalType: "struct AttNetworkResponseResolve[]",
290
- components: [
291
- { name: "keyName", type: "string", internalType: "string" },
292
- {
293
- name: "parseType",
294
- type: "string",
295
- internalType: "string"
296
- },
297
- {
298
- name: "parsePath",
299
- type: "string",
300
- internalType: "string"
301
- }
302
- ]
303
- },
304
- { name: "data", type: "string", internalType: "string" },
305
- {
306
- name: "attConditions",
307
- type: "string",
308
- internalType: "string"
309
- },
310
- { name: "timestamp", type: "uint64", internalType: "uint64" },
311
- {
312
- name: "additionParams",
313
- type: "string",
314
- internalType: "string"
315
- },
316
- {
317
- name: "attestors",
318
- type: "tuple[]",
319
- internalType: "struct Attestor[]",
320
- components: [
321
- {
322
- name: "attestorAddr",
323
- type: "address",
324
- internalType: "address"
325
- },
326
- { name: "url", type: "string", internalType: "string" }
327
- ]
328
- },
329
- { name: "signatures", type: "bytes[]", internalType: "bytes[]" }
330
- ]
276
+ name: "account",
277
+ type: "address",
278
+ internalType: "address"
331
279
  }
332
280
  ],
333
- outputs: [],
334
- stateMutability: "payable"
281
+ outputs: [
282
+ {
283
+ name: "",
284
+ type: "uint256",
285
+ internalType: "uint256"
286
+ }
287
+ ],
288
+ stateMutability: "view"
335
289
  },
336
290
  {
337
291
  type: "function",
338
- name: "claimBySourceAndTipIndex",
339
- inputs: [
340
- { name: "idSource", type: "string", internalType: "string" },
292
+ name: "decimals",
293
+ inputs: [],
294
+ outputs: [
341
295
  {
342
- name: "att",
343
- type: "tuple",
344
- internalType: "struct Attestation",
345
- components: [
346
- { name: "recipient", type: "address", internalType: "address" },
347
- {
348
- name: "request",
349
- type: "tuple",
350
- internalType: "struct AttNetworkRequest",
351
- components: [
352
- { name: "url", type: "string", internalType: "string" },
353
- { name: "header", type: "string", internalType: "string" },
354
- { name: "method", type: "string", internalType: "string" },
355
- { name: "body", type: "string", internalType: "string" }
356
- ]
357
- },
358
- {
359
- name: "reponseResolve",
360
- type: "tuple[]",
361
- internalType: "struct AttNetworkResponseResolve[]",
362
- components: [
363
- { name: "keyName", type: "string", internalType: "string" },
364
- {
365
- name: "parseType",
366
- type: "string",
367
- internalType: "string"
368
- },
369
- {
370
- name: "parsePath",
371
- type: "string",
372
- internalType: "string"
373
- }
374
- ]
375
- },
376
- { name: "data", type: "string", internalType: "string" },
377
- {
378
- name: "attConditions",
379
- type: "string",
380
- internalType: "string"
381
- },
382
- { name: "timestamp", type: "uint64", internalType: "uint64" },
383
- {
384
- name: "additionParams",
385
- type: "string",
386
- internalType: "string"
387
- },
388
- {
389
- name: "attestors",
390
- type: "tuple[]",
391
- internalType: "struct Attestor[]",
392
- components: [
393
- {
394
- name: "attestorAddr",
395
- type: "address",
396
- internalType: "address"
397
- },
398
- { name: "url", type: "string", internalType: "string" }
399
- ]
400
- },
401
- { name: "signatures", type: "bytes[]", internalType: "bytes[]" }
402
- ]
403
- },
404
- { name: "index", type: "uint32", internalType: "uint32" }
296
+ name: "",
297
+ type: "uint8",
298
+ internalType: "uint8"
299
+ }
405
300
  ],
406
- outputs: [],
407
- stateMutability: "payable"
408
- },
409
- {
410
- type: "function",
411
- name: "claimFee",
412
- inputs: [],
413
- outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
414
301
  stateMutability: "view"
415
302
  },
416
303
  {
417
304
  type: "function",
418
- name: "feeRecipient",
305
+ name: "name",
419
306
  inputs: [],
420
- outputs: [{ name: "", type: "address", internalType: "address" }],
307
+ outputs: [
308
+ {
309
+ name: "",
310
+ type: "string",
311
+ internalType: "string"
312
+ }
313
+ ],
421
314
  stateMutability: "view"
422
315
  },
423
316
  {
424
317
  type: "function",
425
- name: "getTipRecords",
426
- inputs: [
427
- {
428
- name: "tipRecipient",
429
- type: "tuple",
430
- internalType: "struct TipRecipient",
431
- components: [
432
- { name: "idSource", type: "string", internalType: "string" },
433
- { name: "id", type: "string", internalType: "string" }
434
- ]
435
- }
436
- ],
318
+ name: "symbol",
319
+ inputs: [],
437
320
  outputs: [
438
321
  {
439
322
  name: "",
440
- type: "tuple[]",
441
- internalType: "struct TipRecord[]",
442
- components: [
443
- { name: "amount", type: "uint256", internalType: "uint256" },
444
- {
445
- name: "tipToken",
446
- type: "tuple",
447
- internalType: "struct TipToken",
448
- components: [
449
- {
450
- name: "tokenType",
451
- type: "uint32",
452
- internalType: "uint32"
453
- },
454
- {
455
- name: "tokenAddress",
456
- type: "address",
457
- internalType: "address"
458
- }
459
- ]
460
- },
461
- { name: "timestamp", type: "uint64", internalType: "uint64" },
462
- { name: "tipper", type: "address", internalType: "address" },
463
- { name: "nftIds", type: "uint256[]", internalType: "uint256[]" }
464
- ]
323
+ type: "string",
324
+ internalType: "string"
465
325
  }
466
326
  ],
467
327
  stateMutability: "view"
468
328
  },
469
329
  {
470
330
  type: "function",
471
- name: "idSourceCache",
472
- inputs: [{ name: "", type: "string", internalType: "string" }],
331
+ name: "totalSupply",
332
+ inputs: [],
473
333
  outputs: [
474
- { name: "url", type: "string", internalType: "string" },
475
- { name: "jsonPath", type: "string", internalType: "string" }
334
+ {
335
+ name: "",
336
+ type: "uint256",
337
+ internalType: "uint256"
338
+ }
476
339
  ],
477
340
  stateMutability: "view"
478
341
  },
479
342
  {
480
343
  type: "function",
481
- name: "initialize",
344
+ name: "transfer",
482
345
  inputs: [
483
- { name: "owner", type: "address", internalType: "address" },
484
346
  {
485
- name: "primusZKTLS_",
347
+ name: "to",
486
348
  type: "address",
487
- internalType: "contract IPrimusZKTLS"
349
+ internalType: "address"
488
350
  },
489
- { name: "feeRecipient_", type: "address", internalType: "address" },
490
- { name: "claimFee_", type: "uint256", internalType: "uint256" }
351
+ {
352
+ name: "value",
353
+ type: "uint256",
354
+ internalType: "uint256"
355
+ }
491
356
  ],
492
- outputs: [],
493
- stateMutability: "nonpayable"
494
- },
495
- {
496
- type: "function",
497
- name: "owner",
498
- inputs: [],
499
- outputs: [{ name: "", type: "address", internalType: "address" }],
500
- stateMutability: "view"
501
- },
502
- {
503
- type: "function",
504
- name: "primusZKTLS",
505
- inputs: [],
506
357
  outputs: [
507
- { name: "", type: "address", internalType: "contract IPrimusZKTLS" }
358
+ {
359
+ name: "",
360
+ type: "bool",
361
+ internalType: "bool"
362
+ }
508
363
  ],
509
- stateMutability: "view"
510
- },
511
- {
512
- type: "function",
513
- name: "renounceOwnership",
514
- inputs: [],
515
- outputs: [],
516
364
  stateMutability: "nonpayable"
517
365
  },
518
366
  {
519
367
  type: "function",
520
- name: "setClaimFee",
368
+ name: "transferFrom",
521
369
  inputs: [
522
- { 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
+ }
523
385
  ],
524
- outputs: [],
525
- stateMutability: "nonpayable"
526
- },
527
- {
528
- type: "function",
529
- name: "setFeeRecipient",
530
- inputs: [
531
- { name: "feeRecipient_", type: "address", internalType: "address" }
386
+ outputs: [
387
+ {
388
+ name: "",
389
+ type: "bool",
390
+ internalType: "bool"
391
+ }
532
392
  ],
533
- outputs: [],
534
393
  stateMutability: "nonpayable"
535
394
  },
536
395
  {
537
- type: "function",
538
- name: "setPrimusZKTLS",
396
+ type: "event",
397
+ name: "Approval",
539
398
  inputs: [
540
399
  {
541
- name: "primusZKTLS_",
400
+ name: "owner",
542
401
  type: "address",
543
- 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"
544
416
  }
545
417
  ],
546
- outputs: [],
547
- stateMutability: "nonpayable"
548
- },
549
- {
550
- type: "function",
551
- name: "setWithdrawDelay",
552
- inputs: [
553
- { name: "delay", type: "uint256", internalType: "uint256" }
554
- ],
555
- outputs: [],
556
- stateMutability: "nonpayable"
418
+ anonymous: false
557
419
  },
558
420
  {
559
- type: "function",
560
- name: "tip",
421
+ type: "event",
422
+ name: "Transfer",
561
423
  inputs: [
562
424
  {
563
- name: "token",
564
- type: "tuple",
565
- internalType: "struct TipToken",
566
- components: [
567
- { name: "tokenType", type: "uint32", internalType: "uint32" },
568
- {
569
- name: "tokenAddress",
570
- type: "address",
571
- internalType: "address"
572
- }
573
- ]
425
+ name: "from",
426
+ type: "address",
427
+ indexed: true,
428
+ internalType: "address"
574
429
  },
575
430
  {
576
- name: "recipient",
577
- type: "tuple",
578
- internalType: "struct TipRecipientInfo",
579
- components: [
580
- { name: "idSource", type: "string", internalType: "string" },
581
- { name: "id", type: "string", internalType: "string" },
582
- { name: "amount", type: "uint256", internalType: "uint256" },
583
- { name: "nftIds", type: "uint256[]", internalType: "uint256[]" }
584
- ]
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"
585
441
  }
586
442
  ],
587
- outputs: [],
588
- stateMutability: "payable"
443
+ anonymous: false
589
444
  },
590
445
  {
591
- type: "function",
592
- name: "tipBatch",
446
+ type: "error",
447
+ name: "ERC20InsufficientAllowance",
593
448
  inputs: [
594
449
  {
595
- name: "token",
596
- type: "tuple",
597
- internalType: "struct TipToken",
598
- components: [
599
- { name: "tokenType", type: "uint32", internalType: "uint32" },
600
- {
601
- name: "tokenAddress",
602
- type: "address",
603
- internalType: "address"
604
- }
605
- ]
450
+ name: "spender",
451
+ type: "address",
452
+ internalType: "address"
606
453
  },
607
454
  {
608
- name: "recipients",
609
- type: "tuple[]",
610
- internalType: "struct TipRecipientInfo[]",
611
- components: [
612
- { name: "idSource", type: "string", internalType: "string" },
613
- { name: "id", type: "string", internalType: "string" },
614
- { name: "amount", type: "uint256", internalType: "uint256" },
615
- { name: "nftIds", type: "uint256[]", internalType: "uint256[]" }
616
- ]
617
- }
618
- ],
619
- outputs: [],
620
- stateMutability: "payable"
621
- },
622
- {
623
- type: "function",
624
- name: "tipperWithdraw",
625
- inputs: [
455
+ name: "allowance",
456
+ type: "uint256",
457
+ internalType: "uint256"
458
+ },
626
459
  {
627
- name: "tipRecipients",
628
- type: "tuple[]",
629
- internalType: "struct TipWithdrawInfo[]",
630
- components: [
631
- { name: "idSource", type: "string", internalType: "string" },
632
- { name: "id", type: "string", internalType: "string" },
633
- { name: "tipTimestamp", type: "uint64", internalType: "uint64" }
634
- ]
460
+ name: "needed",
461
+ type: "uint256",
462
+ internalType: "uint256"
635
463
  }
636
- ],
637
- outputs: [],
638
- stateMutability: "nonpayable"
639
- },
640
- {
641
- type: "function",
642
- name: "transferOwnership",
643
- inputs: [
644
- { name: "newOwner", type: "address", internalType: "address" }
645
- ],
646
- outputs: [],
647
- stateMutability: "nonpayable"
648
- },
649
- {
650
- type: "function",
651
- name: "withdrawDelay",
652
- inputs: [],
653
- outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
654
- stateMutability: "view"
464
+ ]
655
465
  },
656
466
  {
657
- type: "event",
658
- name: "ClaimEvent",
467
+ type: "error",
468
+ name: "ERC20InsufficientBalance",
659
469
  inputs: [
660
470
  {
661
- name: "recipient",
662
- type: "address",
663
- indexed: true,
664
- internalType: "address"
665
- },
666
- {
667
- name: "claimTime",
668
- type: "uint64",
669
- indexed: false,
670
- internalType: "uint64"
671
- },
672
- {
673
- name: "idSource",
674
- type: "string",
675
- indexed: false,
676
- internalType: "string"
677
- },
678
- {
679
- name: "id",
680
- type: "string",
681
- indexed: false,
682
- internalType: "string"
683
- },
684
- {
685
- name: "tipper",
686
- type: "address",
687
- indexed: false,
688
- internalType: "address"
689
- },
690
- {
691
- name: "tokenAddr",
471
+ name: "sender",
692
472
  type: "address",
693
- indexed: false,
694
473
  internalType: "address"
695
474
  },
696
475
  {
697
- name: "amount",
476
+ name: "balance",
698
477
  type: "uint256",
699
- indexed: false,
700
478
  internalType: "uint256"
701
479
  },
702
480
  {
703
- name: "tipTime",
704
- type: "uint64",
705
- indexed: false,
706
- internalType: "uint64"
707
- }
708
- ],
709
- anonymous: false
710
- },
711
- {
712
- type: "event",
713
- name: "Initialized",
714
- inputs: [
715
- {
716
- name: "version",
717
- type: "uint64",
718
- indexed: false,
719
- internalType: "uint64"
481
+ name: "needed",
482
+ type: "uint256",
483
+ internalType: "uint256"
720
484
  }
721
- ],
722
- anonymous: false
485
+ ]
723
486
  },
724
487
  {
725
- type: "event",
726
- name: "OwnershipTransferred",
488
+ type: "error",
489
+ name: "ERC20InvalidApprover",
727
490
  inputs: [
728
491
  {
729
- name: "previousOwner",
730
- type: "address",
731
- indexed: true,
732
- internalType: "address"
733
- },
734
- {
735
- name: "newOwner",
492
+ name: "approver",
736
493
  type: "address",
737
- indexed: true,
738
494
  internalType: "address"
739
495
  }
740
- ],
741
- anonymous: false
496
+ ]
742
497
  },
743
498
  {
744
- type: "event",
745
- name: "TipEvent",
499
+ type: "error",
500
+ name: "ERC20InvalidReceiver",
746
501
  inputs: [
747
502
  {
748
- name: "idSource",
749
- type: "string",
750
- indexed: false,
751
- internalType: "string"
752
- },
753
- {
754
- name: "id",
755
- type: "string",
756
- indexed: false,
757
- internalType: "string"
758
- },
759
- {
760
- name: "tipper",
761
- type: "address",
762
- indexed: false,
763
- internalType: "address"
764
- },
765
- {
766
- name: "tokenAddr",
503
+ name: "receiver",
767
504
  type: "address",
768
- indexed: false,
769
505
  internalType: "address"
770
- },
771
- {
772
- name: "amount",
773
- type: "uint256",
774
- indexed: false,
775
- internalType: "uint256"
776
- },
777
- {
778
- name: "tipTime",
779
- type: "uint64",
780
- indexed: false,
781
- internalType: "uint64"
782
506
  }
783
- ],
784
- anonymous: false
507
+ ]
785
508
  },
786
509
  {
787
- type: "event",
788
- name: "WithdrawEvent",
510
+ type: "error",
511
+ name: "ERC20InvalidSender",
789
512
  inputs: [
790
513
  {
791
- name: "withdrawTime",
792
- type: "uint64",
793
- indexed: false,
794
- internalType: "uint64"
795
- },
796
- {
797
- name: "idSource",
798
- type: "string",
799
- indexed: false,
800
- internalType: "string"
801
- },
802
- {
803
- name: "id",
804
- type: "string",
805
- indexed: false,
806
- internalType: "string"
807
- },
808
- {
809
- name: "tipper",
810
- type: "address",
811
- indexed: false,
812
- internalType: "address"
813
- },
814
- {
815
- name: "tokenAddr",
514
+ name: "sender",
816
515
  type: "address",
817
- indexed: false,
818
516
  internalType: "address"
819
- },
820
- {
821
- name: "amount",
822
- type: "uint256",
823
- indexed: false,
824
- internalType: "uint256"
825
- },
826
- {
827
- name: "tipTime",
828
- type: "uint64",
829
- indexed: false,
830
- internalType: "uint64"
831
517
  }
832
- ],
833
- anonymous: false
834
- },
835
- { type: "error", name: "InvalidInitialization", inputs: [] },
836
- { type: "error", name: "NotInitializing", inputs: [] },
837
- {
838
- type: "error",
839
- name: "OwnableInvalidOwner",
840
- inputs: [
841
- { name: "owner", type: "address", internalType: "address" }
842
518
  ]
843
519
  },
844
520
  {
845
521
  type: "error",
846
- name: "OwnableUnauthorizedAccount",
847
- inputs: [
848
- { name: "account", type: "address", internalType: "address" }
849
- ]
850
- },
851
- { type: "error", name: "ReentrancyGuardReentrantCall", inputs: [] }
852
- ];
853
-
854
- // src/config/erc20Abi.json
855
- var erc20Abi_default = [
856
- {
857
- type: "function",
858
- name: "allowance",
522
+ name: "ERC20InvalidSpender",
859
523
  inputs: [
860
- {
861
- name: "owner",
862
- type: "address",
863
- internalType: "address"
864
- },
865
524
  {
866
525
  name: "spender",
867
526
  type: "address",
868
527
  internalType: "address"
869
528
  }
870
- ],
871
- outputs: [
872
- {
873
- name: "",
874
- type: "uint256",
529
+ ]
530
+ }
531
+ ];
532
+
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,
875
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
+ ]
876
1874
  }
877
1875
  ],
878
1876
  stateMutability: "view"
879
1877
  },
880
1878
  {
881
1879
  type: "function",
882
- name: "approve",
1880
+ name: "idCounter",
1881
+ inputs: [],
1882
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
1883
+ stateMutability: "view"
1884
+ },
1885
+ {
1886
+ type: "function",
1887
+ name: "initialize",
883
1888
  inputs: [
1889
+ { name: "owner", type: "address", internalType: "address" },
884
1890
  {
885
- name: "spender",
1891
+ name: "primusZKTLS_",
886
1892
  type: "address",
887
- internalType: "address"
1893
+ internalType: "contract IPrimusZKTLS"
888
1894
  },
889
- {
890
- name: "value",
891
- type: "uint256",
892
- internalType: "uint256"
893
- }
1895
+ { name: "feeRecipient_", type: "address", internalType: "address" },
1896
+ { name: "claimFee_", type: "uint256", internalType: "uint256" }
894
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: [],
895
1912
  outputs: [
896
- {
897
- name: "",
898
- type: "bool",
899
- internalType: "bool"
900
- }
1913
+ { name: "", type: "address", internalType: "contract IPrimusZKTLS" }
901
1914
  ],
902
- stateMutability: "nonpayable"
1915
+ stateMutability: "view"
903
1916
  },
904
1917
  {
905
1918
  type: "function",
906
- name: "balanceOf",
1919
+ name: "reCheckClaim",
907
1920
  inputs: [
908
1921
  {
909
- name: "account",
910
- type: "address",
911
- internalType: "address"
912
- }
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
+ ]
1983
+ },
1984
+ { name: "checkParams", type: "bytes", internalType: "bytes" }
913
1985
  ],
914
1986
  outputs: [
915
- {
916
- name: "",
917
- type: "uint256",
918
- internalType: "uint256"
919
- }
1987
+ { name: "", type: "string", internalType: "string" },
1988
+ { name: "", type: "address", internalType: "address" }
920
1989
  ],
921
1990
  stateMutability: "view"
922
1991
  },
923
1992
  {
924
1993
  type: "function",
925
- name: "decimals",
926
- inputs: [],
927
- outputs: [
1994
+ name: "reClaim",
1995
+ inputs: [
1996
+ { name: "reId", type: "bytes32", internalType: "bytes32" },
928
1997
  {
929
- name: "",
930
- type: "uint8",
931
- internalType: "uint8"
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
  ],
934
- stateMutability: "view"
2061
+ outputs: [],
2062
+ stateMutability: "payable"
935
2063
  },
936
2064
  {
937
2065
  type: "function",
938
- name: "name",
939
- inputs: [],
2066
+ name: "reRecords",
2067
+ inputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
940
2068
  outputs: [
941
- {
942
- name: "",
943
- type: "string",
944
- internalType: "string"
945
- }
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",
2081
+ type: "uint256",
2082
+ internalType: "uint256"
2083
+ },
2084
+ { name: "checkParams", type: "bytes", internalType: "bytes" }
946
2085
  ],
947
2086
  stateMutability: "view"
948
2087
  },
949
2088
  {
950
2089
  type: "function",
951
- name: "symbol",
952
- inputs: [],
953
- outputs: [
2090
+ name: "reSend",
2091
+ inputs: [
954
2092
  {
955
- name: "",
956
- type: "string",
957
- internalType: "string"
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
+ ]
958
2120
  }
959
2121
  ],
960
- stateMutability: "view"
2122
+ outputs: [],
2123
+ stateMutability: "payable"
961
2124
  },
962
2125
  {
963
2126
  type: "function",
964
- name: "totalSupply",
2127
+ name: "reSenderWithdraw",
2128
+ inputs: [
2129
+ { name: "reId", type: "bytes32", internalType: "bytes32" }
2130
+ ],
2131
+ outputs: [],
2132
+ stateMutability: "nonpayable"
2133
+ },
2134
+ {
2135
+ type: "function",
2136
+ name: "renounceOwnership",
965
2137
  inputs: [],
966
- outputs: [
967
- {
968
- name: "",
969
- type: "uint256",
970
- internalType: "uint256"
971
- }
2138
+ outputs: [],
2139
+ stateMutability: "nonpayable"
2140
+ },
2141
+ {
2142
+ type: "function",
2143
+ name: "setClaimFee",
2144
+ inputs: [
2145
+ { name: "claimFee_", type: "uint256", internalType: "uint256" }
2146
+ ],
2147
+ outputs: [],
2148
+ stateMutability: "nonpayable"
2149
+ },
2150
+ {
2151
+ type: "function",
2152
+ name: "setFeeRecipient",
2153
+ inputs: [
2154
+ { name: "feeRecipient_", type: "address", internalType: "address" }
972
2155
  ],
973
- stateMutability: "view"
2156
+ outputs: [],
2157
+ stateMutability: "nonpayable"
974
2158
  },
975
2159
  {
976
2160
  type: "function",
977
- name: "transfer",
2161
+ name: "setPrimusZKTLS",
978
2162
  inputs: [
979
2163
  {
980
- name: "to",
2164
+ name: "primusZKTLS_",
981
2165
  type: "address",
982
- internalType: "address"
983
- },
984
- {
985
- name: "value",
986
- type: "uint256",
987
- internalType: "uint256"
988
- }
989
- ],
990
- outputs: [
991
- {
992
- name: "",
993
- type: "bool",
994
- internalType: "bool"
2166
+ internalType: "contract IPrimusZKTLS"
995
2167
  }
996
2168
  ],
2169
+ outputs: [],
997
2170
  stateMutability: "nonpayable"
998
2171
  },
999
2172
  {
1000
2173
  type: "function",
1001
- name: "transferFrom",
2174
+ name: "setWithdrawDelay",
1002
2175
  inputs: [
1003
- {
1004
- name: "from",
1005
- type: "address",
1006
- internalType: "address"
1007
- },
1008
- {
1009
- name: "to",
1010
- type: "address",
1011
- internalType: "address"
1012
- },
1013
- {
1014
- name: "value",
1015
- type: "uint256",
1016
- internalType: "uint256"
1017
- }
2176
+ { name: "delay", type: "uint256", internalType: "uint256" }
1018
2177
  ],
1019
- outputs: [
1020
- {
1021
- name: "",
1022
- type: "bool",
1023
- internalType: "bool"
1024
- }
2178
+ outputs: [],
2179
+ stateMutability: "nonpayable"
2180
+ },
2181
+ {
2182
+ type: "function",
2183
+ name: "transferOwnership",
2184
+ inputs: [
2185
+ { name: "newOwner", type: "address", internalType: "address" }
1025
2186
  ],
2187
+ outputs: [],
1026
2188
  stateMutability: "nonpayable"
1027
2189
  },
2190
+ {
2191
+ type: "function",
2192
+ name: "withdrawDelay",
2193
+ inputs: [],
2194
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
2195
+ stateMutability: "view"
2196
+ },
1028
2197
  {
1029
2198
  type: "event",
1030
- name: "Approval",
2199
+ name: "Initialized",
1031
2200
  inputs: [
1032
2201
  {
1033
- name: "owner",
1034
- type: "address",
1035
- indexed: true,
1036
- internalType: "address"
1037
- },
1038
- {
1039
- name: "spender",
1040
- type: "address",
1041
- indexed: true,
1042
- internalType: "address"
1043
- },
1044
- {
1045
- name: "value",
1046
- type: "uint256",
2202
+ name: "version",
2203
+ type: "uint64",
1047
2204
  indexed: false,
1048
- internalType: "uint256"
2205
+ internalType: "uint64"
1049
2206
  }
1050
2207
  ],
1051
2208
  anonymous: false
1052
2209
  },
1053
2210
  {
1054
2211
  type: "event",
1055
- name: "Transfer",
2212
+ name: "OwnershipTransferred",
1056
2213
  inputs: [
1057
2214
  {
1058
- name: "from",
2215
+ name: "previousOwner",
1059
2216
  type: "address",
1060
2217
  indexed: true,
1061
2218
  internalType: "address"
1062
2219
  },
1063
2220
  {
1064
- name: "to",
2221
+ name: "newOwner",
1065
2222
  type: "address",
1066
2223
  indexed: true,
1067
2224
  internalType: "address"
1068
- },
1069
- {
1070
- name: "value",
1071
- type: "uint256",
1072
- indexed: false,
1073
- internalType: "uint256"
1074
2225
  }
1075
2226
  ],
1076
2227
  anonymous: false
1077
2228
  },
1078
2229
  {
1079
- type: "error",
1080
- name: "ERC20InsufficientAllowance",
2230
+ type: "event",
2231
+ name: "REClaimEvent",
1081
2232
  inputs: [
1082
2233
  {
1083
- name: "spender",
1084
- type: "address",
1085
- internalType: "address"
1086
- },
1087
- {
1088
- name: "allowance",
1089
- type: "uint256",
1090
- internalType: "uint256"
2234
+ name: "id",
2235
+ type: "bytes32",
2236
+ indexed: true,
2237
+ internalType: "bytes32"
1091
2238
  },
1092
2239
  {
1093
- name: "needed",
1094
- type: "uint256",
1095
- internalType: "uint256"
1096
- }
1097
- ]
1098
- },
1099
- {
1100
- type: "error",
1101
- name: "ERC20InsufficientBalance",
1102
- inputs: [
1103
- {
1104
- name: "sender",
2240
+ name: "recipient",
1105
2241
  type: "address",
2242
+ indexed: false,
1106
2243
  internalType: "address"
1107
2244
  },
1108
2245
  {
1109
- name: "balance",
1110
- type: "uint256",
1111
- internalType: "uint256"
2246
+ name: "userId",
2247
+ type: "string",
2248
+ indexed: false,
2249
+ internalType: "string"
1112
2250
  },
1113
2251
  {
1114
- name: "needed",
2252
+ name: "claimAmount",
1115
2253
  type: "uint256",
2254
+ indexed: false,
1116
2255
  internalType: "uint256"
1117
- }
1118
- ]
1119
- },
1120
- {
1121
- type: "error",
1122
- name: "ERC20InvalidApprover",
1123
- inputs: [
1124
- {
1125
- name: "approver",
1126
- type: "address",
1127
- internalType: "address"
1128
- }
1129
- ]
1130
- },
1131
- {
1132
- type: "error",
1133
- name: "ERC20InvalidReceiver",
1134
- inputs: [
1135
- {
1136
- name: "receiver",
1137
- type: "address",
1138
- internalType: "address"
1139
- }
1140
- ]
1141
- },
1142
- {
1143
- type: "error",
1144
- name: "ERC20InvalidSender",
1145
- inputs: [
2256
+ },
1146
2257
  {
1147
- name: "sender",
1148
- type: "address",
1149
- internalType: "address"
1150
- }
1151
- ]
1152
- },
1153
- {
1154
- type: "error",
1155
- name: "ERC20InvalidSpender",
1156
- inputs: [
2258
+ name: "reIndex",
2259
+ type: "uint32",
2260
+ indexed: false,
2261
+ internalType: "uint32"
2262
+ },
1157
2263
  {
1158
- name: "spender",
1159
- type: "address",
1160
- internalType: "address"
1161
- }
1162
- ]
1163
- }
1164
- ];
1165
-
1166
- // src/config/erc721Abi.json
1167
- var erc721Abi_default = [
1168
- {
1169
- type: "function",
1170
- name: "supportsInterface",
1171
- stateMutability: "view",
1172
- inputs: [
1173
- { internalType: "bytes4", name: "interfaceId", type: "bytes4" }
1174
- ],
1175
- outputs: [{ internalType: "bool", name: "", type: "bool" }]
1176
- },
1177
- {
1178
- type: "function",
1179
- name: "balanceOf",
1180
- stateMutability: "view",
1181
- inputs: [
1182
- { internalType: "address", name: "owner", type: "address" }
1183
- ],
1184
- outputs: [{ internalType: "uint256", name: "", type: "uint256" }]
1185
- },
1186
- {
1187
- type: "function",
1188
- name: "ownerOf",
1189
- stateMutability: "view",
1190
- inputs: [
1191
- { internalType: "uint256", name: "tokenId", type: "uint256" }
1192
- ],
1193
- outputs: [{ internalType: "address", name: "", type: "address" }]
1194
- },
1195
- {
1196
- type: "function",
1197
- name: "tokenURI",
1198
- stateMutability: "view",
1199
- inputs: [
1200
- { internalType: "uint256", name: "tokenId", type: "uint256" }
1201
- ],
1202
- outputs: [{ internalType: "string", name: "", type: "string" }]
1203
- },
1204
- {
1205
- type: "function",
1206
- name: "approve",
1207
- stateMutability: "nonpayable",
1208
- inputs: [
1209
- { internalType: "address", name: "to", type: "address" },
1210
- { internalType: "uint256", name: "tokenId", type: "uint256" }
1211
- ],
1212
- outputs: []
1213
- },
1214
- {
1215
- type: "function",
1216
- name: "getApproved",
1217
- stateMutability: "view",
1218
- inputs: [
1219
- { internalType: "uint256", name: "tokenId", type: "uint256" }
1220
- ],
1221
- outputs: [{ internalType: "address", name: "", type: "address" }]
1222
- },
1223
- {
1224
- type: "function",
1225
- name: "setApprovalForAll",
1226
- stateMutability: "nonpayable",
1227
- inputs: [
1228
- { internalType: "address", name: "operator", type: "address" },
1229
- { internalType: "bool", name: "approved", type: "bool" }
1230
- ],
1231
- outputs: []
1232
- },
1233
- {
1234
- type: "function",
1235
- name: "isApprovedForAll",
1236
- stateMutability: "view",
1237
- inputs: [
1238
- { internalType: "address", name: "owner", type: "address" },
1239
- { internalType: "address", name: "operator", type: "address" }
2264
+ name: "timestamp",
2265
+ type: "uint64",
2266
+ indexed: false,
2267
+ internalType: "uint64"
2268
+ }
1240
2269
  ],
1241
- outputs: [{ internalType: "bool", name: "", type: "bool" }]
2270
+ anonymous: false
1242
2271
  },
1243
2272
  {
1244
- type: "function",
1245
- name: "transferFrom",
1246
- stateMutability: "nonpayable",
2273
+ type: "event",
2274
+ name: "RESWithdrawEvent",
1247
2275
  inputs: [
1248
- { internalType: "address", name: "from", type: "address" },
1249
- { internalType: "address", name: "to", type: "address" },
1250
- { 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
+ }
1251
2306
  ],
1252
- outputs: []
2307
+ anonymous: false
1253
2308
  },
1254
2309
  {
1255
- type: "function",
1256
- name: "safeTransferFrom",
1257
- stateMutability: "nonpayable",
2310
+ type: "event",
2311
+ name: "RESendEvent",
1258
2312
  inputs: [
1259
- { internalType: "address", name: "from", type: "address" },
1260
- { internalType: "address", name: "to", type: "address" },
1261
- { 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
+ }
1262
2361
  ],
1263
- outputs: []
2362
+ anonymous: false
1264
2363
  },
2364
+ { type: "error", name: "InvalidInitialization", inputs: [] },
2365
+ { type: "error", name: "NotInitializing", inputs: [] },
1265
2366
  {
1266
- type: "function",
1267
- name: "name",
1268
- stateMutability: "view",
1269
- inputs: [],
1270
- outputs: [{ internalType: "string", name: "", type: "string" }]
2367
+ type: "error",
2368
+ name: "OwnableInvalidOwner",
2369
+ inputs: [
2370
+ { name: "owner", type: "address", internalType: "address" }
2371
+ ]
1271
2372
  },
1272
2373
  {
1273
- type: "function",
1274
- name: "symbol",
1275
- stateMutability: "view",
1276
- inputs: [],
1277
- outputs: [{ internalType: "string", name: "", type: "string" }]
2374
+ type: "error",
2375
+ name: "OwnableUnauthorizedAccount",
2376
+ inputs: [
2377
+ { name: "account", type: "address", internalType: "address" }
2378
+ ]
1278
2379
  }
1279
2380
  ];
1280
2381
 
1281
- // src/classes/Erc721Contract.ts
1282
- var Erc721Contract = class {
1283
- contractInstance;
1284
- constructor(provider, address) {
1285
- if (!provider || !address) {
1286
- throw new Error("provider, address are required");
1287
- }
1288
- this.contractInstance = new Contract_default(provider, address, erc721Abi_default);
1289
- }
1290
- async approve(address, tokenId) {
1291
- return new Promise(async (resolve, reject) => {
1292
- try {
1293
- const approver = await this.contractInstance.callMethod("getApproved", [tokenId]);
1294
- if (approver === address) {
1295
- console.log(`Already approved:: ${approver}`);
1296
- resolve("Approved");
1297
- } else {
1298
- await this.contractInstance.sendTransaction("approve", [address, tokenId]);
1299
- console.log(`Approved`);
1300
- resolve("Approved");
1301
- }
1302
- } catch (error) {
1303
- console.error("Approval failed:", error);
1304
- return reject(error);
1305
- }
1306
- });
1307
- }
1308
- // ownerAddress: string,
1309
- async setApprovalForAll(operatorAddress) {
1310
- return new Promise(async (resolve, reject) => {
1311
- try {
1312
- await this.contractInstance.sendTransaction("setApprovalForAll", [operatorAddress, true]);
1313
- console.log(`Approved`);
1314
- resolve("Approved");
1315
- } catch (error) {
1316
- console.error("Approval failed:", error);
1317
- return reject(error);
1318
- }
1319
- });
1320
- }
1321
- async fetchMetaData(nftContractAddress, tokenId) {
1322
- return new Promise(async (resolve, reject) => {
1323
- try {
1324
- let url = await this.contractInstance.callMethod("tokenURI", [tokenId]);
1325
- if (url.startsWith("ipfs://")) {
1326
- url = url.replace("ipfs://", "https://ipfs.io/ipfs/");
1327
- }
1328
- const res = await fetch(url);
1329
- if (!res.ok) {
1330
- return reject(`Failed to fetch metadata from ${url}`);
1331
- }
1332
- let metadata = await res.json();
1333
- if (metadata.image && metadata.image.startsWith("ipfs://")) {
1334
- metadata.image = metadata.image.replace(
1335
- "ipfs://",
1336
- "https://ipfs.io/ipfs/"
1337
- );
1338
- }
1339
- metadata.address = nftContractAddress;
1340
- metadata.tokenId = tokenId;
1341
- return resolve(metadata);
1342
- } catch (error) {
1343
- return reject(error);
1344
- }
1345
- });
1346
- }
1347
- };
1348
- var Erc721Contract_default = Erc721Contract;
1349
-
1350
- // src/classes/Fund.ts
1351
- var { parseUnits, formatUnits } = ethers2.utils;
1352
- var Fund = class {
1353
- zkTlsSdk;
2382
+ // src/classes/FundForRedPacket.ts
2383
+ var { parseUnits: parseUnits3 } = ethers4.utils;
2384
+ var FundForRedPacket = class {
1354
2385
  fundContract;
1355
2386
  provider;
1356
2387
  formatProvider;
1357
2388
  chainId;
1358
- _dataSourceTemplateMap = DATASOURCETEMPLATESMAP;
1359
2389
  constructor() {
1360
2390
  }
1361
- getZkTlsSdk() {
1362
- return this.zkTlsSdk;
1363
- }
1364
- async init(provider, chainId, appId) {
2391
+ async init(provider, chainId) {
1365
2392
  return new Promise(async (resolve, reject) => {
1366
2393
  try {
1367
- let formatProvider;
1368
- if (provider instanceof ethers2.providers.JsonRpcProvider) {
1369
- formatProvider = provider;
1370
- } else {
1371
- formatProvider = new ethers2.providers.Web3Provider(provider);
1372
- }
1373
- const gasPrice = await formatProvider.getGasPrice();
1374
- console.log("getGasPrice=", gasPrice);
1375
- await formatProvider.ready;
1376
- const network = await formatProvider.getNetwork();
1377
- const providerChainId = network.chainId;
1378
- console.log("init provider", provider, network);
1379
- console.log("init providerChainId", providerChainId, chainId);
1380
- if (providerChainId !== chainId) {
1381
- return reject(`Please connect to the chain with ID ${chainId} first.`);
1382
- }
1383
- const fundContractAddress = Fund_CONTRACTS[chainId];
2394
+ const fundContractAddress = FundForRedPacket_CONTRACTS[chainId];
1384
2395
  if (!fundContractAddress) {
1385
2396
  return reject(`Unsupported chainId:${chainId}`);
1386
2397
  }
1387
- this.fundContract = new Contract_default(provider, fundContractAddress, abi_default);
2398
+ this.fundContract = new Contract_default(provider, fundContractAddress, abiForRedPacket_default);
1388
2399
  this.provider = provider;
1389
- this.formatProvider = formatProvider;
1390
2400
  this.chainId = chainId;
1391
- if (appId) {
1392
- this.zkTlsSdk = new PrimusZKTLS();
1393
- let platformDevice = "pc";
1394
- const isIpad = () => {
1395
- const userAgent = navigator.userAgent.toLowerCase();
1396
- const isTabletSize = window.innerWidth > 768 && window.innerWidth < 1366;
1397
- return /ipad/.test(userAgent) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 0 && isTabletSize;
1398
- };
1399
- if (navigator.userAgent.toLocaleLowerCase().includes("android")) {
1400
- platformDevice = "android";
1401
- } else if (navigator.userAgent.toLocaleLowerCase().includes("iphone") || isIpad()) {
1402
- platformDevice = "ios";
1403
- }
1404
- console.log("init appId", appId, platformDevice);
1405
- const extensionVersion = await this.zkTlsSdk.init(
1406
- appId,
1407
- "",
1408
- { platform: platformDevice }
1409
- );
1410
- resolve(extensionVersion);
1411
- } else {
1412
- resolve("success");
1413
- }
2401
+ resolve("success");
1414
2402
  } catch (error) {
1415
2403
  return reject(error);
1416
2404
  }
1417
2405
  });
1418
2406
  }
1419
- async fund(tokenInfo, recipientInfo) {
2407
+ async fundForRedPacket(tokenInfo, sendParam) {
1420
2408
  return new Promise(async (resolve, reject) => {
1421
2409
  try {
1422
- const recipientInfos = [];
1423
- recipientInfos[0] = recipientInfo;
1424
2410
  let decimals = 18;
1425
2411
  let params = [];
1426
2412
  if (tokenInfo.tokenType === 0) {
1427
- await this.approve(tokenInfo, recipientInfos);
2413
+ await this.approveForRedPacket(tokenInfo, sendParam.amount);
1428
2414
  console.log("after approve in fund fn");
1429
- const web3Provider = new ethers2.providers.Web3Provider(this.provider);
1430
- const erc20Contract = new ethers2.Contract(tokenInfo.tokenAddress, erc20Abi_default, web3Provider);
1431
- decimals = await erc20Contract.decimals();
1432
- } else if (tokenInfo.tokenType === 2) {
1433
- decimals = 0;
1434
- const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenInfo.tokenAddress);
1435
- await erc721ContractInstance.approve(this.fundContract.address, recipientInfo.nftIds[0]);
2415
+ const tokenContract = new Erc20Contract_default(this.provider, tokenInfo.tokenAddress);
2416
+ decimals = await tokenContract.decimals();
1436
2417
  }
1437
- const tokenAmount = parseUnits(recipientInfo.tokenAmount.toString(), decimals);
1438
- const newFundRecipientInfo = {
1439
- idSource: recipientInfo.socialPlatform,
1440
- id: recipientInfo.userIdentifier,
1441
- amount: tokenAmount,
1442
- 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
1443
2425
  };
1444
2426
  if (tokenInfo.tokenType === 1) {
1445
- params = [tokenInfo, newFundRecipientInfo, { value: tokenAmount }];
2427
+ params = [tokenInfo, formatSendParam, { value: formatSendAmount }];
1446
2428
  } else {
1447
- params = [tokenInfo, newFundRecipientInfo];
2429
+ params = [tokenInfo, formatSendParam];
1448
2430
  }
1449
2431
  if ([97, 56].includes(this.chainId)) {
1450
- const gasPrice = await this.formatProvider.getGasPrice();
2432
+ const gasPrice = await this.provider.getGasPrice();
1451
2433
  params[2] = params[2] ? { ...params[2], gasPrice } : { gasPrice };
1452
2434
  }
1453
- console.log("tip-params", params, this.chainId);
1454
- 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);
1455
2437
  resolve(result);
1456
2438
  } catch (error) {
1457
2439
  return reject(error);
1458
2440
  }
1459
2441
  });
1460
2442
  }
1461
- async onlyFund(tokenInfo, recipientInfo) {
2443
+ async onlyFundForRedPacket(tokenInfo, sendParam) {
1462
2444
  return new Promise(async (resolve, reject) => {
1463
2445
  try {
1464
- const recipientInfos = [];
1465
- recipientInfos[0] = recipientInfo;
1466
2446
  let decimals = 18;
1467
2447
  let params = [];
1468
2448
  if (tokenInfo.tokenType === 0) {
1469
- const web3Provider = new ethers2.providers.Web3Provider(this.provider);
1470
- const erc20Contract = new ethers2.Contract(tokenInfo.tokenAddress, erc20Abi_default, web3Provider);
1471
- decimals = await erc20Contract.decimals();
1472
- } else if (tokenInfo.tokenType === 2) {
1473
- decimals = 0;
1474
- const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenInfo.tokenAddress);
1475
- await erc721ContractInstance.approve(this.fundContract.address, recipientInfo.nftIds[0]);
2449
+ const tokenContract = new Erc20Contract_default(this.provider, tokenInfo.tokenAddress);
2450
+ decimals = await tokenContract.decimals();
1476
2451
  }
1477
- const tokenAmount = parseUnits(recipientInfo.tokenAmount.toString(), decimals);
1478
- const newFundRecipientInfo = {
1479
- idSource: recipientInfo.socialPlatform,
1480
- id: recipientInfo.userIdentifier,
1481
- amount: tokenAmount,
1482
- 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
1483
2459
  };
1484
2460
  if (tokenInfo.tokenType === 1) {
1485
- params = [tokenInfo, newFundRecipientInfo, { value: tokenAmount }];
2461
+ params = [tokenInfo, formatSendParam, { value: formatSendAmount }];
1486
2462
  } else {
1487
- params = [tokenInfo, newFundRecipientInfo];
2463
+ params = [tokenInfo, formatSendParam];
1488
2464
  }
1489
2465
  if ([97, 56].includes(this.chainId)) {
1490
- const gasPrice = await this.formatProvider.getGasPrice();
2466
+ const gasPrice = await this.provider.getGasPrice();
1491
2467
  params[2] = params[2] ? { ...params[2], gasPrice } : { gasPrice };
1492
2468
  }
1493
- console.log("tip-params", params, this.chainId);
1494
- 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);
1495
2471
  resolve(result);
1496
2472
  } catch (error) {
1497
2473
  return reject(error);
1498
2474
  }
1499
2475
  });
1500
2476
  }
1501
- async refund(recipients) {
2477
+ async withdrawForRedPacket(redPacketId) {
1502
2478
  return new Promise(async (resolve, reject) => {
1503
2479
  try {
1504
- const newRecipients = recipients.map((i) => {
1505
- return {
1506
- idSource: i.socialPlatform,
1507
- id: i.userIdentifier,
1508
- tipTimestamp: i.tipTimestamp
1509
- };
1510
- });
1511
- 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
+ };
1512
2501
  if ([97, 56].includes(this.chainId)) {
1513
- const gasPrice = await this.formatProvider.getGasPrice();
1514
- params.push({
1515
- gasPrice
1516
- });
2502
+ const gasPrice = await this.provider.getGasPrice();
2503
+ approveParams.otherParams = { gasPrice };
1517
2504
  }
1518
- const result = await this.fundContract.sendTransaction("tipperWithdraw", params);
1519
- return resolve(result);
2505
+ const tokenContract = new Erc20Contract_default(this.provider, tokenInfo.tokenAddress);
2506
+ await tokenContract.approve(approveParams);
2507
+ resolve("Approved");
1520
2508
  } catch (error) {
1521
2509
  return reject(error);
1522
2510
  }
1523
2511
  });
1524
2512
  }
1525
- async fundBatch(tokenInfo, recipientInfoList) {
2513
+ async claimForRedPacket(redPacketId, attestation) {
1526
2514
  return new Promise(async (resolve, reject) => {
1527
2515
  try {
1528
- let decimals = 18;
1529
- let params = [];
1530
- if (tokenInfo.tokenType === 0) {
1531
- await this.approve(tokenInfo, recipientInfoList);
1532
- const web3Provider = new ethers2.providers.Web3Provider(this.provider);
1533
- const erc20Contract = new ethers2.Contract(tokenInfo.tokenAddress, erc20Abi_default, web3Provider);
1534
- decimals = await erc20Contract.decimals();
1535
- } else if (tokenInfo.tokenType === 2) {
1536
- decimals = 0;
1537
- const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenInfo.tokenAddress);
1538
- await erc721ContractInstance.setApprovalForAll(this.fundContract.address);
1539
- }
1540
- let totalFormatAmount = recipientInfoList.reduce((acc, cur) => acc.add(parseUnits(cur.tokenAmount.toString(), decimals)), ethers2.BigNumber.from(0));
1541
- const newRecipientInfoList = recipientInfoList.map((i) => {
1542
- const formatAmount = parseUnits(i.tokenAmount.toString(), decimals);
1543
- return {
1544
- idSource: i.socialPlatform,
1545
- id: i.userIdentifier,
1546
- amount: formatAmount,
1547
- nftIds: i.nftIds
1548
- };
1549
- });
1550
- if (tokenInfo.tokenType === 1) {
1551
- params = [tokenInfo, newRecipientInfoList, { value: totalFormatAmount }];
1552
- } else {
1553
- params = [tokenInfo, newRecipientInfoList];
1554
- }
2516
+ const claimFee = await this.fundContract.callMethod("claimFee", []);
2517
+ let params = [redPacketId, attestation, { value: claimFee }];
1555
2518
  if ([97, 56].includes(this.chainId)) {
1556
- const gasPrice = await this.formatProvider.getGasPrice();
1557
- params[2] = params[2] ? { ...params[2], gasPrice } : { gasPrice };
2519
+ const gasPrice = await this.provider.getGasPrice();
2520
+ params[2].gasPrice = gasPrice;
1558
2521
  }
1559
- const result = await this.fundContract.sendTransaction("tipBatch", params);
1560
- return resolve(result);
2522
+ const txreceipt = await this.fundContract.sendTransaction("reClaim", params);
2523
+ return resolve(txreceipt);
1561
2524
  } catch (error) {
1562
2525
  return reject(error);
1563
2526
  }
1564
2527
  });
1565
2528
  }
1566
- // TODO-nft
1567
- async approve(tokenInfo, recipientInfoList) {
2529
+ async getRedPacketInfo(redPacketId) {
1568
2530
  return new Promise(async (resolve, reject) => {
1569
2531
  try {
1570
- const web3Provider = new ethers2.providers.Web3Provider(this.provider);
1571
- const signer = web3Provider.getSigner();
1572
- const address = await signer.getAddress();
1573
- const erc20Contract = new ethers2.Contract(tokenInfo.tokenAddress, erc20Abi_default, signer);
1574
- const allowance = await erc20Contract.allowance(address, this.fundContract.address);
1575
- const decimals = await erc20Contract.decimals();
1576
- console.log("allowance", formatUnits(allowance.toString(), decimals));
1577
- const requiredAllowance = recipientInfoList.reduce((acc, cur) => acc.add(parseUnits(cur.tokenAmount.toString(), decimals)), ethers2.BigNumber.from(0));
1578
- if (allowance.lt(requiredAllowance)) {
1579
- let params = [this.fundContract.address, requiredAllowance];
1580
- if ([97, 56].includes(this.chainId)) {
1581
- const gasPrice = await this.formatProvider.getGasPrice();
1582
- params.push({ gasPrice });
1583
- }
1584
- const tx = await erc20Contract.approve(...params);
1585
- await tx.wait();
1586
- console.log(`Approved: ${requiredAllowance.toString()}`);
1587
- } else {
1588
- console.log(`Already approved: ${allowance.toString()}`);
1589
- }
1590
- resolve("Approved");
2532
+ const redpacketInfo = await this.fundContract.callMethod("getREInfo", [redPacketId]);
2533
+ return resolve(redpacketInfo);
1591
2534
  } catch (error) {
1592
- console.error("Approval failed:", error);
1593
- if (error?.code === "ACTION_REJECTED") {
1594
- 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";
1595
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) {
1596
2573
  return reject(error);
1597
2574
  }
1598
2575
  });
1599
2576
  }
1600
- async attest(attestParams, genAppSignature, backUrl) {
2577
+ async attest(attestParams, signFn, backUrl) {
1601
2578
  return new Promise(async (resolve, reject) => {
1602
2579
  console.log("this.zkTlsSdk", this.zkTlsSdk);
1603
2580
  const { socialPlatform, userIdentifier, address } = attestParams;
1604
- const { id: templateId, field } = this._dataSourceTemplateMap[socialPlatform];
2581
+ const { id: templateId, field } = DATASOURCETEMPLATESMAP[socialPlatform];
1605
2582
  const attRequest = this.zkTlsSdk.generateRequestParams(
1606
2583
  templateId,
1607
2584
  address
@@ -1620,7 +2597,7 @@ var Fund = class {
1620
2597
  ]
1621
2598
  ]);
1622
2599
  const signParams = attRequest.toJsonString();
1623
- const signature = await genAppSignature(signParams);
2600
+ const signature = await signFn(signParams);
1624
2601
  if (!signature) {
1625
2602
  return reject(`appSignature is empty!`);
1626
2603
  }
@@ -1640,121 +2617,41 @@ var Fund = class {
1640
2617
  }
1641
2618
  });
1642
2619
  }
1643
- async claimBySource(socialPlatform, userIdentifier, attestation) {
2620
+ async attestCommon(attestParams) {
2621
+ const { templateId, address, signFn, conditions, additionParams, backUrl } = attestParams;
1644
2622
  return new Promise(async (resolve, reject) => {
1645
- try {
1646
- const claimFee = await this.fundContract.callMethod("claimFee", []);
1647
- const fundRecords = await this.fundContract.callMethod("getTipRecords", [{ idSource: socialPlatform, id: userIdentifier }]);
1648
- console.log("fundRecords", fundRecords);
1649
- const recordCount = fundRecords.length;
1650
- if (recordCount <= 0) {
1651
- return reject(`No fund records.`);
1652
- } else {
1653
- const totalFee = claimFee.mul(recordCount);
1654
- let params = [socialPlatform, attestation, { value: totalFee }];
1655
- if ([97, 56].includes(this.chainId)) {
1656
- const gasPrice = await this.formatProvider.getGasPrice();
1657
- params[2].gasPrice = gasPrice;
1658
- }
1659
- const txreceipt = await this.fundContract.sendTransaction("claimBySource", params);
1660
- return resolve(txreceipt);
1661
- }
1662
- } catch (error) {
1663
- 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);
1664
2630
  }
1665
- });
1666
- }
1667
- async claimByMultiSource(socialPlatforms, userIdentifiers, attestationList) {
1668
- return new Promise(async (resolve, reject) => {
1669
- try {
1670
- if (socialPlatforms.length !== userIdentifiers.length || socialPlatforms.length !== attestationList.length) {
1671
- return reject(`socialPlatforms, userIdentifiers, attestationList length must be equal.`);
1672
- }
1673
- const claimFee = await this.fundContract.callMethod("claimFee", []);
1674
- let allFundRecords = [];
1675
- let recordCount = 0;
1676
- for (const [index, value] of socialPlatforms.entries()) {
1677
- const fundRecords = await this.fundContract.callMethod("getTipRecords", [{ idSource: value, id: userIdentifiers[index] }]);
1678
- allFundRecords.push(...fundRecords);
1679
- recordCount += fundRecords.length;
1680
- }
1681
- if (recordCount <= 0) {
1682
- return reject(`No fund records.`);
1683
- } else {
1684
- const totalFee = claimFee.mul(recordCount);
1685
- let params = [socialPlatforms, userIdentifiers, attestationList, { value: totalFee }];
1686
- if ([97, 56].includes(this.chainId)) {
1687
- const gasPrice = await this.formatProvider.getGasPrice();
1688
- params[3].gasPrice = gasPrice;
1689
- }
1690
- const txreceipt = await this.fundContract.sendTransaction("claimByMultiSource", params);
1691
- return resolve(txreceipt);
1692
- }
1693
- } catch (error) {
1694
- console.error("claimByMultiSource", error);
1695
- 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!`);
1696
2643
  }
1697
- });
1698
- }
1699
- async getTipRecords(getFundRecordsParams) {
1700
- return new Promise(async (resolve, reject) => {
1701
2644
  try {
1702
- const formatGetFundRecordsParams = getFundRecordsParams.map((item) => {
1703
- return {
1704
- idSource: item.socialPlatform,
1705
- id: item.userIdentifier
1706
- };
1707
- });
1708
- const fundRecords = await this.fundContract.callMethod("getTipRecords", formatGetFundRecordsParams);
1709
- console.log("fundRecords", fundRecords);
1710
- let formatRecords = [];
1711
- for (const record of fundRecords) {
1712
- const { tipper, timestamp, tipToken: [tokenType, tokenAddress], amount, nftIds } = record;
1713
- let decimals = 18;
1714
- let symbol = "";
1715
- let tokenId = null;
1716
- let nftInfo = null;
1717
- if (tokenType === 0) {
1718
- let formatProvider;
1719
- if (this.provider instanceof ethers2.providers.JsonRpcProvider) {
1720
- formatProvider = this.provider;
1721
- } else {
1722
- formatProvider = new ethers2.providers.Web3Provider(this.provider);
1723
- }
1724
- const erc20Contract = new ethers2.Contract(tokenAddress, erc20Abi_default, formatProvider);
1725
- decimals = await erc20Contract.decimals();
1726
- symbol = await erc20Contract.symbol();
1727
- } else if (tokenType === 1) {
1728
- symbol = NATIVETOKENS[this.chainId];
1729
- } else if (tokenType === 2) {
1730
- decimals = 0;
1731
- tokenId = parseInt(nftIds[0]);
1732
- const erc721ContractInstance = new Erc721Contract_default(this.provider, tokenAddress);
1733
- nftInfo = await erc721ContractInstance.fetchMetaData(tokenAddress, tokenId);
1734
- }
1735
- let fundToken = {
1736
- tokenType,
1737
- // tokenAmount: formatUnits(amount, decimals),
1738
- decimals,
1739
- symbol,
1740
- chainName: CHAINNAMES[this.chainId],
1741
- chainId: this.chainId
1742
- };
1743
- if (tokenType === 0) {
1744
- fundToken.tokenAddress = tokenAddress;
1745
- }
1746
- if (tokenType === 2) {
1747
- Object.assign(fundToken, nftInfo ?? {});
1748
- }
1749
- formatRecords.push({
1750
- funder: tipper,
1751
- fundToken,
1752
- amount: formatUnits(amount, decimals),
1753
- timestamp: timestamp.toNumber()
1754
- });
1755
- }
1756
- console.log("formatRecords", formatRecords);
1757
- 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);
1758
2655
  } catch (error) {
1759
2656
  return reject(error);
1760
2657
  }
@@ -1766,15 +2663,41 @@ var Fund = class {
1766
2663
  var PrimusFund = class {
1767
2664
  supportedChainIds = SUPPORTEDCHAINIDS;
1768
2665
  supportedSocialPlatforms = SUPPORTEDSOCIALPLATFORMS;
2666
+ provider;
1769
2667
  _fund;
2668
+ _fundForRedPacket;
2669
+ _zkTlsSdk;
1770
2670
  async init(provider, chainId, appId) {
1771
2671
  return new Promise(async (resolve, reject) => {
1772
2672
  try {
1773
2673
  if (!this.supportedChainIds.includes(chainId)) {
1774
2674
  return reject("chainId is not supported");
1775
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;
1776
2693
  this._fund = new Fund();
1777
- 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
+ }
1778
2701
  return resolve(result);
1779
2702
  } catch (error) {
1780
2703
  return reject(error);
@@ -1793,7 +2716,7 @@ var PrimusFund = class {
1793
2716
  return reject("socialPlatform is not supported");
1794
2717
  }
1795
2718
  if (tokenInfo.tokenType === 1) {
1796
- tokenInfo.tokenAddress = ethers3.constants.AddressZero;
2719
+ tokenInfo.tokenAddress = ethers5.constants.AddressZero;
1797
2720
  }
1798
2721
  const newFundRecipientInfos = recipientInfos.map((i) => {
1799
2722
  const formatSocialPlatform = i.socialPlatform.toLowerCase();
@@ -1832,7 +2755,7 @@ var PrimusFund = class {
1832
2755
  return reject("socialPlatform is not supported");
1833
2756
  }
1834
2757
  if (tokenInfo.tokenType === 1) {
1835
- tokenInfo.tokenAddress = ethers3.constants.AddressZero;
2758
+ tokenInfo.tokenAddress = ethers5.constants.AddressZero;
1836
2759
  }
1837
2760
  const newFundRecipientInfos = recipientInfos.map((i) => {
1838
2761
  const formatSocialPlatform = i.socialPlatform.toLowerCase();
@@ -1866,7 +2789,7 @@ var PrimusFund = class {
1866
2789
  return reject("socialPlatform is not supported");
1867
2790
  }
1868
2791
  if (tokenInfo.tokenType === 1) {
1869
- tokenInfo.tokenAddress = ethers3.constants.AddressZero;
2792
+ tokenInfo.tokenAddress = ethers5.constants.AddressZero;
1870
2793
  }
1871
2794
  const newFundRecipientInfos = recipientInfos.map((i) => {
1872
2795
  const formatSocialPlatform = i.socialPlatform.toLowerCase();
@@ -1908,15 +2831,15 @@ var PrimusFund = class {
1908
2831
  }
1909
2832
  });
1910
2833
  }
1911
- async attest(attestParams, genAppSignature, backUrl) {
2834
+ async attest(attestParams, signFn, backUrl) {
1912
2835
  return new Promise(async (resolve, reject) => {
1913
2836
  try {
1914
2837
  const { socialPlatform } = attestParams;
1915
2838
  const lcSocialPlatform = socialPlatform.toLowerCase();
1916
- const attestation = await this._fund?.attest({
2839
+ const attestation = await this._zkTlsSdk?.attest({
1917
2840
  ...attestParams,
1918
2841
  socialPlatform: lcSocialPlatform
1919
- }, genAppSignature, backUrl);
2842
+ }, signFn, backUrl);
1920
2843
  return resolve(attestation);
1921
2844
  } catch (error) {
1922
2845
  return reject(error);
@@ -1984,6 +2907,79 @@ var PrimusFund = class {
1984
2907
  }
1985
2908
  });
1986
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
+ }
1987
2983
  };
1988
2984
  export {
1989
2985
  PrimusFund