@primuslabs/fund-js-sdk 0.1.12 → 0.1.14

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