anymal-protocol 1.0.0 → 1.0.2

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
@@ -3,6 +3,545 @@ import { useCallback } from "react";
3
3
  import { encodeFunctionData, parseGwei } from "viem";
4
4
 
5
5
  // src/helpers/BlockchainAbiHelper.tsx
6
+ var PET_NFT_ABI = [
7
+ { inputs: [], stateMutability: "nonpayable", type: "constructor" },
8
+ {
9
+ inputs: [],
10
+ name: "AccessControlBadConfirmation",
11
+ type: "error"
12
+ },
13
+ {
14
+ inputs: [
15
+ { internalType: "address", name: "account", type: "address" },
16
+ {
17
+ internalType: "bytes32",
18
+ name: "neededRole",
19
+ type: "bytes32"
20
+ }
21
+ ],
22
+ name: "AccessControlUnauthorizedAccount",
23
+ type: "error"
24
+ },
25
+ {
26
+ inputs: [{ internalType: "address", name: "target", type: "address" }],
27
+ name: "AddressEmptyCode",
28
+ type: "error"
29
+ },
30
+ {
31
+ inputs: [{ internalType: "address", name: "implementation", type: "address" }],
32
+ name: "ERC1967InvalidImplementation",
33
+ type: "error"
34
+ },
35
+ { inputs: [], name: "ERC1967NonPayable", type: "error" },
36
+ {
37
+ inputs: [],
38
+ name: "EnforcedPause",
39
+ type: "error"
40
+ },
41
+ { inputs: [], name: "ExpectedPause", type: "error" },
42
+ {
43
+ inputs: [],
44
+ name: "FailedCall",
45
+ type: "error"
46
+ },
47
+ { inputs: [], name: "InvalidInitialization", type: "error" },
48
+ {
49
+ inputs: [],
50
+ name: "NotInitializing",
51
+ type: "error"
52
+ },
53
+ {
54
+ inputs: [],
55
+ name: "UUPSUnauthorizedCallContext",
56
+ type: "error"
57
+ },
58
+ {
59
+ inputs: [{ internalType: "bytes32", name: "slot", type: "bytes32" }],
60
+ name: "UUPSUnsupportedProxiableUUID",
61
+ type: "error"
62
+ },
63
+ {
64
+ anonymous: false,
65
+ inputs: [{ indexed: false, internalType: "uint64", name: "version", type: "uint64" }],
66
+ name: "Initialized",
67
+ type: "event"
68
+ },
69
+ {
70
+ anonymous: false,
71
+ inputs: [
72
+ {
73
+ indexed: true,
74
+ internalType: "address",
75
+ name: "user",
76
+ type: "address"
77
+ },
78
+ { indexed: false, internalType: "string", name: "pid", type: "string" },
79
+ {
80
+ indexed: false,
81
+ internalType: "string",
82
+ name: "nftId",
83
+ type: "string"
84
+ },
85
+ { indexed: false, internalType: "string", name: "metadataURL", type: "string" },
86
+ {
87
+ indexed: false,
88
+ internalType: "uint256",
89
+ name: "campaignId",
90
+ type: "uint256"
91
+ },
92
+ { indexed: false, internalType: "uint256", name: "rewardAmount", type: "uint256" }
93
+ ],
94
+ name: "MetadataApproved",
95
+ type: "event"
96
+ },
97
+ {
98
+ anonymous: false,
99
+ inputs: [
100
+ {
101
+ indexed: true,
102
+ internalType: "address",
103
+ name: "user",
104
+ type: "address"
105
+ },
106
+ { indexed: false, internalType: "string", name: "pid", type: "string" },
107
+ {
108
+ indexed: false,
109
+ internalType: "string",
110
+ name: "nftId",
111
+ type: "string"
112
+ },
113
+ { indexed: false, internalType: "string", name: "metadataURL", type: "string" },
114
+ {
115
+ indexed: false,
116
+ internalType: "uint256",
117
+ name: "campaignId",
118
+ type: "uint256"
119
+ },
120
+ { indexed: false, internalType: "uint256", name: "rewardAmount", type: "uint256" }
121
+ ],
122
+ name: "MetadataRejected",
123
+ type: "event"
124
+ },
125
+ {
126
+ anonymous: false,
127
+ inputs: [
128
+ {
129
+ indexed: true,
130
+ internalType: "address",
131
+ name: "user",
132
+ type: "address"
133
+ },
134
+ { indexed: false, internalType: "string", name: "pid", type: "string" },
135
+ {
136
+ indexed: false,
137
+ internalType: "string",
138
+ name: "nftId",
139
+ type: "string"
140
+ },
141
+ { indexed: false, internalType: "string", name: "metadataURL", type: "string" },
142
+ {
143
+ indexed: false,
144
+ internalType: "uint256",
145
+ name: "campaignId",
146
+ type: "uint256"
147
+ },
148
+ { indexed: false, internalType: "uint256", name: "rewardAmount", type: "uint256" }
149
+ ],
150
+ name: "MetadataSubmitted",
151
+ type: "event"
152
+ },
153
+ {
154
+ anonymous: false,
155
+ inputs: [{ indexed: false, internalType: "address", name: "account", type: "address" }],
156
+ name: "Paused",
157
+ type: "event"
158
+ },
159
+ {
160
+ anonymous: false,
161
+ inputs: [
162
+ {
163
+ indexed: true,
164
+ internalType: "address",
165
+ name: "user",
166
+ type: "address"
167
+ },
168
+ { indexed: false, internalType: "string", name: "pid", type: "string" },
169
+ {
170
+ indexed: false,
171
+ internalType: "string",
172
+ name: "nftId",
173
+ type: "string"
174
+ },
175
+ {
176
+ indexed: false,
177
+ internalType: "uint256",
178
+ name: "rewardAmount",
179
+ type: "uint256"
180
+ },
181
+ { indexed: false, internalType: "uint256", name: "campaignId", type: "uint256" }
182
+ ],
183
+ name: "RewardDistributed",
184
+ type: "event"
185
+ },
186
+ {
187
+ anonymous: false,
188
+ inputs: [
189
+ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
190
+ {
191
+ indexed: true,
192
+ internalType: "bytes32",
193
+ name: "previousAdminRole",
194
+ type: "bytes32"
195
+ },
196
+ { indexed: true, internalType: "bytes32", name: "newAdminRole", type: "bytes32" }
197
+ ],
198
+ name: "RoleAdminChanged",
199
+ type: "event"
200
+ },
201
+ {
202
+ anonymous: false,
203
+ inputs: [
204
+ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
205
+ {
206
+ indexed: true,
207
+ internalType: "address",
208
+ name: "account",
209
+ type: "address"
210
+ },
211
+ { indexed: true, internalType: "address", name: "sender", type: "address" }
212
+ ],
213
+ name: "RoleGranted",
214
+ type: "event"
215
+ },
216
+ {
217
+ anonymous: false,
218
+ inputs: [
219
+ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
220
+ {
221
+ indexed: true,
222
+ internalType: "address",
223
+ name: "account",
224
+ type: "address"
225
+ },
226
+ { indexed: true, internalType: "address", name: "sender", type: "address" }
227
+ ],
228
+ name: "RoleRevoked",
229
+ type: "event"
230
+ },
231
+ {
232
+ anonymous: false,
233
+ inputs: [{ indexed: false, internalType: "address", name: "account", type: "address" }],
234
+ name: "Unpaused",
235
+ type: "event"
236
+ },
237
+ {
238
+ anonymous: false,
239
+ inputs: [{ indexed: true, internalType: "address", name: "implementation", type: "address" }],
240
+ name: "Upgraded",
241
+ type: "event"
242
+ },
243
+ {
244
+ inputs: [],
245
+ name: "APPROVER_ROLE",
246
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
247
+ stateMutability: "view",
248
+ type: "function"
249
+ },
250
+ {
251
+ inputs: [],
252
+ name: "DEFAULT_ADMIN_ROLE",
253
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
254
+ stateMutability: "view",
255
+ type: "function"
256
+ },
257
+ {
258
+ inputs: [],
259
+ name: "UPGRADE_INTERFACE_VERSION",
260
+ outputs: [{ internalType: "string", name: "", type: "string" }],
261
+ stateMutability: "view",
262
+ type: "function"
263
+ },
264
+ {
265
+ inputs: [
266
+ { internalType: "address", name: "_user", type: "address" },
267
+ {
268
+ internalType: "string",
269
+ name: "_pid",
270
+ type: "string"
271
+ },
272
+ { internalType: "string", name: "_nftId", type: "string" },
273
+ {
274
+ internalType: "string",
275
+ name: "_metadataURL",
276
+ type: "string"
277
+ },
278
+ { internalType: "uint256", name: "_campaignId", type: "uint256" }
279
+ ],
280
+ name: "approveMetadata",
281
+ outputs: [],
282
+ stateMutability: "nonpayable",
283
+ type: "function"
284
+ },
285
+ {
286
+ inputs: [],
287
+ name: "campaignCount",
288
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
289
+ stateMutability: "view",
290
+ type: "function"
291
+ },
292
+ {
293
+ inputs: [{ internalType: "uint256", name: "", type: "uint256" }],
294
+ name: "campaigns",
295
+ outputs: [
296
+ { internalType: "string", name: "name", type: "string" },
297
+ {
298
+ internalType: "uint256",
299
+ name: "rewardAmount",
300
+ type: "uint256"
301
+ },
302
+ { internalType: "bool", name: "isActive", type: "bool" }
303
+ ],
304
+ stateMutability: "view",
305
+ type: "function"
306
+ },
307
+ {
308
+ inputs: [
309
+ { internalType: "string", name: "_name", type: "string" },
310
+ {
311
+ internalType: "uint256",
312
+ name: "_rewardAmount",
313
+ type: "uint256"
314
+ }
315
+ ],
316
+ name: "createCampaign",
317
+ outputs: [],
318
+ stateMutability: "nonpayable",
319
+ type: "function"
320
+ },
321
+ {
322
+ inputs: [],
323
+ name: "defaultRewardAmount",
324
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
325
+ stateMutability: "view",
326
+ type: "function"
327
+ },
328
+ {
329
+ inputs: [{ internalType: "bytes32", name: "role", type: "bytes32" }],
330
+ name: "getRoleAdmin",
331
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
332
+ stateMutability: "view",
333
+ type: "function"
334
+ },
335
+ {
336
+ inputs: [
337
+ { internalType: "bytes32", name: "role", type: "bytes32" },
338
+ {
339
+ internalType: "address",
340
+ name: "account",
341
+ type: "address"
342
+ }
343
+ ],
344
+ name: "grantRole",
345
+ outputs: [],
346
+ stateMutability: "nonpayable",
347
+ type: "function"
348
+ },
349
+ {
350
+ inputs: [
351
+ { internalType: "bytes32", name: "role", type: "bytes32" },
352
+ {
353
+ internalType: "address",
354
+ name: "account",
355
+ type: "address"
356
+ }
357
+ ],
358
+ name: "hasRole",
359
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
360
+ stateMutability: "view",
361
+ type: "function"
362
+ },
363
+ {
364
+ inputs: [
365
+ {
366
+ internalType: "address",
367
+ name: "initialOwner",
368
+ type: "address"
369
+ },
370
+ {
371
+ internalType: "contract IERC20",
372
+ name: "_rewardToken",
373
+ type: "address"
374
+ },
375
+ {
376
+ internalType: "contract IPetToken",
377
+ name: "_petToken",
378
+ type: "address"
379
+ },
380
+ { internalType: "uint256", name: "_defaultRewardAmount", type: "uint256" }
381
+ ],
382
+ name: "initialize",
383
+ outputs: [],
384
+ stateMutability: "nonpayable",
385
+ type: "function"
386
+ },
387
+ {
388
+ inputs: [],
389
+ name: "pause",
390
+ outputs: [],
391
+ stateMutability: "nonpayable",
392
+ type: "function"
393
+ },
394
+ {
395
+ inputs: [],
396
+ name: "paused",
397
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
398
+ stateMutability: "view",
399
+ type: "function"
400
+ },
401
+ {
402
+ inputs: [],
403
+ name: "petToken",
404
+ outputs: [{ internalType: "contract IPetToken", name: "", type: "address" }],
405
+ stateMutability: "view",
406
+ type: "function"
407
+ },
408
+ {
409
+ inputs: [],
410
+ name: "proxiableUUID",
411
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
412
+ stateMutability: "view",
413
+ type: "function"
414
+ },
415
+ {
416
+ inputs: [
417
+ { internalType: "bytes32", name: "role", type: "bytes32" },
418
+ {
419
+ internalType: "address",
420
+ name: "callerConfirmation",
421
+ type: "address"
422
+ }
423
+ ],
424
+ name: "renounceRole",
425
+ outputs: [],
426
+ stateMutability: "nonpayable",
427
+ type: "function"
428
+ },
429
+ {
430
+ inputs: [
431
+ { internalType: "bytes32", name: "role", type: "bytes32" },
432
+ {
433
+ internalType: "address",
434
+ name: "account",
435
+ type: "address"
436
+ }
437
+ ],
438
+ name: "revokeRole",
439
+ outputs: [],
440
+ stateMutability: "nonpayable",
441
+ type: "function"
442
+ },
443
+ {
444
+ inputs: [],
445
+ name: "rewardToken",
446
+ outputs: [{ internalType: "contract IERC20", name: "", type: "address" }],
447
+ stateMutability: "view",
448
+ type: "function"
449
+ },
450
+ {
451
+ inputs: [
452
+ { internalType: "string", name: "_pid", type: "string" },
453
+ {
454
+ internalType: "string",
455
+ name: "_nftId",
456
+ type: "string"
457
+ },
458
+ { internalType: "string", name: "_metadataURL", type: "string" },
459
+ {
460
+ internalType: "uint256",
461
+ name: "_campaignId",
462
+ type: "uint256"
463
+ }
464
+ ],
465
+ name: "submitMetadata",
466
+ outputs: [],
467
+ stateMutability: "nonpayable",
468
+ type: "function"
469
+ },
470
+ {
471
+ inputs: [
472
+ { internalType: "string", name: "_pid", type: "string" },
473
+ {
474
+ internalType: "string",
475
+ name: "_nftId",
476
+ type: "string"
477
+ },
478
+ { internalType: "string", name: "_metadataURL", type: "string" },
479
+ {
480
+ internalType: "string",
481
+ name: "_campaignName",
482
+ type: "string"
483
+ }
484
+ ],
485
+ name: "submitMetadataByCampaignName",
486
+ outputs: [],
487
+ stateMutability: "nonpayable",
488
+ type: "function"
489
+ },
490
+ {
491
+ inputs: [{ internalType: "bytes4", name: "interfaceId", type: "bytes4" }],
492
+ name: "supportsInterface",
493
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
494
+ stateMutability: "view",
495
+ type: "function"
496
+ },
497
+ {
498
+ inputs: [],
499
+ name: "unpause",
500
+ outputs: [],
501
+ stateMutability: "nonpayable",
502
+ type: "function"
503
+ },
504
+ {
505
+ inputs: [
506
+ {
507
+ internalType: "uint256",
508
+ name: "_campaignId",
509
+ type: "uint256"
510
+ },
511
+ { internalType: "uint256", name: "_rewardAmount", type: "uint256" },
512
+ {
513
+ internalType: "bool",
514
+ name: "_isActive",
515
+ type: "bool"
516
+ }
517
+ ],
518
+ name: "updateCampaign",
519
+ outputs: [],
520
+ stateMutability: "nonpayable",
521
+ type: "function"
522
+ },
523
+ {
524
+ inputs: [{ internalType: "uint256", name: "_rewardAmount", type: "uint256" }],
525
+ name: "updateDefaultReward",
526
+ outputs: [],
527
+ stateMutability: "nonpayable",
528
+ type: "function"
529
+ },
530
+ {
531
+ inputs: [
532
+ {
533
+ internalType: "address",
534
+ name: "newImplementation",
535
+ type: "address"
536
+ },
537
+ { internalType: "bytes", name: "data", type: "bytes" }
538
+ ],
539
+ name: "upgradeToAndCall",
540
+ outputs: [],
541
+ stateMutability: "payable",
542
+ type: "function"
543
+ }
544
+ ];
6
545
  var VERIFY_ACCOUNT_ABI = [
7
546
  {
8
547
  inputs: [
@@ -59,6 +598,188 @@ function useVerifyAccount() {
59
598
  []
60
599
  );
61
600
  }
601
+
602
+ // src/utils/anymals/useMintAnymalNFT.ts
603
+ import { encodeFunctionData as encodeFunctionData2, parseGwei as parseGwei2 } from "viem";
604
+ import { useCallback as useCallback2 } from "react";
605
+ function useMintAnymalNFT() {
606
+ return useCallback2(
607
+ async (pid, nftId, dbAuthToken, validationContractAddress, smartAccount, bundlerClient) => {
608
+ if (!dbAuthToken || !nftId || !bundlerClient || !smartAccount || !pid || !validationContractAddress) {
609
+ return {
610
+ success: false,
611
+ message: "Missing authentication token OR NFT ID."
612
+ };
613
+ }
614
+ const callData = encodeFunctionData2({
615
+ abi: PET_NFT_ABI,
616
+ functionName: "submitMetadataByCampaignName",
617
+ args: [
618
+ pid,
619
+ nftId,
620
+ `https://dev-nft.petastic.com/metadata/${nftId}`,
621
+ "petastic-signup-campaign-1"
622
+ ]
623
+ });
624
+ const userOpHash = await bundlerClient.sendUserOperation({
625
+ account: smartAccount,
626
+ calls: [
627
+ {
628
+ to: validationContractAddress,
629
+ data: callData
630
+ }
631
+ ],
632
+ maxPriorityFeePerGas: parseGwei2("0.001"),
633
+ maxFeePerGas: parseGwei2("0.001")
634
+ });
635
+ await bundlerClient.waitForUserOperationReceipt({
636
+ hash: userOpHash
637
+ });
638
+ return { success: true, message: "Pet Passport Created!" };
639
+ },
640
+ []
641
+ );
642
+ }
643
+
644
+ // src/utils/anymals/useAddAnymalToDatabase.ts
645
+ import { useCallback as useCallback3 } from "react";
646
+ function useAddAnymalToDatabase() {
647
+ return useCallback3(
648
+ async (dbAuthToken, endpoint, anymalData) => {
649
+ if (!dbAuthToken) {
650
+ return {
651
+ success: false,
652
+ message: "Authentication token is missing.",
653
+ _docID: null
654
+ };
655
+ }
656
+ let anymalDocID = null;
657
+ try {
658
+ const mutation = `
659
+ mutation Create_Anymal($input: [AnymalMutationInputArg!]) {
660
+ create_Anymal(input: $input) {
661
+ _docID
662
+ name
663
+ passportID
664
+ }
665
+ }
666
+ `;
667
+ const response = await fetch(endpoint, {
668
+ method: "POST",
669
+ headers: {
670
+ "Content-Type": "application/json",
671
+ Authorization: `Bearer ${dbAuthToken}`
672
+ },
673
+ body: JSON.stringify({
674
+ query: mutation,
675
+ variables: { input: [anymalData] }
676
+ })
677
+ });
678
+ if (!response.ok) {
679
+ throw new Error(
680
+ `Failed to create pet. HTTP status ${response.status}`
681
+ );
682
+ }
683
+ const { data, errors } = await response.json();
684
+ if (errors) {
685
+ const errorMessage = JSON.stringify(errors);
686
+ if (errorMessage.includes("given ID already exists")) {
687
+ console.warn("Duplicate document ID detected.");
688
+ anymalDocID = data?.create_Anymal[0]?._docID || null;
689
+ throw new Error("Document with the given ID already exists.");
690
+ }
691
+ throw new Error(`GraphQL error: ${errorMessage}`);
692
+ }
693
+ anymalDocID = data.create_Anymal[0]._docID;
694
+ return {
695
+ success: true,
696
+ _docID: anymalDocID,
697
+ message: "Anymal added to account"
698
+ };
699
+ } catch (error) {
700
+ return {
701
+ success: false,
702
+ _docID: null,
703
+ message: "Error adding anymal to account"
704
+ };
705
+ }
706
+ },
707
+ []
708
+ );
709
+ }
710
+
711
+ // src/utils/anymals/useDeleteAnymalFromDatabase.ts
712
+ import { useCallback as useCallback4 } from "react";
713
+ function useDeleteAnymalFromDatabase() {
714
+ return useCallback4(
715
+ async (dbAuthToken, endpoint, anymalDocID) => {
716
+ if (!dbAuthToken || !endpoint || !anymalDocID) return;
717
+ try {
718
+ const mutation = `
719
+ mutation Delete_Anymal($docId: [ID]) {
720
+ delete_Anymal(docID: $docId) {
721
+ _docID
722
+ }
723
+ }
724
+ `;
725
+ const response = await fetch(endpoint, {
726
+ method: "POST",
727
+ headers: {
728
+ "Content-Type": "application/json",
729
+ Authorization: `Bearer ${dbAuthToken}`
730
+ },
731
+ body: JSON.stringify({
732
+ query: mutation,
733
+ variables: { docId: [anymalDocID] }
734
+ })
735
+ });
736
+ if (!response.ok)
737
+ throw new Error(
738
+ `Failed to delete anymal. HTTP status ${response.status}`
739
+ );
740
+ const { errors } = await response.json();
741
+ if (errors) throw new Error(`GraphQL error: ${JSON.stringify(errors)}`);
742
+ } catch (error) {
743
+ console.error("Error deleting anymal from database:", error);
744
+ throw error;
745
+ }
746
+ },
747
+ []
748
+ );
749
+ }
750
+
751
+ // src/utils/anymals/useSaveAnymalMetadata.ts
752
+ import { useCallback as useCallback5 } from "react";
753
+ function useSaveAnymalMetadata() {
754
+ return useCallback5(
755
+ async (idToken, publicKey, nftMetadataInput, authServiceBaseUrl) => {
756
+ const response = await fetch(`${authServiceBaseUrl}/process-nft`, {
757
+ method: "POST",
758
+ headers: {
759
+ "Content-Type": "application/json",
760
+ Authorization: "Bearer " + idToken
761
+ },
762
+ body: JSON.stringify({
763
+ appPubKey: publicKey,
764
+ nftMetadataInput
765
+ })
766
+ });
767
+ const data = await response.json();
768
+ if (data.errors) {
769
+ throw new Error(`GraphQL error: ${JSON.stringify(data.errors)}`);
770
+ }
771
+ return {
772
+ success: true,
773
+ message: data[0]
774
+ };
775
+ },
776
+ []
777
+ );
778
+ }
62
779
  export {
780
+ useAddAnymalToDatabase,
781
+ useDeleteAnymalFromDatabase,
782
+ useMintAnymalNFT,
783
+ useSaveAnymalMetadata,
63
784
  useVerifyAccount
64
785
  };