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