anymal-protocol 1.0.0

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.
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="GitToolBoxBlameSettings">
4
+ <option name="version" value="2" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
5
+ </profile>
6
+ </component>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="EslintConfiguration">
4
+ <option name="fix-on-save" value="true" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/anymal-protocol.iml" filepath="$PROJECT_DIR$/.idea/anymal-protocol.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="PrettierConfiguration">
4
+ <option name="myRunOnSave" value="true" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,6 @@
1
+ declare function useVerifyAccount(): (pid: string, dbAuthToken: string, bundlerClient: any, smartAccount: any, accountRewardsContractAddress: `0x${string}`) => Promise<{
2
+ success: boolean;
3
+ message: string;
4
+ }>;
5
+
6
+ export { useVerifyAccount };
@@ -0,0 +1,6 @@
1
+ declare function useVerifyAccount(): (pid: string, dbAuthToken: string, bundlerClient: any, smartAccount: any, accountRewardsContractAddress: `0x${string}`) => Promise<{
2
+ success: boolean;
3
+ message: string;
4
+ }>;
5
+
6
+ export { useVerifyAccount };
package/dist/index.js ADDED
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ useVerifyAccount: () => useVerifyAccount
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/utils/useVerifyAccount.ts
28
+ var import_react = require("react");
29
+ var import_viem = require("viem");
30
+
31
+ // src/helpers/BlockchainAbiHelper.tsx
32
+ var VERIFY_ACCOUNT_ABI = [
33
+ {
34
+ inputs: [
35
+ {
36
+ internalType: "string",
37
+ name: "_campaignName",
38
+ type: "string"
39
+ },
40
+ { internalType: "string", name: "_pid", type: "string" }
41
+ ],
42
+ name: "claimRewardByName",
43
+ outputs: [],
44
+ stateMutability: "nonpayable",
45
+ type: "function"
46
+ }
47
+ ];
48
+
49
+ // src/utils/useVerifyAccount.ts
50
+ function useVerifyAccount() {
51
+ return (0, import_react.useCallback)(
52
+ async (pid, dbAuthToken, bundlerClient, smartAccount, accountRewardsContractAddress) => {
53
+ if (!dbAuthToken || !bundlerClient || !smartAccount || !accountRewardsContractAddress || !pid) {
54
+ return {
55
+ success: false,
56
+ message: "Missing authentication token OR NFT ID."
57
+ };
58
+ }
59
+ const callData = (0, import_viem.encodeFunctionData)({
60
+ abi: VERIFY_ACCOUNT_ABI,
61
+ functionName: "claimRewardByName",
62
+ args: ["petastic-signup-campaign-1", pid]
63
+ });
64
+ try {
65
+ const userOpHash = await bundlerClient.sendUserOperation({
66
+ account: smartAccount,
67
+ calls: [
68
+ {
69
+ to: accountRewardsContractAddress,
70
+ data: callData
71
+ }
72
+ ],
73
+ maxPriorityFeePerGas: (0, import_viem.parseGwei)("0.001"),
74
+ maxFeePerGas: (0, import_viem.parseGwei)("0.001")
75
+ });
76
+ await bundlerClient.waitForUserOperationReceipt({
77
+ hash: userOpHash
78
+ });
79
+ return { success: true, message: "Registration kibble awarded" };
80
+ } catch (error) {
81
+ console.error(error);
82
+ return { success: false, message: error.message };
83
+ }
84
+ },
85
+ []
86
+ );
87
+ }
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ useVerifyAccount
91
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,64 @@
1
+ // src/utils/useVerifyAccount.ts
2
+ import { useCallback } from "react";
3
+ import { encodeFunctionData, parseGwei } from "viem";
4
+
5
+ // src/helpers/BlockchainAbiHelper.tsx
6
+ var VERIFY_ACCOUNT_ABI = [
7
+ {
8
+ inputs: [
9
+ {
10
+ internalType: "string",
11
+ name: "_campaignName",
12
+ type: "string"
13
+ },
14
+ { internalType: "string", name: "_pid", type: "string" }
15
+ ],
16
+ name: "claimRewardByName",
17
+ outputs: [],
18
+ stateMutability: "nonpayable",
19
+ type: "function"
20
+ }
21
+ ];
22
+
23
+ // src/utils/useVerifyAccount.ts
24
+ function useVerifyAccount() {
25
+ return useCallback(
26
+ async (pid, dbAuthToken, bundlerClient, smartAccount, accountRewardsContractAddress) => {
27
+ if (!dbAuthToken || !bundlerClient || !smartAccount || !accountRewardsContractAddress || !pid) {
28
+ return {
29
+ success: false,
30
+ message: "Missing authentication token OR NFT ID."
31
+ };
32
+ }
33
+ const callData = encodeFunctionData({
34
+ abi: VERIFY_ACCOUNT_ABI,
35
+ functionName: "claimRewardByName",
36
+ args: ["petastic-signup-campaign-1", pid]
37
+ });
38
+ try {
39
+ const userOpHash = await bundlerClient.sendUserOperation({
40
+ account: smartAccount,
41
+ calls: [
42
+ {
43
+ to: accountRewardsContractAddress,
44
+ data: callData
45
+ }
46
+ ],
47
+ maxPriorityFeePerGas: parseGwei("0.001"),
48
+ maxFeePerGas: parseGwei("0.001")
49
+ });
50
+ await bundlerClient.waitForUserOperationReceipt({
51
+ hash: userOpHash
52
+ });
53
+ return { success: true, message: "Registration kibble awarded" };
54
+ } catch (error) {
55
+ console.error(error);
56
+ return { success: false, message: error.message };
57
+ }
58
+ },
59
+ []
60
+ );
61
+ }
62
+ export {
63
+ useVerifyAccount
64
+ };
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "anymal-protocol",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/types/index.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "build": "tsup src/index.ts --format cjs,esm --dts",
10
+ "prepublishOnly": "npm run build"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "dependencies": {
16
+ "react": "^19.0.0",
17
+ "react-dom": "^19.0.0",
18
+ "viem": "^2.22.8"
19
+ },
20
+ "devDependencies": {
21
+ "@types/react": "^19.0.7",
22
+ "@types/react-dom": "^19.0.3",
23
+ "tsup": "^8.3.5",
24
+ "typescript": "^5.7.3"
25
+ }
26
+ }
@@ -0,0 +1,922 @@
1
+ export const PET_NFT_ABI = [
2
+ { inputs: [], stateMutability: 'nonpayable', type: 'constructor' },
3
+ {
4
+ inputs: [],
5
+ name: 'AccessControlBadConfirmation',
6
+ type: 'error',
7
+ },
8
+ {
9
+ inputs: [
10
+ { internalType: 'address', name: 'account', type: 'address' },
11
+ {
12
+ internalType: 'bytes32',
13
+ name: 'neededRole',
14
+ type: 'bytes32',
15
+ },
16
+ ],
17
+ name: 'AccessControlUnauthorizedAccount',
18
+ type: 'error',
19
+ },
20
+ {
21
+ inputs: [{ internalType: 'address', name: 'target', type: 'address' }],
22
+ name: 'AddressEmptyCode',
23
+ type: 'error',
24
+ },
25
+ {
26
+ inputs: [{ internalType: 'address', name: 'implementation', type: 'address' }],
27
+ name: 'ERC1967InvalidImplementation',
28
+ type: 'error',
29
+ },
30
+ { inputs: [], name: 'ERC1967NonPayable', type: 'error' },
31
+ {
32
+ inputs: [],
33
+ name: 'EnforcedPause',
34
+ type: 'error',
35
+ },
36
+ { inputs: [], name: 'ExpectedPause', type: 'error' },
37
+ {
38
+ inputs: [],
39
+ name: 'FailedCall',
40
+ type: 'error',
41
+ },
42
+ { inputs: [], name: 'InvalidInitialization', type: 'error' },
43
+ {
44
+ inputs: [],
45
+ name: 'NotInitializing',
46
+ type: 'error',
47
+ },
48
+ {
49
+ inputs: [],
50
+ name: 'UUPSUnauthorizedCallContext',
51
+ type: 'error',
52
+ },
53
+ {
54
+ inputs: [{ internalType: 'bytes32', name: 'slot', type: 'bytes32' }],
55
+ name: 'UUPSUnsupportedProxiableUUID',
56
+ type: 'error',
57
+ },
58
+ {
59
+ anonymous: false,
60
+ inputs: [{ indexed: false, internalType: 'uint64', name: 'version', type: 'uint64' }],
61
+ name: 'Initialized',
62
+ type: 'event',
63
+ },
64
+ {
65
+ anonymous: false,
66
+ inputs: [
67
+ {
68
+ indexed: true,
69
+ internalType: 'address',
70
+ name: 'user',
71
+ type: 'address',
72
+ },
73
+ { indexed: false, internalType: 'string', name: 'pid', type: 'string' },
74
+ {
75
+ indexed: false,
76
+ internalType: 'string',
77
+ name: 'nftId',
78
+ type: 'string',
79
+ },
80
+ { indexed: false, internalType: 'string', name: 'metadataURL', type: 'string' },
81
+ {
82
+ indexed: false,
83
+ internalType: 'uint256',
84
+ name: 'campaignId',
85
+ type: 'uint256',
86
+ },
87
+ { indexed: false, internalType: 'uint256', name: 'rewardAmount', type: 'uint256' },
88
+ ],
89
+ name: 'MetadataApproved',
90
+ type: 'event',
91
+ },
92
+ {
93
+ anonymous: false,
94
+ inputs: [
95
+ {
96
+ indexed: true,
97
+ internalType: 'address',
98
+ name: 'user',
99
+ type: 'address',
100
+ },
101
+ { indexed: false, internalType: 'string', name: 'pid', type: 'string' },
102
+ {
103
+ indexed: false,
104
+ internalType: 'string',
105
+ name: 'nftId',
106
+ type: 'string',
107
+ },
108
+ { indexed: false, internalType: 'string', name: 'metadataURL', type: 'string' },
109
+ {
110
+ indexed: false,
111
+ internalType: 'uint256',
112
+ name: 'campaignId',
113
+ type: 'uint256',
114
+ },
115
+ { indexed: false, internalType: 'uint256', name: 'rewardAmount', type: 'uint256' },
116
+ ],
117
+ name: 'MetadataRejected',
118
+ type: 'event',
119
+ },
120
+ {
121
+ anonymous: false,
122
+ inputs: [
123
+ {
124
+ indexed: true,
125
+ internalType: 'address',
126
+ name: 'user',
127
+ type: 'address',
128
+ },
129
+ { indexed: false, internalType: 'string', name: 'pid', type: 'string' },
130
+ {
131
+ indexed: false,
132
+ internalType: 'string',
133
+ name: 'nftId',
134
+ type: 'string',
135
+ },
136
+ { indexed: false, internalType: 'string', name: 'metadataURL', type: 'string' },
137
+ {
138
+ indexed: false,
139
+ internalType: 'uint256',
140
+ name: 'campaignId',
141
+ type: 'uint256',
142
+ },
143
+ { indexed: false, internalType: 'uint256', name: 'rewardAmount', type: 'uint256' },
144
+ ],
145
+ name: 'MetadataSubmitted',
146
+ type: 'event',
147
+ },
148
+ {
149
+ anonymous: false,
150
+ inputs: [{ indexed: false, internalType: 'address', name: 'account', type: 'address' }],
151
+ name: 'Paused',
152
+ type: 'event',
153
+ },
154
+ {
155
+ anonymous: false,
156
+ inputs: [
157
+ {
158
+ indexed: true,
159
+ internalType: 'address',
160
+ name: 'user',
161
+ type: 'address',
162
+ },
163
+ { indexed: false, internalType: 'string', name: 'pid', type: 'string' },
164
+ {
165
+ indexed: false,
166
+ internalType: 'string',
167
+ name: 'nftId',
168
+ type: 'string',
169
+ },
170
+ {
171
+ indexed: false,
172
+ internalType: 'uint256',
173
+ name: 'rewardAmount',
174
+ type: 'uint256',
175
+ },
176
+ { indexed: false, internalType: 'uint256', name: 'campaignId', type: 'uint256' },
177
+ ],
178
+ name: 'RewardDistributed',
179
+ type: 'event',
180
+ },
181
+ {
182
+ anonymous: false,
183
+ inputs: [
184
+ { indexed: true, internalType: 'bytes32', name: 'role', type: 'bytes32' },
185
+ {
186
+ indexed: true,
187
+ internalType: 'bytes32',
188
+ name: 'previousAdminRole',
189
+ type: 'bytes32',
190
+ },
191
+ { indexed: true, internalType: 'bytes32', name: 'newAdminRole', type: 'bytes32' },
192
+ ],
193
+ name: 'RoleAdminChanged',
194
+ type: 'event',
195
+ },
196
+ {
197
+ anonymous: false,
198
+ inputs: [
199
+ { indexed: true, internalType: 'bytes32', name: 'role', type: 'bytes32' },
200
+ {
201
+ indexed: true,
202
+ internalType: 'address',
203
+ name: 'account',
204
+ type: 'address',
205
+ },
206
+ { indexed: true, internalType: 'address', name: 'sender', type: 'address' },
207
+ ],
208
+ name: 'RoleGranted',
209
+ type: 'event',
210
+ },
211
+ {
212
+ anonymous: false,
213
+ inputs: [
214
+ { indexed: true, internalType: 'bytes32', name: 'role', type: 'bytes32' },
215
+ {
216
+ indexed: true,
217
+ internalType: 'address',
218
+ name: 'account',
219
+ type: 'address',
220
+ },
221
+ { indexed: true, internalType: 'address', name: 'sender', type: 'address' },
222
+ ],
223
+ name: 'RoleRevoked',
224
+ type: 'event',
225
+ },
226
+ {
227
+ anonymous: false,
228
+ inputs: [{ indexed: false, internalType: 'address', name: 'account', type: 'address' }],
229
+ name: 'Unpaused',
230
+ type: 'event',
231
+ },
232
+ {
233
+ anonymous: false,
234
+ inputs: [{ indexed: true, internalType: 'address', name: 'implementation', type: 'address' }],
235
+ name: 'Upgraded',
236
+ type: 'event',
237
+ },
238
+ {
239
+ inputs: [],
240
+ name: 'APPROVER_ROLE',
241
+ outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],
242
+ stateMutability: 'view',
243
+ type: 'function',
244
+ },
245
+ {
246
+ inputs: [],
247
+ name: 'DEFAULT_ADMIN_ROLE',
248
+ outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],
249
+ stateMutability: 'view',
250
+ type: 'function',
251
+ },
252
+ {
253
+ inputs: [],
254
+ name: 'UPGRADE_INTERFACE_VERSION',
255
+ outputs: [{ internalType: 'string', name: '', type: 'string' }],
256
+ stateMutability: 'view',
257
+ type: 'function',
258
+ },
259
+ {
260
+ inputs: [
261
+ { internalType: 'address', name: '_user', type: 'address' },
262
+ {
263
+ internalType: 'string',
264
+ name: '_pid',
265
+ type: 'string',
266
+ },
267
+ { internalType: 'string', name: '_nftId', type: 'string' },
268
+ {
269
+ internalType: 'string',
270
+ name: '_metadataURL',
271
+ type: 'string',
272
+ },
273
+ { internalType: 'uint256', name: '_campaignId', type: 'uint256' },
274
+ ],
275
+ name: 'approveMetadata',
276
+ outputs: [],
277
+ stateMutability: 'nonpayable',
278
+ type: 'function',
279
+ },
280
+ {
281
+ inputs: [],
282
+ name: 'campaignCount',
283
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
284
+ stateMutability: 'view',
285
+ type: 'function',
286
+ },
287
+ {
288
+ inputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
289
+ name: 'campaigns',
290
+ outputs: [
291
+ { internalType: 'string', name: 'name', type: 'string' },
292
+ {
293
+ internalType: 'uint256',
294
+ name: 'rewardAmount',
295
+ type: 'uint256',
296
+ },
297
+ { internalType: 'bool', name: 'isActive', type: 'bool' },
298
+ ],
299
+ stateMutability: 'view',
300
+ type: 'function',
301
+ },
302
+ {
303
+ inputs: [
304
+ { internalType: 'string', name: '_name', type: 'string' },
305
+ {
306
+ internalType: 'uint256',
307
+ name: '_rewardAmount',
308
+ type: 'uint256',
309
+ },
310
+ ],
311
+ name: 'createCampaign',
312
+ outputs: [],
313
+ stateMutability: 'nonpayable',
314
+ type: 'function',
315
+ },
316
+ {
317
+ inputs: [],
318
+ name: 'defaultRewardAmount',
319
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
320
+ stateMutability: 'view',
321
+ type: 'function',
322
+ },
323
+ {
324
+ inputs: [{ internalType: 'bytes32', name: 'role', type: 'bytes32' }],
325
+ name: 'getRoleAdmin',
326
+ outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],
327
+ stateMutability: 'view',
328
+ type: 'function',
329
+ },
330
+ {
331
+ inputs: [
332
+ { internalType: 'bytes32', name: 'role', type: 'bytes32' },
333
+ {
334
+ internalType: 'address',
335
+ name: 'account',
336
+ type: 'address',
337
+ },
338
+ ],
339
+ name: 'grantRole',
340
+ outputs: [],
341
+ stateMutability: 'nonpayable',
342
+ type: 'function',
343
+ },
344
+ {
345
+ inputs: [
346
+ { internalType: 'bytes32', name: 'role', type: 'bytes32' },
347
+ {
348
+ internalType: 'address',
349
+ name: 'account',
350
+ type: 'address',
351
+ },
352
+ ],
353
+ name: 'hasRole',
354
+ outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
355
+ stateMutability: 'view',
356
+ type: 'function',
357
+ },
358
+ {
359
+ inputs: [
360
+ {
361
+ internalType: 'address',
362
+ name: 'initialOwner',
363
+ type: 'address',
364
+ },
365
+ {
366
+ internalType: 'contract IERC20',
367
+ name: '_rewardToken',
368
+ type: 'address',
369
+ },
370
+ {
371
+ internalType: 'contract IPetToken',
372
+ name: '_petToken',
373
+ type: 'address',
374
+ },
375
+ { internalType: 'uint256', name: '_defaultRewardAmount', type: 'uint256' },
376
+ ],
377
+ name: 'initialize',
378
+ outputs: [],
379
+ stateMutability: 'nonpayable',
380
+ type: 'function',
381
+ },
382
+ {
383
+ inputs: [],
384
+ name: 'pause',
385
+ outputs: [],
386
+ stateMutability: 'nonpayable',
387
+ type: 'function',
388
+ },
389
+ {
390
+ inputs: [],
391
+ name: 'paused',
392
+ outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
393
+ stateMutability: 'view',
394
+ type: 'function',
395
+ },
396
+ {
397
+ inputs: [],
398
+ name: 'petToken',
399
+ outputs: [{ internalType: 'contract IPetToken', name: '', type: 'address' }],
400
+ stateMutability: 'view',
401
+ type: 'function',
402
+ },
403
+ {
404
+ inputs: [],
405
+ name: 'proxiableUUID',
406
+ outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],
407
+ stateMutability: 'view',
408
+ type: 'function',
409
+ },
410
+ {
411
+ inputs: [
412
+ { internalType: 'bytes32', name: 'role', type: 'bytes32' },
413
+ {
414
+ internalType: 'address',
415
+ name: 'callerConfirmation',
416
+ type: 'address',
417
+ },
418
+ ],
419
+ name: 'renounceRole',
420
+ outputs: [],
421
+ stateMutability: 'nonpayable',
422
+ type: 'function',
423
+ },
424
+ {
425
+ inputs: [
426
+ { internalType: 'bytes32', name: 'role', type: 'bytes32' },
427
+ {
428
+ internalType: 'address',
429
+ name: 'account',
430
+ type: 'address',
431
+ },
432
+ ],
433
+ name: 'revokeRole',
434
+ outputs: [],
435
+ stateMutability: 'nonpayable',
436
+ type: 'function',
437
+ },
438
+ {
439
+ inputs: [],
440
+ name: 'rewardToken',
441
+ outputs: [{ internalType: 'contract IERC20', name: '', type: 'address' }],
442
+ stateMutability: 'view',
443
+ type: 'function',
444
+ },
445
+ {
446
+ inputs: [
447
+ { internalType: 'string', name: '_pid', type: 'string' },
448
+ {
449
+ internalType: 'string',
450
+ name: '_nftId',
451
+ type: 'string',
452
+ },
453
+ { internalType: 'string', name: '_metadataURL', type: 'string' },
454
+ {
455
+ internalType: 'uint256',
456
+ name: '_campaignId',
457
+ type: 'uint256',
458
+ },
459
+ ],
460
+ name: 'submitMetadata',
461
+ outputs: [],
462
+ stateMutability: 'nonpayable',
463
+ type: 'function',
464
+ },
465
+ {
466
+ inputs: [
467
+ { internalType: 'string', name: '_pid', type: 'string' },
468
+ {
469
+ internalType: 'string',
470
+ name: '_nftId',
471
+ type: 'string',
472
+ },
473
+ { internalType: 'string', name: '_metadataURL', type: 'string' },
474
+ {
475
+ internalType: 'string',
476
+ name: '_campaignName',
477
+ type: 'string',
478
+ },
479
+ ],
480
+ name: 'submitMetadataByCampaignName',
481
+ outputs: [],
482
+ stateMutability: 'nonpayable',
483
+ type: 'function',
484
+ },
485
+ {
486
+ inputs: [{ internalType: 'bytes4', name: 'interfaceId', type: 'bytes4' }],
487
+ name: 'supportsInterface',
488
+ outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
489
+ stateMutability: 'view',
490
+ type: 'function',
491
+ },
492
+ {
493
+ inputs: [],
494
+ name: 'unpause',
495
+ outputs: [],
496
+ stateMutability: 'nonpayable',
497
+ type: 'function',
498
+ },
499
+ {
500
+ inputs: [
501
+ {
502
+ internalType: 'uint256',
503
+ name: '_campaignId',
504
+ type: 'uint256',
505
+ },
506
+ { internalType: 'uint256', name: '_rewardAmount', type: 'uint256' },
507
+ {
508
+ internalType: 'bool',
509
+ name: '_isActive',
510
+ type: 'bool',
511
+ },
512
+ ],
513
+ name: 'updateCampaign',
514
+ outputs: [],
515
+ stateMutability: 'nonpayable',
516
+ type: 'function',
517
+ },
518
+ {
519
+ inputs: [{ internalType: 'uint256', name: '_rewardAmount', type: 'uint256' }],
520
+ name: 'updateDefaultReward',
521
+ outputs: [],
522
+ stateMutability: 'nonpayable',
523
+ type: 'function',
524
+ },
525
+ {
526
+ inputs: [
527
+ {
528
+ internalType: 'address',
529
+ name: 'newImplementation',
530
+ type: 'address',
531
+ },
532
+ { internalType: 'bytes', name: 'data', type: 'bytes' },
533
+ ],
534
+ name: 'upgradeToAndCall',
535
+ outputs: [],
536
+ stateMutability: 'payable',
537
+ type: 'function',
538
+ },
539
+ ];
540
+ export const NFT_BALANCE_ABI = [
541
+ {
542
+ inputs: [{ internalType: 'address', name: 'initialOwner', type: 'address' }],
543
+ stateMutability: 'nonpayable',
544
+ type: 'constructor',
545
+ },
546
+ {
547
+ inputs: [
548
+ { internalType: 'address', name: 'sender', type: 'address' },
549
+ {
550
+ internalType: 'uint256',
551
+ name: 'tokenId',
552
+ type: 'uint256',
553
+ },
554
+ { internalType: 'address', name: 'owner', type: 'address' },
555
+ ],
556
+ name: 'ERC721IncorrectOwner',
557
+ type: 'error',
558
+ },
559
+ {
560
+ inputs: [
561
+ { internalType: 'address', name: 'operator', type: 'address' },
562
+ {
563
+ internalType: 'uint256',
564
+ name: 'tokenId',
565
+ type: 'uint256',
566
+ },
567
+ ],
568
+ name: 'ERC721InsufficientApproval',
569
+ type: 'error',
570
+ },
571
+ {
572
+ inputs: [{ internalType: 'address', name: 'approver', type: 'address' }],
573
+ name: 'ERC721InvalidApprover',
574
+ type: 'error',
575
+ },
576
+ {
577
+ inputs: [{ internalType: 'address', name: 'operator', type: 'address' }],
578
+ name: 'ERC721InvalidOperator',
579
+ type: 'error',
580
+ },
581
+ {
582
+ inputs: [{ internalType: 'address', name: 'owner', type: 'address' }],
583
+ name: 'ERC721InvalidOwner',
584
+ type: 'error',
585
+ },
586
+ {
587
+ inputs: [{ internalType: 'address', name: 'receiver', type: 'address' }],
588
+ name: 'ERC721InvalidReceiver',
589
+ type: 'error',
590
+ },
591
+ {
592
+ inputs: [{ internalType: 'address', name: 'sender', type: 'address' }],
593
+ name: 'ERC721InvalidSender',
594
+ type: 'error',
595
+ },
596
+ {
597
+ inputs: [{ internalType: 'uint256', name: 'tokenId', type: 'uint256' }],
598
+ name: 'ERC721NonexistentToken',
599
+ type: 'error',
600
+ },
601
+ { inputs: [], name: 'EnforcedPause', type: 'error' },
602
+ {
603
+ inputs: [],
604
+ name: 'ExpectedPause',
605
+ type: 'error',
606
+ },
607
+ {
608
+ inputs: [{ internalType: 'address', name: 'owner', type: 'address' }],
609
+ name: 'OwnableInvalidOwner',
610
+ type: 'error',
611
+ },
612
+ {
613
+ inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
614
+ name: 'OwnableUnauthorizedAccount',
615
+ type: 'error',
616
+ },
617
+ {
618
+ anonymous: false,
619
+ inputs: [
620
+ { indexed: true, internalType: 'address', name: 'owner', type: 'address' },
621
+ {
622
+ indexed: true,
623
+ internalType: 'address',
624
+ name: 'approved',
625
+ type: 'address',
626
+ },
627
+ { indexed: true, internalType: 'uint256', name: 'tokenId', type: 'uint256' },
628
+ ],
629
+ name: 'Approval',
630
+ type: 'event',
631
+ },
632
+ {
633
+ anonymous: false,
634
+ inputs: [
635
+ { indexed: true, internalType: 'address', name: 'owner', type: 'address' },
636
+ {
637
+ indexed: true,
638
+ internalType: 'address',
639
+ name: 'operator',
640
+ type: 'address',
641
+ },
642
+ { indexed: false, internalType: 'bool', name: 'approved', type: 'bool' },
643
+ ],
644
+ name: 'ApprovalForAll',
645
+ type: 'event',
646
+ },
647
+ {
648
+ anonymous: false,
649
+ inputs: [
650
+ {
651
+ indexed: false,
652
+ internalType: 'uint256',
653
+ name: '_fromTokenId',
654
+ type: 'uint256',
655
+ },
656
+ { indexed: false, internalType: 'uint256', name: '_toTokenId', type: 'uint256' },
657
+ ],
658
+ name: 'BatchMetadataUpdate',
659
+ type: 'event',
660
+ },
661
+ {
662
+ anonymous: false,
663
+ inputs: [{ indexed: false, internalType: 'uint256', name: '_tokenId', type: 'uint256' }],
664
+ name: 'MetadataUpdate',
665
+ type: 'event',
666
+ },
667
+ {
668
+ anonymous: false,
669
+ inputs: [
670
+ {
671
+ indexed: true,
672
+ internalType: 'address',
673
+ name: 'previousOwner',
674
+ type: 'address',
675
+ },
676
+ { indexed: true, internalType: 'address', name: 'newOwner', type: 'address' },
677
+ ],
678
+ name: 'OwnershipTransferred',
679
+ type: 'event',
680
+ },
681
+ {
682
+ anonymous: false,
683
+ inputs: [{ indexed: false, internalType: 'address', name: 'account', type: 'address' }],
684
+ name: 'Paused',
685
+ type: 'event',
686
+ },
687
+ {
688
+ anonymous: false,
689
+ inputs: [
690
+ { indexed: true, internalType: 'address', name: 'from', type: 'address' },
691
+ {
692
+ indexed: true,
693
+ internalType: 'address',
694
+ name: 'to',
695
+ type: 'address',
696
+ },
697
+ { indexed: true, internalType: 'uint256', name: 'tokenId', type: 'uint256' },
698
+ ],
699
+ name: 'Transfer',
700
+ type: 'event',
701
+ },
702
+ {
703
+ anonymous: false,
704
+ inputs: [{ indexed: false, internalType: 'address', name: 'account', type: 'address' }],
705
+ name: 'Unpaused',
706
+ type: 'event',
707
+ },
708
+ {
709
+ inputs: [
710
+ { internalType: 'address', name: 'to', type: 'address' },
711
+ {
712
+ internalType: 'uint256',
713
+ name: 'tokenId',
714
+ type: 'uint256',
715
+ },
716
+ ],
717
+ name: 'approve',
718
+ outputs: [],
719
+ stateMutability: 'nonpayable',
720
+ type: 'function',
721
+ },
722
+ {
723
+ inputs: [{ internalType: 'address', name: 'owner', type: 'address' }],
724
+ name: 'balanceOf',
725
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
726
+ stateMutability: 'view',
727
+ type: 'function',
728
+ },
729
+ {
730
+ inputs: [{ internalType: 'uint256', name: 'tokenId', type: 'uint256' }],
731
+ name: 'burn',
732
+ outputs: [],
733
+ stateMutability: 'nonpayable',
734
+ type: 'function',
735
+ },
736
+ {
737
+ inputs: [{ internalType: 'uint256', name: 'tokenId', type: 'uint256' }],
738
+ name: 'getApproved',
739
+ outputs: [{ internalType: 'address', name: '', type: 'address' }],
740
+ stateMutability: 'view',
741
+ type: 'function',
742
+ },
743
+ {
744
+ inputs: [
745
+ { internalType: 'address', name: 'owner', type: 'address' },
746
+ {
747
+ internalType: 'address',
748
+ name: 'operator',
749
+ type: 'address',
750
+ },
751
+ ],
752
+ name: 'isApprovedForAll',
753
+ outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
754
+ stateMutability: 'view',
755
+ type: 'function',
756
+ },
757
+ {
758
+ inputs: [],
759
+ name: 'name',
760
+ outputs: [{ internalType: 'string', name: '', type: 'string' }],
761
+ stateMutability: 'view',
762
+ type: 'function',
763
+ },
764
+ {
765
+ inputs: [],
766
+ name: 'owner',
767
+ outputs: [{ internalType: 'address', name: '', type: 'address' }],
768
+ stateMutability: 'view',
769
+ type: 'function',
770
+ },
771
+ {
772
+ inputs: [{ internalType: 'uint256', name: 'tokenId', type: 'uint256' }],
773
+ name: 'ownerOf',
774
+ outputs: [{ internalType: 'address', name: '', type: 'address' }],
775
+ stateMutability: 'view',
776
+ type: 'function',
777
+ },
778
+ {
779
+ inputs: [],
780
+ name: 'pause',
781
+ outputs: [],
782
+ stateMutability: 'nonpayable',
783
+ type: 'function',
784
+ },
785
+ {
786
+ inputs: [],
787
+ name: 'paused',
788
+ outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
789
+ stateMutability: 'view',
790
+ type: 'function',
791
+ },
792
+ {
793
+ inputs: [],
794
+ name: 'renounceOwnership',
795
+ outputs: [],
796
+ stateMutability: 'nonpayable',
797
+ type: 'function',
798
+ },
799
+ {
800
+ inputs: [
801
+ { internalType: 'address', name: 'to', type: 'address' },
802
+ {
803
+ internalType: 'string',
804
+ name: 'uri',
805
+ type: 'string',
806
+ },
807
+ ],
808
+ name: 'safeMint',
809
+ outputs: [],
810
+ stateMutability: 'nonpayable',
811
+ type: 'function',
812
+ },
813
+ {
814
+ inputs: [
815
+ { internalType: 'address', name: 'from', type: 'address' },
816
+ {
817
+ internalType: 'address',
818
+ name: 'to',
819
+ type: 'address',
820
+ },
821
+ { internalType: 'uint256', name: 'tokenId', type: 'uint256' },
822
+ ],
823
+ name: 'safeTransferFrom',
824
+ outputs: [],
825
+ stateMutability: 'nonpayable',
826
+ type: 'function',
827
+ },
828
+ {
829
+ inputs: [
830
+ { internalType: 'address', name: 'from', type: 'address' },
831
+ {
832
+ internalType: 'address',
833
+ name: 'to',
834
+ type: 'address',
835
+ },
836
+ { internalType: 'uint256', name: 'tokenId', type: 'uint256' },
837
+ {
838
+ internalType: 'bytes',
839
+ name: 'data',
840
+ type: 'bytes',
841
+ },
842
+ ],
843
+ name: 'safeTransferFrom',
844
+ outputs: [],
845
+ stateMutability: 'nonpayable',
846
+ type: 'function',
847
+ },
848
+ {
849
+ inputs: [
850
+ { internalType: 'address', name: 'operator', type: 'address' },
851
+ {
852
+ internalType: 'bool',
853
+ name: 'approved',
854
+ type: 'bool',
855
+ },
856
+ ],
857
+ name: 'setApprovalForAll',
858
+ outputs: [],
859
+ stateMutability: 'nonpayable',
860
+ type: 'function',
861
+ },
862
+ {
863
+ inputs: [{ internalType: 'bytes4', name: 'interfaceId', type: 'bytes4' }],
864
+ name: 'supportsInterface',
865
+ outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
866
+ stateMutability: 'view',
867
+ type: 'function',
868
+ },
869
+ {
870
+ inputs: [],
871
+ name: 'symbol',
872
+ outputs: [{ internalType: 'string', name: '', type: 'string' }],
873
+ stateMutability: 'view',
874
+ type: 'function',
875
+ },
876
+ {
877
+ inputs: [{ internalType: 'uint256', name: 'tokenId', type: 'uint256' }],
878
+ name: 'tokenURI',
879
+ outputs: [{ internalType: 'string', name: '', type: 'string' }],
880
+ stateMutability: 'view',
881
+ type: 'function',
882
+ },
883
+ {
884
+ inputs: [
885
+ { internalType: 'address', name: 'from', type: 'address' },
886
+ {
887
+ internalType: 'address',
888
+ name: 'to',
889
+ type: 'address',
890
+ },
891
+ { internalType: 'uint256', name: 'tokenId', type: 'uint256' },
892
+ ],
893
+ name: 'transferFrom',
894
+ outputs: [],
895
+ stateMutability: 'nonpayable',
896
+ type: 'function',
897
+ },
898
+ {
899
+ inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }],
900
+ name: 'transferOwnership',
901
+ outputs: [],
902
+ stateMutability: 'nonpayable',
903
+ type: 'function',
904
+ },
905
+ { inputs: [], name: 'unpause', outputs: [], stateMutability: 'nonpayable', type: 'function' },
906
+ ];
907
+ export const VERIFY_ACCOUNT_ABI = [
908
+ {
909
+ inputs: [
910
+ {
911
+ internalType: 'string',
912
+ name: '_campaignName',
913
+ type: 'string',
914
+ },
915
+ { internalType: 'string', name: '_pid', type: 'string' },
916
+ ],
917
+ name: 'claimRewardByName',
918
+ outputs: [],
919
+ stateMutability: 'nonpayable',
920
+ type: 'function',
921
+ },
922
+ ];
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./utils/useVerifyAccount";
@@ -0,0 +1,61 @@
1
+ import { useCallback } from "react";
2
+ import { encodeFunctionData, parseGwei } from "viem";
3
+ import { VERIFY_ACCOUNT_ABI } from "../helpers/BlockchainAbiHelper";
4
+
5
+ export function useVerifyAccount() {
6
+ return useCallback(
7
+ async (
8
+ pid: string,
9
+ dbAuthToken: string,
10
+ bundlerClient: any,
11
+ smartAccount: any,
12
+ accountRewardsContractAddress: `0x${string}`
13
+ ): Promise<{
14
+ success: boolean;
15
+ message: string;
16
+ }> => {
17
+ if (
18
+ !dbAuthToken ||
19
+ !bundlerClient ||
20
+ !smartAccount ||
21
+ !accountRewardsContractAddress ||
22
+ !pid
23
+ ) {
24
+ return {
25
+ success: false,
26
+ message: "Missing authentication token OR NFT ID.",
27
+ };
28
+ }
29
+
30
+ const callData = encodeFunctionData({
31
+ abi: VERIFY_ACCOUNT_ABI,
32
+ functionName: "claimRewardByName",
33
+ args: ["petastic-signup-campaign-1", pid],
34
+ });
35
+
36
+ try {
37
+ const userOpHash = await bundlerClient.sendUserOperation({
38
+ account: smartAccount,
39
+ calls: [
40
+ {
41
+ to: accountRewardsContractAddress,
42
+ data: callData,
43
+ },
44
+ ],
45
+ maxPriorityFeePerGas: parseGwei("0.001"),
46
+ maxFeePerGas: parseGwei("0.001"),
47
+ });
48
+
49
+ await bundlerClient.waitForUserOperationReceipt({
50
+ hash: userOpHash,
51
+ });
52
+
53
+ return { success: true, message: "Registration kibble awarded" };
54
+ } catch (error) {
55
+ console.error(error);
56
+ return { success: false, message: (error as Error).message };
57
+ }
58
+ },
59
+ []
60
+ );
61
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "lib": ["DOM", "ESNext"],
6
+ "declaration": true,
7
+ "declarationDir": "dist/types",
8
+ "outDir": "dist",
9
+ "strict": true,
10
+ "jsx": "react-jsx",
11
+ "moduleResolution": "node",
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true
14
+ },
15
+ "include": ["src/**/*"],
16
+ "exclude": ["node_modules", "dist"]
17
+ }